All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v4 05/42] dm: core: Allow dropping run-time binding of devices
Date: Mon, 15 Mar 2021 17:25:15 +1300	[thread overview]
Message-ID: <20210315172537.v4.5.I2883cc0cb1edf613bf2dfb30e4bf982cf03daafc@changeid> (raw)
In-Reply-To: <20210315042553.1932494-1-sjg@chromium.org>

With OF_PLATDATA_INST devices are bound at build time. We should not need
binding of devices at runtime in most cases. However it is inflexible to
absolutely prohibit it, so add an option to control this.

Update the driver model core so that it does not bind devices. Update
device_bind() to return an error if called.

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

(no changes since v3)

Changes in v3:
- Update the commit message to explain OF_PLATDATA_NO_BIND better
- Update OF_PLATDATA_NO_BIND help as well

 drivers/core/device.c | 42 +++++++++++++++++++++++++-----------------
 dts/Kconfig           | 18 ++++++++++++++++++
 2 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/drivers/core/device.c b/drivers/core/device.c
index 81f6880eac4..e915b3089de 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -45,6 +45,9 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
 	bool auto_seq = true;
 	void *ptr;
 
+	if (CONFIG_IS_ENABLED(OF_PLATDATA_NO_BIND))
+		return -ENOSYS;
+
 	if (devp)
 		*devp = NULL;
 	if (!name)
@@ -395,26 +398,31 @@ int device_of_to_plat(struct udevice *dev)
 	if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
 		return 0;
 
-	/* Ensure all parents have ofdata */
-	if (dev->parent) {
-		ret = device_of_to_plat(dev->parent);
+	/*
+	 * This is not needed if binding is disabled, since data is allocated
+	 * at build time.
+	 */
+	if (!CONFIG_IS_ENABLED(OF_PLATDATA_NO_BIND)) {
+		/* Ensure all parents have ofdata */
+		if (dev->parent) {
+			ret = device_of_to_plat(dev->parent);
+			if (ret)
+				goto fail;
+
+			/*
+			 * The device might have already been probed during
+			 * the call to device_probe() on its parent device
+			 * (e.g. PCI bridge devices). Test the flags again
+			 * so that we don't mess up the device.
+			 */
+			if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
+				return 0;
+		}
+
+		ret = device_alloc_priv(dev);
 		if (ret)
 			goto fail;
-
-		/*
-		 * The device might have already been probed during
-		 * the call to device_probe() on its parent device
-		 * (e.g. PCI bridge devices). Test the flags again
-		 * so that we don't mess up the device.
-		 */
-		if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
-			return 0;
 	}
-
-	ret = device_alloc_priv(dev);
-	if (ret)
-		goto fail;
-
 	drv = dev->driver;
 	assert(drv);
 
diff --git a/dts/Kconfig b/dts/Kconfig
index c39cc368881..d289752a139 100644
--- a/dts/Kconfig
+++ b/dts/Kconfig
@@ -371,6 +371,15 @@ config SPL_OF_PLATDATA_INST
 	  Declare devices as udevice instances so that they do not need to be
 	  bound when U-Boot starts. This can save time and code space.
 
+config SPL_OF_PLATDATA_NO_BIND
+	bool "Don't allow run-time binding of devices"
+	depends on SPL_OF_PLATDATA_INST
+	default y
+	help
+	  This removes the ability to bind devices at run time, thus saving
+	  some code space in U-Boot. This can be disabled if binding is needed,
+	  at the code of some code size increase.
+
 endif
 
 config TPL_OF_PLATDATA
@@ -411,6 +420,15 @@ config TPL_OF_PLATDATA_INST
 	  Declare devices as udevice instances so that they do not need to be
 	  bound when U-Boot starts. This can save time and code space.
 
+config TPL_OF_PLATDATA_NO_BIND
+	bool "Don't allow run-time binding of devices"
+	depends on TPL_OF_PLATDATA_INST
+	default y
+	help
+	  This removes the ability to bind devices at run time, thus saving
+	  some code space in U-Boot. This can be disabled if binding is needed,
+	  at the code of some code size increase.
+
 endif
 
 endmenu
-- 
2.31.0.rc2.261.g7f71774620-goog

  parent reply	other threads:[~2021-03-15  4:25 UTC|newest]

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