All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH 19/19] dm: devres: Add a new OFDATA phase
Date: Sun, 29 Dec 2019 21:19:28 -0700	[thread overview]
Message-ID: <20191229211913.19.I74bb68c045c73ec453a9b95e6c407ec82c845573@changeid> (raw)
In-Reply-To: <20191230041928.74874-1-sjg@chromium.org>

Since the ofdata_to_platdata() method can allocate resources, add it as a
new devres phase.

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

 drivers/core/devres.c | 18 +++++++++++++-----
 include/test/test.h   |  3 ++-
 test/dm/devres.c      | 14 +++++++++++---
 test/dm/test-fdt.c    | 11 +++++++++++
 4 files changed, 37 insertions(+), 9 deletions(-)

diff --git a/drivers/core/devres.c b/drivers/core/devres.c
index 5376118f12..237b42653c 100644
--- a/drivers/core/devres.c
+++ b/drivers/core/devres.c
@@ -20,10 +20,12 @@
 /** enum devres_phase - Shows where resource was allocated
  *
  * DEVRES_PHASE_BIND: In the bind() method
+ * DEVRES_PHASE_OFDATA: In the ofdata_to_platdata() method
  * DEVRES_PHASE_PROBE: In the probe() method
  */
 enum devres_phase {
 	DEVRES_PHASE_BIND,
+	DEVRES_PHASE_OFDATA,
 	DEVRES_PHASE_PROBE,
 };
 
@@ -102,8 +104,12 @@ void devres_add(struct udevice *dev, void *res)
 
 	devres_log(dev, dr, "ADD");
 	assert_noisy(list_empty(&dr->entry));
-	dr->phase = dev->flags & DM_FLAG_BOUND ? DEVRES_PHASE_PROBE :
-		DEVRES_PHASE_BIND;
+	if (dev->flags & DM_FLAG_PLATDATA_VALID)
+		dr->phase = DEVRES_PHASE_PROBE;
+	else if (dev->flags & DM_FLAG_BOUND)
+		dr->phase = DEVRES_PHASE_OFDATA;
+	else
+		dr->phase = DEVRES_PHASE_BIND;
 	list_add_tail(&dr->entry, &dev->devres_head);
 }
 
@@ -184,12 +190,12 @@ int devres_release(struct udevice *dev, dr_release_t release,
 }
 
 static void release_nodes(struct udevice *dev, struct list_head *head,
-			  bool probe_only)
+			  bool probe_and_ofdata_only)
 {
 	struct devres *dr, *tmp;
 
 	list_for_each_entry_safe_reverse(dr, tmp, head, entry)  {
-		if (probe_only && dr->phase != DEVRES_PHASE_PROBE)
+		if (probe_and_ofdata_only && dr->phase == DEVRES_PHASE_BIND)
 			break;
 		devres_log(dev, dr, "REL");
 		dr->release(dev, dr->data);
@@ -209,6 +215,8 @@ void devres_release_all(struct udevice *dev)
 }
 
 #ifdef CONFIG_DEBUG_DEVRES
+static char *const devres_phase_name[] = {"BIND", "OFDATA", "PROBE"};
+
 static void dump_resources(struct udevice *dev, int depth)
 {
 	struct devres *dr;
@@ -219,7 +227,7 @@ static void dump_resources(struct udevice *dev, int depth)
 	list_for_each_entry(dr, &dev->devres_head, entry)
 		printf("    %p (%lu byte) %s  %s\n", dr,
 		       (unsigned long)dr->size, dr->name,
-		       dr->phase == DEVRES_PHASE_PROBE ? "PROBE" : "BIND");
+		       devres_phase_name[dr->phase]);
 
 	list_for_each_entry(child, &dev->child_head, sibling_node)
 		dump_resources(child, depth + 1);
diff --git a/include/test/test.h b/include/test/test.h
index 5977c59d3f..e5bef4759a 100644
--- a/include/test/test.h
+++ b/include/test/test.h
@@ -52,8 +52,9 @@ enum {
 	TEST_DEVRES_COUNT	= 10,
 	TEST_DEVRES_TOTAL	= TEST_DEVRES_SIZE * TEST_DEVRES_COUNT,
 
-	/* A different size */
+	/* A few different sizes */
 	TEST_DEVRES_SIZE2	= 15,
+	TEST_DEVRES_SIZE3	= 37,
 };
 
 #endif /* __TEST_TEST_H */
diff --git a/test/dm/devres.c b/test/dm/devres.c
index c351844db9..e7331897de 100644
--- a/test/dm/devres.c
+++ b/test/dm/devres.c
@@ -140,6 +140,7 @@ static int dm_test_devres_kcalloc(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_devres_kcalloc, DM_TESTF_SCAN_PDATA);
 
+/* Test devres releases resources automatically as expected */
 static int dm_test_devres_phase(struct unit_test_state *uts)
 {
 	struct devres_stats stats;
@@ -154,14 +155,21 @@ static int dm_test_devres_phase(struct unit_test_state *uts)
 	ut_asserteq(1, stats.allocs);
 	ut_asserteq(TEST_DEVRES_SIZE, stats.total_size);
 
+	/* Getting platdata should add one allocation */
+	ut_assertok(device_ofdata_to_platdata(dev));
+	devres_get_stats(dev, &stats);
+	ut_asserteq(2, stats.allocs);
+	ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE3, stats.total_size);
+
 	/* Probing the device should add one allocation */
 	ut_assertok(uclass_first_device(UCLASS_TEST_DEVRES, &dev));
 	ut_assert(dev != NULL);
 	devres_get_stats(dev, &stats);
-	ut_asserteq(2, stats.allocs);
-	ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2, stats.total_size);
+	ut_asserteq(3, stats.allocs);
+	ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2 + TEST_DEVRES_SIZE3,
+		    stats.total_size);
 
-	/* Removing the device should drop one allocation */
+	/* Removing the device should drop both those allocations */
 	device_remove(dev, DM_REMOVE_NORMAL);
 	devres_get_stats(dev, &stats);
 	ut_asserteq(1, stats.allocs);
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index bbac37761d..d59c449ce0 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -159,6 +159,7 @@ struct dm_testdevres_pdata {
 
 struct dm_testdevres_priv {
 	void *ptr;
+	void *ptr_ofdata;
 };
 
 static int testdevres_drv_bind(struct udevice *dev)
@@ -170,6 +171,15 @@ static int testdevres_drv_bind(struct udevice *dev)
 	return 0;
 }
 
+static int testdevres_drv_ofdata_to_platdata(struct udevice *dev)
+{
+	struct dm_testdevres_priv *priv = dev_get_priv(dev);
+
+	priv->ptr_ofdata = devm_kmalloc(dev, TEST_DEVRES_SIZE3, 0);
+
+	return 0;
+}
+
 static int testdevres_drv_probe(struct udevice *dev)
 {
 	struct dm_testdevres_priv *priv = dev_get_priv(dev);
@@ -189,6 +199,7 @@ U_BOOT_DRIVER(testdevres_drv) = {
 	.of_match	= testdevres_ids,
 	.id	= UCLASS_TEST_DEVRES,
 	.bind	= testdevres_drv_bind,
+	.ofdata_to_platdata	= testdevres_drv_ofdata_to_platdata,
 	.probe	= testdevres_drv_probe,
 	.platdata_auto_alloc_size	= sizeof(struct dm_testdevres_pdata),
 	.priv_auto_alloc_size	= sizeof(struct dm_testdevres_priv),
-- 
2.24.1.735.g03f4e72817-goog

  parent reply	other threads:[~2019-12-30  4:19 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30  4:19 [PATCH 00/19] dm: core: Fully separate ofdata_to_platdata() from probe() Simon Glass
2019-12-30  4:19 ` [PATCH 01/19] common: Add a noisy assert() Simon Glass
2019-12-30  4:19 ` [PATCH 02/19] dm: core: Use assert_noisy() in devres Simon Glass
2019-12-30  4:19 ` [PATCH 03/19] usb: Drop use of BUG_ON() and WARN_ON() Simon Glass
2019-12-30  4:19 ` [PATCH 04/19] x86: apl: Avoid accessing the PCI bus before it is probed Simon Glass
2019-12-30  4:19 ` [PATCH 05/19] pci: Print a warning if the bus is accessed before probing Simon Glass
2019-12-30  4:19 ` [PATCH 06/19] aspeed: ast2500: Read clock ofdata in the correct method Simon Glass
2020-01-07  8:20   ` Cédric Le Goater
2020-01-09 20:04     ` Simon Glass
2020-01-10  8:57     ` sjg at google.com
2019-12-30  4:19 ` [PATCH 07/19] dm: core: Don't clear active flag twice when probe() fails Simon Glass
2019-12-30  4:19 ` [PATCH 08/19] dm: core: Move ofdata_to_platdata() call earlier Simon Glass
2019-12-30  4:19 ` [PATCH 09/19] dm: core: Allocate parent data separate from probing parent Simon Glass
2019-12-30  4:19 ` [PATCH 10/19] dm: core: Add a comment for DM_FLAG_OF_PLATDATA Simon Glass
2019-12-30  4:19 ` [PATCH 11/19] dm: core: Export a new function to read platdata Simon Glass
2019-12-30  4:19 ` [PATCH 12/19] dm: core: Add a new flag to track platform data Simon Glass
2019-12-30  4:19 ` [PATCH 13/19] dm: devres: Create a new devres header file Simon Glass
2019-12-30  4:19 ` [PATCH 14/19] test: Add functions to find the amount of allocated memory Simon Glass
2019-12-30  4:19 ` [PATCH 15/19] dm: devres: Convert to use logging Simon Glass
2019-12-30  4:19 ` [PATCH 16/19] dm: test: Add a test driver for devres Simon Glass
2019-12-30  4:19 ` [PATCH 17/19] dm: devres: Add tests Simon Glass
2019-12-30  4:19 ` [PATCH 18/19] dm: devres: Use an enum for the allocation phase Simon Glass
2019-12-30  4:19 ` Simon Glass [this message]
2020-01-10  8:57 ` sjg at google.com
2020-01-10  8:57 ` [PATCH 19/19] dm: devres: Add a new OFDATA phase sjg at google.com
2020-01-10  8:57 ` [PATCH 17/19] dm: devres: Add tests sjg at google.com
2020-01-10  8:57 ` [PATCH 16/19] dm: test: Add a test driver for devres sjg at google.com
2020-01-10  8:57 ` [PATCH 14/19] test: Add functions to find the amount of allocated memory sjg at google.com
2020-01-10  8:57 ` [PATCH 15/19] dm: devres: Convert to use logging sjg at google.com
2020-01-10  8:57 ` [PATCH 13/19] dm: devres: Create a new devres header file sjg at google.com
2020-01-10  8:57 ` [PATCH 12/19] dm: core: Add a new flag to track platform data sjg at google.com
2020-01-10  8:57 ` [PATCH 11/19] dm: core: Export a new function to read platdata sjg at google.com
2020-01-10  8:57 ` [PATCH 10/19] dm: core: Add a comment for DM_FLAG_OF_PLATDATA sjg at google.com
2020-01-10  8:57 ` [PATCH 09/19] dm: core: Allocate parent data separate from probing parent sjg at google.com
2020-01-10  8:57 ` [PATCH 08/19] dm: core: Move ofdata_to_platdata() call earlier sjg at google.com
2020-01-10  8:57 ` [PATCH 07/19] dm: core: Don't clear active flag twice when probe() fails sjg at google.com
2020-01-10  8:57 ` [PATCH 05/19] pci: Print a warning if the bus is accessed before probing sjg at google.com
2020-01-10  8:57 ` [PATCH 04/19] x86: apl: Avoid accessing the PCI bus before it is probed sjg at google.com
2020-01-10  8:57 ` [PATCH 03/19] usb: Drop use of BUG_ON() and WARN_ON() sjg at google.com
2020-01-10  8:57 ` [PATCH 02/19] dm: core: Use assert_noisy() in devres sjg at google.com
2020-01-10  8:57 ` [PATCH 01/19] common: Add a noisy assert() sjg at google.com

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=20191229211913.19.I74bb68c045c73ec453a9b95e6c407ec82c845573@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.