[PATCH 12/35] efi: Add EFI uclass for media

Simon Glass sjg at chromium.org
Wed Sep 8 15:33:42 CEST 2021


At present UCLASS_EFI is used to represent an EFI filesystem The
description of this uclass is "EFI managed devices" which is pretty vague.
The only driver that uses this uclass is in fact not a real U-Boot driver,
since its operations do not include a struct udevice.

Rather than mess with this, create a new UCLASS_EFI_MEDIA uclass to handle
EFI media such as disks. Make this the uclass to use for EFI media.

The existing implementation using UCLASS_EFI remains as is, for
discussion.

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

 arch/sandbox/dts/test.dts        |  4 ++++
 drivers/block/Kconfig            | 23 +++++++++++++++++++++++
 drivers/block/Makefile           |  3 +++
 drivers/block/blk-uclass.c       |  2 +-
 drivers/block/efi-media-uclass.c | 15 +++++++++++++++
 drivers/block/sb_efi_media.c     | 21 +++++++++++++++++++++
 include/dm/uclass-id.h           |  1 +
 test/dm/Makefile                 |  1 +
 test/dm/efi_media.c              | 24 ++++++++++++++++++++++++
 9 files changed, 93 insertions(+), 1 deletion(-)
 create mode 100644 drivers/block/efi-media-uclass.c
 create mode 100644 drivers/block/sb_efi_media.c
 create mode 100644 test/dm/efi_media.c

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 962bdbe5567..af88cf681ae 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -486,6 +486,10 @@
 		compatible = "sandbox,clk-ccf";
 	};
 
+	efi-media {
+		compatible = "sandbox,efi-media";
+	};
+
 	eth at 10002000 {
 		compatible = "sandbox,eth";
 		reg = <0x10002000 0x1000>;
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 4023332dd98..058956ee8ee 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -63,6 +63,29 @@ config TPL_BLOCK_CACHE
 	help
 	  This option enables the disk-block cache in TPL
 
+config EFI_MEDIA
+	bool "Support EFI media drivers"
+	default y if EFI || SANDBOX
+	help
+	  Enable this to support media devices on top of UEFI. This enables
+	  just the uclass so you also need a specific driver to make this do
+	  anything.
+
+	  For sandbox there is a test driver.
+
+if EFI_MEDIA
+
+config EFI_MEDIA_SANDBOX
+	bool "Sandbox EFI media driver"
+	depends on SANDBOX
+	default y
+	help
+	  Enables a simple sandbox media driver, used for testing just the
+	  EFI_MEDIA uclass. It does not do anything useful, since sandbox does
+	  not actually support running on top of UEFI.
+
+endif  # EFI_MEDIA
+
 config IDE
 	bool "Support IDE controllers"
 	select HAVE_BLOCK_DEVICE
diff --git a/drivers/block/Makefile b/drivers/block/Makefile
index 94ab5c6f906..3778633da1d 100644
--- a/drivers/block/Makefile
+++ b/drivers/block/Makefile
@@ -14,3 +14,6 @@ obj-$(CONFIG_IDE) += ide.o
 endif
 obj-$(CONFIG_SANDBOX) += sandbox.o
 obj-$(CONFIG_$(SPL_TPL_)BLOCK_CACHE) += blkcache.o
+
+obj-$(CONFIG_EFI_MEDIA) += efi-media-uclass.o
+obj-$(CONFIG_EFI_MEDIA_SANDBOX) += sb_efi_media.o
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 83682dcc181..2db7ce5de20 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -44,7 +44,7 @@ static enum uclass_id if_type_uclass_id[IF_TYPE_COUNT] = {
 	[IF_TYPE_SATA]		= UCLASS_AHCI,
 	[IF_TYPE_HOST]		= UCLASS_ROOT,
 	[IF_TYPE_NVME]		= UCLASS_NVME,
-	[IF_TYPE_EFI]		= UCLASS_EFI,
+	[IF_TYPE_EFI]		= UCLASS_EFI_MEDIA,
 	[IF_TYPE_VIRTIO]	= UCLASS_VIRTIO,
 	[IF_TYPE_PVBLOCK]	= UCLASS_PVBLOCK,
 };
diff --git a/drivers/block/efi-media-uclass.c b/drivers/block/efi-media-uclass.c
new file mode 100644
index 00000000000..e012f6f2f4c
--- /dev/null
+++ b/drivers/block/efi-media-uclass.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Uclass for EFI media devices
+ *
+ * Copyright 2021 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+
+UCLASS_DRIVER(efi_media) = {
+	.id		= UCLASS_EFI_MEDIA,
+	.name		= "efi_media",
+	.flags		= DM_UC_FLAG_SEQ_ALIAS,
+};
diff --git a/drivers/block/sb_efi_media.c b/drivers/block/sb_efi_media.c
new file mode 100644
index 00000000000..4f242aa13a4
--- /dev/null
+++ b/drivers/block/sb_efi_media.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * EFI_MEDIA driver for sandbox
+ *
+ * Copyright 2021 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+
+static const struct udevice_id sandbox_efi_media_ids[] = {
+	{ .compatible = "sandbox,efi-media" },
+	{ }
+};
+
+
+U_BOOT_DRIVER(sandbox_efi_media) = {
+	.name		= "sandbox_efi_media",
+	.id		= UCLASS_EFI_MEDIA,
+	.of_match	= sandbox_efi_media_ids,
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index e7edd409f30..4906eb836c2 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -49,6 +49,7 @@ enum uclass_id {
 	UCLASS_DSA,		/* Distributed (Ethernet) Switch Architecture */
 	UCLASS_ECDSA,		/* Elliptic curve cryptographic device */
 	UCLASS_EFI,		/* EFI managed devices */
+	UCLASS_EFI_MEDIA,	/* EFI media (e.g. a disk) */
 	UCLASS_ETH,		/* Ethernet device */
 	UCLASS_ETH_PHY,		/* Ethernet PHY device */
 	UCLASS_FIRMWARE,	/* Firmware */
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 516f69d61cb..d9bc37d8313 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -37,6 +37,7 @@ obj-$(CONFIG_DMA) += dma.o
 obj-$(CONFIG_VIDEO_MIPI_DSI) += dsi_host.o
 obj-$(CONFIG_DM_DSA) += dsa.o
 obj-$(CONFIG_ECDSA_VERIFY) += ecdsa.o
+obj-$(CONFIG_EFI_MEDIA_SANDBOX) += efi_media.o
 obj-$(CONFIG_DM_ETH) += eth.o
 ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
diff --git a/test/dm/efi_media.c b/test/dm/efi_media.c
new file mode 100644
index 00000000000..e343a0e9c85
--- /dev/null
+++ b/test/dm/efi_media.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Test for EFI_MEDIA uclass
+ *
+ * Copyright 2021 Google LLC
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* Test that we can use the EFI_MEDIA uclass */
+static int dm_test_efi_media(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_first_device_err(UCLASS_EFI_MEDIA, &dev));
+
+	return 0;
+}
+DM_TEST(dm_test_efi_media, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
-- 
2.33.0.153.gba50c8fa24-goog



More information about the U-Boot mailing list