core: ofnode: Fix translation for #size-cells == 0
PATCH v2 1/1 core: ofnode: Fix translation for #size-cells == 0
Commit 286ede6 ("drivers: core: Add translation in live tree case") made dev_get_addr always use proper bus translations for addresses read from the device tree. But this leads to problems with certain busses, e.g. I2C busses, which run into an error during translation, and hence stop working.
It turns out that of_translate_address() and fdt_translate_address() stop the address translation with an error when they're asked to translate addresses for busses where #size-cells == 0 (comment from drivers/core/of_addr.c):
* Note: We consider that crossing any level with #size-cells == 0 to mean
* that translation is impossible (that is we are not dealing with a value
* that can be mapped to a cpu physical address). This is not really specified
* that way, but this is traditionally the way IBM at least do things
To fix this case, we check in both the live-tree and non-live tree-case, whether the bus of the device whose address is about to be translated has size-cell size zero. If this is the case, we just read the address as a plain integer and return it, and only apply bus translations if the size-cell size if greater than zero.
---
v1 -> v2:
* Add unit tests for address translation as suggested by Simon Glass
--- arch/sandbox/dts/test.dts | 48 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/core/fdtaddr.c | 17 +++++++++++------ drivers/core/ofnode.c | 5 ++++- include/dm/uclass-id.h | 1 + test/dm/test-fdt.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 7 deletions(-)
arch/sandbox/dts/test.dts +48 -0
@@ -27,6 +27,10 @@ testfdt3 = "/b-test"; testfdt5 = "/some-bus/c-test at 5"; testfdt8 = "/a-test"; + fdt_dummy0 = "/translation-test at 8000/dev at 0,0"; + fdt_dummy1 = "/translation-test at 8000/dev at 1,100"; + fdt_dummy2 = "/translation-test at 8000/dev at 2,200"; + fdt_dummy3 = "/translation-test at 8000/noxlatebus at 3,300/dev at 42"; usb0 = &usb_0; usb1 = &usb_1; usb2 = &usb_2;
@@ -487,6 +491,50 @@ reg = <9 1>; }; }; + + translation-test at 8000 { + compatible = "simple-bus"; + reg = <0x8000 0x4000>; + + #address-cells = <0x2>; + #size-cells = <0x1>; + + ranges = <0 0x0 0x8000 0x1000 + 1 0x100 0x9000 0x1000 + 2 0x200 0xA000 0x1000 + 3 0x300 0xB000 0x1000 + >; + + dev at 0,0 { + compatible = "denx,u-boot-fdt-dummy"; + reg = <0 0x0 0x1000>; + }; + + dev at 1,100 { + compatible = "denx,u-boot-fdt-dummy"; + reg = <1 0x100 0x1000>; + + }; + + dev at 2,200 { + compatible = "denx,u-boot-fdt-dummy"; + reg = <2 0x200 0x1000>; + }; + + + noxlatebus at 3,300 { + compatible = "simple-bus"; + reg = <3 0x300 0x1000>; + + #address-cells = <0x1>; + #size-cells = <0x0>; + + dev at 42 { + compatible = "denx,u-boot-fdt-dummy"; + reg = <0x42>; + }; + }; + }; }; #include "sandbox_pmic.dtsi"
drivers/core/fdtaddr.c +11 -6
@@ -49,12 +49,17 @@ fdt_addr_t devfdt_get_addr_index(struct udevice *dev, int index) reg += index * (na + ns); -/* -* Use the full-fledged translate function for complex -* bus setups. -*/ - addr =fdt_translate_address ((void *)gd->fdt_blob, -dev_of_offset (dev), reg); +if (ns) { +/* +* Use the full-fledged translate function for complex +* bus setups. +*/ + addr =fdt_translate_address ((void *)gd->fdt_blob, +dev_of_offset (dev), reg); + }else { +/* Non translatable if #size-cells == 0 */ + addr =fdt_read_number (reg, na); + } }else {/* * Use the "simple" translate function for less complex
drivers/core/ofnode.c +4 -1
@@ -200,13 +200,16 @@ fdt_addr_t ofnode_get_addr_index(ofnode node, int index)uint flags;u64 size;int na; +int ns; prop_val =of_get_address (ofnode_to_np (node), index, &size, &flags);if (!prop_val)return FDT_ADDR_T_NONE ; -if (IS_ENABLED (CONFIG_OF_TRANSLATE )) { + ns =of_n_size_cells (ofnode_to_np (node)); + +if (IS_ENABLED (CONFIG_OF_TRANSLATE ) && ns >0 ) {return of_translate_address (ofnode_to_np (node), prop_val); }else { na =of_n_addr_cells (ofnode_to_np (node));
include/dm/uclass-id.h +1 -0
@@ -19,6 +19,7 @@ enum uclass_id {UCLASS_TEST_FDT ,UCLASS_TEST_BUS ,UCLASS_TEST_PROBE , +UCLASS_TEST_DUMMY ,UCLASS_SPI_EMUL ,/* sandbox SPI device emulator */ UCLASS_I2C_EMUL ,/* sandbox I2C device emulator */ UCLASS_PCI_EMUL, /* sandbox PCI device emulator */
test/dm/test-fdt.c +43 -0
46 lines not on this page · raw message
--
2.11.0
PATCH v2 1/1 core: ofnode: Fix translation for #size-cells == 0
Quoted 31 lines · Mario Six
Commit 286ede6 ("drivers: core: Add translation in live tree case") made
dev_get_addralways use proper bus translations for addresses read from the device tree. But this leads to problems with certain busses, e.g. I2C busses, which run into an error during translation, and hence stop working.It turns out that
of_translate_address()andfdt_translate_address()stop the address translation with an error when they're asked to translate addresses for busses where #size-cells == 0 (comment fromdrivers/core/of_addr.c):* Note: We consider that crossing any level with #size-cells == 0 to mean
* that translation is impossible (that is we are not dealing with a value
* that can be mapped to a cpu physical address). This is not really specified
* that way, but this is traditionally the way IBM at least do thingsTo fix this case, we check in both the live-tree and non-live tree-case, whether the bus of the device whose address is about to be translated has size-cell size zero. If this is the case, we just read the address as a plain integer and return it, and only apply bus translations if the size-cell size if greater than zero.
Signed-off-by Mario Six <[email protected]>Signed-off-by Martin Fuzzey <[email protected]>Reported-by Martin Fuzzey <[email protected]>Fixes 286ede6 ("drivers: core: Add translation in live tree case")---
v1 -> v2:
* Add unit tests for address translation as suggested by Simon Glass
Quoted 8 lines
--- arch/sandbox/dts/test.dts | 48 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/core/fdtaddr.c | 17 +++++++++++------ drivers/core/ofnode.c | 5 ++++- include/dm/uclass-id.h | 1 + test/dm/test-fdt.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 7 deletions(-)
PATCH v2 1/1 core: ofnode: Fix translation for #size-cells == 0
Quoted 41 lines · Simon Glass
Quoted 31 lines · Mario Six
Commit 286ede6 ("drivers: core: Add translation in live tree case") made
dev_get_addralways use proper bus translations for addresses read from the device tree. But this leads to problems with certain busses, e.g. I2C busses, which run into an error during translation, and hence stop working.It turns out that
of_translate_address()andfdt_translate_address()stop the address translation with an error when they're asked to translate addresses for busses where #size-cells == 0 (comment fromdrivers/core/of_addr.c):* Note: We consider that crossing any level with #size-cells == 0 to mean
* that translation is impossible (that is we are not dealing with a value
* that can be mapped to a cpu physical address). This is not really specified
* that way, but this is traditionally the way IBM at least do thingsTo fix this case, we check in both the live-tree and non-live tree-case, whether the bus of the device whose address is about to be translated has size-cell size zero. If this is the case, we just read the address as a plain integer and return it, and only apply bus translations if the size-cell size if greater than zero.
Signed-off-by Mario Six <[email protected]>Signed-off-by Martin Fuzzey <[email protected]>Reported-by Martin Fuzzey <[email protected]>Fixes 286ede6 ("drivers: core: Add translation in live tree case")---
v1 -> v2:
* Add unit tests for address translation as suggested by Simon GlassQuoted 8 lines
--- arch/sandbox/dts/test.dts | 48 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/core/fdtaddr.c | 17 +++++++++++------ drivers/core/ofnode.c | 5 ++++- include/dm/uclass-id.h | 1 + test/dm/test-fdt.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 7 deletions(-)
Quoted 1 line
Reviewed-by Simon Glass <[email protected]>
Applied to u-boot-dm, thanks!