qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

acpi: pci: use build_append_foo() API to construct MCFG

build_append_foo() API doesn't need explicit endianness conversions
which eliminates a source of errors and it makes build_mcfg() look like
declarative definition of MCFG table in ACPI spec, which makes it easy
to review.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
Suggested-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

v3:
* add some comment on the Configuration Space base address allocation
structure
v2:
* miss the reserved[8] of MCFG in last version, add it back
* drop SOBs and make sure bios-tables-test all OK
Message-Id: <20190521062836.6541-3-richardw.yang@linux.intel.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Wei Yang and committed by
Michael S. Tsirkin
e4610781 f13a944c

+24 -27
+24 -9
hw/acpi/pci.c
··· 30 30 31 31 void build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info) 32 32 { 33 - AcpiTableMcfg *mcfg; 34 - int len = sizeof(*mcfg) + sizeof(mcfg->allocation[0]); 33 + int mcfg_start = table_data->len; 35 34 36 - mcfg = acpi_data_push(table_data, len); 37 - mcfg->allocation[0].address = cpu_to_le64(info->base); 35 + /* 36 + * PCI Firmware Specification, Revision 3.0 37 + * 4.1.2 MCFG Table Description. 38 + */ 39 + acpi_data_push(table_data, sizeof(AcpiTableHeader)); 40 + /* Reserved */ 41 + build_append_int_noprefix(table_data, 0, 8); 38 42 39 - /* Only a single allocation so no need to play with segments */ 40 - mcfg->allocation[0].pci_segment = cpu_to_le16(0); 41 - mcfg->allocation[0].start_bus_number = 0; 42 - mcfg->allocation[0].end_bus_number = PCIE_MMCFG_BUS(info->size - 1); 43 + /* 44 + * Memory Mapped Enhanced Configuration Space Base Address Allocation 45 + * Structure 46 + */ 47 + /* Base address, processor-relative */ 48 + build_append_int_noprefix(table_data, info->base, 8); 49 + /* PCI segment group number */ 50 + build_append_int_noprefix(table_data, 0, 2); 51 + /* Starting PCI Bus number */ 52 + build_append_int_noprefix(table_data, 0, 1); 53 + /* Final PCI Bus number */ 54 + build_append_int_noprefix(table_data, PCIE_MMCFG_BUS(info->size - 1), 1); 55 + /* Reserved */ 56 + build_append_int_noprefix(table_data, 0, 4); 43 57 44 - build_header(linker, table_data, (void *)mcfg, "MCFG", len, 1, NULL, NULL); 58 + build_header(linker, table_data, (void *)(table_data->data + mcfg_start), 59 + "MCFG", table_data->len - mcfg_start, 1, NULL, NULL); 45 60 } 46 61
-18
include/hw/acpi/acpi-defs.h
··· 449 449 450 450 typedef struct AcpiSratProcessorGiccAffinity AcpiSratProcessorGiccAffinity; 451 451 452 - /* PCI fw r3.0 MCFG table. */ 453 - /* Subtable */ 454 - struct AcpiMcfgAllocation { 455 - uint64_t address; /* Base address, processor-relative */ 456 - uint16_t pci_segment; /* PCI segment group number */ 457 - uint8_t start_bus_number; /* Starting PCI Bus number */ 458 - uint8_t end_bus_number; /* Final PCI Bus number */ 459 - uint32_t reserved; 460 - } QEMU_PACKED; 461 - typedef struct AcpiMcfgAllocation AcpiMcfgAllocation; 462 - 463 - struct AcpiTableMcfg { 464 - ACPI_TABLE_HEADER_DEF; 465 - uint8_t reserved[8]; 466 - AcpiMcfgAllocation allocation[0]; 467 - } QEMU_PACKED; 468 - typedef struct AcpiTableMcfg AcpiTableMcfg; 469 - 470 452 /* 471 453 * TCPA Description Table 472 454 *