diff mbox

[3/3] of: Handle memory@0 node on PPC32 only

Message ID 20140423131058.D94B6C408D2@trevor.secretlab.ca
State New
Headers show

Commit Message

Grant Likely April 23, 2014, 1:10 p.m. UTC
On Wed, 23 Apr 2014 11:45:28 +0100, Mark Rutland <mark.rutland@arm.com> wrote:
> On Tue, Apr 22, 2014 at 02:35:15PM +0100, Grant Likely wrote:
> > On Fri, 18 Apr 2014 13:59:24 +0100, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> > > Hi Geert,
> > > 
> > > On Fri, Apr 18, 2014 at 10:04:15AM +0200, Geert Uytterhoeven wrote:
> > > > On Thu, Apr 17, 2014 at 7:42 PM, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> > > > > In order to deal with an firmware bug on a specific ppc32 platform
> > > > > (longtrail), early_init_dt_scan_memory() looks for a node called
> > > > > memory@0 on all platforms. Restrict this quirk to ppc32 kernels only.
> > > > 
> > > > This breaks backwards compatibilty with old DTSes (at least on ARM/MIPS,
> > > > where you added the missing property in patches 1 and 2 of the series)?
> > > 
> > > As Rob said in response to 0/3, the MIPSs would likely not be affected,
> > > since they embed the DT.
> > > 
> > > > For the Longtrail, I don't care much anymore, as mine died in 2004.
> > > > AFAIK, there have never been many users anyway.
> > > 
> > > There are still a few mentions of it under arch/powerpc/, so I wouldn't
> > > want to be the one to kill it off...
> > > 
> > > How about the below v2 3/3 to address the ARM platform?
> > 
> > The problem with this approach is that selecting one board that needs it
> > automatically makes it active for all boards. It would need to be
> > something more like the following:
> > 
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index 399e242e1a42..55d65b2b4c74 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -887,12 +887,10 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
> >  
> >  	/* We are scanning "memory" nodes only */
> >  	if (type == NULL) {
> > -		/*
> > -		 * The longtrail doesn't have a device_type on the
> > -		 * /memory node, so look for the node called /memory@0.
> > -		 */
> >  		if (depth != 1 || strcmp(uname, "memory@0") != 0)
> >  			return 0;
> > +		if (!of_flat_dt_match(dt_root, memory_quirk_list))
> > +			return 0;
> >  	} else if (strcmp(type, "memory") != 0)
> >  		return 0;
> >  
> > With a list of compatible properties for affected boards.
> 
> That looks sane to me.
> 
> Does anyone have a LongTrail DT to hand, and if so does the root have a
> compatible string? From grepping through the kernel I could only find a
> model string ("IBM,LongTrail").

Actually, on LongTrail this can be removed from the common code
entirely. It has real open firmware and PowerPC already has the
infrastructure for fixing up the device tree.

Here's a draft patch that I've compile tested, but nothing else.

g.

---

Comments

Leif Lindholm April 24, 2014, 9:26 a.m. UTC | #1
On Wed, Apr 23, 2014 at 02:10:58PM +0100, Grant Likely wrote:
> > Does anyone have a LongTrail DT to hand, and if so does the root have a
> > compatible string? From grepping through the kernel I could only find a
> > model string ("IBM,LongTrail").
> 
> Actually, on LongTrail this can be removed from the common code
> entirely. It has real open firmware and PowerPC already has the
> infrastructure for fixing up the device tree.
> 
> Here's a draft patch that I've compile tested, but nothing else.

I would certainly be happy with that.

Consider my 3/3 withdrawn.

And if the kernel proper will stop honoring nodes with no type,
there is no need for the stub to treat those specially either.

/
    Leif

> g.
> 
> ---
> 
> diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
> index 078145acf7fb..18b2c3fee98f 100644
> --- a/arch/powerpc/kernel/prom_init.c
> +++ b/arch/powerpc/kernel/prom_init.c
> @@ -2587,9 +2587,18 @@ static void __init fixup_device_tree_chrp(void)
>  	phandle ph;
>  	u32 prop[6];
>  	u32 rloc = 0x01006000; /* IO space; PCI device = 12 */
> -	char *name;
> +	char *name, strprop[16];
>  	int rc;
>  
> +	/* Deal with missing device_type in LongTrail memory node */
> +	name = "/memory@0";
> +	ph = call_prom("finddevice", 1, 1, ADDR(name));
> +	rc = prom_getprop(ph, "device_type", strprop, sizeof(strprop));
> +	if (rc == PROM_ERROR || strcmp(strprop, "memory") != 0) {
> +		prom_printf("Fixing up missing device_type on /memory@0 node...\n");
> +		prom_setprop(ph, name, "device_type", "memory", sizeof("memory"));
> +	}
> +
>  	name = "/pci@80000000/isa@c";
>  	ph = call_prom("finddevice", 1, 1, ADDR(name));
>  	if (!PHANDLE_VALID(ph)) {
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index 7a2ef7bb8022..7cda0d279cbe 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -886,14 +886,7 @@ int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
>  	unsigned long l;
>  
>  	/* We are scanning "memory" nodes only */
> -	if (type == NULL) {
> -		/*
> -		 * The longtrail doesn't have a device_type on the
> -		 * /memory node, so look for the node called /memory@0.
> -		 */
> -		if (depth != 1 || strcmp(uname, "memory@0") != 0)
> -			return 0;
> -	} else if (strcmp(type, "memory") != 0)
> +	if (!type || strcmp(type, "memory") != 0)
>  		return 0;
>  
>  	reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);
>
Grant Likely May 15, 2014, 2:59 p.m. UTC | #2
On Thu, 24 Apr 2014 10:26:42 +0100, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> On Wed, Apr 23, 2014 at 02:10:58PM +0100, Grant Likely wrote:
> > > Does anyone have a LongTrail DT to hand, and if so does the root have a
> > > compatible string? From grepping through the kernel I could only find a
> > > model string ("IBM,LongTrail").
> > 
> > Actually, on LongTrail this can be removed from the common code
> > entirely. It has real open firmware and PowerPC already has the
> > infrastructure for fixing up the device tree.
> > 
> > Here's a draft patch that I've compile tested, but nothing else.
> 
> I would certainly be happy with that.
> 
> Consider my 3/3 withdrawn.
> 
> And if the kernel proper will stop honoring nodes with no type,
> there is no need for the stub to treat those specially either.

So, after thinking about it some more, I've changed my minde about the
whole thing again. The impact is quite contained because there weren't a
lot of systems that had ram based at 0. I'm going to commit this patch,
but I'll include a note in the commit text that if it causes trouble for
anyone that they should yell and I'll revert it. I don't think it will
though.

g.
diff mbox

Patch

diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 078145acf7fb..18b2c3fee98f 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -2587,9 +2587,18 @@  static void __init fixup_device_tree_chrp(void)
 	phandle ph;
 	u32 prop[6];
 	u32 rloc = 0x01006000; /* IO space; PCI device = 12 */
-	char *name;
+	char *name, strprop[16];
 	int rc;
 
+	/* Deal with missing device_type in LongTrail memory node */
+	name = "/memory@0";
+	ph = call_prom("finddevice", 1, 1, ADDR(name));
+	rc = prom_getprop(ph, "device_type", strprop, sizeof(strprop));
+	if (rc == PROM_ERROR || strcmp(strprop, "memory") != 0) {
+		prom_printf("Fixing up missing device_type on /memory@0 node...\n");
+		prom_setprop(ph, name, "device_type", "memory", sizeof("memory"));
+	}
+
 	name = "/pci@80000000/isa@c";
 	ph = call_prom("finddevice", 1, 1, ADDR(name));
 	if (!PHANDLE_VALID(ph)) {
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 7a2ef7bb8022..7cda0d279cbe 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -886,14 +886,7 @@  int __init early_init_dt_scan_memory(unsigned long node, const char *uname,
 	unsigned long l;
 
 	/* We are scanning "memory" nodes only */
-	if (type == NULL) {
-		/*
-		 * The longtrail doesn't have a device_type on the
-		 * /memory node, so look for the node called /memory@0.
-		 */
-		if (depth != 1 || strcmp(uname, "memory@0") != 0)
-			return 0;
-	} else if (strcmp(type, "memory") != 0)
+	if (!type || strcmp(type, "memory") != 0)
 		return 0;
 
 	reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l);