Skip to contentSkip to conversation

Add ACPI table support

PATCH New Saket Sinha 3 participants 13 messages Aug 22, 2015 – Aug 23, 2015

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

v6 cover Add ACPI table support

ACPI(Advanced Configuration and Power Interface), is a Power Management and configuration standard allowing the operating system to control the amount of power each device is given (allowing it to put certain devices on standby or power-off for example). It is also used to control and/or check thermal zones (temperature sensors, fan speeds, etc), battery levels, PCI IRQ routing, CPUs, NUMA domains and many other things.

This series adds ACPI support to QEMU targets.
Currently, the Linux kernel graphics console does not work with this series.

Changes in v6:
- Incoporated Bin's review comments.

Saket Sinha (3):
x86: Generate a valid ACPI table
x86: Add ACPI table support to QEMU
x86: Add DSDT table for supporting ACPI on QEMU

 arch/x86/Kconfig                       |   9 +
 arch/x86/cpu/qemu/Makefile             |   1 +
 arch/x86/cpu/qemu/acpi.c               | 179 ++++++++++++++
 arch/x86/cpu/qemu/acpi/cpu-hotplug.asl |  80 ++++++
 arch/x86/cpu/qemu/acpi/dbug.asl        |  25 ++
 arch/x86/cpu/qemu/acpi/hpet.asl        |  31 +++
 arch/x86/cpu/qemu/acpi/isa.asl         | 102 ++++++++
 arch/x86/cpu/qemu/acpi/pci-crs.asl     |  61 +++++
 arch/x86/cpu/qemu/dsdt.asl             | 412 +++++++++++++++++++++++++++++++
 arch/x86/include/asm/acpi_table.h      | 390 +++++++++++++++++++++++++++++
 arch/x86/lib/Makefile                  |   1 +
 arch/x86/lib/acpi_table.c              | 436 +++++++++++++++++++++++++++++++++
 arch/x86/lib/tables.c                  |   5 +
 scripts/Makefile.lib                   |  11 +
 14 files changed, 1743 insertions(+)
 create mode 100644 arch/x86/cpu/qemu/acpi.c
 create mode 100644 arch/x86/cpu/qemu/acpi/cpu-hotplug.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/dbug.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/hpet.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/isa.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/pci-crs.asl
 create mode 100644 arch/x86/cpu/qemu/dsdt.asl
 create mode 100644 arch/x86/include/asm/acpi_table.h
 create mode 100644 arch/x86/lib/acpi_table.c
Signature · 1 line
2.1.4
#1 lore raw

PATCH v6 1/3 x86: Generate a valid ACPI table

Implement write_acpi_table() to create a minimal working ACPI table. This includes writing FACS, XSDT, RSDP, FADT, MCFG, MADT, DSDT & SSDT ACPI table entries.

Use a Kconfig option GENERATE_ACPI_TABLE to tell U-Boot whether we need actually write the APCI table just like we did for PIRQ routing, MP table and SFI tables. With ACPI table existence, linux kernel gets control of power management, thermal management, configuration management and monitoring in hardware.

---

 arch/x86/Kconfig                  |   9 +
 arch/x86/include/asm/acpi_table.h | 390 ++++++++++++++++++++++++++++++++++
 arch/x86/lib/Makefile             |   1 +
 arch/x86/lib/acpi_table.c         | 436 ++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/tables.c             |   5 +
 scripts/Makefile.lib              |  11 +
 6 files changed, 852 insertions(+)
 create mode 100644 arch/x86/include/asm/acpi_table.h
 create mode 100644 arch/x86/lib/acpi_table.c
arch/x86/Kconfig +9 -0
index 273f08f..5e42d7d 100644
@@ -349,6 +349,15 @@ config GENERATE_MP_TABLE
 	  multiprocessing as well as symmetric I/O interrupt handling with
 	  the local APIC and I/O APIC.
 
+config GENERATE_ACPI_TABLE
+	bool "Generate an ACPI (Advanced Configuration and Power Interface) table"
+	default n
+	help
+	  The Advanced Configuration and Power Interface (ACPI) specification
+	  provides an open standard for device configuration and management
+	  by the operating system. It defines platform-independent interfaces
+	  for configuration and power management monitoring.
+
 endmenu
 
 config MAX_PIRQ_LINKS
arch/x86/include/asm/acpi_table.h new file +390 -0

390 lines not on this page · raw message

arch/x86/lib/Makefile +1 -0
index dcfe9ee..6ecd6db 100644
@@ -30,6 +30,7 @@ obj-y += physmem.o
 obj-$(CONFIG_X86_RAMTEST) += ramtest.o
 obj-y += sfi.o
 obj-y	+= string.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi_table.o
 obj-y	+= tables.o
 obj-$(CONFIG_SYS_X86_TSC_TIMER)	+= tsc_timer.o
 obj-$(CONFIG_CMD_ZBOOT)	+= zimage.o
arch/x86/lib/acpi_table.c new file +436 -0

436 lines not on this page · raw message

arch/x86/lib/tables.c +5 -0
index 75ffbc1..f15b2e2 100644
@@ -8,6 +8,7 @@
 #include <asm/sfi.h>
 #include <asm/mpspec.h>
 #include <asm/tables.h>
+#include <asm/acpi_table.h>
 
 u8 table_compute_checksum(void *v, int len)
 {
@@ -51,4 +52,8 @@ void write_tables(void)
 	rom_table_end = write_mp_table(rom_table_end);
 	rom_table_end = ALIGN(rom_table_end, 1024);
 #endif
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+	rom_table_end = write_acpi_tables(rom_table_end);
+	rom_table_end = ALIGN(rom_table_end, 1024);
+#endif
 }
scripts/Makefile.lib +11 -0
index 1c949fc..ed30bf5 100644
@@ -297,6 +297,17 @@ $(obj)/%.dtb: $(src)/%.dts FORCE
 
 dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
 
+# ACPI
+# ---------------------------------------------------------------------------
+quiet_cmd_acpi_c_asl= ASL     $@
+cmd_acpi_c_asl=         \
+	$(CPP) -x assembler-with-cpp -P -o $<.tmp $<; \
+	iasl -p $< -tc -va $<.tmp; \
+	mv $(patsubst %.asl,%.hex,$<) $@
+
+$(obj)/%.c:    $(src)/%.asl
+	$(call cmd,acpi_c_asl)
+
 # Bzip2
 # ---------------------------------------------------------------------------
 
Signature · 1 line
2.1.4
#4 lore raw

PATCH v6 2/3 x86: Add ACPI table support to QEMU

In reply to Saket Sinha

This patch mainly adds ACPI support to QEMU. Verified by booting Linux kernel on QEMU i440FX and Q35.

---

 arch/x86/cpu/qemu/Makefile |   1 +
 arch/x86/cpu/qemu/acpi.c   | 179 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
 create mode 100644 arch/x86/cpu/qemu/acpi.c
arch/x86/cpu/qemu/Makefile +1 -0
index 9a66b16..8c3884c 100644
@@ -8,4 +8,5 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/qemu/acpi.c new file +179 -0

179 lines not on this page · raw message

Signature · 1 line
2.1.4
#10 lore raw

PATCH v6 3/3 x86: Add DSDT table for supporting ACPI on QEMU

In reply to Saket Sinha

The DSDT table contains a bytecode that is executed by a driver in the kernel.

---

 arch/x86/cpu/qemu/Makefile             |   2 +-
 arch/x86/cpu/qemu/acpi/cpu-hotplug.asl |  80 +++++++
 arch/x86/cpu/qemu/acpi/dbug.asl        |  25 ++
 arch/x86/cpu/qemu/acpi/hpet.asl        |  31 +++
 arch/x86/cpu/qemu/acpi/isa.asl         | 102 ++++++++
 arch/x86/cpu/qemu/acpi/pci-crs.asl     |  61 +++++
 arch/x86/cpu/qemu/dsdt.asl             | 412 +++++++++++++++++++++++++++++++++
 7 files changed, 712 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/cpu/qemu/acpi/cpu-hotplug.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/dbug.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/hpet.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/isa.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/pci-crs.asl
 create mode 100644 arch/x86/cpu/qemu/dsdt.asl
arch/x86/cpu/qemu/Makefile +1 -1
index 8c3884c..1c00d1d 100644
@@ -8,5 +8,5 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
-obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o dsdt.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/qemu/acpi/cpu-hotplug.asl new file +80 -0

80 lines not on this page · raw message

arch/x86/cpu/qemu/acpi/dbug.asl new file +25 -0
new file mode 100644
index 0000000..38a6526
@@ -0,0 +1,25 @@
+/* Debugging */
+
+Scope(\) {
+    /* Debug Output */
+    OperationRegion(DBG, SystemIO, 0x0402, 0x01)
+    Field(DBG, ByteAcc, NoLock, Preserve) {
+        DBGB,   8,
+    }
+	/*
+	 * Debug method - use this method to send output to the QEMU
+	 * BIOS debug port.  This method handles strings, integers,
+	 * and buffers.  For example: DBUG("abc") DBUG(0x123)
+	 */
+    Method(DBUG, 1) {
+        ToHexString(Arg0, Local0)
+        ToBuffer(Local0, Local0)
+        Subtract(SizeOf(Local0), 1, Local1)
+        Store(Zero, Local2)
+        While (LLess(Local2, Local1)) {
+            Store(DerefOf(Index(Local0, Local2)), DBGB)
+            Increment(Local2)
+        }
+        Store(0x0a, dbgb)
+    }
+}
arch/x86/cpu/qemu/acpi/hpet.asl new file +31 -0
new file mode 100644
index 0000000..983151e
@@ -0,0 +1,31 @@
+/* HPET */
+
+Scope(\_SB) {
+    Device(HPET) {
+        Name(_HID, EISAID("PNP0103"))
+        Name(_UID, 0)
+        OperationRegion(HPTM, SystemMemory, 0xfed00000, 0x400)
+        Field(HPTM, DWordAcc, Lock, Preserve) {
+            VEND, 32,
+            PRD, 32,
+        }
+        Method(_STA, 0, NotSerialized) {
+            Store(VEND, Local0)
+            Store(PRD, Local1)
+            ShiftRight(Local0, 16, Local0)
+            If (LOr(LEqual(Local0, 0), LEqual(Local0, 0xffff))) {
+                Return (0x0)
+            }
+            If (LOr(LEqual(Local1, 0), LGreater(Local1, 100000000))) {
+                Return (0x0)
+            }
+            Return (0x0f)
+        }
+        Name(_CRS, ResourceTemplate() {
+            Memory32Fixed(ReadOnly,
+                0xfed00000,         /* Address Base */
+                0x00000400,         /* Address Length */
+                )
+        })
+    }
+}
arch/x86/cpu/qemu/acpi/isa.asl new file +102 -0

102 lines not on this page · raw message

arch/x86/cpu/qemu/acpi/pci-crs.asl new file +61 -0

61 lines not on this page · raw message

arch/x86/cpu/qemu/dsdt.asl new file +412 -0

412 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw

PATCH v6 1/3 x86: Generate a valid ACPI table

In reply to Saket Sinha

Hi Saket,

Quoted 11 lines · Saket Sinha

Implement write_acpi_table() to create a minimal working ACPI table. This includes writing FACS, XSDT, RSDP, FADT, MCFG, MADT, DSDT & SSDT ACPI table entries.

Use a Kconfig option GENERATE_ACPI_TABLE to tell U-Boot whether we need actually write the APCI table just like we did for PIRQ routing, MP table and SFI tables. With ACPI table existence, linux kernel gets control of power management, thermal management, configuration management and monitoring in hardware.

Now I am more comfortable with this version, so

But still two nits below.

Quoted 45 lines

---

 arch/x86/Kconfig                  |   9 +
 arch/x86/include/asm/acpi_table.h | 390 ++++++++++++++++++++++++++++++++++
 arch/x86/lib/Makefile             |   1 +
 arch/x86/lib/acpi_table.c         | 436 ++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/tables.c             |   5 +
 scripts/Makefile.lib              |  11 +
 6 files changed, 852 insertions(+)
 create mode 100644 arch/x86/include/asm/acpi_table.h
 create mode 100644 arch/x86/lib/acpi_table.c
arch/x86/Kconfig +9 -0
index 273f08f..5e42d7d 100644
@@ -349,6 +349,15 @@ config GENERATE_MP_TABLE
          multiprocessing as well as symmetric I/O interrupt handling with
          the local APIC and I/O APIC.
 
+config GENERATE_ACPI_TABLE
+       bool "Generate an ACPI (Advanced Configuration and Power Interface) table"
+       default n
+       help
+         The Advanced Configuration and Power Interface (ACPI) specification
+         provides an open standard for device configuration and management
+         by the operating system. It defines platform-independent interfaces
+         for configuration and power management monitoring.
+
 endmenu
 
 config MAX_PIRQ_LINKS
arch/x86/include/asm/acpi_table.h new file +7 -0
new file mode 100644
index 0000000..cceed97
@@ -0,0 +1,390 @@
+/*
+ * Based on acpi.c from coreboot
+ *
+ * Copyright (C) 2015, Saket Sinha <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */

arch/x86/include/asm/acpi_table.h line 17

Quoted 10 lines
arch/x86/include/asm/acpi_table.h new file +10 -0
+
+#include <common.h>
+#include <malloc.h>
+#include <asm/post.h>
+#include <linux/string.h>
+
+#define        RSDP_SIG        "RSD PTR "      /* RSDT pointer signature */
+#define        ACPI_TABLE_CREATOR      "UBOOT   "      /* Must be 8 bytes long! */
+#define        OEM_ID  "UBOOT "        /* Must be 6 bytes long! */
+#define        ASLC    "INTL"  /* Must be exactly 4 bytes long! */

I think you misunderstood me. I was saying adding tab to make those macros' values aligned on the same indention level. But no need to add tab between 'defined' and the macro. Like this:

#define<space>RSDP_SIG<one or more tabs>"RSD PTR "

[snip]

arch/x86/include/asm/acpi_table.h line 378

Quoted 6 lines
arch/x86/include/asm/acpi_table.h new file +6 -0
+/* FACS flags */
+#define        ACPI_FACS_S4BIOS_F      (1 << 0)
+#define        ACPI_FACS_64BIT_WAKE_F  (1 << 1)
+/* Bits 31..2: reserved */
+
+/* These can be used by the target port. */

Nits: ending period is not needed for a single sentence.

[snip]

Regards,
Bin

#5 lore raw

PATCH v6 2/3 x86: Add ACPI table support to QEMU

In reply to Saket Sinha

Hi Saket,

Quoted 2 lines · Saket Sinha

This patch mainly adds ACPI support to QEMU. Verified by booting Linux kernel on QEMU i440FX and Q35.

I don't think ACPI is for i440FX. Although it boots, but that does not mean ACPI really works. These ASL files describing Q35 platform, not i440FX.

Quoted 36 lines

---

 arch/x86/cpu/qemu/Makefile |   1 +
 arch/x86/cpu/qemu/acpi.c   | 179 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
 create mode 100644 arch/x86/cpu/qemu/acpi.c
arch/x86/cpu/qemu/Makefile +1 -0
index 9a66b16..8c3884c 100644
@@ -8,4 +8,5 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/qemu/acpi.c new file +11 -0
new file mode 100644
index 0000000..2496da7
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2015, Saket Sinha <[email protected]>
+ *
+ * SPDX-License-Identifier:   GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/acpi_table.h>
+#include <asm/ioapic.h>
+#include <asm/tables.h>
+

arch/x86/cpu/qemu/acpi.c line 21

Quoted 10 lines
arch/x86/cpu/qemu/acpi.c new file +10 -0
+void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
+               void *dsdt)
+{
+       acpi_header_t *header = &(fadt->header);
+       u16 pmbase;
+
+       pci_dev_t bdf = PCI_BDF(0, 0x1f, 0);
+       pci_read_config_word(bdf, 0x40, &pmbase);
+
+     /*

Nits: misaligned

arch/x86/cpu/qemu/acpi.c line 23

Quoted 2 lines
arch/x86/cpu/qemu/acpi.c new file +2 -0
+        * TODO(saket.sinha89 at gmail.com): wrong value
+        * of pmbase by above function. Harcoding it to

Typo: Hardcoding

arch/x86/cpu/qemu/acpi.c line 28

Quoted 5 lines
arch/x86/cpu/qemu/acpi.c new file +5 -0
+        * correct value. Since no PCI register is
+        * programmed Power Management Interface is
+        * not working
+        */
+

You still did not address this issue before sending v6. I don't understand why don't you just prepare a separate patch to program this PMBASE register by yourself. Are you waiting for me or Simon to do this, or are you looking for something else?

Quoted 142 lines
arch/x86/cpu/qemu/acpi.c new file +142 -0
+       pmbase = 0x0600;
+
+       memset((void *)fadt, 0, sizeof(struct acpi_fadt));
+       memcpy(header->signature, "FACP", 4);
+       header->length = sizeof(struct acpi_fadt);
+       header->revision = 3;
+       memcpy(header->oem_id, OEM_ID, 6);
+       memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
+       memcpy(header->asl_compiler_id, ASLC, 4);
+       header->asl_compiler_revision = 0;
+
+       fadt->firmware_ctrl = (unsigned long) facs;
+       fadt->dsdt = (unsigned long) dsdt;
+       fadt->model = 0x00;
+       fadt->preferred_pm_profile = PM_MOBILE;
+       fadt->sci_int = 0x9;
+       fadt->smi_cmd = 0;
+       fadt->acpi_enable = 0;
+       fadt->acpi_disable = 0;
+       fadt->s4bios_req = 0x0;
+       fadt->pstate_cnt = 0;
+       fadt->pm1a_evt_blk = pmbase;
+       fadt->pm1b_evt_blk = 0x0;
+       fadt->pm1a_cnt_blk = pmbase + 0x4;
+       fadt->pm1b_cnt_blk = 0x0;
+       fadt->pm2_cnt_blk = pmbase + 0x50;
+       fadt->pm_tmr_blk = pmbase + 0x8;
+       fadt->gpe0_blk = pmbase + 0x20;
+       fadt->gpe1_blk = 0;
+       fadt->pm1_evt_len = 4;
+       /*
+        * Upper word is reserved and
+        * Linux complains about 32 bit
+        */
+       fadt->pm1_cnt_len = 2;
+       fadt->pm2_cnt_len = 1;
+       fadt->pm_tmr_len = 4;
+       fadt->gpe0_blk_len = 16;
+       fadt->gpe1_blk_len = 0;
+       fadt->gpe1_base = 0;
+       fadt->cst_cnt = 0;
+       fadt->p_lvl2_lat = 1;
+       fadt->p_lvl3_lat = 0x39;
+       fadt->flush_size = 0;
+       fadt->flush_stride = 0;
+       fadt->duty_offset = 1;
+       fadt->duty_width = 3;
+       fadt->day_alrm = 0xd;
+       fadt->mon_alrm = 0x00;
+       fadt->century = 0x32;
+       fadt->iapc_boot_arch = 0x00;
+       fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
+                       ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_S4_RTC_WAKE |
+                       ACPI_FADT_DOCKING_SUPPORTED | ACPI_FADT_RESET_REGISTER |
+                       ACPI_FADT_PLATFORM_CLOCK;
+       fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
+       fadt->reset_reg.bit_width = 8;
+       fadt->reset_reg.bit_offset = 0;
+       fadt->reset_reg.resv = 0;
+       fadt->reset_reg.addrl = 0xcf9;
+       fadt->reset_reg.addrh = 0;
+       fadt->reset_value = 0x06;
+       /*
+        * Set X_FIRMWARE_CTRL only if FACS is
+        * above 4GB. If X_FIRMWARE_CTRL is set,
+        * then FIRMWARE_CTRL must be zero
+        */
+       fadt->x_firmware_ctl_l = 0;
+       fadt->x_firmware_ctl_h = 0;
+       fadt->x_dsdt_l = (unsigned long)dsdt;
+       fadt->x_dsdt_h = 0;
+       fadt->x_pm1a_evt_blk.space_id = 1;
+       fadt->x_pm1a_evt_blk.bit_width = 32;
+       fadt->x_pm1a_evt_blk.bit_offset = 0;
+       fadt->x_pm1a_evt_blk.resv = 0;
+       fadt->x_pm1a_evt_blk.addrl = pmbase;
+       fadt->x_pm1a_evt_blk.addrh = 0x0;
+       fadt->x_pm1b_evt_blk.space_id = 0;
+       fadt->x_pm1b_evt_blk.bit_width = 0;
+       fadt->x_pm1b_evt_blk.bit_offset = 0;
+       fadt->x_pm1b_evt_blk.resv = 0;
+       fadt->x_pm1b_evt_blk.addrl = 0x0;
+       fadt->x_pm1b_evt_blk.addrh = 0x0;
+       fadt->x_pm1a_cnt_blk.space_id = 1;
+       /*
+        * Upper word is reserved and
+        * Linux complains about 32 bit
+        */
+       fadt->x_pm1a_cnt_blk.bit_width = 16;
+       fadt->x_pm1a_cnt_blk.bit_offset = 0;
+       fadt->x_pm1a_cnt_blk.resv = 0;
+       fadt->x_pm1a_cnt_blk.addrl = pmbase + 0x4;
+       fadt->x_pm1a_cnt_blk.addrh = 0x0;
+       fadt->x_pm1b_cnt_blk.space_id = 0;
+       fadt->x_pm1b_cnt_blk.bit_width = 0;
+       fadt->x_pm1b_cnt_blk.bit_offset = 0;
+       fadt->x_pm1b_cnt_blk.resv = 0;
+       fadt->x_pm1b_cnt_blk.addrl = 0x0;
+       fadt->x_pm1b_cnt_blk.addrh = 0x0;
+       fadt->x_pm2_cnt_blk.space_id = 1;
+       fadt->x_pm2_cnt_blk.bit_width = 8;
+       fadt->x_pm2_cnt_blk.bit_offset = 0;
+       fadt->x_pm2_cnt_blk.resv = 0;
+       fadt->x_pm2_cnt_blk.addrl = pmbase + 0x50;
+       fadt->x_pm2_cnt_blk.addrh = 0x0;
+       fadt->x_pm_tmr_blk.space_id = 1;
+       fadt->x_pm_tmr_blk.bit_width = 32;
+       fadt->x_pm_tmr_blk.bit_offset = 0;
+       fadt->x_pm_tmr_blk.resv = 0;
+       fadt->x_pm_tmr_blk.addrl = pmbase + 0x8;
+       fadt->x_pm_tmr_blk.addrh = 0x0;
+       fadt->x_gpe0_blk.space_id = 1;
+       fadt->x_gpe0_blk.bit_width = 128;
+       fadt->x_gpe0_blk.bit_offset = 0;
+       fadt->x_gpe0_blk.resv = 0;
+       fadt->x_gpe0_blk.addrl = pmbase + 0x20;
+       fadt->x_gpe0_blk.addrh = 0x0;
+       fadt->x_gpe1_blk.space_id = 0;
+       fadt->x_gpe1_blk.bit_width = 0;
+       fadt->x_gpe1_blk.bit_offset = 0;
+       fadt->x_gpe1_blk.resv = 0;
+       fadt->x_gpe1_blk.addrl = 0x0;
+       fadt->x_gpe1_blk.addrh = 0x0;
+
+       header->checksum =
+           table_compute_checksum((void *)fadt, header->length);
+}
+
+unsigned long acpi_fill_madt(unsigned long current)
+{
+       /* create all subtables for processors */
+       current = acpi_create_madt_lapics(current);
+
+       /*
+        * TODO(saket.sinha89 at gmail.com): get these
+        * IRQ values from device tree
+        */
+       current += acpi_create_madt_ioapic
+               ((struct acpi_madt_ioapic *)current, 2, IO_APIC_ADDR, 0);
+       current += acpi_create_madt_irqoverride
+               ((struct acpi_madt_irqoverride *)current, 0, 0, 2, 0);
+       current += acpi_create_madt_irqoverride

arch/x86/cpu/qemu/acpi.c

Quoted 10 lines
arch/x86/cpu/qemu/acpi.c new file +9 -1
+               ((struct acpi_madt_irqoverride *)current, 0, 9, 9, 0xd);
+       current += acpi_create_madt_irqoverride
+               ((struct acpi_madt_irqoverride *)current, 0, 0xd, 0xd, 0xd);
+       acpi_create_madt_lapic_nmi
+               ((struct acpi_madt_lapic_nmi *)current, 0, 0, 0);
+
+       return current;
+}
+
--

Regards,
Bin

#6 lore raw

PATCH v6 2/3 x86: Add ACPI table support to QEMU

In reply to Bin Meng

Hi Bin,

Quoted 70 lines · Bin Meng

Hi Saket,

Quoted 2 lines · Saket Sinha

This patch mainly adds ACPI support to QEMU. Verified by booting Linux kernel on QEMU i440FX and Q35.

I don't think ACPI is for i440FX. Although it boots, but that does not mean ACPI really works. These ASL files describing Q35 platform, not i440FX.

Quoted 36 lines

---

 arch/x86/cpu/qemu/Makefile |   1 +
 arch/x86/cpu/qemu/acpi.c   | 179 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
 create mode 100644 arch/x86/cpu/qemu/acpi.c
arch/x86/cpu/qemu/Makefile +1 -0
index 9a66b16..8c3884c 100644
@@ -8,4 +8,5 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/qemu/acpi.c new file +11 -0
new file mode 100644
index 0000000..2496da7
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2015, Saket Sinha <[email protected]>
+ *
+ * SPDX-License-Identifier:   GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/acpi_table.h>
+#include <asm/ioapic.h>
+#include <asm/tables.h>
+

arch/x86/cpu/qemu/acpi.c line 21

Quoted 10 lines
arch/x86/cpu/qemu/acpi.c new file +10 -0
+void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
+               void *dsdt)
+{
+       acpi_header_t *header = &(fadt->header);
+       u16 pmbase;
+
+       pci_dev_t bdf = PCI_BDF(0, 0x1f, 0);
+       pci_read_config_word(bdf, 0x40, &pmbase);
+
+     /*

Nits: misaligned

arch/x86/cpu/qemu/acpi.c line 23

Quoted 2 lines
arch/x86/cpu/qemu/acpi.c new file +2 -0
+        * TODO(saket.sinha89 at gmail.com): wrong value
+        * of pmbase by above function. Harcoding it to

Typo: Hardcoding

arch/x86/cpu/qemu/acpi.c line 28

Quoted 5 lines
arch/x86/cpu/qemu/acpi.c new file +5 -0
+        * correct value. Since no PCI register is
+        * programmed Power Management Interface is
+        * not working
+        */
+
Quoted 5 lines

You still did not address this issue before sending v6. I don't understand why don't you just prepare a separate patch to program this PMBASE register by yourself. Are you waiting for me or Simon to do this, or are you looking for something else?

As discussed with Simon, he wants me to come up with ACPI support on Minnowmax first and look up for QEMU fixes later before the deadline of this program(GSOC) ends.

Currently, I have been working on Minnowmax ACPI support and post a workable patch for the same on mailing list ASAP.

If you want me to currently stop on this activity and work on the Qemu patch which programs PMBASE register first,
let us discuss it with Simon and plan accordingly.

Regards,
Saket Sinha

#7 lore raw

PATCH v6 2/3 x86: Add ACPI table support to QEMU

Hi Saket,

Quoted 84 lines · Saket Sinha

Hi Bin,

Quoted 70 lines · Bin Meng

Hi Saket,

Quoted 2 lines · Saket Sinha

This patch mainly adds ACPI support to QEMU. Verified by booting Linux kernel on QEMU i440FX and Q35.

I don't think ACPI is for i440FX. Although it boots, but that does not mean ACPI really works. These ASL files describing Q35 platform, not i440FX.

Quoted 36 lines

---

 arch/x86/cpu/qemu/Makefile |   1 +
 arch/x86/cpu/qemu/acpi.c   | 179 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
 create mode 100644 arch/x86/cpu/qemu/acpi.c
arch/x86/cpu/qemu/Makefile +1 -0
index 9a66b16..8c3884c 100644
@@ -8,4 +8,5 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/qemu/acpi.c new file +11 -0
new file mode 100644
index 0000000..2496da7
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2015, Saket Sinha <[email protected]>
+ *
+ * SPDX-License-Identifier:   GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/acpi_table.h>
+#include <asm/ioapic.h>
+#include <asm/tables.h>
+

arch/x86/cpu/qemu/acpi.c line 21

Quoted 10 lines
arch/x86/cpu/qemu/acpi.c new file +10 -0
+void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
+               void *dsdt)
+{
+       acpi_header_t *header = &(fadt->header);
+       u16 pmbase;
+
+       pci_dev_t bdf = PCI_BDF(0, 0x1f, 0);
+       pci_read_config_word(bdf, 0x40, &pmbase);
+
+     /*

Nits: misaligned

arch/x86/cpu/qemu/acpi.c line 23

Quoted 2 lines
arch/x86/cpu/qemu/acpi.c new file +2 -0
+        * TODO(saket.sinha89 at gmail.com): wrong value
+        * of pmbase by above function. Harcoding it to

Typo: Hardcoding

arch/x86/cpu/qemu/acpi.c line 28

Quoted 5 lines
arch/x86/cpu/qemu/acpi.c new file +5 -0
+        * correct value. Since no PCI register is
+        * programmed Power Management Interface is
+        * not working
+        */
+
Quoted 5 lines

You still did not address this issue before sending v6. I don't understand why don't you just prepare a separate patch to program this PMBASE register by yourself. Are you waiting for me or Simon to do this, or are you looking for something else?

As discussed with Simon, he wants me to come up with ACPI support on Minnowmax first and look up for QEMU fixes later before the deadline of this program(GSOC) ends.

Quoted 7 lines

Currently, I have been working on Minnowmax ACPI support and post a workable patch for the same on mailing list ASAP.

If you want me to currently stop on this activity and work on the Qemu patch which programs PMBASE register first,
let us discuss it with Simon and plan accordingly.

OK, thanks for the update. It's better you'd send this clarification in your v5 patch thread which should have addressed my concern before sending v6.

Frankly speaking, working on MinnowMax now without a basically working ACPI platform does not save us time. So far ACPI on QEMU is just partially working. We only addressed the Configuration part, but nothing in the Power management part was looked at. That's where this PMBASE is concerned.

Regards,
Bin

#8 lore raw

PATCH v6 2/3 x86: Add ACPI table support to QEMU

Hi Bin,

Quoted 99 lines · Bin Meng

Hi Saket,

Quoted 84 lines · Saket Sinha

Hi Bin,

Quoted 70 lines · Bin Meng

Hi Saket,

Quoted 2 lines · Saket Sinha

This patch mainly adds ACPI support to QEMU. Verified by booting Linux kernel on QEMU i440FX and Q35.

I don't think ACPI is for i440FX. Although it boots, but that does not mean ACPI really works. These ASL files describing Q35 platform, not i440FX.

Quoted 36 lines

---

 arch/x86/cpu/qemu/Makefile |   1 +
 arch/x86/cpu/qemu/acpi.c   | 179 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
 create mode 100644 arch/x86/cpu/qemu/acpi.c
arch/x86/cpu/qemu/Makefile +1 -0
index 9a66b16..8c3884c 100644
@@ -8,4 +8,5 @@ ifndef CONFIG_EFI_STUB
 obj-y += car.o dram.o
 endif
 obj-y += qemu.o
+obj-$(CONFIG_GENERATE_ACPI_TABLE) += acpi.o
 obj-$(CONFIG_PCI) += pci.o
arch/x86/cpu/qemu/acpi.c new file +11 -0
new file mode 100644
index 0000000..2496da7
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2015, Saket Sinha <[email protected]>
+ *
+ * SPDX-License-Identifier:   GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/acpi_table.h>
+#include <asm/ioapic.h>
+#include <asm/tables.h>
+

arch/x86/cpu/qemu/acpi.c line 21

Quoted 10 lines
arch/x86/cpu/qemu/acpi.c new file +10 -0
+void acpi_create_fadt(struct acpi_fadt *fadt, struct acpi_facs *facs,
+               void *dsdt)
+{
+       acpi_header_t *header = &(fadt->header);
+       u16 pmbase;
+
+       pci_dev_t bdf = PCI_BDF(0, 0x1f, 0);
+       pci_read_config_word(bdf, 0x40, &pmbase);
+
+     /*

Nits: misaligned

arch/x86/cpu/qemu/acpi.c line 23

Quoted 2 lines
arch/x86/cpu/qemu/acpi.c new file +2 -0
+        * TODO(saket.sinha89 at gmail.com): wrong value
+        * of pmbase by above function. Harcoding it to

Typo: Hardcoding

arch/x86/cpu/qemu/acpi.c line 28

Quoted 5 lines
arch/x86/cpu/qemu/acpi.c new file +5 -0
+        * correct value. Since no PCI register is
+        * programmed Power Management Interface is
+        * not working
+        */
+
Quoted 5 lines

You still did not address this issue before sending v6. I don't understand why don't you just prepare a separate patch to program this PMBASE register by yourself. Are you waiting for me or Simon to do this, or are you looking for something else?

As discussed with Simon, he wants me to come up with ACPI support on Minnowmax first and look up for QEMU fixes later before the deadline of this program(GSOC) ends.

Quoted 7 lines

Currently, I have been working on Minnowmax ACPI support and post a workable patch for the same on mailing list ASAP.

If you want me to currently stop on this activity and work on the Qemu patch which programs PMBASE register first,
let us discuss it with Simon and plan accordingly.

OK, thanks for the update. It's better you'd send this clarification in your v5 patch thread which should have addressed my concern before sending v6.

Quoted 5 lines

Frankly speaking, working on MinnowMax now without a basically working ACPI platform does not save us time. So far ACPI on QEMU is just partially working. We only addressed the Configuration part, but nothing in the Power management part was looked at. That's where this PMBASE is concerned.

I agree with you on this but what I believe is that if I post a minimal working patch of minnowmax on the mailing list, others can review and gauge the work done and current progress.

Let Simon has his opinion on this and then we can decide as to what actions to take from here.

Regards,
Saket Sinha

#3 lore raw

PATCH v6 1/3 x86: Generate a valid ACPI table

In reply to Saket Sinha

Hi,

Quoted 13 lines · Saket Sinha

Implement write_acpi_table() to create a minimal working ACPI table. This includes writing FACS, XSDT, RSDP, FADT, MCFG, MADT, DSDT & SSDT ACPI table entries.

Use a Kconfig option GENERATE_ACPI_TABLE to tell U-Boot whether we need actually write the APCI table just like we did for PIRQ routing, MP table and SFI tables. With ACPI table existence, linux kernel gets control of power management, thermal management, configuration management and monitoring in hardware.

---

Quoted 9 lines
 arch/x86/Kconfig                  |   9 +
 arch/x86/include/asm/acpi_table.h | 390 ++++++++++++++++++++++++++++++++++
 arch/x86/lib/Makefile             |   1 +
 arch/x86/lib/acpi_table.c         | 436 ++++++++++++++++++++++++++++++++++++++
 arch/x86/lib/tables.c             |   5 +
 scripts/Makefile.lib              |  11 +
 6 files changed, 852 insertions(+)
 create mode 100644 arch/x86/include/asm/acpi_table.h
 create mode 100644 arch/x86/lib/acpi_table.c

I'd like to get this in and deal with TODOs and other changes with separate patches.

I've fixed up a few minor whitespace things. If there is anything else really egregious I'll accept a fix-up patch for a few days.

Applied to u-boot-x86, thanks!

#9 lore raw

PATCH v6 2/3 x86: Add ACPI table support to QEMU

In reply to Saket Sinha

Hi,

Quoted 10 lines · Saket Sinha

This patch mainly adds ACPI support to QEMU. Verified by booting Linux kernel on QEMU i440FX and Q35.

---

 arch/x86/cpu/qemu/Makefile |   1 +
 arch/x86/cpu/qemu/acpi.c   | 179 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
 create mode 100644 arch/x86/cpu/qemu/acpi.c

I'd like to get this in and deal with TODOs and other changes with separate patches.

I've fixed up a few minor whitespace things. If there is anything else really egregious I'll accept a fix-up patch for a few days.

Applied to u-boot-x86, thanks!

#12 lore raw

PATCH v6 3/3 x86: Add DSDT table for supporting ACPI on QEMU

In reply to Saket Sinha
Quoted 5 lines · Saket Sinha

The DSDT table contains a bytecode that is executed by a driver in the kernel.

---

Quoted 14 lines
 arch/x86/cpu/qemu/Makefile             |   2 +-
 arch/x86/cpu/qemu/acpi/cpu-hotplug.asl |  80 +++++++
 arch/x86/cpu/qemu/acpi/dbug.asl        |  25 ++
 arch/x86/cpu/qemu/acpi/hpet.asl        |  31 +++
 arch/x86/cpu/qemu/acpi/isa.asl         | 102 ++++++++
 arch/x86/cpu/qemu/acpi/pci-crs.asl     |  61 +++++
 arch/x86/cpu/qemu/dsdt.asl             | 412 +++++++++++++++++++++++++++++++++
 7 files changed, 712 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/cpu/qemu/acpi/cpu-hotplug.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/dbug.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/hpet.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/isa.asl
 create mode 100644 arch/x86/cpu/qemu/acpi/pci-crs.asl
 create mode 100644 arch/x86/cpu/qemu/dsdt.asl

Applied to u-boot-x86, thanks!