Skip to contentSkip to conversation

Move qfw to DM, add Arm support

PATCH New Asherah Connor 2 participants 9 messages Mar 19, 2021 – Apr 13, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v8 cover Move qfw to DM, add Arm support

This series moves the QFW driver into a uclass, UCLASS_QFW, and splits the driver into qfw_pio and qfw_mmio. Each driver is selected on the appropriate QEMU board. A sandbox driver is also added, and a DM unit test against that driver. The qfw command is tested in QEMU, and documentation added.

Version 7 ensures the qfw test assertions work both against real QEMU instances and the sandbox and removes CMD_QFW from the sandbox_spl config. Version 8 removes some extraneous whitespace.

To view the changes online, see:
https://git.src.kameliya.ee/~kameliya/u-boot/log/qfw-priv

Changes in v8:
* Removed extraneous newlines at EOF.

Changes in v7:
* Make the qfw tests agnostic to running against a real QEMU instance or in the sandbox.
* Remove CONFIG_CMD_QFW=y from sandbox_spl_defconfig, per trini's request.

Changes in v6:
* Sandbox driver and tests are split into own commit.

Changes in v5:
* Split conversion of existing x86-only QFW to DM into its own patch.
* Split MMIO driver into its own commit.
* Split adding MMIO driver to QEMU arm/64 into own commit.

Asherah Connor (4):
x86: qemu: move QFW to its own uclass
test: qemu: add qfw sandbox driver, dm tests, qemu tests
qemu: add MMIO driver for QFW
qemu: arm: select QFW, MMIO on qemu-arm

 arch/x86/cpu/qemu/cpu.c          |   9 +-
 arch/x86/cpu/qemu/qemu.c         |  49 +------
 arch/x86/cpu/qfw_cpu.c           |  11 +-
 board/emulation/qemu-arm/Kconfig |   2 +
 board/emulation/qemu-x86/Kconfig |   1 +
 cmd/qfw.c                        |  56 ++++---
 common/Makefile                  |   2 +
 common/qfw.c                     | 104 +++++++++++++
 configs/sandbox_spl_defconfig    |   1 -
 drivers/misc/Kconfig             |  18 ++-
 drivers/misc/Makefile            |   7 +-
 drivers/misc/qfw.c               | 243 +++++++++++--------------------
 drivers/misc/qfw_mmio.c          | 119 +++++++++++++++
 drivers/misc/qfw_pio.c           |  69 +++++++++
 drivers/misc/qfw_sandbox.c       | 127 ++++++++++++++++
 include/dm/uclass-id.h           |   1 +
 include/qfw.h                    | 200 +++++++++++++++++++++----
 test/dm/Makefile                 |   1 +
 test/dm/qfw.c                    |  42 ++++++
 test/py/tests/test_qfw.py        |  26 ++++
 20 files changed, 815 insertions(+), 273 deletions(-)
 create mode 100644 common/qfw.c
 create mode 100644 drivers/misc/qfw_mmio.c
 create mode 100644 drivers/misc/qfw_pio.c
 create mode 100644 drivers/misc/qfw_sandbox.c
 create mode 100644 test/dm/qfw.c
 create mode 100644 test/py/tests/test_qfw.py
Signature · 1 line
2.20.1
#1 lore raw

PATCH v8 1/4 x86: qemu: move QFW to its own uclass

We move qfw into its own uclass and split the PIO functions into a specific driver for that uclass. The PIO driver is selected in the qemu-x86 board config (this covers x86 and x86_64).

include/qfw.h is cleaned up and documentation added.

---

Changes in v8:
* Removed extraneous newline at EOF.

Changes in v6:
* Sandbox driver and tests are split into own commit.

Changes in v5:
* Split conversion of existing x86-only QFW to DM into its own patch.
* Fix qfw_get_dev() so it actually returns -ENODEV when device is missing.
* Add CONFIG_QFW_PIO.
* Choose CONFIG_QFW_PIO in board/emulation/qemu-x86/Kconfig.
* QFW sandbox driver no longer inserts itself from device tree; wasn't relevant to implementation and the ``compatible'' string was too made-up. Use U_BOOT_DRVINFO like the other QFW driver in this patch.
* Relevant documentation and sandbox/qemu tests are now here.

 arch/x86/cpu/qemu/cpu.c          |   9 +-
 arch/x86/cpu/qemu/qemu.c         |  49 +------
 arch/x86/cpu/qfw_cpu.c           |  11 +-
 board/emulation/qemu-x86/Kconfig |   1 +
 cmd/qfw.c                        |  56 ++++---
 common/Makefile                  |   2 +
 common/qfw.c                     | 104 +++++++++++++
 drivers/misc/Kconfig             |  11 +-
 drivers/misc/Makefile            |   5 +-
 drivers/misc/qfw.c               | 243 +++++++++++--------------------
 drivers/misc/qfw_pio.c           |  69 +++++++++
 include/dm/uclass-id.h           |   1 +
 include/qfw.h                    | 200 +++++++++++++++++++++----
 13 files changed, 489 insertions(+), 272 deletions(-)
 create mode 100644 common/qfw.c
 create mode 100644 drivers/misc/qfw_pio.c
arch/x86/cpu/qemu/cpu.c +8 -1
index 9ce86b379c..735b656084 100644
@@ -22,7 +22,14 @@ int cpu_qemu_get_desc(const struct udevice *dev, char *buf, int size)
 
 static int cpu_qemu_get_count(const struct udevice *dev)
 {
-	return qemu_fwcfg_online_cpus();
+	int ret;
+	struct udevice *qfw_dev;
+
+	ret = qfw_get_dev(&qfw_dev);
+	if (ret)
+		return ret;
+
+	return qfw_online_cpus(qfw_dev);
 }
 
 static const struct cpu_ops cpu_qemu_ops = {
arch/x86/cpu/qemu/qemu.c +4 -45

67 lines not on this page · raw message

arch/x86/cpu/qfw_cpu.c +9 -2
index b959eaddde..ee00b8fe73 100644
@@ -18,7 +18,7 @@ int qemu_cpu_fixup(void)
 	int cpu_num;
 	int cpu_online;
 	struct uclass *uc;
-	struct udevice *dev, *pdev;
+	struct udevice *dev, *pdev, *qfwdev;
 	struct cpu_plat *plat;
 	char *cpu;
 
@@ -39,6 +39,13 @@ int qemu_cpu_fixup(void)
 		return -ENODEV;
 	}
 
+	/* get qfw dev */
+	ret = qfw_get_dev(&qfwdev);
+	if (ret) {
+		printf("unable to find qfw device\n");
+		return ret;
+	}
+
 	/* calculate cpus that are already bound */
 	cpu_num = 0;
 	for (uclass_find_first_device(UCLASS_CPU, &dev);
@@ -48,7 +55,7 @@ int qemu_cpu_fixup(void)
 	}
 
 	/* get actual cpu number */
-	cpu_online = qemu_fwcfg_online_cpus();
+	cpu_online = qfw_online_cpus(qfwdev);
 	if (cpu_online < 0) {
 		printf("unable to get online cpu number: %d\n", cpu_online);
 		return cpu_online;
board/emulation/qemu-x86/Kconfig +1 -0
index 6d19299d8b..9bb8a726ed 100644
@@ -20,6 +20,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy
 	def_bool y
 	select X86_RESET_VECTOR
 	select QEMU
+	select QFW_PIO
 	select BOARD_ROMSIZE_KB_1024
 	imply VIRTIO_PCI
 	imply VIRTIO_NET
cmd/qfw.c +26 -30

129 lines not on this page · raw message

common/Makefile +2 -0
index daeea67cf2..f174a06c33 100644
@@ -137,3 +137,5 @@ obj-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
 
 obj-$(CONFIG_AVB_VERIFY) += avb_verify.o
+
+obj-$(CONFIG_QFW) += qfw.o
common/qfw.c new file +104 -0

104 lines not on this page · raw message

drivers/misc/Kconfig +9 -2
index 7d2a299779..3a254eba4b 100644
@@ -368,8 +368,15 @@ config WINBOND_W83627
 config QFW
 	bool
 	help
-	  Hidden option to enable QEMU fw_cfg interface. This will be selected by
-	  either CONFIG_CMD_QFW or CONFIG_GENERATE_ACPI_TABLE.
+	  Hidden option to enable QEMU fw_cfg interface and uclass. This will
+	  be selected by either CONFIG_CMD_QFW or CONFIG_GENERATE_ACPI_TABLE.
+
+config QFW_PIO
+	bool
+	depends on QFW
+	help
+	  Hidden option to enable PIO QEMU fw_cfg interface. This will be
+	  selected by the appropriate QEMU board.
 
 config I2C_EEPROM
 	bool "Enable driver for generic I2C-attached EEPROMs"
drivers/misc/Makefile +4 -1
index 1a49396007..53bff72428 100644
@@ -55,7 +55,10 @@ obj-$(CONFIG_NUVOTON_NCT6102D) += nuvoton_nct6102d.o
 obj-$(CONFIG_P2SB) += p2sb-uclass.o
 obj-$(CONFIG_PCA9551_LED) += pca9551_led.o
 obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
-obj-$(CONFIG_QFW) += qfw.o
+ifdef CONFIG_QFW
+obj-y += qfw.o
+obj-$(CONFIG_QFW_PIO) += qfw_pio.o
+endif
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
drivers/misc/qfw.c +84 -159

383 lines not on this page · raw message

drivers/misc/qfw_pio.c new file +69 -0

69 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index d75de368c5..d800f679d5 100644
@@ -90,6 +90,7 @@ enum uclass_id {
 	UCLASS_POWER_DOMAIN,	/* (SoC) Power domains */
 	UCLASS_PWM,		/* Pulse-width modulator */
 	UCLASS_PWRSEQ,		/* Power sequence device */
+	UCLASS_QFW,		/* QEMU firmware config device */
 	UCLASS_RAM,		/* RAM controller */
 	UCLASS_REGULATOR,	/* Regulator device */
 	UCLASS_REMOTEPROC,	/* Remote Processor device */
include/qfw.h +168 -32

239 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

PATCH v8 1/4 x86: qemu: move QFW to its own uclass

Quoted 10 lines · Asherah Connor

We move qfw into its own uclass and split the PIO functions into a specific driver for that uclass. The PIO driver is selected in the qemu-x86 board config (this covers x86 and x86_64).

include/qfw.h is cleaned up and documentation added.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210413/c54d7e67/attachment.sig>
#3 lore raw

PATCH v8 2/4 test: qemu: add qfw sandbox driver, dm tests, qemu tests

In reply to Asherah Connor

A sandbox driver and test are added for the qfw uclass, and a test in QEMU added for qfw functionality to confirm it doesn't break in real world use.

---

Changes in v8:
* Removed extraneous newline at EOF.

Changes in v7:
* Make the qfw tests agnostic to running against a real QEMU instance or in the sandbox.
* Remove CONFIG_CMD_QFW=y from sandbox_spl_defconfig, per trini's request.

 configs/sandbox_spl_defconfig |   1 -
 drivers/misc/Makefile         |   1 +
 drivers/misc/qfw_sandbox.c    | 127 ++++++++++++++++++++++++++++++++++
 test/dm/Makefile              |   1 +
 test/dm/qfw.c                 |  42 +++++++++++
 test/py/tests/test_qfw.py     |  26 +++++++
 6 files changed, 197 insertions(+), 1 deletion(-)
 create mode 100644 drivers/misc/qfw_sandbox.c
 create mode 100644 test/dm/qfw.c
 create mode 100644 test/py/tests/test_qfw.py
configs/sandbox_spl_defconfig +0 -1
index c0118702a8..76b52a38ed 100644
@@ -72,7 +72,6 @@ CONFIG_CMD_EFIDEBUG=y
 CONFIG_CMD_TIME=y
 CONFIG_CMD_TIMER=y
 CONFIG_CMD_SOUND=y
-CONFIG_CMD_QFW=y
 CONFIG_CMD_BOOTSTAGE=y
 CONFIG_CMD_PMIC=y
 CONFIG_CMD_REGULATOR=y
drivers/misc/Makefile +1 -0
index 53bff72428..2864b84af9 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 ifdef CONFIG_QFW
 obj-y += qfw.o
 obj-$(CONFIG_QFW_PIO) += qfw_pio.o
+obj-$(CONFIG_SANDBOX) += qfw_sandbox.o
 endif
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
drivers/misc/qfw_sandbox.c new file +127 -0

127 lines not on this page · raw message

test/dm/Makefile +1 -0
index fd1455109d..fc2902a3ea 100644
@@ -98,5 +98,6 @@ endif
 ifneq ($(CONFIG_EFI_PARTITION),)
 obj-$(CONFIG_FASTBOOT_FLASH_MMC) += fastboot.o
 endif
+obj-$(CONFIG_QFW) += qfw.o
 endif
 endif # !SPL
test/dm/qfw.c new file +42 -0

42 lines not on this page · raw message

test/py/tests/test_qfw.py new file +26 -0
new file mode 100644
index 0000000000..8b668c9721
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2021, Asherah Connor <[email protected]>
+
+# Test qfw command implementation
+
+import pytest
+
+ at pytest.mark.buildconfigspec('cmd_qfw')
+def test_qfw_cpus(u_boot_console):
+    "Test QEMU firmware config reports the CPU count."
+
+    output = u_boot_console.run_command('qfw cpus')
+    # The actual number varies depending on the board under test, so only
+    # assert a non-zero output.
+    assert 'cpu(s) online' in output
+    assert '0 cpu(s) online' not in output
+
+ at pytest.mark.buildconfigspec('cmd_qfw')
+def test_qfw_list(u_boot_console):
+    "Test QEMU firmware config lists devices."
+
+    output = u_boot_console.run_command('qfw list')
+    # Assert either:
+    # 1) 'test-one', from the sandbox driver, or
+    # 2) 'bootorder', found in every real QEMU implementation.
+    assert ("bootorder" in output) or ("test-one" in output)
Signature · 1 line
2.20.1
#4 lore raw

PATCH v8 2/4 test: qemu: add qfw sandbox driver, dm tests, qemu tests

Quoted 7 lines · Asherah Connor

A sandbox driver and test are added for the qfw uclass, and a test in QEMU added for qfw functionality to confirm it doesn't break in real world use.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210413/24b32362/attachment.sig>
#5 lore raw

PATCH v8 3/4 qemu: add MMIO driver for QFW

In reply to Asherah Connor

Add MMIO driver for QFW.

Note that there is no consumer as of this patch.

---

(no changes since v5)

Changes in v5:
* Split MMIO driver into its own commit.
* Add CONFIG_QFW_MMIO for selection by arch/board.

 drivers/misc/Kconfig    |   7 +++
 drivers/misc/Makefile   |   1 +
 drivers/misc/qfw_mmio.c | 119 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 drivers/misc/qfw_mmio.c
drivers/misc/Kconfig +7 -0
index 3a254eba4b..c650471ff7 100644
@@ -378,6 +378,13 @@ config QFW_PIO
 	  Hidden option to enable PIO QEMU fw_cfg interface. This will be
 	  selected by the appropriate QEMU board.
 
+config QFW_MMIO
+	bool
+	depends on QFW
+	help
+	  Hidden option to enable MMIO QEMU fw_cfg interface. This will be
+	  selected by the appropriate QEMU board.
+
 config I2C_EEPROM
 	bool "Enable driver for generic I2C-attached EEPROMs"
 	depends on MISC
drivers/misc/Makefile +1 -0
index 2864b84af9..0c67d43a5d 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_$(SPL_)PWRSEQ) += pwrseq-uclass.o
 ifdef CONFIG_QFW
 obj-y += qfw.o
 obj-$(CONFIG_QFW_PIO) += qfw_pio.o
+obj-$(CONFIG_QFW_MMIO) += qfw_mmio.o
 obj-$(CONFIG_SANDBOX) += qfw_sandbox.o
 endif
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
drivers/misc/qfw_mmio.c new file +119 -0

119 lines not on this page · raw message

Signature · 1 line
2.20.1
#6 lore raw

PATCH v8 3/4 qemu: add MMIO driver for QFW

Quoted 7 lines · Asherah Connor

Add MMIO driver for QFW.

Note that there is no consumer as of this patch.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210413/41055938/attachment.sig>
#7 lore raw

PATCH v8 4/4 qemu: arm: select QFW, MMIO on qemu-arm

In reply to Asherah Connor

Select CMD_QFW and QFW_MMIO in the qemu-arm board (covers arm and arm64).

---

(no changes since v5)

Changes in v5:
* Split adding MMIO driver to QEMU arm/64 into own commit.
* Use the generic qemu-arm board config rather than adding to multiple defconfigs.

 board/emulation/qemu-arm/Kconfig | 2 ++
 1 file changed, 2 insertions(+)
board/emulation/qemu-arm/Kconfig +2 -0
index fb8d38f5b8..95dbefa78b 100644
@@ -5,6 +5,8 @@ config SYS_TEXT_BASE
 
 config BOARD_SPECIFIC_OPTIONS # dummy
 	def_bool y
+	select CMD_QFW
+	select QFW_MMIO
 	imply VIRTIO_MMIO
 	imply VIRTIO_PCI
 	imply VIRTIO_NET
Signature · 1 line
2.20.1
#8 lore raw

PATCH v8 4/4 qemu: arm: select QFW, MMIO on qemu-arm

Quoted 6 lines · Asherah Connor

Select CMD_QFW and QFW_MMIO in the qemu-arm board (covers arm and arm64).

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210413/f1790a61/attachment.sig>