Commit 66eaea6cd152a0dae5964930483f68d92047b2f5
Committed by
Simon Glass
1 parent
9b20519887
Exists in
v2017.01-smarct4x
and in
30 other branches
dm: core: Add option to configure an offset for the address translation
Some platforms need to ability to configure an offset to the standard addresses extracted from the device-tree. This patch allows this by adding a function to DM to configure this offset (if needed). Signed-off-by: Stefan Roese <sr@denx.de> Acked-by: Simon Glass <sjg@chromium.org> Cc: Simon Glass <sjg@chromium.org> Fixed space before tab: Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 3 changed files with 62 additions and 11 deletions Side-by-side Diff
drivers/core/device.c
... | ... | @@ -597,22 +597,31 @@ |
597 | 597 | * Use the full-fledged translate function for complex |
598 | 598 | * bus setups. |
599 | 599 | */ |
600 | - return fdt_translate_address((void *)gd->fdt_blob, | |
600 | + addr = fdt_translate_address((void *)gd->fdt_blob, | |
601 | 601 | dev->of_offset, reg); |
602 | + } else { | |
603 | + /* | |
604 | + * Use the "simple" translate function for less complex | |
605 | + * bus setups. | |
606 | + */ | |
607 | + addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob, | |
608 | + dev->parent->of_offset, | |
609 | + dev->of_offset, "reg", | |
610 | + 0, NULL); | |
611 | + if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) { | |
612 | + if (device_get_uclass_id(dev->parent) == | |
613 | + UCLASS_SIMPLE_BUS) | |
614 | + addr = simple_bus_translate(dev->parent, addr); | |
615 | + } | |
602 | 616 | } |
603 | 617 | |
604 | 618 | /* |
605 | - * Use the "simple" translate function for less complex | |
606 | - * bus setups. | |
619 | + * Some platforms need a special address translation. Those | |
620 | + * platforms (e.g. mvebu in SPL) can configure a translation | |
621 | + * offset in the DM by calling dm_set_translation_offset() that | |
622 | + * will get added to all addresses returned by dev_get_addr(). | |
607 | 623 | */ |
608 | - addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob, | |
609 | - dev->parent->of_offset, | |
610 | - dev->of_offset, "reg", | |
611 | - 0, NULL); | |
612 | - if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) { | |
613 | - if (device_get_uclass_id(dev->parent) == UCLASS_SIMPLE_BUS) | |
614 | - addr = simple_bus_translate(dev->parent, addr); | |
615 | - } | |
624 | + addr += dm_get_translation_offset(); | |
616 | 625 | |
617 | 626 | return addr; |
618 | 627 | #else |
drivers/core/root.c
... | ... | @@ -23,6 +23,10 @@ |
23 | 23 | |
24 | 24 | DECLARE_GLOBAL_DATA_PTR; |
25 | 25 | |
26 | +struct root_priv { | |
27 | + fdt_addr_t translation_offset; /* optional translation offset */ | |
28 | +}; | |
29 | + | |
26 | 30 | static const struct driver_info root_info = { |
27 | 31 | .name = "root_driver", |
28 | 32 | }; |
... | ... | @@ -37,6 +41,22 @@ |
37 | 41 | return gd->dm_root; |
38 | 42 | } |
39 | 43 | |
44 | +fdt_addr_t dm_get_translation_offset(void) | |
45 | +{ | |
46 | + struct udevice *root = dm_root(); | |
47 | + struct root_priv *priv = dev_get_priv(root); | |
48 | + | |
49 | + return priv->translation_offset; | |
50 | +} | |
51 | + | |
52 | +void dm_set_translation_offset(fdt_addr_t offs) | |
53 | +{ | |
54 | + struct udevice *root = dm_root(); | |
55 | + struct root_priv *priv = dev_get_priv(root); | |
56 | + | |
57 | + priv->translation_offset = offs; | |
58 | +} | |
59 | + | |
40 | 60 | #if defined(CONFIG_NEEDS_MANUAL_RELOC) |
41 | 61 | void fix_drivers(void) |
42 | 62 | { |
... | ... | @@ -228,6 +248,7 @@ |
228 | 248 | U_BOOT_DRIVER(root_driver) = { |
229 | 249 | .name = "root_driver", |
230 | 250 | .id = UCLASS_ROOT, |
251 | + .priv_auto_alloc_size = sizeof(struct root_priv), | |
231 | 252 | }; |
232 | 253 | |
233 | 254 | /* This is the root uclass */ |
include/dm/device.h
... | ... | @@ -776,5 +776,26 @@ |
776 | 776 | |
777 | 777 | #endif /* ! CONFIG_DEVRES */ |
778 | 778 | |
779 | +/** | |
780 | + * dm_set_translation_offset() - Set translation offset | |
781 | + * @offs: Translation offset | |
782 | + * | |
783 | + * Some platforms need a special address translation. Those | |
784 | + * platforms (e.g. mvebu in SPL) can configure a translation | |
785 | + * offset in the DM by calling this function. It will be | |
786 | + * added to all addresses returned in dev_get_addr(). | |
787 | + */ | |
788 | +void dm_set_translation_offset(fdt_addr_t offs); | |
789 | + | |
790 | +/** | |
791 | + * dm_get_translation_offset() - Get translation offset | |
792 | + * | |
793 | + * This function returns the translation offset that can | |
794 | + * be configured by calling dm_set_translation_offset(). | |
795 | + * | |
796 | + * @return translation offset for the device address (0 as default). | |
797 | + */ | |
798 | +fdt_addr_t dm_get_translation_offset(void); | |
799 | + | |
779 | 800 | #endif |