All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-11-25 18:46 ` Curt Brune
  0 siblings, 0 replies; 14+ messages in thread
From: Curt Brune @ 2015-11-25 18:46 UTC (permalink / raw)
  To: galak-sgV2jX0FEOL9JmXXK+q4OQ,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg, mark.rutland-5wv7dgnIgG8,
	pawel.moll-5wv7dgnIgG8, benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r,
	paulus-eUNUBHrolfbYtjvyW6yDsg, mpe-Gsx/Oe8HsFggBc27wqDAHg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A
  Cc: linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ, devicetree-u79uwXL29TY76Z2rM5mHXA

Currently for PowerPC systems using device tree, the legacy serial
ports are allocated in the order by which they are found in the device
tree structure.

This can cause problems in cases where the device tree nodes are
sysnthesized by an external program (kexec for example), which may not
preserve the original order of the device tree nodes.  This in turn
can result in the serial console changing from ttyS0 to ttyS1
unexpectedly.

This patch uses the 'cell-index' property (if present) to map UART
device tree nodes to legacy serial port number.  The cell-index
property is widely used in all the Freescale .dts files for PowerPC.

Signed-off-by: Curt Brune <curt-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
---
 arch/powerpc/kernel/legacy_serial.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index 7b750c4..b717133 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -164,6 +164,8 @@ static int __init add_legacy_soc_port(struct device_node *np,
 	u64 addr;
 	const __be32 *addrp;
 	struct device_node *tsi = of_get_parent(np);
+	int index = -1, len;
+	u32 *indexp;
 
 	/* We only support ports that have a clock frequency properly
 	 * encoded in the device-tree.
@@ -188,14 +190,19 @@ static int __init add_legacy_soc_port(struct device_node *np,
 	if (addr == OF_BAD_ADDR)
 		return -1;
 
+	/* Check if the ports have an ordering, defined by 'cell-index' */
+	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) != NULL) &&
+	    (len == sizeof(u32)))
+		index = *indexp;
+
 	/* Add port, irq will be dealt with later. We passed a translated
 	 * IO port value. It will be fixed up later along with the irq
 	 */
 	if (tsi && !strcmp(tsi->type, "tsi-bridge"))
-		return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
+		return add_legacy_port(np, index, UPIO_TSI, addr, addr,
 				       NO_IRQ, legacy_port_flags, 0);
 	else
-		return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
+		return add_legacy_port(np, index, UPIO_MEM, addr, addr,
 				       NO_IRQ, legacy_port_flags, 0);
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-11-25 18:46 ` Curt Brune
  0 siblings, 0 replies; 14+ messages in thread
From: Curt Brune @ 2015-11-25 18:46 UTC (permalink / raw)
  To: galak, ijc+devicetree, mark.rutland, pawel.moll, benh, paulus,
	mpe, robh+dt
  Cc: linuxppc-dev, devicetree

Currently for PowerPC systems using device tree, the legacy serial
ports are allocated in the order by which they are found in the device
tree structure.

This can cause problems in cases where the device tree nodes are
sysnthesized by an external program (kexec for example), which may not
preserve the original order of the device tree nodes.  This in turn
can result in the serial console changing from ttyS0 to ttyS1
unexpectedly.

This patch uses the 'cell-index' property (if present) to map UART
device tree nodes to legacy serial port number.  The cell-index
property is widely used in all the Freescale .dts files for PowerPC.

Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
---
 arch/powerpc/kernel/legacy_serial.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c b/arch/powerpc/kernel/legacy_serial.c
index 7b750c4..b717133 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -164,6 +164,8 @@ static int __init add_legacy_soc_port(struct device_node *np,
 	u64 addr;
 	const __be32 *addrp;
 	struct device_node *tsi = of_get_parent(np);
+	int index = -1, len;
+	u32 *indexp;
 
 	/* We only support ports that have a clock frequency properly
 	 * encoded in the device-tree.
@@ -188,14 +190,19 @@ static int __init add_legacy_soc_port(struct device_node *np,
 	if (addr == OF_BAD_ADDR)
 		return -1;
 
+	/* Check if the ports have an ordering, defined by 'cell-index' */
+	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) != NULL) &&
+	    (len == sizeof(u32)))
+		index = *indexp;
+
 	/* Add port, irq will be dealt with later. We passed a translated
 	 * IO port value. It will be fixed up later along with the irq
 	 */
 	if (tsi && !strcmp(tsi->type, "tsi-bridge"))
-		return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
+		return add_legacy_port(np, index, UPIO_TSI, addr, addr,
 				       NO_IRQ, legacy_port_flags, 0);
 	else
-		return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
+		return add_legacy_port(np, index, UPIO_MEM, addr, addr,
 				       NO_IRQ, legacy_port_flags, 0);
 }
 
-- 
1.9.1

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
  2015-11-25 18:46 ` Curt Brune
@ 2015-12-20 15:02   ` Segher Boessenkool
  -1 siblings, 0 replies; 14+ messages in thread
From: Segher Boessenkool @ 2015-12-20 15:02 UTC (permalink / raw)
  To: Curt Brune
  Cc: mark.rutland, devicetree, pawel.moll, ijc+devicetree, robh+dt,
	paulus, galak, linuxppc-dev

On Wed, Nov 25, 2015 at 10:46:49AM -0800, Curt Brune wrote:
> +	/* Check if the ports have an ordering, defined by 'cell-index' */
> +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) != NULL) &&
> +	    (len == sizeof(u32)))
> +		index = *indexp;
> +
>  	/* Add port, irq will be dealt with later. We passed a translated
>  	 * IO port value. It will be fixed up later along with the irq
>  	 */
>  	if (tsi && !strcmp(tsi->type, "tsi-bridge"))
> -		return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
> +		return add_legacy_port(np, index, UPIO_TSI, addr, addr,
>  				       NO_IRQ, legacy_port_flags, 0);
>  	else
> -		return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
> +		return add_legacy_port(np, index, UPIO_MEM, addr, addr,
>  				       NO_IRQ, legacy_port_flags, 0);

What does this do if the value in cell-index is a duplicate. or the port
with that number is already created some other way?  Are the numbers in
cell-index global anyway, or relative to some parent device (I couldn't
find the documentation for this).


Segher
_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-12-20 15:02   ` Segher Boessenkool
  0 siblings, 0 replies; 14+ messages in thread
From: Segher Boessenkool @ 2015-12-20 15:02 UTC (permalink / raw)
  To: Curt Brune
  Cc: galak, ijc+devicetree, mark.rutland, pawel.moll, benh, paulus,
	mpe, robh+dt, devicetree, linuxppc-dev

On Wed, Nov 25, 2015 at 10:46:49AM -0800, Curt Brune wrote:
> +	/* Check if the ports have an ordering, defined by 'cell-index' */
> +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) != NULL) &&
> +	    (len == sizeof(u32)))
> +		index = *indexp;
> +
>  	/* Add port, irq will be dealt with later. We passed a translated
>  	 * IO port value. It will be fixed up later along with the irq
>  	 */
>  	if (tsi && !strcmp(tsi->type, "tsi-bridge"))
> -		return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
> +		return add_legacy_port(np, index, UPIO_TSI, addr, addr,
>  				       NO_IRQ, legacy_port_flags, 0);
>  	else
> -		return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
> +		return add_legacy_port(np, index, UPIO_MEM, addr, addr,
>  				       NO_IRQ, legacy_port_flags, 0);

What does this do if the value in cell-index is a duplicate. or the port
with that number is already created some other way?  Are the numbers in
cell-index global anyway, or relative to some parent device (I couldn't
find the documentation for this).


Segher

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
  2015-11-25 18:46 ` Curt Brune
@ 2015-12-22  3:42   ` Scott Wood
  -1 siblings, 0 replies; 14+ messages in thread
From: Scott Wood @ 2015-12-22  3:42 UTC (permalink / raw)
  To: Curt Brune, galak, ijc+devicetree, mark.rutland, pawel.moll,
	benh, paulus, mpe, robh+dt
  Cc: devicetree, linuxppc-dev

On Wed, 2015-11-25 at 10:46 -0800, Curt Brune wrote:
> Currently for PowerPC systems using device tree, the legacy serial
> ports are allocated in the order by which they are found in the device
> tree structure.
> 
> This can cause problems in cases where the device tree nodes are
> sysnthesized by an external program (kexec for example), which may not
> preserve the original order of the device tree nodes.  This in turn
> can result in the serial console changing from ttyS0 to ttyS1
> unexpectedly.
> 
> This patch uses the 'cell-index' property (if present) to map UART
> device tree nodes to legacy serial port number.  The cell-index
> property is widely used in all the Freescale .dts files for PowerPC.
> 
> Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
> ---
>  arch/powerpc/kernel/legacy_serial.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/legacy_serial.c
> b/arch/powerpc/kernel/legacy_serial.c
> index 7b750c4..b717133 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -164,6 +164,8 @@ static int __init add_legacy_soc_port(struct device_node
> *np,
>  	u64 addr;
>  	const __be32 *addrp;
>  	struct device_node *tsi = of_get_parent(np);
> +	int index = -1, len;
> +	u32 *indexp;
>  
>  	/* We only support ports that have a clock frequency properly
>  	 * encoded in the device-tree.
> @@ -188,14 +190,19 @@ static int __init add_legacy_soc_port(struct
> device_node *np,
>  	if (addr == OF_BAD_ADDR)
>  		return -1;
>  
> +	/* Check if the ports have an ordering, defined by 'cell-index' */
> +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) !=
> NULL) &&
> +	    (len == sizeof(u32)))
> +		index = *indexp;

const u32 *

Or better, use of_read_number() or similar.

-Scott

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-12-22  3:42   ` Scott Wood
  0 siblings, 0 replies; 14+ messages in thread
From: Scott Wood @ 2015-12-22  3:42 UTC (permalink / raw)
  To: Curt Brune, galak, ijc+devicetree, mark.rutland, pawel.moll,
	benh, paulus, mpe, robh+dt
  Cc: linuxppc-dev, devicetree

On Wed, 2015-11-25 at 10:46 -0800, Curt Brune wrote:
> Currently for PowerPC systems using device tree, the legacy serial
> ports are allocated in the order by which they are found in the device
> tree structure.
> 
> This can cause problems in cases where the device tree nodes are
> sysnthesized by an external program (kexec for example), which may not
> preserve the original order of the device tree nodes.  This in turn
> can result in the serial console changing from ttyS0 to ttyS1
> unexpectedly.
> 
> This patch uses the 'cell-index' property (if present) to map UART
> device tree nodes to legacy serial port number.  The cell-index
> property is widely used in all the Freescale .dts files for PowerPC.
> 
> Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
> ---
>  arch/powerpc/kernel/legacy_serial.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/legacy_serial.c
> b/arch/powerpc/kernel/legacy_serial.c
> index 7b750c4..b717133 100644
> --- a/arch/powerpc/kernel/legacy_serial.c
> +++ b/arch/powerpc/kernel/legacy_serial.c
> @@ -164,6 +164,8 @@ static int __init add_legacy_soc_port(struct device_node
> *np,
>  	u64 addr;
>  	const __be32 *addrp;
>  	struct device_node *tsi = of_get_parent(np);
> +	int index = -1, len;
> +	u32 *indexp;
>  
>  	/* We only support ports that have a clock frequency properly
>  	 * encoded in the device-tree.
> @@ -188,14 +190,19 @@ static int __init add_legacy_soc_port(struct
> device_node *np,
>  	if (addr == OF_BAD_ADDR)
>  		return -1;
>  
> +	/* Check if the ports have an ordering, defined by 'cell-index' */
> +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) !=
> NULL) &&
> +	    (len == sizeof(u32)))
> +		index = *indexp;

const u32 *

Or better, use of_read_number() or similar.

-Scott

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
  2015-12-20 15:02   ` Segher Boessenkool
@ 2015-12-30 16:36       ` Curt Brune
  -1 siblings, 0 replies; 14+ messages in thread
From: Curt Brune @ 2015-12-30 16:36 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: galak-sgV2jX0FEOL9JmXXK+q4OQ,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg, mark.rutland-5wv7dgnIgG8,
	pawel.moll-5wv7dgnIgG8, benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r,
	paulus-eUNUBHrolfbYtjvyW6yDsg, mpe-Gsx/Oe8HsFggBc27wqDAHg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Sun Dec 20 09:02, Segher Boessenkool wrote:
> On Wed, Nov 25, 2015 at 10:46:49AM -0800, Curt Brune wrote:
> > +	/* Check if the ports have an ordering, defined by 'cell-index' */
> > +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) != NULL) &&
> > +	    (len == sizeof(u32)))
> > +		index = *indexp;
> > +
> >  	/* Add port, irq will be dealt with later. We passed a translated
> >  	 * IO port value. It will be fixed up later along with the irq
> >  	 */
> >  	if (tsi && !strcmp(tsi->type, "tsi-bridge"))
> > -		return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
> > +		return add_legacy_port(np, index, UPIO_TSI, addr, addr,
> >  				       NO_IRQ, legacy_port_flags, 0);
> >  	else
> > -		return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
> > +		return add_legacy_port(np, index, UPIO_MEM, addr, addr,
> >  				       NO_IRQ, legacy_port_flags, 0);
> 
> What does this do if the value in cell-index is a duplicate. or the port
> with that number is already created some other way?  Are the numbers in
> cell-index global anyway, or relative to some parent device (I couldn't
> find the documentation for this).
> 
> 
> Segher

add_legacy_port() has support for handling duplicate index entries.
Reading that code it looks like the recent entry wins and the older
entry is moved to the next available index.

The numbers in cell-index are not global nor explicitly relative to a
parent device.  I also could not find documentation on this.

In common usage, however, the cell-index property is used in two
different ways:

1.  For devices that have "channels" or "regions" (DMA for example),
the parent device node has child nodes enumerated by cell-index.  For
example see:  arch/powerpc/boot/dts/fsl/pq3-dma-0.dtsi

2.  For multiple instances of a device, for example UARTS,
each device node is enumerated using cell-index.  See:
arch/powerpc/boot/dts/fsl/qoriq-duart-0.dtsi

Cheers,
Curt
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-12-30 16:36       ` Curt Brune
  0 siblings, 0 replies; 14+ messages in thread
From: Curt Brune @ 2015-12-30 16:36 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: galak, ijc+devicetree, mark.rutland, pawel.moll, benh, paulus,
	mpe, robh+dt, devicetree, linuxppc-dev

On Sun Dec 20 09:02, Segher Boessenkool wrote:
> On Wed, Nov 25, 2015 at 10:46:49AM -0800, Curt Brune wrote:
> > +	/* Check if the ports have an ordering, defined by 'cell-index' */
> > +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) != NULL) &&
> > +	    (len == sizeof(u32)))
> > +		index = *indexp;
> > +
> >  	/* Add port, irq will be dealt with later. We passed a translated
> >  	 * IO port value. It will be fixed up later along with the irq
> >  	 */
> >  	if (tsi && !strcmp(tsi->type, "tsi-bridge"))
> > -		return add_legacy_port(np, -1, UPIO_TSI, addr, addr,
> > +		return add_legacy_port(np, index, UPIO_TSI, addr, addr,
> >  				       NO_IRQ, legacy_port_flags, 0);
> >  	else
> > -		return add_legacy_port(np, -1, UPIO_MEM, addr, addr,
> > +		return add_legacy_port(np, index, UPIO_MEM, addr, addr,
> >  				       NO_IRQ, legacy_port_flags, 0);
> 
> What does this do if the value in cell-index is a duplicate. or the port
> with that number is already created some other way?  Are the numbers in
> cell-index global anyway, or relative to some parent device (I couldn't
> find the documentation for this).
> 
> 
> Segher

add_legacy_port() has support for handling duplicate index entries.
Reading that code it looks like the recent entry wins and the older
entry is moved to the next available index.

The numbers in cell-index are not global nor explicitly relative to a
parent device.  I also could not find documentation on this.

In common usage, however, the cell-index property is used in two
different ways:

1.  For devices that have "channels" or "regions" (DMA for example),
the parent device node has child nodes enumerated by cell-index.  For
example see:  arch/powerpc/boot/dts/fsl/pq3-dma-0.dtsi

2.  For multiple instances of a device, for example UARTS,
each device node is enumerated using cell-index.  See:
arch/powerpc/boot/dts/fsl/qoriq-duart-0.dtsi

Cheers,
Curt

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
  2015-12-22  3:42   ` Scott Wood
@ 2015-12-30 16:37       ` Curt Brune
  -1 siblings, 0 replies; 14+ messages in thread
From: Curt Brune @ 2015-12-30 16:37 UTC (permalink / raw)
  To: Scott Wood
  Cc: galak-sgV2jX0FEOL9JmXXK+q4OQ,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg, mark.rutland-5wv7dgnIgG8,
	pawel.moll-5wv7dgnIgG8, benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r,
	paulus-eUNUBHrolfbYtjvyW6yDsg, mpe-Gsx/Oe8HsFggBc27wqDAHg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ,
	devicetree-u79uwXL29TY76Z2rM5mHXA

On Mon Dec 21 21:42, Scott Wood wrote:
> On Wed, 2015-11-25 at 10:46 -0800, Curt Brune wrote:
> > Currently for PowerPC systems using device tree, the legacy serial
> > ports are allocated in the order by which they are found in the device
> > tree structure.
> > 
> > This can cause problems in cases where the device tree nodes are
> > sysnthesized by an external program (kexec for example), which may not
> > preserve the original order of the device tree nodes.  This in turn
> > can result in the serial console changing from ttyS0 to ttyS1
> > unexpectedly.
> > 
> > This patch uses the 'cell-index' property (if present) to map UART
> > device tree nodes to legacy serial port number.  The cell-index
> > property is widely used in all the Freescale .dts files for PowerPC.
> > 
> > Signed-off-by: Curt Brune <curt-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
> > ---
> >  arch/powerpc/kernel/legacy_serial.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/powerpc/kernel/legacy_serial.c
> > b/arch/powerpc/kernel/legacy_serial.c
> > index 7b750c4..b717133 100644
> > --- a/arch/powerpc/kernel/legacy_serial.c
> > +++ b/arch/powerpc/kernel/legacy_serial.c
> > @@ -164,6 +164,8 @@ static int __init add_legacy_soc_port(struct device_node
> > *np,
> >  	u64 addr;
> >  	const __be32 *addrp;
> >  	struct device_node *tsi = of_get_parent(np);
> > +	int index = -1, len;
> > +	u32 *indexp;
> >  
> >  	/* We only support ports that have a clock frequency properly
> >  	 * encoded in the device-tree.
> > @@ -188,14 +190,19 @@ static int __init add_legacy_soc_port(struct
> > device_node *np,
> >  	if (addr == OF_BAD_ADDR)
> >  		return -1;
> >  
> > +	/* Check if the ports have an ordering, defined by 'cell-index' */
> > +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) !=
> > NULL) &&
> > +	    (len == sizeof(u32)))
> > +		index = *indexp;
> 
> const u32 *
> 
> Or better, use of_read_number() or similar.
> 
> -Scott
> 

Ack.  Thanks for the pointer.

-Curt
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-12-30 16:37       ` Curt Brune
  0 siblings, 0 replies; 14+ messages in thread
From: Curt Brune @ 2015-12-30 16:37 UTC (permalink / raw)
  To: Scott Wood
  Cc: galak, ijc+devicetree, mark.rutland, pawel.moll, benh, paulus,
	mpe, robh+dt, linuxppc-dev, devicetree

On Mon Dec 21 21:42, Scott Wood wrote:
> On Wed, 2015-11-25 at 10:46 -0800, Curt Brune wrote:
> > Currently for PowerPC systems using device tree, the legacy serial
> > ports are allocated in the order by which they are found in the device
> > tree structure.
> > 
> > This can cause problems in cases where the device tree nodes are
> > sysnthesized by an external program (kexec for example), which may not
> > preserve the original order of the device tree nodes.  This in turn
> > can result in the serial console changing from ttyS0 to ttyS1
> > unexpectedly.
> > 
> > This patch uses the 'cell-index' property (if present) to map UART
> > device tree nodes to legacy serial port number.  The cell-index
> > property is widely used in all the Freescale .dts files for PowerPC.
> > 
> > Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
> > ---
> >  arch/powerpc/kernel/legacy_serial.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/powerpc/kernel/legacy_serial.c
> > b/arch/powerpc/kernel/legacy_serial.c
> > index 7b750c4..b717133 100644
> > --- a/arch/powerpc/kernel/legacy_serial.c
> > +++ b/arch/powerpc/kernel/legacy_serial.c
> > @@ -164,6 +164,8 @@ static int __init add_legacy_soc_port(struct device_node
> > *np,
> >  	u64 addr;
> >  	const __be32 *addrp;
> >  	struct device_node *tsi = of_get_parent(np);
> > +	int index = -1, len;
> > +	u32 *indexp;
> >  
> >  	/* We only support ports that have a clock frequency properly
> >  	 * encoded in the device-tree.
> > @@ -188,14 +190,19 @@ static int __init add_legacy_soc_port(struct
> > device_node *np,
> >  	if (addr == OF_BAD_ADDR)
> >  		return -1;
> >  
> > +	/* Check if the ports have an ordering, defined by 'cell-index' */
> > +	if (((indexp = (u32*)of_get_property(np, "cell-index", &len)) !=
> > NULL) &&
> > +	    (len == sizeof(u32)))
> > +		index = *indexp;
> 
> const u32 *
> 
> Or better, use of_read_number() or similar.
> 
> -Scott
> 

Ack.  Thanks for the pointer.

-Curt

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
  2015-12-30 16:36       ` Curt Brune
@ 2015-12-30 20:12           ` Segher Boessenkool
  -1 siblings, 0 replies; 14+ messages in thread
From: Segher Boessenkool @ 2015-12-30 20:12 UTC (permalink / raw)
  To: Curt Brune
  Cc: galak-sgV2jX0FEOL9JmXXK+q4OQ,
	ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg, mark.rutland-5wv7dgnIgG8,
	pawel.moll-5wv7dgnIgG8, benh-XVmvHMARGAS8U2dJNN8I7kB+6BGkLq7r,
	paulus-eUNUBHrolfbYtjvyW6yDsg, mpe-Gsx/Oe8HsFggBc27wqDAHg,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	devicetree-u79uwXL29TY76Z2rM5mHXA,
	linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ

On Wed, Dec 30, 2015 at 08:36:01AM -0800, Curt Brune wrote:
> > What does this do if the value in cell-index is a duplicate. or the port
> > with that number is already created some other way?  Are the numbers in
> > cell-index global anyway, or relative to some parent device (I couldn't
> > find the documentation for this).
> 
> add_legacy_port() has support for handling duplicate index entries.
> Reading that code it looks like the recent entry wins and the older
> entry is moved to the next available index.
> 
> The numbers in cell-index are not global nor explicitly relative to a
> parent device.  I also could not find documentation on this.

That sounds like it should work then.  It does change behaviour for
existing configs.

Thanks,


Segher
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-12-30 20:12           ` Segher Boessenkool
  0 siblings, 0 replies; 14+ messages in thread
From: Segher Boessenkool @ 2015-12-30 20:12 UTC (permalink / raw)
  To: Curt Brune
  Cc: galak, ijc+devicetree, mark.rutland, pawel.moll, benh, paulus,
	mpe, robh+dt, devicetree, linuxppc-dev

On Wed, Dec 30, 2015 at 08:36:01AM -0800, Curt Brune wrote:
> > What does this do if the value in cell-index is a duplicate. or the port
> > with that number is already created some other way?  Are the numbers in
> > cell-index global anyway, or relative to some parent device (I couldn't
> > find the documentation for this).
> 
> add_legacy_port() has support for handling duplicate index entries.
> Reading that code it looks like the recent entry wins and the older
> entry is moved to the next available index.
> 
> The numbers in cell-index are not global nor explicitly relative to a
> parent device.  I also could not find documentation on this.

That sounds like it should work then.  It does change behaviour for
existing configs.

Thanks,


Segher

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
  2015-11-25 18:46 ` Curt Brune
@ 2015-12-30 22:34     ` Rob Herring
  -1 siblings, 0 replies; 14+ messages in thread
From: Rob Herring @ 2015-12-30 22:34 UTC (permalink / raw)
  To: Curt Brune
  Cc: Kumar Gala, Ian Campbell, Mark Rutland, Pawel Moll,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	linuxppc-dev, devicetree-u79uwXL29TY76Z2rM5mHXA

On Wed, Nov 25, 2015 at 12:46 PM, Curt Brune <curt-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org> wrote:
> Currently for PowerPC systems using device tree, the legacy serial
> ports are allocated in the order by which they are found in the device
> tree structure.
>
> This can cause problems in cases where the device tree nodes are
> sysnthesized by an external program (kexec for example), which may not
> preserve the original order of the device tree nodes.  This in turn
> can result in the serial console changing from ttyS0 to ttyS1
> unexpectedly.
>
> This patch uses the 'cell-index' property (if present) to map UART
> device tree nodes to legacy serial port number.  The cell-index
> property is widely used in all the Freescale .dts files for PowerPC.

If cell-index is already present in the dtbs, then this is okay.
Otherwise use aliases. cell-index is pretty much deprecated.

Rob
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [RFC 1/1] powerpc: legacy serial port use device tree cell-index property
@ 2015-12-30 22:34     ` Rob Herring
  0 siblings, 0 replies; 14+ messages in thread
From: Rob Herring @ 2015-12-30 22:34 UTC (permalink / raw)
  To: Curt Brune
  Cc: Kumar Gala, Ian Campbell, Mark Rutland, Pawel Moll,
	Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
	linuxppc-dev, devicetree

On Wed, Nov 25, 2015 at 12:46 PM, Curt Brune <curt@cumulusnetworks.com> wrote:
> Currently for PowerPC systems using device tree, the legacy serial
> ports are allocated in the order by which they are found in the device
> tree structure.
>
> This can cause problems in cases where the device tree nodes are
> sysnthesized by an external program (kexec for example), which may not
> preserve the original order of the device tree nodes.  This in turn
> can result in the serial console changing from ttyS0 to ttyS1
> unexpectedly.
>
> This patch uses the 'cell-index' property (if present) to map UART
> device tree nodes to legacy serial port number.  The cell-index
> property is widely used in all the Freescale .dts files for PowerPC.

If cell-index is already present in the dtbs, then this is okay.
Otherwise use aliases. cell-index is pretty much deprecated.

Rob

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

end of thread, other threads:[~2015-12-30 22:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-25 18:46 [RFC 1/1] powerpc: legacy serial port use device tree cell-index property Curt Brune
2015-11-25 18:46 ` Curt Brune
2015-12-20 15:02 ` Segher Boessenkool
2015-12-20 15:02   ` Segher Boessenkool
     [not found]   ` <20151220150225.GA27380-JorI+TVEvZrY24RiXHRV3ti2O/JbrIOy@public.gmane.org>
2015-12-30 16:36     ` Curt Brune
2015-12-30 16:36       ` Curt Brune
     [not found]       ` <20151230163601.GX14046-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
2015-12-30 20:12         ` Segher Boessenkool
2015-12-30 20:12           ` Segher Boessenkool
2015-12-22  3:42 ` Scott Wood
2015-12-22  3:42   ` Scott Wood
     [not found]   ` <1450755731.18314.76.camel-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2015-12-30 16:37     ` Curt Brune
2015-12-30 16:37       ` Curt Brune
     [not found] ` <1448477209-22340-2-git-send-email-curt-qUQiAmfTcIp+XZJcv9eMoEEOCMrvLtNR@public.gmane.org>
2015-12-30 22:34   ` Rob Herring
2015-12-30 22:34     ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.