[PATCH v3 27/28] dm: core: Drop seq and req_seq

Simon Glass sjg at chromium.org
Thu Dec 17 05:20:32 CET 2020


Now that migration to the new sequence numbers is complete, drop the old
fields. Add a test that covers the new behaviour.

Also drop the check for OF_PRIOR_STAGE since we always assign sequence
numbers now.

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

(no changes since v2)

Changes in v2:
- Adjust the tests to handle the new allocation scheme
- Simplify the logic so auto_seq is positive

 drivers/core/device-remove.c |  1 -
 drivers/core/device.c        | 17 ++--------------
 include/dm/device.h          |  9 +--------
 test/dm/test-fdt.c           | 39 ++++++++++++++++++++++++++++++++++++
 4 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 9f7615dea72..289220b98e8 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -207,7 +207,6 @@ int device_remove(struct udevice *dev, uint flags)
 	if (flags_remove(flags, drv->flags)) {
 		device_free(dev);
 
-		dev->seq = -1;
 		dev->flags &= ~DM_FLAG_ACTIVATED;
 	}
 
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 4abb5be56a4..d1a08ce7834 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -72,30 +72,18 @@ static int device_bind_common(struct udevice *parent, const struct driver *drv,
 	dev->driver = drv;
 	dev->uclass = uc;
 
-	dev->seq = -1;
-	dev->req_seq = -1;
 	dev->sqq = -1;
 	if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
 	    (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
 		/*
 		 * Some devices, such as a SPI bus, I2C bus and serial ports
 		 * are numbered using aliases.
-		 *
-		 * This is just a 'requested' sequence, and will be
-		 * resolved (and ->seq updated) when the device is probed.
 		 */
 		if (CONFIG_IS_ENABLED(OF_CONTROL) &&
 		    !CONFIG_IS_ENABLED(OF_PLATDATA)) {
 			if (uc->uc_drv->name && ofnode_valid(node)) {
-				dev_read_alias_seq(dev, &dev->sqq);
-				dev_read_alias_seq(dev, &dev->req_seq);
-				auto_seq = false;
-			}
-			if (CONFIG_IS_ENABLED(OF_PRIOR_STAGE)) {
-				if (dev->req_seq == -1) {
-					dev->req_seq =
-						uclass_find_next_free_seq(uc);
-				}
+				if (!dev_read_alias_seq(dev, &dev->sqq))
+					auto_seq = false;
 			}
 		}
 	}
@@ -509,7 +497,6 @@ fail_uclass:
 fail:
 	dev->flags &= ~DM_FLAG_ACTIVATED;
 
-	dev->seq = -1;
 	device_free(dev);
 
 	return ret;
diff --git a/include/dm/device.h b/include/dm/device.h
index 75f75497c5f..30fc98dc345 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -131,16 +131,11 @@ enum {
  * @child_head: List of children of this device
  * @sibling_node: Next device in list of all devices
  * @flags: Flags for this device DM_FLAG_...
- * @sqq: Allocated sequence number for this device (-1 = none). This is set up
+ * @seq: Allocated sequence number for this device (-1 = none). This is set up
  * when the device is bound and is unique within the device's uclass. If the
  * device has an alias in the devicetree then that is used to set the sequence
  * number. Otherwise, the next available number is used. Sequence numbers are
  * used by certain commands that need device to be numbered (e.g. 'mmc dev')
- *
- * The following two fields are deprecated:
- * @req_seq: Requested sequence number for this device (-1 = any)
- * @seq: Allocated sequence number for this device (-1 = none). This is set up
- * when the device is probed and will be unique within the device's uclass.
  * @devres_head: List of memory allocations associated with this device.
  *		When CONFIG_DEVRES is enabled, devm_kmalloc() and friends will
  *		add to this list. Memory so-allocated will be freed
@@ -164,8 +159,6 @@ struct udevice {
 	struct list_head sibling_node;
 	uint32_t flags;
 	int sqq;
-	int req_seq;
-	int seq;
 #ifdef CONFIG_DEVRES
 	struct list_head devres_head;
 #endif
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 5f443bdb6c0..eb3c2cf161b 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -441,6 +441,45 @@ static int dm_test_fdt_uclass_seq_manual(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_fdt_uclass_seq_manual, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
 
+static int dm_test_fdt_uclass_seq_more(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	ofnode node;
+
+	/* Check creating a device with an alias */
+	node = ofnode_path("/some-bus/c-test at 1");
+	ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+				"c-test at 1", NULL, node, &dev));
+	ut_asserteq(12, dev_seq(dev));
+	ut_assertok(uclass_get_device_by_seq(UCLASS_TEST_FDT, 12, &dev));
+	ut_asserteq_str("c-test at 1", dev->name);
+
+	/*
+	 * Now bind a device without an alias. It should not get the next
+	 * sequence number after all aliases, and existing bound devices. The
+	 * last alias is 12, so we have:
+	 *
+	 * 13 d-test
+	 * 14 f-test
+	 * 15 g-test
+	 * 16 h-test
+	 * 17 another-test
+	 * 18 chosen-test
+	 *
+	 * So next available is 19
+	 */
+	ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+				"fred", NULL, ofnode_null(), &dev));
+	ut_asserteq(19, dev_seq(dev));
+
+	ut_assertok(device_bind(dm_root(), DM_GET_DRIVER(testfdt_drv),
+				"fred2", NULL, ofnode_null(), &dev));
+	ut_asserteq(20, dev_seq(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_fdt_uclass_seq_more, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
 /* Test that we can find a device by device tree offset */
 static int dm_test_fdt_offset(struct unit_test_state *uts)
 {
-- 
2.29.2.684.gfbc64c5ab5-goog



More information about the U-Boot mailing list