From 139eaa7a2b5f25e42307a672849eba0e5b4cddf0 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Fri, 30 Apr 2021 21:16:58 +0800 Subject: [PATCH 1/6] of: addr: Translate 'dma-ranges' for parent nodes missing 'dma-ranges' 'dma-ranges' frequently exists without parent nodes having 'dma-ranges'. While this is an error for 'ranges', this is fine because DMA capable devices always have a translatable DMA address. Also, with no 'dma-ranges' at all, the assumption is that DMA addresses are 1:1 with no restrictions unless perhaps the device itself has implicit restrictions. This keeps in sync with Linux kernel commit: 81db12ee15cb: of/address: Translate 'dma-ranges' for parent nodes missing 'dma-ranges' Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- drivers/core/of_addr.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/core/of_addr.c b/drivers/core/of_addr.c index 9b77308182d..a3af48fd885 100644 --- a/drivers/core/of_addr.c +++ b/drivers/core/of_addr.c @@ -192,9 +192,13 @@ static int of_translate_one(const struct device_node *parent, * * As far as we know, this damage only exists on Apple machines, so * This code is only enabled on powerpc. --gcl + * + * This quirk also applies for 'dma-ranges' which frequently exist in + * child nodes without 'dma-ranges' in the parent nodes. --RobH */ ranges = of_get_property(parent, rprop, &rlen); - if (ranges == NULL && !of_empty_ranges_quirk(parent)) { + if (ranges == NULL && !of_empty_ranges_quirk(parent) && + strcmp(rprop, "dma-ranges")) { debug("no ranges; cannot translate\n"); return 1; } From 0e35b937b9c46f313a38aa7d4aba88be76d8abf7 Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Fri, 30 Apr 2021 21:16:59 +0800 Subject: [PATCH 2/6] of: addr: Remove call to dev_count_cells() in of_get_address() In of_get_address(), there is: dev_count_cells(dev, &na, &ns); followed by: bus->count_cells(dev, &na, &ns); but no codes in between use na/ns, hence the first call is useless. By dropping the first call, dev_count_cells() is now useless too. Signed-off-by: Bin Meng Reviewed-by: Simon Glass --- drivers/core/of_addr.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/core/of_addr.c b/drivers/core/of_addr.c index a3af48fd885..3fbc0a7afa6 100644 --- a/drivers/core/of_addr.c +++ b/drivers/core/of_addr.c @@ -118,11 +118,6 @@ static struct of_bus *of_match_bus(struct device_node *np) return NULL; } -static void dev_count_cells(const struct device_node *np, int *nap, int *nsp) -{ - of_bus_default_count_cells(np, nap, nsp); -} - const __be32 *of_get_address(const struct device_node *dev, int index, u64 *size, unsigned int *flags) { @@ -136,7 +131,6 @@ const __be32 *of_get_address(const struct device_node *dev, int index, parent = of_get_parent(dev); if (parent == NULL) return NULL; - dev_count_cells(dev, &na, &ns); bus = of_match_bus(parent); bus->count_cells(dev, &na, &ns); of_node_put(parent); From 205b9f510035b835d48bae07ce8b968c3d6d75af Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sat, 15 May 2021 19:29:13 +0200 Subject: [PATCH 3/6] sandbox: correct determination of the text base os_find_text_base() assumes that first line of /proc/self/maps holds information about the text. Hence we must call the function before calling os_malloc() which calls mmap(0x10000000,). Failure to do so has led to incorrect values for pc_reloc when an exception was reported => exception undefined Illegal instruction pc = 0x5628d82e9d3c, pc_reloc = 0x5628c82e9d3c as well as incorrect output of the bdinfo command => bdinfo relocaddr = 0x0000000007858000 reloc off = 0x0000000010000000 Fixes: b308d9fd18fa ("sandbox: Avoid using malloc() for system state") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- arch/sandbox/cpu/start.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c index 63ca514ebd5..6bb94473f19 100644 --- a/arch/sandbox/cpu/start.c +++ b/arch/sandbox/cpu/start.c @@ -436,10 +436,13 @@ void sandbox_reset(void) int main(int argc, char *argv[]) { struct sandbox_state *state; + void * text_base; gd_t data; int size; int ret; + text_base = os_find_text_base(); + /* * Copy argv[] so that we can pass the arguments in the original * sequence when resetting the sandbox. @@ -452,7 +455,7 @@ int main(int argc, char *argv[]) memset(&data, '\0', sizeof(data)); gd = &data; - gd->arch.text_base = os_find_text_base(); + gd->arch.text_base = text_base; ret = state_init(); if (ret) From ca2f948a4b44b587db760510e324c87fda02c15e Mon Sep 17 00:00:00 2001 From: Alper Nebi Yasak Date: Fri, 14 May 2021 16:48:40 +0300 Subject: [PATCH 4/6] pwm: cros_ec: Rename "priv_auto_alloc_size" to "priv_auto" With commit 41575d8e4c33 ("dm: treewide: Rename auto_alloc_size members to be shorter") "priv_auto_alloc_size" was renamed to "priv_auto". This driver was sent to the mailing list before that change, merged after it, and still has the old form. Apply the rename here as well. Fixes: 1b9ee2882e6b ("pwm: Add a driver for Chrome OS EC PWM") Signed-off-by: Alper Nebi Yasak Reviewed-by: Simon Glass --- drivers/pwm/cros_ec_pwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pwm/cros_ec_pwm.c b/drivers/pwm/cros_ec_pwm.c index 44f4105dfd5..4a39c319aa2 100644 --- a/drivers/pwm/cros_ec_pwm.c +++ b/drivers/pwm/cros_ec_pwm.c @@ -80,5 +80,5 @@ U_BOOT_DRIVER(cros_ec_pwm) = { .id = UCLASS_PWM, .of_match = cros_ec_pwm_ids, .ops = &cros_ec_pwm_ops, - .priv_auto_alloc_size = sizeof(struct cros_ec_pwm_priv), + .priv_auto = sizeof(struct cros_ec_pwm_priv), }; From 0d1ab576f2e706f221b42e229eeabc80e5b51d35 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 21 May 2021 12:24:59 +0200 Subject: [PATCH 5/6] net: luton: remove address translation after ofnode_read_resource Removed call of ofnode_translate_address() after ofnode_read_resource in luton_switch.c:luton_probe(); it is unnecessary since the commit feb7ac457c20 ("dm: core: Add address translation in fdt_get_resource"). Fixes: feb7ac457c20 ("dm: core: Add address translation in fdt_get_resource") Reviewed-by: Ramon Fried Reported-by: Horatiu Vultur Signed-off-by: Patrick Delaunay --- drivers/net/mscc_eswitch/luton_switch.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/net/mscc_eswitch/luton_switch.c b/drivers/net/mscc_eswitch/luton_switch.c index 54afa14c9dd..73c950d118f 100644 --- a/drivers/net/mscc_eswitch/luton_switch.c +++ b/drivers/net/mscc_eswitch/luton_switch.c @@ -588,7 +588,6 @@ static int luton_probe(struct udevice *dev) struct luton_private *priv = dev_get_priv(dev); int i, ret; struct resource res; - fdt32_t faddr; phys_addr_t addr_base; unsigned long addr_size; ofnode eth_node, node, mdio_node; @@ -658,9 +657,7 @@ static int luton_probe(struct udevice *dev) if (ofnode_read_resource(mdio_node, 0, &res)) return -ENOMEM; - faddr = cpu_to_fdt32(res.start); - - addr_base = ofnode_translate_address(mdio_node, &faddr); + addr_base = res.start; addr_size = res.end - res.start; /* If the bus is new then create a new bus */ From 269fa8468df40952d538ac945db3d98a8d44f79e Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 21 May 2021 12:25:00 +0200 Subject: [PATCH 6/6] test: add dm_test_read_resource Add a test of dev_read_resource with translation or without translation Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- test/dm/test-fdt.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 9b771fdf193..d273e218530 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1165,3 +1166,35 @@ static int dm_test_decode_display_timing(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_decode_display_timing, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/* Test read_resourcee() */ +static int dm_test_read_resource(struct unit_test_state *uts) +{ + struct udevice *dev; + struct resource res; + + /* test resource without translation */ + ut_assertok(uclass_find_device_by_name(UCLASS_SIMPLE_BUS, "syscon@2", &dev)); + ut_assertok(dev_read_resource(dev, 0, &res)); + ut_asserteq(0x40, res.start); + ut_asserteq(0x44, res.end); + ut_assertok(dev_read_resource(dev, 1, &res)); + ut_asserteq(0x48, res.start); + ut_asserteq(0x4d, res.end); + + /* test resource with translation */ + ut_assertok(uclass_find_device_by_name(UCLASS_TEST_DUMMY, "dev@1,100", &dev)); + ut_assertok(dev_read_resource(dev, 0, &res)); + ut_asserteq(0x9000, res.start); + ut_asserteq(0x9fff, res.end); + + /* test named resource */ + ut_assertok(uclass_find_device_by_name(UCLASS_TEST_DUMMY, "dev@0,0", &dev)); + ut_assertok(dev_read_resource_byname(dev, "sandbox-dummy-0", &res)); + ut_asserteq(0x8000, res.start); + ut_asserteq(0x8fff, res.end); + + return 0; +} + +DM_TEST(dm_test_read_resource, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);