public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: David Howells <dhowells@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] param: Adapt MN10300 to the new parameter handling regime
Date: Fri, 5 Dec 2008 18:55:06 +1030	[thread overview]
Message-ID: <200812051855.07203.rusty@rustcorp.com.au> (raw)
In-Reply-To: <20081203163207.13965.56517.stgit@warthog.procyon.org.uk>

On Thursday 04 December 2008 03:02:07 David Howells wrote:
> Make MN10300 use the new core parameter code.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>

Hi David,

   Maybe we should add a new param type to the general code so this can be
done with core_param.  See below. Not sure if it's a win tho (many archs want
mem=num@pos, x86 wants mem=nopentium, etc).

I've applied this and 3/3 meanwhile.

Thanks!
Rusty.

param: add "mem" type for module_param/core_param

core_param is now called early enough to be useful for arch's mem=
parameter.  Some archs want fancier parsing, but this allows:

	static unsigned long mem_override;
	core_param(mem, mem_override, mem, 0444);

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -94,7 +94,7 @@ struct kparam_array
 	__module_param_call(MODULE_PARAM_PREFIX, name, set, get, arg, perm)
 
 /* Helper functions: type is byte, short, ushort, int, uint, long,
-   ulong, charp, bool or invbool, or XXX if you define param_get_XXX,
+   ulong, charp, bool or invbool, mem or XXX if you define param_get_XXX,
    param_set_XXX and param_check_XXX. */
 #define module_param_named(name, value, type, perm)			   \
 	param_check_##type(name, &(value));				   \
@@ -184,6 +184,10 @@ extern int param_get_invbool(char *buffe
 extern int param_get_invbool(char *buffer, struct kernel_param *kp);
 #define param_check_invbool(name, p) __param_check(name, p, int)
 
+extern int param_set_mem(const char *val, struct kernel_param *kp);
+extern int param_get_mem(char *buffer, struct kernel_param *kp);
+#define param_check_mem(name, p) __param_check(name, p, unsigned long)
+
 /* Comma-separated array: *nump is set to number they actually specified. */
 #define module_param_array_named(name, array, type, nump, perm)		\
 	static const struct kparam_array __param_arr_##name		\
diff --git a/kernel/params.c b/kernel/params.c
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -264,6 +264,44 @@ int param_get_invbool(char *buffer, stru
 int param_get_invbool(char *buffer, struct kernel_param *kp)
 {
 	return sprintf(buffer, "%c", (*(int *)kp->arg) ? 'N' : 'Y');
+}
+
+int param_set_mem(const char *val, struct kernel_param *kp)
+{
+	unsigned long long mem;
+	char *endp;
+
+	if (!val || !*val)
+		return -EINVAL;
+
+	mem = memparse(val, &endp);
+	if (*endp)
+		return -EINVAL;
+
+	if ((unsigned long)mem != mem)
+		return -E2BIG;
+	*(unsigned long *)kp->arg = mem;
+	return 0;
+}
+
+int param_get_mem(char *buffer, struct kernel_param *kp)
+{
+	unsigned long mem = *(unsigned long *)kp->arg;
+	const char *suffix = "";
+
+	if (mem > 0) {
+		if (mem % (1024*1024*1024) == 0) {
+			suffix = "G";
+			mem /= 1024*1024*1024;
+		} else if (mem % (1024*1024) == 0) {
+			suffix = "M";
+			mem /= 1024*1024;
+		} else if (mem % 1024 == 0) {
+			suffix = "K";
+			mem /= 1024;
+		}
+	}		
+	return sprintf(buffer, "%lu%s", mem, suffix);
 }
 
 /* We break the rule and mangle the string. */

  parent reply	other threads:[~2008-12-05  8:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-03 16:32 [PATCH 1/3] param: Adapt MN10300 to the new parameter handling regime David Howells
2008-12-03 16:32 ` [PATCH 2/3] [PATCH] param: Stop gcc from inlining empty weak functions David Howells
2008-12-05  8:28   ` Rusty Russell
2008-12-05 12:02     ` David Howells
2008-12-03 16:32 ` [PATCH 3/3] [PATCH] param: Adapt FRV to the new parameter handling regime David Howells
2008-12-05  8:25 ` Rusty Russell [this message]
2008-12-05 11:58   ` [PATCH 1/3] param: Adapt MN10300 " David Howells
2008-12-05 12:55     ` Rusty Russell
2008-12-05 13:07       ` David Howells
2008-12-07  9:21       ` Rusty Russell
2008-12-10 10:39         ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200812051855.07203.rusty@rustcorp.com.au \
    --to=rusty@rustcorp.com.au \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox