acpi: fix up EJ0 in DSDT
v2 cover acpi: fix up EJ0 in DSDT
This is a second iteration of the patch. The patch has been significantly reworked to address (offline) comments by Gleb.
I think the infrastructure created is generic enough to be generally useful beyond the specific bug that I would like to fix. Specifically it will be able to find S3 Name to patch that, or process compiled CPU SSDT to avoid the need for hardcoded offsets.
Please comment.
Main changes:
- tools rewritten in python
- Original ASL retains _EJ0 methods, BIOS patches that to EJ0_
- generic ACP_EXTRACT infrastructure that can match Method and Name Operators
- instead of matching specific method name, insert tags in original DSL source and match that to AML
-----
Here's a bug: guest thinks it can eject VGA device and ISA bridge.
[root@dhcp74-172 ~]#lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:02.0 VGA compatible controller: Cirrus Logic GD 5446
00:03.0 PCI bridge: Red Hat, Inc. Device 0001
00:04.0 Ethernet controller: Qumranet, Inc. Virtio network device
00:05.0 SCSI storage controller: Qumranet, Inc. Virtio block device
01:00.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
[root@dhcp74-172 ~]# ls /sys/bus/pci/slots/1/
adapter address attention latch module power
[root@dhcp74-172 ~]# ls /sys/bus/pci/slots/2/
adapter address attention latch module power
[root@dhcp74-172 ~]# echo 0 > /sys/bus/pci/slots/2/power
[root@dhcp74-172 ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02) 00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II] 00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II] 00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03)
00:03.0 PCI bridge: Red Hat, Inc. Device 0001
00:04.0 Ethernet controller: Qumranet, Inc. Virtio network device
00:05.0 SCSI storage controller: Qumranet, Inc. Virtio block device
01:00.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
This is wrong because slots 1 and 2 are marked as not hotpluggable in qemu.
The reason is that our acpi tables declare both _RMV with value 0, and _EJ0 method for these slots. What happens in this case is undocumented by ACPI spec, so linux ignores _RMV, and windows seems to ignore _EJ0.
The correct way to suppress hotplug is not to have _EJ0, so this is what this patch does: it probes PIIX and modifies DSDT to match.
With these patches applied, we get:
[root@dhcp74-172 ~]# ls /sys/bus/pci/slots/1/
address
[root@dhcp74-172 ~]# ls /sys/bus/pci/slots/2/
address
Michael S. Tsirkin (3):
acpi: generate and parse mixed asl/aml listing
acpi: EJ0 method name patching
acpi: remove _RMV
Makefile | 10 +- src/acpi-dsdt.dsl | 96 ++++++++----------- src/acpi.c | 31 ++++++ tools/acpi_extract.py | 195 ++++++++++++++++++++++++++++++++++++++ tools/acpi_extract_preprocess.py | 37 +++++++ 5 files changed, 307 insertions(+), 62 deletions(-) create mode 100755 tools/acpi_extract.py create mode 100755 tools/acpi_extract_preprocess.py
Signature · 1 line
1.7.5.53.gc233e
PATCH v2 1/3 acpi: generate and parse mixed asl/aml listing
Use iasl -l flag to produce a mixed listing, where a source line is followed by matching AML.
Add a tool tools/acpi_extract.py to process this listing. The tool looks for ACPI_EXTRACT tags in the ASL source and outputs matching AML offsets in an array.
To make these directives pass through ASL without affecting AML, and to make it possible to match AML to source exactly, add a preprocessing stage, which prepares input for iasl, and puts each ACPI_EXTRACT tag within a comment,
on a line by itself.
--- Makefile | 10 +- tools/acpi_extract.py | 195 ++++++++++++++++++++++++++++++++++++++ tools/acpi_extract_preprocess.py | 37 +++++++ 3 files changed, 238 insertions(+), 4 deletions(-) create mode 100755 tools/acpi_extract.py create mode 100755 tools/acpi_extract_preprocess.py
Makefile +6 -4
@@ -192,11 +192,13 @@ $(OUT)vgabios.bin: $(OUT)vgabios.bin.raw tools/buildrom.py $(Q)./tools/buildrom.py $< $@ ####### dsdt build rules -src/%.hex: src/%.dsl +src/%.hex: src/%.dsl ./tools/acpi_extract_preprocess.py ./tools/acpi_extract.py @echo "Compiling DSDT" - $(Q)cpp -P $< > $(OUT)$*.dsl.i - $(Q)iasl -tc -p $(OUT)$* $(OUT)$*.dsl.i - $(Q)cp $(OUT)$*.hex $@ + $(Q)cpp -P $< > $(OUT)$*.dsl.i.orig + $(Q)./tools/acpi_extract_preprocess.py $(OUT)$*.dsl.i.orig > $(OUT)$*.dsl.i + $(Q)iasl -l -tc -p $(OUT)$* $(OUT)$*.dsl.i + $(Q)./tools/acpi_extract.py $(OUT)$*.lst > $(OUT)$*.off + $(Q)cat $(OUT)$*.hex $(OUT)$*.off > $@ $(OUT)ccode32flat.o: src/acpi-dsdt.hex
tools/acpi_extract.py new file +195 -0
195 lines not on this page · raw message
tools/acpi_extract_preprocess.py new file +37 -0
@@ -0,0 +1,37 @@ +#!/usr/bin/python +# Read a preprocessed ASL listing and put each ACPI_EXTRACT +# directive in a comment, to make iasl skip it. +# We also put each directive on a new line, the machinery +# in tools/acpi_extract.py requires this. + +import re; +import sys; +import fileinput; + +def die(diag): + sys.stderr.write("Error: %s\n" % (diag)) + sys.exit(1) + +# Note: () around pattern make split return matched string as part of list +psplit = re.compile(r''' ( + \b # At word boundary + ACPI_EXTRACT_\w+ # directive + \s+ # some whitespace + \w+ # array name + )''', re.VERBOSE); + +lineno = 0 +for line in fileinput.input(): + # line number and debug string to output in case of errors + lineno = lineno + 1 + debug = "input line %d: %s" % (lineno, line.rstrip()) + + s = psplit.split(line); + # The way split works, each odd item is the matching ACPI_EXTRACT directive. + # Put each in a comment, and on a line by itself. + for i in range(len(s)): + if (i % 2): + sys.stdout.write("\n/* %s */\n" % s[i]) + else: + sys.stdout.write(s[i]) +
Signature · 1 line
1.7.5.53.gc233e
PATCH v2 2/3 acpi: EJ0 method name patching
In reply to Michael S. TsirkinModify ACPI to only supply _EJ0 methods for PCI
slots that support hotplug.
This is done by runtime patching:
- Instrument ASL code with ACPI_EXTRACT directives tagging _EJ0 and _ADR fields.
- At compile time, tools/acpi_extract.py looks for these methods in ASL source finds the matching AML, and stores the offsets of these methods in tables named aml_ej0_name and aml_adr_dword.
- At run time, go over aml_ej0_name, use aml_adr_dword to get slot information and check which slots
support hotplug.
If hotplug is disabled, we patch the _EJ0 NameString in ACPI table, replacing _EJ0 with EJ0_.
Note that this has the same checksum, but
is ignored by OSPM.
Note: the method used is robust in that we don't need
to change any offsets manually in case of ASL code changes. As all parsing is done at compile time, any unexpected input causes build failure, not a runtime failure.
--- src/acpi-dsdt.dsl | 47 ++++++++++++++++++++++++++++++++++++++--------- src/acpi.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 9 deletions(-)
src/acpi-dsdt.dsl +38 -9
@@ -16,6 +16,30 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +/* +Documentation of ACPI_EXTRACT_* directive tags: + +These directive tags are processed by tools/acpi_extract.py +to output offset information from AML for BIOS runtime table generation. +Each directive is of the form: +ACPI_EXTRACT_<TYPE> <array_name> <Operator> (...) +and causes the extractor to create an array +named <array_name> with offset, in the generated AML, +of an object of a given type from the following <Operator>. + +A directive and array name must fit on a single code line. + +Object type in AML is verified, a mismatch causes a build failure. + +Directives and operators currently supported are: +ACPI_EXTRACT_NAME_DWORD_CONST - extract a Dword Const object from Name() +ACPI_EXTRACT_METHOD_STRING - extract a NameString from Method() +ACPI_EXTRACT_NAME_STRING - extract a NameString from Name() + +ACPI_EXTRACT is not allowed anywhere else in code, except in comments. +*/ + DefinitionBlock ( "acpi-dsdt.aml", // Output Filename "DSDT", // Signature
@@ -127,15 +151,20 @@ DefinitionBlock ( { PCRM, 32, } - -#define hotplug_slot(name, nr) \ - Device (S##name) { \ - Name (_ADR, nr##0000) \ - Method (_EJ0,1) { \ - Store(ShiftLeft(1, nr), B0EJ) \ - Return (0x0) \ - } \ - Name (_SUN, name) \ + // Method _EJ0 can be patched by BIOS to EJ0_ + // at runtime, if the slot is detected to not support hotplug. + // Extract the offset of the address dword and the + // _EJ0 name to allow this patching. +#define hotplug_slot(name, nr) \ + Device (S##name) { \ + ACPI_EXTRACT_NAME_DWORD_CONST aml_adr_dword \ + Name (_ADR, nr##0000) \ + ACPI_EXTRACT_METHOD_STRING aml_ej0_name \ + Method (_EJ0, 1) { \ + Store(ShiftLeft(1, nr), B0EJ) \ + Return (0x0) \ + } \ + Name (_SUN, name) \ } hotplug_slot(1, 0x0001)
src/acpi.c +31 -0
@@ -198,6 +198,8 @@ struct srat_memory_affinityu32 reserved3[2 ]; }PACKED ; +#define PCI_RMV_BASE 0xae0c +#include "acpi-dsdt.hex" static void
@@ -237,12 +239,16 @@ static const struct pci_device_id fadt_init_tbl[] = { PCI_DEVICE_END }; +extern void link_time_assertion (void ); +static void *build_fadt (struct pci_device *pci) {struct fadt_descriptor_rev1 *fadt =malloc_high (sizeof (*fadt));struct facs_descriptor_rev1 *facs =memalign_high (64 ,sizeof (*facs));void *dsdt =malloc_high (sizeof (AmlCode)); +u32 rmvc_pcrm; +int i;if (!fadt || !facs || !dsdt) {warn_noalloc ();
@@ -257,6 +263,25 @@ build_fadt(struct pci_device *pci)/* DSDT */ memcpy (dsdt, AmlCode,sizeof (AmlCode)); +/* Runtime patching of EJ0: to disable hotplug for a slot, +* replace the method name: _EJ0 by EJ0_. */ +if (ARRAY_SIZE (aml_ej0_name) !=ARRAY_SIZE (aml_adr_dword)) { +link_time_assertion (); + } + rmvc_pcrm =inl (PCI_RMV_BASE ); +for (i =0 ; i <ARRAY_SIZE (aml_ej0_name); ++i) { +/* Slot is in byte 2 in _ADR */ +u8 slot = AmlCode[aml_adr_dword[i] +2 ] &0x1F ; +/* Sanity check */ +if (memcmp (AmlCode + aml_ej0_name[i],"_EJ0" ,4 )) { +warn_internalerror (); + goto error; + } +if (!(rmvc_pcrm & (0x1 << slot))) { +memcpy (dsdt + aml_ej0_name[i],"EJ0_" ,4 ); + } + } +/* FADT */ memset (fadt,0 ,sizeof (*fadt)); fadt->firmware_ctrl =cpu_to_le32 ((u32 )facs);
@@ -281,6 +306,12 @@ build_fadt(struct pci_device *pci)build_header ((void *)fadt,FACP_SIGNATURE ,sizeof (*fadt),1 );return fadt; + +error: +free (fadt); +free (facs); +free (dsdt); +return NULL ; } static void*
Signature · 1 line
1.7.5.53.gc233e
PATCH v2 3/3 acpi: remove _RMV
In reply to Michael S. TsirkinThe macro gen_pci_device is used to add _RMV method to a slot device so it is no longer needed:
presence of _EJ0 now indicates that the slot is ejectable. It is also placing two devices with the same _ADR on the same bus, which isn't defined by the ACPI spec. So let's remove it.
--- src/acpi-dsdt.dsl | 49 ------------------------------------------------- 1 files changed, 0 insertions(+), 49 deletions(-)
src/acpi-dsdt.dsl +0 -49
@@ -145,12 +145,6 @@ DefinitionBlock ( { B0EJ, 32, } - - OperationRegion(RMVC, SystemIO, 0xae0c, 0x04) - Field(RMVC, DWordAcc, NoLock, WriteAsZeros) - { - PCRM, 32, - } // Method _EJ0 can be patched by BIOS to EJ0_ // at runtime, if the slot is detected to not support hotplug. // Extract the offset of the address dword and the
@@ -488,49 +482,6 @@ DefinitionBlock ( DRSJ, 32 } } - -#define gen_pci_device(name, nr) \ - Device(SL##name) { \ - Name (_ADR, nr##0000) \ - Method (_RMV) { \ - If (And(\_SB.PCI0.PCRM, ShiftLeft(1, nr))) { \ - Return (0x1) \ - } \ - Return (0x0) \ - } \ - Name (_SUN, name) \ - } - - /* VGA (slot 1) and ISA bus (slot 2) defined above */ - gen_pci_device(3, 0x0003) - gen_pci_device(4, 0x0004) - gen_pci_device(5, 0x0005) - gen_pci_device(6, 0x0006) - gen_pci_device(7, 0x0007) - gen_pci_device(8, 0x0008) - gen_pci_device(9, 0x0009) - gen_pci_device(10, 0x000a) - gen_pci_device(11, 0x000b) - gen_pci_device(12, 0x000c) - gen_pci_device(13, 0x000d) - gen_pci_device(14, 0x000e) - gen_pci_device(15, 0x000f) - gen_pci_device(16, 0x0010) - gen_pci_device(17, 0x0011) - gen_pci_device(18, 0x0012) - gen_pci_device(19, 0x0013) - gen_pci_device(20, 0x0014) - gen_pci_device(21, 0x0015) - gen_pci_device(22, 0x0016) - gen_pci_device(23, 0x0017) - gen_pci_device(24, 0x0018) - gen_pci_device(25, 0x0019) - gen_pci_device(26, 0x001a) - gen_pci_device(27, 0x001b) - gen_pci_device(28, 0x001c) - gen_pci_device(29, 0x001d) - gen_pci_device(30, 0x001e) - gen_pci_device(31, 0x001f) } /* PCI IRQs */
Signature · 1 line
1.7.5.53.gc233e
Quoted 20 lines · Michael S. Tsirkin
This is a second iteration of the patch. The patch has been significantly reworked to address (offline) comments by Gleb.
I think the infrastructure created is generic enough to be generally useful beyond the specific bug that I would like to fix. Specifically it will be able to find S3 Name to patch that, or process compiled CPU SSDT to avoid the need for hardcoded offsets.
Please comment.
Main changes:
- tools rewritten in python
- Original ASL retains_EJ0methods, BIOS patches that toEJ0_
- genericACP_EXTRACTinfrastructure that can match Method and Name Operators
- instead of matching specific method name, insert tags in original DSL source and match that to AML
Quoted 1 line
-----
Neat, looks good to me.
----- Original Message -----
Quoted 12 lines
This is a second iteration of the patch. The patch has been significantly reworked to address (offline) comments by Gleb.
I think the infrastructure created is generic enough to be generally useful beyond the specific bug that I would like to fix. Specifically it will be able to find S3 Name to patch that, or process compiled CPU SSDT to avoid the need for hardcoded offsets.
Please comment.
Quoted 7 lines
Main changes:
- tools rewritten in python
- Original ASL retains_EJ0methods, BIOS patches that toEJ0_
- genericACP_EXTRACTinfrastructure that can match Method and Name Operators
- instead of matching specific method name, insert tags in original DSL source and match that to AML
Patch looks good to me.
Quoted 82 lines
-----
Here's a bug: guest thinks it can eject VGA device and ISA bridge.
[root@dhcp74-172 ~]#lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) 00:02.0 VGA compatible controller: Cirrus Logic GD 5446 00:03.0 PCI bridge: Red Hat, Inc. Device 0001
00:04.0 Ethernet controller: Qumranet, Inc. Virtio network device 00:05.0 SCSI storage controller: Qumranet, Inc. Virtio block device 01:00.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)[root@dhcp74-172 ~]# ls
/sys/bus/pci/slots/1/
adapter address attention latch module power
[root@dhcp74-172 ~]# ls/sys/bus/pci/slots/2/
adapter address attention latch module power[root@dhcp74-172 ~]# echo 0 >
/sys/bus/pci/slots/2/power[root@dhcp74-172 ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)
00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 03) 00:03.0 PCI bridge: Red Hat, Inc. Device 0001
00:04.0 Ethernet controller: Qumranet, Inc. Virtio network device 00:05.0 SCSI storage controller: Qumranet, Inc. Virtio block device 01:00.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)This is wrong because slots 1 and 2 are marked as not hotpluggable in qemu.
The reason is that our acpi tables declare both
_RMVwith value 0, and_EJ0method for these slots. What happens in this case is undocumented by ACPI spec, so linux ignores_RMV, and windows seems to ignore_EJ0.The correct way to suppress hotplug is not to have
_EJ0, so this is what this patch does: it probes PIIX and modifies DSDT to match.With these patches applied, we get:
[root@dhcp74-172 ~]# ls
/sys/bus/pci/slots/1/
address
[root@dhcp74-172 ~]# ls/sys/bus/pci/slots/2/
addressMichael S. Tsirkin (3):
acpi: generate and parse mixed asl/aml listing
acpi: EJ0 method name patching
acpi: remove_RMVMakefile | 10 +- src/acpi-dsdt.dsl | 96 ++++++++----------- src/acpi.c | 31 ++++++ tools/acpi_extract.py | 195 ++++++++++++++++++++++++++++++++++++++ tools/acpi_extract_preprocess.py | 37 +++++++ 5 files changed, 307 insertions(+), 62 deletions(-) create mode 100755 tools/acpi_extract.py create mode 100755 tools/acpi_extract_preprocess.py--
1.7.5.53.gc233e
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html