All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v2 25/37] dm: core: Create a struct for device runtime info
Date: Wed,  3 Feb 2021 09:43:41 -0700	[thread overview]
Message-ID: <20210203094345.v2.25.I6420b248f58963ecf5c57a67b084d782478ae8c8@changeid> (raw)
In-Reply-To: <20210203164353.2577985-1-sjg@chromium.org>

At present when driver model needs to change a device it simply updates
the struct udevice structure. But with of-platdata-inst most of the fields
are not modified at runtime. In fact, typically only the flags need to
change.

For systems running SPL from read-only memory it is convenient to separate
out the runtime information, so that the devices don't need to be copied
before being used.

Create a new udevice_rt table, similar to the existing driver_rt. For now
it just holds the flags, although they are not used in this patch.

Add a new Kconfig for the driver_rt data, since this is not needed when
of-platdata-inst is used.

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

Changes in v2:
- Use separate OF_PLATDATA_DRIVER_RT Kconfigs for driver run-time data
- Update the condition for dm_test_of_plat_dev()

 drivers/core/root.c               | 14 +++++++++++++-
 dts/Kconfig                       | 20 ++++++++++++++++++++
 include/asm-generic/global_data.h | 16 ++++++++++++++--
 include/dm/device.h               | 15 +++++++++++++++
 test/dm/of_platdata.c             |  2 +-
 5 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/drivers/core/root.c b/drivers/core/root.c
index 75513c2ab25..2591eb62347 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -132,6 +132,18 @@ static int dm_setup_inst(void)
 {
 	DM_ROOT_NON_CONST = DM_DEVICE_GET(root);
 
+	if (CONFIG_IS_ENABLED(OF_PLATDATA_RT)) {
+		struct udevice_rt *urt;
+		int n_ents;
+
+		/* Allocate the udevice_rt table */
+		n_ents = ll_entry_count(struct udevice, udevice);
+		urt = calloc(n_ents, sizeof(struct udevice_rt));
+		if (!urt)
+			return log_msg_ret("urt", -ENOMEM);
+		gd_set_dm_udevice_rt(urt);
+	}
+
 	return 0;
 }
 
@@ -202,7 +214,7 @@ int dm_scan_plat(bool pre_reloc_only)
 {
 	int ret;
 
-	if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
+	if (CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT)) {
 		struct driver_rt *dyn;
 		int n_ents;
 
diff --git a/dts/Kconfig b/dts/Kconfig
index a6bfa706637..40a6d7151d5 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -338,6 +338,7 @@ config SPL_OF_PLATDATA
 	bool "Generate platform data for use in SPL"
 	depends on SPL_OF_CONTROL
 	select DTOC
+	select SPL_OF_PLATDATA_DRIVER_RT if !SPL_OF_PLATDATA_INST
 	help
 	  For very constrained SPL environments the overhead of decoding
 	  device tree nodes and converting their contents into platform data
@@ -390,12 +391,22 @@ config SPL_OF_PLATDATA_RT
 	  struct udevice (at present just the flags) into a separate struct,
 	  which is allocated at runtime.
 
+config SPL_OF_PLATDATA_DRIVER_RT
+	bool
+	help
+	  Use a separate struct for driver runtime data.
+
+	  This enables the driver_rt information, used with of-platdata when
+	  of-platdata-inst is not used. It allows finding devices by their
+	  driver data.
+
 endif
 
 config TPL_OF_PLATDATA
 	bool "Generate platform data for use in TPL"
 	depends on TPL_OF_CONTROL
 	select DTOC
+	select TPL_OF_PLATDATA_DRIVER_RT if !TPL_OF_PLATDATA_INST
 	help
 	  For very constrained SPL environments the overhead of decoding
 	  device tree nodes and converting their contents into platform data
@@ -449,6 +460,15 @@ config TPL_OF_PLATDATA_RT
 	  struct udevice (at present just the flags) into a separate struct,
 	  which is allocated at runtime.
 
+config TPL_OF_PLATDATA_DRIVER_RT
+	bool
+	help
+	  Use a separate struct for driver runtime data.
+
+	  This enables the driver_rt information, used with of-platdata when
+	  of-platdata-inst is not used. It allows finding devices by their
+	  driver data.
+
 endif
 
 endmenu
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index b6f707e97e5..4fbfad8f70e 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -215,10 +215,14 @@ struct global_data {
 	 * @uclass_root_s.
 	 */
 	struct list_head *uclass_root;
-# if CONFIG_IS_ENABLED(OF_PLATDATA)
+# if CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT)
 	/** @dm_driver_rt: Dynamic info about the driver */
 	struct driver_rt *dm_driver_rt;
 # endif
+#if CONFIG_IS_ENABLED(OF_PLATDATA_RT)
+	/** @dm_udevice_rt: Dynamic info about the udevice */
+	struct udevice_rt *dm_udevice_rt;
+# endif
 #endif
 #ifdef CONFIG_TIMER
 	/**
@@ -471,7 +475,7 @@ struct global_data {
 #define gd_set_of_root(_root)
 #endif
 
-#if CONFIG_IS_ENABLED(OF_PLATDATA)
+#if CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT)
 #define gd_set_dm_driver_rt(dyn)	gd->dm_driver_rt = dyn
 #define gd_dm_driver_rt()		gd->dm_driver_rt
 #else
@@ -479,6 +483,14 @@ struct global_data {
 #define gd_dm_driver_rt()		NULL
 #endif
 
+#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
+#else
+#define gd_set_dm_udevice_rt(dyn)
+#define gd_dm_udevice_rt()		NULL
+#endif
+
 #ifdef CONFIG_GENERATE_ACPI_TABLE
 #define gd_acpi_ctx()		gd->acpi_ctx
 #else
diff --git a/include/dm/device.h b/include/dm/device.h
index 891a5f84243..cb165c2e922 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -174,6 +174,21 @@ struct udevice {
 #endif
 };
 
+/**
+ * udevice_rt - runtime information set up by U-Boot
+ *
+ * This is only used with OF_PLATDATA_RT
+ *
+ * There is one of these for every udevice in the linker list, indexed by
+ * the udevice_info idx value.
+ *
+ * @flags_: Flags for this device DM_FLAG_... (do not access outside driver
+ *	model)
+ */
+struct udevice_rt {
+	u32 flags_;
+};
+
 /* Maximum sequence number supported */
 #define DM_MAX_SEQ	999
 
diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index 81c8e3d5b60..15021335e9f 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -146,7 +146,7 @@ static int dm_test_of_plat_dev(struct unit_test_state *uts)
 	uint i;
 
 	/* Skip this test if there is no platform data */
-	if (CONFIG_IS_ENABLED(OF_PLATDATA_INST))
+	if (!CONFIG_IS_ENABLED(OF_PLATDATA_DRIVER_RT))
 		return 0;
 
 	/* Record the indexes that are found */
-- 
2.30.0.365.g02bc693789-goog

  parent reply	other threads:[~2021-02-03 16:43 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-03 16:43 [PATCH v2 00/37] dm: Implement OF_PLATDATA_INST in driver model (part E) Simon Glass
2021-02-03 16:43 ` [PATCH v2 01/37] sandbox: Drop debug message in os_spl_to_uboot() Simon Glass
2021-02-04 13:36   ` Heinrich Schuchardt
2021-02-03 16:43 ` [PATCH v2 02/37] linker_lists: Allow use in data structures Simon Glass
2021-02-04 13:54   ` Heinrich Schuchardt
2021-02-07 14:37     ` Simon Glass
2021-02-03 16:43 ` [PATCH v2 03/37] dm: core: Add macros to access the new linker lists Simon Glass
2021-02-04 13:46   ` Heinrich Schuchardt
2021-02-03 16:43 ` [PATCH v2 04/37] dm: core: Allow dropping run-time binding of devices Simon Glass
2021-02-04 13:57   ` Heinrich Schuchardt
2021-02-03 16:43 ` [PATCH v2 05/37] dm: core: Adjust uclass setup with of-platdata Simon Glass
2021-02-03 16:43 ` [PATCH v2 06/37] dm: core: Set up driver model for OF_PLATDATA_INST Simon Glass
2021-02-03 16:43 ` [PATCH v2 07/37] dm: core: Skip adding uclasses with OF_PLATDATA_INST Simon Glass
2021-02-03 16:43 ` [PATCH v2 08/37] dm: Add the new dtoc-generated files to the build Simon Glass
2021-02-03 16:43 ` [PATCH v2 09/37] dm: core: Include dt-decl.h automatically Simon Glass
2021-02-03 16:43 ` [PATCH v2 10/37] dm: test: Avoid destroying uclasses with of-platdata-inst Simon Glass
2021-02-03 16:43 ` [PATCH v2 11/37] clk: sandbox: Move priv/plat data to a header file Simon Glass
2021-02-03 16:43 ` [PATCH v2 12/37] clk: fixed-rate: Export driver parts for OF_PLATDATA_INST Simon Glass
2021-02-03 16:43 ` [PATCH v2 13/37] clk: sandbox: Create a special fixed-rate driver Simon Glass
2021-02-03 16:43 ` [PATCH v2 14/37] dm: core: Drop device_get_by_driver_info() Simon Glass
2021-02-03 16:43 ` [PATCH v2 15/37] dm: core: Drop uclass_find_device_by_phandle() with of-platdata Simon Glass
2021-02-03 16:43 ` [PATCH v2 16/37] sandbox: i2c: Move platdata structs to header files Simon Glass
2021-02-03 16:43 ` [PATCH v2 17/37] dm: Rename device_get_by_driver_info_idx() Simon Glass
2021-02-03 16:43 ` [PATCH v2 18/37] sandbox_spl: Increase SPL malloc() size Simon Glass
2021-02-04 14:01   ` Heinrich Schuchardt
2021-02-03 16:43 ` [PATCH v2 19/37] sandbox: i2c: Support i2c emulation with of-platdata Simon Glass
2021-02-03 16:43 ` [PATCH v2 20/37] Revert "sandbox: Disable I2C emulators in SPL" Simon Glass
2021-02-03 16:43 ` [PATCH v2 21/37] sandbox: Create a new sandbox_noinst build Simon Glass
2021-02-03 16:43 ` [PATCH v2 22/37] test: Run sandbox_spl tests on sandbox_noinst Simon Glass
2021-02-03 16:43 ` [PATCH v2 23/37] azure/gitlab: Add tests for sandbox_noinst Simon Glass
2021-02-03 16:43 ` [PATCH v2 24/37] dm: core: Add an option to support SPL in read-only memory Simon Glass
2021-02-03 16:43 ` Simon Glass [this message]
2021-02-03 16:43 ` [PATCH v2 26/37] dm: core: Move flags to device-runtime info Simon Glass
2021-02-03 16:43 ` [PATCH v2 27/37] dm: core: Allow storing priv/plat data separately Simon Glass
2021-02-03 16:43 ` [PATCH v2 28/37] sandbox: Define a region for device priv/plat data Simon Glass
2021-02-03 16:43 ` [PATCH v2 29/37] dm: core: Use separate priv/plat data region Simon Glass
2021-02-03 16:43 ` [PATCH v2 30/37] x86: Define a region for device priv/plat data Simon Glass
2021-02-03 16:43 ` [PATCH v2 31/37] x86: apl: Fix the header order in pmc Simon Glass
2021-02-03 16:43 ` [PATCH v2 32/37] x86: apl: Tell of-platdata about a required header file Simon Glass
2021-02-03 16:43 ` [PATCH v2 33/37] x86: itss: Tidy up bind() for of-platdata-inst Simon Glass
2021-02-03 16:43 ` [PATCH v2 34/37] x86: Support a fake PCI device with of-platdata-inst Simon Glass
2021-02-03 16:43 ` [PATCH v2 35/37] x86: Don't include reset driver in SPL Simon Glass
2021-02-03 16:43 ` [PATCH v2 36/37] x86: coral: Drop ACPI properties from of-platdata Simon Glass
2021-02-03 16:43 ` [PATCH v2 37/37] x86: apl: Use read-only SPL and new of-platdata Simon Glass
2021-02-04  7:48 ` [PATCH v2 00/37] dm: Implement OF_PLATDATA_INST in driver model (part E) Heinrich Schuchardt
2021-02-04 15:08   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210203094345.v2.25.I6420b248f58963ecf5c57a67b084d782478ae8c8@changeid \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.