ACPI refactoring: replace template patching with C AML API
v5 cover ACPI refactoring: replace template patching with C AML API
NOTE to maintaner:
Needs updating DSDT hex.generated and ACPI tests blobs
Changes since v4:
* split PCI0._CRS patch onto simple ones
* move _CRS into SSDT
* a series to drop manual hole punching in PIIX4 _CRS
* add test case for ACPI table with coldplugged bridge
* fixed up current algorithm rewrite fallout on Q35 machine, see for detailed changelog in
"pc: acpi-build: simplify PCI bus tree generation"
* fixed minor mst's notes on v4 in PCI patches
Remaining pieces of refactoring PC/Q35 machines to AML API. There is no more template patching left.
There are TPM and DSDT table blobs left to convert but that's left for future.
Boot tested with XP3/WS2012R2, correctnes of resource reservation was checked with WS2012R2 help.
reference to previous iteration:
https://www.mail-archive.com/[email protected]/msg280791.html
tree for testing:
https://github.com/imammedo/qemu.git ASL_API_v5
for browsing:
https://github.com/imammedo/qemu/commits/ASL_API_v5
Igor Mammedov (16):
pc: acpi-build: create PCI0._CRS dynamically
pc: acpi: drop manual hole punching for PCI hotplug resources
pc: acpi: drop manual hole punching for CPU hotplug resources
pc: acpi: drop manual hole punching for GPE0 resources
pc: acpi-build: drop remaining ssdt_misc template
acpi: add acpi_irq_no_flags() term
pc: export applesmc IO port/len
pc: acpi-build: drop template patching and create Device(SMC)
dynamically
tests: ACPI test blobs update due to PCI0._CRS changes
tests: bios-tables-test: add support for testing bridges
tests: add ACPI blobs for qemu with bridge cases
pc: acpi-build: simplify PCI bus tree generation
tests: ACPI: update pc/SSDT.bridge due to new alg of PCI tree creation
pc: acpi-build: drop template patching and create PCI bus tree
dynamically
pc: acpi: remove not used anymore ssdt-[misc|pcihp].hex.generated
blobs
acpi: make build_*() routines static to aml-build.c
hw/acpi/aml-build.c | 41 ++- hw/i386/Makefile.objs | 2 - hw/i386/acpi-build.c | 491 ++++++++++++----------------------- hw/i386/acpi-dsdt-isa.dsl | 11 - hw/i386/acpi-dsdt-pci-crs.dsl | 92 ------- hw/i386/acpi-dsdt.dsl | 46 ---- hw/i386/q35-acpi-dsdt.dsl | 19 -- hw/i386/ssdt-misc.dsl | 40 --- hw/i386/ssdt-misc.hex.generated | 139 ---------- hw/i386/ssdt-pcihp.dsl | 100 ------- hw/i386/ssdt-pcihp.hex.generated | 251 ------------------ hw/misc/applesmc.c | 5 +- include/hw/acpi/aml-build.h | 17 +- include/hw/isa/isa.h | 11 +- tests/acpi-test-data/pc/DSDT | Bin 3415 -> 2970 bytes tests/acpi-test-data/pc/SSDT | Bin 2374 -> 2480 bytes tests/acpi-test-data/pc/SSDT.bridge | Bin 0 -> 4351 bytes tests/acpi-test-data/q35/DSDT | Bin 8005 -> 7608 bytes tests/acpi-test-data/q35/SSDT | Bin 578 -> 685 bytes tests/acpi-test-data/q35/SSDT.bridge | Bin 0 -> 702 bytes tests/bios-tables-test.c | 45 +++- 21 files changed, 250 insertions(+), 1060 deletions(-) delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl delete mode 100644 hw/i386/ssdt-misc.dsl delete mode 100644 hw/i386/ssdt-misc.hex.generated delete mode 100644 hw/i386/ssdt-pcihp.dsl delete mode 100644 hw/i386/ssdt-pcihp.hex.generated create mode 100644 tests/acpi-test-data/pc/SSDT.bridge create mode 100644 tests/acpi-test-data/q35/SSDT.bridge
Signature · 1 line
1.8.3.1
PATCH v5 1/16 pc: acpi-build: create PCI0._CRS dynamically
Replace template patching and runtime calculation in _CRS() method with static _CRS defined in SSDT. No functional change except of as mentined above and _CRS being moved from DSDT to SSDT.
--- hw/i386/acpi-build.c | 88 ++++++++++++++++++++++++----------------- hw/i386/acpi-dsdt-pci-crs.dsl | 92 ------------------------------------------- hw/i386/acpi-dsdt.dsl | 45 --------------------- hw/i386/q35-acpi-dsdt.dsl | 18 --------- hw/i386/ssdt-misc.dsl | 19 --------- 5 files changed, 52 insertions(+), 210 deletions(-) delete mode 100644 hw/i386/acpi-dsdt-pci-crs.dsl
hw/i386/acpi-build.c +52 -36
@@ -346,24 +346,6 @@ static void acpi_align_size(GArray *blob, unsigned align)g_array_set_size (blob,ROUND_UP (acpi_data_len (blob), align)); } -/* Set a value within table in a safe manner */ -#define ACPI_BUILD_SET_LE (table, size, off, bits, val) \ - do { \ - uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \ - memcpy(acpi_data_get_ptr(table, size, off, \ - (bits) / BITS_PER_BYTE), \ - &ACPI_BUILD_SET_LE_val, \ - (bits) / BITS_PER_BYTE); \ - } while (0) - -static inline void *acpi_data_get_ptr (uint8_t *table_data,unsigned table_size, -unsigned off,unsigned size) -{ -assert (off + size > off); -assert (off + size <= table_size); -return table_data + off; -} -static inline void acpi_add_table (GArray *table_offsets,GArray *table_data) {uint32_t offset =cpu_to_le32 (table_data->len);
@@ -860,22 +842,6 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)g_free (child); } -static void patch_pci_windows (PcPciInfo *pci,uint8_t *start,unsigned size) -{ -ACPI_BUILD_SET_LE (start, size, acpi_pci32_start[0 ],32 , pci->w32.begin); - -ACPI_BUILD_SET_LE (start, size, acpi_pci32_end[0 ],32 , pci->w32.end -1 ); - -if (pci->w64.end || pci->w64.begin) { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_start[0 ],64 , pci->w64.begin); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_end[0 ],64 , pci->w64.end -1 ); -ACPI_BUILD_SET_LE (start, size, acpi_pci64_length[0 ],64 , pci->w64.end - pci->w64.begin); - }else { -ACPI_BUILD_SET_LE (start, size, acpi_pci64_valid[0 ],8 ,0 ); - } -} - static void build_ssdt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -898,9 +864,59 @@ build_ssdt(GArray *table_data, GArray *linker, ssdt_ptr =acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml));memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); -patch_pci_windows (pci, ssdt_ptr,sizeof (ssdp_misc_aml)); - scope =aml_scope ("\\_SB.PCI0" ); +/* build PCI0._CRS */ + crs =aml_resource_template (); +aml_append (crs, +aml_word_bus_number (aml_min_fixed, aml_max_fixed, aml_pos_decode, +0x0000 ,0x0000 ,0x00FF ,0x0000 ,0x0100 )); +aml_append (crs,aml_io (aml_decode16,0x0CF8 ,0x0CF8 ,0x01 ,0x08 )); + +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0000 ,0x0CF7 ,0x0000 ,0x0CF8 )); +if (ich9_lpc_find ()) {/* Q35 */ +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0D00 ,0xFFFF ,0x0000 ,0xF300 )); + }else {/* piix4 */ +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0D00 ,0xADFF ,0x0000 ,0xA100 )); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0xAE0F ,0xAEFF ,0x0000 ,0x00F1 )); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0xAF20 ,0xAFDF ,0x0000 ,0x00C0 )); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0xAFE4 ,0xFFFF ,0x0000 ,0x501C )); + } +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 ,0x000A0000 ,0x000BFFFF ,0 ,0x00020000 )); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_non_cacheable, aml_ReadWrite, +0 , pci->w32.begin, pci->w32.end -1 ,0 , + pci->w32.end - pci->w32.begin)); +if (pci->w64.begin) { +aml_append (crs, +aml_qword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_cacheable, aml_ReadWrite, +0 , pci->w64.begin, pci->w64.end -1 ,0 , + pci->w64.end - pci->w64.begin)); + } +aml_append (scope,aml_name_decl ("_CRS" , crs)); +/* reserve PCIHP resources */ if (pm->pcihp_io_len) { dev =aml_device ("PHPR" );
hw/i386/acpi-dsdt-pci-crs.dsl deleted +0 -92
92 lines not on this page · raw message
hw/i386/acpi-dsdt.dsl +0 -45
57 lines not on this page · raw message
hw/i386/q35-acpi-dsdt.dsl +0 -18
@@ -48,23 +48,6 @@ DefinitionBlock ( /**************************************************************** * PCI Bus definition ****************************************************************/ -#define BOARD_SPECIFIC_PCI_RESOURSES \ - WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \ - 0x0000, \ - 0x0000, \ - 0x0CD7, \ - 0x0000, \ - 0x0CD8, \ - ,, , TypeStatic) \ - /* 0xcd8-0xcf7 hole for CPU hotplug, hw/acpi/ich9.c:ICH9_PROC_BASE */ \ - WordIO(ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange, \ - 0x0000, \ - 0x0D00, \ - 0xFFFF, \ - 0x0000, \ - 0xF300, \ - ,, , TypeStatic) - Scope(\_SB) { Device(PCI0) { Name(_HID, EisaId("PNP0A08"))
@@ -131,7 +114,6 @@ DefinitionBlock ( } } -#include "acpi-dsdt-pci-crs.dsl" #include "acpi-dsdt-hpet.dsl"
hw/i386/ssdt-misc.dsl +0 -19
@@ -18,23 +18,4 @@ ACPI_EXTRACT_ALL_CODE ssdp_misc_aml DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1) { - -/**************************************************************** - * PCI memory ranges - ****************************************************************/ - - Scope(\) { - ACPI_EXTRACT_NAME_DWORD_CONST acpi_pci32_start - Name(P0S, 0x12345678) - ACPI_EXTRACT_NAME_DWORD_CONST acpi_pci32_end - Name(P0E, 0x12345678) - ACPI_EXTRACT_NAME_BYTE_CONST acpi_pci64_valid - Name(P1V, 0x12) - ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_start - Name(P1S, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }) - ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_end - Name(P1E, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }) - ACPI_EXTRACT_NAME_BUFFER8 acpi_pci64_length - Name(P1L, Buffer() { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }) - } }
Signature · 1 line
1.8.3.1
PATCH v5 2/16 pc: acpi: drop manual hole punching for PCI hotplug resources
In reply to Igor MammedovDrops manual hole punching in PCI0._CRS for PIIX4 machine type. Resources will be consumed by Device(PHPR) that cwis attached to PCI bus. The same way how it currently works for mem hotlpug.
Manual hole in PIIX4 _CRS wasn't correct anyway since it was legacy size 0xF while current PCIHP MMIO region is of size 0x14.
--- hw/i386/acpi-build.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
hw/i386/acpi-build.c +1 -5
@@ -885,11 +885,7 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (crs,aml_word_io (aml_min_fixed, aml_max_fixed, aml_pos_decode, aml_entire_range, -0x0000 ,0x0D00 ,0xADFF ,0x0000 ,0xA100 )); -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0x0000 ,0xAE0F ,0xAEFF ,0x0000 ,0x00F1 )); +0x0000 ,0x0D00 ,0xAEFF ,0x0000 ,0xA200 )); aml_append(crs, aml_word_io(aml_min_fixed, aml_max_fixed, aml_pos_decode, aml_entire_range,
Signature · 1 line
1.8.3.1
PATCH v5 3/16 pc: acpi: drop manual hole punching for CPU hotplug resources
In reply to Igor MammedovDrops manual hole punching in PCI0._CRS on PIIX4 machine type for CPU hotplug resources.
Resources will be consumed by Device(PRES) that is attached to PCI bus. The same way how it currently works for mem hotlpug.
--- hw/i386/acpi-build.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
hw/i386/acpi-build.c +1 -5
@@ -885,11 +885,7 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (crs,aml_word_io (aml_min_fixed, aml_max_fixed, aml_pos_decode, aml_entire_range, -0x0000 ,0x0D00 ,0xAEFF ,0x0000 ,0xA200 )); -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0x0000 ,0xAF20 ,0xAFDF ,0x0000 ,0x00C0 )); +0x0000 ,0x0D00 ,0xAFDF ,0x0000 ,0xA2E0 )); aml_append(crs, aml_word_io(aml_min_fixed, aml_max_fixed, aml_pos_decode, aml_entire_range,
Signature · 1 line
1.8.3.1
PATCH v5 4/16 pc: acpi: drop manual hole punching for GPE0 resources
In reply to Igor MammedovDrops manual hole punching in PCI0._CRS on PIIX4 machine type for GPE0 resources. Resources will be consumed by Device(GPE0) that is attached to PCI namespace.
There is GPE device with HID ACPI0006 since ACPI2.0 that should be used for this purpose but none of Windows versions support it and show it as "unknown device", so reserve resource in old fashioned way with PNP0A06 device to make windows happy and actually reserve resources.
Along with last hole _CRS layout of PIIX4 machine becomes the same as Q35 one, so merge them together and use the same _CRS for both machine types.
--- hw/i386/acpi-build.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
hw/i386/acpi-build.c +17 -15
@@ -876,21 +876,10 @@ build_ssdt(GArray *table_data, GArray *linker,aml_word_io (aml_min_fixed, aml_max_fixed, aml_pos_decode, aml_entire_range, 0x0000, 0x0000, 0x0CF7, 0x0000, 0x0CF8)); -if (ich9_lpc_find ()) {/* Q35 */ -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0x0000 ,0x0D00 ,0xFFFF ,0x0000 ,0xF300 )); - }else {/* piix4 */ -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0x0000 ,0x0D00 ,0xAFDF ,0x0000 ,0xA2E0 )); -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0x0000 ,0xAFE4 ,0xFFFF ,0x0000 ,0x501C )); - } +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 ,0x0D00 ,0xFFFF ,0x0000 ,0xF300 )); aml_append(crs, aml_dword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed, aml_cacheable, aml_ReadWrite,
@@ -909,6 +898,19 @@ build_ssdt(GArray *table_data, GArray *linker, }aml_append (scope,aml_name_decl ("_CRS" , crs)); +/* reserve GPE0 block resources */ + dev =aml_device ("GPE0" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A06" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_string ("GPE0 resources" ))); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, pm->gpe0_blk, pm->gpe0_blk,1 , pm->gpe0_blk_len) + ); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (scope, dev); +/* reserve PCIHP resources */ if (pm->pcihp_io_len) { dev =aml_device ("PHPR" );
Signature · 1 line
1.8.3.1
PATCH v5 5/16 pc: acpi-build: drop remaining ssdt_misc template
In reply to Igor MammedovIt drops empty ssdt_misc templete. It also hides from user almost all pointer arithmetic when building SSDT which makes resulting code a bit cleaner and concentrating only on composing ASL construct /i.e. a task build_ssdt() should be doing/.
Also it makes one binary blob less stored in QEMU source tree by removing need to keep and update hw/i386/ssdt-misc.hex.generated file here in total saving us ~430LOC.
--- hw/i386/Makefile.objs | 1 - hw/i386/acpi-build.c | 7 ++----- hw/i386/ssdt-misc.dsl | 21 --------------------- 3 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 hw/i386/ssdt-misc.dsl
hw/i386/Makefile.objs +0 -1
@@ -10,7 +10,6 @@ obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c \ hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ hw/i386/ssdt-pcihp.hex \ - hw/i386/ssdt-misc.hex \ hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
hw/i386/acpi-build.c +2 -5
@@ -526,7 +526,6 @@ static inline char acpi_get_hex(uint32_t val)#define ACPI_SSDT_SIGNATURE 0x54445353/* SSDT */ #define ACPI_SSDT_HEADER_LENGTH 36 -#include "hw/i386/ssdt-misc.hex" #include "hw/i386/ssdt-pcihp.hex" #include "hw/i386/ssdt-tpm.hex"
@@ -850,7 +849,6 @@ build_ssdt(GArray *table_data, GArray *linker,MachineState *machine =MACHINE (qdev_get_machine ());uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit; -uint8_t *ssdt_ptr;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;int i;
@@ -860,9 +858,8 @@ build_ssdt(GArray *table_data, GArray *linker,QEMU_BUILD_BUG_ON (ACPI_CPU_HOTPLUG_ID_LIMIT >256 );g_assert (acpi_cpus <=ACPI_CPU_HOTPLUG_ID_LIMIT ); -/* Copy header and patch values in the S3_ / S4_ / S5_ packages */ - ssdt_ptr =acpi_data_push (ssdt->buf,sizeof (ssdp_misc_aml)); -memcpy (ssdt_ptr, ssdp_misc_aml,sizeof (ssdp_misc_aml)); +/* Reserve space for header */ +acpi_data_push (ssdt->buf,sizeof (AcpiTableHeader)); scope =aml_scope ("\\_SB.PCI0" );/* build PCI0._CRS */
hw/i386/ssdt-misc.dsl deleted +0 -21
@@ -1,21 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License along - * with this program; if not, see <http://www.gnu.org/licenses/>. - */ -#include "hw/acpi/pc-hotplug.h" - -ACPI_EXTRACT_ALL_CODE ssdp_misc_aml - -DefinitionBlock ("ssdt-misc.aml", "SSDT", 0x01, "BXPC", "BXSSDTSUSP", 0x1) -{ -}
Signature · 1 line
1.8.3.1
PATCH v5 6/16 acpi: add acpi_irq_no_flags() term
In reply to Igor Mammedov--- hw/acpi/aml-build.c | 21 +++++++++++++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 22 insertions(+)
hw/acpi/aml-build.c +21 -0
@@ -514,6 +514,27 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base,return var; } +/* +* ACPI 1.0b: 6.4.2.1.1 ASL Macro for IRQ Descriptor +* +* More verbose description at: +* ACPI 5.0: 19.5.64 IRQNoFlags (Interrupt Resource Descriptor Macro) +* 6.4.2.1 IRQ Descriptor +*/ +Aml *aml_irq_no_flags (uint8_t irq) +{ +uint16_t irq_mask; +Aml *var =aml_alloc (); + +assert (irq <16 ); +build_append_byte (var->buf,0x22 );/* IRQ descriptor 2 byte form */ + + irq_mask =1U << irq; +build_append_byte (var->buf, irq_mask &0xFF );/* IRQ mask bits[7:0] */ +build_append_byte (var->buf, irq_mask >>8 );/* IRQ mask bits[15:8] */ +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLEqual */ Aml *aml_equal (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -146,6 +146,7 @@ Aml *aml_io(AmlIODecode dec, uint16_t min_base, uint16_t max_base, uint8_t aln, uint8_t len);Aml *aml_operation_region (const char *name,AmlRegionSpace rs,uint32_t offset,uint32_t len); +Aml *aml_irq_no_flags (uint8_t irq);Aml *aml_named_field (const char *name,unsigned length);Aml *aml_reserved_field (unsigned length);Aml *aml_local (int num);
Signature · 1 line
1.8.3.1
PATCH v5 7/16 pc: export applesmc IO port/len
In reply to Igor MammedovIO port and length will be used in following patch to correctly generate SMC ACPI device in SSDT.
--- hw/i386/acpi-build.c | 2 +- hw/misc/applesmc.c | 5 ++--- include/hw/isa/isa.h | 11 +++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-)
hw/i386/acpi-build.c +1 -1
@@ -145,7 +145,7 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)/* Patch in appropriate value for AppleSMC _STA */ *(uint8_t *)(info->dsdt_code + *applesmc_sta) = -applesmc_find () ?0x0b :0x00 ; +applesmc_port () ?0x0b :0x00 ; } static
hw/misc/applesmc.c +2 -3
@@ -43,7 +43,6 @@/* command/status port used by Apple SMC */ #define APPLESMC_CMD_PORT 0x4#define APPLESMC_NR_PORTS 32 -#define APPLESMC_MAX_DATA_LENGTH 32#define APPLESMC_READ_CMD 0x10#define APPLESMC_WRITE_CMD 0x11
@@ -249,8 +248,8 @@ static void applesmc_isa_realize(DeviceState *dev, Error **errp) }static Property applesmc_isa_properties[] = { -DEFINE_PROP_UINT32 ("iobase" , AppleSMCState, iobase, -APPLESMC_DEFAULT_IOBASE ), +DEFINE_PROP_UINT32 (APPLESMC_PROP_IO_BASE , AppleSMCState, iobase, +APPLESMC_DEFAULT_IOBASE ),DEFINE_PROP_STRING ("osk" , AppleSMCState, osk),DEFINE_PROP_END_OF_LIST (), };
include/hw/isa/isa.h +9 -2
@@ -21,10 +21,17 @@#define ISA_BUS (obj) OBJECT_CHECK(ISABus, (obj), TYPE_ISA_BUS)#define TYPE_APPLE_SMC "isa-applesmc" +#define APPLESMC_MAX_DATA_LENGTH 32 +#define APPLESMC_PROP_IO_BASE "iobase" -static inline bool applesmc_find (void ) +static inline uint16_t applesmc_port (void ) { -return object_resolve_path_type ("" ,TYPE_APPLE_SMC ,NULL ); +Object *obj =object_resolve_path_type ("" ,TYPE_APPLE_SMC ,NULL ); + +if (obj) { +return object_property_get_int (obj,APPLESMC_PROP_IO_BASE ,NULL ); + } +return 0 ; } typedef struct ISADeviceClass {
Signature · 1 line
1.8.3.1
PATCH v5 8/16 pc: acpi-build: drop template patching and create Device(SMC) dynamically
In reply to Igor Mammedovpatch moves SMC device into SSDT and creates it only when device is present, which makes ACPI tables smaller in default case when device is not present.
Also it fixes wrong IO range in CRS if "iobase" property is set to a non default value.
PS:
Testing with XP shows that current default "iobase" used SMC device conflicts with floppy controller IO, but it's topic for another patch and I'd leave it to SMC device author for resolving conflict.
--- hw/i386/acpi-build.c | 29 ++++++++++++++++++++++------- hw/i386/acpi-dsdt-isa.dsl | 11 ----------- hw/i386/acpi-dsdt.dsl | 1 - hw/i386/q35-acpi-dsdt.dsl | 1 - 4 files changed, 22 insertions(+), 20 deletions(-)
hw/i386/acpi-build.c +22 -7
@@ -116,6 +116,7 @@ typedef struct AcpiMiscInfo {const unsigned char *dsdt_code;unsigned dsdt_size;uint16_t pvpanic_port; +uint16_t applesmc_io_base; } AcpiMiscInfo; typedef struct AcpiBuildPciBusHotplugState {
@@ -127,7 +128,6 @@ typedef struct AcpiBuildPciBusHotplugState {static void acpi_get_dsdt (AcpiMiscInfo *info) { -uint16_t *applesmc_sta;Object *piix =piix4_pm_find ();Object *lpc =ich9_lpc_find ();assert (!!piix != !!lpc);
@@ -135,17 +135,11 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)if (piix) { info->dsdt_code = AcpiDsdtAmlCode; info->dsdt_size =sizeof AcpiDsdtAmlCode; - applesmc_sta = piix_dsdt_applesmc_sta; }if (lpc) { info->dsdt_code = Q35AcpiDsdtAmlCode; info->dsdt_size =sizeof Q35AcpiDsdtAmlCode; - applesmc_sta = q35_dsdt_applesmc_sta; } - -/* Patch in appropriate value for AppleSMC _STA */ - *(uint8_t *)(info->dsdt_code + *applesmc_sta) = -applesmc_port () ?0x0b :0x00 ; } static
@@ -248,6 +242,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) info->has_hpet =hpet_find (); info->has_tpm =tpm_find (); info->pvpanic_port =pvpanic_port (); + info->applesmc_io_base =applesmc_port (); }static void acpi_get_pci_info (PcPciInfo *info)
@@ -955,6 +950,26 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (scope,aml_name_decl ("_S5" , pkg));aml_append (ssdt, scope); +if (misc->applesmc_io_base) { + scope =aml_scope ("\\_SB.PCI0.ISA" ); + dev =aml_device ("SMC" ); + +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("APP0001" ))); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, misc->applesmc_io_base, misc->applesmc_io_base, +0x01 ,APPLESMC_MAX_DATA_LENGTH ) + ); +aml_append (crs,aml_irq_no_flags (6 )); +aml_append (dev,aml_name_decl ("_CRS" , crs)); + +aml_append (scope, dev); +aml_append (ssdt, scope); + } +if (misc->pvpanic_port) { scope =aml_scope ("\\_SB.PCI0.ISA" );
hw/i386/acpi-dsdt-isa.dsl +0 -11
@@ -16,17 +16,6 @@ /* Common legacy ISA style devices. */ Scope(\_SB.PCI0.ISA) { - Device (SMC) { - Name(_HID, EisaId("APP0001")) - /* _STA will be patched to 0x0B if AppleSMC is present */ - ACPI_EXTRACT_NAME_BYTE_CONST DSDT_APPLESMC_STA - Name(_STA, 0xF0) - Name(_CRS, ResourceTemplate () { - IO (Decode16, 0x0300, 0x0300, 0x01, 0x20) - IRQNoFlags() { 6 } - }) - } - Device(RTC) { Name(_HID, EisaId("PNP0B00")) Name(_CRS, ResourceTemplate() {
hw/i386/acpi-dsdt.dsl +0 -1
@@ -85,7 +85,6 @@ DefinitionBlock ( } } -#define DSDT_APPLESMC_STA piix_dsdt_applesmc_sta #include "acpi-dsdt-isa.dsl"
hw/i386/q35-acpi-dsdt.dsl +0 -1
@@ -150,7 +150,6 @@ DefinitionBlock ( } } -#define DSDT_APPLESMC_STA q35_dsdt_applesmc_sta #include "acpi-dsdt-isa.dsl"
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v5 08/16] pc: acpi-build: drop template patching and create Device(SMC) dynamically
Quoted 6 lines · On Fri, 20 Feb 2015 18:22:12 +0000 Igor Mammedov <[email protected]> wrote:
patch moves SMC device into SSDT and creates it only when device is present, which makes ACPI tables smaller in default case when device is not present.
Also it fixes wrong IO range in CRS if "iobase" property is set to a non default value.
Reza could check that patch doesn't break OSX pls?
Quoted 135 lines
PS:
Testing with XP shows that current default "iobase" used SMC device conflicts with floppy controller IO, but it's topic for another patch and I'd leave it to SMC device author for resolving conflict.Signed-off-by Igor Mammedov <[email protected]>--- hw/i386/acpi-build.c | 29 ++++++++++++++++++++++------- hw/i386/acpi-dsdt-isa.dsl | 11 ----------- hw/i386/acpi-dsdt.dsl | 1 - hw/i386/q35-acpi-dsdt.dsl | 1 - 4 files changed, 22 insertions(+), 20 deletions(-)hw/i386/acpi-build.c +22
-7@@ -116,6 +116,7 @@ typedef struct AcpiMiscInfo {const unsigned char *dsdt_code;unsigned dsdt_size;uint16_t pvpanic_port; +uint16_t applesmc_io_base; } AcpiMiscInfo; typedef struct AcpiBuildPciBusHotplugState {@@ -127,7 +128,6 @@ typedef struct AcpiBuildPciBusHotplugState {static void acpi_get_dsdt (AcpiMiscInfo *info) { -uint16_t *applesmc_sta;Object *piix =piix4_pm_find ();Object *lpc =ich9_lpc_find ();assert (!!piix != !!lpc);@@ -135,17 +135,11 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)if (piix) { info->dsdt_code = AcpiDsdtAmlCode; info->dsdt_size =sizeof AcpiDsdtAmlCode; - applesmc_sta = piix_dsdt_applesmc_sta; }if (lpc) { info->dsdt_code = Q35AcpiDsdtAmlCode; info->dsdt_size =sizeof Q35AcpiDsdtAmlCode; - applesmc_sta = q35_dsdt_applesmc_sta; } - -/* Patch in appropriate value for AppleSMC _STA */ - *(uint8_t *)(info->dsdt_code + *applesmc_sta) = -applesmc_port () ?0x0b :0x00 ; } static@@ -248,6 +242,7 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) info->has_hpet =hpet_find (); info->has_tpm =tpm_find (); info->pvpanic_port =pvpanic_port (); + info->applesmc_io_base =applesmc_port (); }static void acpi_get_pci_info (PcPciInfo *info)@@ -955,6 +950,26 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (scope,aml_name_decl ("_S5" , pkg));aml_append (ssdt, scope); +if (misc->applesmc_io_base) { + scope =aml_scope ("\\_SB.PCI0.ISA" ); + dev =aml_device ("SMC" ); + +aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("APP0001" ))); +/* device present, functioning, decoding, not shown in UI */ +aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xB ))); + + crs =aml_resource_template (); +aml_append (crs, +aml_io (aml_decode16, misc->applesmc_io_base, misc->applesmc_io_base, +0x01 ,APPLESMC_MAX_DATA_LENGTH ) + ); +aml_append (crs,aml_irq_no_flags (6 )); +aml_append (dev,aml_name_decl ("_CRS" , crs)); + +aml_append (scope, dev); +aml_append (ssdt, scope); + } +if (misc->pvpanic_port) { scope =aml_scope ("\\_SB.PCI0.ISA" );hw/i386/acpi-dsdt-isa.dsl +0
-11@@ -16,17 +16,6 @@ /* Common legacy ISA style devices. */ Scope(\_SB.PCI0.ISA) { - Device (SMC) { - Name(_HID, EisaId("APP0001")) - /* _STA will be patched to 0x0B if AppleSMC is present */ - ACPI_EXTRACT_NAME_BYTE_CONST DSDT_APPLESMC_STA - Name(_STA, 0xF0) - Name(_CRS, ResourceTemplate () { - IO (Decode16, 0x0300, 0x0300, 0x01, 0x20) - IRQNoFlags() { 6 } - }) - } - Device(RTC) { Name(_HID, EisaId("PNP0B00")) Name(_CRS, ResourceTemplate() {hw/i386/acpi-dsdt.dsl +0
-1@@ -85,7 +85,6 @@ DefinitionBlock ( } } -#define DSDT_APPLESMC_STA piix_dsdt_applesmc_sta #include "acpi-dsdt-isa.dsl"hw/i386/q35-acpi-dsdt.dsl +0
-1@@ -150,7 +150,6 @@ DefinitionBlock ( } } -#define DSDT_APPLESMC_STA q35_dsdt_applesmc_sta #include "acpi-dsdt-isa.dsl"
PATCH v5 9/16 tests: ACPI test blobs update due to PCI0._CRS changes
In reply to Igor MammedovPCI0._CRS was moved into SSDT and became the same for PIIX4/Q35 machines.
--- tests/acpi-test-data/pc/DSDT | Bin 3415 -> 2970 bytes tests/acpi-test-data/pc/SSDT | Bin 2374 -> 2480 bytes tests/acpi-test-data/q35/DSDT | Bin 8005 -> 7608 bytes tests/acpi-test-data/q35/SSDT | Bin 578 -> 685 bytes 4 files changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/pc/DSDT binary +0 -0
tests/acpi-test-data/pc/SSDT binary +0 -0
tests/acpi-test-data/q35/DSDT binary +0 -0
tests/acpi-test-data/q35/SSDT binary +0 -0
Signature · 1 line
1.8.3.1
PATCH v5 10/16 tests: bios-tables-test: add support for testing bridges
In reply to Igor MammedovAdds alternative ACPI table blob selection for testing non default QEMU configurations. If blob file for test variant is not present, fallback to default blob.
With this change implement testing with a coldplugged bridge.
--- tests/bios-tables-test.c | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-)
tests/bios-tables-test.c +40 -5
@@ -40,6 +40,7 @@ typedef struct { typedef struct { const char *machine; + const char *variant; uint32_t rsdp_addr; AcpiRsdpDescriptor rsdp_table; AcpiRsdtDescriptorRev1 rsdt_table;
@@ -396,13 +397,14 @@ static void dump_aml_files(test_data *data, bool rebuild)int i;for (i =0 ; i < data->tables->len; ++i) { +const char *ext = data->variant ? data->variant :"" ; sdt = &g_array_index (data->tables, AcpiSdtTable, i);g_assert (sdt->aml);if (rebuild) {uint32_t signature =cpu_to_le32 (sdt->header.signature); - aml_file =g_strdup_printf ("%s/%s/%.4s" , data_dir, data->machine, - (gchar *)&signature); + aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, + (gchar *)&signature, ext); fd =g_open (aml_file,O_WRONLY |O_TRUNC |O_CREAT ,S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP |S_IROTH ); }else {
@@ -509,7 +511,7 @@ static GArray *load_expected_aml(test_data *data) {int i;AcpiSdtTable *sdt; -gchar *aml_file; +gchar *aml_file =NULL ;GError *error =NULL ;gboolean ret;
@@ -517,6 +519,7 @@ static GArray *load_expected_aml(test_data *data)for (i =0 ; i < data->tables->len; ++i) {AcpiSdtTable exp_sdt;uint32_t signature; +const char *ext = data->variant ? data->variant :"" ; sdt = &g_array_index (data->tables, AcpiSdtTable, i);
@@ -524,8 +527,15 @@ static GArray *load_expected_aml(test_data *data) exp_sdt.header.signature = sdt->header.signature; signature =cpu_to_le32 (sdt->header.signature); - aml_file =g_strdup_printf ("%s/%s/%.4s" , data_dir, data->machine, - (gchar *)&signature); + +try_again: + aml_file =g_strdup_printf ("%s/%s/%.4s%s" , data_dir, data->machine, + (gchar *)&signature, ext); +if (data->variant && !g_file_test (aml_file,G_FILE_TEST_EXISTS )) { +g_free (aml_file); + ext ="" ; + goto try_again; + } exp_sdt.aml_file = aml_file;g_assert (g_file_test (aml_file,G_FILE_TEST_EXISTS )); ret = g_file_get_contents(aml_file, &exp_sdt.aml,
@@ -778,6 +788,17 @@ static void test_acpi_piix4_tcg(void)free_test_data (&data); } +static void test_acpi_piix4_tcg_bridge (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_PC ; + data.variant =".bridge" ; +test_acpi_one ("-machine accel=tcg -device pci-bridge,chassis_nr=1" , &data); +free_test_data (&data); +} +static void test_acpi_q35_tcg (void ) {test_data data;
@@ -788,6 +809,18 @@ static void test_acpi_q35_tcg(void)free_test_data (&data); } +static void test_acpi_q35_tcg_bridge (void ) +{ +test_data data; + +memset (&data,0 ,sizeof (data)); + data.machine =MACHINE_Q35 ; + data.variant =".bridge" ; +test_acpi_one ("-machine q35,accel=tcg -device pci-bridge,chassis_nr=1" , + &data); +free_test_data (&data); +} +int main (int argc,char *argv[]) {const char *arch =qtest_get_arch ();
@@ -805,7 +838,9 @@ int main(int argc, char *argv[])if (strcmp (arch,"i386" ) ==0 ||strcmp (arch,"x86_64" ) ==0 ) {qtest_add_func ("acpi/piix4/tcg" , test_acpi_piix4_tcg); +qtest_add_func ("acpi/piix4/tcg/bridge" , test_acpi_piix4_tcg_bridge);qtest_add_func ("acpi/q35/tcg" , test_acpi_q35_tcg); +qtest_add_func ("acpi/q35/tcg/bridge" , test_acpi_q35_tcg_bridge); } ret =g_test_run ();unlink (disk);
Signature · 1 line
1.8.3.1
PATCH v5 11/16 tests: add ACPI blobs for qemu with bridge cases
In reply to Igor Mammedov--- tests/acpi-test-data/pc/SSDT.bridge | Bin 0 -> 4352 bytes tests/acpi-test-data/q35/SSDT.bridge | Bin 0 -> 702 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/acpi-test-data/pc/SSDT.bridge create mode 100644 tests/acpi-test-data/q35/SSDT.bridge
tests/acpi-test-data/pc/SSDT.bridge new file binary +0 -0
tests/acpi-test-data/q35/SSDT.bridge new file binary +0 -0
Signature · 1 line
1.8.3.1
PATCH v5 12/16 pc: acpi-build: simplify PCI bus tree generation
In reply to Igor Mammedovit basicaly does the same as original approach,
* just without bus/notify tables tracking (less obscure) which is easier to follow.
* drops unnecessary loops and bitmaps,
creating devices and notification method in the same loop.
* saves us ~100LOC
---
v2:
* fixed 'make check' failure on Q35, which was caused by adding slots for non present devices when ACPI hotplug is disabled
* fixed 'make check' failure on Q35, which was caused by marking devices as hotpluggable when ACPI hotplug is disabled
--- hw/i386/acpi-build.c | 274 ++++++++++++++++----------------------------------- 1 file changed, 85 insertions(+), 189 deletions(-)
hw/i386/acpi-build.c +85 -189
@@ -112,7 +112,6 @@ typedef struct AcpiPmInfo { typedef struct AcpiMiscInfo { bool has_hpet; bool has_tpm; - DECLARE_BITMAP(slot_hotplug_enable, PCI_SLOT_MAX); const unsigned char *dsdt_code; unsigned dsdt_size; uint16_t pvpanic_port;
@@ -591,74 +590,37 @@ static void acpi_set_pci_info(void) } } -static void build_pci_bus_state_init (AcpiBuildPciBusHotplugState *state, -AcpiBuildPciBusHotplugState *parent, -bool pcihp_bridge_en) +static void build_append_pcihp_notify_entry (GArray *method,int slot) { - state->parent = parent; - state->device_table =build_alloc_array (); - state->notify_table =build_alloc_array (); - state->pcihp_bridge_en = pcihp_bridge_en; +GArray *ifctx; + + ifctx =build_alloc_array (); +build_append_byte (ifctx,0x7B );/* AndOp */ +build_append_byte (ifctx,0x68 );/* Arg0Op */ +build_append_int (ifctx,0x1U << slot); +build_append_byte (ifctx,0x00 );/* NullName */ +build_append_byte (ifctx,0x86 );/* NotifyOp */ +build_append_namestring (ifctx,"S%.02X" ,PCI_DEVFN (slot,0 )); +build_append_byte (ifctx,0x69 );/* Arg1Op */ + +/* Pack it up */ +build_package (ifctx,0xA0 /* IfOp */ ); +build_append_array (method, ifctx); +build_free_array (ifctx); } -static void build_pci_bus_state_cleanup (AcpiBuildPciBusHotplugState *state) +static void build_append_pci_bus_devices (GArray *parent_scope,PCIBus *bus, +bool pcihp_bridge_en) { -build_free_array (state->device_table); -build_free_array (state->notify_table); -} - -static void *build_pci_bus_begin (PCIBus *bus,void *parent_state) -{ -AcpiBuildPciBusHotplugState *parent = parent_state; -AcpiBuildPciBusHotplugState *child =g_malloc (sizeof *child); - -build_pci_bus_state_init (child, parent, parent->pcihp_bridge_en); - -return child; -} - -static void build_pci_bus_end (PCIBus *bus,void *bus_state) -{ -AcpiBuildPciBusHotplugState *child = bus_state; -AcpiBuildPciBusHotplugState *parent = child->parent;GArray *bus_table =build_alloc_array (); -DECLARE_BITMAP (slot_hotplug_enable,PCI_SLOT_MAX ); -DECLARE_BITMAP (slot_device_present,PCI_SLOT_MAX ); -DECLARE_BITMAP (slot_device_system,PCI_SLOT_MAX ); -DECLARE_BITMAP (slot_device_vga,PCI_SLOT_MAX ); -DECLARE_BITMAP (slot_device_qxl,PCI_SLOT_MAX ); -uint8_t op; -int i; +GArray *method =NULL ;QObject *bsel; -GArray *method; -bool bus_hotplug_support = false; - -/* -* Skip bridge subtree creation if bridge hotplug is disabled -* to make acpi tables compatible with legacy machine types. -* Skip creation for hotplugged bridges as well. -*/ -if (bus->parent_dev && (!child->pcihp_bridge_en || -DEVICE (bus->parent_dev)->hotplugged)) { -build_free_array (bus_table); -build_pci_bus_state_cleanup (child); -g_free (child); -return ; - } +PCIBus *sec; +int i;if (bus->parent_dev) { - op =0x82 ;/* DeviceOp */ -build_append_namestring (bus_table,"S%.02X" , - bus->parent_dev->devfn); -build_append_byte (bus_table,0x08 );/* NameOp */ -build_append_namestring (bus_table,"_SUN" ); -build_append_int (bus_table,PCI_SLOT (bus->parent_dev->devfn)); -build_append_byte (bus_table,0x08 );/* NameOp */ -build_append_namestring (bus_table,"_ADR" ); -build_append_int (bus_table, (PCI_SLOT (bus->parent_dev->devfn) <<16 ) | -PCI_FUNC (bus->parent_dev->devfn)); +build_append_namestring (bus_table,"S%.02X_" , bus->parent_dev->devfn); }else { - op =0x10 ;/* ScopeOp */ ;build_append_namestring (bus_table,"PCI0" ); }
@@ -667,29 +629,28 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)build_append_byte (bus_table,0x08 );/* NameOp */ build_append_namestring (bus_table,"BSEL" );build_append_int (bus_table,qint_get_int (qobject_to_qint (bsel))); -memset (slot_hotplug_enable,0xff ,sizeof slot_hotplug_enable); - }else { -/* No bsel - no slots are hot-pluggable */ -memset (slot_hotplug_enable,0x00 ,sizeof slot_hotplug_enable); + method =build_alloc_method ("DVNT" ,2 ); } -memset (slot_device_present,0x00 ,sizeof slot_device_present); -memset (slot_device_system,0x00 ,sizeof slot_device_present); -memset (slot_device_vga,0x00 ,sizeof slot_device_vga); -memset (slot_device_qxl,0x00 ,sizeof slot_device_qxl); -for (i =0 ; i <ARRAY_SIZE (bus->devices); i +=PCI_FUNC_MAX ) {DeviceClass *dc;PCIDeviceClass *pc;PCIDevice *pdev = bus->devices[i];int slot =PCI_SLOT (i); +bool hotplug_enabled_dev;bool bridge_in_acpi;if (!pdev) { +if (bsel) {/* add hotplug slots for non present devices */ +void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); +memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); +patch_pcihp (slot, pcihp); + +build_append_pcihp_notify_entry (method, slot); + }continue ; } -set_bit (slot, slot_device_present); pc =PCI_DEVICE_GET_CLASS (pdev); dc =DEVICE_GET_CLASS (pdev);
@@ -698,142 +659,83 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)* In this case they aren't themselves hot-pluggable. * Hotplugged bridges *are* hot-pluggable. */ - bridge_in_acpi = pc->is_bridge && child->pcihp_bridge_en && - !DEVICE (pdev)->hotplugged; + bridge_in_acpi = pc->is_bridge && pcihp_bridge_en && + !DEVICE (pdev)->hotplugged; -if (pc->class_id ==PCI_CLASS_BRIDGE_ISA || bridge_in_acpi) { -set_bit (slot, slot_device_system); + hotplug_enabled_dev = bsel && dc->hotpluggable && !bridge_in_acpi; + +if (pc->class_id ==PCI_CLASS_BRIDGE_ISA ) { +continue ; }if (pc->class_id ==PCI_CLASS_DISPLAY_VGA ) { -set_bit (slot, slot_device_vga); -if (object_dynamic_cast (OBJECT (pdev),"qxl-vga" )) { -set_bit (slot, slot_device_qxl); +void *pcihp =acpi_data_push (bus_table, +ACPI_PCIQXL_SIZEOF ); +memcpy (pcihp,ACPI_PCIQXL_AML ,ACPI_PCIQXL_SIZEOF ); +patch_pciqxl (slot, pcihp); + }else { +void *pcihp =acpi_data_push (bus_table, +ACPI_PCIVGA_SIZEOF ); +memcpy (pcihp,ACPI_PCIVGA_AML ,ACPI_PCIVGA_SIZEOF ); +patch_pcivga (slot, pcihp); } - } - -if (!dc->hotpluggable || bridge_in_acpi) { -clear_bit (slot, slot_hotplug_enable); - } - } + }else if (hotplug_enabled_dev) { +void *pcihp =acpi_data_push (bus_table,ACPI_PCIHP_SIZEOF ); -/* Append Device object for each slot */ -for (i =0 ; i <PCI_SLOT_MAX ; i++) { -bool can_eject =test_bit (i, slot_hotplug_enable); -bool present =test_bit (i, slot_device_present); -bool vga =test_bit (i, slot_device_vga); -bool qxl =test_bit (i, slot_device_qxl); -bool system =test_bit (i, slot_device_system); -if (can_eject) { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCIHP_SIZEOF );memcpy (pcihp,ACPI_PCIHP_AML ,ACPI_PCIHP_SIZEOF ); -patch_pcihp (i, pcihp); - bus_hotplug_support = true; - }else if (qxl) { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCIQXL_SIZEOF ); -memcpy (pcihp,ACPI_PCIQXL_AML ,ACPI_PCIQXL_SIZEOF ); -patch_pciqxl (i, pcihp); - }else if (vga) { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCIVGA_SIZEOF ); -memcpy (pcihp,ACPI_PCIVGA_AML ,ACPI_PCIVGA_SIZEOF ); -patch_pcivga (i, pcihp); - }else if (system) { -/* Nothing to do: system devices are in DSDT or in SSDT above. */ - }else if (present) { -void *pcihp =acpi_data_push (bus_table, -ACPI_PCINOHP_SIZEOF ); +patch_pcihp (slot, pcihp); +build_append_pcihp_notify_entry (method, slot); + }else if (bridge_in_acpi) { +PCIBus *sec_bus =pci_bridge_get_sec_bus (PCI_BRIDGE (pdev)); +void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); + +memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); +patch_pcinohp (slot, pcihp); +build_append_pci_bus_devices (bus_table, sec_bus, pcihp_bridge_en); + }else {/* non hotpluggable present devices */ +void *pcihp =acpi_data_push (bus_table,ACPI_PCINOHP_SIZEOF ); +memcpy (pcihp,ACPI_PCINOHP_AML ,ACPI_PCINOHP_SIZEOF ); -patch_pcinohp (i, pcihp); +patch_pcinohp (slot, pcihp); } }if (bsel) { - method =build_alloc_method ("DVNT" ,2 ); - -for (i =0 ; i <PCI_SLOT_MAX ; i++) { -GArray *notify; -uint8_t op; - -if (!test_bit (i, slot_hotplug_enable)) { -continue ; - } - - notify =build_alloc_array (); - op =0xA0 ;/* IfOp */ - -build_append_byte (notify,0x7B );/* AndOp */ -build_append_byte (notify,0x68 );/* Arg0Op */ -build_append_int (notify,0x1U << i); -build_append_byte (notify,0x00 );/* NullName */ -build_append_byte (notify,0x86 );/* NotifyOp */ -build_append_namestring (notify,"S%.02X" ,PCI_DEVFN (i,0 )); -build_append_byte (notify,0x69 );/* Arg1Op */ - -/* Pack it up */ -build_package (notify, op); - -build_append_array (method, notify); - -build_free_array (notify); - } -build_append_and_cleanup_method (bus_table, method); }/* Append PCNT method to notify about events on local and child buses. * Add unconditionally for root since DSDT expects it. */ -if (bus_hotplug_support || child->notify_table->len || !bus->parent_dev) { - method =build_alloc_method ("PCNT" ,0 ); - -/* If bus supports hotplug select it and notify about local events */ -if (bsel) { -build_append_byte (method,0x70 );/* StoreOp */ -build_append_int (method,qint_get_int (qobject_to_qint (bsel))); -build_append_namestring (method,"BNUM" ); -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCIU" ); -build_append_int (method,1 );/* Device Check */ -build_append_namestring (method,"DVNT" ); -build_append_namestring (method,"PCID" ); -build_append_int (method,3 );/* Eject Request */ - } - -/* Notify about child bus events in any case */ -build_append_array (method, child->notify_table); - -build_append_and_cleanup_method (bus_table, method); - -/* Append description of child buses */ -build_append_array (bus_table, child->device_table); - -/* Pack it up */ -if (bus->parent_dev) { -build_extop_package (bus_table, op); - }else { -build_package (bus_table, op); - } + method =build_alloc_method ("PCNT" ,0 ); -/* Append our bus description to parent table */ -build_append_array (parent->device_table, bus_table); +/* If bus supports hotplug select it and notify about local events */ +if (bsel) { +build_append_byte (method,0x70 );/* StoreOp */ +build_append_int (method,qint_get_int (qobject_to_qint (bsel))); +build_append_namestring (method,"BNUM" ); +build_append_namestring (method,"DVNT" ); +build_append_namestring (method,"PCIU" ); +build_append_int (method,1 );/* Device Check */ +build_append_namestring (method,"DVNT" ); +build_append_namestring (method,"PCID" ); +build_append_int (method,3 );/* Eject Request */ + } -/* Also tell parent how to notify us, invoking PCNT method. -* At the moment this is not needed for root as we have a single root. -*/ -if (bus->parent_dev) { -build_append_namestring (parent->notify_table,"^PCNT.S%.02X" , - bus->parent_dev->devfn); +/* Notify about child bus events in any case */ +if (pcihp_bridge_en) { + QLIST_FOREACH(sec, &bus->child, sibling) { +build_append_namestring (method,"^S%.02X.PCNT" , + sec->parent_dev->devfn); } } -qobject_decref (bsel); +build_append_and_cleanup_method (bus_table, method); + +build_package (bus_table,0x10 );/* ScopeOp */ +build_append_array (parent_scope, bus_table);build_free_array (bus_table); -build_pci_bus_state_cleanup (child); -g_free (child); } static void
@@ -1175,7 +1077,6 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (sb_scope, method); { -AcpiBuildPciBusHotplugState hotplug_state;Object *pci_host;PCIBus *bus =NULL ;bool ambiguous;
@@ -1185,16 +1086,11 @@ build_ssdt(GArray *table_data, GArray *linker, bus =PCI_HOST_BRIDGE (pci_host)->bus; } -build_pci_bus_state_init (&hotplug_state,NULL , pm->pcihp_bridge_en); -if (bus) {/* Scan all PCI buses. Generate tables to support hotplug. */ -pci_for_each_bus_depth_first (bus, build_pci_bus_begin, - build_pci_bus_end, &hotplug_state); +build_append_pci_bus_devices (sb_scope->buf, bus, + pm->pcihp_bridge_en); } - -build_append_array (sb_scope->buf, hotplug_state.device_table); -build_pci_bus_state_cleanup (&hotplug_state); }aml_append (ssdt, sb_scope); }
Signature · 1 line
1.8.3.1
PATCH v5 13/16 tests: ACPI: update pc/SSDT.bridge due to new alg of PCI tree creation
In reply to Igor Mammedov--- tests/acpi-test-data/pc/SSDT.bridge | Bin 4352 -> 4351 bytes 1 file changed, 0 insertions(+), 0 deletions(-)
tests/acpi-test-data/pc/SSDT.bridge binary +0 -0
Signature · 1 line
1.8.3.1
PATCH v5 14/16 pc: acpi-build: drop template patching and create PCI bus tree dynamically
In reply to Igor MammedovReplace AML template patching with direct composing of PCI device entries in C. It allows to simplify PCI tree generation further and saves us about 400LOC scattered through different files, confining tree generation to one C function which is much easier to deal with.
---
v2:
* add some comments to the process of device creation
--- hw/i386/Makefile.objs | 1 - hw/i386/acpi-build.c | 235 +++++++++++++++++-------------------------------- hw/i386/ssdt-pcihp.dsl | 100 --------------------- 3 files changed, 80 insertions(+), 256 deletions(-) delete mode 100644 hw/i386/ssdt-pcihp.dsl
hw/i386/Makefile.objs +0 -1
@@ -9,7 +9,6 @@ obj-y += kvmvapic.o obj-y += acpi-build.o hw/i386/acpi-build.o: hw/i386/acpi-build.c \ hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \ - hw/i386/ssdt-pcihp.hex \ hw/i386/ssdt-tpm.hex iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
hw/i386/acpi-build.c +80 -155
317 lines not on this page · raw message
hw/i386/ssdt-pcihp.dsl deleted +0 -100
100 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 15/16 pc: acpi: remove not used anymore ssdt-[misc|pcihp].hex.generated blobs
In reply to Igor Mammedov--- hw/i386/ssdt-misc.hex.generated | 139 ---------------------- hw/i386/ssdt-pcihp.hex.generated | 251 --------------------------------------- 2 files changed, 390 deletions(-) delete mode 100644 hw/i386/ssdt-misc.hex.generated delete mode 100644 hw/i386/ssdt-pcihp.hex.generated
hw/i386/ssdt-misc.hex.generated deleted +0 -139
@@ -1,139 +0,0 @@ -static unsigned char acpi_pci64_length[] = { -0x6f -}; -static unsigned char acpi_pci32_start[] = { -0x2f -}; -static unsigned char acpi_pci64_valid[] = { -0x43 -}; -static unsigned char ssdp_misc_aml[] = { -0x53, -0x53, -0x44, -0x54, -0x77, -0x0, -0x0, -0x0, -0x1, -0x40, -0x42, -0x58, -0x50, -0x43, -0x0, -0x0, -0x42, -0x58, -0x53, -0x53, -0x44, -0x54, -0x53, -0x55, -0x1, -0x0, -0x0, -0x0, -0x49, -0x4e, -0x54, -0x4c, -0x7, -0x11, -0x14, -0x20, -0x10, -0x42, -0x5, -0x5c, -0x0, -0x8, -0x50, -0x30, -0x53, -0x5f, -0xc, -0x78, -0x56, -0x34, -0x12, -0x8, -0x50, -0x30, -0x45, -0x5f, -0xc, -0x78, -0x56, -0x34, -0x12, -0x8, -0x50, -0x31, -0x56, -0x5f, -0xa, -0x12, -0x8, -0x50, -0x31, -0x53, -0x5f, -0x11, -0xb, -0xa, -0x8, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x8, -0x50, -0x31, -0x45, -0x5f, -0x11, -0xb, -0xa, -0x8, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x8, -0x50, -0x31, -0x4c, -0x5f, -0x11, -0xb, -0xa, -0x8, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0, -0x0 -}; -static unsigned char acpi_pci64_start[] = { -0x4d -}; -static unsigned char acpi_pci64_end[] = { -0x5e -}; -static unsigned char acpi_pci32_end[] = { -0x39 -};
hw/i386/ssdt-pcihp.hex.generated deleted +0 -251
251 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v5 16/16 acpi: make build_*() routines static to aml-build.c
In reply to Igor Mammedovbuild_*() routines were used for composing AML structures manually in acpi-build.c but after conversion to AML API they are not used outside of aml-build.c anymore, so hide them from external users.
--- hw/acpi/aml-build.c | 20 ++++++++++---------- include/hw/acpi/aml-build.h | 16 ---------------- 2 files changed, 10 insertions(+), 26 deletions(-)
hw/acpi/aml-build.c +10 -10
@@ -27,27 +27,27 @@#include "hw/acpi/aml-build.h" #include "qemu/bswap.h" -GArray *build_alloc_array (void ) +static GArray *build_alloc_array (void ) {return g_array_new (false, true/* clear */ ,1 ); } -void build_free_array (GArray *array) +static void build_free_array (GArray *array) {g_array_free (array, true); } -void build_prepend_byte (GArray *array,uint8_t val) +static void build_prepend_byte (GArray *array,uint8_t val) {g_array_prepend_val (array, val); } -void build_append_byte (GArray *array,uint8_t val) +static void build_append_byte (GArray *array,uint8_t val) {g_array_append_val (array, val); } -void build_append_array (GArray *array,GArray *val) +static void build_append_array (GArray *array,GArray *val) {g_array_append_vals (array, val->data, val->len); }
@@ -141,7 +141,7 @@ build_append_namestringv(GArray *array, const char *format, va_list ap)g_strfreev (segs); } -void build_append_namestring (GArray *array,const char *format, ...) +static void build_append_namestring (GArray *array,const char *format, ...) {va_list ap;
@@ -158,7 +158,7 @@ enum { PACKAGE_LENGTH_4BYTE_SHIFT = 20, }; -void +static void build_prepend_package_length (GArray *package,unsigned length,bool incl_self) {uint8_t byte;
@@ -226,13 +226,13 @@ build_append_pkg_length(GArray *array, unsigned length, bool incl_self)build_free_array (tmp); } -void build_package (GArray *package,uint8_t op) +static void build_package (GArray *package,uint8_t op) {build_prepend_package_length (package, package->len, true);build_prepend_byte (package, op); } -void build_extop_package (GArray *package,uint8_t op) +static void build_extop_package (GArray *package,uint8_t op) {build_package (package, op);build_prepend_byte (package,0x5B );/* ExtOpPrefix */
@@ -248,7 +248,7 @@ static void build_append_int_noprefix(GArray *table, uint64_t value, int size) } } -void build_append_int (GArray *table,uint64_t value) +static void build_append_int (GArray *table,uint64_t value) {if (value ==0x00 ) {build_append_byte (table,0x00 );/* ZeroOp */
include/hw/acpi/aml-build.h +0 -16
@@ -188,20 +188,4 @@ Aml *aml_resource_template(void);Aml *aml_field (const char *name,AmlFieldFlags flags);Aml *aml_varpackage (uint32_t num_elements); -/* other helpers */ -GArray *build_alloc_array (void ); -void build_free_array (GArray *array); -void build_prepend_byte (GArray *array,uint8_t val); -void build_append_byte (GArray *array,uint8_t val); -void build_append_array (GArray *array,GArray *val); - -void GCC_FMT_ATTR(2, 3) -build_append_namestring(GArray *array, const char *format, ...); - -void -build_prepend_package_length(GArray *package, unsigned length, bool incl_self); -void build_package(GArray *package, uint8_t op); -void build_append_int(GArray *table, uint64_t value); -void build_extop_package(GArray *package, uint8_t op); -#endif
Signature · 1 line
1.8.3.1