ACPI related fixes to comform the spec better
PATCH v4 1/10 checkpatch: don't emit warning on newly created acpi data files
In reply to [email protected]From: Isaku Yamahata <[email protected]>
Newly created acpi data files(tests/data/acpi/) cause false positive warning.
If file names are acpi expected file, don't emit warning.
--- scripts/checkpatch.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +3 -1
@@ -1530,7 +1530,9 @@ sub process { ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && - (defined($1) || defined($2))))) { + (defined($1) || defined($2)))) && + !(($realfile ne '') && + ($realfile eq $acpi_testexpected))) { $reported_maintainer_file = 1; WARN("added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); }
Signature · 1 line
2.17.1
PATCH v4 8/10 i386: acpi: Don't build HPET ACPI entry if HPET is disabled
In reply to [email protected]From: Sean Christopherson <[email protected]>
Omit HPET AML if the HPET is disabled, QEMU is not emulating it and the guest may get confused by seeing HPET in the ACPI tables without a "physical" device present.
The change of DSDT when -no-hpet is as follows.
@@ -141,47 +141,6 @@ DefinitionBlock ("", "DSDT", 1, "BOCHS "
}
}- Scope (_SB)
- {
- Device (HPET)
- {
- Name (_HID, EisaId ("PNP0103") /* HPET System Timer */) // _HID: Hardware ID
- Name (_UID, Zero) // _UID: Unique ID
- OperationRegion (HPTM, SystemMemory, 0xFED00000, 0x0400)
- Field (HPTM, DWordAcc, Lock, Preserve)
- {
- VEND, 32,
- PRD, 32- }
-
- Method (_STA, 0, NotSerialized) // _STA: Status
- {
- Local0 = VEND /* \_SB_.HPET.VEND */
- Local1 = PRD /* \_SB_.HPET.PRD_ */
- Local0 >>= 0x10
- If (((Local0 == Zero) || (Local0 == 0xFFFF)))
- {- Return (Zero)
- }
-
- If (((Local1 == Zero) || (Local1 > 0x05F5E100)))
- {
- Return (Zero)
- }
-
- Return (0x0F)
- }
-
- Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
- {
- Memory32Fixed (ReadOnly,
- 0xFED00000, // Address Base - 0x00000400, // Address Length - )
- })
- }
- }
-
Scope (_SB.PCI0)
{
Device (ISA)--- hw/i386/acpi-build.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/i386/acpi-build.c +6 -2
@@ -1290,7 +1290,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (sb_scope, dev);aml_append (dsdt, sb_scope); -build_hpet_aml (dsdt); +if (misc->has_hpet) { +build_hpet_aml (dsdt); + }build_piix4_isa_bridge (dsdt);build_isa_devices_aml (dsdt);if (pm->pcihp_bridge_en || pm->pcihp_root_en) {
@@ -1337,7 +1339,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dsdt, sb_scope); -build_hpet_aml (dsdt); +if (misc->has_hpet) { +build_hpet_aml (dsdt); + }build_q35_isa_bridge (dsdt);build_isa_devices_aml (dsdt);build_q35_pci0_int (dsdt);
Signature · 1 line
2.17.1
PATCH v4 5/10 acpi: set fadt.smi_cmd to zero when SMM is not supported
In reply to [email protected]From: Isaku Yamahata <[email protected]>
From table 5.9 SMI_CMD of ACPI spec
Quoted 2 lines
This field is reserved and must be zero on system
that does not support System Management mode.
When smm is not enabled, set it to zero to comform to the spec. When -machine smm=off is passed, the change to FACP is as follows.
@@ -1,46 +1,46 @@
/*
* Intel ACPI Component Architecture
* AML/ASL+ Disassembler version 20180105 (64-bit version)
* Copyright (c) 2000 - 2018 Intel Corporation
*
- * Disassembly of tests/data/acpi/q35/FACP, Fri Feb 5 16:57:04 2021
+ * Disassembly of /tmp/aml-1OQYX0, Fri Feb 5 16:57:04 2021 *
* ACPI Data Table [FACP]
*
* Format: [HexOffset DecimalOffset ByteLength] FieldName : FieldValue */
[000h 0000 4] Signature : "FACP" [Fixed ACPI Description Table (FADT)] [004h 0004 4] Table Length : 000000F4 [008h 0008 1] Revision : 03 -[009h 0009 1] Checksum : 1F +[009h 0009 1] Checksum : D6 [00Ah 0010 6] Oem ID : "BOCHS " [010h 0016 8] Oem Table ID : "BXPCFACP" [018h 0024 4] Oem Revision : 00000001 [01Ch 0028 4] Asl Compiler ID : "BXPC" [020h 0032 4] Asl Compiler Revision : 00000001
[024h 0036 4] FACS Address : 00000000 [028h 0040 4] DSDT Address : 00000000 [02Ch 0044 1] Model : 01 [02Dh 0045 1] PM Profile : 00 [Unspecified] [02Eh 0046 2] SCI Interrupt : 0009 -[030h 0048 4] SMI Command Port : 000000B2 -[034h 0052 1] ACPI Enable Value : 02 -[035h 0053 1] ACPI Disable Value : 03 +[030h 0048 4] SMI Command Port : 00000000 +[034h 0052 1] ACPI Enable Value : 00 +[035h 0053 1] ACPI Disable Value : 00 [036h 0054 1] S4BIOS Command : 00 [037h 0055 1] P-State Control : 00 [038h 0056 4] PM1A Event Block Address : 00000600 [03Ch 0060 4] PM1B Event Block Address : 00000000 [040h 0064 4] PM1A Control Block Address : 00000604 [044h 0068 4] PM1B Control Block Address : 00000000 [048h 0072 4] PM2 Control Block Address : 00000000 [04Ch 0076 4] PM Timer Block Address : 00000608 [050h 0080 4] GPE0 Block Address : 00000620 [054h 0084 4] GPE1 Block Address : 00000000 [058h 0088 1] PM1 Event Block Length : 04 [059h 0089 1] PM1 Control Block Length : 02 [05Ah 0090 1] PM2 Control Block Length : 00 [05Bh 0091 1] PM Timer Block Length : 04 [05Ch 0092 1] GPE0 Block Length : 10 [05Dh 0093 1] GPE1 Block Length : 00
--- hw/i386/acpi-build.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +15 -3
@@ -139,6 +139,14 @@ const struct AcpiGenericAddress x86_nvdimm_acpi_dsmio = {static void init_common_fadt_data (MachineState *ms,Object *o,AcpiFadtData *data) { +X86MachineState *x86ms =X86_MACHINE (ms); +/* +* "ICH9-LPC" or "PIIX4_PM" has "smm-compat" property to keep the old +* behavior for compatibility irrelevant to smm_enabled, which doesn't +* comforms to ACPI spec. +*/ +bool smm_enabled =object_property_get_bool (o,"smm-compat" ,NULL ) ? + true :x86_machine_is_smm_enabled (x86ms);uint32_t io =object_property_get_uint (o,ACPI_PM_PROP_PM_IO_BASE ,NULL );AmlAddressSpace as =AML_AS_SYSTEM_IO ;AcpiFadtData fadt = {
@@ -159,12 +167,16 @@ static void init_common_fadt_data(MachineState *ms, Object *o, .rtc_century = RTC_CENTURY, .plvl2_lat = 0xfff /* C2 state not supported */, .plvl3_lat = 0xfff /* C3 state not supported */, - .smi_cmd = ACPI_PORT_SMI_CMD, + .smi_cmd = smm_enabled ? ACPI_PORT_SMI_CMD : 0, .sci_int = object_property_get_uint(o, ACPI_PM_PROP_SCI_INT, NULL), .acpi_enable_cmd = - object_property_get_uint(o, ACPI_PM_PROP_ACPI_ENABLE_CMD, NULL), + smm_enabled ? +object_property_get_uint (o,ACPI_PM_PROP_ACPI_ENABLE_CMD ,NULL ) : + 0, .acpi_disable_cmd = - object_property_get_uint(o, ACPI_PM_PROP_ACPI_DISABLE_CMD, NULL), + smm_enabled ? +object_property_get_uint (o,ACPI_PM_PROP_ACPI_DISABLE_CMD ,NULL ) : + 0, .pm1a_evt = { .space_id = as, .bit_width = 4 * 8, .address = io }, .pm1a_cnt = { .space_id = as, .bit_width = 2 * 8, .address = io + 0x04 },
Signature · 1 line
2.17.1
PATCH v4 7/10 hw/i386: declare ACPI mother board resource for MMCONFIG region
In reply to [email protected]From: Isaku Yamahata <[email protected]>
Declare PNP0C01 device to reserve MMCONFIG region to conform to the spec better and play nice with guest BIOSes/OSes.
According to PCI Firmware Specification[0], MMCONFIG region must be reserved by declaring a motherboard resource. It's optional to reserve the region in memory map by Int 15 E820h or EFIGetMemoryMap. Guest Linux checks if the MMCFG region is reserved by bios memory map or ACPI resource. If it's not reserved, Linux falls back to legacy PCI configuration access.
TDVF [1] [2] doesn't reserve MMCONFIG the region in memory map. On the other hand OVMF reserves it in memory map without declaring a motherboard resource. With memory map reservation, linux guest uses MMCONFIG region. However it doesn't comply to PCI Firmware specification.
[0] PCI Firmware specification Revision 3.2
4.1.2 MCFG Table Description table 4-2 NOTE 2
If the operating system does not natively comprehend reserving the MMCFG region, The MMCFG region must e reserved by firmware. ... For most systems, the mortheroard resource would appear at the root of the ACPI namespace (under \_SB)...
The resource can optionally be returned in Int15 E820h or EFIGetMemoryMap as reserved memory but must always be reported through ACPI as a motherboard resource
[1] TDX: Intel Trust Domain Extension
https://software.intel.com/content/www/us/en/develop/articles/intel-trust-domain-extensions.html
[2] TDX Virtual Firmware
https://github.com/tianocore/edk2-staging/tree/TDVF
The change to DSDT is as follows.
@@ -68,32 +68,51 @@
If ((CDW3 != Local0))
{
CDW1 |= 0x10
}
CDW3 = Local0
}
Else
{
CDW1 |= 0x04
}
Return (Arg3)
}
}
+
+ Device (DRAC)
+ {
+ Name (_HID, "PNP0C01" /* System Board */) // _HID: Hardware ID
+ Name (RBUF, ResourceTemplate ()
+ {
+ DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
+ 0x00000000, // Granularity
+ 0xB0000000, // Range Minimum
+ 0xB0000000, // Range Maximum
+ 0x00000000, // Translation Offset
+ 0x10000000, // Length
+ ,, , AddressRangeMemory, TypeStatic)
+ })
+ Method (_CRS, 0, Serialized) // _CRS: Current Resource Settings
+ {
+ Return (RBUF) /* \_SB_.DRAC.RBUF */
+ }
+ }
}
Scope (_SB)
{
Device (HPET)
{
Name (_HID, EisaId ("PNP0103") /* HPET System Timer */) // _HID: Hardware ID
Name (_UID, Zero) // _UID: Unique ID
OperationRegion (HPTM, SystemMemory, 0xFED00000, 0x0400)
Field (HPTM, DWordAcc, Lock, Preserve)
{
VEND, 32,
PRD, 32
}
Method (_STA, 0, NotSerialized) // _STA: Status--- hw/i386/acpi-build.c | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)
hw/i386/acpi-build.c +54 -1
@@ -1072,6 +1072,55 @@ static void build_q35_pci0_int(Aml *table)aml_append (table, sb_scope); } +static Aml *build_q35_dram_controller (AcpiMcfgInfo *mcfg) +{ +Aml *dev; +Aml *rbuf; +Aml *resource_template; +Aml *rbuf_name; +Aml *crs; + +/* DRAM controller */ + dev =aml_device ("DRAC" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0C01" ))); + + resource_template =aml_resource_template (); +if (mcfg->base + mcfg->size -1 >= (1ULL <<32 )) { +aml_append (resource_template, +aml_qword_memory (AML_POS_DECODE , +AML_MIN_FIXED , +AML_MAX_FIXED , +AML_NON_CACHEABLE , +AML_READ_WRITE , +0x0000000000000000 , + mcfg->base, + mcfg->base, +0x0000000000000000 , + mcfg->size)); + }else { +aml_append (resource_template, +aml_dword_memory (AML_POS_DECODE , +AML_MIN_FIXED , +AML_MAX_FIXED , +AML_NON_CACHEABLE , +AML_READ_WRITE , +0x0000000000000000 , + mcfg->base, + mcfg->base, +0x0000000000000000 , + mcfg->size)); + } + rbuf =aml_name_decl ("RBUF" , resource_template); +aml_append (dev, rbuf); + + crs =aml_method ("_CRS" ,0 ,AML_SERIALIZED ); + rbuf_name =aml_name ("RBUF" ); +aml_append (crs,aml_return (rbuf_name)); +aml_append (dev, crs); + +return dev; +} +static void build_q35_isa_bridge (Aml *table) {Aml *dev;
@@ -1218,6 +1267,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (machine);X86MachineState *x86ms =X86_MACHINE (machine);AcpiMcfgInfo mcfg; +bool mcfg_valid = !!acpi_get_mcfg (&mcfg);uint32_t nr_mem = machine->ram_slots;int root_bus_limit =0xFF ;PCIBus *bus =NULL ;
@@ -1256,6 +1306,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 )));aml_append (dev,build_q35_osc_method ());aml_append (sb_scope, dev); +if (mcfg_valid) { +aml_append (sb_scope,build_q35_dram_controller (&mcfg)); + }if (pm->smi_on_cpuhp) {/* reserve SMI block resources, IO ports 0xB2, 0xB3 */
@@ -1386,7 +1439,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,* the PCI0._CRS. Add mmconfig to the set so it will be excluded * too. */ -if (acpi_get_mcfg (&mcfg)) { +if (mcfg_valid) {crs_range_insert (crs_range_set.mem_ranges, mcfg.base, mcfg.base + mcfg.size -1 ); }
Signature · 1 line
2.17.1
v4 cover ACPI related fixes to comform the spec better
From: Isaku Yamahata <[email protected]>
Miscellaneous bug fixes related to ACPI to play nice with guest BIOSes/OSes by conforming to ACPI spec better.
Changes from v3:
- rename compat property name to smm-compat and add it to ICH9-LPC and PIIX4_PM
- MMCFG memory region to use dword memory region when possible
- fix max base address of MMCFG memory region
- add more test cases with smm-compat=on and/or piix4
Changes from v2:
- improved commit message
- introduced compat property x-smm-compat-5
- _CRS for MMCONFIG resource, read MMCONFIG info from qemu, generate resource instead of dynamically reading chipset configuration.
Changes from v1:
- fixed style issue with fixes to checkpatch.pl
- fixed make check breakage
- added ACPI table tests
- update comment message to include acpi table diff
Isaku Yamahata (9):
checkpatch: don't emit warning on newly created acpi data files
qtest: update tests/qtest/bios-tables-test-allowed-diff.h ich9, piix4: add properoty, smm-compat, to keep compatibility of SMM acpi/core: always set SCI_EN when SMM isn't supported
acpi: set fadt.smi_cmd to zero when SMM is not supported
acpi: add test case for smm unsupported -machine smm=off hw/i386: declare ACPI mother board resource for MMCONFIG region
acpi: add test case for -no-hpet qtest/acpi/bios-tables-test: update acpi tables
Sean Christopherson (1):
i386: acpi: Don't build HPET ACPI entry if HPET is disabled
hw/acpi/core.c | 11 +++- hw/acpi/ich9.c | 2 +- hw/acpi/piix4.c | 5 +- hw/core/machine.c | 5 +- hw/i386/acpi-build.c | 81 ++++++++++++++++++++++-- hw/isa/lpc_ich9.c | 1 + hw/isa/vt82c686.c | 2 +- include/hw/acpi/acpi.h | 4 +- include/hw/acpi/ich9.h | 1 + scripts/checkpatch.pl | 4 +- tests/data/acpi/pc/DSDT.nohpet | Bin 0 -> 4923 bytes tests/data/acpi/pc/FACP.nosmm | Bin 0 -> 116 bytes tests/data/acpi/q35/DSDT | Bin 7801 -> 7872 bytes tests/data/acpi/q35/DSDT.acpihmat | Bin 9126 -> 9197 bytes tests/data/acpi/q35/DSDT.bridge | Bin 7819 -> 7890 bytes tests/data/acpi/q35/DSDT.cphp | Bin 8265 -> 8336 bytes tests/data/acpi/q35/DSDT.dimmpxm | Bin 9455 -> 9526 bytes tests/data/acpi/q35/DSDT.ipmibt | Bin 7876 -> 7947 bytes tests/data/acpi/q35/DSDT.memhp | Bin 9160 -> 9231 bytes tests/data/acpi/q35/DSDT.mmio64 | Bin 8932 -> 9003 bytes tests/data/acpi/q35/DSDT.nohpet | Bin 0 -> 7730 bytes tests/data/acpi/q35/DSDT.numamem | Bin 7807 -> 7878 bytes tests/data/acpi/q35/DSDT.tis | Bin 8407 -> 8478 bytes tests/data/acpi/q35/FACP.nosmm | Bin 0 -> 244 bytes tests/qtest/bios-tables-test.c | 100 ++++++++++++++++++++++++++++++ 25 files changed, 203 insertions(+), 13 deletions(-) create mode 100644 tests/data/acpi/pc/DSDT.nohpet create mode 100644 tests/data/acpi/pc/FACP.nosmm create mode 100644 tests/data/acpi/q35/DSDT.nohpet create mode 100644 tests/data/acpi/q35/FACP.nosmm
Signature · 1 line
2.17.1
PATCH v4 9/10 acpi: add test case for -no-hpet
From: Isaku Yamahata <[email protected]>
--- tests/qtest/bios-tables-test.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
tests/qtest/bios-tables-test.c +24 -0
@@ -990,6 +990,17 @@ static void test_acpi_piix4_tcg_smm_compat_nosmm(void)free_test_data (&data); } +static void test_acpi_piix4_tcg_nohpet (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".nohpet" ; +test_acpi_one ("-no-hpet" , &data); +free_test_data (&data); +} +static void test_acpi_q35_tcg_numamem (void ) {test_data data;
@@ -1035,6 +1046,17 @@ static void test_acpi_q35_tcg_smm_compat_nosmm(void)free_test_data (&data); } +static void test_acpi_q35_tcg_nohpet (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".nohpet" ; +test_acpi_one ("-no-hpet" , &data); +free_test_data (&data); +} +static void test_acpi_piix4_tcg_numamem (void ) {test_data data;
@@ -1396,11 +1418,13 @@ int main(int argc, char *argv[]) test_acpi_piix4_tcg_smm_compat);qtest_add_func ("acpi/piix4/smm-compat-nosmm" , test_acpi_piix4_tcg_smm_compat_nosmm); +qtest_add_func ("acpi/piix4/nohpet" , test_acpi_piix4_tcg_nohpet);qtest_add_func ("acpi/q35/nosmm" , test_acpi_q35_tcg_nosmm);qtest_add_func ("acpi/q35/smm-compat" , test_acpi_q35_tcg_smm_compat);qtest_add_func ("acpi/q35/smm-compat-nosmm" , test_acpi_q35_tcg_smm_compat_nosmm); +qtest_add_func ("acpi/q35/nohpet" , test_acpi_q35_tcg_nohpet);qtest_add_func ("acpi/piix4/dimmpxm" , test_acpi_piix4_tcg_dimm_pxm);qtest_add_func ("acpi/q35/dimmpxm" , test_acpi_q35_tcg_dimm_pxm);qtest_add_func ("acpi/piix4/acpihmat" , test_acpi_piix4_tcg_acpi_hmat);
Signature · 1 line
2.17.1
PATCH v4 2/10 qtest: update tests/qtest/bios-tables-test-allowed-diff.h
In reply to [email protected]From: Isaku Yamahata <[email protected]>
The following tests will modify acpi tables.
prepare qtests to allow acpi table change.
add new tables for new tests.
- tests/data/acpi/pc/DSDT.nohpet
- tests/data/acpi/pc/FACP.nosmm
- tests/data/acpi/q35/DSDT.nohpet
- tests/data/acpi/q35/FACP.nosmm
--- tests/data/acpi/pc/DSDT.nohpet | 0 tests/data/acpi/pc/FACP.nosmm | 0 tests/data/acpi/q35/DSDT.nohpet | 0 tests/data/acpi/q35/FACP.nosmm | 0 tests/qtest/bios-tables-test-allowed-diff.h | 14 ++++++++++++++ 5 files changed, 14 insertions(+) create mode 100644 tests/data/acpi/pc/DSDT.nohpet create mode 100644 tests/data/acpi/pc/FACP.nosmm create mode 100644 tests/data/acpi/q35/DSDT.nohpet create mode 100644 tests/data/acpi/q35/FACP.nosmm
tests/data/acpi/pc/DSDT.nohpet new file +0 -0
tests/data/acpi/pc/FACP.nosmm new file +0 -0
tests/data/acpi/q35/DSDT.nohpet new file +0 -0
tests/data/acpi/q35/FACP.nosmm new file +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +14 -0
@@ -1 +1,15 @@/* List of comma-separated changed AML files to ignore */ +"tests/data/acpi/pc/FACP.nosmm" , +"tests/data/acpi/pc/DSDT.nohpet" , +"tests/data/acpi/q35/DSDT" , +"tests/data/acpi/q35/DSDT.tis" , +"tests/data/acpi/q35/DSDT.bridge" , +"tests/data/acpi/q35/DSDT.mmio64" , +"tests/data/acpi/q35/DSDT.ipmibt" , +"tests/data/acpi/q35/DSDT.cphp" , +"tests/data/acpi/q35/DSDT.memhp" , +"tests/data/acpi/q35/DSDT.numamem" , +"tests/data/acpi/q35/FACP.nosmm" , +"tests/data/acpi/q35/DSDT.nohpet" , +"tests/data/acpi/q35/DSDT.dimmpxm" , +"tests/data/acpi/q35/DSDT.acpihmat",
Signature · 1 line
2.17.1
PATCH v4 6/10 acpi: add test case for smm unsupported -machine smm=off
In reply to [email protected]From: Isaku Yamahata <[email protected]>
--- tests/qtest/bios-tables-test.c | 76 ++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
tests/qtest/bios-tables-test.c +76 -0
@@ -957,6 +957,39 @@ static void test_acpi_piix4_tcg_memhp(void)free_test_data (&data); } +static void test_acpi_piix4_tcg_nosmm (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".nosmm" ; +test_acpi_one ("-machine smm=off" , &data); +free_test_data (&data); +} + +static void test_acpi_piix4_tcg_smm_compat (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".smm-compat" ; +test_acpi_one ("-global PIIX4_PM.smm-compat=on" , &data); +free_test_data (&data); +} + +static void test_acpi_piix4_tcg_smm_compat_nosmm (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".smm-compat-nosmm" ; +test_acpi_one ("-global PIIX4_PM.smm-compat=on -machine smm=off" , &data); +free_test_data (&data); +} +static void test_acpi_q35_tcg_numamem (void ) {test_data data;
@@ -969,6 +1002,39 @@ static void test_acpi_q35_tcg_numamem(void)free_test_data (&data); } +static void test_acpi_q35_tcg_nosmm (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".nosmm" ; +test_acpi_one ("-machine smm=off" , &data); +free_test_data (&data); +} + +static void test_acpi_q35_tcg_smm_compat (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".smm-compat" ; +test_acpi_one ("-global ICH9-LPC.smm-compat=on" , &data); +free_test_data (&data); +} + +static void test_acpi_q35_tcg_smm_compat_nosmm (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".smm-compat-nosmm" ; +test_acpi_one ("-global ICH9-LPC.smm-compat=on -machine smm=off" , &data); +free_test_data (&data); +} +static void test_acpi_piix4_tcg_numamem (void ) {test_data data;
@@ -1325,6 +1391,16 @@ int main(int argc, char *argv[])qtest_add_func ("acpi/q35/memhp" , test_acpi_q35_tcg_memhp);qtest_add_func ("acpi/piix4/numamem" , test_acpi_piix4_tcg_numamem);qtest_add_func ("acpi/q35/numamem" , test_acpi_q35_tcg_numamem); +qtest_add_func ("acpi/piix4/nosmm" , test_acpi_piix4_tcg_nosmm); +qtest_add_func ("acpi/piix4/smm-compat" , + test_acpi_piix4_tcg_smm_compat); +qtest_add_func ("acpi/piix4/smm-compat-nosmm" , + test_acpi_piix4_tcg_smm_compat_nosmm); +qtest_add_func ("acpi/q35/nosmm" , test_acpi_q35_tcg_nosmm); +qtest_add_func ("acpi/q35/smm-compat" , + test_acpi_q35_tcg_smm_compat); +qtest_add_func ("acpi/q35/smm-compat-nosmm" , + test_acpi_q35_tcg_smm_compat_nosmm);qtest_add_func ("acpi/piix4/dimmpxm" , test_acpi_piix4_tcg_dimm_pxm);qtest_add_func ("acpi/q35/dimmpxm" , test_acpi_q35_tcg_dimm_pxm);qtest_add_func ("acpi/piix4/acpihmat" , test_acpi_piix4_tcg_acpi_hmat);
Signature · 1 line
2.17.1
PATCH v4 10/10 qtest/acpi/bios-tables-test: update acpi tables
In reply to [email protected]From: Isaku Yamahata <[email protected]>
update golden master acpi tables and emptybios-tables-test-allowed-diff.h.
--- tests/data/acpi/pc/DSDT.nohpet | Bin 0 -> 4923 bytes tests/data/acpi/pc/FACP.nosmm | Bin 0 -> 116 bytes tests/data/acpi/q35/DSDT | Bin 7801 -> 7872 bytes tests/data/acpi/q35/DSDT.acpihmat | Bin 9126 -> 9197 bytes tests/data/acpi/q35/DSDT.bridge | Bin 7819 -> 7890 bytes tests/data/acpi/q35/DSDT.cphp | Bin 8265 -> 8336 bytes tests/data/acpi/q35/DSDT.dimmpxm | Bin 9455 -> 9526 bytes tests/data/acpi/q35/DSDT.ipmibt | Bin 7876 -> 7947 bytes tests/data/acpi/q35/DSDT.memhp | Bin 9160 -> 9231 bytes tests/data/acpi/q35/DSDT.mmio64 | Bin 8932 -> 9003 bytes tests/data/acpi/q35/DSDT.nohpet | Bin 0 -> 7730 bytes tests/data/acpi/q35/DSDT.numamem | Bin 7807 -> 7878 bytes tests/data/acpi/q35/DSDT.tis | Bin 8407 -> 8478 bytes tests/data/acpi/q35/FACP.nosmm | Bin 0 -> 244 bytes tests/qtest/bios-tables-test-allowed-diff.h | 14 -------------- 15 files changed, 14 deletions(-)
tests/data/acpi/pc/DSDT.nohpet binary +0 -0
tests/data/acpi/pc/FACP.nosmm binary +0 -0
tests/data/acpi/q35/DSDT binary +0 -0
tests/data/acpi/q35/DSDT.acpihmat binary +0 -0
tests/data/acpi/q35/DSDT.bridge binary +0 -0
tests/data/acpi/q35/DSDT.cphp binary +0 -0
tests/data/acpi/q35/DSDT.dimmpxm binary +0 -0
tests/data/acpi/q35/DSDT.ipmibt binary +0 -0
tests/data/acpi/q35/DSDT.memhp binary +0 -0
tests/data/acpi/q35/DSDT.mmio64 binary +0 -0
tests/data/acpi/q35/DSDT.nohpet binary +0 -0
tests/data/acpi/q35/DSDT.numamem binary +0 -0
tests/data/acpi/q35/DSDT.tis binary +0 -0
tests/data/acpi/q35/FACP.nosmm binary +0 -0
tests/qtest/bios-tables-test-allowed-diff.h +0 -14
@@ -1,15 +1 @@/* List of comma-separated changed AML files to ignore */ -"tests/data/acpi/pc/FACP.nosmm" , -"tests/data/acpi/pc/DSDT.nohpet" , -"tests/data/acpi/q35/DSDT" , -"tests/data/acpi/q35/DSDT.tis" , -"tests/data/acpi/q35/DSDT.bridge" , -"tests/data/acpi/q35/DSDT.mmio64" , -"tests/data/acpi/q35/DSDT.ipmibt" , -"tests/data/acpi/q35/DSDT.cphp" , -"tests/data/acpi/q35/DSDT.memhp" , -"tests/data/acpi/q35/DSDT.numamem" , -"tests/data/acpi/q35/FACP.nosmm" , -"tests/data/acpi/q35/DSDT.nohpet" , -"tests/data/acpi/q35/DSDT.dimmpxm" , -"tests/data/acpi/q35/DSDT.acpihmat",
Signature · 1 line
2.17.1
PATCH v4 4/10 acpi/core: always set SCI_EN when SMM isn't supported
In reply to [email protected]From: Isaku Yamahata <[email protected]>
If SMM is not supported, ACPI fixed hardware doesn't support legacy-mode. ACPI-only platform. Where SCI_EN in PM1_CNT register is always set.
The bit tells OS legacy mode(SCI_EN cleared) or ACPI mode(SCI_EN set).
With the next patch (setting fadt.smi_cmd = 0 when smm isn't enabled), guest Linux tries to switch to ACPI mode, finds smi_cmd = 0, and then fails to initialize acpi subsystem. This patch proactively fixes it.
This patch changes guest ABI. To keep compatibility, use "x-smm-compat-5" introduced by earlier patch. If the property is true, disable new behavior.
ACPI spec 4.8.10.1 PM1 Event Grouping
PM1 Eanble Registers
Quoted 1 line
For ACPI-only platforms (where
SCI_ENis always set)
--- hw/acpi/core.c | 11 ++++++++++- hw/acpi/ich9.c | 2 +- hw/acpi/piix4.c | 3 ++- hw/isa/vt82c686.c | 2 +- include/hw/acpi/acpi.h | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-)
hw/acpi/core.c +10 -1
@@ -579,6 +579,10 @@ void acpi_pm1_cnt_update(ACPIREGS *ar, bool sci_enable, bool sci_disable) {/* ACPI specs 3.0, 4.7.2.5 */ +if (ar->pm1.cnt.acpi_only) { +return ; + } +if (sci_enable) { ar->pm1.cnt.cnt |=ACPI_BITMASK_SCI_ENABLE ; }else if (sci_disable) {
@@ -608,11 +612,13 @@ static const MemoryRegionOps acpi_pm_cnt_ops = { };void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent, -bool disable_s3,bool disable_s4,uint8_t s4_val) +bool disable_s3,bool disable_s4,uint8_t s4_val, +bool acpi_only) {FWCfgState *fw_cfg; ar->pm1.cnt.s4_val = s4_val; + ar->pm1.cnt.acpi_only = acpi_only; ar->wakeup.notify = acpi_notify_wakeup;qemu_register_wakeup_notifier (&ar->wakeup);
@@ -638,6 +644,9 @@ void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,void acpi_pm1_cnt_reset (ACPIREGS *ar) { ar->pm1.cnt.cnt =0 ; +if (ar->pm1.cnt.acpi_only) { + ar->pm1.cnt.cnt |=ACPI_BITMASK_SCI_ENABLE ; + } }/* ACPI GPE */
hw/acpi/ich9.c +1 -1
@@ -282,7 +282,7 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,acpi_pm_tmr_init (&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);acpi_pm1_evt_init (&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);acpi_pm1_cnt_init (&pm->acpi_regs, &pm->io, pm->disable_s3, pm->disable_s4, - pm->s4_val); + pm->s4_val, !pm->smm_compat && !smm_enabled);acpi_gpe_init (&pm->acpi_regs,ICH9_PMIO_GPE0_LEN ); memory_region_init_io(&pm->io_gpe, OBJECT(lpc_pci), &ich9_gpe_ops, pm,
hw/acpi/piix4.c +2 -1
@@ -497,7 +497,8 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)acpi_pm_tmr_init (&s->ar, pm_tmr_timer, &s->io);acpi_pm1_evt_init (&s->ar, pm_tmr_timer, &s->io); -acpi_pm1_cnt_init (&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val); +acpi_pm1_cnt_init (&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val, + !s->smm_compat && !s->smm_enabled);acpi_gpe_init (&s->ar,GPE_LEN ); s->powerdown_notifier.notify = piix4_pm_powerdown_req;
hw/isa/vt82c686.c +1 -1
@@ -240,7 +240,7 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp)acpi_pm_tmr_init (&s->ar, pm_tmr_timer, &s->io);acpi_pm1_evt_init (&s->ar, pm_tmr_timer, &s->io); -acpi_pm1_cnt_init (&s->ar, &s->io, false, false,2 ); +acpi_pm1_cnt_init (&s->ar, &s->io, false, false,2 , false); }static Property via_pm_properties[] = {
include/hw/acpi/acpi.h +3 -1
@@ -128,6 +128,7 @@ struct ACPIPM1CNT {MemoryRegion io;uint16_t cnt;uint8_t s4_val; +bool acpi_only; };struct ACPIGPE {
@@ -163,7 +164,8 @@ void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */ void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent, -bool disable_s3,bool disable_s4,uint8_t s4_val); +bool disable_s3,bool disable_s4,uint8_t s4_val, +bool acpi_only);void acpi_pm1_cnt_update (ACPIREGS *ar,bool sci_enable,bool sci_disable);void acpi_pm1_cnt_reset (ACPIREGS *ar);
Signature · 1 line
2.17.1
PATCH v4 3/10 ich9, piix4: add properoty, smm-compat, to keep compatibility of SMM
In reply to [email protected]From: Isaku Yamahata <[email protected]>
The following patch will introduce incompatible behavior of SMM. Introduce a property to keep the old behavior for compatibility. To enable smm compat, use "-global ICH9-LPC.smm-compat=on" or "-global PIIX4.smm-compat=on"
--- hw/acpi/piix4.c | 2 ++ hw/core/machine.c | 5 ++++- hw/isa/lpc_ich9.c | 1 + include/hw/acpi/ich9.h | 1 + 4 files changed, 8 insertions(+), 1 deletion(-)
hw/acpi/piix4.c +2 -0
@@ -74,6 +74,7 @@ struct PIIX4PMState {qemu_irq irq;qemu_irq smi_irq;int smm_enabled; +bool smm_compat;Notifier machine_ready;Notifier powerdown_notifier;
@@ -642,6 +643,7 @@ static Property piix4_pm_properties[] = { use_acpi_root_pci_hotplug, true),DEFINE_PROP_BOOL ("memory-hotplug-support" , PIIX4PMState, acpi_memory_hotplug.is_enabled, true), +DEFINE_PROP_BOOL ("smm-compat" , PIIX4PMState, smm_compat, false), DEFINE_PROP_END_OF_LIST(), };
hw/core/machine.c +4 -1
@@ -33,7 +33,10 @@#include "migration/global_state.h" #include "migration/vmstate.h" -GlobalProperty hw_compat_5_2[] = {}; +GlobalProperty hw_compat_5_2[] = { + {"ICH9-LPC" ,"smm-compat" ,"on" }, + {"PIIX4_PM" ,"smm-compat" ,"on" }, +};const size_t hw_compat_5_2_len =G_N_ELEMENTS (hw_compat_5_2);GlobalProperty hw_compat_5_1[] = {
hw/isa/lpc_ich9.c +1 -0
@@ -775,6 +775,7 @@ static const VMStateDescription vmstate_ich9_lpc = {static Property ich9_lpc_properties[] = {DEFINE_PROP_BOOL ("noreboot" , ICH9LPCState, pin_strap.spkr_hi, true), +DEFINE_PROP_BOOL ("smm-compat" , ICH9LPCState, pm.smm_compat, false),DEFINE_PROP_BIT64 ("x-smi-broadcast" , ICH9LPCState, smi_host_features,ICH9_LPC_SMI_F_BROADCAST_BIT , true), DEFINE_PROP_BIT64("x-smi-cpu-hotplug", ICH9LPCState, smi_host_features,
include/hw/acpi/ich9.h +1 -0
@@ -59,6 +59,7 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s4;uint8_t s4_val;uint8_t smm_enabled; +bool smm_compat;bool enable_tco;TCOIORegs tco_regs; } ICH9LPCPMRegs;
Signature · 1 line
2.17.1
Re: [PATCH v4 03/10] ich9, piix4: add properoty, smm-compat, to keep compatibility of SMM
Quoted 9 lines · On Mon, 15 Feb 2021 17:04:08 -0800 [email protected] wrote:
From: Isaku Yamahata <[email protected]>
The following patch will introduce incompatible behavior of SMM. Introduce a property to keep the old behavior for compatibility. To enable smm compat, use "-global ICH9-LPC.smm-compat=on" or "-global PIIX4.smm-compat=on"
Suggested-by Igor Mammedov <[email protected]>Signed-off-by Isaku Yamahata <[email protected]>
looks good to me, but doesn't apply to master anymore, so needs to be rebased
Quoted 32 lines
--- hw/acpi/piix4.c | 2 ++ hw/core/machine.c | 5 ++++- hw/isa/lpc_ich9.c | 1 + include/hw/acpi/ich9.h | 1 + 4 files changed, 8 insertions(+), 1 deletion(-)hw/acpi/piix4.c +2
-0@@ -74,6 +74,7 @@ struct PIIX4PMState {qemu_irq irq;qemu_irq smi_irq;int smm_enabled; +bool smm_compat;Notifier machine_ready;Notifier powerdown_notifier;@@ -642,6 +643,7 @@ static Property piix4_pm_properties[] = { use_acpi_root_pci_hotplug, true),DEFINE_PROP_BOOL ("memory-hotplug-support" , PIIX4PMState, acpi_memory_hotplug.is_enabled, true), +DEFINE_PROP_BOOL ("smm-compat" , PIIX4PMState, smm_compat, false), DEFINE_PROP_END_OF_LIST(), };hw/core/machine.c +0
-0
hw/core/machine.c line 39
Quoted 8 lines
hw/core/machine.c +4
-1@@ -33,7 +33,10 @@#include "migration/global_state.h" #include "migration/vmstate.h" -GlobalProperty hw_compat_5_2[] = {}; +GlobalProperty hw_compat_5_2[] = { + {"ICH9-LPC" ,"smm-compat" ,"on" }, + {"PIIX4_PM" ,"smm-compat" ,"on" }, +};
I'd put this hunk into the 4/10, where behavior changes
and add a note to commit this message that property will be used by the next patch
Quoted 27 lines
hw/core/machine.c +0
-0const size_t hw_compat_5_2_len =G_N_ELEMENTS (hw_compat_5_2);GlobalProperty hw_compat_5_1[] = {hw/isa/lpc_ich9.c +1
-0@@ -775,6 +775,7 @@ static const VMStateDescription vmstate_ich9_lpc = {static Property ich9_lpc_properties[] = {DEFINE_PROP_BOOL ("noreboot" , ICH9LPCState, pin_strap.spkr_hi, true), +DEFINE_PROP_BOOL ("smm-compat" , ICH9LPCState, pm.smm_compat, false),DEFINE_PROP_BIT64 ("x-smi-broadcast" , ICH9LPCState, smi_host_features,ICH9_LPC_SMI_F_BROADCAST_BIT , true), DEFINE_PROP_BIT64("x-smi-cpu-hotplug", ICH9LPCState, smi_host_features,include/hw/acpi/ich9.h +1
-0@@ -59,6 +59,7 @@ typedef struct ICH9LPCPMRegs {uint8_t disable_s4;uint8_t s4_val;uint8_t smm_enabled; +bool smm_compat;bool enable_tco;TCOIORegs tco_regs; } ICH9LPCPMRegs;
Re: [PATCH v4 04/10] acpi/core: always set SCI_EN when SMM isn't supported
In reply to [email protected]Quoted 15 lines · On Mon, 15 Feb 2021 17:04:09 -0800 [email protected] wrote:
From: Isaku Yamahata <[email protected]>
If SMM is not supported, ACPI fixed hardware doesn't support legacy-mode. ACPI-only platform. Where
SCI_ENinPM1_CNTregister is always set.
The bit tells OS legacymode(SCI_EN cleared)or ACPImode(SCI_EN set).With the next patch (setting fadt.smi_cmd = 0 when smm isn't enabled), guest Linux tries to switch to ACPI mode, finds
smi_cmd= 0, and then fails to initialize acpi subsystem. This patch proactively fixes it.This patch changes guest ABI. To keep compatibility, use "x-smm-compat-5" introduced by earlier patch. If the property is true, disable new behavior.
Quoted 5 lines
ACPI spec 4.8.10.1 PM1 Event Grouping
PM1 Eanble RegistersQuoted 1 line
For ACPI-only platforms (where
SCI_ENis always set)Signed-off-by Isaku Yamahata <[email protected]>
Quoted 110 lines
--- hw/acpi/core.c | 11 ++++++++++- hw/acpi/ich9.c | 2 +- hw/acpi/piix4.c | 3 ++- hw/isa/vt82c686.c | 2 +- include/hw/acpi/acpi.h | 4 +++- 5 files changed, 17 insertions(+), 5 deletions(-)hw/acpi/core.c +10
-1@@ -579,6 +579,10 @@ void acpi_pm1_cnt_update(ACPIREGS *ar, bool sci_enable, bool sci_disable) {/* ACPI specs 3.0, 4.7.2.5 */ +if (ar->pm1.cnt.acpi_only) { +return ; + } +if (sci_enable) { ar->pm1.cnt.cnt |=ACPI_BITMASK_SCI_ENABLE ; }else if (sci_disable) {@@ -608,11 +612,13 @@ static const MemoryRegionOps acpi_pm_cnt_ops = { };void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent, -bool disable_s3,bool disable_s4,uint8_t s4_val) +bool disable_s3,bool disable_s4,uint8_t s4_val, +bool acpi_only) {FWCfgState *fw_cfg; ar->pm1.cnt.s4_val = s4_val; + ar->pm1.cnt.acpi_only = acpi_only; ar->wakeup.notify = acpi_notify_wakeup;qemu_register_wakeup_notifier (&ar->wakeup);@@ -638,6 +644,9 @@ void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,void acpi_pm1_cnt_reset (ACPIREGS *ar) { ar->pm1.cnt.cnt =0 ; +if (ar->pm1.cnt.acpi_only) { + ar->pm1.cnt.cnt |=ACPI_BITMASK_SCI_ENABLE ; + } }/* ACPI GPE */ hw/acpi/ich9.c +1
-1@@ -282,7 +282,7 @@ void ich9_pm_init(PCIDevice *lpc_pci, ICH9LPCPMRegs *pm,acpi_pm_tmr_init (&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);acpi_pm1_evt_init (&pm->acpi_regs, ich9_pm_update_sci_fn, &pm->io);acpi_pm1_cnt_init (&pm->acpi_regs, &pm->io, pm->disable_s3, pm->disable_s4, - pm->s4_val); + pm->s4_val, !pm->smm_compat && !smm_enabled);acpi_gpe_init (&pm->acpi_regs,ICH9_PMIO_GPE0_LEN ); memory_region_init_io(&pm->io_gpe, OBJECT(lpc_pci), &ich9_gpe_ops, pm,hw/acpi/piix4.c +2
-1@@ -497,7 +497,8 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp)acpi_pm_tmr_init (&s->ar, pm_tmr_timer, &s->io);acpi_pm1_evt_init (&s->ar, pm_tmr_timer, &s->io); -acpi_pm1_cnt_init (&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val); +acpi_pm1_cnt_init (&s->ar, &s->io, s->disable_s3, s->disable_s4, s->s4_val, + !s->smm_compat && !s->smm_enabled);acpi_gpe_init (&s->ar,GPE_LEN ); s->powerdown_notifier.notify = piix4_pm_powerdown_req;hw/isa/vt82c686.c +1
-1@@ -240,7 +240,7 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp)acpi_pm_tmr_init (&s->ar, pm_tmr_timer, &s->io);acpi_pm1_evt_init (&s->ar, pm_tmr_timer, &s->io); -acpi_pm1_cnt_init (&s->ar, &s->io, false, false,2 ); +acpi_pm1_cnt_init (&s->ar, &s->io, false, false,2 , false); }static Property via_pm_properties[] = {include/hw/acpi/acpi.h +3
-1@@ -128,6 +128,7 @@ struct ACPIPM1CNT {MemoryRegion io;uint16_t cnt;uint8_t s4_val; +bool acpi_only; };struct ACPIGPE {@@ -163,7 +164,8 @@ void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */ void acpi_pm1_cnt_init (ACPIREGS *ar,MemoryRegion *parent, -bool disable_s3,bool disable_s4,uint8_t s4_val); +bool disable_s3,bool disable_s4,uint8_t s4_val, +bool acpi_only);void acpi_pm1_cnt_update (ACPIREGS *ar,bool sci_enable,bool sci_disable);void acpi_pm1_cnt_reset (ACPIREGS *ar);
Re: [PATCH v4 07/10] hw/i386: declare ACPI mother board resource for MMCONFIG region
In reply to [email protected]Quoted 114 lines · On Mon, 15 Feb 2021 17:04:12 -0800 [email protected] wrote:
From: Isaku Yamahata <[email protected]>
Declare PNP0C01 device to reserve MMCONFIG region to conform to the spec better and play nice with guest BIOSes/OSes.
According to PCI Firmware Specification[0], MMCONFIG region must be reserved by declaring a motherboard resource. It's optional to reserve the region in memory map by Int 15 E820h or EFIGetMemoryMap. Guest Linux checks if the MMCFG region is reserved by bios memory map or ACPI resource. If it's not reserved, Linux falls back to legacy PCI configuration access.
TDVF [1] [2] doesn't reserve MMCONFIG the region in memory map. On the other hand OVMF reserves it in memory map without declaring a motherboard resource. With memory map reservation, linux guest uses MMCONFIG region. However it doesn't comply to PCI Firmware specification.
[0] PCI Firmware specification Revision 3.2
4.1.2 MCFG Table Description table 4-2 NOTE 2
If the operating system does not natively comprehend reserving the MMCFG region, The MMCFG region must e reserved by firmware. ... For most systems, the mortheroard resource would appear at the root of the ACPI namespace (under \_SB)...
The resource can optionally be returned in Int15 E820h or EFIGetMemoryMap as reserved memory but must always be reported through ACPI as a motherboard resource[1] TDX: Intel Trust Domain Extension
https://software.intel.com/content/www/us/en/develop/articles/intel-trust-domain-extensions.html
[2] TDX Virtual Firmware
https://github.com/tianocore/edk2-staging/tree/TDVFThe change to DSDT is as follows.
(quoted diff) +19
-0@@ -68,32 +68,51 @@ If ((CDW3 != Local0)) { CDW1 |= 0x10 } CDW3 = Local0 } Else { CDW1 |= 0x04 } Return (Arg3) } } + + Device (DRAC) + { + Name (_HID, "PNP0C01" /* System Board */) // _HID: Hardware ID + Name (RBUF, ResourceTemplate () + { + DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite, + 0x00000000, // Granularity + 0xB0000000, // Range Minimum + 0xB0000000, // Range Maximum + 0x00000000, // Translation Offset + 0x10000000, // Length + ,, , AddressRangeMemory, TypeStatic) + }) + Method (_CRS, 0, Serialized) // _CRS: Current Resource Settings + { + Return (RBUF) /* \_SB_.DRAC.RBUF */ + } + } } Scope (_SB) { Device (HPET) { Name (_HID, EisaId ("PNP0103") /* HPET System Timer */) // _HID: Hardware ID Name (_UID, Zero) // _UID: Unique ID OperationRegion (HPTM, SystemMemory, 0xFED00000, 0x0400) Field (HPTM, DWordAcc, Lock, Preserve) { VEND, 32, PRD, 32 } Method (_STA, 0, NotSerialized) // _STA: StatusSigned-off-by Isaku Yamahata <[email protected]>--- hw/i386/acpi-build.c | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-)hw/i386/acpi-build.c +13
-0@@ -1072,6 +1072,55 @@ static void build_q35_pci0_int(Aml *table)aml_append (table, sb_scope); } +static Aml *build_q35_dram_controller (AcpiMcfgInfo *mcfg) +{ +Aml *dev; +Aml *rbuf; +Aml *resource_template; +Aml *rbuf_name; +Aml *crs; + +/* DRAM controller */ + dev =aml_device ("DRAC" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0C01" ))); + + resource_template =aml_resource_template ();
hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1097
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+if (mcfg->base + mcfg->size -1 >= (1ULL <<32 )) { + aml_append(resource_template, + aml_qword_memory(AML_POS_DECODE, + AML_MIN_FIXED, + AML_MAX_FIXED, + AML_NON_CACHEABLE, + AML_READ_WRITE, + 0x0000000000000000, + mcfg->base, + mcfg->base,
here ^^^
hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1109
Quoted 9 lines
hw/i386/acpi-build.c +9
-0+ aml_append(resource_template, + aml_dword_memory(AML_POS_DECODE, + AML_MIN_FIXED, + AML_MAX_FIXED, + AML_NON_CACHEABLE, + AML_READ_WRITE, + 0x0000000000000000, + mcfg->base, + mcfg->base,
and here ^^^
please revert it to the way did it in v3,
I was wrong suggesting that for fixed address case.
hw/i386/acpi-build.c static void build_q35_pci0_int(Aml *table) · line 1119
Quoted 11 lines
hw/i386/acpi-build.c +10
-0+0x0000000000000000 , + mcfg->size)); + } + rbuf =aml_name_decl ("RBUF" , resource_template); +aml_append (dev, rbuf); + + crs =aml_method ("_CRS" ,0 ,AML_SERIALIZED ); + rbuf_name =aml_name ("RBUF" ); +aml_append (crs,aml_return (rbuf_name)); +aml_append (dev, crs);
can be simpler if method is replaced with _CRS variable, i.e.:
aml_append(dev, aml_name_decl("_CRS", resource_template));Quoted 34 lines
hw/i386/acpi-build.c +9
-1+ +return dev; +} +static void build_q35_isa_bridge (Aml *table) {Aml *dev;@@ -1218,6 +1267,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,PCMachineClass *pcmc =PC_MACHINE_GET_CLASS (machine);X86MachineState *x86ms =X86_MACHINE (machine);AcpiMcfgInfo mcfg; +bool mcfg_valid = !!acpi_get_mcfg (&mcfg);uint32_t nr_mem = machine->ram_slots;int root_bus_limit =0xFF ;PCIBus *bus =NULL ;@@ -1256,6 +1306,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 )));aml_append (dev,build_q35_osc_method ());aml_append (sb_scope, dev); +if (mcfg_valid) { +aml_append (sb_scope,build_q35_dram_controller (&mcfg)); + }if (pm->smi_on_cpuhp) {/* reserve SMI block resources, IO ports 0xB2, 0xB3 */ @@ -1386,7 +1439,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,* the PCI0._CRS. Add mmconfig to the set so it will be excluded * too. */ -if (acpi_get_mcfg (&mcfg)) { +if (mcfg_valid) {crs_range_insert (crs_range_set.mem_ranges, mcfg.base, mcfg.base + mcfg.size -1 ); }