serial: ns16550: Move PCI access from ofdata_to_platdata() to probe()
RFC PATCH 1/1 serial: ns16550: Move PCI access from ofdata_to_platdata() to probe()
Currently the ofdata_to_platdata() method calls dev_read_addr_pci(), which potentially accesses the parent PCI bus. If this happens before the parent PCI bus is probed the resulting address will be wrong.
This behavior was triggered by commit 82de42fa1468 ("dm: core:
Allocate parent data separate from probing parent").
According to a comment in drivers/pci/pci-uclass.c [1] accessing the PCI parent bus in ofdata_to_platdata() is not allowed, and the access should be moved to the probe() function.
Move the call to dev_read_addr_pci() and the related handling of the 'addr' value from the ofdata_to_platdata() to the probe() method.
While moving the code, the comment /* try Processor Local Bus device first */ was dropped. It was initially added with commit 3db886a5bf38 ("serial: ns16550: Support ns16550 compatible pci uart devices") and later made obsolete with commit 33c215af4b9d ("dm: pci: Add a function to read a PCI BAR").
[1] Comment in drivers/pci/pci-uclass.c:
"A common cause of this problem is that this function is called in the ofdata_to_platdata() method of @dev. Accessing the PCI bus in that method is not allowed, since it has not yet been probed. To fix this, move that access to the probe() method of @dev instead."
probing parent")
---
The discussion leading to this patch is located at
https://lists.denx.de/pipermail/u-boot/2020-February/399811.html
drivers/serial/ns16550.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/serial/ns16550.c +13 -13
@@ -484,12 +484,24 @@ int ns16550_serial_probe(struct udevice *dev)struct NS16550 *const com_port =dev_get_priv (dev);struct reset_ctl_bulk reset_bulk;int ret; +fdt_addr_t addr; + + com_port->plat =dev_get_platdata (dev); + + addr =dev_read_addr_pci (dev); +if (addr ==FDT_ADDR_T_NONE ) +return -EINVAL ; + +#ifdef CONFIG_SYS_NS16550_PORT_MAPPED + com_port->plat->base = addr; +#else + com_port->plat->base = (unsigned long )map_physmem (addr,0 ,MAP_NOCACHE ); +#endif ret =reset_get_bulk (dev, &reset_bulk);if (!ret)reset_deassert_bulk (&reset_bulk); - com_port->plat =dev_get_platdata (dev);NS16550_init (com_port,-1 );return 0 ;
@@ -507,21 +519,9 @@ int ns16550_serial_ofdata_to_platdata(struct udevice *dev) {struct ns16550_platdata *plat = dev->platdata;const u32 port_type =dev_get_driver_data (dev); -fdt_addr_t addr;struct clk clk;int err; -/* try Processor Local Bus device first */ - addr =dev_read_addr_pci (dev); -if (addr ==FDT_ADDR_T_NONE ) -return -EINVAL ; - -#ifdef CONFIG_SYS_NS16550_PORT_MAPPED - plat->base = addr; -#else - plat->base = (unsigned long )map_physmem (addr,0 ,MAP_NOCACHE ); -#endif - plat->reg_offset =dev_read_u32_default (dev,"reg-offset" ,0 ); plat->reg_shift =dev_read_u32_default (dev,"reg-shift" ,0 ); plat->reg_width =dev_read_u32_default (dev,"reg-io-width" ,1 );
Signature · 1 line
2.25.0
RFC PATCH 1/1 serial: ns16550: Move PCI access from ofdata_to_platdata() to probe()
Quoted 30 lines · Wolfgang Wallner
Currently the
ofdata_to_platdata()method callsdev_read_addr_pci(), which potentially accesses the parent PCI bus. If this happens before the parent PCI bus is probed the resulting address will be wrong.This behavior was triggered by commit
82de42fa1468("dm: core:
Allocate parent data separate from probing parent").According to a comment in
drivers/pci/pci-uclass.c[1] accessing the PCI parent bus inofdata_to_platdata()is not allowed, and the access should be moved to theprobe()function.Move the call to
dev_read_addr_pci()and the related handling of the 'addr' value from theofdata_to_platdata()to theprobe()method.While moving the code, the comment /* try Processor Local Bus device first */ was dropped. It was initially added with commit
3db886a5bf38("serial: ns16550: Support ns16550 compatible pci uart devices") and later made obsolete with commit33c215af4b9d("dm: pci: Add a function to read a PCI BAR").[1] Comment in
drivers/pci/pci-uclass.c:
"A common cause of this problem is that this function is called in theofdata_to_platdata()method of @dev. Accessing the PCI bus in that method is not allowed, since it has not yet been probed. To fix this, move that access to theprobe()method of @dev instead."Signed-off-by Wolfgang Wallner <[email protected]>Fixes 82de42fa1468 ("dm: core: Allocate parent data separate from
Quoted 8 lines
probing parent")
---
The discussion leading to this patch is located at
https://lists.denx.de/pipermail/u-boot/2020-February/399811.htmldrivers/serial/ns16550.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
RFC PATCH 1/1 serial: ns16550: Move PCI access from ofdata_to_platdata() to probe()
In reply to Wolfgang WallnerQuoted 30 lines · Wolfgang Wallner
Currently the
ofdata_to_platdata()method callsdev_read_addr_pci(), which potentially accesses the parent PCI bus. If this happens before the parent PCI bus is probed the resulting address will be wrong.This behavior was triggered by commit
82de42fa1468("dm: core:
Allocate parent data separate from probing parent").According to a comment in
drivers/pci/pci-uclass.c[1] accessing the PCI parent bus inofdata_to_platdata()is not allowed, and the access should be moved to theprobe()function.Move the call to
dev_read_addr_pci()and the related handling of the 'addr' value from theofdata_to_platdata()to theprobe()method.While moving the code, the comment /* try Processor Local Bus device first */ was dropped. It was initially added with commit
3db886a5bf38("serial: ns16550: Support ns16550 compatible pci uart devices") and later made obsolete with commit33c215af4b9d("dm: pci: Add a function to read a PCI BAR").[1] Comment in
drivers/pci/pci-uclass.c:
"A common cause of this problem is that this function is called in theofdata_to_platdata()method of @dev. Accessing the PCI bus in that method is not allowed, since it has not yet been probed. To fix this, move that access to theprobe()method of @dev instead."Signed-off-by Wolfgang Wallner <[email protected]>Fixes 82de42fa1468 ("dm: core: Allocate parent data separate from
Quoted 9 lines
probing parent")
---
The discussion leading to this patch is located at
https://lists.denx.de/pipermail/u-boot/2020-February/399811.htmldrivers/serial/ns16550.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
This fixed the boot failure of Intel Galileo
Tested on Intel Galileo
RFC PATCH 1/1 serial: ns16550: Move PCI access from ofdata_to_platdata() to probe()
Quoted 43 lines · Bin Meng
Quoted 30 lines · Wolfgang Wallner
Currently the
ofdata_to_platdata()method callsdev_read_addr_pci(), which potentially accesses the parent PCI bus. If this happens before the parent PCI bus is probed the resulting address will be wrong.This behavior was triggered by commit
82de42fa1468("dm: core:
Allocate parent data separate from probing parent").According to a comment in
drivers/pci/pci-uclass.c[1] accessing the PCI parent bus inofdata_to_platdata()is not allowed, and the access should be moved to theprobe()function.Move the call to
dev_read_addr_pci()and the related handling of the 'addr' value from theofdata_to_platdata()to theprobe()method.While moving the code, the comment /* try Processor Local Bus device first */ was dropped. It was initially added with commit
3db886a5bf38("serial: ns16550: Support ns16550 compatible pci uart devices") and later made obsolete with commit33c215af4b9d("dm: pci: Add a function to read a PCI BAR").[1] Comment in
drivers/pci/pci-uclass.c:
"A common cause of this problem is that this function is called in theofdata_to_platdata()method of @dev. Accessing the PCI bus in that method is not allowed, since it has not yet been probed. To fix this, move that access to theprobe()method of @dev instead."Signed-off-by Wolfgang Wallner <[email protected]>Fixes 82de42fa1468 ("dm: core: Allocate parent data separate fromQuoted 9 lines
probing parent")
---
The discussion leading to this patch is located at
https://lists.denx.de/pipermail/u-boot/2020-February/399811.htmldrivers/serial/ns16550.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
Quoted 6 lines
Reviewed-by Bin Meng <[email protected]>This fixed the boot failure of Intel Galileo
Tested on Intel Galileo
Tested-by Bin Meng <[email protected]>
applied to u-boot-x86, thanks!
RFC PATCH 1/1 serial: ns16550: Move PCI access from ofdata_to_platdata() to probe()
Hi Wolfgang,
Quoted 45 lines · Bin Meng
Quoted 43 lines · Bin Meng
Quoted 39 lines · Wolfgang Wallner
Currently the
ofdata_to_platdata()method callsdev_read_addr_pci(), which potentially accesses the parent PCI bus. If this happens before the parent PCI bus is probed the resulting address will be wrong.This behavior was triggered by commit
82de42fa1468("dm: core:
Allocate parent data separate from probing parent").According to a comment in
drivers/pci/pci-uclass.c[1] accessing the PCI parent bus inofdata_to_platdata()is not allowed, and the access should be moved to theprobe()function.Move the call to
dev_read_addr_pci()and the related handling of the 'addr' value from theofdata_to_platdata()to theprobe()method.While moving the code, the comment /* try Processor Local Bus device first */ was dropped. It was initially added with commit
3db886a5bf38("serial: ns16550: Support ns16550 compatible pci uart devices") and later made obsolete with commit33c215af4b9d("dm: pci: Add a function to read a PCI BAR").[1] Comment in
drivers/pci/pci-uclass.c:
"A common cause of this problem is that this function is called in theofdata_to_platdata()method of @dev. Accessing the PCI bus in that method is not allowed, since it has not yet been probed. To fix this, move that access to theprobe()method of @dev instead."Signed-off-by Wolfgang Wallner <[email protected]>Fixes 82de42fa1468 ("dm: core: Allocate parent data separate fromprobing parent")
---
The discussion leading to this patch is located at
https://lists.denx.de/pipermail/u-boot/2020-February/399811.htmldrivers/serial/ns16550.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
Quoted 8 lines
Quoted 6 lines
Reviewed-by Bin Meng <[email protected]>This fixed the boot failure of Intel Galileo
Tested on Intel Galileo
Tested-by Bin Meng <[email protected]>applied to u-boot-x86, thanks!
Unfortunately this patch breaks several ARM board:
+drivers/built-in.o: In function `ofnode_get_parent':+drivers/core/ofnode.c:235: undefined reference to fdt_parent_offset' +drivers/built-in.o: In function ofnode_read_simple_addr_cells':+drivers/core/ofnode.c:717: undefined reference to fdt_address_cells' +drivers/built-in.o: In function ofnode_read_simple_size_cells':+drivers/core/ofnode.c:725: undefined reference to fdt_size_cells' +drivers/built-in.o: In function ofnode_get_addr_size_index':+drivers/core/ofnode.c:294: undefined reference to `fdtdec_get_addr_size_fixed'
Would you please send a v2 to address this? thanks!
Regards,
Bin
Antwort: Re: [RFC PATCH] serial: ns16550: Move PCI access from ofdata_to_platdata() to probe()
Hi Bin,
-----"Bin Meng" <[email protected]> schrieb: -----
Quoted 15 lines
Hi Wolfgang,
[snip]
Unfortunately this patch breaks several ARM board:
(quoted diff) +8
-0+drivers/built-in.o: In function `ofnode_get_parent': +drivers/core/ofnode.c:235: undefined reference to `fdt_parent_offset' +drivers/built-in.o: In function `ofnode_read_simple_addr_cells': +drivers/core/ofnode.c:717: undefined reference to `fdt_address_cells' +drivers/built-in.o: In function `ofnode_read_simple_size_cells': +drivers/core/ofnode.c:725: undefined reference to `fdt_size_cells' +drivers/built-in.o: In function `ofnode_get_addr_size_index': +drivers/core/ofnode.c:294: undefined reference to `fdtdec_get_addr_size_fixed'
Quoted 1 line
Thanks for pointing this out.
I have missed that the code was guarded with
#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
before, and is not guarded anymore now.
Quoted 1 line
Would you please send a v2 to address this? thanks!
Yes, I will follow up with a v2.
regards, Wolfgang