linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* /proc/residual (CONFIG_PREP_PROCRESIDUAL)
@ 2002-01-28 16:08 Tom Rini
  2002-01-29 16:08 ` Leigh Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Rini @ 2002-01-28 16:08 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: hollis, Sven Dickert, Leigh Brown


Hey all.  Here's a version of the /proc/residual patch (originally by
David Monro, updated for 2.4 by Sven Dickert) vs current 2_4_devel.
This is slightly different than the previous versions that've been
floating around:
1) It can't be a module now.  After talking to Al Viro, doing /proc
stuff in a module correctly is a giant PITA (it wasn't working in the
previous versions I don't think...)
2) Use __initcall() instead of editing fs/proc/root.c.  This should make
it easier to run past Marcelo/Linus, since it only touches PPC-specific
things (and the help file).
3) I cleaned up the DPRINTK() macros slightly in a few places.

In some quick testing on my machine, I always got the same image file
(md5'ed).  Can a few more people try this and make sure it still works
for them?  Thanks.

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/

===== Documentation/Configure.help 1.109 vs edited =====
--- 1.109/Documentation/Configure.help	Wed Jan 23 18:06:24 2002
+++ edited/Documentation/Configure.help	Mon Jan 28 08:25:59 2002
@@ -14413,6 +14413,14 @@
   Unless you expect to boot on a PReP system, there is not need to
   select Y.

+PReP residual data avaiable in /proc/residual
+CONFIG_PROC_PREPRESIDUAL
+  Enabling this option will create a /proc/residual file which allows
+  you to get at the residual data on PReP systems (the data the firmware
+  passes to the kernel describing the system. You will need a tool
+  (lsresidual) to parse it. If you aren't on a PReP system, you don't
+  want this. It is also available as a module (prep_residual.o).
+
 /dev file system support
 CONFIG_DEVFS_FS
   This is support for devfs, a virtual file system (like /proc) which
===== arch/ppc/config.in 1.114 vs edited =====
--- 1.114/arch/ppc/config.in	Sun Jan 20 13:30:26 2002
+++ edited/arch/ppc/config.in	Mon Jan 28 08:25:59 2002
@@ -393,6 +393,7 @@
   bool 'Support for Open Firmware device tree in /proc' CONFIG_PROC_DEVICETREE
   bool 'Support for RTAS (RunTime Abstraction Services) in /proc' CONFIG_PPC_RTAS
   bool 'Support for PReP Residual Data' CONFIG_PREP_RESIDUAL
+  dep_bool '  Support for reading of PReP Residual data in /proc' CONFIG_PROC_PREPRESIDUAL $CONFIG_PREP_RESIDUAL
 fi

 bool 'Default bootloader kernel arguments' CONFIG_CMDLINE_BOOL
===== arch/ppc/platforms/Makefile 1.15 vs edited =====
--- 1.15/arch/ppc/platforms/Makefile	Sat Jan 26 17:32:42 2002
+++ edited/arch/ppc/platforms/Makefile	Mon Jan 28 08:26:25 2002
@@ -49,6 +49,7 @@
 obj-$(CONFIG_PMAC_PBOOK)	+= sleep.o
 obj-$(CONFIG_PPC_RTAS)		+= error_log.o proc_rtas.o
 obj-$(CONFIG_PREP_RESIDUAL)	+= residual.o
+obj-$(CONFIG_PROC_PREPRESIDUAL)	+= prep_procresidual.o
 obj-$(CONFIG_ADIR)		+= adir_setup.o adir_pic.o adir_pci.o
 obj-$(CONFIG_EV64260)		+= ev64260_setup.o
 obj-$(CONFIG_GEMINI)		+= gemini_pci.o gemini_setup.o gemini_prom.o
--- a/dev/null	Wed Dec 31 17:00:00 1969
+++ b/arch/ppc/platforms/prep_procresidual.c	Mon Jan 28 08:25:59 2002
@@ -0,0 +1,105 @@
+/*
+ *  linux/arch/ppc/platforms/prep_procresidual.c
+ *
+ *  Copyright (C) 2000 by David Monro
+ *  Ported to linux 2.4 by Sven Dickert 2001
+ *  Additional cleanups by Tom Rini, Jan 26 2002.
+ *
+ */
+
+#include <linux/types.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/proc_fs.h>
+#include <linux/init.h>
+
+#include <asm/residual.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+
+#undef DEBUG
+
+#ifdef DEBUG
+#define DPRINTK(x...) printk(x)
+#else
+#define DPRINTK(x...)
+#endif
+
+static int
+prep_residual_open(struct inode *inode, struct file *file)
+{
+	if (res->ResidualLength == 0)
+		return -ENOENT;
+
+	DPRINTK("/proc/residual opened\n");
+
+	return 0;
+}
+
+static int
+prep_residual_release(struct inode *inode, struct file *file)
+{
+	if (res->ResidualLength == 0)
+		return -ENOENT;
+
+	DPRINTK("/proc/residual released\n");
+
+	return 0;
+}
+
+static ssize_t
+prep_residual_read(struct file *file, char *buf, size_t count, loff_t * ppos)
+{
+	int retval;
+	int rlen = res->ResidualLength;
+	int offset = *ppos;
+
+	DPRINTK("prep_residual_read called, offset = %d\n", offset);
+
+	/* Make sure we're have something to do, and are called correctly */
+	if (!count)
+		return 0;
+	else if (rlen == 0)
+		retval = -ENOENT;
+	else if (!buf || count < 0)
+		retval = -EINVAL;
+	else
+		retval = verify_area(VERIFY_WRITE, buf, count);
+
+	if (retval)
+		return retval;
+
+	if ((count + offset) > rlen)
+		count = rlen - offset;
+
+	copy_to_user(buf, ((char *) res) + offset, count);
+	*ppos += count;
+
+	return count;
+}
+
+static struct file_operations proc_prep_residual_operations = {
+	read:prep_residual_read,
+	open:prep_residual_open,
+	release:prep_residual_release,
+};
+
+struct proc_dir_entry *entry;
+
+int __init
+prep_procresidual_init(void)
+{
+	DPRINTK("Registering /proc/residual... ");
+
+	entry = create_proc_entry("residual", S_IFREG | S_IRUGO, &proc_root);
+
+	if (entry)
+		entry->proc_fops = &proc_prep_residual_operations;
+	else
+		return -EAGAIN;
+
+	return 0;
+}
+
+__initcall(prep_procresidual_init);

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

* Re: /proc/residual (CONFIG_PREP_PROCRESIDUAL)
  2002-01-28 16:08 /proc/residual (CONFIG_PREP_PROCRESIDUAL) Tom Rini
@ 2002-01-29 16:08 ` Leigh Brown
  2002-01-29 16:56   ` hollis
  0 siblings, 1 reply; 7+ messages in thread
From: Leigh Brown @ 2002-01-29 16:08 UTC (permalink / raw)
  To: Tom Rini; +Cc: linuxppc-dev, hollis, Sven Dickert


Tom,

On Mon, 28 Jan 2002, Tom Rini wrote:

> Hey all.  Here's a version of the /proc/residual patch (originally by
> David Monro, updated for 2.4 by Sven Dickert) vs current 2_4_devel.
> This is slightly different than the previous versions that've been
> floating around:
> 1) It can't be a module now.  After talking to Al Viro, doing /proc
> stuff in a module correctly is a giant PITA (it wasn't working in the
> previous versions I don't think...)
> 2) Use __initcall() instead of editing fs/proc/root.c.  This should make
> it easier to run past Marcelo/Linus, since it only touches PPC-specific
> things (and the help file).
> 3) I cleaned up the DPRINTK() macros slightly in a few places.
>
> In some quick testing on my machine, I always got the same image file
> (md5'ed).  Can a few more people try this and make sure it still works
> for them?  Thanks.

[...]

It works for me.  The comment needs to be changed to say it can't be a
module.  I've attached the version I came up with, mainly because I went
to some trouble to do it.  Differences:

1. Stuck on the end of residual.c 'coz it's hardly worth it's own file
2. Remove #ifdef __KERNEL__ from header file for use space utility
3. Use create_proc_read_entry 'coz it's simpler (which is best, I dunno?)
4. Only create entry if residual size > 0 'coz what you can't see won't
   hurt you + eliminate chance of people wondering why they are getting an
   error trying to read it.
5. Fix a couple of typos

Cheers,

Leigh.



diff -uNr -X /home/leigh/.diffex MASTER/linuxppc_2_4_devel/Documentation/Configure.help linuxppc_2_4_devel-140/Documentation/Configure.help
--- MASTER/linuxppc_2_4_devel/Documentation/Configure.help	Mon Jan 28 20:27:49 2002
+++ linuxppc_2_4_devel-140/Documentation/Configure.help	Tue Jan 29 12:54:59 2002
@@ -14410,8 +14410,15 @@
   other useful pieces of information.  Sometimes this information is
   not present or incorrect.

-  Unless you expect to boot on a PReP system, there is not need to
+  Unless you expect to boot on a PReP system, there is no need to
   select Y.
+
+PReP residual data available in /proc/residual
+CONFIG_PROC_PREPRESIDUAL
+  Enabling this option will create a /proc/residual file which allows
+  you to get at the residual data on PReP systems.  You will need a tool
+  (lsresidual) to parse it.  If you aren't on a PReP system, you don't
+  want this.

 /dev file system support
 CONFIG_DEVFS_FS
diff -uNr -X /home/leigh/.diffex MASTER/linuxppc_2_4_devel/arch/ppc/config.in linuxppc_2_4_devel-140/arch/ppc/config.in
--- MASTER/linuxppc_2_4_devel/arch/ppc/config.in	Mon Jan 28 20:24:43 2002
+++ linuxppc_2_4_devel-140/arch/ppc/config.in	Tue Jan 29 12:53:56 2002
@@ -393,6 +393,7 @@
   bool 'Support for Open Firmware device tree in /proc' CONFIG_PROC_DEVICETREE
   bool 'Support for RTAS (RunTime Abstraction Services) in /proc' CONFIG_PPC_RTAS
   bool 'Support for PReP Residual Data' CONFIG_PREP_RESIDUAL
+  dep_bool '  Support for reading of PReP Residual Data in /proc' CONFIG_PROC_PREPRESIDUAL $CONFIG_PREP_RESIDUAL
 fi

 bool 'Default bootloader kernel arguments' CONFIG_CMDLINE_BOOL
diff -uNr -X /home/leigh/.diffex MASTER/linuxppc_2_4_devel/arch/ppc/platforms/residual.c linuxppc_2_4_devel-140/arch/ppc/platforms/residual.c
--- MASTER/linuxppc_2_4_devel/arch/ppc/platforms/residual.c	Mon Jan 28 20:26:53 2002
+++ linuxppc_2_4_devel-140/arch/ppc/platforms/residual.c	Tue Jan 29 12:45:32 2002
@@ -876,3 +876,38 @@
 	};
 	return 0; /* not found */
 }
+
+#ifdef CONFIG_PROC_PREPRESIDUAL
+static int proc_prep_residual_read(char * buf, char ** start, off_t off,
+		int count, int *eof, void *data)
+{
+	int n;
+
+	n = res->ResidualLength - off;
+	if (n < 0) {
+		*eof = 1;
+		n = 0;
+	}
+	else {
+		if (n > count)
+			n = count;
+		else
+			*eof = 1;
+
+		memcpy(buf, (char *)res + off, n);
+		*start = buf;
+	}
+
+	return n;
+}
+
+void __init
+proc_prep_residual_init(void)
+{
+	if (res->ResidualLength)
+		create_proc_read_entry("residual", S_IRUGO, NULL,
+					proc_prep_residual_read, NULL);
+}
+
+__initcall(proc_prep_residual_init);
+#endif
diff -uNr -X /home/leigh/.diffex MASTER/linuxppc_2_4_devel/include/asm-ppc/residual.h linuxppc_2_4_devel-140/include/asm-ppc/residual.h
--- MASTER/linuxppc_2_4_devel/include/asm-ppc/residual.h	Mon Jan 28 20:27:37 2002
+++ linuxppc_2_4_devel-140/include/asm-ppc/residual.h	Tue Jan 29 12:47:50 2002
@@ -13,7 +13,6 @@
 /*             i.e. only one bit is on for each enum                          */
 /* Reserved fields must be filled with zeros.                                */

-#ifdef __KERNEL__
 #ifndef _RESIDUAL_
 #define _RESIDUAL_

@@ -334,4 +333,3 @@
 #endif /* __ASSEMBLY__ */
 #endif  /* ndef _RESIDUAL_ */

-#endif /* __KERNEL__ */


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

* Re: /proc/residual (CONFIG_PREP_PROCRESIDUAL)
  2002-01-29 16:08 ` Leigh Brown
@ 2002-01-29 16:56   ` hollis
  2002-01-29 21:47     ` Leigh Brown
  0 siblings, 1 reply; 7+ messages in thread
From: hollis @ 2002-01-29 16:56 UTC (permalink / raw)
  To: Leigh Brown; +Cc: linuxppc-dev, Sven Dickert


On Tue, Jan 29, 2002 at 04:08:43PM +0000, Leigh Brown wrote:
>
> It works for me.  The comment needs to be changed to say it can't be a
> module.  I've attached the version I came up with, mainly because I went
> to some trouble to do it.  Differences:
>
> 2. Remove #ifdef __KERNEL__ from header file for use space utility

This encourages user applications to include kernel header files, which has
been deemed ungood. I believe there should be many lengthy threads on the
subject in the lkml archives, but more practically speaking Paul has said he'd
be perfectly happy if all kernel headers were completely protected from user
space.

> 4. Only create entry if residual size > 0 'coz what you can't see won't
>    hurt you + eliminate chance of people wondering why they are getting an
>    error trying to read it.

I don't like that, because it leaves you wondering if you compiled in residual
support at all... I'd much rather have it be 0 length.

-Hollis

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

* Re: /proc/residual (CONFIG_PREP_PROCRESIDUAL)
  2002-01-29 16:56   ` hollis
@ 2002-01-29 21:47     ` Leigh Brown
  2002-01-29 22:03       ` Tom Rini
  0 siblings, 1 reply; 7+ messages in thread
From: Leigh Brown @ 2002-01-29 21:47 UTC (permalink / raw)
  To: hollis; +Cc: linuxppc-dev, Sven Dickert


Hollis,

On Tue, 29 Jan 2002 hollis@austin.ibm.com wrote:

> On Tue, Jan 29, 2002 at 04:08:43PM +0000, Leigh Brown wrote:
> >
> > It works for me.  The comment needs to be changed to say it can't be a
> > module.  I've attached the version I came up with, mainly because I went
> > to some trouble to do it.  Differences:
> >
> > 2. Remove #ifdef __KERNEL__ from header file for use space utility
>
> This encourages user applications to include kernel header files, which has
> been deemed ungood. I believe there should be many lengthy threads on the
> subject in the lkml archives, but more practically speaking Paul has said he'd
> be perfectly happy if all kernel headers were completely protected from user
> space.

Surely that can't be true.  What about asm/errno.h?  I thought you just
put #ifdef __KERNEL__ around stuff you don't want to export to user space.
In the case of asm/residual.h it all needs to be exported to user space.
The alternative is to simply clone the file, which seems a bit silly.

> > 4. Only create entry if residual size > 0 'coz what you can't see won't
> >    hurt you + eliminate chance of people wondering why they are getting an
> >    error trying to read it.
>
> I don't like that, because it leaves you wondering if you compiled in residual
> support at all... I'd much rather have it be 0 length.

Okay.  I think the best behaviour is to simply return 0 bytes if there
is no residual data and let lsresidual interpret that as being no
residual data.

Cheers,

Leigh.


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

* Re: /proc/residual (CONFIG_PREP_PROCRESIDUAL)
  2002-01-29 21:47     ` Leigh Brown
@ 2002-01-29 22:03       ` Tom Rini
  2002-01-30 20:47         ` Leigh Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Rini @ 2002-01-29 22:03 UTC (permalink / raw)
  To: Leigh Brown; +Cc: hollis, linuxppc-dev, Sven Dickert


On Tue, Jan 29, 2002 at 09:47:02PM +0000, Leigh Brown wrote:

> On Tue, 29 Jan 2002 hollis@austin.ibm.com wrote:
>
> > On Tue, Jan 29, 2002 at 04:08:43PM +0000, Leigh Brown wrote:
> > >
> > > It works for me.  The comment needs to be changed to say it can't be a
> > > module.  I've attached the version I came up with, mainly because I went
> > > to some trouble to do it.  Differences:
> > >
> > > 2. Remove #ifdef __KERNEL__ from header file for use space utility
> >
> > This encourages user applications to include kernel header files, which has
> > been deemed ungood. I believe there should be many lengthy threads on the
> > subject in the lkml archives, but more practically speaking Paul has said he'd
> > be perfectly happy if all kernel headers were completely protected from user
> > space.
>
> Surely that can't be true.  What about asm/errno.h?  I thought you just
> put #ifdef __KERNEL__ around stuff you don't want to export to user space.
> In the case of asm/residual.h it all needs to be exported to user space.
> The alternative is to simply clone the file, which seems a bit silly.

There's a few legacy files which unfortunatly can't be clamped down on.
In general you are supposed to copy the file and be done with it.  In
fact, if I ever wanted to read the residual image from my PReP box
(usually off) on my x86 (which I'm typing on right now), I'd need to do
this anyways since x86 won't have '<asm/residual.h>'.

> > > 4. Only create entry if residual size > 0 'coz what you can't see won't
> > >    hurt you + eliminate chance of people wondering why they are getting an
> > >    error trying to read it.
> >
> > I don't like that, because it leaves you wondering if you compiled in residual
> > support at all... I'd much rather have it be 0 length.
>
> Okay.  I think the best behaviour is to simply return 0 bytes if there
> is no residual data and let lsresidual interpret that as being no
> residual data.

If we don't have any residual data, shouldn't we be returning a 0 byte
file anyhow?  I didn't explicitly test this, but in the original version
I got from Sven/Hollis, no residual data gave me an empty
/proc/residual.

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

* Re: /proc/residual (CONFIG_PREP_PROCRESIDUAL)
  2002-01-30 20:47         ` Leigh Brown
@ 2002-01-30 20:41           ` Tom Rini
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2002-01-30 20:41 UTC (permalink / raw)
  To: Leigh Brown; +Cc: hollis, linuxppc-dev, Sven Dickert


On Wed, Jan 30, 2002 at 08:47:46PM +0000, Leigh Brown wrote:

> On Tue, 29 Jan 2002, Tom Rini wrote:
>
> > On Tue, Jan 29, 2002 at 09:47:02PM +0000, Leigh Brown wrote:
> >
> > > On Tue, 29 Jan 2002 hollis@austin.ibm.com wrote:
> > >
> > > > On Tue, Jan 29, 2002 at 04:08:43PM +0000, Leigh Brown wrote:
> [...]
> > > > > 2. Remove #ifdef __KERNEL__ from header file for use space utility
> > > >
> > > > This encourages user applications to include kernel header files, which has
> > > > been deemed ungood. I believe there should be many lengthy threads on the
> > > > subject in the lkml archives, but more practically speaking Paul has said he'd
> > > > be perfectly happy if all kernel headers were completely protected from user
> > > > space.
> > >
> > > Surely that can't be true.  What about asm/errno.h?  I thought you just
> > > put #ifdef __KERNEL__ around stuff you don't want to export to user space.
> > > In the case of asm/residual.h it all needs to be exported to user space.
> > > The alternative is to simply clone the file, which seems a bit silly.
> >
> > There's a few legacy files which unfortunatly can't be clamped down on.
> > In general you are supposed to copy the file and be done with it.  In
> > fact, if I ever wanted to read the residual image from my PReP box
> > (usually off) on my x86 (which I'm typing on right now), I'd need to do
> > this anyways since x86 won't have '<asm/residual.h>'.
>
> That's a fairly contrived example but I'm not going to argue.  I'm
> amending lsresidual to use a local copy of any kernel headers it needs
> (plus making it endian safe so that you really can see your residual data
> on your x86 box :-)

heh.  Well the better example is stuff like atomic ops, which on some
arches can only be done in kernel-space. :)

> > > > > 4. Only create entry if residual size > 0 'coz what you can't see won't
> > > > >    hurt you + eliminate chance of people wondering why they are getting an
> > > > >    error trying to read it.
> > > >
> > > > I don't like that, because it leaves you wondering if you compiled in residual
> > > > support at all... I'd much rather have it be 0 length.
> > >
> > > Okay.  I think the best behaviour is to simply return 0 bytes if there
> > > is no residual data and let lsresidual interpret that as being no
> > > residual data.
> >
> > If we don't have any residual data, shouldn't we be returning a 0 byte
> > file anyhow?  I didn't explicitly test this, but in the original version
> > I got from Sven/Hollis, no residual data gave me an empty
> > /proc/residual.
>
> The original may have, but the one you posted doesn't:
>
> +static int prep_residual_open(struct inode * inode, struct file * file)
> +{
> +	if (res->ResidualLength == 0) {
> +		return -ENOENT;
> +	}
> +	DPRINTK("/proc/residual opened\n");
> +	MOD_INC_USE_COUNT;
> +	return 0;
> +}
>
> The above will cause the open to fail if no residual data is present.
> I've attached an updated version of my patch that has the required
> behaviour (based on what you and Hollis have said).

Er, I think this is the desired output.  dd, et al will give an empty
file and things checking more througly will/can give a proper error msg.
Sorry for the confusion :)

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

* Re: /proc/residual (CONFIG_PREP_PROCRESIDUAL)
  2002-01-29 22:03       ` Tom Rini
@ 2002-01-30 20:47         ` Leigh Brown
  2002-01-30 20:41           ` Tom Rini
  0 siblings, 1 reply; 7+ messages in thread
From: Leigh Brown @ 2002-01-30 20:47 UTC (permalink / raw)
  To: Tom Rini; +Cc: hollis, linuxppc-dev, Sven Dickert


Tom,

On Tue, 29 Jan 2002, Tom Rini wrote:

> On Tue, Jan 29, 2002 at 09:47:02PM +0000, Leigh Brown wrote:
>
> > On Tue, 29 Jan 2002 hollis@austin.ibm.com wrote:
> >
> > > On Tue, Jan 29, 2002 at 04:08:43PM +0000, Leigh Brown wrote:
[...]
> > > > 2. Remove #ifdef __KERNEL__ from header file for use space utility
> > >
> > > This encourages user applications to include kernel header files, which has
> > > been deemed ungood. I believe there should be many lengthy threads on the
> > > subject in the lkml archives, but more practically speaking Paul has said he'd
> > > be perfectly happy if all kernel headers were completely protected from user
> > > space.
> >
> > Surely that can't be true.  What about asm/errno.h?  I thought you just
> > put #ifdef __KERNEL__ around stuff you don't want to export to user space.
> > In the case of asm/residual.h it all needs to be exported to user space.
> > The alternative is to simply clone the file, which seems a bit silly.
>
> There's a few legacy files which unfortunatly can't be clamped down on.
> In general you are supposed to copy the file and be done with it.  In
> fact, if I ever wanted to read the residual image from my PReP box
> (usually off) on my x86 (which I'm typing on right now), I'd need to do
> this anyways since x86 won't have '<asm/residual.h>'.

That's a fairly contrived example but I'm not going to argue.  I'm
amending lsresidual to use a local copy of any kernel headers it needs
(plus making it endian safe so that you really can see your residual data
on your x86 box :-)

> > > > 4. Only create entry if residual size > 0 'coz what you can't see won't
> > > >    hurt you + eliminate chance of people wondering why they are getting an
> > > >    error trying to read it.
> > >
> > > I don't like that, because it leaves you wondering if you compiled in residual
> > > support at all... I'd much rather have it be 0 length.
> >
> > Okay.  I think the best behaviour is to simply return 0 bytes if there
> > is no residual data and let lsresidual interpret that as being no
> > residual data.
>
> If we don't have any residual data, shouldn't we be returning a 0 byte
> file anyhow?  I didn't explicitly test this, but in the original version
> I got from Sven/Hollis, no residual data gave me an empty
> /proc/residual.

The original may have, but the one you posted doesn't:

+static int prep_residual_open(struct inode * inode, struct file * file)
+{
+	if (res->ResidualLength == 0) {
+		return -ENOENT;
+	}
+	DPRINTK("/proc/residual opened\n");
+	MOD_INC_USE_COUNT;
+	return 0;
+}

The above will cause the open to fail if no residual data is present.
I've attached an updated version of my patch that has the required
behaviour (based on what you and Hollis have said).

Cheers,

Leigh.



diff -uNr -X /home/leigh/.diffex MASTER/linuxppc_2_4_devel/Documentation/Configure.help linuxppc_2_4_devel-140/Documentation/Configure.help
--- MASTER/linuxppc_2_4_devel/Documentation/Configure.help	Mon Jan 28 20:27:49 2002
+++ linuxppc_2_4_devel-140/Documentation/Configure.help	Tue Jan 29 12:54:59 2002
@@ -14410,8 +14410,15 @@
   other useful pieces of information.  Sometimes this information is
   not present or incorrect.

-  Unless you expect to boot on a PReP system, there is not need to
+  Unless you expect to boot on a PReP system, there is no need to
   select Y.
+
+PReP residual data available in /proc/residual
+CONFIG_PROC_PREPRESIDUAL
+  Enabling this option will create a /proc/residual file which allows
+  you to get at the residual data on PReP systems.  You will need a tool
+  (lsresidual) to parse it.  If you aren't on a PReP system, you don't
+  want this.

 /dev file system support
 CONFIG_DEVFS_FS
diff -uNr -X /home/leigh/.diffex MASTER/linuxppc_2_4_devel/arch/ppc/config.in linuxppc_2_4_devel-140/arch/ppc/config.in
--- MASTER/linuxppc_2_4_devel/arch/ppc/config.in	Mon Jan 28 20:24:43 2002
+++ linuxppc_2_4_devel-140/arch/ppc/config.in	Tue Jan 29 12:53:56 2002
@@ -393,6 +393,7 @@
   bool 'Support for Open Firmware device tree in /proc' CONFIG_PROC_DEVICETREE
   bool 'Support for RTAS (RunTime Abstraction Services) in /proc' CONFIG_PPC_RTAS
   bool 'Support for PReP Residual Data' CONFIG_PREP_RESIDUAL
+  dep_bool '  Support for reading of PReP Residual Data in /proc' CONFIG_PROC_PREPRESIDUAL $CONFIG_PREP_RESIDUAL
 fi

 bool 'Default bootloader kernel arguments' CONFIG_CMDLINE_BOOL
diff -uNr -X /home/leigh/.diffex MASTER/linuxppc_2_4_devel/arch/ppc/platforms/residual.c linuxppc_2_4_devel-140/arch/ppc/platforms/residual.c
--- MASTER/linuxppc_2_4_devel/arch/ppc/platforms/residual.c	Mon Jan 28 20:26:53 2002
+++ linuxppc_2_4_devel-140/arch/ppc/platforms/residual.c	Tue Jan 29 20:22:32 2002
@@ -876,3 +876,37 @@
 	};
 	return 0; /* not found */
 }
+
+#ifdef CONFIG_PROC_PREPRESIDUAL
+static int proc_prep_residual_read(char * buf, char ** start, off_t off,
+		int count, int *eof, void *data)
+{
+	int n;
+
+	n = res->ResidualLength - off;
+	if (n < 0) {
+		*eof = 1;
+		n = 0;
+	}
+	else {
+		if (n > count)
+			n = count;
+		else
+			*eof = 1;
+
+		memcpy(buf, (char *)res + off, n);
+		*start = buf;
+	}
+
+	return n;
+}
+
+void __init
+proc_prep_residual_init(void)
+{
+	create_proc_read_entry("residual", S_IRUGO, NULL,
+				proc_prep_residual_read, NULL);
+}
+
+__initcall(proc_prep_residual_init);
+#endif


** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

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

end of thread, other threads:[~2002-01-30 20:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-01-28 16:08 /proc/residual (CONFIG_PREP_PROCRESIDUAL) Tom Rini
2002-01-29 16:08 ` Leigh Brown
2002-01-29 16:56   ` hollis
2002-01-29 21:47     ` Leigh Brown
2002-01-29 22:03       ` Tom Rini
2002-01-30 20:47         ` Leigh Brown
2002-01-30 20:41           ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).