[PATCH v3 28/42] dm: core: Allow storing priv/plat data separately

Simon Glass sjg at chromium.org
Mon Feb 8 05:17:53 CET 2021


At present the device priv/data data allocated by dtoc is stored in the
data section along with other variables. On some platforms it is better
to allocate space for it separately, e.g. if SPL is running from read-only
memory.

Create a new space with the same size as that allocated by dtoc, ready for
use.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 drivers/core/root.c               | 12 ++++++++++++
 include/asm-generic/global_data.h | 10 ++++++++++
 include/asm-generic/sections.h    |  3 +++
 3 files changed, 25 insertions(+)

diff --git a/drivers/core/root.c b/drivers/core/root.c
index 3ac912bbe0e..947d1cdb912 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -11,6 +11,7 @@
 #include <fdtdec.h>
 #include <log.h>
 #include <malloc.h>
+#include <asm-generic/sections.h>
 #include <linux/libfdt.h>
 #include <dm/acpi.h>
 #include <dm/device.h>
@@ -134,7 +135,9 @@ static int dm_setup_inst(void)
 
 	if (CONFIG_IS_ENABLED(OF_PLATDATA_RT)) {
 		struct udevice_rt *urt;
+		void *base;
 		int n_ents;
+		uint size;
 
 		/* Allocate the udevice_rt table */
 		n_ents = ll_entry_count(struct udevice, udevice);
@@ -142,6 +145,15 @@ static int dm_setup_inst(void)
 		if (!urt)
 			return log_msg_ret("urt", -ENOMEM);
 		gd_set_dm_udevice_rt(urt);
+
+		/* Now allocate space for the priv/plat data, and copy it in */
+		size = __priv_data_end - __priv_data_start;
+
+		base = calloc(1, size);
+		if (!base)
+			return log_msg_ret("priv", -ENOMEM);
+		memcpy(base, __priv_data_start, size);
+		gd_set_dm_priv_base(base);
 	}
 
 	return 0;
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 38bfb91e56d..6a77183a32e 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -222,6 +222,12 @@ struct global_data {
 #if CONFIG_IS_ENABLED(OF_PLATDATA_RT)
 	/** @dm_udevice_rt: Dynamic info about the udevice */
 	struct udevice_rt *dm_udevice_rt;
+	/**
+	 * @dm_priv_base: Base address of the priv/plat region used when
+	 * udevices and uclasses are in read-only memory. This is NULL if not
+	 * used
+	 */
+	void *dm_priv_base;
 # endif
 #endif
 #ifdef CONFIG_TIMER
@@ -486,9 +492,13 @@ struct global_data {
 #if CONFIG_IS_ENABLED(OF_PLATDATA_RT)
 #define gd_set_dm_udevice_rt(dyn)	gd->dm_udevice_rt = dyn
 #define gd_dm_udevice_rt()		gd->dm_udevice_rt
+#define gd_set_dm_priv_base(dyn)	gd->dm_priv_base = dyn
+#define gd_dm_priv_base()		gd->dm_priv_base
 #else
 #define gd_set_dm_udevice_rt(dyn)
 #define gd_dm_udevice_rt()		NULL
+#define gd_set_dm_priv_base(dyn)
+#define gd_dm_priv_base()		NULL
 #endif
 
 #ifdef CONFIG_GENERATE_ACPI_TABLE
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 0577238d60b..267f1db73f2 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -28,6 +28,9 @@ extern char __efi_helloworld_end[];
 extern char __efi_var_file_begin[];
 extern char __efi_var_file_end[];
 
+/* Private data used by of-platdata devices/uclasses */
+extern char __priv_data_start[], __priv_data_end[];
+
 /* Start and end of .ctors section - used for constructor calls. */
 extern char __ctors_start[], __ctors_end[];
 
-- 
2.30.0.478.g8a0d178c01-goog



More information about the U-Boot mailing list