Q35 initial support for HVM guests
cover Q35 initial support for HVM guests
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
In order to create a Q35 guest, a new domain config option has been added, named 'device_model_machine'. Possible values are:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machine
If the option is omitted it defaults to "i440", not impacting existing domain configuration files.
DSDT files for Q35 and i440 are largely similar so the existing file dsdt.asl has been split with i440 and q35 specific parts put in seperated files.
The PCIe MMCONFIG area is configured by hvmloader and its base address and size are set in Xen using a new pair of hypercalls HVMOP_get|set_ecam_space. Access to the MMCONFIG area from a guest is trapped by Xen and transfered to the emulator as XEN_DMOP_IO_RANGE_PCI ioreq type.
[1] https://lore.kernel.org/xen-devel/[email protected]/
Thierry Escande (17):
libacpi: Split dsdt.asl file and extract i440 specific parts
libacpi: new DSDT ACPI table for Q35
hvmloader: add function to set the emulated machine type (i440/Q35)
hvmloader: add ACPI enabling for Q35
hvmloader: add Q35 DSDT table loading
hvmloader: Move pci devices setup to a separate function
hvmloader: add basic Q35 support
hvmloader: Extend PCI BAR struct
xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
hvmloader: Add support for HVMOP_set|get_ecam_space hypercalls
hvmloader: allocate MMCONFIG area in the MMIO hole
libxl: Q35 support (new option device_model_machine)
libxl: Add xen-platform device for Q35 machine
libacpi: build ACPI MCFG table if requested
hvmloader: Set MCFG in ACPI table
Handle PCIe ECAM space access from guests
docs: provide description for device_model_machine option
docs/man/xl.cfg.5.pod.in | 27 +++ tools/firmware/hvmloader/Makefile | 2 +- tools/firmware/hvmloader/config.h | 5 + tools/firmware/hvmloader/e820.c | 11 ++ tools/firmware/hvmloader/hvmloader.c | 21 ++- tools/firmware/hvmloader/ovmf.c | 4 +- tools/firmware/hvmloader/pci.c | 264 +++++++++++++++++++-------- tools/firmware/hvmloader/pci_regs.h | 16 ++ tools/firmware/hvmloader/seabios.c | 4 +- tools/firmware/hvmloader/util.c | 94 +++++++++- tools/firmware/hvmloader/util.h | 21 ++- tools/libacpi/Makefile | 10 +- tools/libacpi/acpi2_0.h | 17 ++ tools/libacpi/build.c | 43 +++++ tools/libacpi/dsdt.asl | 28 +-- tools/libacpi/dsdt_i440.asl | 36 ++++ tools/libacpi/dsdt_q35.asl | 130 +++++++++++++ tools/libacpi/libacpi.h | 6 + tools/libs/light/libxl_dm.c | 22 ++- tools/libs/light/libxl_types.idl | 7 + tools/xl/xl_parse.c | 14 ++ xen/arch/x86/hvm/hvm.c | 52 ++++++ xen/arch/x86/hvm/ioreq.c | 15 ++ xen/arch/x86/include/asm/domain.h | 4 + xen/include/public/hvm/hvm_op.h | 11 ++ 25 files changed, 739 insertions(+), 125 deletions(-) create mode 100644 tools/libacpi/dsdt_i440.asl create mode 100644 tools/libacpi/dsdt_q35.asl
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
PATCH 1/17 libacpi: Split dsdt.asl file and extract i440 specific parts
In order to factorize the common parts between i440 and q35 dsdt files, this patch splits dsdt.asl and put the i440 specific parts into dsdt_i400.asl.
This also makes use of #include directives instead of file concatenations to build the asl files.
Also, the anycpu asl files generation makes use of makefile pattern rules to avoid duplication for i440 and q35.
Becuase the LPC controller BDF (which differs between i440 and q35) must be set at device declaration, it is still set in dsdt.asl by checking for a MACHINE_TYPE_I440 macro defined in dsdt_i400.asl.
--- tools/firmware/hvmloader/Makefile | 2 +- tools/firmware/hvmloader/ovmf.c | 4 ++-- tools/firmware/hvmloader/seabios.c | 4 ++-- tools/firmware/hvmloader/util.c | 4 ++-- tools/firmware/hvmloader/util.h | 4 ++-- tools/libacpi/Makefile | 10 ++++----- tools/libacpi/dsdt.asl | 25 ++++----------------- tools/libacpi/dsdt_i440.asl | 36 ++++++++++++++++++++++++++++++ 8 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 tools/libacpi/dsdt_i440.asl
tools/firmware/hvmloader/Makefile +1 -1
@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o $(ACPI_OBJS): CFLAGS += -iquote . -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\" CFLAGS += -I$(ACPI_PATH)
tools/firmware/hvmloader/ovmf.c +2 -2
@@ -119,8 +119,8 @@ static void ovmf_load(const struct bios_config *config,static void ovmf_acpi_build_tables (void ) {struct acpi_config config = { - .dsdt_anycpu = dsdt_anycpu_qemu_xen, - .dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len, + .dsdt_anycpu = dsdt_i440_anycpu_qemu_xen, + .dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len, .dsdt_15cpu =NULL , .dsdt_15cpu_len =0 };
tools/firmware/hvmloader/seabios.c +2 -2
@@ -90,8 +90,8 @@ static void seabios_acpi_build_tables(void) {uint32_t rsdp = (uint32_t )scratch_alloc (sizeof (struct acpi_20_rsdp ),0 );struct acpi_config config = { - .dsdt_anycpu = dsdt_anycpu_qemu_xen, - .dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len, + .dsdt_anycpu = dsdt_i440_anycpu_qemu_xen, + .dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len, .dsdt_15cpu =NULL , .dsdt_15cpu_len =0 , };
tools/firmware/hvmloader/util.c +2 -2
@@ -843,8 +843,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, s =xenstore_read ("platform/device-model" ,"" );if ( !strncmp (s,"qemu_xen" ,9 ) ) { - config->dsdt_anycpu = dsdt_anycpu_qemu_xen; - config->dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len; + config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; config->dsdt_15cpu =NULL ; config->dsdt_15cpu_len =0 ; }
tools/firmware/hvmloader/util.h +2 -2
@@ -381,8 +381,8 @@ extern struct e820map memory_map;bool check_overlap (uint64_t start,uint64_t size,uint64_t reserved_start,uint64_t reserved_size); -extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; -extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len; +extern const unsigned char dsdt_i440_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; +extern const int dsdt_i440_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;unsigned long acpi_pages_allocated (void );
tools/libacpi/Makefile +4 -6
@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c DSDT_FILES ?= $(C_SRC-y) C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))
@@ -39,18 +39,16 @@ $(H_SRC): $(ACPI_BUILD_DIR)/%.h: %.asl $(MK_DSDT): mk_dsdt.c $(HOSTCC) $(HOSTCFLAGS) $(MKDSDT_CFLAGS-y) $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -o $@ mk_dsdt.c -$(ACPI_BUILD_DIR)/dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) +$(ACPI_BUILD_DIR)/dsdt_%_anycpu_qemu_xen.asl: dsdt_%.asl dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) # Remove last bracket awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) - cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) $(MK_DSDT) --debug=$(debug) --dm-version qemu-xen >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@ # NB. awk invocation is a portable alternative to 'head -n -1' -$(ACPI_BUILD_DIR)/dsdt_%cpu.asl: dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) +$(ACPI_BUILD_DIR)/dsdt_%cpu.asl: dsdt_i440.asl dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) # Remove last bracket awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) - cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) $(MK_DSDT) --debug=$(debug) --maxcpu $* >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@
@@ -65,7 +63,7 @@ $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl: $(MK_DSDT) mv -f $@.$(TMP_SUFFIX) $@ $(C_SRC): $(ACPI_BUILD_DIR)/%.c: $(ACPI_BUILD_DIR)/%.asl - $(IASL) -vs -p $(ACPI_BUILD_DIR)/$*.$(TMP_SUFFIX) -tc $< + $(IASL) -vs -I $(CURDIR) -p $(ACPI_BUILD_DIR)/$*.$(TMP_SUFFIX) -tc $< sed -e 's/AmlCode/$*/g' -e 's/_aml_code//g' $(ACPI_BUILD_DIR)/$*.hex > $@.$(TMP_SUFFIX) echo "int $*_len=sizeof($*);" >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@
tools/libacpi/dsdt.asl +4 -21
@@ -5,8 +5,6 @@ * Copyright (c) 2004, Intel Corporation. */ -DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) -{ Name (\PMBS, 0x0C00) Name (\PMLN, 0x08) Name (\IOB1, 0x00)
@@ -199,7 +197,10 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) Device (ISA) { - Name (_ADR, 0x00010000) /* device 1, fn 0 */ + /* Error will be raised if the machine type is not defined */ + #ifdef MACHINE_TYPE_I440 + Name (_ADR, 0x00010000) /* device 1, fn 0 */ + #endif OperationRegion(PIRQ, PCI_Config, 0x60, 0x4) Scope(\) {
@@ -329,23 +330,6 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) }) } - Device (FDC0) - { - Name (_HID, EisaId ("PNP0700")) - Method (_STA, 0, NotSerialized) - { - Return (0x0F) - } - - Name (_CRS, ResourceTemplate () - { - IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06) - IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01) - IRQNoFlags () {6} - DMA (Compatibility, NotBusMaster, Transfer8) {2} - }) - } - Device (UAR1) { Name (_HID, EisaId ("PNP0501"))
@@ -444,4 +428,3 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) Method(_PIC, 1) { Store(Arg0, PICD) } -}
tools/libacpi/dsdt_i440.asl new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/****************************************************************************** + * DSDT for Xen with Qemu device model (for i440 machine) + * + * Copyright (c) 2004, Intel Corporation. + */ + +DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) +{ + #define MACHINE_TYPE_I440 + + #include "dsdt.asl" + + Scope (\_SB.PCI0.ISA) + { + Device (FDC0) + { + Name (_HID, EisaId ("PNP0700")) + + Method (_STA, 0, NotSerialized) + { + Return (0x0F) + } + + Name (_CRS, ResourceTemplate () + { + IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06) + IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01) + IRQNoFlags () {6} + DMA (Compatibility, NotBusMaster, Transfer8) {2} + }) + } + } + + #include "dsdt_acpi_info.asl" +}
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 01/17] libacpi: Split dsdt.asl file and extract i440 specific parts
Quoted 11 lines · Thierry Escande
In order to factorize the common parts between i440 and q35 dsdt files, this patch splits dsdt.asl and put the i440 specific parts into dsdt_i400.asl.
This also makes use of #include directives instead of file concatenations to build the asl files.
Also, the anycpu asl files generation makes use of makefile pattern rules to avoid duplication for i440 and q35.
Becuase the LPC controller BDF (which differs between i440 and q35) must
s/Becuase/Because/
Quoted 2 lines
be set at device declaration, it is still set in dsdt.asl by checking for a
MACHINE_TYPE_I440macro defined in dsdt_i400.asl.
s/i400/i440/
Quoted 76 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/Makefile | 2 +- tools/firmware/hvmloader/ovmf.c | 4 ++-- tools/firmware/hvmloader/seabios.c | 4 ++-- tools/firmware/hvmloader/util.c | 4 ++-- tools/firmware/hvmloader/util.h | 4 ++-- tools/libacpi/Makefile | 10 ++++----- tools/libacpi/dsdt.asl | 25 ++++----------------- tools/libacpi/dsdt_i440.asl | 36 ++++++++++++++++++++++++++++++ 8 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 tools/libacpi/dsdt_i440.asltools/firmware/hvmloader/Makefile +1
-1@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o $(ACPI_OBJS): CFLAGS += -iquote . -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\" CFLAGS += -I$(ACPI_PATH)tools/firmware/hvmloader/ovmf.c +2
-2@@ -119,8 +119,8 @@ static void ovmf_load(const struct bios_config *config,static void ovmf_acpi_build_tables (void ) {struct acpi_config config = { - .dsdt_anycpu = dsdt_anycpu_qemu_xen, - .dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len, + .dsdt_anycpu = dsdt_i440_anycpu_qemu_xen, + .dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len, .dsdt_15cpu =NULL , .dsdt_15cpu_len =0 };tools/firmware/hvmloader/seabios.c +2
-2@@ -90,8 +90,8 @@ static void seabios_acpi_build_tables(void) {uint32_t rsdp = (uint32_t )scratch_alloc (sizeof (struct acpi_20_rsdp ),0 );struct acpi_config config = { - .dsdt_anycpu = dsdt_anycpu_qemu_xen, - .dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len, + .dsdt_anycpu = dsdt_i440_anycpu_qemu_xen, + .dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len, .dsdt_15cpu =NULL , .dsdt_15cpu_len =0 , };tools/firmware/hvmloader/util.c +2
-2@@ -843,8 +843,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, s =xenstore_read ("platform/device-model" ,"" );if ( !strncmp (s,"qemu_xen" ,9 ) ) { - config->dsdt_anycpu = dsdt_anycpu_qemu_xen; - config->dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len; + config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; config->dsdt_15cpu =NULL ; config->dsdt_15cpu_len =0 ; }tools/firmware/hvmloader/util.h +0
-0
tools/firmware/hvmloader/util.h extern struct e820map memory_map; · line 385
Quoted 7 lines
tools/firmware/hvmloader/util.h +2
-2@@ -381,8 +381,8 @@ extern struct e820map memory_map;bool check_overlap (uint64_t start,uint64_t size,uint64_t reserved_start,uint64_t reserved_size); -extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; -extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len; +extern const unsigned char dsdt_i440_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; +extern const int dsdt_i440_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;
While there you can make this unsigned int, like the dsdt_anycpu_len field.
Quoted 60 lines
tools/firmware/hvmloader/util.h +0
-0unsigned long acpi_pages_allocated (void );tools/libacpi/Makefile +4
-6@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c DSDT_FILES ?= $(C_SRC-y) C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))@@ -39,18 +39,16 @@ $(H_SRC): $(ACPI_BUILD_DIR)/%.h: %.asl $(MK_DSDT): mk_dsdt.c $(HOSTCC) $(HOSTCFLAGS) $(MKDSDT_CFLAGS-y) $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -o $@ mk_dsdt.c -$(ACPI_BUILD_DIR)/dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) +$(ACPI_BUILD_DIR)/dsdt_%_anycpu_qemu_xen.asl: dsdt_%.asl dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) # Remove last bracket awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) - cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) $(MK_DSDT) --debug=$(debug) --dm-version qemu-xen >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@ # NB. awk invocation is a portable alternative to 'head -n -1' -$(ACPI_BUILD_DIR)/dsdt_%cpu.asl: dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) +$(ACPI_BUILD_DIR)/dsdt_%cpu.asl: dsdt_i440.asl dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) # Remove last bracket awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) - cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) $(MK_DSDT) --debug=$(debug) --maxcpu $* >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@@@ -65,7 +63,7 @@ $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl: $(MK_DSDT) mv -f $@.$(TMP_SUFFIX) $@ $(C_SRC): $(ACPI_BUILD_DIR)/%.c: $(ACPI_BUILD_DIR)/%.asl - $(IASL) -vs -p $(ACPI_BUILD_DIR)/$*.$(TMP_SUFFIX) -tc $< + $(IASL) -vs -I $(CURDIR) -p $(ACPI_BUILD_DIR)/$*.$(TMP_SUFFIX) -tc $< sed -e 's/AmlCode/$*/g' -e 's/_aml_code//g' $(ACPI_BUILD_DIR)/$*.hex > $@.$(TMP_SUFFIX) echo "int $*_len=sizeof($*);" >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@tools/libacpi/dsdt.asl +0
-2@@ -5,8 +5,6 @@ * Copyright (c) 2004, Intel Corporation. */ -DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) -{ Name (\PMBS, 0x0C00) Name (\PMLN, 0x08) Name (\IOB1, 0x00)
tools/libacpi/dsdt.asl DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) · line 203
Quoted 8 lines
tools/libacpi/dsdt.asl +4
-1@@ -199,7 +197,10 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) Device (ISA) { - Name (_ADR, 0x00010000) /* device 1, fn 0 */ + /* Error will be raised if the machine type is not defined */ + #ifdef MACHINE_TYPE_I440 + Name (_ADR, 0x00010000) /* device 1, fn 0 */ + #endif
I think we want the preprocessor directives not indented the same as asl code, like we do in C, iow:
Device (ISA)
{
/* Error will be raised if the machine type is not defined */
#ifdef MACHINE_TYPE_I440
Name (_ADR, 0x00010000) /* device 1, fn 0 */#endif
Same with the includes and defines below.
Quoted 13 lines
tools/libacpi/dsdt.asl +0
-6OperationRegion(PIRQ, PCI_Config, 0x60, 0x4) Scope(\) {@@ -329,23 +330,6 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) }) } - Device (FDC0) - { - Name (_HID, EisaId ("PNP0700")) - Method (_STA, 0, NotSerialized) - { - Return (0x0F)
tools/libacpi/dsdt.asl DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) · line 347
Quoted 10 lines
tools/libacpi/dsdt.asl +0
-10- } - - Name (_CRS, ResourceTemplate () - { - IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06) - IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01) - IRQNoFlags () {6} - DMA (Compatibility, NotBusMaster, Transfer8) {2} - }) - }
I need to look at the Q35 changes, but ff the only differences are the Name() method at the top and this, we might as well use an #ifdef here, and there's no need to split into so many separate files? I need to look at further patches.
The ACPI table generation stuff could certainly do with an overall rework.
Quoted 14 lines
tools/libacpi/dsdt.asl +0
-1Device (UAR1) { Name (_HID, EisaId ("PNP0501"))@@ -444,4 +428,3 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) Method(_PIC, 1) { Store(Arg0, PICD) } -}tools/libacpi/dsdt_i440.asl new file +0
-0
tools/libacpi/dsdt_i440.asl line 10
Quoted 10 lines
tools/libacpi/dsdt_i440.asl new file +10
-0@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/****************************************************************************** + * DSDT for Xen with Qemu device model (for i440 machine) + * + * Copyright (c) 2004, Intel Corporation. + */ + +DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) +{ + #define MACHINE_TYPE_I440
IMO we probably want to define this outside of the DefinitionBlock section, just after the copyright header.
Quoted 38 lines
tools/libacpi/dsdt_i440.asl new file +26
-0+ + #include "dsdt.asl" + + Scope (\_SB.PCI0.ISA) + { + Device (FDC0) + { + Name (_HID, EisaId ("PNP0700")) + + Method (_STA, 0, NotSerialized) + { + Return (0x0F) + } + + Name (_CRS, ResourceTemplate () + { + IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06) + IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01) + IRQNoFlags () {6} + DMA (Compatibility, NotBusMaster, Transfer8) {2} + }) + } + } + + #include "dsdt_acpi_info.asl" +}Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 01/17] libacpi: Split dsdt.asl file and extract i440 specific parts
Quoted 99 lines · Roger Pau Monné
Quoted 11 lines · Thierry Escande
In order to factorize the common parts between i440 and q35 dsdt files, this patch splits dsdt.asl and put the i440 specific parts into dsdt_i400.asl.
This also makes use of #include directives instead of file concatenations to build the asl files.
Also, the anycpu asl files generation makes use of makefile pattern rules to avoid duplication for i440 and q35.
Becuase the LPC controller BDF (which differs between i440 and q35) must
s/Becuase/Because/
Quoted 2 lines
be set at device declaration, it is still set in dsdt.asl by checking for a
MACHINE_TYPE_I440macro defined in dsdt_i400.asl.s/i400/i440/
Quoted 79 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/Makefile | 2 +- tools/firmware/hvmloader/ovmf.c | 4 ++-- tools/firmware/hvmloader/seabios.c | 4 ++-- tools/firmware/hvmloader/util.c | 4 ++-- tools/firmware/hvmloader/util.h | 4 ++-- tools/libacpi/Makefile | 10 ++++----- tools/libacpi/dsdt.asl | 25 ++++----------------- tools/libacpi/dsdt_i440.asl | 36 ++++++++++++++++++++++++++++++ 8 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 tools/libacpi/dsdt_i440.asltools/firmware/hvmloader/Makefile +1
-1@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o $(ACPI_OBJS): CFLAGS += -iquote . -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\" CFLAGS += -I$(ACPI_PATH)tools/firmware/hvmloader/ovmf.c +2
-2@@ -119,8 +119,8 @@ static void ovmf_load(const struct bios_config *config,static void ovmf_acpi_build_tables (void ) {struct acpi_config config = { - .dsdt_anycpu = dsdt_anycpu_qemu_xen, - .dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len, + .dsdt_anycpu = dsdt_i440_anycpu_qemu_xen, + .dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len, .dsdt_15cpu =NULL , .dsdt_15cpu_len =0 };tools/firmware/hvmloader/seabios.c +2
-2@@ -90,8 +90,8 @@ static void seabios_acpi_build_tables(void) {uint32_t rsdp = (uint32_t )scratch_alloc (sizeof (struct acpi_20_rsdp ),0 );struct acpi_config config = { - .dsdt_anycpu = dsdt_anycpu_qemu_xen, - .dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len, + .dsdt_anycpu = dsdt_i440_anycpu_qemu_xen, + .dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len, .dsdt_15cpu =NULL , .dsdt_15cpu_len =0 , };tools/firmware/hvmloader/util.c +2
-2@@ -843,8 +843,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, s =xenstore_read ("platform/device-model" ,"" );if ( !strncmp (s,"qemu_xen" ,9 ) ) { - config->dsdt_anycpu = dsdt_anycpu_qemu_xen; - config->dsdt_anycpu_len = dsdt_anycpu_qemu_xen_len; + config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; config->dsdt_15cpu =NULL ; config->dsdt_15cpu_len =0 ; }tools/firmware/hvmloader/util.h +0
-0@@ -381,8 +381,8 @@ extern struct e820map memory_map;bool check_overlap (uint64_t start,uint64_t size,uint64_t reserved_start,uint64_t reserved_size);
Quoted 7 lines
tools/firmware/hvmloader/util.h extern struct e820map memory_map; · line 385
Quoted 4 lines
tools/firmware/hvmloader/util.h +2
-2-extern const unsigned char dsdt_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; -extern const int dsdt_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len; +extern const unsigned char dsdt_i440_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; +extern const int dsdt_i440_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len;While there you can make this unsigned int, like the
dsdt_anycpu_lenfield.
Sure.
Quoted 73 lines
Quoted 61 lines
tools/firmware/hvmloader/util.h +0
-0unsigned long acpi_pages_allocated (void );tools/libacpi/Makefile +4
-6@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c DSDT_FILES ?= $(C_SRC-y) C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))@@ -39,18 +39,16 @@ $(H_SRC): $(ACPI_BUILD_DIR)/%.h: %.asl $(MK_DSDT): mk_dsdt.c $(HOSTCC) $(HOSTCFLAGS) $(MKDSDT_CFLAGS-y) $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -o $@ mk_dsdt.c -$(ACPI_BUILD_DIR)/dsdt_anycpu_qemu_xen.asl: dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) +$(ACPI_BUILD_DIR)/dsdt_%_anycpu_qemu_xen.asl: dsdt_%.asl dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) # Remove last bracket awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) - cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) $(MK_DSDT) --debug=$(debug) --dm-version qemu-xen >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@ # NB. awk invocation is a portable alternative to 'head -n -1' -$(ACPI_BUILD_DIR)/dsdt_%cpu.asl: dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) +$(ACPI_BUILD_DIR)/dsdt_%cpu.asl: dsdt_i440.asl dsdt.asl dsdt_acpi_info.asl $(MK_DSDT) # Remove last bracket awk 'NR > 1 {print s} {s=$$0}' $< > $@.$(TMP_SUFFIX) - cat dsdt_acpi_info.asl >> $@.$(TMP_SUFFIX) $(MK_DSDT) --debug=$(debug) --maxcpu $* >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@@@ -65,7 +63,7 @@ $(ACPI_BUILD_DIR)/dsdt_anycpu_arm.asl: $(MK_DSDT) mv -f $@.$(TMP_SUFFIX) $@ $(C_SRC): $(ACPI_BUILD_DIR)/%.c: $(ACPI_BUILD_DIR)/%.asl - $(IASL) -vs -p $(ACPI_BUILD_DIR)/$*.$(TMP_SUFFIX) -tc $< + $(IASL) -vs -I $(CURDIR) -p $(ACPI_BUILD_DIR)/$*.$(TMP_SUFFIX) -tc $< sed -e 's/AmlCode/$*/g' -e 's/_aml_code//g' $(ACPI_BUILD_DIR)/$*.hex > $@.$(TMP_SUFFIX) echo "int $*_len=sizeof($*);" >> $@.$(TMP_SUFFIX) mv -f $@.$(TMP_SUFFIX) $@tools/libacpi/dsdt.asl +0
-2@@ -5,8 +5,6 @@ * Copyright (c) 2004, Intel Corporation. */ -DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) -{ Name (\PMBS, 0x0C00) Name (\PMLN, 0x08) Name (\IOB1, 0x00)tools/libacpi/dsdt.asl DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) · line 203
Quoted 8 lines
tools/libacpi/dsdt.asl +4
-1@@ -199,7 +197,10 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) Device (ISA) { - Name (_ADR, 0x00010000) /* device 1, fn 0 */ + /* Error will be raised if the machine type is not defined */ + #ifdef MACHINE_TYPE_I440 + Name (_ADR, 0x00010000) /* device 1, fn 0 */ + #endifI think we want the preprocessor directives not indented the same as asl code, like we do in C, iow:
Quoted 8 lines
Device (ISA) { /* Error will be raised if the machine type is not defined */ #ifdef MACHINE_TYPE_I440 Name (_ADR, 0x00010000) /* device 1, fn 0 */#endif
Same with the includes and defines below.
Will do.
Quoted 21 lines
Quoted 21 lines
tools/libacpi/dsdt.asl +0
-13OperationRegion(PIRQ, PCI_Config, 0x60, 0x4) Scope(\) {@@ -329,23 +330,6 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) }) } - Device (FDC0) - { - Name (_HID, EisaId ("PNP0700")) - Method (_STA, 0, NotSerialized) - { - Return (0x0F) - } - - Name (_CRS, ResourceTemplate () - { - IO (Decode16, 0x03F0, 0x03F0, 0x01, 0x06) - IO (Decode16, 0x03F7, 0x03F7, 0x01, 0x01) - IRQNoFlags () {6}
Quoted 8 lines
tools/libacpi/dsdt.asl DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) · line 347
Quoted 3 lines
tools/libacpi/dsdt.asl +0
-3- DMA (Compatibility, NotBusMaster, Transfer8) {2} - }) - }I need to look at the Q35 changes, but ff the only differences are the
Name()method at the top and this, we might as well use an #ifdef here, and there's no need to split into so many separate files? I need to look at further patches.
Since the changes are not that big I can indeed use #ifdef within dstd.asl directly and avoid the split. There would be specific files declaring the machine type and I can keep the current concatenation mecanism.
Quoted 23 lines
The ACPI table generation stuff could certainly do with an overall rework.
Quoted 19 lines
tools/libacpi/dsdt.asl +0
-1Device (UAR1) { Name (_HID, EisaId ("PNP0501"))@@ -444,4 +428,3 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) Method(_PIC, 1) { Store(Arg0, PICD) } -}tools/libacpi/dsdt_i440.asl new file +5
-0@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/****************************************************************************** + * DSDT for Xen with Qemu device model (for i440 machine) + * + * Copyright (c) 2004, Intel Corporation.
Quoted 8 lines
tools/libacpi/dsdt_i440.asl line 10
Quoted 5 lines
tools/libacpi/dsdt_i440.asl new file +5
-0+ */ + +DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) +{ + #define MACHINE_TYPE_I440IMO we probably want to define this outside of the DefinitionBlock section, just after the copyright header.
Yes, I'll define that in dsdt_i440.asl and dsdt_q35.asl along with the isa device sbdf.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 01/17] libacpi: Split dsdt.asl file and extract i440 specific parts
In reply to Thierry Escandetools/firmware/hvmloader/Makefile rombios.o: roms.inc · line 81
Quoted 8 lines · Thierry Escande
tools/firmware/hvmloader/Makefile +1
-1@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c
Instead of merely adding the i440 infix, could we perhaps replace the anycpu one (which doesn't serve any purpose here anymore, afaics)?
Jan
Re: [PATCH 01/17] libacpi: Split dsdt.asl file and extract i440 specific parts
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Thierry Escande
tools/firmware/hvmloader/Makefile +0
-0@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\""
Quoted 6 lines
tools/firmware/hvmloader/Makefile rombios.o: roms.inc · line 81
Quoted 3 lines
tools/firmware/hvmloader/Makefile +1
-1ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.cInstead of merely adding the i440 infix, could we perhaps replace the anycpu one (which doesn't serve any purpose here anymore, afaics)?
Thinking about it, qemu and xen perhaps fall into the same category, and could perhaps also be dropped.
Jan
Re: [PATCH 01/17] libacpi: Split dsdt.asl file and extract i440 specific parts
Quoted 14 lines · Jan Beulich
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Thierry Escande
tools/firmware/hvmloader/Makefile +0
-0@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\""Quoted 6 lines
tools/firmware/hvmloader/Makefile rombios.o: roms.inc · line 81
Quoted 3 lines
tools/firmware/hvmloader/Makefile +1
-1ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.cInstead of merely adding the i440 infix, could we perhaps replace the anycpu one (which doesn't serve any purpose here anymore, afaics)?
Quoted 2 lines
Thinking about it, qemu and xen perhaps fall into the same category, and could perhaps also be dropped.
I'll do this in a separate patchset if that's ok.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 2/17 libacpi: new DSDT ACPI table for Q35
In reply to Thierry EscandeThis patch adds the DSDT table for Q35 (new tools/libacpi/dsdt_q35.asl file). It only contains the specific Q35 parts that differ from i440). At the moment, these are:
- BDF location of LPC Controller
- Minor changes related to FDC detection
- Addition of _OSC method to inform OSPM about PCIe features supported
As we are still using 4 PCI router links and their corresponding device/register addresses are same (offset 0x60), no need to change PCI routing descriptions.
Note that '15cpu' ACPI tables are only applicable to qemu-traditional (which have no support for Q35), so we need to use 'anycpu' version only.
--- tools/firmware/hvmloader/Makefile | 2 +- tools/libacpi/Makefile | 2 +- tools/libacpi/dsdt.asl | 3 + tools/libacpi/dsdt_q35.asl | 130 ++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tools/libacpi/dsdt_q35.asl
tools/firmware/hvmloader/Makefile +1 -1
@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o $(ACPI_OBJS): CFLAGS += -iquote . -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\" CFLAGS += -I$(ACPI_PATH)
tools/libacpi/Makefile +1 -1
@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c dsdt_pvh.c C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c DSDT_FILES ?= $(C_SRC-y) C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))
tools/libacpi/dsdt.asl +3 -0
@@ -201,6 +201,9 @@ #ifdef MACHINE_TYPE_I440 Name (_ADR, 0x00010000) /* device 1, fn 0 */ #endif + #ifdef MACHINE_TYPE_Q35 + Name (_ADR, 0x001f0000) /* device 31, fn 0 */ + #endif OperationRegion(PIRQ, PCI_Config, 0x60, 0x4) Scope(\) {
tools/libacpi/dsdt_q35.asl new file +130 -0
130 lines not on this page · raw message
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 02/17] libacpi: new DSDT ACPI table for Q35
Quoted 8 lines · Thierry Escande
This patch adds the DSDT table for Q35 (new
tools/libacpi/dsdt_q35.aslfile). It only contains the specific Q35 parts that differ from i440). At the moment, these are:- BDF location of LPC Controller
- Minor changes related to FDC detection
- Addition of_OSCmethod to inform OSPM about PCIe features supported
Quoted 6 lines
As we are still using 4 PCI router links and their corresponding device/register addresses are same (offset
0x60), no need to change PCI routing descriptions.Note that '15cpu' ACPI tables are only applicable to qemu-traditional (which have no support for Q35), so we need to use 'anycpu' version only.
Is the above statement fully accurate? It seems like 15cpu tables are used with rombios, so the dependency is not on qemu-trad, but rather rombios?
If it's truly only dependent on qemu-trad then we should remove those, as we have removed qemu-trad.
Quoted 2 lines
Signed-off-by Alexey Gerasimenko <[email protected]>
If the first SoB if from Alexey, the From: should also match.
Quoted 40 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/Makefile | 2 +- tools/libacpi/Makefile | 2 +- tools/libacpi/dsdt.asl | 3 + tools/libacpi/dsdt_q35.asl | 130 ++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tools/libacpi/dsdt_q35.asltools/firmware/hvmloader/Makefile +1
-1@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o $(ACPI_OBJS): CFLAGS += -iquote . -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\" CFLAGS += -I$(ACPI_PATH)tools/libacpi/Makefile +1
-1@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c dsdt_pvh.c C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c DSDT_FILES ?= $(C_SRC-y) C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))tools/libacpi/dsdt.asl +0
-0
tools/libacpi/dsdt.asl line 206
Quoted 6 lines
tools/libacpi/dsdt.asl +3
-0@@ -201,6 +201,9 @@ #ifdef MACHINE_TYPE_I440 Name (_ADR, 0x00010000) /* device 1, fn 0 */ #endif + #ifdef MACHINE_TYPE_Q35 + Name (_ADR, 0x001f0000) /* device 31, fn 0 */ + #endif
You possibly want to do:
#ifdef ...
#elif defined(...)
#else
#error ...
#endif
But seeing the difference is only for the address, why not do:
#define ISA_DEV_SBDF 0x00010000
...
Name (_ADR, ISA_DEV_SBDF)
...
And avoid the ifdef mess?
Quoted 21 lines
tools/libacpi/dsdt.asl +0
-0OperationRegion(PIRQ, PCI_Config, 0x60, 0x4) Scope(\) {tools/libacpi/dsdt_q35.asl new file +12
-0@@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/****************************************************************************** + * DSDT for Xen with Qemu device model (for Q35 machine) + */ + +DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) +{ + #define MACHINE_TYPE_Q35 + + #include "dsdt.asl" + + Scope (\_SB.PCI0)
tools/libacpi/dsdt_q35.asl line 22
Quoted 10 lines
tools/libacpi/dsdt_q35.asl new file +10
-0+ { + /* _OSC, modified from ASL sample in ACPI spec */ + Name (SUPP, 0) /* PCI _OSC Support Field value */ + Name (CTRL, 0) /* PCI _OSC Control Field value */ + Method (_OSC, 4) { + /* Create DWORD-addressable fields from the Capabilities Buffer */ + CreateDWordField (Arg3, 0, CDW1) + + /* Switch by UUID. + * Only PCI Host Bridge Device capabilities UUID used for now
Comment style, in Xen we use:
/*
* Switch by UIID.
* Only PCI Host Bridge Device capabilities UUID used for now. */
The opening and closing lines are standalone. Also missing a full stop on the last line. The rest of the comments below also need adjusting.
Quoted 29 lines
tools/libacpi/dsdt_q35.asl new file +29
-0+ */ + If (LEqual (Arg0, ToUUID ("33DB4D5B-1FF7-401C-9657-7441C03DD766"))) { + /* Create DWORD-addressable fields from the Capabilities Buffer */ + CreateDWordField (Arg3, 4, CDW2) + CreateDWordField (Arg3, 8, CDW3) + + /* Save Capabilities DWORD2 & 3 */ + Store (CDW2, SUPP) + Store (CDW3, CTRL) + + /* Validate Revision DWORD */ + If (LNotEqual (Arg1, One)) { + /* Unknown revision */ + /* Support and Control DWORDs will be returned anyway */ + Or (CDW1, 0x08, CDW1) + } + + /* Control field bits are: + * bit 0 PCI Express Native Hot Plug control + * bit 1 SHPC Native Hot Plug control + * bit 2 PCI Express Native Power Management Events control + * bit 3 PCI Express Advanced Error Reporting control + * bit 4 PCI Express Capability Structure control + */ + + /* Always allow native PME, AER (no dependencies) + * Never allow SHPC (no SHPC controller in this system) + * Do not allow PCIe Capability Structure control for now + * Also, ACPI hotplug is used for now instead of PCIe
tools/libacpi/dsdt_q35.asl line 61
Quoted 10 lines
tools/libacpi/dsdt_q35.asl new file +10
-0+ * Native Hot Plug + */ + And (CTRL, 0x0C, CTRL) + + If (LNotEqual (CDW3, CTRL)) { + /* Some of Capabilities bits were masked */ + Or (CDW1, 0x10, CDW1) + } + /* Update DWORD3 in the buffer */ + Store (CTRL, CDW3)
This looks equal to the QEMU code FWIW.
tools/libacpi/dsdt_q35.asl line 72
Quoted 11 lines
tools/libacpi/dsdt_q35.asl new file +11
-0+ } Else { + Or (CDW1, 4, CDW1) /* Unrecognized UUID */ + } + Return (Arg3) + } + /* end of _OSC */ + } + + /**************************************************************** + * LPC ISA bridge + ****************************************************************/
I would use a normal one-line comment here: /* LPCI ISA Bridge */
Has any of this been picked up from the QEMU asl files? Asking because the above comment looks to be verbatim copied from the QEMU file, and we then need to carry their copyright notice, which is not done in this patch.
tools/libacpi/dsdt_q35.asl line 74
Quoted 2 lines
tools/libacpi/dsdt_q35.asl new file +2
-0+ + Scope (\_SB.PCI0.ISA)
AFAICT this is adding more content to the ISA device already defined in dsdt.asl?
tools/libacpi/dsdt_q35.asl line 82
Quoted 8 lines
tools/libacpi/dsdt_q35.asl new file +8
-0+ { + /* + LPC ISA bridge + + PCI Interrupt Routing Register 2 (PIRQE..PIRQH) cannot be + used because of existing Xen IRQ limitations (4 PCI links + only) + */
Right, and PIRQA..PIRQD is already defined in the generic dsdt.asl. Might be worth mentioning, otherwise the block looks incomplete.
Quoted 35 lines
tools/libacpi/dsdt_q35.asl new file +35
-0+ + /* LPC_I/O: I/O Decode Ranges Register */ + OperationRegion (LPCD, PCI_Config, 0x80, 0x2) + Field (LPCD, AnyAcc, NoLock, Preserve) { + COMA, 3, + , 1, + COMB, 3, + + Offset(0x01), + LPTD, 2, + , 2, + FDCD, 2 + } + + /* LPC_EN: LPC I/F Enables Register */ + OperationRegion(LPCE, PCI_Config, 0x82, 0x2) + Field(LPCE, AnyAcc, NoLock, Preserve) { + CAEN, 1, + CBEN, 1, + LPEN, 1, + FDEN, 1 + } + + Device (FDC0) + { + Name (_HID, EisaId ("PNP0700")) + Method (_STA, 0, NotSerialized) + { + Store (FDEN, Local0) + If (LEqual (Local0, 0)) { + Return (0x00) + } Else { + Return (0x0F) + } + }
tools/libacpi/dsdt_q35.asl line 127
Quoted 10 lines
tools/libacpi/dsdt_q35.asl new file +10
-0+ + Name (_CRS, ResourceTemplate () + { + IO (Decode16, 0x03F2, 0x03F2, 0x00, 0x04) + IO (Decode16, 0x03F7, 0x03F7, 0x00, 0x01) + IRQNoFlags () {6} + DMA (Compatibility, NotBusMaster, Transfer8) {2} + }) + } + }
This seem to match the blocks in QEMU, so it's likely fine.
Thanks, Roger.
Re: [PATCH 02/17] libacpi: new DSDT ACPI table for Q35
Quoted 16 lines · Roger Pau Monné
Quoted 8 lines · Thierry Escande
This patch adds the DSDT table for Q35 (new
tools/libacpi/dsdt_q35.aslfile). It only contains the specific Q35 parts that differ from i440). At the moment, these are:- BDF location of LPC Controller
- Minor changes related to FDC detection
- Addition of_OSCmethod to inform OSPM about PCIe features supportedQuoted 6 lines
As we are still using 4 PCI router links and their corresponding device/register addresses are same (offset
0x60), no need to change PCI routing descriptions.Note that '15cpu' ACPI tables are only applicable to qemu-traditional (which have no support for Q35), so we need to use 'anycpu' version only.
Quoted 6 lines
Is the above statement fully accurate? It seems like 15cpu tables are used with rombios, so the dependency is not on qemu-trad, but rather rombios?
If it's truly only dependent on qemu-trad then we should remove those, as we have removed qemu-trad.
You're right, the dependency is on Rombios. And I though Rombios was only used for qemu-trad, my bad. So it implies to use Seabios or OVMF to have Q35 support. Is it something acceptable?
Quoted 5 lines
Quoted 3 lines
Signed-off-by Alexey Gerasimenko <[email protected]>If the first SoB if from Alexey, the From: should also match.
Ok, I'll change authorship or signed-off order depending on how close it is from the original patch.
Quoted 50 lines
Quoted 41 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/Makefile | 2 +- tools/libacpi/Makefile | 2 +- tools/libacpi/dsdt.asl | 3 + tools/libacpi/dsdt_q35.asl | 130 ++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tools/libacpi/dsdt_q35.asltools/firmware/hvmloader/Makefile +1
-1@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o $(ACPI_OBJS): CFLAGS += -iquote . -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\" CFLAGS += -I$(ACPI_PATH)tools/libacpi/Makefile +1
-1@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c dsdt_pvh.c C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c DSDT_FILES ?= $(C_SRC-y) C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))tools/libacpi/dsdt.asl +0
-0tools/libacpi/dsdt.asl line 206
Quoted 6 lines
tools/libacpi/dsdt.asl +3
-0@@ -201,6 +201,9 @@ #ifdef MACHINE_TYPE_I440 Name (_ADR, 0x00010000) /* device 1, fn 0 */ #endif + #ifdef MACHINE_TYPE_Q35 + Name (_ADR, 0x001f0000) /* device 31, fn 0 */ + #endifYou possibly want to do:
Quoted 5 lines
#ifdef ...
#elif defined(...)
#else
#error ...
#endif
Well, the iasl compiler doesn't support the defined() directive (at least the latest Debian version from 2025) so I'll rather use something like:
#define MACHINE_TYPE MACHINE_TYPE_XXX
#if MACHINE_TYPE == MACHINE_TYPE_XXX
...
#elif MACHINE_TYPE == MACHINE_TYPE_YYY
...
#endif
Quoted 9 lines
But seeing the difference is only for the address, why not do:
#define
ISA_DEV_SBDF0x00010000
...
Name (_ADR,ISA_DEV_SBDF)
...And avoid the ifdef mess?
Yes, sure.
Quoted 35 lines
Quoted 22 lines
tools/libacpi/dsdt.asl +0
-0OperationRegion(PIRQ, PCI_Config, 0x60, 0x4) Scope(\) {tools/libacpi/dsdt_q35.asl new file +12
-0@@ -0,0 +1,130 @@ +/* SPDX-License-Identifier: LGPL-2.1-only */ +/****************************************************************************** + * DSDT for Xen with Qemu device model (for Q35 machine) + */ + +DefinitionBlock ("DSDT.aml", "DSDT", 2, "Xen", "HVM", 0) +{ + #define MACHINE_TYPE_Q35 + + #include "dsdt.asl" + + Scope (\_SB.PCI0)tools/libacpi/dsdt_q35.asl line 22
Quoted 10 lines
tools/libacpi/dsdt_q35.asl new file +10
-0+ { + /* _OSC, modified from ASL sample in ACPI spec */ + Name (SUPP, 0) /* PCI _OSC Support Field value */ + Name (CTRL, 0) /* PCI _OSC Control Field value */ + Method (_OSC, 4) { + /* Create DWORD-addressable fields from the Capabilities Buffer */ + CreateDWordField (Arg3, 0, CDW1) + + /* Switch by UUID. + * Only PCI Host Bridge Device capabilities UUID used for nowComment style, in Xen we use:
Quoted 8 lines
/*
* Switch by UIID.
* Only PCI Host Bridge Device capabilities UUID used for now. */The opening and closing lines are standalone. Also missing a full stop on the last line. The rest of the comments below also need adjusting.
Will fix that.
Quoted 61 lines
Quoted 29 lines
Quoted 1 line
+ */
tools/libacpi/dsdt_q35.asl new file +28
-0+ If (LEqual (Arg0, ToUUID ("33DB4D5B-1FF7-401C-9657-7441C03DD766"))) { + /* Create DWORD-addressable fields from the Capabilities Buffer */ + CreateDWordField (Arg3, 4, CDW2) + CreateDWordField (Arg3, 8, CDW3) + + /* Save Capabilities DWORD2 & 3 */ + Store (CDW2, SUPP) + Store (CDW3, CTRL) + + /* Validate Revision DWORD */ + If (LNotEqual (Arg1, One)) { + /* Unknown revision */ + /* Support and Control DWORDs will be returned anyway */ + Or (CDW1, 0x08, CDW1) + } + + /* Control field bits are: + * bit 0 PCI Express Native Hot Plug control + * bit 1 SHPC Native Hot Plug control + * bit 2 PCI Express Native Power Management Events control + * bit 3 PCI Express Advanced Error Reporting control + * bit 4 PCI Express Capability Structure control + */ + + /* Always allow native PME, AER (no dependencies) + * Never allow SHPC (no SHPC controller in this system) + * Do not allow PCIe Capability Structure control for now + * Also, ACPI hotplug is used for now instead of PCIetools/libacpi/dsdt_q35.asl line 61
Quoted 10 lines
tools/libacpi/dsdt_q35.asl new file +10
-0+ * Native Hot Plug + */ + And (CTRL, 0x0C, CTRL) + + If (LNotEqual (CDW3, CTRL)) { + /* Some of Capabilities bits were masked */ + Or (CDW1, 0x10, CDW1) + } + /* Update DWORD3 in the buffer */ + Store (CTRL, CDW3)This looks equal to the QEMU code FWIW.
tools/libacpi/dsdt_q35.asl line 72
Quoted 11 lines
tools/libacpi/dsdt_q35.asl new file +11
-0+ } Else { + Or (CDW1, 4, CDW1) /* Unrecognized UUID */ + } + Return (Arg3) + } + /* end of _OSC */ + } + + /**************************************************************** + * LPC ISA bridge + ****************************************************************/I would use a normal one-line comment here: /* LPCI ISA Bridge */
Has any of this been picked up from the QEMU asl files? Asking because the above comment looks to be verbatim copied from the QEMU file, and we then need to carry their copyright notice, which is not done in this patch.
Quoted 5 lines
tools/libacpi/dsdt_q35.asl
Quoted 2 lines
tools/libacpi/dsdt_q35.asl new file +2
-0+ + Scope (\_SB.PCI0.ISA)AFAICT this is adding more content to the ISA device already defined in dsdt.asl?
AFAIU, yes that's the goal. Since I'll revert the split and use #ifdef directives in dsdt.asl this will be removed.
Quoted 52 lines
tools/libacpi/dsdt_q35.asl line 82
Quoted 9 lines
tools/libacpi/dsdt_q35.asl new file +8
-0+ { + /* + LPC ISA bridge + + PCI Interrupt Routing Register 2 (PIRQE..PIRQH) cannot be + used because of existing Xen IRQ limitations (4 PCI links + only) + */Right, and PIRQA..PIRQD is already defined in the generic dsdt.asl. Might be worth mentioning, otherwise the block looks incomplete.
Quoted 39 lines
tools/libacpi/dsdt_q35.asl new file +39
-0+ + /* LPC_I/O: I/O Decode Ranges Register */ + OperationRegion (LPCD, PCI_Config, 0x80, 0x2) + Field (LPCD, AnyAcc, NoLock, Preserve) { + COMA, 3, + , 1, + COMB, 3, + + Offset(0x01), + LPTD, 2, + , 2, + FDCD, 2 + } + + /* LPC_EN: LPC I/F Enables Register */ + OperationRegion(LPCE, PCI_Config, 0x82, 0x2) + Field(LPCE, AnyAcc, NoLock, Preserve) { + CAEN, 1, + CBEN, 1, + LPEN, 1, + FDEN, 1 + } + + Device (FDC0) + { + Name (_HID, EisaId ("PNP0700")) + Method (_STA, 0, NotSerialized) + { + Store (FDEN, Local0) + If (LEqual (Local0, 0)) { + Return (0x00) + } Else { + Return (0x0F) + } + } + + Name (_CRS, ResourceTemplate () + { + IO (Decode16, 0x03F2, 0x03F2, 0x00, 0x04)
Quoted 8 lines
tools/libacpi/dsdt_q35.asl line 127
Quoted 6 lines
tools/libacpi/dsdt_q35.asl new file +6
-0+ IO (Decode16, 0x03F7, 0x03F7, 0x00, 0x01) + IRQNoFlags () {6} + DMA (Compatibility, NotBusMaster, Transfer8) {2} + }) + } + }This seem to match the blocks in QEMU, so it's likely fine.
I'll add qemu copyright header
Would that be ok under the original copyright notice ? /******************************************************************
* Q35 part heavily inspired by q35-acpi-dsdt.dsl from Qemu *
* Copyright (c) 2010 Isaku Yamahata
* yamahata at valinux co jp
*/
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 02/17] libacpi: new DSDT ACPI table for Q35
Quoted 22 lines · Thierry Escande
Quoted 20 lines · Roger Pau Monné
Quoted 8 lines · Thierry Escande
This patch adds the DSDT table for Q35 (new
tools/libacpi/dsdt_q35.aslfile). It only contains the specific Q35 parts that differ from i440). At the moment, these are:- BDF location of LPC Controller
- Minor changes related to FDC detection
- Addition of_OSCmethod to inform OSPM about PCIe features supportedQuoted 6 lines
As we are still using 4 PCI router links and their corresponding device/register addresses are same (offset
0x60), no need to change PCI routing descriptions.Note that '15cpu' ACPI tables are only applicable to qemu-traditional (which have no support for Q35), so we need to use 'anycpu' version only.
Is the above statement fully accurate? It seems like 15cpu tables are used with rombios, so the dependency is not on qemu-trad, but rather rombios?
Quoted 6 lines
Quoted 2 lines
If it's truly only dependent on qemu-trad then we should remove those, as we have removed qemu-trad.
You're right, the dependency is on Rombios. And I though Rombios was only used for qemu-trad, my bad. So it implies to use Seabios or OVMF to have Q35 support. Is it something acceptable?
IIRC XenServer still uses RomBIOS with upstream QEMU, for compatibility purposes. I'm fine with just adding Q35 support with SeaBIOS and OVMF, it seems justified to request a newer firmware if you want to use a newer chipset.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Signed-off-by Alexey Gerasimenko <[email protected]>If the first SoB if from Alexey, the From: should also match.
Ok, I'll change authorship or signed-off order depending on how close it is from the original patch.
I'm not an expert, but I think as long as it's based on a patch from Alexey you need to keep is SoB first.
Quoted 60 lines
Quoted 50 lines
Quoted 41 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/Makefile | 2 +- tools/libacpi/Makefile | 2 +- tools/libacpi/dsdt.asl | 3 + tools/libacpi/dsdt_q35.asl | 130 ++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tools/libacpi/dsdt_q35.asltools/firmware/hvmloader/Makefile +1
-1@@ -78,7 +78,7 @@ rombios.o: roms.inc smbios.o: CFLAGS += -D__SMBIOS_DATE__="\"$(SMBIOS_REL_DATE)\"" ACPI_PATH = ../../libacpi -DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c +DSDT_FILES += dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES)) build.o static_tables.o $(ACPI_OBJS): CFLAGS += -iquote . -DLIBACPI_STDUTILS=\"$(CURDIR)/util.h\" CFLAGS += -I$(ACPI_PATH)tools/libacpi/Makefile +1
-1@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c dsdt_pvh.c C_SRC-$(CONFIG_ARM_64) = dsdt_anycpu_arm.c DSDT_FILES ?= $(C_SRC-y) C_SRC = $(addprefix $(ACPI_BUILD_DIR)/, $(DSDT_FILES))tools/libacpi/dsdt.asl +0
-0tools/libacpi/dsdt.asl line 206
Quoted 6 lines
tools/libacpi/dsdt.asl +3
-0@@ -201,6 +201,9 @@ #ifdef MACHINE_TYPE_I440 Name (_ADR, 0x00010000) /* device 1, fn 0 */ #endif + #ifdef MACHINE_TYPE_Q35 + Name (_ADR, 0x001f0000) /* device 31, fn 0 */ + #endifYou possibly want to do:
Quoted 5 lines
#ifdef ...
#elif defined(...)
#else
#error ...
#endifWell, the iasl compiler doesn't support the
defined()directive (at least the latest Debian version from 2025) so I'll rather use something like:
Quoted 7 lines
#define
MACHINE_TYPEMACHINE_TYPE_XXX#if
MACHINE_TYPE==MACHINE_TYPE_XXX
...
#elifMACHINE_TYPE==MACHINE_TYPE_YYY
...
#endif
Oh, I see, I wasn't aware of it not supporting defined() when #ifdef is available. Kind of weird to support one but not the other.
Quoted 72 lines
Quoted 52 lines
tools/libacpi/dsdt.asl
Quoted 9 lines
tools/libacpi/dsdt.asl +8
-0+ { + /* + LPC ISA bridge + + PCI Interrupt Routing Register 2 (PIRQE..PIRQH) cannot be + used because of existing Xen IRQ limitations (4 PCI links + only) + */Right, and PIRQA..PIRQD is already defined in the generic dsdt.asl. Might be worth mentioning, otherwise the block looks incomplete.
Quoted 39 lines
tools/libacpi/dsdt.asl +39
-0+ + /* LPC_I/O: I/O Decode Ranges Register */ + OperationRegion (LPCD, PCI_Config, 0x80, 0x2) + Field (LPCD, AnyAcc, NoLock, Preserve) { + COMA, 3, + , 1, + COMB, 3, + + Offset(0x01), + LPTD, 2, + , 2, + FDCD, 2 + } + + /* LPC_EN: LPC I/F Enables Register */ + OperationRegion(LPCE, PCI_Config, 0x82, 0x2) + Field(LPCE, AnyAcc, NoLock, Preserve) { + CAEN, 1, + CBEN, 1, + LPEN, 1, + FDEN, 1 + } + + Device (FDC0) + { + Name (_HID, EisaId ("PNP0700")) + Method (_STA, 0, NotSerialized) + { + Store (FDEN, Local0) + If (LEqual (Local0, 0)) { + Return (0x00) + } Else { + Return (0x0F) + } + } + + Name (_CRS, ResourceTemplate () + { + IO (Decode16, 0x03F2, 0x03F2, 0x00, 0x04)Quoted 8 lines
tools/libacpi/dsdt.asl
Quoted 6 lines
tools/libacpi/dsdt.asl +6
-0+ IO (Decode16, 0x03F7, 0x03F7, 0x00, 0x01) + IRQNoFlags () {6} + DMA (Compatibility, NotBusMaster, Transfer8) {2} + }) + } + }This seem to match the blocks in QEMU, so it's likely fine.
I'll add qemu copyright header
Would that be ok under the original copyright notice ? /******************************************************************
* Q35 part heavily inspired by q35-acpi-dsdt.dsl from Qemu *
* Copyright (c) 2010 Isaku Yamahata
* yamahata at valinux co jp
*/
Quoted 1 line
Regards,
Seems fine.
Thanks, Roger.
Re: [PATCH 02/17] libacpi: new DSDT ACPI table for Q35
Quoted 10 lines · Roger Pau Monné
Quoted 9 lines · Thierry Escande
On 4/28/26 12:17, Roger Pau Monné wrote:
Well, the iasl compiler doesn't support the
defined()directive (at least the latest Debian version from 2025) so I'll rather use something like:#define
MACHINE_TYPEMACHINE_TYPE_XXX
Quoted 9 lines
Quoted 5 lines
#if
MACHINE_TYPE==MACHINE_TYPE_XXX
...
#elifMACHINE_TYPE==MACHINE_TYPE_YYY
...
#endifOh, I see, I wasn't aware of it not supporting
defined()when #ifdef is available. Kind of weird to support one but not the other.
And there's more fun: The iasl compiler complains about multiline comments when enclosed within #if #endif directives. Sometimes it's a warning about nested comments, sometimes it produces errors.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 02/17] libacpi: new DSDT ACPI table for Q35
In reply to Thierry Escandetools/libacpi/Makefile endif · line 14
Quoted 8 lines · Thierry Escande
tools/libacpi/Makefile +1
-1@@ -11,7 +11,7 @@ endif MK_DSDT = $(ACPI_BUILD_DIR)/mk_dsdt -C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_pvh.c +C_SRC-$(CONFIG_X86) = dsdt_anycpu.c dsdt_15cpu.c dsdt_i440_anycpu_qemu_xen.c dsdt_q35_anycpu_qemu_xen.c dsdt_pvh.c
This line's now definitely getting too long. Maybe with the suggested name change (see patch 1, to be extended to here) it would remain tolerable as a single line. Otherwise it wants splitting.
Jan
PATCH 3/17 hvmloader: add function to set the emulated machine type (i440/Q35)
In reply to Thierry EscandeThis adds a new function init_pc_machine_type() which allows to determine and set the emulated chipset type. Possible values are MACHINE_TYPE_I440 and MACHINE_TYPE_Q35 and stored in the global variable machine_type.
The machine_type variable will be used from multiple places in following commits.
--- tools/firmware/hvmloader/hvmloader.c | 2 ++ tools/firmware/hvmloader/pci_regs.h | 4 +++ tools/firmware/hvmloader/util.c | 42 ++++++++++++++++++++++++++++ tools/firmware/hvmloader/util.h | 11 ++++++++ 4 files changed, 59 insertions(+)
tools/firmware/hvmloader/hvmloader.c +2 -0
@@ -332,6 +332,8 @@ int main(void)init_hypercalls (); +init_pc_machine_type (); +memory_map_setup ();xenbus_setup ();
tools/firmware/hvmloader/pci_regs.h +4 -0
@@ -107,6 +107,10 @@#define PCI_INTEL_OPREGION 0xfc/* 4 bits */ +#define PCI_VENDOR_ID_INTEL 0x8086 +#define PCI_DEVICE_ID_INTEL_82441 0x1237 +#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0 +#endif /* __HVMLOADER_PCI_REGS_H__ */ /*
tools/firmware/hvmloader/util.c +42 -0
54 lines not on this page · raw message
tools/firmware/hvmloader/util.h +11 -0
@@ -170,6 +170,17 @@ void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val);#define pci_writew (devfn, reg, val) pci_write(devfn, reg, 2, (uint16_t)(val))#define pci_writel (devfn, reg, val) pci_write(devfn, reg, 4, (uint32_t)(val)) +/* Emulated machine types */ +typedef enum { +MACHINE_TYPE_UNDEFINED =0 , +MACHINE_TYPE_I440 , +MACHINE_TYPE_Q35 , +}machine_type_t ; + +extern machine_type_t machine_type; + +void init_pc_machine_type (void ); +/* Get a pointer to the shared-info page */ struct shared_info *get_shared_info (void ) __attribute__ ((const));
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)
Quoted 7 lines · Thierry Escande
This adds a new function
init_pc_machine_type()which allows to determine and set the emulated chipset type. Possible values areMACHINE_TYPE_I440andMACHINE_TYPE_Q35and stored in the global variablemachine_type.The
machine_typevariable will be used from multiple places in following commits.
Is this initialization something that OVMF or SeaBIOS also does? (maybe not for Xen ATM)
Asking myself because as said earlier we want to possibly get rid of hvmloader, plus we will want ECAM support in PVH at some point.
Quoted 1 line
Signed-off-by Alexey Gerasimenko <[email protected]>
Same as previous patch, if the first SoB is from Alexey the From:
(patch author) should also match.
Quoted 26 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/hvmloader.c | 2 ++ tools/firmware/hvmloader/pci_regs.h | 4 +++ tools/firmware/hvmloader/util.c | 42 ++++++++++++++++++++++++++++ tools/firmware/hvmloader/util.h | 11 ++++++++ 4 files changed, 59 insertions(+)tools/firmware/hvmloader/hvmloader.c +2
-0@@ -332,6 +332,8 @@ int main(void)init_hypercalls (); +init_pc_machine_type (); +memory_map_setup ();xenbus_setup ();tools/firmware/hvmloader/pci_regs.h +0
-0
tools/firmware/hvmloader/pci_regs.h line 112
Quoted 6 lines
tools/firmware/hvmloader/pci_regs.h +3
-0@@ -107,6 +107,10 @@#define PCI_INTEL_OPREGION 0xfc/* 4 bits */ +#define PCI_VENDOR_ID_INTEL 0x8086 +#define PCI_DEVICE_ID_INTEL_82441 0x1237 +#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0
In Xen we have a separate file for vendor and device IDs, called pci_ids.h. Maybe it would be better to use a similar approach in hvmloader, and keep pci_regs.h only containing PCI register offsets.
Quoted 17 lines
tools/firmware/hvmloader/pci_regs.h +1
-0+#endif /* __HVMLOADER_PCI_REGS_H__ */ /* tools/firmware/hvmloader/util.c +1
-0@@ -22,6 +22,7 @@#include "hypercall.h" #include "ctype.h" #include "vnuma.h" +#include "pci_regs.h" #include <acpi2_0.h> #include <libacpi.h> #include <stdint.h>
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 654
Quoted 6 lines
tools/firmware/hvmloader/util.c +3
-0@@ -648,6 +649,47 @@ void __bug(const char *file, int line)crash (); } +machine_type_t machine_type; + +void init_pc_machine_type (void )
Since detection is done based on PCI device IDs, it might be better placed in pci.c, and so you don't need to include pci_regs.h in util.c.
Quoted 24 lines
tools/firmware/hvmloader/util.c +24
-0+{ +uint16_t vendor_id; +uint16_t device_id; + +if ( machine_type !=MACHINE_TYPE_UNDEFINED ) +return ; + + vendor_id =pci_readw (0 ,PCI_VENDOR_ID ); + device_id =pci_readw (0 ,PCI_DEVICE_ID ); + +/* only Intel platforms are emulated currently */ +if ( vendor_id !=PCI_VENDOR_ID_INTEL ) + goto error; + +switch ( device_id ) + { +case PCI_DEVICE_ID_INTEL_82441 : + machine_type =MACHINE_TYPE_I440 ; +printf ("Detected i440 chipset\n" ); +break ; + +case PCI_DEVICE_ID_INTEL_Q35_MCH : + machine_type =MACHINE_TYPE_Q35 ; +printf ("Detected Q35 chipset\n" );
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 688
Quoted 10 lines
tools/firmware/hvmloader/util.c +10
-0+break ; + +default : + goto error; + } + +return ; + +error: + printf("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n",
We don't usually use the h suffix in hex numbers in hvmloader, it's more common to prefix them with 0x, so I would recommend to use the %#06x formatter instead.
Thanks, Roger.
Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Thierry Escande
tools/firmware/hvmloader/pci_regs.h +0
-0@@ -107,6 +107,10 @@#define PCI_INTEL_OPREGION 0xfc/* 4 bits */
Quoted 7 lines
tools/firmware/hvmloader/pci_regs.h line 112
Quoted 3 lines
tools/firmware/hvmloader/pci_regs.h +3
-0+#define PCI_VENDOR_ID_INTEL 0x8086 +#define PCI_DEVICE_ID_INTEL_82441 0x1237 +#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0In Xen we have a separate file for vendor and device IDs, called
pci_ids.h. Maybe it would be better to use a similar approach in hvmloader, and keeppci_regs.honly containing PCI register offsets.
Can't hvmloader simply re-use Xen's header(s)?
Quoted 52 lines
Quoted 11 lines
tools/firmware/hvmloader/util.c +1
-0@@ -22,6 +22,7 @@#include "hypercall.h" #include "ctype.h" #include "vnuma.h" +#include "pci_regs.h" #include <acpi2_0.h> #include <libacpi.h> #include <stdint.h> tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 654
Quoted 6 lines
tools/firmware/hvmloader/util.c +3
-0@@ -648,6 +649,47 @@ void __bug(const char *file, int line)crash (); } +machine_type_t machine_type; + +void init_pc_machine_type (void )Since detection is done based on PCI device IDs, it might be better placed in
pci.c, and so you don't need to includepci_regs.hinutil.c.Quoted 30 lines
tools/firmware/hvmloader/util.c +30
-0+{ +uint16_t vendor_id; +uint16_t device_id; + +if ( machine_type !=MACHINE_TYPE_UNDEFINED ) +return ; + + vendor_id =pci_readw (0 ,PCI_VENDOR_ID ); + device_id =pci_readw (0 ,PCI_DEVICE_ID ); + +/* only Intel platforms are emulated currently */ +if ( vendor_id !=PCI_VENDOR_ID_INTEL ) + goto error; + +switch ( device_id ) + { +case PCI_DEVICE_ID_INTEL_82441 : + machine_type =MACHINE_TYPE_I440 ; +printf ("Detected i440 chipset\n" ); +break ; + +case PCI_DEVICE_ID_INTEL_Q35_MCH : + machine_type =MACHINE_TYPE_Q35 ; +printf ("Detected Q35 chipset\n" ); +break ; + +default : + goto error; + } +
Quoted 8 lines
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 688
Quoted 4 lines
tools/firmware/hvmloader/util.c +4
-0+return ; + +error: + printf("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n",We don't usually use the h suffix in hex numbers in hvmloader, it's more common to prefix them with 0x, so I would recommend to use the %#06x formatter instead.
I'd generally advise against use of # with a width specifier, as that ends up awkward for 0. That is, %#x is fine and generally to be preferred, but for a specific with it might better be 0x%0<n>x (with n=4 here). Arguably here we don't really expect either of the values to be 0, so the suggested use may indeed be okay in this case (while still introducing an example which later may be copied elsewhere without much thought).
Jan
Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)
Quoted 16 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Thierry Escande
tools/firmware/hvmloader/pci_regs.h +0
-0@@ -107,6 +107,10 @@#define PCI_INTEL_OPREGION 0xfc/* 4 bits */ Quoted 7 lines
tools/firmware/hvmloader/pci_regs.h line 112
Quoted 3 lines
tools/firmware/hvmloader/pci_regs.h +3
-0+#define PCI_VENDOR_ID_INTEL 0x8086 +#define PCI_DEVICE_ID_INTEL_82441 0x1237 +#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0In Xen we have a separate file for vendor and device IDs, called
pci_ids.h. Maybe it would be better to use a similar approach in hvmloader, and keeppci_regs.honly containing PCI register offsets.
Quoted 1 line
Can't hvmloader simply re-use Xen's header(s)?
If it's ok to add a symlink to pci_ids.h in tools/include/xen then yes.
Quoted 7 lines
Quoted 6 lines
tools/firmware/hvmloader/pci_regs.h line 114
Quoted 2 lines
tools/firmware/hvmloader/pci_regs.h +2
-0+error: + printf("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n",We don't usually use the h suffix in hex numbers in hvmloader, it's more common to prefix them with 0x, so I would recommend to use the %#06x formatter instead.
Quoted 7 lines
I'd generally advise against use of # with a width specifier, as that ends up awkward for 0. That is, %#x is fine and generally to be preferred, but for a specific with it might better be 0x%0<n>x (with n=4 here). Arguably here we don't really expect either of the values to be 0, so the suggested use may indeed be okay in this case (while still introducing an example which later may be copied elsewhere without much thought).
Indeed printf("%#08x\n", 0x1234) outputs 0x001234. so 0x%04x then.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)
In reply to Roger Pau MonnéQuoted 6 lines · Roger Pau Monné
Quoted 5 lines · Thierry Escande
This adds a new function
init_pc_machine_type()which allows to determine and set the emulated chipset type. Possible values areMACHINE_TYPE_I440andMACHINE_TYPE_Q35and stored in the global variablemachine_type.
Quoted 8 lines
Quoted 2 lines
The
machine_typevariable will be used from multiple places in following commits.Is this initialization something that OVMF or SeaBIOS also does? (maybe not for Xen ATM)
Asking myself because as said earlier we want to possibly get rid of hvmloader, plus we will want ECAM support in PVH at some point.
Possibly. There are surely overlaps in term of initialization between the toolstack, hvmloader and the firmwares but that's another story imo.
Quoted 35 lines
Quoted 2 lines
Signed-off-by Alexey Gerasimenko <[email protected]>Same as previous patch, if the first SoB is from Alexey the From:
(patch author) should also match.Quoted 29 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/hvmloader.c | 2 ++ tools/firmware/hvmloader/pci_regs.h | 4 +++ tools/firmware/hvmloader/util.c | 42 ++++++++++++++++++++++++++++ tools/firmware/hvmloader/util.h | 11 ++++++++ 4 files changed, 59 insertions(+)tools/firmware/hvmloader/hvmloader.c +2
-0@@ -332,6 +332,8 @@ int main(void)init_hypercalls (); +init_pc_machine_type (); +memory_map_setup ();xenbus_setup ();tools/firmware/hvmloader/pci_regs.h +0
-0@@ -107,6 +107,10 @@#define PCI_INTEL_OPREGION 0xfc/* 4 bits */
Quoted 7 lines
tools/firmware/hvmloader/pci_regs.h line 112
Quoted 3 lines
tools/firmware/hvmloader/pci_regs.h +3
-0+#define PCI_VENDOR_ID_INTEL 0x8086 +#define PCI_DEVICE_ID_INTEL_82441 0x1237 +#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0In Xen we have a separate file for vendor and device IDs, called
pci_ids.h. Maybe it would be better to use a similar approach in hvmloader, and keeppci_regs.honly containing PCI register offsets.
As suggested by Jan, I'll use pci_ids.h from Xen (if it's ok to add a symlink to pci_ids.h in tools/include/xen)
And is it ok to add the PCI device IDs to pci_ids.h in this commit or should it be done in a separate one ?
Quoted 21 lines
Quoted 21 lines
tools/firmware/hvmloader/pci_regs.h +1
-0+#endif /* __HVMLOADER_PCI_REGS_H__ */ /* tools/firmware/hvmloader/util.c +1
-0@@ -22,6 +22,7 @@#include "hypercall.h" #include "ctype.h" #include "vnuma.h" +#include "pci_regs.h" #include <acpi2_0.h> #include <libacpi.h> #include <stdint.h> @@ -648,6 +649,47 @@ void __bug(const char *file, int line)crash (); }
Quoted 7 lines
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 654
Quoted 3 lines
tools/firmware/hvmloader/util.c +3
-0+machine_type_t machine_type; + +void init_pc_machine_type (void )Since detection is done based on PCI device IDs, it might be better placed in
pci.c, and so you don't need to includepci_regs.hinutil.c.
Yes, that makes more sense. And I'll rename it aspci_init_machine_type() then.
Quoted 31 lines
Quoted 31 lines
tools/firmware/hvmloader/util.c +30
-0+{ +uint16_t vendor_id; +uint16_t device_id; + +if ( machine_type !=MACHINE_TYPE_UNDEFINED ) +return ; + + vendor_id =pci_readw (0 ,PCI_VENDOR_ID ); + device_id =pci_readw (0 ,PCI_DEVICE_ID ); + +/* only Intel platforms are emulated currently */ +if ( vendor_id !=PCI_VENDOR_ID_INTEL ) + goto error; + +switch ( device_id ) + { +case PCI_DEVICE_ID_INTEL_82441 : + machine_type =MACHINE_TYPE_I440 ; +printf ("Detected i440 chipset\n" ); +break ; + +case PCI_DEVICE_ID_INTEL_Q35_MCH : + machine_type =MACHINE_TYPE_Q35 ; +printf ("Detected Q35 chipset\n" ); +break ; + +default : + goto error; + } +
Quoted 8 lines
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 688
Quoted 4 lines
tools/firmware/hvmloader/util.c +4
-0+return ; + +error: + printf("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n",We don't usually use the h suffix in hex numbers in hvmloader, it's more common to prefix them with 0x, so I would recommend to use the %#06x formatter instead.
I did some tests regarding Jan comment and yes, # and width specifier seem to act weirdly. Will use 0x%0nx instead.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)
In reply to Thierry EscandeQuoted 8 lines · Thierry Escande
tools/firmware/hvmloader/util.c +4
-0@@ -648,6 +649,47 @@ void __bug(const char *file, int line)crash (); } +machine_type_t machine_type; + +void init_pc_machine_type (void ) +{
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 665
Quoted 10 lines
tools/firmware/hvmloader/util.c +10
-0+uint16_t vendor_id; +uint16_t device_id; + +if ( machine_type !=MACHINE_TYPE_UNDEFINED ) +return ; + + vendor_id =pci_readw (0 ,PCI_VENDOR_ID ); + device_id =pci_readw (0 ,PCI_DEVICE_ID ); + +/* only Intel platforms are emulated currently */
Nit: Comment style.
Quoted 12 lines
tools/firmware/hvmloader/util.c +12
-0+if ( vendor_id !=PCI_VENDOR_ID_INTEL ) + goto error; + +switch ( device_id ) + { +case PCI_DEVICE_ID_INTEL_82441 : + machine_type =MACHINE_TYPE_I440 ; +printf ("Detected i440 chipset\n" ); +break ; + +case PCI_DEVICE_ID_INTEL_Q35_MCH : + machine_type =MACHINE_TYPE_Q35 ;
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 687
Quoted 10 lines
tools/firmware/hvmloader/util.c +10
-0+printf ("Detected Q35 chipset\n" ); +break ; + +default : + goto error; + } + +return ; + +error:
Nit: Labels indented by at least one blank please.
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 690
Quoted 3 lines
tools/firmware/hvmloader/util.c +3
-0+printf ("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n" , + vendor_id, device_id); +BUG ();
Can't this be moved up into the default case, thus avoiding "goto" and label altogether?
Jan
Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Thierry Escande
tools/firmware/hvmloader/util.c +0
-0@@ -648,6 +649,47 @@ void __bug(const char *file, int line)crash (); }
Quoted 16 lines
Quoted 4 lines
tools/firmware/hvmloader/util.c +4
-0+machine_type_t machine_type; + +void init_pc_machine_type (void ) +{tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 665
Quoted 10 lines
tools/firmware/hvmloader/util.c +10
-0+uint16_t vendor_id; +uint16_t device_id; + +if ( machine_type !=MACHINE_TYPE_UNDEFINED ) +return ; + + vendor_id =pci_readw (0 ,PCI_VENDOR_ID ); + device_id =pci_readw (0 ,PCI_DEVICE_ID ); + +/* only Intel platforms are emulated currently */ Nit: Comment style.
That's for the missing capital on the first word and full stop, right?
Quoted 26 lines
Quoted 13 lines
tools/firmware/hvmloader/util.c +12
-0+if ( vendor_id !=PCI_VENDOR_ID_INTEL ) + goto error; + +switch ( device_id ) + { +case PCI_DEVICE_ID_INTEL_82441 : + machine_type =MACHINE_TYPE_I440 ; +printf ("Detected i440 chipset\n" ); +break ; + +case PCI_DEVICE_ID_INTEL_Q35_MCH : + machine_type =MACHINE_TYPE_Q35 ;tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 687
Quoted 10 lines
tools/firmware/hvmloader/util.c +10
-0+printf ("Detected Q35 chipset\n" ); +break ; + +default : + goto error; + } + +return ; + +error:Nit: Labels indented by at least one blank please.
Quoted 6 lines
tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 690
Quoted 3 lines
tools/firmware/hvmloader/util.c +3
-0+printf ("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n" , + vendor_id, device_id); +BUG ();Can't this be moved up into the default case, thus avoiding "goto" and label altogether?
There is already a goto error on the vendor ID check. That makes it more readable imo.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 03/17] hvmloader: add function to set the emulated machine type (i440/Q35)
Quoted 25 lines · Thierry Escande
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Thierry Escande
tools/firmware/hvmloader/util.c +0
-0@@ -648,6 +649,47 @@ void __bug(const char *file, int line)crash (); }Quoted 16 lines
Quoted 4 lines
tools/firmware/hvmloader/util.c +4
-0+machine_type_t machine_type; + +void init_pc_machine_type (void ) +{tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 665
Quoted 10 lines
tools/firmware/hvmloader/util.c +10
-0+uint16_t vendor_id; +uint16_t device_id; + +if ( machine_type !=MACHINE_TYPE_UNDEFINED ) +return ; + + vendor_id =pci_readw (0 ,PCI_VENDOR_ID ); + device_id =pci_readw (0 ,PCI_DEVICE_ID ); + +/* only Intel platforms are emulated currently */ Nit: Comment style.
Quoted 1 line
That's for the missing capital on the first word and full stop, right?
See ./CODING_STYLE - the full stop isn't required here, but the capital first letter indeed is.
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
tools/firmware/hvmloader/util.c +12
-0+if ( vendor_id !=PCI_VENDOR_ID_INTEL ) + goto error; + +switch ( device_id ) + { +case PCI_DEVICE_ID_INTEL_82441 : + machine_type =MACHINE_TYPE_I440 ; +printf ("Detected i440 chipset\n" ); +break ; + +case PCI_DEVICE_ID_INTEL_Q35_MCH : + machine_type =MACHINE_TYPE_Q35 ;tools/firmware/hvmloader/util.c void __bug(const char *file, int line) · line 687
Quoted 10 lines
tools/firmware/hvmloader/util.c +10
-0+printf ("Detected Q35 chipset\n" ); +break ; + +default : + goto error; + } + +return ; + +error:Nit: Labels indented by at least one blank please.
Quoted 3 lines
tools/firmware/hvmloader/util.c +3
-0+printf ("Unknown emulated chipset encountered, VID=%04Xh, DID=%04Xh\n" , + vendor_id, device_id); +BUG ();
Quoted 5 lines
Quoted 2 lines
Can't this be moved up into the default case, thus avoiding "goto" and label altogether?
There is already a goto error on the vendor ID check. That makes it more readable imo.
Hmm, maybe to some people. To me the extra "return" goes against better readability. I agree we don't want to duplicate things, but we can still get away with one less "goto" if the label was moved next to the "default" one in the switch().
Jan
PATCH 4/17 hvmloader: add ACPI enabling for Q35
In reply to Thierry EscandeIn order to turn on ACPI for OS, we need to write a chipset-specific value to SMI_CMD register (sort of imitation of the APM->ACPI switch on real systems). Modify acpi_enable_sci() function to support both i440 and Q35 emulation.
--- tools/firmware/hvmloader/hvmloader.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
tools/firmware/hvmloader/hvmloader.c +17 -2
@@ -258,9 +258,24 @@ static const struct bios_config *detect_bios(void)static void acpi_enable_sci (void ) {uint8_t pm1a_cnt_val; +uint8_t acpi_enable_val; -#define PIIX4_SMI_CMD_IOPORT 0xb2 +#define SMI_CMD_IOPORT 0xb2#define PIIX4_ACPI_ENABLE 0xf1 +#define ICH9_ACPI_ENABLE 0x02 + +switch ( machine_type ) + { +case MACHINE_TYPE_Q35 : + acpi_enable_val =ICH9_ACPI_ENABLE ; +break ; +case MACHINE_TYPE_I440 : + acpi_enable_val =PIIX4_ACPI_ENABLE ; +break ; +default : +/* Not likely to happen */ +BUG (); + }/* * PIIX4 emulation in QEMU has SCI_EN=0 by default. We have no legacy
@@ -268,7 +283,7 @@ static void acpi_enable_sci(void)*/ pm1a_cnt_val =inb (ACPI_PM1A_CNT_BLK_ADDRESS_V1 );if ( !(pm1a_cnt_val &ACPI_PM1C_SCI_EN ) ) -outb (PIIX4_SMI_CMD_IOPORT ,PIIX4_ACPI_ENABLE ); +outb (SMI_CMD_IOPORT , acpi_enable_val); pm1a_cnt_val =inb (ACPI_PM1A_CNT_BLK_ADDRESS_V1 );BUG_ON (!(pm1a_cnt_val &ACPI_PM1C_SCI_EN ));
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 04/17] hvmloader: add ACPI enabling for Q35
Quoted 7 lines · Thierry Escande
In order to turn on ACPI for OS, we need to write a chipset-specific value to
SMI_CMDregister (sort of imitation of theAPM->ACPIswitch on real systems). Modifyacpi_enable_sci()function to support both i440 and Q35 emulation.Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>
It's not great to add more stuff into hvmloader when we want to move out of it, but it's also not helpful to tie the Q35 addition to the removal of hvmloader.
Quoted 17 lines
--- tools/firmware/hvmloader/hvmloader.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)tools/firmware/hvmloader/hvmloader.c +2
-1@@ -258,9 +258,24 @@ static const struct bios_config *detect_bios(void)static void acpi_enable_sci (void ) {uint8_t pm1a_cnt_val; +uint8_t acpi_enable_val; -#define PIIX4_SMI_CMD_IOPORT 0xb2 +#define SMI_CMD_IOPORT 0xb2#define PIIX4_ACPI_ENABLE 0xf1
tools/firmware/hvmloader/hvmloader.c static const struct bios_config *detect_bios(void) · line 274
Quoted 10 lines
tools/firmware/hvmloader/hvmloader.c +10
-0+#define ICH9_ACPI_ENABLE 0x02 + +switch ( machine_type ) + { +case MACHINE_TYPE_Q35 : + acpi_enable_val =ICH9_ACPI_ENABLE ; +break ; +case MACHINE_TYPE_I440 : + acpi_enable_val =PIIX4_ACPI_ENABLE ; +break ;
We might want to add a newline after the break statements.
Thanks, Roger.
Re: [PATCH 04/17] hvmloader: add ACPI enabling for Q35
Quoted 6 lines · On Tue, 28 Apr 2026 12:48:23 +0200 Roger Pau Monné <[email protected]> wrote:
Quoted 5 lines · Thierry Escande
In order to turn on ACPI for OS, we need to write a chipset-specific value to
SMI_CMDregister (sort of imitation of theAPM->ACPIswitch on real systems). Modifyacpi_enable_sci()function to support both i440 and Q35 emulation.
Quoted 8 lines
Quoted 2 lines
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>It's not great to add more stuff into hvmloader when we want to move out of it, but it's also not helpful to tie the Q35 addition to the removal of hvmloader.
I'm afraid the only option to get rid of hvmloader is to move its responsibilities back into the firmware (SeaBIOS/OVMF). But if I understand it right, the whole idea of introducing hvmloader originally was to delegate Xen-specific parts of HVM guest initialization from firmware to a component managed by Xen itself.
So, to some extent hvmloader can be considered as a part of the firmware itself as it does things like PCI BAR allocation etc which are normally done by the guest firmware, but with more knowledge of Xen specifics.
I guess this hvmloader/firmware split model was introduced to have more freedom/maintainability/control - I suppose it's much faster and easier to integrate Xen-specific changes to hvmloader directly then to upstream them to SeaBIOS/OVMF codebases.
But other than moving hvmloader's responsibilities to the firmware we can't do much I think - HVM guests expect to have full freedom over the emulated platform. Among problems are non-standard (chipset-specific) devices which also need to have assigned resources like MMIO ranges - and Xen doesn't know anything about these devices and their resource requirements (left alone how to configure them), yet they still need to have correct BARs assigned with no conflicts with other PCI devices and to contribute to MMIO hole sizing. This is something which cannot be solved on the toolstack level unless Xen emulates the whole chipset and knows about all emulated chipset devices - we limit ourselves to MMCONFIG now but there are more configurable ranges like this.
Re: [PATCH 04/17] hvmloader: add ACPI enabling for Q35
Quoted 17 lines · Alexey G
Quoted 6 lines · On Tue, 28 Apr 2026 12:48:23 +0200 Roger Pau Monné <[email protected]> wrote:
Quoted 5 lines · Thierry Escande
In order to turn on ACPI for OS, we need to write a chipset-specific value to
SMI_CMDregister (sort of imitation of theAPM->ACPIswitch on real systems). Modifyacpi_enable_sci()function to support both i440 and Q35 emulation.Quoted 8 lines
Quoted 2 lines
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>Reviewed-by Roger Pau Monné <[email protected]>It's not great to add more stuff into hvmloader when we want to move out of it, but it's also not helpful to tie the Q35 addition to the removal of hvmloader.
Quoted 5 lines
I'm afraid the only option to get rid of hvmloader is to move its responsibilities back into the firmware (SeaBIOS/OVMF). But if I understand it right, the whole idea of introducing hvmloader originally was to delegate Xen-specific parts of HVM guest initialization from firmware to a component managed by Xen itself.
Maybe originally? We then ended up having to add all sorts of Xen specific logic into both SeaBIOS and OVMF, so much to OVMF that there's a Xen-specific target/platform in OVMF.
Quoted 8 lines
So, to some extent hvmloader can be considered as a part of the firmware itself as it does things like PCI BAR allocation etc which are normally done by the guest firmware, but with more knowledge of Xen specifics.
I guess this hvmloader/firmware split model was introduced to have more freedom/maintainability/control - I suppose it's much faster and easier to integrate Xen-specific changes to hvmloader directly then to upstream them to SeaBIOS/OVMF codebases.
Faster to integrate possibly, but then we end up with IMO a lot of duplication between what hvmloader does vs what we could offload to OVMF.
Quoted 11 lines
But other than moving hvmloader's responsibilities to the firmware we can't do much I think - HVM guests expect to have full freedom over the emulated platform. Among problems are non-standard (chipset-specific) devices which also need to have assigned resources like MMIO ranges - and Xen doesn't know anything about these devices and their resource requirements (left alone how to configure them), yet they still need to have correct BARs assigned with no conflicts with other PCI devices and to contribute to MMIO hole sizing. This is something which cannot be solved on the toolstack level unless Xen emulates the whole chipset and knows about all emulated chipset devices - we limit ourselves to MMCONFIG now but there are more configurable ranges like this.
I think we do want to move a lot of hvmloader responsibilities into OVMF (maybe SeaBIOS if possible also, albeit that's a legacy firmware by today standards anyway). Whether we would need to partially offload some of what hvmloader does into the toolstack remains to be seen.
Chipset initialization would possibly need to be done by OVMF, at which point we might require PVH guests that want to use PCI passthrough to also rely on OVMF instead of direct kernel boot. Anyway, this is quite distant future.
Thanks, Roger.
PATCH 5/17 hvmloader: add Q35 DSDT table loading
In reply to Thierry EscandeThis patch allows to select Q35 DSDT table in the function hvmloader_acpi_build_tables(). The machine_type global variable is used to select a proper table (i440/q35).
As we are bound to the qemu-xen device model for Q35, there is no need to initialize config->dsdt_15cpu/config->dsdt_15cpu_len fields.
--- tools/firmware/hvmloader/util.c | 17 +++++++++++++++-- tools/firmware/hvmloader/util.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-)
tools/firmware/hvmloader/util.c +15 -2
@@ -885,8 +885,21 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, s =xenstore_read ("platform/device-model" ,"" );if ( !strncmp (s,"qemu_xen" ,9 ) ) { - config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; - config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; +switch ( machine_type ) + { +case MACHINE_TYPE_Q35 : + config->dsdt_anycpu = dsdt_q35_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_q35_anycpu_qemu_xen_len; +break ; +case MACHINE_TYPE_I440 : + config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; +break ; +default : +/* Not likely to happen */ +BUG (); + } + config->dsdt_15cpu =NULL ; config->dsdt_15cpu_len =0 ; }
tools/firmware/hvmloader/util.h +2 -0
@@ -393,7 +393,9 @@ bool check_overlap(uint64_t start, uint64_t size, uint64_t reserved_start, uint64_t reserved_size);extern const unsigned char dsdt_i440_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; +extern const unsigned char dsdt_q35_anycpu_qemu_xen[];extern const int dsdt_i440_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len; +extern const int dsdt_q35_anycpu_qemu_xen_len;unsigned long acpi_pages_allocated (void );
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 05/17] hvmloader: add Q35 DSDT table loading
Quoted 19 lines · Thierry Escande
This patch allows to select Q35 DSDT table in the function
hvmloader_acpi_build_tables(). Themachine_typeglobal variable is used to select a proper table (i440/q35).As we are bound to the qemu-xen device model for Q35, there is no need to initialize config->dsdt_15cpu/config->dsdt_15cpu_len fields.
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/util.c | 17 +++++++++++++++-- tools/firmware/hvmloader/util.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-)tools/firmware/hvmloader/util.c +0
-0
tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 886
Quoted 2 lines
tools/firmware/hvmloader/util.c +0
-0@@ -885,8 +885,21 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, s =xenstore_read ("platform/device-model" ,"" );if ( !strncmp (s,"qemu_xen" ,9 ) )
Tying Q35 to xenstore seems a bit sub-optimal, as Q35 detection is done purely from the PCI config space. It would be better if we could avoid relying on the xenstore node, and hence also fixup at least ovmf_acpi_build_tables() and seabios_acpi_build_tables() to use the Q35 ACPI tables when Q35 is detected, regardless of the device-model xenstore node.
Quoted 26 lines
tools/firmware/hvmloader/util.c +15
-2{ - config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; - config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; +switch ( machine_type ) + { +case MACHINE_TYPE_Q35 : + config->dsdt_anycpu = dsdt_q35_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_q35_anycpu_qemu_xen_len; +break ; +case MACHINE_TYPE_I440 : + config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; +break ; +default : +/* Not likely to happen */ +BUG (); + } + config->dsdt_15cpu =NULL ; config->dsdt_15cpu_len =0 ; }tools/firmware/hvmloader/util.h +0
-0
tools/firmware/hvmloader/util.h bool check_overlap(uint64_t start, uint64_t size, · line 396
Quoted 4 lines
tools/firmware/hvmloader/util.h +1
-0@@ -393,7 +393,9 @@ bool check_overlap(uint64_t start, uint64_t size, uint64_t reserved_start, uint64_t reserved_size);extern const unsigned char dsdt_i440_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; +extern const unsigned char dsdt_q35_anycpu_qemu_xen[];
If I'm not mistaken, patch 2 introduces the dsdt_q35_anycpu_qemu_xen symbol to the hvmloader build, so that you can reference it here?
At first I was going to comment that you are referencing a symbol not included in the patch, but I think such symbol was previously added to the build in patch 2 (and was unused there).
tools/firmware/hvmloader/util.h bool check_overlap(uint64_t start, uint64_t size, · line 398
Quoted 2 lines
tools/firmware/hvmloader/util.h +1
-0extern const int dsdt_i440_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len; +extern const int dsdt_q35_anycpu_qemu_xen_len;
unsigned int would be better here.
Thanks, Roger.
Re: [PATCH 05/17] hvmloader: add Q35 DSDT table loading
Quoted 15 lines · Roger Pau Monné
Quoted 14 lines · Thierry Escande
This patch allows to select Q35 DSDT table in the function
hvmloader_acpi_build_tables(). Themachine_typeglobal variable is used to select a proper table (i440/q35).As we are bound to the qemu-xen device model for Q35, there is no need to initialize config->dsdt_15cpu/config->dsdt_15cpu_len fields.
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/util.c | 17 +++++++++++++++-- tools/firmware/hvmloader/util.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-)
Quoted 14 lines
tools/firmware/hvmloader/util.c void hvmloader_acpi_build_tables(struct acpi_config *config, · line 886
Quoted 7 lines
tools/firmware/hvmloader/util.c +0
-0@@ -885,8 +885,21 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, s =xenstore_read ("platform/device-model" ,"" );if ( !strncmp (s,"qemu_xen" ,9 ) )Tying Q35 to xenstore seems a bit sub-optimal, as Q35 detection is done purely from the PCI config space. It would be better if we could avoid relying on the xenstore node, and hence also fixup at least
ovmf_acpi_build_tables()andseabios_acpi_build_tables()to use the Q35 ACPI tables when Q35 is detected, regardless of the device-model xenstore node.
Looking at the acpi_build_tables() for ovmf, seabios, and rombios, I suppose the idea here was to set the correct ACPI tables for guest using Rombios with qemu-xen.
So I can move the qemu-xen check in rombios_acpi_build_tables() and do the machine_type check in all acpi_build_tables callbacks. I'm a bit puzzled by the duplication, though...
Quoted 35 lines
Quoted 27 lines
tools/firmware/hvmloader/util.c +15
-2{ - config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; - config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; +switch ( machine_type ) + { +case MACHINE_TYPE_Q35 : + config->dsdt_anycpu = dsdt_q35_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_q35_anycpu_qemu_xen_len; +break ; +case MACHINE_TYPE_I440 : + config->dsdt_anycpu = dsdt_i440_anycpu_qemu_xen; + config->dsdt_anycpu_len = dsdt_i440_anycpu_qemu_xen_len; +break ; +default : +/* Not likely to happen */ +BUG (); + } + config->dsdt_15cpu =NULL ; config->dsdt_15cpu_len =0 ; }tools/firmware/hvmloader/util.h +0
-0tools/firmware/hvmloader/util.h bool check_overlap(uint64_t start, uint64_t size, · line 396
Quoted 4 lines
tools/firmware/hvmloader/util.h +1
-0@@ -393,7 +393,9 @@ bool check_overlap(uint64_t start, uint64_t size, uint64_t reserved_start, uint64_t reserved_size);extern const unsigned char dsdt_i440_anycpu_qemu_xen[], dsdt_anycpu[], dsdt_15cpu[]; +extern const unsigned char dsdt_q35_anycpu_qemu_xen[];If I'm not mistaken, patch 2 introduces the
dsdt_q35_anycpu_qemu_xensymbol to the hvmloader build, so that you can reference it here?
Quoted 3 lines
At first I was going to comment that you are referencing a symbol not included in the patch, but I think such symbol was previously added to the build in patch 2 (and was unused there).
Right, dsdt_q35_anycpu_qemu_xen.c that declares dsdt_q35_anycpu_qemu_xen[] is generated by patch 2 and used in this patch.
Quoted 5 lines
tools/firmware/hvmloader/util.h bool check_overlap(uint64_t start, uint64_t size, · line 398
Quoted 3 lines
tools/firmware/hvmloader/util.h +1
-0extern const int dsdt_i440_anycpu_qemu_xen_len, dsdt_anycpu_len, dsdt_15cpu_len; +extern const int dsdt_q35_anycpu_qemu_xen_len;unsigned int would be better here.
Yes, that will be done in a previous patch when dsdt_anycpu_qemu_xen_len is renamed to dsdt_i440_anycpu_qemu_xen_len.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 6/17 hvmloader: Move pci devices setup to a separate function
In reply to Thierry EscandeFor readability and code simplification, this patch moves PCI-device specific initializations out of the pci_setup() function to a new function class_specific_pci_device_setup().
--- tools/firmware/hvmloader/pci.c | 117 +++++++++++++++------------- tools/firmware/hvmloader/pci_regs.h | 4 + 2 files changed, 68 insertions(+), 53 deletions(-)
tools/firmware/hvmloader/pci.c +64 -53
@@ -84,12 +84,71 @@ static int find_next_rmrr(uint32_t base)return next_rmrr; } +static void class_specific_pci_device_setup (uint16_t vendor_id, +uint16_t device_id, +uint16_t class, +uint8_t bus, +uint8_t devfn,uint8_t *vga_devfn) +{ +switch ( class ) + { +case PCI_CLASS_DISPLAY_VGA : +/* If emulated VGA is found, preserve it as primary VGA. */ +if ( (vendor_id ==0x1234 ) && (device_id ==0x1111 ) ) + { + *vga_devfn = devfn; + virtual_vga = VGA_std; + } +else if ( (vendor_id ==0x1013 ) && (device_id ==0xb8 ) ) + { + *vga_devfn = devfn; + virtual_vga = VGA_cirrus; + } +else if ( virtual_vga == VGA_none ) + { + *vga_devfn = devfn; + virtual_vga = VGA_pt; +if ( vendor_id ==0x8086 ) + { + igd_opregion_pgbase =mem_hole_alloc (IGD_OPREGION_PAGES ); +/* +* Write the the OpRegion offset to give the opregion +* address to the device model. The device model will trap +* and map the OpRegion at the give address. +*/ +pci_writel (*vga_devfn,PCI_INTEL_OPREGION , + igd_opregion_pgbase <<PAGE_SHIFT ); + } + } +break ; +case PCI_CLASS_BRIDGE_OTHER : +/* PIIX4 ACPI PM. Special device with special PCI config space. */ +ASSERT ((vendor_id ==0x8086 ) && (device_id ==0x7113 )); +pci_writew (devfn,0x20 ,0x0000 );/* No smb bus IO enable */ +pci_writew (devfn,0xd2 ,0x0000 );/* No smb bus IO enable */ +pci_writew (devfn,0x22 ,0x0000 ); +pci_writew (devfn,0x3c ,0x0009 );/* Hardcoded IRQ9 */ +pci_writew (devfn,0x3d ,0x0001 ); +pci_writel (devfn,0x40 ,ACPI_PM1A_EVT_BLK_ADDRESS_V1 |1 ); +pci_writeb (devfn,0x80 ,0x01 );/* enable PM io space */ +break ; +case PCI_CLASS_STORAGE_IDE : +if ( vendor_id ==0x8086 ) + { +/* Intel ICHs since PIIX3: enable IDE legacy mode. */ +pci_writew (devfn,0x40 ,0x8000 );/* enable IDE0 */ +pci_writew (devfn,0x42 ,0x8000 );/* enable IDE1 */ + } +break ; + } +} +void pci_setup (void ) {uint8_t is_64bar, using_64bar, bar64_relocate =0 ;uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper;uint64_t base, bar_sz, bar_sz_upper, mmio_total =0 ; -uint32_t vga_devfn =256 ; +uint8_t vga_devfn =0xff ;uint16_t class, vendor_id, device_id;unsigned int bar, pin, link, isa_irq;uint8_t pci_devfn_decode_type[256 ] = {};
@@ -170,57 +229,9 @@ void pci_setup(void)ASSERT ((devfn !=PCI_ISA_DEVFN ) || ((vendor_id ==0x8086 ) && (device_id ==0x7000 ))); -switch ( class ) - { -case 0x0300 : -/* If emulated VGA is found, preserve it as primary VGA. */ -if ( (vendor_id ==0x1234 ) && (device_id ==0x1111 ) ) - { - vga_devfn = devfn; - virtual_vga = VGA_std; - } -else if ( (vendor_id ==0x1013 ) && (device_id ==0xb8 ) ) - { - vga_devfn = devfn; - virtual_vga = VGA_cirrus; - } -else if ( virtual_vga == VGA_none ) - { - vga_devfn = devfn; - virtual_vga = VGA_pt; -if ( vendor_id ==0x8086 ) - { - igd_opregion_pgbase =mem_hole_alloc (IGD_OPREGION_PAGES ); -/* -* Write the the OpRegion offset to give the opregion -* address to the device model. The device model will trap -* and map the OpRegion at the give address. -*/ -pci_writel (vga_devfn,PCI_INTEL_OPREGION , - igd_opregion_pgbase <<PAGE_SHIFT ); - } - } -break ; -case 0x0680 : -/* PIIX4 ACPI PM. Special device with special PCI config space. */ -ASSERT ((vendor_id ==0x8086 ) && (device_id ==0x7113 )); -pci_writew (devfn,0x20 ,0x0000 );/* No smb bus IO enable */ -pci_writew (devfn,0xd2 ,0x0000 );/* No smb bus IO enable */ -pci_writew (devfn,0x22 ,0x0000 ); -pci_writew (devfn,0x3c ,0x0009 );/* Hardcoded IRQ9 */ -pci_writew (devfn,0x3d ,0x0001 ); -pci_writel (devfn,0x40 ,ACPI_PM1A_EVT_BLK_ADDRESS_V1 |1 ); -pci_writeb (devfn,0x80 ,0x01 );/* enable PM io space */ -break ; -case 0x0101 : -if ( vendor_id ==0x8086 ) - { -/* Intel ICHs since PIIX3: enable IDE legacy mode. */ -pci_writew (devfn,0x40 ,0x8000 );/* enable IDE0 */ -pci_writew (devfn,0x42 ,0x8000 );/* enable IDE1 */ - } -break ; - } +class_specific_pci_device_setup (vendor_id, device_id, class, +0 /* virt_bus support TBD */ , + devfn, &vga_devfn);/* * It is recommended that BAR programming be done whilst decode
@@ -583,7 +594,7 @@ void pci_setup(void) ((pci_hi_mem_start & -pci_hi_mem_start) - 1)) + 1; } -if ( vga_devfn !=256 ) +if ( vga_devfn !=0xff ) {/* * VGA registers live in I/O space so ensure that primary VGA
tools/firmware/hvmloader/pci_regs.h +4 -0
@@ -111,6 +111,10 @@#define PCI_DEVICE_ID_INTEL_82441 0x1237#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0 +#define PCI_CLASS_STORAGE_IDE 0x0101 +#define PCI_CLASS_DISPLAY_VGA 0x0300 +#define PCI_CLASS_BRIDGE_OTHER 0x0680 +#endif /* __HVMLOADER_PCI_REGS_H__ */ /*
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 06/17] hvmloader: Move pci devices setup to a separate function
Quoted 3 lines · Thierry Escande
For readability and code simplification, this patch moves PCI-device specific initializations out of the
pci_setup()function to a new functionclass_specific_pci_device_setup().
AFAICT this is a non-functional change. Should likely be mentioned in the commit message to avoid any doubts.
Quoted 11 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/pci.c | 117 +++++++++++++++------------- tools/firmware/hvmloader/pci_regs.h | 4 + 2 files changed, 68 insertions(+), 53 deletions(-)tools/firmware/hvmloader/pci.c +0
-0
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 89
Quoted 6 lines
tools/firmware/hvmloader/pci.c +3
-0@@ -84,12 +84,71 @@ static int find_next_rmrr(uint32_t base)return next_rmrr; } +static void class_specific_pci_device_setup(uint16_t vendor_id, + uint16_t device_id, + uint16_t class,
It's a bit weird to pass the class value into the function, the value is only used inside the function itself, and hence could be fetched inside the function as the device BDF is provided as parameters?
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 102
Quoted 13 lines
tools/firmware/hvmloader/pci.c +13
-0+uint8_t bus, + uint8_t devfn, uint8_t *vga_devfn) +{ + switch ( class ) + { + case PCI_CLASS_DISPLAY_VGA: + /* If emulated VGA is found, preserve it as primary VGA. */ + if ( (vendor_id == 0x1234) && (device_id == 0x1111) ) + { + *vga_devfn = devfn; + virtual_vga = VGA_std; + } + else if ( (vendor_id == 0x1013) && (device_id == 0xb8) )
Since you introduce defines for the device classes, could you also introduce defines for the vendor and device IDs used here?
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 111
Quoted 9 lines
tools/firmware/hvmloader/pci.c +9
-0+ { + *vga_devfn = devfn; + virtual_vga = VGA_cirrus; + } + else if ( virtual_vga == VGA_none ) + { + *vga_devfn = devfn; + virtual_vga = VGA_pt; +if ( vendor_id ==0x8086 )
This one is PCI_VENDOR_ID_INTEL, also a couple of more instances below.
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 123
Quoted 12 lines
tools/firmware/hvmloader/pci.c +12
-0+ { + igd_opregion_pgbase =mem_hole_alloc (IGD_OPREGION_PAGES ); +/* +* Write the the OpRegion offset to give the opregion +* address to the device model. The device model will trap +* and map the OpRegion at the give address. +*/ +pci_writel (*vga_devfn,PCI_INTEL_OPREGION , + igd_opregion_pgbase <<PAGE_SHIFT ); + } + } +break ;
Newlines after break statements.
Quoted 107 lines
tools/firmware/hvmloader/pci.c +27
-53+case PCI_CLASS_BRIDGE_OTHER : +/* PIIX4 ACPI PM. Special device with special PCI config space. */ +ASSERT ((vendor_id ==0x8086 ) && (device_id ==0x7113 )); +pci_writew (devfn,0x20 ,0x0000 );/* No smb bus IO enable */ +pci_writew (devfn,0xd2 ,0x0000 );/* No smb bus IO enable */ +pci_writew (devfn,0x22 ,0x0000 ); +pci_writew (devfn,0x3c ,0x0009 );/* Hardcoded IRQ9 */ +pci_writew (devfn,0x3d ,0x0001 ); +pci_writel (devfn,0x40 ,ACPI_PM1A_EVT_BLK_ADDRESS_V1 |1 ); +pci_writeb (devfn,0x80 ,0x01 );/* enable PM io space */ +break ; +case PCI_CLASS_STORAGE_IDE : +if ( vendor_id ==0x8086 ) + { +/* Intel ICHs since PIIX3: enable IDE legacy mode. */ +pci_writew (devfn,0x40 ,0x8000 );/* enable IDE0 */ +pci_writew (devfn,0x42 ,0x8000 );/* enable IDE1 */ + } +break ; + } +} +void pci_setup (void ) {uint8_t is_64bar, using_64bar, bar64_relocate =0 ;uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper;uint64_t base, bar_sz, bar_sz_upper, mmio_total =0 ; -uint32_t vga_devfn =256 ; +uint8_t vga_devfn =0xff ;uint16_t class, vendor_id, device_id;unsigned int bar, pin, link, isa_irq;uint8_t pci_devfn_decode_type[256 ] = {};@@ -170,57 +229,9 @@ void pci_setup(void)ASSERT ((devfn !=PCI_ISA_DEVFN ) || ((vendor_id ==0x8086 ) && (device_id ==0x7000 ))); -switch ( class ) - { -case 0x0300 : -/* If emulated VGA is found, preserve it as primary VGA. */ -if ( (vendor_id ==0x1234 ) && (device_id ==0x1111 ) ) - { - vga_devfn = devfn; - virtual_vga = VGA_std; - } -else if ( (vendor_id ==0x1013 ) && (device_id ==0xb8 ) ) - { - vga_devfn = devfn; - virtual_vga = VGA_cirrus; - } -else if ( virtual_vga == VGA_none ) - { - vga_devfn = devfn; - virtual_vga = VGA_pt; -if ( vendor_id ==0x8086 ) - { - igd_opregion_pgbase =mem_hole_alloc (IGD_OPREGION_PAGES ); -/* -* Write the the OpRegion offset to give the opregion -* address to the device model. The device model will trap -* and map the OpRegion at the give address. -*/ -pci_writel (vga_devfn,PCI_INTEL_OPREGION , - igd_opregion_pgbase <<PAGE_SHIFT ); - } - } -break ; -case 0x0680 : -/* PIIX4 ACPI PM. Special device with special PCI config space. */ -ASSERT ((vendor_id ==0x8086 ) && (device_id ==0x7113 )); -pci_writew (devfn,0x20 ,0x0000 );/* No smb bus IO enable */ -pci_writew (devfn,0xd2 ,0x0000 );/* No smb bus IO enable */ -pci_writew (devfn,0x22 ,0x0000 ); -pci_writew (devfn,0x3c ,0x0009 );/* Hardcoded IRQ9 */ -pci_writew (devfn,0x3d ,0x0001 ); -pci_writel (devfn,0x40 ,ACPI_PM1A_EVT_BLK_ADDRESS_V1 |1 ); -pci_writeb (devfn,0x80 ,0x01 );/* enable PM io space */ -break ; -case 0x0101 : -if ( vendor_id ==0x8086 ) - { -/* Intel ICHs since PIIX3: enable IDE legacy mode. */ -pci_writew (devfn,0x40 ,0x8000 );/* enable IDE0 */ -pci_writew (devfn,0x42 ,0x8000 );/* enable IDE1 */ - } -break ; - } +class_specific_pci_device_setup (vendor_id, device_id, class, +0 /* virt_bus support TBD */ , + devfn, &vga_devfn);/* * It is recommended that BAR programming be done whilst decode @@ -583,7 +594,7 @@ void pci_setup(void) ((pci_hi_mem_start & -pci_hi_mem_start) - 1)) + 1; } -if ( vga_devfn !=256 ) +if ( vga_devfn !=0xff ) {/* * VGA registers live in I/O space so ensure that primary VGA tools/firmware/hvmloader/pci_regs.h +0
-0
tools/firmware/hvmloader/pci_regs.h line 116
Quoted 6 lines
tools/firmware/hvmloader/pci_regs.h +3
-0@@ -111,6 +111,10 @@#define PCI_DEVICE_ID_INTEL_82441 0x1237#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0 +#define PCI_CLASS_STORAGE_IDE 0x0101 +#define PCI_CLASS_DISPLAY_VGA 0x0300 +#define PCI_CLASS_BRIDGE_OTHER 0x0680
As mentioned in a previous patch, this would better be placed in a pci_ids.h header.
Thanks, Roger.
Re: [PATCH 06/17] hvmloader: Move pci devices setup to a separate function
Quoted 7 lines · Roger Pau Monné
Quoted 3 lines · Thierry Escande
For readability and code simplification, this patch moves PCI-device specific initializations out of the
pci_setup()function to a new functionclass_specific_pci_device_setup().AFAICT this is a non-functional change. Should likely be mentioned in the commit message to avoid any doubts.
Sure, will do.
Quoted 15 lines
Quoted 15 lines
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/pci.c | 117 +++++++++++++++------------- tools/firmware/hvmloader/pci_regs.h | 4 + 2 files changed, 68 insertions(+), 53 deletions(-)tools/firmware/hvmloader/pci.c +0
-0@@ -84,12 +84,71 @@ static int find_next_rmrr(uint32_t base)return next_rmrr; }
Quoted 7 lines
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 89
Quoted 3 lines
tools/firmware/hvmloader/pci.c +3
-0+static void class_specific_pci_device_setup(uint16_t vendor_id, + uint16_t device_id, + uint16_t class,It's a bit weird to pass the class value into the function, the value is only used inside the function itself, and hence could be fetched inside the function as the device BDF is provided as parameters?
That was to have less modification and have all calls to pci_readw() in one place. I can move this one to the new function, no problem.
Quoted 15 lines
Quoted 4 lines
tools/firmware/hvmloader/pci.c +3
-0+uint8_t bus, + uint8_t devfn, uint8_t *vga_devfn) +{tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 102
Quoted 10 lines
tools/firmware/hvmloader/pci.c +10
-0+switch ( class ) + { +case PCI_CLASS_DISPLAY_VGA : +/* If emulated VGA is found, preserve it as primary VGA. */ +if ( (vendor_id ==0x1234 ) && (device_id ==0x1111 ) ) + { + *vga_devfn = devfn; + virtual_vga = VGA_std; + } +else if ( (vendor_id ==0x1013 ) && (device_id ==0xb8 ) )
Quoted 2 lines
Since you introduce defines for the device classes, could you also introduce defines for the vendor and device IDs used here?
Sure.
Quoted 11 lines
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 111
Quoted 10 lines
tools/firmware/hvmloader/pci.c +9
-0+ { + *vga_devfn = devfn; + virtual_vga = VGA_cirrus; + } + else if ( virtual_vga == VGA_none ) + { + *vga_devfn = devfn; + virtual_vga = VGA_pt; +if ( vendor_id ==0x8086 )
Quoted 1 line
This one is
PCI_VENDOR_ID_INTEL, also a couple of more instances below.
Right. Will do the same for all IDs.
Quoted 14 lines
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 123
Quoted 13 lines
tools/firmware/hvmloader/pci.c +12
-0+ { + igd_opregion_pgbase =mem_hole_alloc (IGD_OPREGION_PAGES ); +/* +* Write the the OpRegion offset to give the opregion +* address to the device model. The device model will trap +* and map the OpRegion at the give address. +*/ +pci_writel (*vga_devfn,PCI_INTEL_OPREGION , + igd_opregion_pgbase <<PAGE_SHIFT ); + } + } +break ;
Quoted 1 line
Newlines after break statements.
Ok
Quoted 8 lines
Quoted 8 lines
tools/firmware/hvmloader/pci_regs.h +0
-0@@ -111,6 +111,10 @@#define PCI_DEVICE_ID_INTEL_82441 0x1237#define PCI_DEVICE_ID_INTEL_Q35_MCH 0x29c0
Quoted 6 lines
tools/firmware/hvmloader/pci_regs.h line 116
Quoted 3 lines
tools/firmware/hvmloader/pci_regs.h +3
-0+#define PCI_CLASS_STORAGE_IDE 0x0101 +#define PCI_CLASS_DISPLAY_VGA 0x0300 +#define PCI_CLASS_BRIDGE_OTHER 0x0680As mentioned in a previous patch, this would better be placed in a
pci_ids.hheader.
Sure, will do.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 06/17] hvmloader: Move pci devices setup to a separate function
In reply to Thierry Escandetools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 151
Quoted 7 lines · Thierry Escande
void
pci_setup(void){ uint8_t is_64bar, using_64bar, bar64_relocate = 0; uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper; uint64_t base, bar_sz, bar_sz_upper, mmio_total = 0;tools/firmware/hvmloader/pci.c +1
-1-uint32_t vga_devfn =256 ; +uint8_t vga_devfn =0xff ;
This change (and the related ones elsewhere) looks bogus to me: 0xff is a valid devfn value, whereas 256 isn't.
Jan
Re: [PATCH 06/17] hvmloader: Move pci devices setup to a separate function
Quoted 11 lines · Jan Beulich
tools/firmware/hvmloader/pci.c static int find_next_rmrr(uint32_t base) · line 151
Quoted 7 lines · Thierry Escande
void
pci_setup(void){ uint8_t is_64bar, using_64bar, bar64_relocate = 0; uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper; uint64_t base, bar_sz, bar_sz_upper, mmio_total = 0;tools/firmware/hvmloader/pci.c +1
-1-uint32_t vga_devfn =256 ; +uint8_t vga_devfn =0xff ;This change (and the related ones elsewhere) looks bogus to me:
0xffis a valid devfn value, whereas 256 isn't.
I'll revert this.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 7/17 hvmloader: add basic Q35 support
In reply to Thierry EscandeThe current hvmloader implementation assumes a fixed PCI-to-ISA bridge at 00:01.0 (PIIX3). This patch introduces support for the ICH9 LPC bridge used in Q35 machine types, which resides at 00:1f.0.
It also initializes PIRQA...{PIRQD, PIRQH} routing accordingly to the emulated south bridge (either located on PCI_ISA_DEVFN or PCI_ICH9_LPC_DEVFN).
--- tools/firmware/hvmloader/config.h | 1 + tools/firmware/hvmloader/pci.c | 34 ++++++++++++++++++++++++----- tools/firmware/hvmloader/pci_regs.h | 1 + 3 files changed, 31 insertions(+), 5 deletions(-)
tools/firmware/hvmloader/config.h +1 -0
@@ -54,6 +54,7 @@ extern uint32_t *cpu_to_apicid;#define PCI_ISA_DEVFN 0x08/* dev 1, fn 0 */ #define PCI_ISA_IRQ_MASK 0x0c20U/* ISA IRQs 5,10,11 are PCI connected */ +#define PCI_ICH9_LPC_DEVFN 0xf8/* dev 31, fn 0 */ #define ACPI_TIS_HDR_ADDRESS 0xFED40F00UL
tools/firmware/hvmloader/pci.c +29 -5
@@ -84,6 +84,10 @@ static int find_next_rmrr(uint32_t base)return next_rmrr; } +#define SCI_EN_IOPORT (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + 0x30) +#define GBL_SMI_EN (1 << 0) +#define APMC_EN (1 << 5) + static void class_specific_pci_device_setup(uint16_t vendor_id, uint16_t device_id, uint16_t class,
@@ -140,6 +144,17 @@ static void class_specific_pci_device_setup(uint16_t vendor_id,pci_writew (devfn,0x42 ,0x8000 );/* enable IDE1 */ }break ; +case PCI_CLASS_BRIDGE_ISA : +/* LPC bridge */ +if ( vendor_id ==0x8086 && device_id ==0x2918 ) + { +pci_writeb (devfn,0x3c ,0x09 );/* Hardcoded IRQ9 */ +pci_writeb (devfn,0x3d ,0x01 ); +pci_writel (devfn,0x40 ,ACPI_PM1A_EVT_BLK_ADDRESS_V1 |1 ); +pci_writeb (devfn,0x44 ,0x80 );/* enable PM io space */ +outl (SCI_EN_IOPORT ,inl (SCI_EN_IOPORT ) |GBL_SMI_EN |APMC_EN ); + } +break ; } }
@@ -152,6 +167,7 @@ void pci_setup(void)uint16_t class, vendor_id, device_id;unsigned int bar, pin, link, isa_irq;uint8_t pci_devfn_decode_type[256 ] = {}; +int is_running_on_q35 = (machine_type ==MACHINE_TYPE_Q35 );/* Resources assignable to PCI devices via BARs. */ struct resource {
@@ -209,7 +225,16 @@ void pci_setup(void) {do { isa_irq = (isa_irq +1 ) &15 ; }while ( !(PCI_ISA_IRQ_MASK & (1U << isa_irq)) ); -pci_writeb (PCI_ISA_DEVFN ,0x60 + link, isa_irq); + +if ( is_running_on_q35 ) + { +pci_writeb (PCI_ICH9_LPC_DEVFN ,0x60 + link, isa_irq); + } +else + { +pci_writeb (PCI_ISA_DEVFN ,0x60 + link, isa_irq); + } +printf ("PCI-ISA link %u routed to IRQ%u\n" , link, isa_irq); }
@@ -226,9 +251,6 @@ void pci_setup(void)if ( (vendor_id ==0xffff ) && (device_id ==0xffff ) )continue ; -ASSERT ((devfn !=PCI_ISA_DEVFN ) || - ((vendor_id ==0x8086 ) && (device_id ==0x7000 ))); -class_specific_pci_device_setup (vendor_id, device_id, class,0 /* virt_bus support TBD */ , devfn, &vga_devfn);
@@ -362,7 +384,9 @@ void pci_setup(void) {/* This is the barber's pole mapping used by Xen. */ link = ((pin -1 ) + (devfn >>3 )) &3 ; - isa_irq =pci_readb (PCI_ISA_DEVFN ,0x60 + link); + isa_irq =pci_readb (is_running_on_q35 ? +PCI_ICH9_LPC_DEVFN :PCI_ISA_DEVFN , +0x60 + link);pci_writeb (devfn,PCI_INTERRUPT_LINE , isa_irq);printf ("pci dev %02x:%x INT%c->IRQ%u\n" , devfn>>3 , devfn&7 ,'A' +pin-1 , isa_irq);
tools/firmware/hvmloader/pci_regs.h +1 -0
@@ -114,6 +114,7 @@#define PCI_CLASS_STORAGE_IDE 0x0101#define PCI_CLASS_DISPLAY_VGA 0x0300#define PCI_CLASS_BRIDGE_OTHER 0x0680 +#define PCI_CLASS_BRIDGE_ISA 0x0601#endif /* __HVMLOADER_PCI_REGS_H__ */
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 07/17] hvmloader: add basic Q35 support
Quoted 21 lines · Thierry Escande
The current hvmloader implementation assumes a fixed PCI-to-ISA bridge at 00:01.0 (PIIX3). This patch introduces support for the ICH9 LPC bridge used in Q35 machine types, which resides at 00:1f.0.
It also initializes PIRQA...{PIRQD, PIRQH} routing accordingly to the emulated south bridge (either located on
PCI_ISA_DEVFNorPCI_ICH9_LPC_DEVFN).Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/config.h | 1 + tools/firmware/hvmloader/pci.c | 34 ++++++++++++++++++++++++----- tools/firmware/hvmloader/pci_regs.h | 1 + 3 files changed, 31 insertions(+), 5 deletions(-)tools/firmware/hvmloader/config.h +0
-0
tools/firmware/hvmloader/config.h extern uint32_t *cpu_to_apicid; · line 57
Quoted 4 lines
tools/firmware/hvmloader/config.h +1
-0@@ -54,6 +54,7 @@ extern uint32_t *cpu_to_apicid;#define PCI_ISA_DEVFN 0x08/* dev 1, fn 0 */ #define PCI_ISA_IRQ_MASK 0x0c20U/* ISA IRQs 5,10,11 are PCI connected */ +#define PCI_ICH9_LPC_DEVFN 0xf8/* dev 31, fn 0 */
We should introduce a macro to generate BDFs more easily in the hvmloader context. Having them as plain numbers is not very friendly.
Quoted 19 lines
tools/firmware/hvmloader/config.h +0
-0#define ACPI_TIS_HDR_ADDRESS 0xFED40F00ULtools/firmware/hvmloader/pci.c +4
-0@@ -84,6 +84,10 @@ static int find_next_rmrr(uint32_t base)return next_rmrr; } +#define SCI_EN_IOPORT (ACPI_PM1A_EVT_BLK_ADDRESS_V1 + 0x30) +#define GBL_SMI_EN (1 << 0) +#define APMC_EN (1 << 5) + static void class_specific_pci_device_setup(uint16_t vendor_id, uint16_t device_id, uint16_t class,
tools/firmware/hvmloader/pci.c static void class_specific_pci_device_setup(uint16_t vendor_id, · line 149
Quoted 6 lines
tools/firmware/hvmloader/pci.c +3
-0@@ -140,6 +144,17 @@ static void class_specific_pci_device_setup(uint16_t vendor_id,pci_writew (devfn,0x42 ,0x8000 );/* enable IDE1 */ }break ; +case PCI_CLASS_BRIDGE_ISA : +/* LPC bridge */ +if ( vendor_id ==0x8086 && device_id ==0x2918 )
If you don't add parentheses around the equal comparisons please also removing the existing ones when moving the code. Also device ID would batter be a constant with a proper name.
tools/firmware/hvmloader/pci.c static void class_specific_pci_device_setup(uint16_t vendor_id, · line 152
Quoted 3 lines
tools/firmware/hvmloader/pci.c +3
-0+ { +pci_writeb (devfn,0x3c ,0x09 );/* Hardcoded IRQ9 */ +pci_writeb (devfn,0x3d ,0x01 );
0x3c and 0x3d are PCI_INTERRUPT_LINE and PCI_INTERRUPT_PIN respectively, let's please try to use the named constants when available (or when they can be introduced).
tools/firmware/hvmloader/pci.c static void class_specific_pci_device_setup(uint16_t vendor_id, · line 155
Quoted 3 lines
tools/firmware/hvmloader/pci.c +3
-0+pci_writel (devfn,0x40 ,ACPI_PM1A_EVT_BLK_ADDRESS_V1 |1 ); +pci_writeb (devfn,0x44 ,0x80 );/* enable PM io space */ +outl (SCI_EN_IOPORT ,inl (SCI_EN_IOPORT ) |GBL_SMI_EN |APMC_EN );
Most of the above looks like black magic. It's not like the context of this function is great, most of the existing stuff is poorly documented. Can we get a bit more comments about what's this supposed to do, and maybe a reference to the Intel specification that lists where those PCI config space registers are coming from?
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 170
Quoted 10 lines
tools/firmware/hvmloader/pci.c +3
-0+ } +break ; } }@@ -152,6 +167,7 @@ void pci_setup(void)uint16_t class, vendor_id, device_id;unsigned int bar, pin, link, isa_irq;uint8_t pci_devfn_decode_type[256 ] = {}; +int is_running_on_q35 = (machine_type ==MACHINE_TYPE_Q35 );
Maybe you can avoid that and instead simply store the BDF of the ISA device?
unsigned int isa_bdf = (machine_type == MACHINE_TYPE_Q35) ? PCI_ICH9_LPC_DEVFN
: PCI_ISA_DEVFN;
Or if you really need it to be a boolean, let's make it:
bool is_q35 = ...
It makes no sense for it to be an int, and the naming could be shorter IMO.
Thanks, Roger.
Re: [PATCH 07/17] hvmloader: add basic Q35 support
Quoted 10 lines · On Tue, 28 Apr 2026 15:15:36 +0200 Roger Pau Monné <[email protected]> wrote:
tools/firmware/hvmloader/pci.c static void class_specific_pci_device_setup(uint16_t vendor_id, · line 155
Quoted 4 lines
tools/firmware/hvmloader/pci.c +3
-0+pci_writel (devfn,0x40 ,ACPI_PM1A_EVT_BLK_ADDRESS_V1 |1 ); +pci_writeb (devfn,0x44 ,0x80 );/* enable PM io space */ +outl (SCI_EN_IOPORT ,inl (SCI_EN_IOPORT ) |GBL_SMI_EN |APMC_EN );Most of the above looks like black magic. It's not like the context of this function is great, most of the existing stuff is poorly documented. Can we get a bit more comments about what's this supposed to do, and maybe a reference to the Intel specification that lists where those PCI config space registers are coming from?
This is a precondition for the (later) switch to ACPI.
First, we set the ACPI I/O registers base - it can be absolutely arbitrary but we choose the same value that was used before for PIIX4 - ACPI_PM1A_EVT_BLK_ADDRESS_V1. The "| 1" part is likely NOT necessary and should be removed unless QEMU has a bug with its handling - according to Intel datasheet, bit0 is "Hardwired to 1 to indicate I/O space", no need to set it explicitly.
At this point we can use ACPI I/O register block at ACPI_PM1A_EVT_BLK_ADDRESS_V1. We are only interested in one register from this range - at offset +30h. SCI_EN_IOPORT is a wrong name actually, it should be renamed to SMI_EN_IOPORT.
Finally, the line
"outl(SCI_EN_IOPORT, inl(SCI_EN_IOPORT) | GBL_SMI_EN | APMC_EN)" enables SMI generation - we will use it later to perform a classic APM -> ACPI switch via a write to the APM_CNT (0B2h) register to trigger an SW SMI, followed by validating SCI_EN=1 to confirm the successful switch.
Basically, all this setup is just a preparation for the step done in the next patch - "hvmloader: add ACPI enabling for Q35".
What I don't remember is who was actually responsible for actual ACPI enabling - either QEMU or firmware.
On real systems it is a bit more complicated - the APM -> ACPI switch is done by an ACPI-aware OS itself (OSPM, how they call it). The OS extracts information from ACPI tables and use it to find out what and where to write in order to switch to ACPI. Under the hood it's still a special value written to the SW SMI register, triggering a SMI handler in the firmware. The actual hand-off to ACPI was done by the SMI handler, including switching the PM interrupt from SMI to ACPI's SCI.
I'm not sure why hvmloader does this switch early instead. But at least this APM -> ACPI switch flow matches the older (PIIX4) one. Perhaps this is how it was handled by QEMU.
Re: [PATCH 07/17] hvmloader: add basic Q35 support
In reply to Thierry EscandeQuoted 4 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +0
-0@@ -209,7 +225,16 @@ void pci_setup(void) {do { isa_irq = (isa_irq +1 ) &15 ; }while ( !(PCI_ISA_IRQ_MASK & (1U << isa_irq)) );
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 236
Quoted 10 lines
tools/firmware/hvmloader/pci.c +9
-1-pci_writeb (PCI_ISA_DEVFN ,0x60 + link, isa_irq); + +if ( is_running_on_q35 ) + { +pci_writeb (PCI_ICH9_LPC_DEVFN ,0x60 + link, isa_irq); + } +else + { +pci_writeb (PCI_ISA_DEVFN ,0x60 + link, isa_irq); + }
Nit: Easier to read imo without the figure braces.
Jan
Re: [PATCH 07/17] hvmloader: add basic Q35 support
Quoted 17 lines · Jan Beulich
Quoted 4 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +0
-0@@ -209,7 +225,16 @@ void pci_setup(void) {do { isa_irq = (isa_irq +1 ) &15 ; }while ( !(PCI_ISA_IRQ_MASK & (1U << isa_irq)) );tools/firmware/hvmloader/pci.c void pci_setup(void) · line 236
Quoted 10 lines
tools/firmware/hvmloader/pci.c +9
-1-pci_writeb (PCI_ISA_DEVFN ,0x60 + link, isa_irq); + +if ( is_running_on_q35 ) + { +pci_writeb (PCI_ICH9_LPC_DEVFN ,0x60 + link, isa_irq); + } +else + { +pci_writeb (PCI_ISA_DEVFN ,0x60 + link, isa_irq); + }Nit: Easier to read imo without the figure braces.
I'll rework that part and use a isa_devfn variable instead.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 8/17 hvmloader: Extend PCI BAR struct
In reply to Thierry EscandeFor the upcoming allocation of the MMCONFIG range in MMIO hole, this patch extends the 'bars' structure to make it universal for any arbitrary BAR type. Either IO, MMIO, ROM or a chipset-specific resource.
One important new field is addr_mask, which tells which bits of the base address can (should) be written. Different address types (ROM, MMIO BAR, PCIEXBAR) will have different addr_mask values.
For every assignable BAR range we store its size, PCI device BDF (devfn actually) to which it belongs, BAR type (mem/io/mem64) and corresponding register offset in device PCI conf space.
Also, to reduce code complexity, all long mem/mem64 BAR flags checks are replaced by simple bars[i] field probing, eg.:
- if ( (bar_reg == PCI_ROM_ADDRESS) ||
- ((bar_data & PCI_BASE_ADDRESS_SPACE) ==
- PCI_BASE_ADDRESS_SPACE_MEMORY) )
+ if ( bars[i].is_mem )
--- tools/firmware/hvmloader/pci.c | 58 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 23 deletions(-)
tools/firmware/hvmloader/pci.c +35 -23
@@ -160,9 +160,10 @@ static void class_specific_pci_device_setup(uint16_t vendor_id,void pci_setup (void ) { -uint8_t is_64bar, using_64bar, bar64_relocate =0 ; +uint8_t is_64bar, using_64bar, bar64_relocate =0 , is_mem;uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper;uint64_t base, bar_sz, bar_sz_upper, mmio_total =0 ; +uint64_t addr_mask;uint8_t vga_devfn =0xff ;uint16_t class, vendor_id, device_id;unsigned int bar, pin, link, isa_irq;
@@ -176,10 +177,13 @@ void pci_setup(void)/* Create a list of device BARs in descending order of size. */ struct bars { -uint32_t is_64bar;uint32_t devfn;uint32_t bar_reg;uint64_t bar_sz; +uint64_t addr_mask;/* which bits of the base address can be written */ +uint32_t bar_data;/* initial value - BAR flags here */ +uint8_t is_64bar; +uint8_t is_mem; } *bars = (struct bars *)scratch_start;unsigned int i, nr_bars =0 ;uint64_t mmio_hole_size =0 ;
@@ -278,13 +282,21 @@ void pci_setup(void) bar_reg =PCI_ROM_ADDRESS ; bar_data =pci_readl (devfn, bar_reg); + + is_mem = !!(((bar_data &PCI_BASE_ADDRESS_SPACE ) == +PCI_BASE_ADDRESS_SPACE_MEMORY ) || + (bar_reg ==PCI_ROM_ADDRESS )); +if ( bar_reg !=PCI_ROM_ADDRESS ) { - is_64bar = !!((bar_data & (PCI_BASE_ADDRESS_SPACE | -PCI_BASE_ADDRESS_MEM_TYPE_MASK )) == - (PCI_BASE_ADDRESS_SPACE_MEMORY | + is_64bar = !!(is_mem && + ((bar_data &PCI_BASE_ADDRESS_MEM_TYPE_MASK ) ==PCI_BASE_ADDRESS_MEM_TYPE_64 )); +pci_writel (devfn, bar_reg, ~0 ); + + addr_mask = is_mem ?PCI_BASE_ADDRESS_MEM_MASK + :PCI_BASE_ADDRESS_IO_MASK ; }else {
@@ -292,15 +304,16 @@ void pci_setup(void)pci_writel (devfn, bar_reg, (bar_data |PCI_ROM_ADDRESS_MASK ) & ~PCI_ROM_ADDRESS_ENABLE ); + + addr_mask =PCI_ROM_ADDRESS_MASK ; } + bar_sz =pci_readl (devfn, bar_reg);pci_writel (devfn, bar_reg, bar_data);if ( bar_reg !=PCI_ROM_ADDRESS ) - bar_sz &= (((bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) ? -PCI_BASE_ADDRESS_MEM_MASK : - (PCI_BASE_ADDRESS_IO_MASK &0xffff )); + bar_sz &= is_mem ?PCI_BASE_ADDRESS_MEM_MASK : + (PCI_BASE_ADDRESS_IO_MASK &0xffff );else bar_sz &=PCI_ROM_ADDRESS_MASK ;if (is_64bar) {
@@ -314,6 +327,9 @@ void pci_setup(void)if ( bar_sz ==0 )continue ; +/* leave only memtype/enable bits etc */ + bar_data &= ~addr_mask; + if ( !xenpci_bar_uc && ((bar_data & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY) &&
@@ -359,16 +375,17 @@ void pci_setup(void)if ( i != nr_bars )memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); - bars[i].is_64bar = is_64bar; bars[i].devfn = devfn; bars[i].bar_reg = bar_reg; bars[i].bar_sz = bar_sz; + bars[i].is_64bar = is_64bar; + bars[i].is_mem = is_mem; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data;if ( is_64bar && bar_sz >BAR_RELOC_THRESH ) bar64_relocate =1 ; -else if ( ((bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) || - (bar_reg ==PCI_ROM_ADDRESS ) ) +else if ( is_mem ) mmio_total += bar_sz; nr_bars++;
@@ -531,10 +548,10 @@ void pci_setup(void) using_64bar = bars[i].is_64bar && bar64_relocate && (mmio_total > (mem_resource.max - mem_resource.base) || bar_sz >BAR_RELOC_THRESH ); - bar_data =pci_readl (devfn, bar_reg); -if ( (bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) + bar_data = bars[i].bar_data; + +if ( bars[i].is_mem ) {/* Mapping high memory if PCI device is 64 bits bar */ if ( using_64bar ) {
@@ -544,11 +561,9 @@ void pci_setup(void)if ( !pci_hi_mem_start ) pci_hi_mem_start = high_mem_resource.base; resource = &high_mem_resource; - bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK ; }else { resource = &mem_resource; - bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK ; }if ( bar_sz <=BAR_RELOC_THRESH ) mmio_total -= bar_sz;
@@ -556,7 +571,6 @@ void pci_setup(void)else { resource = &io_resource; - bar_data &= ~PCI_BASE_ADDRESS_IO_MASK ; } base = (resource->base + bar_sz -1 ) & ~(uint64_t )(bar_sz -1 );
@@ -578,7 +592,7 @@ void pci_setup(void) } } - bar_data |= (uint32_t )base; + bar_data |= (uint32_t ) (base & bars[i].addr_mask); bar_data_upper = (uint32_t )(base >>32 ); base += bar_sz;
@@ -600,9 +614,7 @@ void pci_setup(void)PRIllx_arg (bar_sz), bar_data_upper, bar_data); -if ( (bar_reg ==PCI_ROM_ADDRESS ) || - ((bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) ) +if ( bars[i].is_mem ) pci_devfn_decode_type[devfn] |=PCI_COMMAND_MEMORY ;else pci_devfn_decode_type[devfn] |=PCI_COMMAND_IO ;
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 08/17] hvmloader: Extend PCI BAR struct
Quoted 14 lines · Thierry Escande
For the upcoming allocation of the MMCONFIG range in MMIO hole, this patch extends the 'bars' structure to make it universal for any arbitrary BAR type. Either IO, MMIO, ROM or a chipset-specific resource.
One important new field is
addr_mask, which tells which bits of the base address can (should) be written. Different address types (ROM, MMIO BAR, PCIEXBAR) will have differentaddr_maskvalues.For every assignable BAR range we store its size, PCI device BDF (devfn actually) to which it belongs, BAR type (mem/io/mem64) and corresponding register offset in device PCI conf space.
Also, to reduce code complexity, all long mem/mem64 BAR flags checks are replaced by simple bars[i] field probing, eg.:
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 617
Quoted 4 lines
tools/firmware/hvmloader/pci.c +1
-3-if ( (bar_reg ==PCI_ROM_ADDRESS ) || - ((bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) ) +if ( bars[i].is_mem )
I think this is also supposed to be a non-functional change, just adding new fields and adjusting the code to make use of them?
Quoted 12 lines
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/pci.c | 58 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 23 deletions(-)tools/firmware/hvmloader/pci.c +0
-0
tools/firmware/hvmloader/pci.c static void class_specific_pci_device_setup(uint16_t vendor_id, · line 163
Quoted 5 lines
tools/firmware/hvmloader/pci.c +1
-1@@ -160,9 +160,10 @@ static void class_specific_pci_device_setup(uint16_t vendor_id,void pci_setup (void ) { -uint8_t is_64bar, using_64bar, bar64_relocate =0 ; +uint8_t is_64bar, using_64bar, bar64_relocate =0 , is_mem;
The newly introduce fields want to be booleans types.
Quoted 7 lines
tools/firmware/hvmloader/pci.c +1
-0uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper;uint64_t base, bar_sz, bar_sz_upper, mmio_total =0 ; +uint64_t addr_mask;uint8_t vga_devfn =0xff ;uint16_t class, vendor_id, device_id;unsigned int bar, pin, link, isa_irq;
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 184
Quoted 9 lines
tools/firmware/hvmloader/pci.c +2
-1@@ -176,10 +177,13 @@ void pci_setup(void)/* Create a list of device BARs in descending order of size. */ struct bars { -uint32_t is_64bar;uint32_t devfn;uint32_t bar_reg;uint64_t bar_sz; +uint64_t addr_mask;/* which bits of the base address can be written */ +uint32_t bar_data;/* initial value - BAR flags here */
Hm, that's just storing the flags of the BAR, given that you already store the 64bit and memory flags, you just need the prefetch and ROM enabled booleans to have the full set, and then you can remove the bar_data field from the struct.
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 186
Quoted 2 lines
tools/firmware/hvmloader/pci.c +2
-0+uint8_t is_64bar; +uint8_t is_mem;
Use bool types please for the is_ fields.
Quoted 116 lines
tools/firmware/hvmloader/pci.c +27
-17} *bars = (struct bars *)scratch_start;unsigned int i, nr_bars =0 ;uint64_t mmio_hole_size =0 ;@@ -278,13 +282,21 @@ void pci_setup(void) bar_reg =PCI_ROM_ADDRESS ; bar_data =pci_readl (devfn, bar_reg); + + is_mem = !!(((bar_data &PCI_BASE_ADDRESS_SPACE ) == +PCI_BASE_ADDRESS_SPACE_MEMORY ) || + (bar_reg ==PCI_ROM_ADDRESS )); +if ( bar_reg !=PCI_ROM_ADDRESS ) { - is_64bar = !!((bar_data & (PCI_BASE_ADDRESS_SPACE | -PCI_BASE_ADDRESS_MEM_TYPE_MASK )) == - (PCI_BASE_ADDRESS_SPACE_MEMORY | + is_64bar = !!(is_mem && + ((bar_data &PCI_BASE_ADDRESS_MEM_TYPE_MASK ) ==PCI_BASE_ADDRESS_MEM_TYPE_64 )); +pci_writel (devfn, bar_reg, ~0 ); + + addr_mask = is_mem ?PCI_BASE_ADDRESS_MEM_MASK + :PCI_BASE_ADDRESS_IO_MASK ; }else {@@ -292,15 +304,16 @@ void pci_setup(void)pci_writel (devfn, bar_reg, (bar_data |PCI_ROM_ADDRESS_MASK ) & ~PCI_ROM_ADDRESS_ENABLE ); + + addr_mask =PCI_ROM_ADDRESS_MASK ; } + bar_sz =pci_readl (devfn, bar_reg);pci_writel (devfn, bar_reg, bar_data);if ( bar_reg !=PCI_ROM_ADDRESS ) - bar_sz &= (((bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) ? -PCI_BASE_ADDRESS_MEM_MASK : - (PCI_BASE_ADDRESS_IO_MASK &0xffff )); + bar_sz &= is_mem ?PCI_BASE_ADDRESS_MEM_MASK : + (PCI_BASE_ADDRESS_IO_MASK &0xffff );else bar_sz &=PCI_ROM_ADDRESS_MASK ;if (is_64bar) {@@ -314,6 +327,9 @@ void pci_setup(void)if ( bar_sz ==0 )continue ; +/* leave only memtype/enable bits etc */ + bar_data &= ~addr_mask; + if ( !xenpci_bar_uc && ((bar_data & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY) &&@@ -359,16 +375,17 @@ void pci_setup(void)if ( i != nr_bars )memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); - bars[i].is_64bar = is_64bar; bars[i].devfn = devfn; bars[i].bar_reg = bar_reg; bars[i].bar_sz = bar_sz; + bars[i].is_64bar = is_64bar; + bars[i].is_mem = is_mem; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data;if ( is_64bar && bar_sz >BAR_RELOC_THRESH ) bar64_relocate =1 ; -else if ( ((bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) || - (bar_reg ==PCI_ROM_ADDRESS ) ) +else if ( is_mem ) mmio_total += bar_sz; nr_bars++;@@ -531,10 +548,10 @@ void pci_setup(void) using_64bar = bars[i].is_64bar && bar64_relocate && (mmio_total > (mem_resource.max - mem_resource.base) || bar_sz >BAR_RELOC_THRESH ); - bar_data =pci_readl (devfn, bar_reg); -if ( (bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) + bar_data = bars[i].bar_data; + +if ( bars[i].is_mem ) {/* Mapping high memory if PCI device is 64 bits bar */ if ( using_64bar ) {@@ -544,11 +561,9 @@ void pci_setup(void)if ( !pci_hi_mem_start ) pci_hi_mem_start = high_mem_resource.base; resource = &high_mem_resource; - bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK ; }else { resource = &mem_resource; - bar_data &= ~PCI_BASE_ADDRESS_MEM_MASK ; }if ( bar_sz <=BAR_RELOC_THRESH ) mmio_total -= bar_sz;@@ -556,7 +571,6 @@ void pci_setup(void)else { resource = &io_resource; - bar_data &= ~PCI_BASE_ADDRESS_IO_MASK ; } base = (resource->base + bar_sz -1 ) & ~(uint64_t )(bar_sz -1 );
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 595
Quoted 5 lines
tools/firmware/hvmloader/pci.c +1
-1@@ -578,7 +592,7 @@ void pci_setup(void) } } - bar_data |= (uint32_t )base; + bar_data |= (uint32_t ) (base & bars[i].addr_mask);
^ unintended space?
Thanks, Roger.
Re: [PATCH 08/17] hvmloader: Extend PCI BAR struct
Quoted 20 lines · Roger Pau Monné
Quoted 14 lines · Thierry Escande
For the upcoming allocation of the MMCONFIG range in MMIO hole, this patch extends the 'bars' structure to make it universal for any arbitrary BAR type. Either IO, MMIO, ROM or a chipset-specific resource.
One important new field is
addr_mask, which tells which bits of the base address can (should) be written. Different address types (ROM, MMIO BAR, PCIEXBAR) will have differentaddr_maskvalues.For every assignable BAR range we store its size, PCI device BDF (devfn actually) to which it belongs, BAR type (mem/io/mem64) and corresponding register offset in device PCI conf space.
Also, to reduce code complexity, all long mem/mem64 BAR flags checks are replaced by simple bars[i] field probing, eg.:
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 617
Quoted 4 lines
tools/firmware/hvmloader/pci.c +1
-3-if ( (bar_reg ==PCI_ROM_ADDRESS ) || - ((bar_data &PCI_BASE_ADDRESS_SPACE ) == -PCI_BASE_ADDRESS_SPACE_MEMORY ) ) +if ( bars[i].is_mem )
Quoted 2 lines
I think this is also supposed to be a non-functional change, just adding new fields and adjusting the code to make use of them?
Right. It's preparation work for MMCONFIG area setup in a next patch.
Quoted 14 lines
Quoted 14 lines
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/pci.c | 58 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 23 deletions(-)tools/firmware/hvmloader/pci.c +0
-0@@ -160,9 +160,10 @@ static void class_specific_pci_device_setup(uint16_t vendor_id,
Quoted 6 lines
tools/firmware/hvmloader/pci.c static void class_specific_pci_device_setup(uint16_t vendor_id, · line 163
Quoted 4 lines
tools/firmware/hvmloader/pci.c +1
-1void pci_setup (void ) { -uint8_t is_64bar, using_64bar, bar64_relocate =0 ; +uint8_t is_64bar, using_64bar, bar64_relocate =0 , is_mem;The newly introduce fields want to be booleans types.
Ok. Should I also change the existing ones to bool or this must be in a separate patch?
Quoted 9 lines
Quoted 9 lines
tools/firmware/hvmloader/pci.c +1
-0uint32_t devfn, bar_reg, cmd, bar_data, bar_data_upper;uint64_t base, bar_sz, bar_sz_upper, mmio_total =0 ; +uint64_t addr_mask;uint8_t vga_devfn =0xff ;uint16_t class, vendor_id, device_id;unsigned int bar, pin, link, isa_irq;@@ -176,10 +177,13 @@ void pci_setup(void)
Quoted 13 lines
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 184
Quoted 8 lines
tools/firmware/hvmloader/pci.c +2
-1/* Create a list of device BARs in descending order of size. */ struct bars { -uint32_t is_64bar;uint32_t devfn;uint32_t bar_reg;uint64_t bar_sz; +uint64_t addr_mask;/* which bits of the base address can be written */ +uint32_t bar_data;/* initial value - BAR flags here */ Hm, that's just storing the flags of the BAR, given that you already store the 64bit and memory flags, you just need the prefetch and ROM enabled booleans to have the full set, and then you can remove the
bar_datafield from the struct.
Do you mean reading the bar data from their registers in the resource assignation loop instead of using the bar_data field? Storing it in this struct saves a few back and forth with Qemu.
Or I didn't get the point...
Quoted 5 lines
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 186
Quoted 3 lines
tools/firmware/hvmloader/pci.c +2
-0+uint8_t is_64bar; +uint8_t is_mem;Use bool types please for the
is_fields.
Sure.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 08/17] hvmloader: Extend PCI BAR struct
In reply to Thierry Escandetools/firmware/hvmloader/pci.c void pci_setup(void) · line 184
Quoted 10 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +2
-1@@ -176,10 +177,13 @@ void pci_setup(void)/* Create a list of device BARs in descending order of size. */ struct bars { -uint32_t is_64bar;uint32_t devfn;uint32_t bar_reg;uint64_t bar_sz; +uint64_t addr_mask;/* which bits of the base address can be written */ +uint32_t bar_data;/* initial value - BAR flags here */
Nit: Comment style again (also elsewhere).
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 288
Quoted 8 lines
tools/firmware/hvmloader/pci.c +4
-0@@ -278,13 +282,21 @@ void pci_setup(void) bar_reg =PCI_ROM_ADDRESS ; bar_data =pci_readl (devfn, bar_reg); + + is_mem = !!(((bar_data &PCI_BASE_ADDRESS_SPACE ) == +PCI_BASE_ADDRESS_SPACE_MEMORY ) || + (bar_reg ==PCI_ROM_ADDRESS ));
Nit: Indentation (pending open parentheses want to be reflected by extra indenting blanks). With, as requested by Roger, is_mem switched to bool, the !! also can go away, and with it perhaps one pair of parentheses.
(I realize pre-existing code further down has similar issues, yet when such code is touched - and even more so when new code is added - this wants getting right, to aid readability.)
Jan
Re: [PATCH 08/17] hvmloader: Extend PCI BAR struct
Quoted 27 lines · Jan Beulich
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 184
Quoted 10 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +2
-1@@ -176,10 +177,13 @@ void pci_setup(void)/* Create a list of device BARs in descending order of size. */ struct bars { -uint32_t is_64bar;uint32_t devfn;uint32_t bar_reg;uint64_t bar_sz; +uint64_t addr_mask;/* which bits of the base address can be written */ +uint32_t bar_data;/* initial value - BAR flags here */ Nit: Comment style again (also elsewhere).
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 288
Quoted 8 lines
tools/firmware/hvmloader/pci.c +4
-0@@ -278,13 +282,21 @@ void pci_setup(void) bar_reg =PCI_ROM_ADDRESS ; bar_data =pci_readl (devfn, bar_reg); + + is_mem = !!(((bar_data &PCI_BASE_ADDRESS_SPACE ) == +PCI_BASE_ADDRESS_SPACE_MEMORY ) || + (bar_reg ==PCI_ROM_ADDRESS ));Nit: Indentation (pending open parentheses want to be reflected by extra indenting blanks). With, as requested by Roger,
is_memswitched to bool, the !! also can go away, and with it perhaps one pair of parentheses.
Quoted 4 lines
(I realize pre-existing code further down has similar issues, yet when such code is touched - and even more so when new code is added - this wants getting right, to aid readability.)
I wanted to keep the changes as small as possible. But it's ok for me to fix that.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 9/17 xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
In reply to Thierry EscandeThis patch adds 2 HVMOP hypercalls, HVMOP_get|set_ecam_space, used to set and get the base address and size of the PCIe ECAM space as configured by hvmloader.
--- xen/arch/x86/hvm/hvm.c | 52 +++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/domain.h | 4 +++ xen/include/public/hvm/hvm_op.h | 11 +++++++ 3 files changed, 67 insertions(+)
xen/arch/x86/hvm/hvm.c +52 -0
@@ -5195,6 +5195,58 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = current->hcall_compat ?compat_altp2m_op (arg) :do_altp2m_op (arg);break ; +case HVMOP_set_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( d->arch.ecam_addr ) { +rcu_unlock_domain (d); +return -EFAULT ; + } + +if ( (ecam.size >>28 ) || (!ecam.addr) ) { +rcu_unlock_domain (d); +return -EINVAL ; + } + + d->arch.ecam_addr = ecam.addr; + d->arch.ecam_size = ecam.size; + +rcu_unlock_domain (d); +break ; + } + +case HVMOP_get_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( ! d->arch.ecam_addr || ! d->arch.ecam_size ) { +rcu_unlock_domain (d); +return -EINVAL ; + } + + ecam.addr = d->arch.ecam_addr; + ecam.size = d->arch.ecam_size; + rc =__copy_to_guest (arg, &ecam,1 ) ? -EFAULT :0 ; + +rcu_unlock_domain (d); +break ; + } +default : rc = -ENOSYS ;break ;
xen/arch/x86/include/asm/domain.h +4 -0
@@ -476,6 +476,10 @@ struct arch_domain/* Emulated devices enabled bitmap. */ uint32_t emulation_flags; + +/* PCI ECAM space emulation */ +uint64_t ecam_addr; +uint32_t ecam_size; } __cacheline_aligned;#ifdef CONFIG_HVM
xen/include/public/hvm/hvm_op.h +11 -0
@@ -166,6 +166,17 @@ struct xen_hvm_get_mem_type {typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_get_mem_type_t); +#define HVMOP_set_ecam_space 16 +#define HVMOP_get_ecam_space 17 +struct xen_hvm_ecam_space { +domid_t domid; +uint16_t pad[3 ];/* align next field on 8-byte boundary */ +uint64_t addr; +uint32_t size; +}; +typedef struct xen_hvm_ecam_space xen_hvm_ecam_space_t ; +DEFINE_XEN_GUEST_HANDLE (xen_hvm_ecam_space_t); +/* Following tools-only interfaces may change in future. */ #if defined(__XEN__) || defined(__XEN_TOOLS__)
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 09/17] xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
Quoted 16 lines · Thierry Escande
This patch adds 2 HVMOP hypercalls, HVMOP_get|set_ecam_space, used to set and get the base address and size of the PCIe ECAM space as configured by hvmloader.
Signed-off-by Thierry Escande <[email protected]>--- xen/arch/x86/hvm/hvm.c | 52 +++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/domain.h | 4 +++ xen/include/public/hvm/hvm_op.h | 11 +++++++ 3 files changed, 67 insertions(+)xen/arch/x86/hvm/hvm.c +0
-0
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5202
Quoted 8 lines
xen/arch/x86/hvm/hvm.c +5
-0@@ -5195,6 +5195,58 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = current->hcall_compat ?compat_altp2m_op (arg) :do_altp2m_op (arg);break ; +case HVMOP_set_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) )
^ extra space, here and at the
closing parenthesis.
Line length is also past the 80 character limit, same below in HVMOP_get_ecam_space.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5203
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+return -EFAULT ;
This operation (and the matching get variant) needs an XSM check.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5209
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+ + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( d->arch.ecam_addr ) {
Coding style, opening braces should be on a new line.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5211
Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2
-0+rcu_unlock_domain (d); +return -EFAULT ;
This would better return -EBUSY
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5212
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+ }
You also need to check the padding fields are 0.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5214
Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2
-0+ +if ( (ecam.size >>28 ) || (!ecam.addr) ) {
^ the parenthesis here are unneeded.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5220
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+rcu_unlock_domain (d); +return -EINVAL ; + } + + d->arch.ecam_addr = ecam.addr; + d->arch.ecam_size = ecam.size;
I'm a bit worried about a domain being able to set it's own ECAM hole, assessing all the side-effects of this might be complex.
Won't the code here better check the region passed in the hypercall is indeed not mapped in the p2m, so that trapping of ECAM accesses works as expected?
Also, how does the ECAM hole get setup on native? I assume there are some magic registers in the PCI config space of a platform device that the firmware uses to position the ECAM space?
Are those trapped by QEMU, in which case won't it be better to do it the native way (iow: with the config space registers), and let QEMU forward it to Xen? It would then be QEMU the one to call HVMOP_set_ecam_space (or whatever hypercall we end up using).
Quoted 37 lines
xen/arch/x86/hvm/hvm.c +29
-0+ +rcu_unlock_domain (d); +break ; + } + +case HVMOP_get_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( ! d->arch.ecam_addr || ! d->arch.ecam_size ) { +rcu_unlock_domain (d); +return -EINVAL ; + } + + ecam.addr = d->arch.ecam_addr; + ecam.size = d->arch.ecam_size; + rc =__copy_to_guest (arg, &ecam,1 ) ? -EFAULT :0 ; + +rcu_unlock_domain (d); +break ; + } +default : rc = -ENOSYS ;break ;xen/arch/x86/include/asm/domain.h +0
-0
xen/arch/x86/include/asm/domain.h struct arch_domain · line 482
Quoted 7 lines
xen/arch/x86/include/asm/domain.h +4
-0@@ -476,6 +476,10 @@ struct arch_domain/* Emulated devices enabled bitmap. */ uint32_t emulation_flags; + +/* PCI ECAM space emulation */ +uint64_t ecam_addr; +uint32_t ecam_size;
This fields would better be in hvm_domain struct, and there you already have the mmcfg_regions list, which we should aim to use for the q35 introduced ECAM region.
Quoted 8 lines
xen/arch/x86/include/asm/domain.h +0
-0} __cacheline_aligned;#ifdef CONFIG_HVM xen/include/public/hvm/hvm_op.h +0
-0
xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 175
Quoted 10 lines
xen/include/public/hvm/hvm_op.h +7
-0@@ -166,6 +166,17 @@ struct xen_hvm_get_mem_type {typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_get_mem_type_t); +#define HVMOP_set_ecam_space 16 +#define HVMOP_get_ecam_space 17 +struct xen_hvm_ecam_space { +domid_t domid; +uint16_t pad[3 ];/* align next field on 8-byte boundary */ +uint64_t addr; +uint32_t size;
There's also a trailing uint32_t padding here on 64bit builds I think?
FWIW, you could do:
domid_t domid;
uint16_t pad;
uint32_t size
uint64_t addr;As that would reduce the padding in the struct?
Thanks, Roger.
Re: [PATCH 09/17] xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
Quoted 31 lines · Roger Pau Monné
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5202
Quoted 11 lines · Thierry Escande
xen/arch/x86/hvm/hvm.c +5
-0@@ -5195,6 +5195,58 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = current->hcall_compat ?compat_altp2m_op (arg) :do_altp2m_op (arg);break ; +case HVMOP_set_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) )^ extra space, here and at the
closing parenthesis.Line length is also past the 80 character limit, same below in
HVMOP_get_ecam_space.xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5203
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+return -EFAULT ;This operation (and the matching get variant) needs an XSM check.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5209
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+ + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( d->arch.ecam_addr ) {Coding style, opening braces should be on a new line.
Quoted 4 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5211
Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2
-0+rcu_unlock_domain (d); +return -EFAULT ;This would better return
-EBUSY
I agree, yet I'd like to suggest that this may want changing further: If one can "set" the address, shouldn't one also be able to "clear" it? That could (pretty) naturally be expressed by ecam.addr being 0 in the request. Which would then require permitting non-0 .ecam_addr in that specific case.
Quoted 14 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5214
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+if ( (ecam.size >>28 ) || (!ecam.addr) ) {^ the parenthesis here are unneeded.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5220
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+rcu_unlock_domain (d); +return -EINVAL ; + } + + d->arch.ecam_addr = ecam.addr; + d->arch.ecam_size = ecam.size;I'm a bit worried about a domain being able to set it's own ECAM hole, assessing all the side-effects of this might be complex.
Quoted 7 lines
Won't the code here better check the region passed in the hypercall is indeed not mapped in the p2m, so that trapping of ECAM accesses works as expected?
Also, how does the ECAM hole get setup on native? I assume there are some magic registers in the PCI config space of a platform device that the firmware uses to position the ECAM space?
That may even be outside of any device's config space, e.g. custom MMIO. I didn't check, but I guess that may also be the case for Q35.
Jan
Re: [PATCH 09/17] xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
In reply to Roger Pau MonnéQuoted 28 lines · Roger Pau Monné
Quoted 16 lines · Thierry Escande
This patch adds 2 HVMOP hypercalls, HVMOP_get|set_ecam_space, used to set and get the base address and size of the PCIe ECAM space as configured by hvmloader.
Signed-off-by Thierry Escande <[email protected]>--- xen/arch/x86/hvm/hvm.c | 52 +++++++++++++++++++++++++++++++ xen/arch/x86/include/asm/domain.h | 4 +++ xen/include/public/hvm/hvm_op.h | 11 +++++++ 3 files changed, 67 insertions(+)xen/arch/x86/hvm/hvm.c +0
-0xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5202
Quoted 8 lines
xen/arch/x86/hvm/hvm.c +5
-0@@ -5195,6 +5195,58 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = current->hcall_compat ?compat_altp2m_op (arg) :do_altp2m_op (arg);break ; +case HVMOP_set_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) )^ extra space, here and at the
closing parenthesis.
Quoted 2 lines
Line length is also past the 80 character limit, same below in
HVMOP_get_ecam_space.
Ok.
Quoted 4 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5203
Quoted 2 lines
xen/arch/x86/hvm/hvm.c +1
-0+return -EFAULT ;This operation (and the matching get variant) needs an XSM check.
I'm not familiar with XSM. Does that imply to add a new flask hook ? Extend an existing one ?
Quoted 31 lines
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5209
Quoted 7 lines
xen/arch/x86/hvm/hvm.c +6
-0+ + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( d->arch.ecam_addr ) {Coding style, opening braces should be on a new line.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5211
Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2
-0+rcu_unlock_domain (d); +return -EFAULT ;This would better return
-EBUSYxen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5212
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+ }You also need to check the padding fields are 0.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5214
Quoted 2 lines
xen/arch/x86/hvm/hvm.c +2
-0+ +if ( (ecam.size >>28 ) || (!ecam.addr) ) {^ the parenthesis here are unneeded.
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5220
Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6
-0+rcu_unlock_domain (d); +return -EINVAL ; + } + + d->arch.ecam_addr = ecam.addr; + d->arch.ecam_size = ecam.size;
Quoted 2 lines
I'm a bit worried about a domain being able to set it's own ECAM hole, assessing all the side-effects of this might be complex.
Would it be related to the XSM check you mentioned earlier to avoid the guest to use the set hypercall?
Quoted 4 lines
Won't the code here better check the region passed in the hypercall is indeed not mapped in the p2m, so that trapping of ECAM accesses works as expected?
Well, it is mapped as p2m_mmio_dm. Do you mean adding a check to make sure it's mapped correctly or not mapped?
Quoted 4 lines
Also, how does the ECAM hole get setup on native? I assume there are some magic registers in the PCI config space of a platform device that the firmware uses to position the ECAM space?
ASAIU, the guest kernel gets the MMCONFIG area info via the ACPI MFCG table and checks if the range is reserved in the 820 table. If ACPI is disabled, it uses the PCI_MCH_PCIEXBAR register (0x60) of the bdf 000.
Quoted 5 lines
Are those trapped by QEMU, in which case won't it be better to do it the native way (iow: with the config space registers), and let QEMU forward it to Xen? It would then be QEMU the one to call
HVMOP_set_ecam_space(or whatever hypercall we end up using).
Yes, setting the PCI_MCH_PCIEXBAR register lands in Qemu. So it is possible to do the hypercall from Qemu. I didn't do it that way to (lazily) avoid big changes in Qemu. And that would also be better if the guest modifies the PCI_MCH_PCIEXBAR register for whatever reason.
Quoted 39 lines
Quoted 39 lines
xen/arch/x86/hvm/hvm.c +29
-0+ +rcu_unlock_domain (d); +break ; + } + +case HVMOP_get_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( ! d->arch.ecam_addr || ! d->arch.ecam_size ) { +rcu_unlock_domain (d); +return -EINVAL ; + } + + ecam.addr = d->arch.ecam_addr; + ecam.size = d->arch.ecam_size; + rc =__copy_to_guest (arg, &ecam,1 ) ? -EFAULT :0 ; + +rcu_unlock_domain (d); +break ; + } +default : rc = -ENOSYS ;break ;xen/arch/x86/include/asm/domain.h +0
-0@@ -476,6 +476,10 @@ struct arch_domain
Quoted 10 lines
xen/arch/x86/include/asm/domain.h struct arch_domain · line 482
Quoted 6 lines
xen/arch/x86/include/asm/domain.h +4
-0/* Emulated devices enabled bitmap. */ uint32_t emulation_flags; + +/* PCI ECAM space emulation */ +uint64_t ecam_addr; +uint32_t ecam_size;This fields would better be in
hvm_domainstruct, and there you already have themmcfg_regionslist, which we should aim to use for the q35 introduced ECAM region.
Ok.
Quoted 22 lines
Quoted 9 lines
xen/arch/x86/include/asm/domain.h +0
-0} __cacheline_aligned;#ifdef CONFIG_HVM xen/include/public/hvm/hvm_op.h +0
-0xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 175
Quoted 10 lines
xen/include/public/hvm/hvm_op.h +7
-0@@ -166,6 +166,17 @@ struct xen_hvm_get_mem_type {typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_get_mem_type_t); +#define HVMOP_set_ecam_space 16 +#define HVMOP_get_ecam_space 17 +struct xen_hvm_ecam_space { +domid_t domid; +uint16_t pad[3 ];/* align next field on 8-byte boundary */ +uint64_t addr; +uint32_t size;There's also a trailing
uint32_tpadding here on 64bit builds I think?
Quoted 8 lines
FWIW, you could do:
domid_t domid; uint16_t pad; uint32_t size uint64_t addr;As that would reduce the padding in the struct?
Indeed, that seems better.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 09/17] xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
In reply to Thierry EscandeQuoted 5 lines · Thierry Escande
This patch adds 2 HVMOP hypercalls, HVMOP_get|set_ecam_space, used to set and get the base address and size of the PCIe ECAM space as configured by hvmloader.
Signed-off-by Thierry Escande <[email protected]>
Just in case we want to stick to these (see Roger's earlier comments throughout the series), a few remarks here:
Quoted 19 lines
xen/arch/x86/hvm/hvm.c +13
-0@@ -5195,6 +5195,58 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = current->hcall_compat ?compat_altp2m_op (arg) :do_altp2m_op (arg);break ; +case HVMOP_set_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( d->arch.ecam_addr ) { +rcu_unlock_domain (d);
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5220
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+return -EFAULT ; + } + +if ( (ecam.size >>28 ) || (!ecam.addr) ) { +rcu_unlock_domain (d); +return -EINVAL ; + } + + d->arch.ecam_addr = ecam.addr; + d->arch.ecam_size = ecam.size;
Shorter (and easier to follow as well as less error prone as to the rcu_unlock_domain())
if ( d->arch.ecam_addr )
rc = -E...;
else if ( (ecam.size >> 28) || !ecam.addr )
rc = -EINVAL;
else
{
d->arch.ecam_addr = ecam.addr;
d->arch.ecam_size = ecam.size;
}all utilizing ...
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5221
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+rcu_unlock_domain (d);
... this.
The magic 28 also needs (a) explaining and/or (b) abstracting (a suitably named #define might address both).
xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 173
Quoted 11 lines
xen/include/public/hvm/hvm_op.h +5
-0@@ -166,6 +166,17 @@ struct xen_hvm_get_mem_type {typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_get_mem_type_t); +#define HVMOP_set_ecam_space 16 +#define HVMOP_get_ecam_space 17 +struct xen_hvm_ecam_space { +domid_t domid; +uint16_t pad[3 ];/* align next field on 8-byte boundary */
The comment, as is, is wrong for 32-bit HVM guests: There ...
xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 174
Quoted 1 line
xen/include/public/hvm/hvm_op.h +1
-0+uint64_t addr;
... this is only 4-byte aligned, and hence the entire structure only has 4-byte alignment, and hence the padding also only guarantees 4- byte alignment.
Jan
Re: [PATCH 09/17] xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
Quoted 53 lines · Jan Beulich
Quoted 5 lines · Thierry Escande
This patch adds 2 HVMOP hypercalls, HVMOP_get|set_ecam_space, used to set and get the base address and size of the PCIe ECAM space as configured by hvmloader.
Signed-off-by Thierry Escande <[email protected]>Just in case we want to stick to these (see Roger's earlier comments throughout the series), a few remarks here:
Quoted 19 lines
xen/arch/x86/hvm/hvm.c +13
-0@@ -5195,6 +5195,58 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) rc = current->hcall_compat ?compat_altp2m_op (arg) :do_altp2m_op (arg);break ; +case HVMOP_set_ecam_space: { +xen_hvm_ecam_space_t ecam; +struct domain *d; + +if (copy_from_guest ( &ecam,guest_handle_cast (arg, xen_hvm_ecam_space_t),1 ) ) +return -EFAULT ; + + d =rcu_lock_domain_by_any_id (ecam.domid); +if ( d ==NULL ) +return -ESRCH ; + +if ( d->arch.ecam_addr ) { +rcu_unlock_domain (d);xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5220
Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10
-0+return -EFAULT ; + } + +if ( (ecam.size >>28 ) || (!ecam.addr) ) { +rcu_unlock_domain (d); +return -EINVAL ; + } + + d->arch.ecam_addr = ecam.addr; + d->arch.ecam_size = ecam.size;Shorter (and easier to follow as well as less error prone as to the
rcu_unlock_domain())if ( d->arch.ecam_addr ) rc = -E...; else if ( (ecam.size >> 28) || !ecam.addr ) rc = -EINVAL; else { d->arch.ecam_addr = ecam.addr; d->arch.ecam_size = ecam.size; }
Quoted 5 lines
all utilizing ...
xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5221
Quoted 1 line
xen/arch/x86/hvm/hvm.c +1
-0+rcu_unlock_domain (d);... this.
Will rework that part.
Quoted 18 lines
The magic 28 also needs (a) explaining and/or (b) abstracting (a suitably named #define might address both).
xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 173
Quoted 11 lines
xen/include/public/hvm/hvm_op.h +5
-0@@ -166,6 +166,17 @@ struct xen_hvm_get_mem_type {typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_get_mem_type_t); +#define HVMOP_set_ecam_space 16 +#define HVMOP_get_ecam_space 17 +struct xen_hvm_ecam_space { +domid_t domid; +uint16_t pad[3 ];/* align next field on 8-byte boundary */ The comment, as is, is wrong for 32-bit HVM guests: There ...
Quoted 5 lines
xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 174
Quoted 1 line
xen/include/public/hvm/hvm_op.h +1
-0+uint64_t addr;... this is only 4-byte aligned, and hence the entire structure only has 4-byte alignment, and hence the padding also only guarantees 4- byte alignment.
Right. Roger proposal fixes it:
domid_t domid;
uint16_t pad;
uint32_t size
uint64_t addr;Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 09/17] xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
Quoted 22 lines · Thierry Escande
Quoted 15 lines · Jan Beulich
xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 173
Quoted 11 lines · Thierry Escande
xen/include/public/hvm/hvm_op.h +5
-0@@ -166,6 +166,17 @@ struct xen_hvm_get_mem_type {typedef struct xen_hvm_get_mem_type xen_hvm_get_mem_type_t ;DEFINE_XEN_GUEST_HANDLE (xen_hvm_get_mem_type_t); +#define HVMOP_set_ecam_space 16 +#define HVMOP_get_ecam_space 17 +struct xen_hvm_ecam_space { +domid_t domid; +uint16_t pad[3 ];/* align next field on 8-byte boundary */ The comment, as is, is wrong for 32-bit HVM guests: There ...
Quoted 5 lines
xen/include/public/hvm/hvm_op.h struct xen_hvm_get_mem_type { · line 174
Quoted 1 line
xen/include/public/hvm/hvm_op.h +1
-0+uint64_t addr;... this is only 4-byte aligned, and hence the entire structure only has 4-byte alignment, and hence the padding also only guarantees 4- byte alignment.
Quoted 5 lines
Right. Roger proposal fixes it:
domid_t domid; uint16_t pad; uint32_t size uint64_t addr;
By not having the bogus comment, yes. It doesn't fix the alignment aspect, yet that may also not be important here in the end.
Jan
PATCH 10/17 hvmloader: Add support for HVMOP_set|get_ecam_space hypercalls
In reply to Thierry EscandeThis patch adds wrappers in hvmloader for the hypercalls used to set and get the ECAM space base address and size.
--- tools/firmware/hvmloader/util.c | 26 ++++++++++++++++++++++++++ tools/firmware/hvmloader/util.h | 4 ++++ 2 files changed, 30 insertions(+)
tools/firmware/hvmloader/util.c +26 -0
@@ -690,6 +690,32 @@ error:BUG (); } +int hvm_set_ecam_space (uint64_t addr,uint32_t size) +{ +xen_hvm_ecam_space_t ecam; + + ecam.domid =DOMID_SELF ; + ecam.addr = addr; + ecam.size = size; +return hypercall_hvm_op (HVMOP_set_ecam_space, &ecam); +} + +int hvm_get_ecam_space (uint64_t *addr,uint32_t *size) +{ +struct xen_hvm_ecam_space e = { }; +int ret; + + e.domid =DOMID_SELF ; + + ret =hypercall_hvm_op (HVMOP_get_ecam_space, &e); +if ( ret ==0 ) { + *addr = e.addr; + *size = e.size; + } + +return ret; +} +static void validate_hvm_info (struct hvm_info_table *t) {uint8_t *ptr = (uint8_t *)t;
tools/firmware/hvmloader/util.h +4 -0
@@ -403,6 +403,10 @@ struct acpi_config;void hvmloader_acpi_build_tables (struct acpi_config *config,unsigned int physical); +/* Pass ecam space information to Xen */ +int hvm_get_ecam_space (uint64_t *addr,uint32_t *size); +int hvm_set_ecam_space (uint64_t addr,uint32_t size); +#endif /* __HVMLOADER_UTIL_H__ */ /*
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 10/17] hvmloader: Add support for HVMOP_set|get_ecam_space hypercalls
Quoted 2 lines · Thierry Escande
This patch adds wrappers in hvmloader for the hypercalls used to set and get the ECAM space base address and size.
This would better be introduced with at least one user, as otherwise it's just unreachable code. And then I'm not convinced we should use hypercalls to set the ECAM position/size from hvmloader, if it can be done using the native registers and QEMU can forward those to Xen.
Thanks, Roger.
PATCH 11/17 hvmloader: allocate MMCONFIG area in the MMIO hole
In reply to Thierry EscandeThe actual MMCONFIG size depends on the number of PCI buses available which should be covered by ECAM. Possible options are 64MB, 128MB and 256MB. As Xen is limited to the bus 0 currently, the lowest possible setting is used (64MB), defined via PCI_MAX_MCFG_BUSES in hvmloader/config.h. When multiple PCI buses support for Xen will be implemented, PCI_MAX_MCFG_BUSES may be replaced by a calculation of the number of buses according to PCI devices enumeration.
The MMCONFIG entry is inserted into bars array in the same manner like for any other BARs. In this case, the devfn field will point to MCH PCI device and bar_reg will contain PCIEXBAR register offset. It will be assigned a slot in the MMIO hole later in a very same way like for plain PCI BARs, with respect to its size and alignment. At this point, the actual base address and size of the ECAM space are passed to Xen using the HVMOP_set_ecam_space hypercall.
--- tools/firmware/hvmloader/config.h | 4 +++ tools/firmware/hvmloader/pci.c | 55 +++++++++++++++++++++++++++++ tools/firmware/hvmloader/pci_regs.h | 7 ++++ 3 files changed, 66 insertions(+)
tools/firmware/hvmloader/config.h +4 -0
@@ -55,6 +55,10 @@ extern uint32_t *cpu_to_apicid;#define PCI_ISA_DEVFN 0x08/* dev 1, fn 0 */ #define PCI_ISA_IRQ_MASK 0x0c20U/* ISA IRQs 5,10,11 are PCI connected */ #define PCI_ICH9_LPC_DEVFN 0xf8/* dev 31, fn 0 */ +#define PCI_MCH_DEVFN 0/* bus 0, dev 0, func 0 */ + +/* possible values are: 64, 128, 256 */ +#define PCI_MAX_MCFG_BUSES 64#define ACPI_TIS_HDR_ADDRESS 0xFED40F00UL
tools/firmware/hvmloader/pci.c +55 -0
67 lines not on this page · raw message
tools/firmware/hvmloader/pci_regs.h +7 -0
@@ -116,6 +116,13 @@#define PCI_CLASS_BRIDGE_OTHER 0x0680#define PCI_CLASS_BRIDGE_ISA 0x0601 +#define PCI_MCH_PCIEXBAR 0x60 + +#define PCIEXBAR_64_BUSES 0x04 +#define PCIEXBAR_128_BUSES 0x02 +#define PCIEXBAR_256_BUSES 0x00 +#define PCIEXBAR_ENABLE 0x01 +#endif /* __HVMLOADER_PCI_REGS_H__ */ /*
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 11/17] hvmloader: allocate MMCONFIG area in the MMIO hole
Quoted 3 lines · Thierry Escande
The actual MMCONFIG size depends on the number of PCI buses available which should be covered by ECAM. Possible options are 64MB, 128MB and 256MB.
Are such values inherited from the real q35 impleemntation?
AFAICT the ACPI MCFG spec notes:
"The size of the memory mapped configuration region is indicated by the start and end bus number fields in the Memory mapped Enhanced configuration space base address allocation structure as shown in Table 4-3. 0-255 is the range of allowed bus numbers supported for a given PCI Segment Group."
So it's in principle possible to specify a MCFG that covers a single bus, and then it would have a size of 256 * 4K = 1M. Which avoids wasting 63M of MMIO space in the low MMIO hole that's already fairly tight on space.
Is this limitation possibly inherited from the way the ECAM region position and size must be notified to the chipset?
And further seeing the code below - I found the answer myself, it's because the chipset only supports negotiation those ECAM sizes. We could possibly expose a smaller region in MCFG, but doesn't seem like a good move.
Quoted 86 lines
As Xen is limited to the bus 0 currently, the lowest possible setting is used (64MB), defined via
PCI_MAX_MCFG_BUSESinhvmloader/config.h. When multiple PCI buses support for Xen will be implemented,PCI_MAX_MCFG_BUSESmay be replaced by a calculation of the number of buses according to PCI devices enumeration.The MMCONFIG entry is inserted into bars array in the same manner like for any other BARs. In this case, the devfn field will point to MCH PCI device and
bar_regwill contain PCIEXBAR register offset. It will be assigned a slot in the MMIO hole later in a very same way like for plain PCI BARs, with respect to its size and alignment. At this point, the actual base address and size of the ECAM space are passed to Xen using theHVMOP_set_ecam_spacehypercall.Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/config.h | 4 +++ tools/firmware/hvmloader/pci.c | 55 +++++++++++++++++++++++++++++ tools/firmware/hvmloader/pci_regs.h | 7 ++++ 3 files changed, 66 insertions(+)tools/firmware/hvmloader/config.h +4
-0@@ -55,6 +55,10 @@ extern uint32_t *cpu_to_apicid;#define PCI_ISA_DEVFN 0x08/* dev 1, fn 0 */ #define PCI_ISA_IRQ_MASK 0x0c20U/* ISA IRQs 5,10,11 are PCI connected */ #define PCI_ICH9_LPC_DEVFN 0xf8/* dev 31, fn 0 */ +#define PCI_MCH_DEVFN 0/* bus 0, dev 0, func 0 */ + +/* possible values are: 64, 128, 256 */ +#define PCI_MAX_MCFG_BUSES 64#define ACPI_TIS_HDR_ADDRESS 0xFED40F00ULtools/firmware/hvmloader/pci.c +41
-0@@ -413,6 +413,58 @@ void pci_setup(void) pci_devfn_decode_type[devfn] |=PCI_COMMAND_MASTER ; } +/* +* Calculate MMCONFIG area size and squeeze it into the bars array +* for assigning a slot in the MMIO hole +*/ +if ( is_running_on_q35 ) + { +/* disable PCIEXBAR decoding for now */ +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR ,0 ); +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR +4 ,0 ); + +switch (PCI_MAX_MCFG_BUSES ) + { +case 64 : + bar_data =PCIEXBAR_64_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (64 ); +break ; + +case 128 : + bar_data =PCIEXBAR_128_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (128 ); +break ; + +case 256 : + bar_data =PCIEXBAR_256_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (256 ); +break ; + +default : +/* unsupported number of buses specified */ +BUG (); + } + + addr_mask = ~(bar_sz -1 ); + +for ( i =0 ; i < nr_bars; i++ ) +if ( bars[i].bar_sz < bar_sz ) +break ; + +if ( i != nr_bars ) +memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); +
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 466
Quoted 10 lines
tools/firmware/hvmloader/pci.c +10
-0+ bars[i].is_mem =1 ; + bars[i].devfn =PCI_MCH_DEVFN ; + bars[i].bar_reg =PCI_MCH_PCIEXBAR ; + bars[i].bar_sz = bar_sz; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data; + + mmio_total += bar_sz; + nr_bars++; + }
I think it might be best if the ECAM fake BAR is the first element in the bars array, so we ensure it's the first item to consume memory from the low MMIO hole. Not sure how that will work with the current sorting of the resources based on their size, but it's imperative for hvmloader to attempt to position ECAM ahead of the other device resources IMO.
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 648
Quoted 10 lines
tools/firmware/hvmloader/pci.c +3
-0+if ( mmio_hole_size ) {uint64_t max_ram_below_4g =GB (4 ) - mmio_hole_size;@@ -592,6 +644,9 @@ void pci_setup(void) } } +if ( bar_reg ==PCI_MCH_PCIEXBAR ) +hvm_set_ecam_space (base, bar_sz);
As noted in a previous patch, it would be better if it's QEMU (as part of handling the PCI_MCH_PCIEXBAR writes) that notifies Xen of the ECAM window placement.
Thanks, Roger.
Re: [PATCH 11/17] hvmloader: allocate MMCONFIG area in the MMIO hole
Quoted 57 lines · Roger Pau Monné
Quoted 56 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +50
-0@@ -413,6 +413,58 @@ void pci_setup(void) pci_devfn_decode_type[devfn] |=PCI_COMMAND_MASTER ; } +/* +* Calculate MMCONFIG area size and squeeze it into the bars array +* for assigning a slot in the MMIO hole +*/ +if ( is_running_on_q35 ) + { +/* disable PCIEXBAR decoding for now */ +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR ,0 ); +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR +4 ,0 ); + +switch (PCI_MAX_MCFG_BUSES ) + { +case 64 : + bar_data =PCIEXBAR_64_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (64 ); +break ; + +case 128 : + bar_data =PCIEXBAR_128_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (128 ); +break ; + +case 256 : + bar_data =PCIEXBAR_256_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (256 ); +break ; + +default : +/* unsupported number of buses specified */ +BUG (); + } + + addr_mask = ~(bar_sz -1 ); + +for ( i =0 ; i < nr_bars; i++ ) +if ( bars[i].bar_sz < bar_sz ) +break ; + +if ( i != nr_bars ) +memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); + + bars[i].is_mem =1 ; + bars[i].devfn =PCI_MCH_DEVFN ; + bars[i].bar_reg =PCI_MCH_PCIEXBAR ; + bars[i].bar_sz = bar_sz; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data; + + mmio_total += bar_sz; + nr_bars++;
Quoted 8 lines
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 466
Quoted 1 line
tools/firmware/hvmloader/pci.c +1
-0+ }I think it might be best if the ECAM fake BAR is the first element in the bars array, so we ensure it's the first item to consume memory from the low MMIO hole. Not sure how that will work with the current sorting of the resources based on their size, but it's imperative for hvmloader to attempt to position ECAM ahead of the other device resources IMO.
Why would this be?
Jan
Re: [PATCH 11/17] hvmloader: allocate MMCONFIG area in the MMIO hole
Quoted 67 lines · Jan Beulich
Quoted 57 lines · Roger Pau Monné
Quoted 56 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +50
-0@@ -413,6 +413,58 @@ void pci_setup(void) pci_devfn_decode_type[devfn] |=PCI_COMMAND_MASTER ; } +/* +* Calculate MMCONFIG area size and squeeze it into the bars array +* for assigning a slot in the MMIO hole +*/ +if ( is_running_on_q35 ) + { +/* disable PCIEXBAR decoding for now */ +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR ,0 ); +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR +4 ,0 ); + +switch (PCI_MAX_MCFG_BUSES ) + { +case 64 : + bar_data =PCIEXBAR_64_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (64 ); +break ; + +case 128 : + bar_data =PCIEXBAR_128_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (128 ); +break ; + +case 256 : + bar_data =PCIEXBAR_256_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (256 ); +break ; + +default : +/* unsupported number of buses specified */ +BUG (); + } + + addr_mask = ~(bar_sz -1 ); + +for ( i =0 ; i < nr_bars; i++ ) +if ( bars[i].bar_sz < bar_sz ) +break ; + +if ( i != nr_bars ) +memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); + + bars[i].is_mem =1 ; + bars[i].devfn =PCI_MCH_DEVFN ; + bars[i].bar_reg =PCI_MCH_PCIEXBAR ; + bars[i].bar_sz = bar_sz; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data; + + mmio_total += bar_sz; + nr_bars++;Quoted 8 lines
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 466
Quoted 1 line
tools/firmware/hvmloader/pci.c +1
-0+ }I think it might be best if the ECAM fake BAR is the first element in the bars array, so we ensure it's the first item to consume memory from the low MMIO hole. Not sure how that will work with the current sorting of the resources based on their size, but it's imperative for hvmloader to attempt to position ECAM ahead of the other device resources IMO.
Quoted 1 line
Why would this be?
I would assume it's best to have ECAM access in the low 4G (for 32bit OSes) at the expense of some 32bit BARs possibly not fitting in the 32bit space. But the ECAM space could be placed above 4G, and 32bit OSes might not care much about extended address space capabilities.
Should is_64bar be set for the MCFG "fake" BAR?
Thanks, Roger.
Re: [PATCH 11/17] hvmloader: allocate MMCONFIG area in the MMIO hole
Quoted 68 lines · Roger Pau Monné
Quoted 67 lines · Jan Beulich
Quoted 65 lines · Roger Pau Monné
Quoted 47 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +41
-0@@ -413,6 +413,58 @@ void pci_setup(void) pci_devfn_decode_type[devfn] |=PCI_COMMAND_MASTER ; } +/* +* Calculate MMCONFIG area size and squeeze it into the bars array +* for assigning a slot in the MMIO hole +*/ +if ( is_running_on_q35 ) + { +/* disable PCIEXBAR decoding for now */ +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR ,0 ); +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR +4 ,0 ); + +switch (PCI_MAX_MCFG_BUSES ) + { +case 64 : + bar_data =PCIEXBAR_64_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (64 ); +break ; + +case 128 : + bar_data =PCIEXBAR_128_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (128 ); +break ; + +case 256 : + bar_data =PCIEXBAR_256_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (256 ); +break ; + +default : +/* unsupported number of buses specified */ +BUG (); + } + + addr_mask = ~(bar_sz -1 ); + +for ( i =0 ; i < nr_bars; i++ ) +if ( bars[i].bar_sz < bar_sz ) +break ; + +if ( i != nr_bars ) +memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); +tools/firmware/hvmloader/pci.c void pci_setup(void) · line 466
Quoted 10 lines
tools/firmware/hvmloader/pci.c +10
-0+ bars[i].is_mem =1 ; + bars[i].devfn =PCI_MCH_DEVFN ; + bars[i].bar_reg =PCI_MCH_PCIEXBAR ; + bars[i].bar_sz = bar_sz; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data; + + mmio_total += bar_sz; + nr_bars++; + }I think it might be best if the ECAM fake BAR is the first element in the bars array, so we ensure it's the first item to consume memory from the low MMIO hole. Not sure how that will work with the current sorting of the resources based on their size, but it's imperative for hvmloader to attempt to position ECAM ahead of the other device resources IMO.
Quoted 6 lines
Quoted 1 line
Why would this be?
I would assume it's best to have ECAM access in the low 4G (for 32bit OSes) at the expense of some 32bit BARs possibly not fitting in the 32bit space. But the ECAM space could be placed above 4G, and 32bit OSes might not care much about extended address space capabilities.
This doesn't require it to be 1st, though? Ideally we would try to put it below 4G if possible (i.e. if all other BARs which aren't 64-bit capable still fit), but fall back to putting it above 4G otherwise. In all of this it would still be put in the slot that its size demands. If we put it first, a significant gap could result between it and the first "real" BAR. (Then again a significant gap could also result if the number of buses to cover wasn't a power of 2.) Properly making use of such a gap would further complicate the code, I expect.
Quoted 1 line
Should
is_64barbe set for the MCFG "fake" BAR?
As per above, maybe when making a 2nd (retry) pass.
Jan
Re: [PATCH 11/17] hvmloader: allocate MMCONFIG area in the MMIO hole
In reply to Roger Pau MonnéQuoted 68 lines · Roger Pau Monné
Quoted 67 lines · Jan Beulich
Quoted 65 lines · Roger Pau Monné
Quoted 47 lines · Thierry Escande
tools/firmware/hvmloader/pci.c +41
-0@@ -413,6 +413,58 @@ void pci_setup(void) pci_devfn_decode_type[devfn] |=PCI_COMMAND_MASTER ; } +/* +* Calculate MMCONFIG area size and squeeze it into the bars array +* for assigning a slot in the MMIO hole +*/ +if ( is_running_on_q35 ) + { +/* disable PCIEXBAR decoding for now */ +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR ,0 ); +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR +4 ,0 ); + +switch (PCI_MAX_MCFG_BUSES ) + { +case 64 : + bar_data =PCIEXBAR_64_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (64 ); +break ; + +case 128 : + bar_data =PCIEXBAR_128_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (128 ); +break ; + +case 256 : + bar_data =PCIEXBAR_256_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (256 ); +break ; + +default : +/* unsupported number of buses specified */ +BUG (); + } + + addr_mask = ~(bar_sz -1 ); + +for ( i =0 ; i < nr_bars; i++ ) +if ( bars[i].bar_sz < bar_sz ) +break ; + +if ( i != nr_bars ) +memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); +tools/firmware/hvmloader/pci.c void pci_setup(void) · line 466
Quoted 10 lines
tools/firmware/hvmloader/pci.c +10
-0+ bars[i].is_mem =1 ; + bars[i].devfn =PCI_MCH_DEVFN ; + bars[i].bar_reg =PCI_MCH_PCIEXBAR ; + bars[i].bar_sz = bar_sz; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data; + + mmio_total += bar_sz; + nr_bars++; + }I think it might be best if the ECAM fake BAR is the first element in the bars array, so we ensure it's the first item to consume memory from the low MMIO hole. Not sure how that will work with the current sorting of the resources based on their size, but it's imperative for hvmloader to attempt to position ECAM ahead of the other device resources IMO.
Quoted 6 lines
Quoted 1 line
Why would this be?
I would assume it's best to have ECAM access in the low 4G (for 32bit OSes) at the expense of some 32bit BARs possibly not fitting in the 32bit space. But the ECAM space could be placed above 4G, and 32bit OSes might not care much about extended address space capabilities.
Ok, so that replies my previous question.
As mentioned earlier, if we agree on the ECAM region being placed first in MMIO hole, then we don't care who set it up (toolstack, hvmloader, firmware). It is setup (for now by hvmloader) if we detect a Q35 chipset.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 11/17] hvmloader: allocate MMCONFIG area in the MMIO hole
In reply to Roger Pau MonnéQuoted 20 lines · Roger Pau Monné
Quoted 3 lines · Thierry Escande
The actual MMCONFIG size depends on the number of PCI buses available which should be covered by ECAM. Possible options are 64MB, 128MB and 256MB.
Are such values inherited from the real q35 impleemntation?
AFAICT the ACPI MCFG spec notes:
"The size of the memory mapped configuration region is indicated by the start and end bus number fields in the Memory mapped Enhanced configuration space base address allocation structure as shown in Table 4-3. 0-255 is the range of allowed bus numbers supported for a given PCI Segment Group."
So it's in principle possible to specify a MCFG that covers a single bus, and then it would have a size of 256 * 4K = 1M. Which avoids wasting 63M of MMIO space in the low MMIO hole that's already fairly tight on space.
Quoted 7 lines
Is this limitation possibly inherited from the way the ECAM region position and size must be notified to the chipset?
And further seeing the code below - I found the answer myself, it's because the chipset only supports negotiation those ECAM sizes. We could possibly expose a smaller region in MCFG, but doesn't seem like a good move.
Yes indeed, it's a waste of space in MMIO hole. Maybe it's ok to only allocate the 1MB needed for 1 bus since there would be no reason for a guest to access passed the 1st MB. I can give it a try but that's possibly risky...
Quoted 96 lines
Quoted 96 lines
As Xen is limited to the bus 0 currently, the lowest possible setting is used (64MB), defined via
PCI_MAX_MCFG_BUSESinhvmloader/config.h. When multiple PCI buses support for Xen will be implemented,PCI_MAX_MCFG_BUSESmay be replaced by a calculation of the number of buses according to PCI devices enumeration.The MMCONFIG entry is inserted into bars array in the same manner like for any other BARs. In this case, the devfn field will point to MCH PCI device and
bar_regwill contain PCIEXBAR register offset. It will be assigned a slot in the MMIO hole later in a very same way like for plain PCI BARs, with respect to its size and alignment. At this point, the actual base address and size of the ECAM space are passed to Xen using theHVMOP_set_ecam_spacehypercall.Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/config.h | 4 +++ tools/firmware/hvmloader/pci.c | 55 +++++++++++++++++++++++++++++ tools/firmware/hvmloader/pci_regs.h | 7 ++++ 3 files changed, 66 insertions(+)tools/firmware/hvmloader/config.h +4
-0@@ -55,6 +55,10 @@ extern uint32_t *cpu_to_apicid;#define PCI_ISA_DEVFN 0x08/* dev 1, fn 0 */ #define PCI_ISA_IRQ_MASK 0x0c20U/* ISA IRQs 5,10,11 are PCI connected */ #define PCI_ICH9_LPC_DEVFN 0xf8/* dev 31, fn 0 */ +#define PCI_MCH_DEVFN 0/* bus 0, dev 0, func 0 */ + +/* possible values are: 64, 128, 256 */ +#define PCI_MAX_MCFG_BUSES 64#define ACPI_TIS_HDR_ADDRESS 0xFED40F00ULtools/firmware/hvmloader/pci.c +50
-0@@ -413,6 +413,58 @@ void pci_setup(void) pci_devfn_decode_type[devfn] |=PCI_COMMAND_MASTER ; } +/* +* Calculate MMCONFIG area size and squeeze it into the bars array +* for assigning a slot in the MMIO hole +*/ +if ( is_running_on_q35 ) + { +/* disable PCIEXBAR decoding for now */ +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR ,0 ); +pci_writel (PCI_MCH_DEVFN ,PCI_MCH_PCIEXBAR +4 ,0 ); + +switch (PCI_MAX_MCFG_BUSES ) + { +case 64 : + bar_data =PCIEXBAR_64_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (64 ); +break ; + +case 128 : + bar_data =PCIEXBAR_128_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (128 ); +break ; + +case 256 : + bar_data =PCIEXBAR_256_BUSES |PCIEXBAR_ENABLE ; + bar_sz =MB (256 ); +break ; + +default : +/* unsupported number of buses specified */ +BUG (); + } + + addr_mask = ~(bar_sz -1 ); + +for ( i =0 ; i < nr_bars; i++ ) +if ( bars[i].bar_sz < bar_sz ) +break ; + +if ( i != nr_bars ) +memmove (&bars[i+1 ], &bars[i], (nr_bars-i) *sizeof (*bars)); + + bars[i].is_mem =1 ; + bars[i].devfn =PCI_MCH_DEVFN ; + bars[i].bar_reg =PCI_MCH_PCIEXBAR ; + bars[i].bar_sz = bar_sz; + bars[i].addr_mask = addr_mask; + bars[i].bar_data = bar_data; + + mmio_total += bar_sz; + nr_bars++;
Quoted 8 lines
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 466
Quoted 1 line
tools/firmware/hvmloader/pci.c +1
-0+ }I think it might be best if the ECAM fake BAR is the first element in the bars array, so we ensure it's the first item to consume memory from the low MMIO hole. Not sure how that will work with the current sorting of the resources based on their size, but it's imperative for hvmloader to attempt to position ECAM ahead of the other device resources IMO.
With a size of 64MB it's always placed first from what I can tell. I don't get why it is imperative. Would it be to make sure that it is actually allocated in the first 4GB?
Quoted 9 lines
Quoted 9 lines
tools/firmware/hvmloader/pci.c +1
-0+if ( mmio_hole_size ) {uint64_t max_ram_below_4g =GB (4 ) - mmio_hole_size;@@ -592,6 +644,9 @@ void pci_setup(void) } }
Quoted 6 lines
tools/firmware/hvmloader/pci.c void pci_setup(void) · line 648
Quoted 2 lines
tools/firmware/hvmloader/pci.c +2
-0+if ( bar_reg ==PCI_MCH_PCIEXBAR ) +hvm_set_ecam_space (base, bar_sz);As noted in a previous patch, it would be better if it's QEMU (as part of handling the
PCI_MCH_PCIEXBARwrites) that notifies Xen of the ECAM window placement.
Yes, as mentioned earlier I can do it that way.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 12/17 libxl: Q35 support (new option device_model_machine)
In reply to Thierry EscandeProvide a new domain config option to select the emulated machine type, device_model_machine. It has following possible values:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machine. By default, the storage interface is AHCI.
Note that omitting device_model_machine parameter means i440 system by default, so the default behavior doesn't change for existing domain config files.
Setting device_model_machine to "q35" sends '-machine q35,accel=xen' argument to QEMU. Unlike i440, there is no separated machine type to enable/disable Xen platform device, it is controlled via a machine property only. See 'libxl: Add xen-platform device for Q35 machine' patch for a detailed description.
--- tools/libs/light/libxl_dm.c | 16 ++++++++++------ tools/libs/light/libxl_types.idl | 7 +++++++ tools/xl/xl_parse.c | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-)
tools/libs/light/libxl_dm.c +10 -6
@@ -1562,13 +1562,17 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,flexarray_append (dm_args, b_info->extra_pv[i]);break ;case LIBXL_DOMAIN_TYPE_HVM : -if (!libxl_defbool_val (b_info->u.hvm.xen_platform_pci)) { -/* Switching here to the machine "pc" which does not add -* the xen-platform device instead of the default "xenfv" machine. -*/ - machinearg =libxl__strdup (gc,"pc,accel=xen,suppress-vmdesc=on" ); +if (b_info->device_model_machine ==LIBXL_DEVICE_MODEL_MACHINE_Q35 ) { + machinearg =libxl__sprintf (gc,"q35,accel=xen" ); }else { - machinearg =libxl__strdup (gc,"xenfv,suppress-vmdesc=on" ); +if (!libxl_defbool_val (b_info->u.hvm.xen_platform_pci)) { +/* Switching here to the machine "pc" which does not add +* the xen-platform device instead of the default "xenfv" machine. +*/ + machinearg =libxl__strdup (gc,"pc,accel=xen,suppress-vmdesc=on" ); + }else { + machinearg =libxl__strdup (gc,"xenfv,suppress-vmdesc=on" ); + } }if (b_info->u.hvm.mmio_hole_memkb) { uint64_t max_ram_below_4g = (1ULL << 32) -
tools/libs/light/libxl_types.idl +7 -0
@@ -109,6 +109,12 @@ libxl_device_model_version = Enumeration("device_model_version", [ (2, "QEMU_XEN"), # Upstream based qemu-xen device model ]) +libxl_device_model_machine = Enumeration("device_model_machine", [ + (0, "UNKNOWN"), + (1, "I440"), + (2, "Q35"), + ]) + libxl_console_type = Enumeration("console_type", [ (0, "UNKNOWN"), (1, "SERIAL"),
@@ -613,6 +619,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("device_model_ssidref", uint32), ("device_model_ssid_label", string), ("device_model_user", string), + ("device_model_machine", libxl_device_model_machine), # extra parameters pass directly to qemu, NULL terminated ("extra", libxl_string_list),
tools/xl/xl_parse.c +14 -0
@@ -2813,6 +2813,20 @@ skip_usbdev:if (!xlu_cfg_get_long (config,"stubdomain_memory" , &l,0 )) b_info->stubdomain_memkb = l *1024 ; +if (!xlu_cfg_get_string (config,"device_model_machine" , &buf,0 )) { +if (!strcmp (buf,"i440" )) { + b_info->device_model_machine =LIBXL_DEVICE_MODEL_MACHINE_I440 ; + }else if (!strcmp (buf,"q35" )) { + b_info->device_model_machine =LIBXL_DEVICE_MODEL_MACHINE_Q35 ; + }else { +fprintf (stderr, +"Unknown device_model_machine \"%s\" specified\n" , buf); +exit (1 ); + } + }else { + b_info->device_model_machine =LIBXL_DEVICE_MODEL_MACHINE_UNKNOWN ; + } +#define parse_extra_args (type) \ e = xlu_cfg_get_list_as_string_list(config, "device_model_args"#type, \ &b_info->extra##type, 0); \
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 12/17] libxl: Q35 support (new option device_model_machine)
Quoted 10 lines · Thierry Escande
Provide a new domain config option to select the emulated machine type,
device_model_machine. It has following possible values:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machine. By default, the storage interface is AHCI.Note that omitting
device_model_machineparameter means i440 system by default, so the default behavior doesn't change for existing domain config files.
Quoted 5 lines
Setting
device_model_machineto "q35" sends '-machine q35,accel=xen' argument to QEMU. Unlike i440, there is no separated machine type to enable/disable Xen platform device, it is controlled via a machine property only. See 'libxl: Add xen-platform device for Q35 machine' patch for a detailed description.
Not an explicit objection to this patch, but I wonder what will we do for PVH when we start exposing PCI devices. We cannot provide a fully complete emulated Q35, but we do need to expose an MCFG for extended config space. The current naming "device_model_machine" won't work for PVH, as there's no device model there. But at the same time I wonder whether what we end up exposing to PVH would resemble any physical chipsets, or it's more likely going to be the minimum needed to make PVH guests happy to access the PCI config space (and hence we might end up emulating too little to match any chipset).
Thanks, Roger.
Quoted 55 lines
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/libs/light/libxl_dm.c | 16 ++++++++++------ tools/libs/light/libxl_types.idl | 7 +++++++ tools/xl/xl_parse.c | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-)tools/libs/light/libxl_dm.c +10
-6@@ -1562,13 +1562,17 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,flexarray_append (dm_args, b_info->extra_pv[i]);break ;case LIBXL_DOMAIN_TYPE_HVM : -if (!libxl_defbool_val (b_info->u.hvm.xen_platform_pci)) { -/* Switching here to the machine "pc" which does not add -* the xen-platform device instead of the default "xenfv" machine. -*/ - machinearg =libxl__strdup (gc,"pc,accel=xen,suppress-vmdesc=on" ); +if (b_info->device_model_machine ==LIBXL_DEVICE_MODEL_MACHINE_Q35 ) { + machinearg =libxl__sprintf (gc,"q35,accel=xen" ); }else { - machinearg =libxl__strdup (gc,"xenfv,suppress-vmdesc=on" ); +if (!libxl_defbool_val (b_info->u.hvm.xen_platform_pci)) { +/* Switching here to the machine "pc" which does not add +* the xen-platform device instead of the default "xenfv" machine. +*/ + machinearg =libxl__strdup (gc,"pc,accel=xen,suppress-vmdesc=on" ); + }else { + machinearg =libxl__strdup (gc,"xenfv,suppress-vmdesc=on" ); + } }if (b_info->u.hvm.mmio_hole_memkb) { uint64_t max_ram_below_4g = (1ULL << 32) -tools/libs/light/libxl_types.idl +6
-0@@ -109,6 +109,12 @@ libxl_device_model_version = Enumeration("device_model_version", [ (2, "QEMU_XEN"), # Upstream based qemu-xen device model ]) +libxl_device_model_machine = Enumeration("device_model_machine", [ + (0, "UNKNOWN"), + (1, "I440"), + (2, "Q35"), + ]) + libxl_console_type = Enumeration("console_type", [ (0, "UNKNOWN"), (1, "SERIAL"),
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 622
Quoted 4 lines
tools/libs/light/libxl_types.idl +1
-0@@ -613,6 +619,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("device_model_ssidref", uint32), ("device_model_ssid_label", string), ("device_model_user", string), + ("device_model_machine", libxl_device_model_machine),
This possibly wants to be inside the u.hvm sub-structure. I don't think we want to use it for PVH, not with this current naming at least.
Thanks, Roger.
Re: [PATCH 12/17] libxl: Q35 support (new option device_model_machine)
Quoted 17 lines · Roger Pau Monné
Quoted 10 lines · Thierry Escande
Provide a new domain config option to select the emulated machine type,
device_model_machine. It has following possible values:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machine. By default, the storage interface is AHCI.Note that omitting
device_model_machineparameter means i440 system by default, so the default behavior doesn't change for existing domain config files.Quoted 5 lines
Setting
device_model_machineto "q35" sends '-machine q35,accel=xen' argument to QEMU. Unlike i440, there is no separated machine type to enable/disable Xen platform device, it is controlled via a machine property only. See 'libxl: Add xen-platform device for Q35 machine' patch for a detailed description.
Quoted 9 lines
Not an explicit objection to this patch, but I wonder what will we do for PVH when we start exposing PCI devices. We cannot provide a fully complete emulated Q35, but we do need to expose an MCFG for extended config space. The current naming "
device_model_machine" won't work for PVH, as there's no device model there. But at the same time I wonder whether what we end up exposing to PVH would resemble any physical chipsets, or it's more likely going to be the minimum needed to make PVH guests happy to access the PCI config space (and hence we might end up emulating too little to match any chipset).
I feel like we are going to want two different settings between HVM and PVH. On PVH, the exposure of MCFG could be done by default, or if a setting is needed and happen to be useful to HVM, we could make that new setting for both HVM and PVH, and that new setting could select the q35 machine if none are selected or it could reject the config if q35 isn't selected as well. That sentence might be overly complicated, but I just mean that "device_model_machine" is fine for now, and will see what we do when a new setting would be introduced for PVH.
Quoted 4 lines
Quoted 4 lines
libxl_console_type= Enumeration("console_type", [(0, "UNKNOWN"), (1, "SERIAL"),(quoted diff) +0
-0@@ -613,6 +619,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
Quoted 8 lines
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 622
Quoted 4 lines
tools/libs/light/libxl_types.idl +1
-0("device_model_ssidref", uint32), ("device_model_ssid_label", string), ("device_model_user", string), + ("device_model_machine", libxl_device_model_machine),This possibly wants to be inside the u.hvm sub-structure. I don't think we want to use it for PVH, not with this current naming at least.
Good suggestion.
Cheers,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 12/17] libxl: Q35 support (new option device_model_machine)
In reply to Thierry EscandeQuoted 6 lines · Thierry Escande
Provide a new domain config option to select the emulated machine type,
device_model_machine. It has following possible values:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machine. By default, the storage interface is AHCI.
Quoted 6 lines
Note that omitting
device_model_machineparameter means i440 system by default, so the default behavior doesn't change for existing domain config files.Setting
device_model_machineto "q35" sends '-machine q35,accel=xen' argument to QEMU.
That new configuration is going to do more than adding this argument to the to the QEMU command line.
"accel=xen" isn't new, it's already used. It just happen that the machine "xenfv" in QEMU sets it by default.
Quoted 3 lines
Unlike i440, there is no separated machine type to enable/disable Xen platform device, it is controlled via a machine property only.
As it should be. We don't use a separated machine type to control the presence or not of the xen-platform-pci device, we use it because historically that was the only way to enable Xen support in QEMU. Before accel=xen was introduced.
We could also add the xen-platform-pci device separately with the i440 chipset, but switching from xenfv to pc would break migration.
Speaking of migration, we might want to force users to select a particular version of a q35 machine, something like "pc-q35-10.0", as this would make it possible to migrate between two different versions of QEMU without too much trouble.
We could have them run something like
/usr/lib/xen/bin/qemu-system-i386 -machine '?'
to have the list of machine, or have libxl list all the possible machine
or just the machine name that would be the alias of "q35".
(in -machine '?' output, that looks like:
q35 Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-10.2))
That would be necessary, until the toolstack would be capable of using the same machine version on both end of a migration.
Quoted 16 lines
See 'libxl: Add xen-platform device for Q35 machine' patch for a detailed description.
Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/libs/light/libxl_dm.c | 16 ++++++++++------ tools/libs/light/libxl_types.idl | 7 +++++++ tools/xl/xl_parse.c | 14 ++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-)tools/libs/light/libxl_dm.c +0
-0
tools/libs/light/libxl_dm.c static int libxl__build_device_model_args_new(libxl__gc *gc, · line 1566
Quoted 10 lines
tools/libs/light/libxl_dm.c +2
-5@@ -1562,13 +1562,17 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,flexarray_append (dm_args, b_info->extra_pv[i]);break ;case LIBXL_DOMAIN_TYPE_HVM : -if (!libxl_defbool_val (b_info->u.hvm.xen_platform_pci)) { -/* Switching here to the machine "pc" which does not add -* the xen-platform device instead of the default "xenfv" machine. -*/ - machinearg =libxl__strdup (gc,"pc,accel=xen,suppress-vmdesc=on" ); +if (b_info->device_model_machine ==LIBXL_DEVICE_MODEL_MACHINE_Q35 ) { + machinearg =libxl__sprintf (gc,"q35,accel=xen" );
I have to check, but I think we still want "suppress-vmdesc=on", here.
Quoted 31 lines
tools/libs/light/libxl_dm.c +8
-1}else { - machinearg =libxl__strdup (gc,"xenfv,suppress-vmdesc=on" ); +if (!libxl_defbool_val (b_info->u.hvm.xen_platform_pci)) { +/* Switching here to the machine "pc" which does not add +* the xen-platform device instead of the default "xenfv" machine. +*/ + machinearg =libxl__strdup (gc,"pc,accel=xen,suppress-vmdesc=on" ); + }else { + machinearg =libxl__strdup (gc,"xenfv,suppress-vmdesc=on" ); + } }if (b_info->u.hvm.mmio_hole_memkb) { uint64_t max_ram_below_4g = (1ULL << 32) -tools/libs/light/libxl_types.idl +6
-0@@ -109,6 +109,12 @@ libxl_device_model_version = Enumeration("device_model_version", [ (2, "QEMU_XEN"), # Upstream based qemu-xen device model ]) +libxl_device_model_machine = Enumeration("device_model_machine", [ + (0, "UNKNOWN"), + (1, "I440"), + (2, "Q35"), + ]) + libxl_console_type = Enumeration("console_type", [ (0, "UNKNOWN"), (1, "SERIAL"),
tools/libs/light/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 622
Quoted 4 lines
tools/libs/light/libxl_types.idl +1
-0@@ -613,6 +619,7 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("device_model_ssidref", uint32), ("device_model_ssid_label", string), ("device_model_user", string), + ("device_model_machine", libxl_device_model_machine),
libxl is going to have to check this new field. When it's set to unknown, we have to change it to the default value before starting to create the new domain. This is done in libxl__domain_build_info_setdefault().
Also, as it's a change to the API, could you add a "LIBXL_HAVE_*" macro in "libxl.h"? LIBXL_HAVE_DEVICE_MODEL_MACHINE would sound like a good name.
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 13/17 libxl: Add xen-platform device for Q35 machine
In reply to Thierry EscandeCurrent Xen/QEMU method to control Xen Platform device is done by setting the 'xen_platform_device' option value that modifies QEMU emulated machine type, namely xenfv <--> pc.
In order to avoid multiplying machine types, this patch supplies '-device xen-platform' directly to Qemu. To maintain backward compatibility with existing Xen/QEMU setups, this is currently only applicable to q35 machine. i440 emulation uses the old method (xenfv/pc machine) to control Xen Platform device.
--- tools/libs/light/libxl_dm.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/libs/light/libxl_dm.c +6 -0
@@ -1811,6 +1811,12 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,flexarray_append (dm_args, state->dm_runas); } } + +if (b_info->device_model_machine ==LIBXL_DEVICE_MODEL_MACHINE_Q35 && +libxl_defbool_val (b_info->u.hvm.xen_platform_pci)) { +flexarray_append (dm_args,"-device" ); +flexarray_append (dm_args,"xen-platform" ); + } }flexarray_append (dm_args,NULL ); *args = (char **)flexarray_contents (dm_args);
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 13/17] libxl: Add xen-platform device for Q35 machine
Quoted 2 lines · Thierry Escande
Current Xen/QEMU method to control Xen Platform device is done by setting the '
xen_platform_device' option value
You mean xen_platform_pci ?
This is still the case with the new type of machine ;-).
Quoted 7 lines
that modifies QEMU
emulated machine type, namely xenfv <--> pc.In order to avoid multiplying machine types, this patch supplies '-device xen-platform' directly to Qemu. To maintain backward compatibility with existing Xen/QEMU setups, this is currently only applicable to q35 machine.
We can already use -device xen-platform with QEMU's machine pc / pc-i440fx-* but this would break migration from previous version of libxl, PCI devices would move around while the guest is running.
So instead of "currently only applicable", something like "we will only apply this to q35" would be a bit more accurate.
Quoted 2 lines
i440 emulation uses the old method (xenfv/pc
machine) to control Xen Platform device.
To be honest, the change between xenfv and pc is bigger than just that device, it's also a different machine version.
-machine xenfv is kind of equivalent to:-machine pc-i440fx-3.1,accel=xen,suppress-vmdesc=on -device xen-platform
But xenfv can also have igd-passthru=on added to -machine which has an influence on the machine setup.
If you manage to rework the commit that would be nice, in anycase, overall the patch looks fine: Reviewed-by: Anthony PERARD <[email protected]>
Cheers,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 14/17 libacpi: build ACPI MCFG table if requested
In reply to Thierry EscandeThis adds construct_mcfg() function to libacpi which allows to build MCFG table for a given mmconfig_addr/mmconfig_len pair if the ACPI_HAS_MCFG flag was specified in acpi_config struct.
The maximum bus number is calculated from mmconfig_size using MCFG_SIZE_TO_NUM_BUSES macro (1MByte of MMIO space per bus).
--- tools/libacpi/acpi2_0.h | 17 ++++++++++++++++ tools/libacpi/build.c | 43 +++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 6 ++++++ 3 files changed, 66 insertions(+)
tools/libacpi/acpi2_0.h +17 -0
@@ -442,6 +442,21 @@ struct acpi_20_slit {uint8_t entry[0 ]; }; +/* +* PCI Express Memory Mapped Configuration Description Table +*/ +struct acpi_10_mcfg { +struct acpi_header header; +uint8_t reserved[8 ]; +struct { +uint64_t base_address; +uint16_t pci_segment; +uint8_t start_pci_bus_num; +uint8_t end_pci_bus_num; +uint32_t reserved; + } entries[1 ]; +}; +/* * Table Signatures. */
@@ -457,6 +472,7 @@ struct acpi_20_slit {#define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')#define ACPI_2_0_SRAT_SIGNATURE ASCII32('S','R','A','T')#define ACPI_2_0_SLIT_SIGNATURE ASCII32('S','L','I','T') +#define ACPI_MCFG_SIGNATURE ASCII32('M','C','F','G')/* * Table revision numbers.
@@ -472,6 +488,7 @@ struct acpi_20_slit {#define ACPI_1_0_FADT_REVISION 0x01#define ACPI_2_0_SRAT_REVISION 0x01#define ACPI_2_0_SLIT_REVISION 0x01 +#define ACPI_1_0_MCFG_REVISION 0x01#pragma pack ()
tools/libacpi/build.c +43 -0
61 lines not on this page · raw message
tools/libacpi/libacpi.h +6 -0
@@ -27,6 +27,9 @@#define ACPI_HAS_8042 (1<<13)#define ACPI_HAS_CMOS_RTC (1<<14)#define ACPI_HAS_SSDT_LAPTOP_SLATE (1<<15) +#define ACPI_HAS_MCFG (1<<16) + +#define MCFG_SIZE_TO_NUM_BUSES (size) ((size) >> 20)struct xen_vmemrange ;struct acpi_numa {
@@ -89,6 +92,9 @@ struct acpi_config {uint32_t ioapic_base_address;uint16_t pci_isa_irq_mask;uint8_t ioapic_id; + +uint64_t mmconfig_addr; +uint32_t mmconfig_size; };int acpi_build_tables (struct acpi_ctxt *ctxt,struct acpi_config *config);
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 14/17] libacpi: build ACPI MCFG table if requested
Quoted 62 lines · Thierry Escande
This adds
construct_mcfg()function to libacpi which allows to build MCFG table for a given mmconfig_addr/mmconfig_len pair if theACPI_HAS_MCFGflag was specified inacpi_configstruct.The maximum bus number is calculated from
mmconfig_sizeusingMCFG_SIZE_TO_NUM_BUSESmacro (1MByte of MMIO space per bus).Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- tools/libacpi/acpi2_0.h | 17 ++++++++++++++++ tools/libacpi/build.c | 43 +++++++++++++++++++++++++++++++++++++++++ tools/libacpi/libacpi.h | 6 ++++++ 3 files changed, 66 insertions(+)tools/libacpi/acpi2_0.h +17
-0@@ -442,6 +442,21 @@ struct acpi_20_slit {uint8_t entry[0 ]; }; +/* +* PCI Express Memory Mapped Configuration Description Table +*/ +struct acpi_10_mcfg { +struct acpi_header header; +uint8_t reserved[8 ]; +struct { +uint64_t base_address; +uint16_t pci_segment; +uint8_t start_pci_bus_num; +uint8_t end_pci_bus_num; +uint32_t reserved; + } entries[1 ]; +}; +/* * Table Signatures. */ @@ -457,6 +472,7 @@ struct acpi_20_slit {#define ACPI_2_0_WAET_SIGNATURE ASCII32('W','A','E','T')#define ACPI_2_0_SRAT_SIGNATURE ASCII32('S','R','A','T')#define ACPI_2_0_SLIT_SIGNATURE ASCII32('S','L','I','T') +#define ACPI_MCFG_SIGNATURE ASCII32('M','C','F','G')/* * Table revision numbers. @@ -472,6 +488,7 @@ struct acpi_20_slit {#define ACPI_1_0_FADT_REVISION 0x01#define ACPI_2_0_SRAT_REVISION 0x01#define ACPI_2_0_SLIT_REVISION 0x01 +#define ACPI_1_0_MCFG_REVISION 0x01#pragma pack ()tools/libacpi/build.c +0
-0
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 303
Quoted 9 lines
tools/libacpi/build.c +6
-0@@ -295,6 +295,37 @@ static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt,return slit; } +static struct acpi_10_mcfg *construct_mcfg (struct acpi_ctxt *ctxt, +const struct acpi_config *config) +{ +struct acpi_10_mcfg *mcfg; + +/* Warning: this code expects that we have only one PCI segment */
Not only one PCI segment, but just one ECAM region. You could in theory have multiple ECAM regions within a single PCI segment.
Quoted 9 lines
tools/libacpi/build.c +9
-0+ mcfg = ctxt->mem_ops.alloc (ctxt,sizeof (*mcfg),16 ); +if ( !mcfg ) +return NULL ; + +memset (mcfg,0 ,sizeof (*mcfg)); + mcfg->header.signature =ACPI_MCFG_SIGNATURE ; + mcfg->header.revision =ACPI_1_0_MCFG_REVISION ; + mcfg->header.creator_id =ACPI_CREATOR_ID ; + mcfg->header.creator_revision =ACPI_CREATOR_REVISION ;
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 322
Quoted 10 lines
tools/libacpi/build.c +10
-0+ mcfg->header.length =sizeof (*mcfg); + mcfg->header.oem_revision =ACPI_OEM_REVISION ; +fixed_strcpy (mcfg->header.oem_id,ACPI_OEM_ID ); +fixed_strcpy (mcfg->header.oem_table_id,ACPI_OEM_TABLE_ID ); + + mcfg->entries[0 ].base_address = config->mmconfig_addr; + mcfg->entries[0 ].pci_segment =0 ; + mcfg->entries[0 ].start_pci_bus_num =0 ; + mcfg->entries[0 ].end_pci_bus_num = +MCFG_SIZE_TO_NUM_BUSES (config->mmconfig_size) -1 ;
You might want to check that mmconfig_addr and mmconfig_size are set ahead of using them? Just in case some bogus toolstack/hvmloader sets ACPI_HAS_MCFG without correctly populating the fields?
Thanks, Roger.
Re: [PATCH 14/17] libacpi: build ACPI MCFG table if requested
Quoted 10 lines · Roger Pau Monné
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 303
Quoted 6 lines · Thierry Escande
tools/libacpi/build.c +6
-0+static struct acpi_10_mcfg *construct_mcfg (struct acpi_ctxt *ctxt, +const struct acpi_config *config) +{ +struct acpi_10_mcfg *mcfg; + +/* Warning: this code expects that we have only one PCI segment */ Not only one PCI segment, but just one ECAM region. You could in theory have multiple ECAM regions within a single PCI segment.
Yes, right. AFAIU, Xen guests have only 1 bus within only 1 segment, with no multiple buses support, hence no multiple segments support, right?
Quoted 17 lines
Quoted 17 lines
tools/libacpi/build.c +16
-0+ mcfg = ctxt->mem_ops.alloc (ctxt,sizeof (*mcfg),16 ); +if ( !mcfg ) +return NULL ; + +memset (mcfg,0 ,sizeof (*mcfg)); + mcfg->header.signature =ACPI_MCFG_SIGNATURE ; + mcfg->header.revision =ACPI_1_0_MCFG_REVISION ; + mcfg->header.creator_id =ACPI_CREATOR_ID ; + mcfg->header.creator_revision =ACPI_CREATOR_REVISION ; + mcfg->header.length =sizeof (*mcfg); + mcfg->header.oem_revision =ACPI_OEM_REVISION ; +fixed_strcpy (mcfg->header.oem_id,ACPI_OEM_ID ); +fixed_strcpy (mcfg->header.oem_table_id,ACPI_OEM_TABLE_ID ); + + mcfg->entries[0 ].base_address = config->mmconfig_addr; + mcfg->entries[0 ].pci_segment =0 ;
Quoted 8 lines
tools/libacpi/build.c static struct acpi_20_slit *construct_slit(struct acpi_ctxt *ctxt, · line 322
Quoted 3 lines
tools/libacpi/build.c +3
-0+ mcfg->entries[0 ].start_pci_bus_num =0 ; + mcfg->entries[0 ].end_pci_bus_num = +MCFG_SIZE_TO_NUM_BUSES (config->mmconfig_size) -1 ;You might want to check that
mmconfig_addrandmmconfig_sizeare set ahead of using them? Just in case some bogus toolstack/hvmloader setsACPI_HAS_MCFGwithout correctly populating the fields?
Makes sense.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 15/17 hvmloader: Set MCFG in ACPI table
In reply to Thierry EscandeThis patch extends hvmloader_acpi_build_tables() to detect if MMCONFIG is available by obtaining its base address and size from the hypercall HVMOP_get_ecam_space and sets the flag ACPI_HAS_MCFG in the ACPI config if needed.
This also sets the MMCONFIG area in E820 map using the same method.
--- tools/firmware/hvmloader/e820.c | 11 +++++++++++ tools/firmware/hvmloader/util.c | 9 +++++++++ 2 files changed, 20 insertions(+)
tools/firmware/hvmloader/e820.c +11 -0
@@ -158,6 +158,8 @@ int build_e820_table(struct e820entry *e820,unsigned long acpi_mem_end = acpi_enabled ?ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated () <<PAGE_SHIFT ) :RESERVED_MEMBASE ; +uint64_t mmconfig_addr; +uint32_t mmconfig_size;if ( !lowmem_reserved_base ) lowmem_reserved_base =0xA0000 ;
@@ -260,6 +262,15 @@ int build_e820_table(struct e820entry *e820, nr++; } +/* mark MMCONFIG area */ +if ( !hvm_get_ecam_space (&mmconfig_addr, &mmconfig_size) ) + { + e820[nr].addr = mmconfig_addr; + e820[nr].size = mmconfig_size; + e820[nr].type =E820_RESERVED ; + nr++; + } +/* Low RAM goes here. Reserve space for special pages. */ BUG_ON (low_mem_end <MB (2 ));
tools/firmware/hvmloader/util.c +9 -0
@@ -903,6 +903,8 @@ void hvmloader_acpi_build_tables(struct acpi_config *config,struct acpi_ctxt ctxt;long long tpm_version;char *end; +uint64_t mmconfig_addr; +uint32_t mmconfig_size;/* Allocate and initialise the acpi info area. */ mem_hole_populate_ram (ACPI_INFO_PHYSICAL_ADDRESS >>PAGE_SHIFT ,1 );
@@ -953,6 +955,13 @@ void hvmloader_acpi_build_tables(struct acpi_config *config, config->pci_hi_len = pci_hi_mem_end - pci_hi_mem_start; } +if ( !hvm_get_ecam_space (&mmconfig_addr, &mmconfig_size) ) + { + config->table_flags |=ACPI_HAS_MCFG ; + config->mmconfig_addr = mmconfig_addr; + config->mmconfig_size = mmconfig_size; + } + s =xenstore_read ("platform/generation-id" ,"0:0" );if ( s ) {
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 15/17] hvmloader: Set MCFG in ACPI table
Quoted 27 lines · Thierry Escande
This patch extends
hvmloader_acpi_build_tables()to detect if MMCONFIG is available by obtaining its base address and size from the hypercallHVMOP_get_ecam_spaceand sets the flagACPI_HAS_MCFGin the ACPI config if needed.This also sets the MMCONFIG area in E820 map using the same method.
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/e820.c | 11 +++++++++++ tools/firmware/hvmloader/util.c | 9 +++++++++ 2 files changed, 20 insertions(+)tools/firmware/hvmloader/e820.c +2
-0@@ -158,6 +158,8 @@ int build_e820_table(struct e820entry *e820,unsigned long acpi_mem_end = acpi_enabled ?ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated () <<PAGE_SHIFT ) :RESERVED_MEMBASE ; +uint64_t mmconfig_addr; +uint32_t mmconfig_size;if ( !lowmem_reserved_base ) lowmem_reserved_base =0xA0000 ;
tools/firmware/hvmloader/e820.c int build_e820_table(struct e820entry *e820, · line 266
Quoted 5 lines
tools/firmware/hvmloader/e820.c +2
-0@@ -260,6 +262,15 @@ int build_e820_table(struct e820entry *e820, nr++; } +/* mark MMCONFIG area */ +if ( !hvm_get_ecam_space (&mmconfig_addr, &mmconfig_size) )
^ extra space
However, having to query the hypervisor for something that has been set by hvmloader itself seems very inefficient. Just store the values in global variables so they can be consumed from here?
Same for the usage below.
Thanks, Roger.
Re: [PATCH 15/17] hvmloader: Set MCFG in ACPI table
Quoted 31 lines · Roger Pau Monné
Quoted 30 lines · Thierry Escande
This patch extends
hvmloader_acpi_build_tables()to detect if MMCONFIG is available by obtaining its base address and size from the hypercallHVMOP_get_ecam_spaceand sets the flagACPI_HAS_MCFGin the ACPI config if needed.This also sets the MMCONFIG area in E820 map using the same method.
Signed-off-by Thierry Escande <[email protected]>--- tools/firmware/hvmloader/e820.c | 11 +++++++++++ tools/firmware/hvmloader/util.c | 9 +++++++++ 2 files changed, 20 insertions(+)tools/firmware/hvmloader/e820.c +2
-0@@ -158,6 +158,8 @@ int build_e820_table(struct e820entry *e820,unsigned long acpi_mem_end = acpi_enabled ?ACPI_MEMORY_DYNAMIC_START + (acpi_pages_allocated () <<PAGE_SHIFT ) :RESERVED_MEMBASE ; +uint64_t mmconfig_addr; +uint32_t mmconfig_size;if ( !lowmem_reserved_base ) lowmem_reserved_base =0xA0000 ;@@ -260,6 +262,15 @@ int build_e820_table(struct e820entry *e820, nr++; }
Quoted 7 lines
tools/firmware/hvmloader/e820.c int build_e820_table(struct e820entry *e820, · line 266
Quoted 2 lines
tools/firmware/hvmloader/e820.c +2
-0+/* mark MMCONFIG area */ +if ( !hvm_get_ecam_space (&mmconfig_addr, &mmconfig_size) )^ extra space
However, having to query the hypervisor for something that has been set by hvmloader itself seems very inefficient. Just store the values in global variables so they can be consumed from here?
Indeed. And that would remove the need for the hvm_get_ecam_space() helper.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH 16/17 Handle PCIe ECAM space access from guests
In reply to Thierry EscandeThis patch adds the logic to decode MMIO-based PCIe ECAM accesses. If the IOREQ_TYPE_COPY request is within the ECAM address space configured by hvmloader, the ioreq type is set to XEN_DMOP_IO_RANGE_PCI and the sbdf decoded from the accessed address.
--- xen/arch/x86/hvm/ioreq.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
xen/arch/x86/hvm/ioreq.c +15 -0
@@ -268,6 +268,8 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d, uint64_t *addr) {unsigned int cf8 = d->arch.hvm.pci_cf8; +unsigned long mmio_start = (p->type ==IOREQ_TYPE_COPY ) ? +ioreq_mmio_first_byte (p) :0 ;if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return false;
@@ -298,6 +300,19 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d, *addr |=CF8_ADDR_HI (cf8); } } +else if ( p->type ==IOREQ_TYPE_COPY && + (mmio_start >= d->arch.ecam_addr && + mmio_start < (d->arch.ecam_addr + d->arch.ecam_size)) ) + { +pci_sbdf_t sbdf; +unsigned int reg = mmio_start & ~PAGE_MASK ; + + sbdf.bdf = (((mmio_start - d->arch.ecam_addr) &0x0ffff000 ) >>12 ); + sbdf.seg =0 ; + + *type =XEN_DMOP_IO_RANGE_PCI ; + *addr = ((uint64_t )sbdf.sbdf <<32 ) | reg; + }else { *type = (p->type == IOREQ_TYPE_PIO) ?
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 16/17] Handle PCIe ECAM space access from guests
Quoted 29 lines · Thierry Escande
This patch adds the logic to decode MMIO-based PCIe ECAM accesses. If the
IOREQ_TYPE_COPYrequest is within the ECAM address space configured by hvmloader, the ioreq type is set toXEN_DMOP_IO_RANGE_PCIand the sbdf decoded from the accessed address.Signed-off-by Thierry Escande <[email protected]>--- xen/arch/x86/hvm/ioreq.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)xen/arch/x86/hvm/ioreq.c +4
-0@@ -268,6 +268,8 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d, uint64_t *addr) {unsigned int cf8 = d->arch.hvm.pci_cf8; +unsigned long mmio_start = (p->type ==IOREQ_TYPE_COPY ) ? +ioreq_mmio_first_byte (p) :0 ;if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return false;@@ -298,6 +300,19 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d, *addr |=CF8_ADDR_HI (cf8); } } + else if ( p->type == IOREQ_TYPE_COPY && + (mmio_start >= d->arch.ecam_addr &&
xen/arch/x86/hvm/ioreq.c bool arch_ioreq_server_get_type_addr(const struct domain *d, · line 314
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+ mmio_start < (d->arch.ecam_addr + d->arch.ecam_size)) ) + { +pci_sbdf_t sbdf; +unsigned int reg = mmio_start & ~PAGE_MASK ; + + sbdf.bdf = (((mmio_start - d->arch.ecam_addr) &0x0ffff000 ) >>12 ); + sbdf.seg =0 ; + + *type =XEN_DMOP_IO_RANGE_PCI ; + *addr = ((uint64_t )sbdf.sbdf <<32 ) | reg;
The trapping & decoding here should better re-use the logic in the vpci_mmcfg* handlers in x86/hvm/io.c. You might want to gate the call to register_mmio_handler() to the domain having vPCI, so that otherwise it will be handled by the IOREQ catch-all. It's a bit hacky, but we already know that vPCI and IOREQs don't play well, and it needs solving properly. Again I don't want to force you having to do that just to get q35 merged. But we should at least aim to not duplicate the data in the domain structures.
Thanks, Roger.
Re: [PATCH 16/17] Handle PCIe ECAM space access from guests
Quoted 41 lines · Roger Pau Monné
Quoted 29 lines · Thierry Escande
This patch adds the logic to decode MMIO-based PCIe ECAM accesses. If the
IOREQ_TYPE_COPYrequest is within the ECAM address space configured by hvmloader, the ioreq type is set toXEN_DMOP_IO_RANGE_PCIand the sbdf decoded from the accessed address.Signed-off-by Thierry Escande <[email protected]>--- xen/arch/x86/hvm/ioreq.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)xen/arch/x86/hvm/ioreq.c +4
-0@@ -268,6 +268,8 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d, uint64_t *addr) {unsigned int cf8 = d->arch.hvm.pci_cf8; +unsigned long mmio_start = (p->type ==IOREQ_TYPE_COPY ) ? +ioreq_mmio_first_byte (p) :0 ;if ( p->type !=IOREQ_TYPE_COPY && p->type !=IOREQ_TYPE_PIO )return false;@@ -298,6 +300,19 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d, *addr |=CF8_ADDR_HI (cf8); } } + else if ( p->type == IOREQ_TYPE_COPY && + (mmio_start >= d->arch.ecam_addr &&xen/arch/x86/hvm/ioreq.c bool arch_ioreq_server_get_type_addr(const struct domain *d, · line 314
Quoted 10 lines
xen/arch/x86/hvm/ioreq.c +10
-0+ mmio_start < (d->arch.ecam_addr + d->arch.ecam_size)) ) + { +pci_sbdf_t sbdf; +unsigned int reg = mmio_start & ~PAGE_MASK ; + + sbdf.bdf = (((mmio_start - d->arch.ecam_addr) &0x0ffff000 ) >>12 ); + sbdf.seg =0 ; + + *type =XEN_DMOP_IO_RANGE_PCI ; + *addr = ((uint64_t )sbdf.sbdf <<32 ) | reg;
Quoted 8 lines
The trapping & decoding here should better re-use the logic in the vpci_mmcfg* handlers in
x86/hvm/io.c. You might want to gate the call toregister_mmio_handler()to the domain having vPCI, so that otherwise it will be handled by the IOREQ catch-all. It's a bit hacky, but we already know that vPCI and IOREQs don't play well, and it needs solving properly. Again I don't want to force you having to do that just to get q35 merged. But we should at least aim to not duplicate the data in the domain structures.
I missed that part about vPCI and HVM. AFAIR it was not possible to use vPCI for HVM domains. I'll take a deeper look and see if that mmcfg handling could be reused.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 16/17] Handle PCIe ECAM space access from guests
In reply to Thierry Escandexen/arch/x86/hvm/ioreq.c bool arch_ioreq_server_get_type_addr(const struct domain *d, · line 308
Quoted 10 lines · Thierry Escande
xen/arch/x86/hvm/ioreq.c +6
-0@@ -298,6 +300,19 @@ bool arch_ioreq_server_get_type_addr(const struct domain *d, *addr |=CF8_ADDR_HI (cf8); } } +else if ( p->type ==IOREQ_TYPE_COPY && + (mmio_start >= d->arch.ecam_addr && + mmio_start < (d->arch.ecam_addr + d->arch.ecam_size)) ) + { +pci_sbdf_t sbdf; +unsigned int reg = mmio_start & ~PAGE_MASK ;
If you use PAGE_MASK here, ...
xen/arch/x86/hvm/ioreq.c bool arch_ioreq_server_get_type_addr(const struct domain *d, · line 310
Quoted 1 line
xen/arch/x86/hvm/ioreq.c +1
-0+ sbdf.bdf = (((mmio_start - d->arch.ecam_addr) &0x0ffff000 ) >>12 );
... why not PAGE_SHIFT here? And why the masking by 0x0ffff000? Doesn't the earlier range check make this unnecessary (as long as .ecam_size is plausible)?
Finally, nit: There's a stray blank after the =, and one pair of parentheses could perhaps also be dropped.
Jan
PATCH 17/17 docs: provide description for device_model_machine option
In reply to Thierry EscandeThis patch adds description for 'device_model_machine' option which allows to control which chipset will be emulated by device model.
--- docs/man/xl.cfg.5.pod.in | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
docs/man/xl.cfg.5.pod.in +27 -0
@@ -2963,6 +2963,33 @@ you have existing guests then, depending on the nature of the guest Operating System, you may wish to force them to use the device model which they were installed with. +=item B<device_model_machine="STRING"> + +Selects which chipset the device model should emulate for this +guest. + +Valid options are: + +=over 4 + +=item B<"i440"> + +Use i440 emulation (a default setting) + +=item B<"q35"> + +Use Q35/ICH9 emulation. This enables additional features for +PCIe device passthrough + +=back + +Note that omitting device_model_machine parameter means i440 system +by default, so the default behavior doesn't change for old domain +config files. + +It is recommended to install the guest OS from scratch to avoid issues +due to the emulated platform change. + =item B<device_model_override="PATH"> Override the path to the binary to be used as the device-model running in
Signature · 10 lines
2.51.0 -- Thierry Escande | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
Re: [PATCH 17/17] docs: provide description for device_model_machine option
Quoted 5 lines · Thierry Escande
This patch adds description for '
device_model_machine' option which allows to control which chipset will be emulated by device model.Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>
This wants squashing with the xl patch that adds the option.
Thanks, Roger.
Re: [PATCH 17/17] docs: provide description for device_model_machine option
Quoted 9 lines · Roger Pau Monné
Quoted 5 lines · Thierry Escande
This patch adds description for '
device_model_machine' option which allows to control which chipset will be emulated by device model.Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>This wants squashing with the xl patch that adds the option.
Will do.
Regards,
--
Thierry Escande | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH 17/17] docs: provide description for device_model_machine option
In reply to Thierry EscandeQuoted 19 lines · Thierry Escande
This patch adds description for '
device_model_machine' option which allows to control which chipset will be emulated by device model.Signed-off-by Alexey Gerasimenko <[email protected]>Signed-off-by Thierry Escande <[email protected]>--- docs/man/xl.cfg.5.pod.in | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)docs/man/xl.cfg.5.pod.in +2
-0@@ -2963,6 +2963,33 @@ you have existing guests then, depending on the nature of the guest Operating System, you may wish to force them to use the device model which they were installed with. +=item B<device_model_machine="STRING"> +
docs/man/xl.cfg.5.pod.in you have existing guests then, depending on the nature of the guest · line 2977
Quoted 10 lines
docs/man/xl.cfg.5.pod.in +10
-0+Selects which chipset the device model should emulate for this +guest. + +Valid options are: + +=over 4 + +=item B<"i440"> + +Use i440 emulation (a default setting)
Just "(default)" or even nothing is fine too.
I don't think we can say "i440" here, QEMU code always reference to it as "i440FX", and if you want to specify the south bridge like you do below, it would be "i440FX/PIIX3".
docs/man/xl.cfg.5.pod.in you have existing guests then, depending on the nature of the guest · line 2982
Quoted 5 lines
docs/man/xl.cfg.5.pod.in +5
-0+ +=item B<"q35"> + +Use Q35/ICH9 emulation. This enables additional features for +PCIe device passthrough
Could you add a full stop, to finish the sentence?
docs/man/xl.cfg.5.pod.in you have existing guests then, depending on the nature of the guest
Quoted 4 lines
docs/man/xl.cfg.5.pod.in +4
-0+=back + +Note that omitting device_model_machine parameter means i440 system +by default,
Just saying "The default is B<"i440fx"> should be enough. No need to explain when a default is selected.
Quoted 2 lines
so the default behavior doesn't change for old domain +config files.
I don't think this explanation belong here.
docs/man/xl.cfg.5.pod.in you have existing guests then, depending on the nature of the guest · line 2991
Quoted 2 lines
docs/man/xl.cfg.5.pod.in +2
-0+It is recommended to install the guest OS from scratch to avoid issues +due to the emulated platform change.
I don't think this belong to the man page because they are other setting that could prevent a guest from booting, when changed. Also I don't think Linux cares. I'm not sure saying that changing this particular setting could break existing guest would be a useful addition to this particular setting description, as I'm sure that also true to quite a few other settings.
On the other hand, there's a warning for device_model_version, about existing guest, and default value that have changed.
So it's probably good enough to say that changing this new setting could prevent existing guest from booting, and a fresh new installation might be needed.
Also installing Linux From Scratch would be quite and endeavor :-)
https://www.linuxfromscratch.org/
Cheers,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Hello,
I'm glad someone wants to commit these patches (and surprised that they're still applicable after so many years), thank you for this effort. Feel free to proceed, it would be good if you manage to upstream them to Xen/QEMU code. But be prepared that it won't be an easy task - the patches cross multiple areas of responsibility, so it will require some effort to make all involved Xen/QEMU maintainers happy. I don't work on virtualization/x86 anymore and I barely remember anything after 8 years, so I probably won't be able to help much, but I'll keep an eye on the email thread.
Some historical background for the Q35 patches:
The project I was working on was relying on Xen for PCIe device passthrough (mostly GPUs, NICs and storage controllers) to HVM guests. So PCIe passthrough and HVM were the top priority - it affected many of my decisions.
IIRC, there were 2 major obstacles to successfully passthrough any PCIe device:
1. Even back then, there were **multiple PCIe devices whose drivers were attempting to read/write registers from their device's PCIe extended config space** (offsets above 100h). Supporting this feature required to have MMCONFIG/ECAM working, which was something only available for Q35 emulation at that time => hence Q35 support was added, with mostly PCIe passthrough in mind. In the process I also discovered that dreadful "PCIe topology check" issue which was bypassed by presenting the passed through PCIe device to the OS as a chipset built-in device. This solution was a bit hacky, but allowed to successfully pass through PCIe devices to a Q35 HVM guest.
2. Some devices had mirrors of BAR registers' values _accessed through a proprietary mechanism_, like reading them through device-specific MMIO registers. As such, their drivers do not read a BAR value from the PCI conf space but rather get it directly from eg. MMIO, whose layout is completely unknown to us. This makes all BAR emulation in the hypervisor useless for such device - the hypervisor returns one value for BARs read via PCI conf space, but the driver sees the real values as it bypasses the PCI conf space. Among such devices were Nvidia GPUs BTW - but not including the "pro" models AFAIR, which were more virtualization-friendly.
That "BAR desync" problem was tricky - I solved it by implementing an option (in the domain config file) for a passed through device which, when turned on, was basically enabling 1:1 matching between virtual and physical BAR values for a given device, without affecting other devices (be it PT or emulated). This way virtual physical addresses in BARs match the real ones - hence the device driver sees the same values either in the PCI conf space or proprietary registers.
But it wasn't that simple, unfortunately - having a specific "locked" BAR value means we need to adjust the MMIO hole size for the guest accordingly. A straightforward approach is to make the MMIO hole size very big. This in turn brought another problems to solve:
2.1. when a recent (back then) Windows OS sees PCI BAR allocation which is far from perfect - it can completely reallocate all BARs of all devices to other, very different addresses. They were calling this feature as PCIe "resource rebalancing" IIRC. This breaks 1:1 mirroring of given device's virtual/physical BARs - it's ok to present BARs with real physical addresses (the sneaky device driver knows them via MMIO registers anyway), but allowing to modify values in BARs is a no go, of course.
Luckily, this problem was solved by a specific PCI BAR allocation - the idea was to keep the MMIO hole as small as possible while avoiding large unused gaps inside it, not claimed by any BAR. It was implemented inside hvmloader, which was populating the MMIO hole while taking into account both fixed and freely modifiable BARs and then reported the new RAM/MMIO hole layout back to Xen. This allowed to prevent the PCI BAR reallocation from the OS - and hotplugging was still working thanks to the high MMIO hole (above 4Gb).
2.2. after experimenting with dynamic resizing of the MMIO hole, I realized that Xen and QEMU have their own vision of the system memory layout which can get out of sync. And MMIO hole resize was creating this bad situation in fact, giving some hard to debug/reproduce bugs with unexpected guest memory corruption.
The way I fixed this memory mismatch was emulating the real Q35 facility for this - namely, chipset's REMAP register which was designed precisely for this goal - to reconfigure the MMIO hole size/position while relocating underlying RAM memory to another range (so no RAM is wasted). As the chipset was emulated by QEMU and the whole idea of HVM was to emulate real hardware as close as possible, this was the obvious solution - we do it in the way like it's done in a real firmware and then QEMU knows the RAM/MMIO hole layout, allowing to sync it with Xen's. There were some other fixed issues relying on this feature - AFAIR, I needed it also to make 'populate on demand' working with (hotplugged?) PT devices.
I was planning to send patches for this feature too, after settling the Q35 patches. I'll try to find the relevant code/notes, maybe they will be helpful.
Quoted 47 lines · On Fri, 13 Mar 2026 16:35:01 +0000 "Thierry Escande"…
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
In order to create a Q35 guest, a new domain config option has been added, named '
device_model_machine'. Possible values are:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machineIf the option is omitted it defaults to "i440", not impacting existing domain configuration files.
DSDT files for Q35 and i440 are largely similar so the existing file dsdt.asl has been split with i440 and q35 specific parts put in seperated files.
The PCIe MMCONFIG area is configured by hvmloader and its base address and size are set in Xen using a new pair of hypercalls HVMOP_get|set_ecam_space. Access to the MMCONFIG area from a guest is trapped by Xen and transfered to the emulator as
XEN_DMOP_IO_RANGE_PCIioreq type.[1] https://lore.kernel.org/xen-devel/[email protected]/
Thierry Escande (17):
libacpi: Split dsdt.asl file and extract i440 specific parts
libacpi: new DSDT ACPI table for Q35
hvmloader: add function to set the emulated machine type (i440/Q35)
hvmloader: add ACPI enabling for Q35
hvmloader: add Q35 DSDT table loading
hvmloader: Move pci devices setup to a separate function
hvmloader: add basic Q35 support
hvmloader: Extend PCI BAR struct
xev/hvm: Add HVMOP_get|set_ecam_space hypercalls
hvmloader: Add support for HVMOP_set|get_ecam_space hypercalls
hvmloader: allocate MMCONFIG area in the MMIO hole
libxl: Q35 support (new optiondevice_model_machine)
libxl: Add xen-platform device for Q35 machine
libacpi: build ACPI MCFG table if requested
hvmloader: Set MCFG in ACPI table
Handle PCIe ECAM space access from guests
docs: provide description fordevice_model_machineoption
Quoted 10 lines · Thierry Escande
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
Quoted 5 lines
In order to create a Q35 guest, a new domain config option has been added, named '
device_model_machine'. Possible values are:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machine
Quoted 8 lines
If the option is omitted it defaults to "i440", not impacting existing domain configuration files.
DSDT files for Q35 and i440 are largely similar so the existing file dsdt.asl has been split with i440 and q35 specific parts put in seperated files.
The PCIe MMCONFIG area is configured by hvmloader and its base address and size are set in Xen using a new pair of hypercalls HVMOP_get|set_ecam_space.
I guess I will see how that looks like in the series, but the setting of the ECAM region would better be done by the toolstack. Setting it in hvmloader is possibly not the best placement, because it doesn't run for PVH guests (and we will want ECAM support for PVH at some point), and there's also a vague plan/intention to get rid of hvmloader even for HVM guests eventually.
Quoted 3 lines
Access
to the MMCONFIG area from a guest is trapped by Xen and transfered to the emulator asXEN_DMOP_IO_RANGE_PCIioreq type.
Thanks for doing this bit, IIRC from when this was last posted this was the biggest shortcoming of the series when originally submitted.
Thanks, Roger.
Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Thierry Escande
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Quoted 7 lines
Quoted 3 lines
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
Can a valid PCIe topology be expressed with just bus 0? If an endpoint to be handed to a guest isn't root complex integrated, would it be valid to make it appear so by putting it on bus 0?
Jan
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Roger Pau Monné
Quoted 10 lines · Thierry Escande
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
Quoted 7 lines
Quoted 3 lines
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
Can a valid PCIe topology be expressed with just bus 0? If an endpoint to be handed to a guest isn't root complex integrated, would it be valid to make it appear so by putting it on bus 0?
We discussed this with Roger on our x86 call, and we came to the agreement that for the time being putting everything on bus 0 may be good enough. Introducing of bridge(s) and anything else that's required for multi-bus support will want to be a separate piece of work.
Jan
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Jan Beulich
Quoted 15 lines · Roger Pau Monné
Quoted 10 lines · Thierry Escande
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
Quoted 8 lines
Quoted 3 lines
Can a valid PCIe topology be expressed with just bus 0? If an endpoint to be handed to a guest isn't root complex integrated, would it be valid to make it appear so by putting it on bus 0?
We discussed this with Roger on our x86 call, and we came to the agreement that for the time being putting everything on bus 0 may be good enough. Introducing of bridge(s) and anything else that's required for multi-bus support will want to be a separate piece of work.
Oh, and: Where applicable this (deliberate) restriction (or should I say mistreatment) will want calling out in description(s).
Jan
Quoted 7 lines · On Mon, 4 May 2026 12:45:23 +0200 Jan Beulich <[email protected]> wrote:
Quoted 3 lines
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
Can a valid PCIe topology be expressed with just bus 0? If an endpoint to be handed to a guest isn't root complex integrated, would it be valid to make it appear so by putting it on bus 0?
No, unfortunately, it will fail at least under Windows' pci.sys driver. Unless they changed something in the past years. To place an endpoint device to bus 0, we need to emulate that it's a chipset-integrated device by trapping its PCIe Capabilities reads.
I found an old pci.sys + .pdb symbols which I used for debugging back in 2017 and, if I remember correctly, the failing function was ExpressValidateFabricTopology().
Quoted 8 lines · On Tue, 28 Apr 2026 09:48:41 +0200 Roger Pau Monné <[email protected]> wrote:
Quoted 7 lines · Thierry Escande
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Quoted 7 lines
Quoted 3 lines
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
The problem with the PCIe bus is that it's very "topological" by design
- and it always wants a valid hierarchy.
Each PCIe device manifests itself (via its PCIe Capabilities entry) as either a chipset-integrated device or a regular PCIe endpoint device, which is the most common case. There are more types IIRC but these are what we deal with mostly - both for PT devices and QEMU-emulated ones.
But, being a PCIe endpoint means that the device must have some parent device. It can be located below a PCIe switch or, in the simplest and the most common case, below a PCIe Root Port device.
In both cases the 'parent' is a PCI-PCI bridge technically, with the PCIe endpoint device being located on its secondary bus.
As the Q35 patch series was done with mostly PCIe device passthrough in mind, this brings the main complication - in order to properly place a passed through device on the PCIe bus, we need an emulated/real/hybrid Root Port device.
A much lengthier description is in this patch message:
https://lists.xenproject.org/archives/html/xen-devel/2018-03/msg01197.html
To summarize, we need this 'valid PCIe topology' nonsense just to make Windows kernel (pci.sys driver specifically) not to discard our PT device due to checking PCIe bus hierarchy above it.
This limitation was found/confirmed via debugging - luckily, pci.sys had symbols and the main bad function which was failing had a very speaking name - something like pcieCheckTopology or similar.
Emulating the "chipset-integrated device" in PT device's PCIe Capabilities was a simple hack which allowed to bypass the requirement to have a valid PCIe hierarchy with multiple buses. But the proper future direction is implementing emulation of Root Ports or PCIe switches I guess.
Quoted 10 lines
Quoted 3 lines
The PCIe MMCONFIG area is configured by hvmloader and its base address and size are set in Xen using a new pair of hypercalls HVMOP_get|set_ecam_space.
I guess I will see how that looks like in the series, but the setting of the ECAM region would better be done by the toolstack. Setting it in hvmloader is possibly not the best placement, because it doesn't run for PVH guests (and we will want ECAM support for PVH at some point), and there's also a vague plan/intention to get rid of hvmloader even for HVM guests eventually.
This is the situation where the difference between HVM and PVH might be very problematic I'm afraid. HVM guests assume full freedom over the IO/MMIO resources setup inside their sandboxed environment.
It's not just Windows reallocating PCI BARs to its liking, but also spans to the emulated chipset's resources. In worst case we could have MMCONFIG reinitialization implemented even in Intel's Q35 drivers installed inside an HVM guest. Fortunately, this is not what I remember was the case, but in theory Q35 driver could have done things like this.
Quoted 51 lines · Alexey G
Quoted 8 lines · On Tue, 28 Apr 2026 09:48:41 +0200 Roger Pau Monné <[email protected]> wrote:
Quoted 7 lines · Thierry Escande
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Quoted 7 lines
Quoted 3 lines
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
The problem with the PCIe bus is that it's very "topological" by design
- and it always wants a valid hierarchy.Each PCIe device manifests itself (via its PCIe Capabilities entry) as either a chipset-integrated device or a regular PCIe endpoint device, which is the most common case. There are more types IIRC but these are what we deal with mostly - both for PT devices and QEMU-emulated ones.
But, being a PCIe endpoint means that the device must have some parent device. It can be located below a PCIe switch or, in the simplest and the most common case, below a PCIe Root Port device.
In both cases the 'parent' is a PCI-PCI bridge technically, with the PCIe endpoint device being located on its secondary bus.
As the Q35 patch series was done with mostly PCIe device passthrough in mind, this brings the main complication - in order to properly place a passed through device on the PCIe bus, we need an emulated/real/hybrid Root Port device.
A much lengthier description is in this patch message:
https://lists.xenproject.org/archives/html/xen-devel/2018-03/msg01197.htmlTo summarize, we need this 'valid PCIe topology' nonsense just to make Windows kernel (pci.sys driver specifically) not to discard our PT device due to checking PCIe bus hierarchy above it.
This limitation was found/confirmed via debugging - luckily, pci.sys had symbols and the main bad function which was failing had a very speaking name - something like pcieCheckTopology or similar.
Quoted 5 lines
Emulating the "chipset-integrated device" in PT device's PCIe Capabilities was a simple hack which allowed to bypass the requirement to have a valid PCIe hierarchy with multiple buses. But the proper future direction is implementing emulation of Root Ports or PCIe switches I guess.
Oh, I see. We discussed this with Jan, it wasn't clear whether it would be a strict requirement or not. We have our answer now, it is a strict requirement for pass-through to Windows guests.
Quoted 15 lines
Quoted 10 lines
Quoted 3 lines
The PCIe MMCONFIG area is configured by hvmloader and its base address and size are set in Xen using a new pair of hypercalls HVMOP_get|set_ecam_space.
I guess I will see how that looks like in the series, but the setting of the ECAM region would better be done by the toolstack. Setting it in hvmloader is possibly not the best placement, because it doesn't run for PVH guests (and we will want ECAM support for PVH at some point), and there's also a vague plan/intention to get rid of hvmloader even for HVM guests eventually.
This is the situation where the difference between HVM and PVH might be very problematic I'm afraid. HVM guests assume full freedom over the IO/MMIO resources setup inside their sandboxed environment.
Quoted 5 lines
It's not just Windows reallocating PCI BARs to its liking, but also spans to the emulated chipset's resources. In worst case we could have MMCONFIG reinitialization implemented even in Intel's Q35 drivers installed inside an HVM guest. Fortunately, this is not what I remember was the case, but in theory Q35 driver could have done things like this.
Indeed. In later patches my recommendation was to trap accesses to the root complex registers that control the position and size of the ECAM region, and forward those to the hypervisor, instead of hvmloader using a side-band hypercall to set the position and size of the ECAM region.
I've also discussed this with Jan, alternatively we could trap the registers directly in Xen itself, but the Xen would need to know the domain has an emulated q35, which we might need to do at some point, but we are likely not there yet.
Thanks, Roger.
Quoted 8 lines · Roger Pau Monné
Quoted 7 lines · Thierry Escande
This series introduces initial Q35 chipset support for HVM guests, based on the patchset at [1] by Alexey Gerasimenko.
Basic support means that this patchset allows to start an HVM guest that emulates a Q35 chipset via Qemu and implements access to PCIe extended configuration space for such devices emulated by Qemu.
Quoted 7 lines
Quoted 3 lines
Support for PCIe device passthrough is not implemented yet. This is planned but implies modifications in the hypervisor and the firmwares, mainly for the support of multiple PCI buses.
Why do you need multi bus support to expose PCIe capabilities? I'm not seeing the relation between those two. You could still expose a single bus on the MCFG table.
I should have explained further but the main reason is that Q35 doesn't support device hot-plug on its main root bus, which is how toolstacks are doing device pass-through. This needs another PCI root port to connect pass-through'd devices to and here begin the problems. The new root complex attached to Qemu is not seen as a secondary bus before the devices are hot-plugged and are simply ignored by the toolstack. And even by hacking around to get the devices plugged, Xen doesn't expose them to the guest because it's not on PCI bus #0.
But instead of adding support for multiple PCIe buses, the solution could be to not use Qemu hot-plug mechanism but rather attach passthrough'd devices using Qemu command line option -device. A patchset as been sent the the ML for that. See [1].
Quoted 15 lines
Quoted 6 lines
In order to create a Q35 guest, a new domain config option has been added, named '
device_model_machine'. Possible values are:
- "i440" - i440 emulation (default)
- "q35" - emulate a Q35 machineQuoted 8 lines
If the option is omitted it defaults to "i440", not impacting existing domain configuration files.
DSDT files for Q35 and i440 are largely similar so the existing file dsdt.asl has been split with i440 and q35 specific parts put in seperated files.
The PCIe MMCONFIG area is configured by hvmloader and its base address and size are set in Xen using a new pair of hypercalls HVMOP_get|set_ecam_space.
Quoted 6 lines
I guess I will see how that looks like in the series, but the setting of the ECAM region would better be done by the toolstack. Setting it in hvmloader is possibly not the best placement, because it doesn't run for PVH guests (and we will want ECAM support for PVH at some point), and there's also a vague plan/intention to get rid of hvmloader even for HVM guests eventually.
Since hvmloader is taking care of the bars array arrangements, that sounds to be the most convenient place to configure the mmconfig entry. All that logic would be moved to the toolstack with the hvmloader removal plan.
I tried to have the toolstack to fix the base address of the ECAM region but then that breaks the logic of hvmloader PCI setup for BARs arrangement. As you suggested (or Jan), we could state that the ECAM region must be placed first in the MMIO hole and the toolstack would just have to indicate that we want an ECAM region, with hvmloader placing it first and with the smallest possible size (as there's only 1 bus).
Regards,
Thierry
Regards,
--
| Vates
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech