public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -mm] x86 boot : export boot_params via sysfs
@ 2007-12-11 16:49 Huang, Ying
  2007-12-12  2:40 ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Huang, Ying @ 2007-12-11 16:49 UTC (permalink / raw)
  To: akpm, H. Peter Anvin, Thomas Gleixner, Ingo Molnar, Andi Kleen,
	Eric W. Biederman
  Cc: linux-kernel

This patch export the boot parameters via sysfs. This can be used for
debugging and kexec.

The files added are as follow:

/sys/kernel/boot_params/data	: binary file for struct boot_params
/sys/kernel/boot_params/version	: boot protocol version

This patch is based on 2.6.24-rc4-mm1 and has been tested on i386 and
x86_64 platoform.

Signed-off-by: Huang Ying <ying.huang@intel.com>

---
 arch/x86/kernel/Makefile_32 |    1 
 arch/x86/kernel/Makefile_64 |    1 
 arch/x86/kernel/ksysfs.c    |   94 ++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/setup64.c   |    2 
 arch/x86/kernel/setup_32.c  |    2 
 5 files changed, 98 insertions(+), 2 deletions(-)

--- a/arch/x86/kernel/Makefile_64
+++ b/arch/x86/kernel/Makefile_64
@@ -39,6 +39,7 @@ obj-$(CONFIG_X86_VSMP)		+= vsmp_64.o
 obj-$(CONFIG_K8_NB)		+= k8.o
 obj-$(CONFIG_AUDIT)		+= audit_64.o
 obj-$(CONFIG_EFI)		+= efi.o efi_64.o efi_stub_64.o
+obj-$(CONFIG_SYSFS)		+= ksysfs.o
 
 obj-$(CONFIG_MODULES)		+= module_64.o
 obj-$(CONFIG_PCI)		+= early-quirks.o
--- a/arch/x86/kernel/setup64.c
+++ b/arch/x86/kernel/setup64.c
@@ -24,7 +24,7 @@
 #include <asm/sections.h>
 #include <asm/setup.h>
 
-struct boot_params __initdata boot_params;
+struct boot_params boot_params;
 
 cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
 
--- /dev/null
+++ b/arch/x86/kernel/ksysfs.c
@@ -0,0 +1,94 @@
+/*
+ * arch/i386/ksysfs.c - architecture specific sysfs attributes in /sys/kernel
+ *
+ * Copyright (C) 2007, Intel Corp.
+ *      Huang Ying <ying.huang@intel.com>
+ *
+ * This file is released under the GPLv2
+ */
+
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/init.h>
+#include <linux/stat.h>
+#include <linux/mm.h>
+
+#include <asm/setup.h>
+
+static ssize_t boot_params_version_show(struct kobject *kobj,
+					struct kobj_attribute *attr, char *buf)
+{
+	return sprintf(buf, "0x%04x\n", boot_params.hdr.version);
+}
+
+static struct kobj_attribute boot_params_version_attr = {
+	.attr = {
+		.name = "version",
+		.mode = S_IRUGO,
+	},
+	.show = boot_params_version_show,
+};
+
+static struct attribute *boot_params_attrs[] = {
+	&boot_params_version_attr.attr,
+	NULL
+};
+
+static struct attribute_group boot_params_attr_group = {
+	.attrs = boot_params_attrs,
+};
+
+static ssize_t boot_params_data_read(struct kobject *kobj,
+				     struct bin_attribute *bin_attr,
+				     char *buf, loff_t off, size_t count)
+{
+	memcpy(buf, (void *)&boot_params + off, count);
+	return count;
+}
+
+static struct bin_attribute boot_params_data_attr = {
+	.attr = {
+		.name = "data",
+		.mode = S_IRUGO,
+	},
+	.read = boot_params_data_read,
+	.size = sizeof(boot_params),
+};
+
+static int __init boot_params_ksysfs_init(void)
+{
+	int error;
+	struct kobject *boot_params_kobj;
+
+	boot_params_kobj = kobject_create_and_register("boot_params",
+						       kernel_kobj);
+	if (!boot_params_kobj) {
+		error = -ENOMEM;
+		goto err_return;
+	}
+	error = sysfs_create_group(boot_params_kobj,
+				   &boot_params_attr_group);
+	if (error)
+		goto err_boot_params_subsys_unregister;
+	error = sysfs_create_bin_file(boot_params_kobj,
+				      &boot_params_data_attr);
+	if (error)
+		goto err_boot_params_subsys_unregister;
+	return 0;
+err_boot_params_subsys_unregister:
+	kobject_unregister(boot_params_kobj);
+err_return:
+	return error;
+}
+
+static int __init arch_ksysfs_init(void)
+{
+	int error;
+
+	error = boot_params_ksysfs_init();
+
+	return error;
+}
+
+arch_initcall(arch_ksysfs_init);
--- a/arch/x86/kernel/Makefile_32
+++ b/arch/x86/kernel/Makefile_32
@@ -44,6 +44,7 @@ obj-$(CONFIG_EARLY_PRINTK)	+= early_prin
 obj-$(CONFIG_HPET_TIMER) 	+= hpet.o
 obj-$(CONFIG_K8_NB)		+= k8.o
 obj-$(CONFIG_MGEODE_LX)		+= geode_32.o mfgpt_32.o
+obj-$(CONFIG_SYSFS)		+= ksysfs.o
 
 obj-$(CONFIG_VMI)		+= vmi_32.o vmiclock_32.o
 obj-$(CONFIG_PARAVIRT)		+= paravirt_32.o
--- a/arch/x86/kernel/setup_32.c
+++ b/arch/x86/kernel/setup_32.c
@@ -194,7 +194,7 @@ unsigned long saved_videomode;
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
 
-struct boot_params __initdata boot_params;
+struct boot_params boot_params;
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -mm] x86 boot : export boot_params via sysfs
  2007-12-11 16:49 [PATCH -mm] x86 boot : export boot_params via sysfs Huang, Ying
@ 2007-12-12  2:40 ` Andrew Morton
  2007-12-12  4:42   ` Dave Young
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2007-12-12  2:40 UTC (permalink / raw)
  To: Huang, Ying
  Cc: H. Peter Anvin, Thomas Gleixner, Ingo Molnar, Andi Kleen,
	Eric W. Biederman, linux-kernel, Greg KH

On Tue, 11 Dec 2007 16:49:09 +0000 "Huang, Ying" <ying.huang@intel.com> wrote:

> This patch export the boot parameters via sysfs. This can be used for
> debugging and kexec.
> 
> The files added are as follow:
> 
> /sys/kernel/boot_params/data	: binary file for struct boot_params
> /sys/kernel/boot_params/version	: boot protocol version

Your patch uses kobject_create_and_register() which was added in Greg's
driver tree as of 2.6.24-rc4-mm1.

However for some reason kobject_create_and_register() has magically vanished
from Greg's current driver tree so I cannot carry this patch, sorry.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -mm] x86 boot : export boot_params via sysfs
  2007-12-12  2:40 ` Andrew Morton
@ 2007-12-12  4:42   ` Dave Young
  2007-12-12  6:55     ` Greg KH
  2007-12-12  6:56     ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: Dave Young @ 2007-12-12  4:42 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Huang, Ying, H. Peter Anvin, Thomas Gleixner, Ingo Molnar,
	Andi Kleen, Eric W. Biederman, linux-kernel, Greg KH

On Dec 12, 2007 10:40 AM, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Tue, 11 Dec 2007 16:49:09 +0000 "Huang, Ying" <ying.huang@intel.com> wrote:
>
> > This patch export the boot parameters via sysfs. This can be used for
> > debugging and kexec.
> >
> > The files added are as follow:
> >
> > /sys/kernel/boot_params/data  : binary file for struct boot_params
> > /sys/kernel/boot_params/version       : boot protocol version
>
> Your patch uses kobject_create_and_register() which was added in Greg's
> driver tree as of 2.6.24-rc4-mm1.
>
> However for some reason kobject_create_and_register() has magically vanished
> from Greg's current driver tree so I cannot carry this patch, sorry.

Seems kobject_create_and_register would be replaced by
kobject_create_and_add, and the uevent handling would be separated
from original create_and_register onefunction.

wait for greg's patches or modify to use:

kobject_init
kobject_add
kobject_uevent

BTW, I suspect whether the uevent is really needed for boot_params object.

Regards
dave

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -mm] x86 boot : export boot_params via sysfs
  2007-12-12  4:42   ` Dave Young
@ 2007-12-12  6:55     ` Greg KH
  2007-12-12  6:56     ` Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: Greg KH @ 2007-12-12  6:55 UTC (permalink / raw)
  To: Dave Young
  Cc: Andrew Morton, Huang, Ying, H. Peter Anvin, Thomas Gleixner,
	Ingo Molnar, Andi Kleen, Eric W. Biederman, linux-kernel

On Wed, Dec 12, 2007 at 12:42:48PM +0800, Dave Young wrote:
> On Dec 12, 2007 10:40 AM, Andrew Morton <akpm@linux-foundation.org> wrote:
> > On Tue, 11 Dec 2007 16:49:09 +0000 "Huang, Ying" <ying.huang@intel.com> wrote:
> >
> > > This patch export the boot parameters via sysfs. This can be used for
> > > debugging and kexec.
> > >
> > > The files added are as follow:
> > >
> > > /sys/kernel/boot_params/data  : binary file for struct boot_params
> > > /sys/kernel/boot_params/version       : boot protocol version
> >
> > Your patch uses kobject_create_and_register() which was added in Greg's
> > driver tree as of 2.6.24-rc4-mm1.
> >
> > However for some reason kobject_create_and_register() has magically vanished
> > from Greg's current driver tree so I cannot carry this patch, sorry.
> 
> Seems kobject_create_and_register would be replaced by
> kobject_create_and_add, and the uevent handling would be separated
> from original create_and_register onefunction.

Yes, that is what has now changed.

> wait for greg's patches or modify to use:
> 
> kobject_init
> kobject_add
> kobject_uevent
> 
> BTW, I suspect whether the uevent is really needed for boot_params object.

Actually, for something as trivial as this, just use the
kobject_create_and_add() and don't worry about the uevent.  It should be
pretty trivial.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH -mm] x86 boot : export boot_params via sysfs
  2007-12-12  4:42   ` Dave Young
  2007-12-12  6:55     ` Greg KH
@ 2007-12-12  6:56     ` Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: Greg KH @ 2007-12-12  6:56 UTC (permalink / raw)
  To: Dave Young
  Cc: Andrew Morton, Huang, Ying, H. Peter Anvin, Thomas Gleixner,
	Ingo Molnar, Andi Kleen, Eric W. Biederman, linux-kernel

On Wed, Dec 12, 2007 at 12:42:48PM +0800, Dave Young wrote:
> On Dec 12, 2007 10:40 AM, Andrew Morton <akpm@linux-foundation.org> wrote:
> > On Tue, 11 Dec 2007 16:49:09 +0000 "Huang, Ying" <ying.huang@intel.com> wrote:
> >
> > > This patch export the boot parameters via sysfs. This can be used for
> > > debugging and kexec.
> > >
> > > The files added are as follow:
> > >
> > > /sys/kernel/boot_params/data  : binary file for struct boot_params
> > > /sys/kernel/boot_params/version       : boot protocol version
> >
> > Your patch uses kobject_create_and_register() which was added in Greg's
> > driver tree as of 2.6.24-rc4-mm1.
> >
> > However for some reason kobject_create_and_register() has magically vanished
> > from Greg's current driver tree so I cannot carry this patch, sorry.
> 
> Seems kobject_create_and_register would be replaced by
> kobject_create_and_add, and the uevent handling would be separated
> from original create_and_register onefunction.
> 
> wait for greg's patches or modify to use:
> 
> kobject_init
> kobject_add
> kobject_uevent
> 
> BTW, I suspect whether the uevent is really needed for boot_params object.

Oh, if you want, I'd be glad to add this to my tree as I am messing with
the kobject API a lot and I don't mind keeping it with the other kobject
patches so that it is known to work properly :)

Just forward it on to me if you want me to fix it up and add it to my
tree.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-12-12  6:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-11 16:49 [PATCH -mm] x86 boot : export boot_params via sysfs Huang, Ying
2007-12-12  2:40 ` Andrew Morton
2007-12-12  4:42   ` Dave Young
2007-12-12  6:55     ` Greg KH
2007-12-12  6:56     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox