Skip to contentSkip to conversation

dm: core: Add option to configure an offset for the address translation

PATCH Superseded Stefan Roese 2 participants 2 messages Dec 14, 2015

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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).

---
v2:
- Change translation_offset type from u32 to fdt_addr_t
- Add comments to function declarations

 drivers/core/device.c | 33 +++++++++++++++++++++------------
 drivers/core/root.c   | 32 ++++++++++++++++++++++++++++++++
 include/dm/device.h   | 21 +++++++++++++++++++++
 3 files changed, 74 insertions(+), 12 deletions(-)
drivers/core/device.c +21 -12
index 758f390..41fbbc6 100644
@@ -597,22 +597,31 @@ fdt_addr_t dev_get_addr(struct udevice *dev)
 		 * Use the full-fledged translate function for complex
 		 * bus setups.
 		 */
-		return fdt_translate_address((void *)gd->fdt_blob,
+		addr = fdt_translate_address((void *)gd->fdt_blob,
 					     dev->of_offset, reg);
+	} else {
+		/*
+		 * Use the "simple" translate function for less complex
+		 * bus setups.
+		 */
+		addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
+							dev->parent->of_offset,
+							dev->of_offset, "reg",
+							0, NULL);
+		if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
+			if (device_get_uclass_id(dev->parent) ==
+			    UCLASS_SIMPLE_BUS)
+				addr = simple_bus_translate(dev->parent, addr);
+		}
 	}
 
 	/*
-	 * Use the "simple" translate function for less complex
-	 * bus setups.
-	 */
-	addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
-						dev->parent->of_offset,
-						dev->of_offset, "reg",
-						0, NULL);
-	if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
-		if (device_get_uclass_id(dev->parent) == UCLASS_SIMPLE_BUS)
-			addr = simple_bus_translate(dev->parent, addr);
-	}
+	 * Some platforms need a special address translation. Those
+	 * platforms (e.g. mvebu in SPL) can configure a translation
+	 * offset in the DM by calling dm_set_translation_offset() that
+	 * will get added to all addresses returned by dev_get_addr().
+ 	 */
+	addr += dm_get_translation_offset();
 
 	return addr;
 #else
drivers/core/root.c +32 -0
index e7b1f24..bbf0d72 100644
@@ -23,6 +23,10 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+struct root_priv {
+	fdt_addr_t translation_offset;
+};
+
 static const struct driver_info root_info = {
 	.name		= "root_driver",
 };
@@ -37,6 +41,33 @@ struct udevice *dm_root(void)
 	return gd->dm_root;
 }
 
+fdt_addr_t dm_get_translation_offset(void)
+{
+	struct udevice *root;
+
+	root = dm_root();
+	if (root) {
+		struct root_priv *priv = dev_get_priv(root);
+
+		return priv->translation_offset;
+	}
+
+	/* No offset as default */
+	return 0;
+}
+
+void dm_set_translation_offset(fdt_addr_t offs)
+{
+	struct udevice *root;
+
+	root = dm_root();
+	if (root) {
+		struct root_priv *priv = dev_get_priv(root);
+
+		priv->translation_offset = offs;
+	}
+}
+
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 void fix_drivers(void)
 {
@@ -228,6 +259,7 @@ int dm_init_and_scan(bool pre_reloc_only)
 U_BOOT_DRIVER(root_driver) = {
 	.name	= "root_driver",
 	.id	= UCLASS_ROOT,
+	.priv_auto_alloc_size = sizeof(struct root_priv),
 };
 
 /* This is the root uclass */
include/dm/device.h +21 -0
index 7fb9935..d9fc7fb 100644
@@ -776,4 +776,25 @@ static inline void devm_kfree(struct udevice *dev, void *ptr)
 
 #endif /* ! CONFIG_DEVRES */
 
+/**
+ * dm_set_translation_offset() - Set translation offset
+ * @offs: Translation offset
+ *
+ * Some platforms need a special address translation. Those
+ * platforms (e.g. mvebu in SPL) can configure a translation
+ * offset in the DM by calling this function. It will be
+ * added to all addresses returned in dev_get_addr().
+ */
+void dm_set_translation_offset(fdt_addr_t offs);
+
+/**
+ * dm_get_translation_offset() - Get translation offset
+ *
+ * This function returns the translation offset that can
+ * be configured by calling dm_set_translation_offset().
+ *
+ * @return translation offset for the device address (0 as default).
+ */
+fdt_addr_t dm_get_translation_offset(void);
+
 #endif
Signature · 1 line
2.6.4
#1 lore raw

PATCH v2 1/1 dm: core: Add option to configure an offset for the address translation

Hi Stefan,

Quoted 11 lines · Stefan Roese

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).

---
v2:
- Change translation_offset type from u32 to fdt_addr_t
- Add comments to function declarations

Quoted 4 lines
 drivers/core/device.c | 33 +++++++++++++++++++++------------
 drivers/core/root.c   | 32 ++++++++++++++++++++++++++++++++
 include/dm/device.h   | 21 +++++++++++++++++++++
 3 files changed, 74 insertions(+), 12 deletions(-)

Please see a few nits below.

Quoted 54 lines
drivers/core/device.c +21 -12
index 758f390..41fbbc6 100644
@@ -597,22 +597,31 @@ fdt_addr_t dev_get_addr(struct udevice *dev)
                 * Use the full-fledged translate function for complex
                 * bus setups.
                 */
-               return fdt_translate_address((void *)gd->fdt_blob,
+               addr = fdt_translate_address((void *)gd->fdt_blob,
                                             dev->of_offset, reg);
+       } else {
+               /*
+                * Use the "simple" translate function for less complex
+                * bus setups.
+                */
+               addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
+                                                       dev->parent->of_offset,
+                                                       dev->of_offset, "reg",
+                                                       0, NULL);
+               if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
+                       if (device_get_uclass_id(dev->parent) ==
+                           UCLASS_SIMPLE_BUS)
+                               addr = simple_bus_translate(dev->parent, addr);
+               }
        }
 
        /*
-        * Use the "simple" translate function for less complex
-        * bus setups.
-        */
-       addr = fdtdec_get_addr_size_auto_parent(gd->fdt_blob,
-                                               dev->parent->of_offset,
-                                               dev->of_offset, "reg",
-                                               0, NULL);
-       if (CONFIG_IS_ENABLED(SIMPLE_BUS) && addr != FDT_ADDR_T_NONE) {
-               if (device_get_uclass_id(dev->parent) == UCLASS_SIMPLE_BUS)
-                       addr = simple_bus_translate(dev->parent, addr);
-       }
+        * Some platforms need a special address translation. Those
+        * platforms (e.g. mvebu in SPL) can configure a translation
+        * offset in the DM by calling dm_set_translation_offset() that
+        * will get added to all addresses returned by dev_get_addr().
+        */
+       addr += dm_get_translation_offset();
 
        return addr;
 #else
drivers/core/root.c +0 -0
index e7b1f24..bbf0d72 100644

drivers/core/root.c line 27

Quoted 5 lines
drivers/core/root.c +2 -0
@@ -23,6 +23,10 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+struct root_priv {
+       fdt_addr_t translation_offset;

Comment for this.

Quoted 6 lines
drivers/core/root.c +2 -0
+};
+
 static const struct driver_info root_info = {
        .name           = "root_driver",
 };

drivers/core/root.c struct udevice *dm_root(void) · line 49

Quoted 9 lines
drivers/core/root.c +6 -0
@@ -37,6 +41,33 @@ struct udevice *dm_root(void)
        return gd->dm_root;
 }
 
+fdt_addr_t dm_get_translation_offset(void)
+{
+       struct udevice *root;
+
+       root = dm_root();
+       if (root) {

This will always be non-NULL since it is not valid to call this before driver model is running.

Quoted 5 lines
drivers/core/root.c +5 -0
+               struct root_priv *priv = dev_get_priv(root);
+
+               return priv->translation_offset;
+       }
+

drivers/core/root.c struct udevice *dm_root(void) · line 64

Quoted 10 lines
drivers/core/root.c +10 -0
+       /* No offset as default */
+       return 0;
+}
+
+void dm_set_translation_offset(fdt_addr_t offs)
+{
+       struct udevice *root;
+
+       root = dm_root();
+       if (root) {

Same here.

Quoted 48 lines
drivers/core/root.c +7 -0
+               struct root_priv *priv = dev_get_priv(root);
+
+               priv->translation_offset = offs;
+       }
+}
+
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
 void fix_drivers(void)
 {
@@ -228,6 +259,7 @@ int dm_init_and_scan(bool pre_reloc_only)
 U_BOOT_DRIVER(root_driver) = {
        .name   = "root_driver",
        .id     = UCLASS_ROOT,
+       .priv_auto_alloc_size = sizeof(struct root_priv),
 };
 
 /* This is the root uclass */
include/dm/device.h +21 -1
index 7fb9935..d9fc7fb 100644
@@ -776,4 +776,25 @@ static inline void devm_kfree(struct udevice *dev, void *ptr)
 
 #endif /* ! CONFIG_DEVRES */
 
+/**
+ * dm_set_translation_offset() - Set translation offset
+ * @offs: Translation offset
+ *
+ * Some platforms need a special address translation. Those
+ * platforms (e.g. mvebu in SPL) can configure a translation
+ * offset in the DM by calling this function. It will be
+ * added to all addresses returned in dev_get_addr().
+ */
+void dm_set_translation_offset(fdt_addr_t offs);
+
+/**
+ * dm_get_translation_offset() - Get translation offset
+ *
+ * This function returns the translation offset that can
+ * be configured by calling dm_set_translation_offset().
+ *
+ * @return translation offset for the device address (0 as default).
+ */
+fdt_addr_t dm_get_translation_offset(void);
+
 #endif
--
Quoted 2 lines

2.6.4

Regards,
Simon