Skip to contentSkip to conversation

dm: fpga: Introduce new uclass

RFC PATCH Superseded Alexander Dahl 2 participants 3 messages Sep 26, 2022 – Sep 30, 2022 FPGA manager framework

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 dm: fpga: Introduce new uclass

For future DM based FPGA drivers and for now to have a meaningful logging class for old FPGA drivers.

---
 arch/sandbox/dts/test.dts  |  4 ++++
 drivers/fpga/Kconfig       | 14 ++++++++++++++
 drivers/fpga/Makefile      |  3 +++
 drivers/fpga/fpga-uclass.c | 11 +++++++++++
 drivers/fpga/sandbox.c     | 11 +++++++++++
 include/dm/uclass-id.h     |  1 +
 test/dm/Makefile           |  1 +
 test/dm/fpga.c             | 20 ++++++++++++++++++++
 8 files changed, 65 insertions(+)
 create mode 100644 drivers/fpga/fpga-uclass.c
 create mode 100644 drivers/fpga/sandbox.c
 create mode 100644 test/dm/fpga.c
arch/sandbox/dts/test.dts +4 -0
index 2761588f0d..3b9cc8cd7c 100644
@@ -650,6 +650,10 @@
 		};
 	};
 
+	fpga {
+		compatible = "sandbox,fpga";
+	};
+
 	pinctrl-gpio {
 		compatible = "sandbox,pinctrl-gpio";
 
drivers/fpga/Kconfig +14 -0
index e07a9cf80e..2ad1ff60b6 100644
@@ -118,4 +118,18 @@ config SPL_FPGA_LOAD_SECURE
 	  Enables the fpga loads() functions that are used to load secure
 	  (authenticated or encrypted or both) bitstreams on to FPGA.
 
+config DM_FPGA
+	bool "Enable Driver Model for FPGA drivers"
+	depends on DM
+	select FPGA
+	help
+	  Enable driver model for FPGA.
+	  For now this is uclass only without a real driver using it.
+
+config SANDBOX_FPGA
+	bool "Enable sandbox FPGA driver"
+	depends on SANDBOX && DM_FPGA
+	help
+	  tbd
+
 endmenu
drivers/fpga/Makefile +3 -0
index 83243fb107..610c168fc3 100644
@@ -4,6 +4,9 @@
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
 obj-y += fpga.o
+obj-$(CONFIG_DM_FPGA) += fpga-uclass.o
+obj-$(CONFIG_SANDBOX_FPGA) += sandbox.o
+
 obj-$(CONFIG_FPGA_SPARTAN2) += spartan2.o
 obj-$(CONFIG_FPGA_SPARTAN3) += spartan3.o
 obj-$(CONFIG_FPGA_VERSALPL) += versalpl.o
drivers/fpga/fpga-uclass.c new file +11 -0
new file mode 100644
index 0000000000..4278ec28e5
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+
+UCLASS_DRIVER(fpga) = {
+	.name	= "fpga",
+	.id	= UCLASS_FPGA,
+};
drivers/fpga/sandbox.c new file +11 -0
new file mode 100644
index 0000000000..5687efccb1
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+
+U_BOOT_DRIVER(sandbox_fpga) = {
+	.name	= "sandbox_fpga",
+	.id	= UCLASS_FPGA,
+};
include/dm/uclass-id.h +1 -0
index a432e43871..c2b15881ba 100644
@@ -56,6 +56,7 @@ enum uclass_id {
 	UCLASS_ETH,		/* Ethernet device */
 	UCLASS_ETH_PHY,		/* Ethernet PHY device */
 	UCLASS_FIRMWARE,	/* Firmware */
+	UCLASS_FPGA,		/* FPGA device */
 	UCLASS_FUZZING_ENGINE,	/* Fuzzing engine */
 	UCLASS_FS_FIRMWARE_LOADER,		/* Generic loader */
 	UCLASS_GPIO,		/* Bank of general-purpose I/O pins */
test/dm/Makefile +1 -0
index 7543df8823..666c85f10a 100644
@@ -47,6 +47,7 @@ ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
 obj-$(CONFIG_FIRMWARE) += firmware.o
+obj-$(CONFIG_DM_FPGA) += fpga.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_SOUND) += i2s.o
test/dm/fpga.c new file +20 -0
new file mode 100644
index 0000000000..8d29c8f159
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_fpga(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	ut_assertok(uclass_get_device(UCLASS_FPGA, 0, &dev));
+
+	return 0;
+}
+
+DM_TEST(dm_test_fpga, UT_TESTF_SCAN_FDT);

base-commit: f117c54cc83e3c519883edb5a48062644d38c443

Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw

Hi Alexander,

Quoted 7 lines · Alexander Dahl

For future DM based FPGA drivers and for now to have a meaningful logging class for old FPGA drivers.

Quoted 13 lines
---
 arch/sandbox/dts/test.dts  |  4 ++++
 drivers/fpga/Kconfig       | 14 ++++++++++++++
 drivers/fpga/Makefile      |  3 +++
 drivers/fpga/fpga-uclass.c | 11 +++++++++++
 drivers/fpga/sandbox.c     | 11 +++++++++++
 include/dm/uclass-id.h     |  1 +
 test/dm/Makefile           |  1 +
 test/dm/fpga.c             | 20 ++++++++++++++++++++
 8 files changed, 65 insertions(+)
 create mode 100644 drivers/fpga/fpga-uclass.c
 create mode 100644 drivers/fpga/sandbox.c
 create mode 100644 test/dm/fpga.c

nits below

Quoted 21 lines
arch/sandbox/dts/test.dts +4 -0
index 2761588f0d..3b9cc8cd7c 100644
@@ -650,6 +650,10 @@
                };
        };
 
+       fpga {
+               compatible = "sandbox,fpga";
+       };
+
        pinctrl-gpio {
                compatible = "sandbox,pinctrl-gpio";
 
drivers/fpga/Kconfig +0 -0
index e07a9cf80e..2ad1ff60b6 100644

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 123

Quoted 6 lines
drivers/fpga/Kconfig +3 -0
@@ -118,4 +118,18 @@ config SPL_FPGA_LOAD_SECURE
          Enables the fpga loads() functions that are used to load secure
          (authenticated or encrypted or both) bitstreams on to FPGA.
 
+config DM_FPGA
+       bool "Enable Driver Model for FPGA drivers"
+       depends on DM

this is the default I think so you can drop this

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 124

Quoted 1 line
drivers/fpga/Kconfig +1 -0
+       select FPGA

Normally we would have 'depends on FPGA' here. With this you will just need to enable DM_FPGA and will get FPGA automatically. If that is what you want, that is fine.

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 127

Quoted 3 lines
drivers/fpga/Kconfig +3 -0
+       help
+         Enable driver model for FPGA.
+         For now this is uclass only without a real driver using it.

What is an FPGA? What sort of features does the uclass support (none yet).

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 133

Quoted 6 lines
drivers/fpga/Kconfig +6 -0
+
+config SANDBOX_FPGA
+       bool "Enable sandbox FPGA driver"
+       depends on SANDBOX && DM_FPGA
+       help
+         tbd

Add help here, explaining that for now it is only a driver with no uclass methods.

Quoted 101 lines
drivers/fpga/Kconfig +1 -0
+
 endmenu
drivers/fpga/Makefile +3 -0
index 83243fb107..610c168fc3 100644
@@ -4,6 +4,9 @@
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
 obj-y += fpga.o
+obj-$(CONFIG_DM_FPGA) += fpga-uclass.o
+obj-$(CONFIG_SANDBOX_FPGA) += sandbox.o
+
 obj-$(CONFIG_FPGA_SPARTAN2) += spartan2.o
 obj-$(CONFIG_FPGA_SPARTAN3) += spartan3.o
 obj-$(CONFIG_FPGA_VERSALPL) += versalpl.o
drivers/fpga/fpga-uclass.c new file +11 -0
new file mode 100644
index 0000000000..4278ec28e5
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+
+UCLASS_DRIVER(fpga) = {
+       .name   = "fpga",
+       .id     = UCLASS_FPGA,
+};
drivers/fpga/sandbox.c new file +11 -0
new file mode 100644
index 0000000000..5687efccb1
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+
+U_BOOT_DRIVER(sandbox_fpga) = {
+       .name   = "sandbox_fpga",
+       .id     = UCLASS_FPGA,
+};
include/dm/uclass-id.h +1 -0
index a432e43871..c2b15881ba 100644
@@ -56,6 +56,7 @@ enum uclass_id {
        UCLASS_ETH,             /* Ethernet device */
        UCLASS_ETH_PHY,         /* Ethernet PHY device */
        UCLASS_FIRMWARE,        /* Firmware */
+       UCLASS_FPGA,            /* FPGA device */
        UCLASS_FUZZING_ENGINE,  /* Fuzzing engine */
        UCLASS_FS_FIRMWARE_LOADER,              /* Generic loader */
        UCLASS_GPIO,            /* Bank of general-purpose I/O pins */
test/dm/Makefile +1 -0
index 7543df8823..666c85f10a 100644
@@ -47,6 +47,7 @@ ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
 obj-$(CONFIG_FIRMWARE) += firmware.o
+obj-$(CONFIG_DM_FPGA) += fpga.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_SOUND) += i2s.o
test/dm/fpga.c new file +20 -0
new file mode 100644
index 0000000000..8d29c8f159
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_fpga(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       ut_assertok(uclass_get_device(UCLASS_FPGA, 0, &dev));
+
+       return 0;
+}
+
+DM_TEST(dm_test_fpga, UT_TESTF_SCAN_FDT);
Quoted 4 lines

base-commit: f117c54cc83e3c519883edb5a48062644d38c443 --
2.30.2

Regards,
Simon

#2 lore raw

Hello Simon,

first of all, thanks for your reviewi(s), it was very helpful. Remarks below.

Am Tue, Sep 27, 2022 at 07:55:00PM -0600 schrieb Simon Glass:

Quoted 24 lines

Hi Alexander,

Quoted 7 lines · Alexander Dahl

For future DM based FPGA drivers and for now to have a meaningful logging class for old FPGA drivers.

Quoted 13 lines
---
 arch/sandbox/dts/test.dts  |  4 ++++
 drivers/fpga/Kconfig       | 14 ++++++++++++++
 drivers/fpga/Makefile      |  3 +++
 drivers/fpga/fpga-uclass.c | 11 +++++++++++
 drivers/fpga/sandbox.c     | 11 +++++++++++
 include/dm/uclass-id.h     |  1 +
 test/dm/Makefile           |  1 +
 test/dm/fpga.c             | 20 ++++++++++++++++++++
 8 files changed, 65 insertions(+)
 create mode 100644 drivers/fpga/fpga-uclass.c
 create mode 100644 drivers/fpga/sandbox.c
 create mode 100644 test/dm/fpga.c
Quoted 1 line

I did not carry that to v2 (which I will send soon), because I felt I changed too much.

Quoted 33 lines

nits below

Quoted 21 lines
arch/sandbox/dts/test.dts +4 -0
index 2761588f0d..3b9cc8cd7c 100644
@@ -650,6 +650,10 @@
                };
        };
 
+       fpga {
+               compatible = "sandbox,fpga";
+       };
+
        pinctrl-gpio {
                compatible = "sandbox,pinctrl-gpio";
 
drivers/fpga/Kconfig +0 -0
index e07a9cf80e..2ad1ff60b6 100644

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 123

Quoted 6 lines
drivers/fpga/Kconfig +3 -0
@@ -118,4 +118,18 @@ config SPL_FPGA_LOAD_SECURE
          Enables the fpga loads() functions that are used to load secure
          (authenticated or encrypted or both) bitstreams on to FPGA.
 
+config DM_FPGA
+       bool "Enable Driver Model for FPGA drivers"
+       depends on DM

this is the default I think so you can drop this

Quoted 5 lines

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 124

Quoted 1 line
drivers/fpga/Kconfig +1 -0
+       select FPGA

Normally we would have 'depends on FPGA' here. With this you will just need to enable DM_FPGA and will get FPGA automatically. If that is what you want, that is fine.

If you look at drivers/fpga/Kconfig you'll see CONFIG_FPGA is currently not user selectable, so I did what CONFIG_FPGA_ALTERA and CONFIG_FPGA_XILINX do. I guess this might be from the old days and I saw it looks different for other driver subsystems, but I did not want to restructure FPGA here at this point. Actually, if I dropped this, and CONFIG_FPGA was not 'y', then neither the new fpga uclass nor the sandbox driver was built, although selected.

Quoted 6 lines

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 127

Quoted 3 lines
drivers/fpga/Kconfig +3 -0
+       help
+         Enable driver model for FPGA.
+         For now this is uclass only without a real driver using it.

What is an FPGA? What sort of features does the uclass support (none yet).

Quoted 9 lines

drivers/fpga/Kconfig config SPL_FPGA_LOAD_SECURE · line 133

Quoted 6 lines
drivers/fpga/Kconfig +6 -0
+
+config SANDBOX_FPGA
+       bool "Enable sandbox FPGA driver"
+       depends on SANDBOX && DM_FPGA
+       help
+         tbd

Add help here, explaining that for now it is only a driver with no uclass methods.

Added some more help in v2.

Quoted 42 lines
Quoted 42 lines
drivers/fpga/Kconfig +1 -0
+
 endmenu
drivers/fpga/Makefile +3 -0
index 83243fb107..610c168fc3 100644
@@ -4,6 +4,9 @@
 # Wolfgang Denk, DENX Software Engineering, [email protected].
 
 obj-y += fpga.o
+obj-$(CONFIG_DM_FPGA) += fpga-uclass.o
+obj-$(CONFIG_SANDBOX_FPGA) += sandbox.o
+
 obj-$(CONFIG_FPGA_SPARTAN2) += spartan2.o
 obj-$(CONFIG_FPGA_SPARTAN3) += spartan3.o
 obj-$(CONFIG_FPGA_VERSALPL) += versalpl.o
drivers/fpga/fpga-uclass.c new file +11 -0
new file mode 100644
index 0000000000..4278ec28e5
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+
+UCLASS_DRIVER(fpga) = {
+       .name   = "fpga",
+       .id     = UCLASS_FPGA,
+};
drivers/fpga/sandbox.c new file +3 -0
new file mode 100644
index 0000000000..5687efccb1
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
Quoted 8 lines

drivers/fpga/sandbox.c line 11

Quoted 8 lines
drivers/fpga/sandbox.c new file +8 -0
+ */
+
+#include <dm.h>
+
+U_BOOT_DRIVER(sandbox_fpga) = {
+       .name   = "sandbox_fpga",
+       .id     = UCLASS_FPGA,
+};

This is not enough to probe the driver, I added something for .of_match in v2.

Greets
Alex

Quoted 58 lines
Quoted 51 lines
include/dm/uclass-id.h +1 -0
index a432e43871..c2b15881ba 100644
@@ -56,6 +56,7 @@ enum uclass_id {
        UCLASS_ETH,             /* Ethernet device */
        UCLASS_ETH_PHY,         /* Ethernet PHY device */
        UCLASS_FIRMWARE,        /* Firmware */
+       UCLASS_FPGA,            /* FPGA device */
        UCLASS_FUZZING_ENGINE,  /* Fuzzing engine */
        UCLASS_FS_FIRMWARE_LOADER,              /* Generic loader */
        UCLASS_GPIO,            /* Bank of general-purpose I/O pins */
test/dm/Makefile +1 -0
index 7543df8823..666c85f10a 100644
@@ -47,6 +47,7 @@ ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
 obj-$(CONFIG_FIRMWARE) += firmware.o
+obj-$(CONFIG_DM_FPGA) += fpga.o
 obj-$(CONFIG_DM_HWSPINLOCK) += hwspinlock.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_SOUND) += i2s.o
test/dm/fpga.c new file +20 -0
new file mode 100644
index 0000000000..8d29c8f159
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2022 Alexander Dahl <[email protected]>
+ */
+
+#include <dm.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+static int dm_test_fpga(struct unit_test_state *uts)
+{
+       struct udevice *dev;
+
+       ut_assertok(uclass_get_device(UCLASS_FPGA, 0, &dev));
+
+       return 0;
+}
+
+DM_TEST(dm_test_fpga, UT_TESTF_SCAN_FDT);
Quoted 4 lines

base-commit: f117c54cc83e3c519883edb5a48062644d38c443 --
2.30.2

Regards,
Simon

Signature · 4 lines
/"\ ASCII RIBBON | »With the first link, the chain is forged. The first
\ / CAMPAIGN     | speech censured, the first thought forbidden, the
 X  AGAINST      | first freedom denied, chains us all irrevocably.«
/ \ HTML MAIL    | (Jean-Luc Picard, quoting Judge Aaron Satie)