Skip to contentSkip to conversation

add support for loading ACPI tables from QEMU

PATCH New Miao Yan 3 participants 11 messages Jan 20, 2016 – Jan 26, 2016 x86

lore
Share & tools
lore

Miao Yan

author
#0 lore raw

v3 cover add support for loading ACPI tables from QEMU

Currently, if CONFIG_GENERATE_ACPI_TABLE is defined, U-Boot will generate ACPI tables itlself, this patchset adds the ability to load the ACPI tables generated by QEMU.

Changes in v3:
- fix a build error in patch 3/4
- re-order patch 3/4 and patch 4/4 in v2

Changes in v2:
- Drop [PATCH 4/4] x86: qemu: loading ACPI table from QEMU, add a config option CONFIG_QEMU_ACPI_TABLE
- various cleanups

Miao Yan (4):
x86: qemu: re-structure qemu_fwcfg_list_firmware()
x86: qemu: setup PM IO base for ACPI in southbridge
x86: qemu: add the ability to load and link ACPI tables from QEMU
x86: config option for loading ACPI table from QEMU

 arch/x86/Kconfig                        |   9 +
 arch/x86/cpu/qemu/Kconfig               |   7 +
 arch/x86/cpu/qemu/Makefile              |   2 +
 arch/x86/cpu/qemu/fw_cfg.c              | 316 ++++++++++++++++++++++++++++++--
 arch/x86/cpu/qemu/qemu.c                |  29 +++
 arch/x86/include/asm/arch-qemu/device.h |   2 +
 arch/x86/include/asm/arch-qemu/qemu.h   |   5 +
 arch/x86/include/asm/fw_cfg.h           |  70 ++++++-
 arch/x86/lib/Makefile                   |   2 +
 arch/x86/lib/acpi_table.c               |   4 +
 10 files changed, 429 insertions(+), 17 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v3 1/4 x86: qemu: re-structure qemu_fwcfg_list_firmware()

Re-write the logic in qemu_fwcfg_list_firmware(), add a function qemu_fwcfg_read_firmware_list() to handle reading firmware list.

---
 arch/x86/cpu/qemu/fw_cfg.c    | 63 +++++++++++++++++++++++++++++++++----------
 arch/x86/include/asm/fw_cfg.h |  9 ++++---
 2 files changed, 55 insertions(+), 17 deletions(-)
arch/x86/cpu/qemu/fw_cfg.c +49 -14
index 0599214..bcd34af 100644
@@ -10,10 +10,13 @@
 #include <malloc.h>
 #include <asm/io.h>
 #include <asm/fw_cfg.h>
+#include <linux/list.h>
 
 static bool fwcfg_present;
 static bool fwcfg_dma_present;
 
+static LIST_HEAD(fw_list);
+
 /* Read configuration item using fw_cfg PIO interface */
 static void qemu_fwcfg_read_entry_pio(uint16_t entry,
 		uint32_t size, void *address)
@@ -162,29 +165,61 @@ static int qemu_fwcfg_setup_kernel(void *load_addr, void *initrd_addr)
 	return 0;
 }
 
-static int qemu_fwcfg_list_firmware(void)
+static int qemu_fwcfg_read_firmware_list(void)
 {
 	int i;
 	uint32_t count;
-	struct fw_cfg_files *files;
+	struct fw_file *file;
+	struct list_head *entry;
+
+	/* don't read it twice */
+	if (!list_empty(&fw_list))
+		return 0;
 
 	qemu_fwcfg_read_entry(FW_CFG_FILE_DIR, 4, &count);
 	if (!count)
 		return 0;
 
 	count = be32_to_cpu(count);
-	files = malloc(count * sizeof(struct fw_cfg_file));
-	if (!files)
-		return -ENOMEM;
-
-	files->count = count;
-	qemu_fwcfg_read_entry(FW_CFG_INVALID,
-			      count * sizeof(struct fw_cfg_file),
-			      files->files);
-
-	for (i = 0; i < files->count; i++)
-		printf("%-56s\n", files->files[i].name);
-	free(files);
+	for (i = 0; i < count; i++) {
+		file = malloc(sizeof(*file));
+		if (!file) {
+			printf("error: allocating resource\n");
+			goto err;
+		}
+		qemu_fwcfg_read_entry(FW_CFG_INVALID,
+				      sizeof(struct fw_cfg_file), &file->cfg);
+		file->addr = 0;
+		list_add_tail(&file->list, &fw_list);
+	}
+
+	return 0;
+
+err:
+	list_for_each(entry, &fw_list) {
+		file = list_entry(entry, struct fw_file, list);
+		free(file);
+	}
+
+	return -ENOMEM;
+}
+
+static int qemu_fwcfg_list_firmware(void)
+{
+	int ret;
+	struct list_head *entry;
+	struct fw_file *file;
+
+	/* make sure fw_list is loaded */
+	ret = qemu_fwcfg_read_firmware_list();
+	if (ret)
+		return ret;
+
+	list_for_each(entry, &fw_list) {
+		file = list_entry(entry, struct fw_file, list);
+		printf("%-56s\n", file->cfg.name);
+	}
+
 	return 0;
 }
 
arch/x86/include/asm/fw_cfg.h +6 -3
index fb110fa..2acf43e 100644
@@ -12,6 +12,8 @@
 #define FW_DMA_PORT_LOW	0x514
 #define FW_DMA_PORT_HIGH	0x518
 
+#include <linux/list.h>
+
 enum qemu_fwcfg_items {
 	FW_CFG_SIGNATURE	= 0x00,
 	FW_CFG_ID		= 0x01,
@@ -67,9 +69,10 @@ struct fw_cfg_file {
 	char name[FW_CFG_MAX_FILE_PATH];
 };
 
-struct fw_cfg_files {
-	__be32 count;
-	struct fw_cfg_file files[];
+struct fw_file {
+	struct fw_cfg_file cfg; /* firmware file information */
+	unsigned long addr;     /* firmware file in-memory address */
+	struct list_head list;  /* list node to link to fw_list */
 };
 
 struct fw_cfg_dma_access {
Signature · 1 line
1.9.1
#3 lore raw

PATCH v3 1/4 x86: qemu: re-structure qemu_fwcfg_list_firmware()

Hi Bin,

Quoted 7 lines · Bin Meng

Hi Simon,

Quoted 3 lines · Miao Yan

Re-write the logic in qemu_fwcfg_list_firmware(), add a function qemu_fwcfg_read_firmware_list() to handle reading firmware list.

Quoted 7 lines
Quoted 4 lines

---

Do you have any comments about this series? If not, I am going to apply it soon.

No, it looks good, thanks.

Regards,
Simon

author
#5 lore raw

PATCH v3 2/4 x86: qemu: setup PM IO base for ACPI in southbridge

In reply to Miao Yan

Enable ACPI IO space for piix4 (for pc board) and ich9 (for q35 board)

---
 arch/x86/cpu/qemu/Kconfig               |  7 +++++++
 arch/x86/cpu/qemu/qemu.c                | 29 +++++++++++++++++++++++++++++
 arch/x86/include/asm/arch-qemu/device.h |  2 ++
 arch/x86/include/asm/arch-qemu/qemu.h   |  5 +++++
 4 files changed, 43 insertions(+)
arch/x86/cpu/qemu/Kconfig +7 -0
index 4f98621..6808c9a 100644
@@ -17,4 +17,11 @@ config SYS_CAR_SIZE
 	hex
 	default 0x10000
 
+config ACPI_PM1_BASE
+	hex
+	default 0xe400
+	help
+	  ACPI Power Managment 1 (PM1) i/o-mapped base address.
+	  This device is defined in ACPI specification, with 16 bytes in size.
+
 endif
arch/x86/cpu/qemu/qemu.c +29 -0
index 46111c9..b794cfe 100644
@@ -15,6 +15,31 @@
 
 static bool i440fx;
 
+static void enable_pm_piix(void)
+{
+	u8 en;
+	u16 cmd;
+
+	/* Set the PM I/O base */
+	x86_pci_write_config32(PIIX_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
+
+	/* Enable access to the PM I/O space */
+	cmd = x86_pci_read_config16(PIIX_PM, PCI_COMMAND);
+	cmd |= PCI_COMMAND_IO;
+	x86_pci_write_config16(PIIX_PM, PCI_COMMAND, cmd);
+
+	/* PM I/O Space Enable (PMIOSE) */
+	en = x86_pci_read_config8(PIIX_PM, PMREGMISC);
+	en |= PMIOSE;
+	x86_pci_write_config8(PIIX_PM, PMREGMISC, en);
+}
+
+static void enable_pm_ich9(void)
+{
+	/* Set the PM I/O base */
+	x86_pci_write_config32(ICH9_PM, PMBA, CONFIG_ACPI_PM1_BASE | 1);
+}
+
 static void qemu_chipset_init(void)
 {
 	u16 device, xbcs;
@@ -53,10 +78,14 @@ static void qemu_chipset_init(void)
 		xbcs = x86_pci_read_config16(PIIX_ISA, XBCS);
 		xbcs |= APIC_EN;
 		x86_pci_write_config16(PIIX_ISA, XBCS, xbcs);
+
+		enable_pm_piix();
 	} else {
 		/* Configure PCIe ECAM base address */
 		x86_pci_write_config32(PCI_BDF(0, 0, 0), PCIEX_BAR,
 				       CONFIG_PCIE_ECAM_BASE | BAR_EN);
+
+		enable_pm_ich9();
 	}
 
 	qemu_fwcfg_init();
arch/x86/include/asm/arch-qemu/device.h +2 -0
index 75a435e..38ab798 100644
@@ -13,6 +13,8 @@
 #define PIIX_ISA	PCI_BDF(0, 1, 0)
 #define PIIX_IDE	PCI_BDF(0, 1, 1)
 #define PIIX_USB	PCI_BDF(0, 1, 2)
+#define PIIX_PM	PCI_BDF(0, 1, 3)
+#define ICH9_PM	PCI_BDF(0, 0x1f, 0)
 #define I440FX_VGA	PCI_BDF(0, 2, 0)
 
 #define QEMU_Q35	PCI_BDF(0, 0, 0)
arch/x86/include/asm/arch-qemu/qemu.h +5 -0
index b67d342..a85eee8 100644
@@ -33,4 +33,9 @@
 #define LOW_RAM_ADDR		0x34
 #define HIGH_RAM_ADDR		0x35
 
+/* PM registers */
+#define PMBA		0x40
+#define PMREGMISC	0x80
+#define PMIOSE		(1 << 0)
+
 #endif /* _ARCH_QEMU_H_ */
Signature · 1 line
1.9.1
author
#7 lore raw

PATCH v3 3/4 x86: qemu: add the ability to load and link ACPI tables from QEMU

In reply to Miao Yan

This patch adds the ability to load and link ACPI tables provided by QEMU. QEMU tells guests how to load and patch ACPI tables through its fw_cfg interface, by adding a firmware file 'etc/table-loader'. Guests are supposed to parse this file and execute corresponding QEMU commands.

---
Change in v3:
- fix a build error
- make it [PATCH 3/4]

 arch/x86/cpu/qemu/Makefile    |   2 +
 arch/x86/cpu/qemu/fw_cfg.c    | 253 ++++++++++++++++++++++++++++++++++++++++++
 arch/x86/include/asm/fw_cfg.h |  61 ++++++++++
 arch/x86/lib/Makefile         |   2 +
 arch/x86/lib/acpi_table.c     |   4 +
 5 files changed, 322 insertions(+)
arch/x86/cpu/qemu/Makefile +2 -0
index 176ea54..801413a 100644
@@ -8,4 +8,6 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += cpu.o fw_cfg.o qemu.o
+ifndef CONFIG_QEMU_ACPI_TABLE
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o dsdt.o
+endif
arch/x86/cpu/qemu/fw_cfg.c +253 -0

266 lines not on this page · raw message

arch/x86/include/asm/fw_cfg.h +61 -0

78 lines not on this page · raw message

arch/x86/lib/Makefile +2 -0
index cd5ecb6..75719e3 100644
@@ -32,7 +32,9 @@ obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y += sfi.o
 obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += smbios.o
 obj-y	+= string.o
+ifndef CONFIG_QEMU_ACPI_TABLE
 obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
+endif
 obj-y	+= tables.o
 obj-$(CONFIG_CMD_ZBOOT)	+= zimage.o
 obj-$(CONFIG_HAVE_FSP) += fsp/
arch/x86/lib/acpi_table.c +4 -0
index ab1db7e..2ec5ad2 100644
@@ -331,6 +331,10 @@ static void acpi_create_ssdt_generator(acpi_header_t *ssdt,
 	ssdt->checksum = table_compute_checksum((void *)ssdt, ssdt->length);
 }
 
+/*
+ * QEMU's version of write_acpi_tables is defined in
+ * arch/x86/cpu/qemu/fw_cfg.c
+ */
 unsigned long write_acpi_tables(unsigned long start)
 {
 	unsigned long current;
Signature · 1 line
1.9.1
#8 lore raw

PATCH v3 3/4 x86: qemu: add the ability to load and link ACPI tables from QEMU

Quoted 9 lines · Miao Yan

This patch adds the ability to load and link ACPI tables provided by QEMU. QEMU tells guests how to load and patch ACPI tables through its fw_cfg interface, by adding a firmware file 'etc/table-loader'. Guests are supposed to parse this file and execute corresponding QEMU commands.

---

applied to u-boot-x86/master, thanks!

author
#9 lore raw

PATCH v3 4/4 x86: config option for loading ACPI table from QEMU

In reply to Miao Yan

This patch adds a config option for loading ACPI table from QEMU. When enabled, U-Boot won't generate ACPI tables, but use those provided by QEMU.

---
Changes in v3:
- fix a build error
- make it [PATCH 4/4]

 arch/x86/Kconfig | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/x86/Kconfig +9 -0
index f07567c..a995e32 100644
@@ -358,6 +358,15 @@ config GENERATE_ACPI_TABLE
 	  by the operating system. It defines platform-independent interfaces
 	  for configuration and power management monitoring.
 
+config QEMU_ACPI_TABLE
+	bool "Load ACPI table from QEMU fw_cfg interface"
+	depends on GENERATE_ACPI_TABLE && QEMU
+	default y
+	help
+	  By default, U-Boot generates its own ACPI tables. This option, if
+	  enabled, disables U-Boot's version and loads ACPI tables generated
+	  by QEMU.
+
 config GENERATE_SMBIOS_TABLE
 	bool "Generate an SMBIOS (System Management BIOS) table"
 	default y
Signature · 1 line
1.9.1