hw/pc: implement multiple primary busses for pc machines
v6 cover hw/pc: implement multiple primary busses for pc machines
Notes:
- I realize that this qualifies as a late submission, but the code was arround
a lot of time and got lots of reviews and it also tested (by Gerd), so should be mature enough.
- This series is not that big, patches 1-8 are really small and can be submitted separately, however I preferred to keep them here to get the whole picture.
The series is fully functional.
- Limitations:
- Pxb's bus does not support hotplug. It will be addressed on top of this series because is already getting to big.
- You are more than welcome to try using:
-device pxb-device,id=pxb,bus_nr=4,numa_node=1 -device e1000,bus=pxb,addr=0x1 -bios <patched with the above series>
v5->v6:
- This version includes a lot of refactoring requested by Michael S. Tsirking, but no new/different functionality:
- Removed the HOST_BRIDGE_FOR_EACH loop because it too generic
- Reduced the generic "extra pci roots" aproach to a more "non-generic" root bus having snooping buses listening to its configuration space. Instead of going over all host bridges, we go only over the snooping host bridges associated with the main host bridge.
- The current implementation made i440fx the only a "snooped" host bridge
- Addressed Michael S. Tsirkin's review:
- Replaced qmp queries with native pci ones.
- Squashed later patches into their places
- Tweaked a few comments
- Addressed Shannon Zhao's review:
- Used build_append_byte instead of build_append_int
- Addressed Gerd's review:
- Reduced the "Line over 80" warnings.
- Rebased on pci branch, tree: git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git
- a few days before, I hope is enough
- Changed some patches order
v4->v5:
- Rebased on pci branch, tree: git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git
- Added PXB documentation (patch 28/28)
- Addressed Gerd Hoffmann's review:
- fix PXB behaviour if used with unsupported BIOS (patch 27/28)
- Addressed Michael S. Tsirkin's review:
- Removed assert in aml_index (patch 5/28)
- Renamed pci_ functions to crs_ (patch 12/28)
- used uint64_t variables instead of signed ones (patch 12/28)
- Emit MEM/IO AML only for PXBs and i440fx (patch 26/28)
- Addressed Shannon Zhao's review:
- Changed build_append_int to build_append_byte in aml_or (patch 2/25)
- Thanks to Igor and Kevin for reviews
v3->v4:
- Addressed Michael S. Tsirkin's review:
- refactored build_prt method (patch 11/25) hw/apci: add _PRT method for extra PCI root busses
- Addressed Igor Mammedov's reiew
- add assert to aml_index (patch 5/25)
- Fixed aml_equal implementation (patch 1/25)
v2->v3:
- Rebased on Michael S. Tsirkin's pci branch (that includes now all the dependencies)
- Refactored acpi terms patch into multiple patches to match Igor's design.
v1->v2:
- Add support for multiple pxb devices.
- Attach pxb's bus to specific NUMA node.
- Got rid of the hacks from prev version.
- Tested also for Win7 and Fedora 20, and for virtio blk devices.
- Several bug-fixes resulting in a stable version ready for submission.
Reasoning:
We need multiple primary busess for a few reasons, the most important one is to be able to associate a pass-trough device with a guest NUMA node. The OS-es are able to associate a NUMA node only to a primary bus, not to a specific PCI device or a pci-2-pci bridge.
PC machines support multiple NUMA nodes for CPUs and memory, however the IO was not yet supported.
patch 1-8 adds the necessary acpi constructs based on Igor's series patch 9 separates the pci_bus code into a designated file
patch 10-11 implement some supporting methods
patch 12-13 Introduces the interfaces used to bind host bridges to the snooping ones patch 14 made i440fx a snooped host bridge
patch 15-18 acpi support for snooping buses
patch 19 a qmp fix for multiple host bridgesi
patch 20 handles the actual implementation of the PXB devices
patch 21-22 enables the device
patch 23-24 adds NUMA support
patch 25 Backward compatibility with SeaBIOS
patch 26 PXB Documentation
Marcel Apfelbaum (26):
acpi: add aml_or() term
acpi: add aml_add() term
acpi: add aml_lless() term
acpi: add aml_index() term
acpi: add aml_shiftleft() term
acpi: add aml_shiftright() term
acpi: add aml_increment() term
acpi: add aml_while() term
hw/pci: move pci bus related code to separate files
hw/pci: made pci_bus_is_root a PCIBusClass method
hw/pci: made pci_bus_num a PCIBusClass method
hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface hw/pci-host/piix: implement TYPE_PCI_HOST_BRIDGE_SNOOPED interface hw/acpi: add support for i440fx 'snooping' root busses hw/apci: add _PRT method for extra PCI root busses
hw/acpi: add _CRS method for extra root busses
hw/acpi: remove from root bus 0 the crs resources used by other busses. hw/pci: removed 'rootbus nr is 0' assumption from qmp_pci_query hw/pci: introduce PCI Expander Bridge (PXB)
hw/pci: inform bios if the system has extra pci root buses hw/pxb: add map_irq func
hw/pci_bus: add support for NUMA nodes
hw/pxb: add numa_node parameter
apci: fix PXB behaviour if used with unsupported BIOS
docs: Add PXB documentation
arch_init.c | 1 + docs/pci_expander_bridge.txt | 52 ++++ hw/acpi/aml-build.c | 75 ++++++ hw/alpha/typhoon.c | 1 + hw/i386/acpi-build.c | 377 ++++++++++++++++++++++++-- hw/i386/kvm/pci-assign.c | 1 + hw/i386/pc.c | 13 + hw/mips/gt64xxx_pci.c | 1 + hw/pci-bridge/Makefile.objs | 1 + hw/pci-bridge/pci_expander_bridge.c | 207 +++++++++++++++ hw/pci-host/bonito.c | 1 + hw/pci-host/grackle.c | 1 + hw/pci-host/piix.c | 128 ++++++++- hw/pci-host/ppce500.c | 1 + hw/pci-host/q35.c | 5 + hw/pci-host/uninorth.c | 1 + hw/pci/Makefile.objs | 2 +- hw/pci/pci.c | 493 +--------------------------------- hw/pci/pci_bus.c | 517 ++++++++++++++++++++++++++++++++++++ hw/pci/pci_host.c | 42 +++ hw/ppc/ppc4xx_pci.c | 1 + hw/scsi/megasas.c | 1 + hw/sh4/r2d.c | 1 + hw/sh4/sh_pci.c | 1 + hw/vfio/pci.c | 1 + hw/xen/xen_pt.c | 1 + include/hw/acpi/aml-build.h | 8 + include/hw/i386/pc.h | 8 +- include/hw/pci/pci.h | 6 +- include/hw/pci/pci_bus.h | 35 +++ include/hw/pci/pci_host.h | 34 +++ include/sysemu/sysemu.h | 1 + 32 files changed, 1508 insertions(+), 510 deletions(-) create mode 100644 docs/pci_expander_bridge.txt create mode 100644 hw/pci-bridge/pci_expander_bridge.c create mode 100644 hw/pci/pci_bus.c
Signature · 1 line
2.1.0
PATCH v6 1/26 acpi: add aml_or() term
Add encoding for ACPI DefOr Opcode.
--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -453,6 +453,16 @@ Aml *aml_and(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefOr */ +Aml *aml_or (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x7D /* OrOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +build_append_byte (var->buf,0x00 );/* NullNameOp */ +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */ Aml *aml_notify (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -137,6 +137,7 @@ Aml *aml_int(const uint64_t val);Aml *aml_arg (int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2); +Aml *aml_or (Aml *arg1,Aml *arg2);Aml *aml_notify (Aml *arg1,Aml *arg2);Aml *aml_call1 (const char *method,Aml *arg1);Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2);
Signature · 1 line
2.1.0
PATCH v6 2/26 acpi: add aml_add() term
In reply to Marcel ApfelbaumAdd encoding for ACPI DefAdd Opcode.
--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -463,6 +463,16 @@ Aml *aml_or(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */ +Aml *aml_add (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x72 /* AddOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +build_append_byte (var->buf,0x00 /* NullNameOp */ ); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */ Aml *aml_notify (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -138,6 +138,7 @@ Aml *aml_arg(int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2);Aml *aml_or (Aml *arg1,Aml *arg2); +Aml *aml_add (Aml *arg1,Aml *arg2);Aml *aml_notify (Aml *arg1,Aml *arg2);Aml *aml_call1 (const char *method,Aml *arg1);Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2);
Signature · 1 line
2.1.0
PATCH v6 3/26 acpi: add aml_lless() term
In reply to Marcel ApfelbaumAdd encoding for ACPI DefLLess Opcode.
--- hw/acpi/aml-build.c | 9 +++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 10 insertions(+)
hw/acpi/aml-build.c +9 -0
@@ -463,6 +463,15 @@ Aml *aml_or(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */ +Aml *aml_lless (Aml *arg1,Aml *arg2) +{ +Aml *var =aml_opcode (0x95 /* LLessOp */ ); +aml_append (var, arg1); +aml_append (var, arg2); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */ Aml *aml_add (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -138,6 +138,7 @@ Aml *aml_arg(int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2);Aml *aml_or (Aml *arg1,Aml *arg2); +Aml *aml_lless (Aml *arg1,Aml *arg2);Aml *aml_add (Aml *arg1,Aml *arg2);Aml *aml_notify (Aml *arg1,Aml *arg2);Aml *aml_call1 (const char *method,Aml *arg1);
Signature · 1 line
2.1.0
PATCH v6 4/26 acpi: add aml_index() term
In reply to Marcel ApfelbaumAdd encoding for ACPI DefIndex Opcode.
--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -482,6 +482,16 @@ Aml *aml_add(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */ +Aml *aml_index (Aml *arg1,Aml *idx) +{ +Aml *var =aml_opcode (0x88 /* IndexOp */ ); +aml_append (var, arg1); +aml_append (var, idx); +build_append_byte (var->buf,0x00 /* NullNameOp */ ); +return var; +} +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */ Aml *aml_notify (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -140,6 +140,7 @@ Aml *aml_and(Aml *arg1, Aml *arg2);Aml *aml_or (Aml *arg1,Aml *arg2);Aml *aml_lless (Aml *arg1,Aml *arg2);Aml *aml_add (Aml *arg1,Aml *arg2); +Aml *aml_index (Aml *arg1,Aml *idx);Aml *aml_notify (Aml *arg1,Aml *arg2);Aml *aml_call1 (const char *method,Aml *arg1);Aml *aml_call2 (const char *method,Aml *arg1,Aml *arg2);
Signature · 1 line
2.1.0
PATCH v6 5/26 acpi: add aml_shiftleft() term
In reply to Marcel ApfelbaumAdd encoding for ACPI DefShiftLeft Opcode.
--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -463,6 +463,16 @@ Aml *aml_or(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefShiftLeft */ +Aml *aml_shiftleft (Aml *arg1,Aml *count) +{ +Aml *var =aml_opcode (0x79 /* ShiftLeftOp */ ); +aml_append (var, arg1); +aml_append (var, count); +build_append_byte (var->buf,0x00 );/* NullNameOp */ +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */ Aml *aml_lless (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -138,6 +138,7 @@ Aml *aml_arg(int pos);Aml *aml_store (Aml *val,Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2);Aml *aml_or (Aml *arg1,Aml *arg2); +Aml *aml_shiftleft (Aml *arg1,Aml *count);Aml *aml_lless (Aml *arg1,Aml *arg2);Aml *aml_add (Aml *arg1,Aml *arg2);Aml *aml_index (Aml *arg1,Aml *idx);
Signature · 1 line
2.1.0
PATCH v6 6/26 acpi: add aml_shiftright() term
In reply to Marcel ApfelbaumAdd encoding for ACPI DefShiftRight Opcode.
--- hw/acpi/aml-build.c | 10 ++++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 11 insertions(+)
hw/acpi/aml-build.c +10 -0
@@ -473,6 +473,16 @@ Aml *aml_shiftleft(Aml *arg1, Aml *count)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefShiftRight */ +Aml *aml_shiftright (Aml *arg1,Aml *count) +{ +Aml *var =aml_opcode (0x7A /* ShiftRightOp */ ); +aml_append (var, arg1); +aml_append (var, count); +build_append_byte (var->buf,0x00 );/* NullNameOp */ +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */ Aml *aml_lless (Aml *arg1,Aml *arg2) {
include/hw/acpi/aml-build.h +1 -0
@@ -139,6 +139,7 @@ Aml *aml_store(Aml *val, Aml *target);Aml *aml_and (Aml *arg1,Aml *arg2);Aml *aml_or (Aml *arg1,Aml *arg2);Aml *aml_shiftleft (Aml *arg1,Aml *count); +Aml *aml_shiftright (Aml *arg1,Aml *count);Aml *aml_lless (Aml *arg1,Aml *arg2);Aml *aml_add (Aml *arg1,Aml *arg2);Aml *aml_index (Aml *arg1,Aml *idx);
Signature · 1 line
2.1.0
PATCH v6 7/26 acpi: add aml_increment() term
In reply to Marcel ApfelbaumAdd encoding for ACPI DefIncrement Opcode.
--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -502,6 +502,14 @@ Aml *aml_add(Aml *arg1, Aml *arg2)return var; } +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIncrement */ +Aml *aml_increment (Aml *arg) +{ +Aml *var =aml_opcode (0x75 /* IncrementOp */ ); +aml_append (var, arg); +return var; +} +/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */ Aml *aml_index (Aml *arg1,Aml *idx) {
include/hw/acpi/aml-build.h +1 -0
@@ -142,6 +142,7 @@ Aml *aml_shiftleft(Aml *arg1, Aml *count);Aml *aml_shiftright (Aml *arg1,Aml *count);Aml *aml_lless (Aml *arg1,Aml *arg2);Aml *aml_add (Aml *arg1,Aml *arg2); +Aml *aml_increment (Aml *arg);Aml *aml_index (Aml *arg1,Aml *idx);Aml *aml_notify (Aml *arg1,Aml *arg2);Aml *aml_call1 (const char *method,Aml *arg1);
Signature · 1 line
2.1.0
PATCH v6 8/26 acpi: add aml_while() term
In reply to Marcel ApfelbaumAdd encoding for ACPI DefWhile Opcode.
--- hw/acpi/aml-build.c | 8 ++++++++ include/hw/acpi/aml-build.h | 1 + 2 files changed, 9 insertions(+)
hw/acpi/aml-build.c +8 -0
@@ -625,6 +625,14 @@ Aml *aml_if(Aml *predicate)return var; } +/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefWhile */ +Aml *aml_while (Aml *predicate) +{ +Aml *var =aml_bundle (0xA2 /* WhileOp */ ,AML_PACKAGE ); +aml_append (var, predicate); +return var; +} +/* ACPI 1.0b: 16.2.5.2 Named Objects Encoding: DefMethod */ Aml *aml_method (const char *name,int arg_count) {
include/hw/acpi/aml-build.h +1 -0
@@ -189,6 +189,7 @@ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);Aml *aml_device (const char *name_format, ...)GCC_FMT_ATTR (1 ,2 );Aml *aml_method (const char *name,int arg_count);Aml *aml_if (Aml *predicate); +Aml *aml_while (Aml *predicate);Aml *aml_package (uint8_t num_elements);Aml *aml_buffer (void );Aml *aml_resource_template (void );
Signature · 1 line
2.1.0
PATCH v6 9/26 hw/pci: move pci bus related code to separate files
In reply to Marcel ApfelbaumThis refactoring moves all the code needed (recursively) to register TYPE_PCI_BUS type to a new file hw/pci/pci_bus.c . This allows to properly add new functionality to the pci bus class.
--- arch_init.c | 1 + hw/alpha/typhoon.c | 1 + hw/mips/gt64xxx_pci.c | 1 + hw/pci-host/bonito.c | 1 + hw/pci-host/grackle.c | 1 + hw/pci-host/piix.c | 1 + hw/pci-host/ppce500.c | 1 + hw/pci-host/q35.c | 1 + hw/pci-host/uninorth.c | 1 + hw/pci/Makefile.objs | 2 +- hw/pci/pci.c | 472 +-------------------------------------------- hw/pci/pci_bus.c | 491 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/ppc4xx_pci.c | 1 + hw/sh4/r2d.c | 1 + hw/sh4/sh_pci.c | 1 + include/hw/pci/pci.h | 3 +- include/hw/pci/pci_bus.h | 8 + 17 files changed, 514 insertions(+), 474 deletions(-) create mode 100644 hw/pci/pci_bus.c
arch_init.c +1 -0
@@ -37,6 +37,7 @@#include "audio/audio.h" #include "hw/i386/pc.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/audio/audio.h" #include "sysemu/kvm.h" #include "migration/migration.h"
hw/alpha/typhoon.c +1 -0
@@ -8,6 +8,7 @@#include "cpu.h" #include "hw/hw.h" +#include "hw/pci/pci_bus.h" #include "hw/devices.h" #include "sysemu/sysemu.h" #include "alpha_sys.h"
hw/mips/gt64xxx_pci.c +1 -0
@@ -25,6 +25,7 @@#include "hw/hw.h" #include "hw/mips/mips.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "hw/i386/pc.h" #include "exec/address-spaces.h"
hw/pci-host/bonito.c +1 -0
@@ -41,6 +41,7 @@#include "hw/hw.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/i386/pc.h" #include "hw/mips/mips.h" #include "hw/pci/pci_host.h"
hw/pci-host/grackle.c +1 -0
@@ -26,6 +26,7 @@#include "hw/pci/pci_host.h" #include "hw/ppc/mac.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" /* debug Grackle */ //#define DEBUG_GRACKLE
hw/pci-host/piix.c +1 -0
@@ -25,6 +25,7 @@#include "hw/hw.h" #include "hw/i386/pc.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "hw/isa/isa.h" #include "hw/sysbus.h"
hw/pci-host/ppce500.c +1 -0
@@ -17,6 +17,7 @@#include "hw/hw.h" #include "hw/ppc/e500-ccsr.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "qemu/bswap.h" #include "hw/pci-host/ppce500.h"
hw/pci-host/q35.c +1 -0
@@ -28,6 +28,7 @@* THE SOFTWARE. */ #include "hw/hw.h" +#include "hw/pci/pci_bus.h" #include "hw/pci-host/q35.h" #include "qapi/visitor.h"
hw/pci-host/uninorth.c +1 -0
@@ -24,6 +24,7 @@#include "hw/hw.h" #include "hw/ppc/mac.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" /* debug UniNorth */
hw/pci/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o +common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bus.o common-obj-$(CONFIG_PCI) += msix.o msi.o common-obj-$(CONFIG_PCI) += shpc.o common-obj-$(CONFIG_PCI) += slotid_cap.o
hw/pci/pci.c +1 -471
531 lines not on this page · raw message
hw/pci/pci_bus.c new file +491 -0
491 lines not on this page · raw message
hw/ppc/ppc4xx_pci.c +1 -0
@@ -23,6 +23,7 @@#include "hw/ppc/ppc.h" #include "hw/ppc/ppc4xx.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "exec/address-spaces.h"
hw/sh4/r2d.c +1 -0
@@ -30,6 +30,7 @@#include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "net/net.h" #include "sh7750_regs.h" #include "hw/ide.h"
hw/sh4/sh_pci.c +1 -0
@@ -24,6 +24,7 @@#include "hw/sysbus.h" #include "hw/sh4/sh.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "qemu/bswap.h" #include "exec/address-spaces.h"
include/hw/pci/pci.h +1 -2
@@ -337,8 +337,6 @@ typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);typedef int (*pci_map_irq_fn )(PCIDevice *pci_dev,int irq_num);typedef PCIINTxRoute (*pci_route_irq_fn )(void *opaque,int pin); -#define TYPE_PCI_BUS "PCI" -#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)#define TYPE_PCIE_BUS "PCIE"bool pci_bus_is_express (PCIBus *bus);
@@ -370,6 +368,7 @@ void pci_bus_fire_intx_routing_notifier(PCIBus *bus);void pci_device_set_intx_routing_notifier (PCIDevice *dev,PCIINTxRoutingNotifier notifier);void pci_device_reset (PCIDevice *dev); +void pci_do_device_reset (PCIDevice *dev); PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model,
include/hw/pci/pci_bus.h +8 -0
@@ -1,6 +1,8 @@#ifndef QEMU_PCI_BUS_H #define QEMU_PCI_BUS_H +#include "hw/pci/pci.h" +/* * PCI Bus and Bridge datastructures. *
@@ -8,6 +10,12 @@* use accessor functions in pci.h, pci_bridge.h */ +PCIBus *pci_find_bus_nr (PCIBus *bus,int bus_num); +PciDeviceInfoList *qmp_query_pci_devices (PCIBus *bus,int bus_num); + +#define TYPE_PCI_BUS "PCI" +#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +struct PCIBus {BusState qbus;PCIIOMMUFunc iommu_fn;
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
hw/pci/pci.c static const TypeInfo pci_device_type_info = { · line 1950
Quoted 8 lines · Marcel Apfelbaum
hw/pci/pci.c +0
-1@@ -2414,7 +1945,6 @@ static const TypeInfo pci_device_type_info = {static void pci_register_types (void ) { -type_register_static (&pci_bus_info);type_register_static (&pcie_bus_info);type_register_static (&pci_device_type_info); }
So pcie bus is not moved. This seems pretty inconsistent.
hw/pci/pci_bus.c line 4
Quoted 10 lines
hw/pci/pci_bus.c new file +4
-0@@ -0,0 +1,491 @@ +/* +* PCI Bus +* +* Copyright (C) 2014 Red Hat Inc
It's 2015 isn't it?
hw/pci/pci_bus.c line 7
Quoted 3 lines
hw/pci/pci_bus.c new file +3
-0+* +* Authors: +* Marcel Apfelbaum <[email protected]> (split out from pci.c)
You don't become the only Author just by moving code around. Better drop this line.
hw/pci/pci_bus.c line 10
Quoted 3 lines
hw/pci/pci_bus.c new file +3
-0+* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory.
The file you are moving this from is GPL only.
You will need to find who contributed this code you are moving and get ack from them ...
Quoted 531 lines
hw/pci/pci_bus.c new file +481
-0+*/ +#include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci_bridge.h" +#include "monitor/monitor.h" + +typedef struct { +uint16_t class; +const char *desc; +const char *fw_name; +uint16_t fw_ign_bits; +}pci_class_desc ; + +static const pci_class_desc pci_class_descriptions[] = { + {0x0001 ,"VGA controller" ,"display" }, + {0x0100 ,"SCSI controller" ,"scsi" }, + {0x0101 ,"IDE controller" ,"ide" }, + {0x0102 ,"Floppy controller" ,"fdc" }, + {0x0103 ,"IPI controller" ,"ipi" }, + {0x0104 ,"RAID controller" ,"raid" }, + {0x0106 ,"SATA controller" }, + {0x0107 ,"SAS controller" }, + {0x0180 ,"Storage controller" }, + {0x0200 ,"Ethernet controller" ,"ethernet" }, + {0x0201 ,"Token Ring controller" ,"token-ring" }, + {0x0202 ,"FDDI controller" ,"fddi" }, + {0x0203 ,"ATM controller" ,"atm" }, + {0x0280 ,"Network controller" }, + {0x0300 ,"VGA controller" ,"display" ,0x00ff }, + {0x0301 ,"XGA controller" }, + {0x0302 ,"3D controller" }, + {0x0380 ,"Display controller" }, + {0x0400 ,"Video controller" ,"video" }, + {0x0401 ,"Audio controller" ,"sound" }, + {0x0402 ,"Phone" }, + {0x0403 ,"Audio controller" ,"sound" }, + {0x0480 ,"Multimedia controller" }, + {0x0500 ,"RAM controller" ,"memory" }, + {0x0501 ,"Flash controller" ,"flash" }, + {0x0580 ,"Memory controller" }, + {0x0600 ,"Host bridge" ,"host" }, + {0x0601 ,"ISA bridge" ,"isa" }, + {0x0602 ,"EISA bridge" ,"eisa" }, + {0x0603 ,"MC bridge" ,"mca" }, + {0x0604 ,"PCI bridge" ,"pci-bridge" }, + {0x0605 ,"PCMCIA bridge" ,"pcmcia" }, + {0x0606 ,"NUBUS bridge" ,"nubus" }, + {0x0607 ,"CARDBUS bridge" ,"cardbus" }, + {0x0608 ,"RACEWAY bridge" }, + {0x0680 ,"Bridge" }, + {0x0700 ,"Serial port" ,"serial" }, + {0x0701 ,"Parallel port" ,"parallel" }, + {0x0800 ,"Interrupt controller" ,"interrupt-controller" }, + {0x0801 ,"DMA controller" ,"dma-controller" }, + {0x0802 ,"Timer" ,"timer" }, + {0x0803 ,"RTC" ,"rtc" }, + {0x0900 ,"Keyboard" ,"keyboard" }, + {0x0901 ,"Pen" ,"pen" }, + {0x0902 ,"Mouse" ,"mouse" }, + {0x0A00 ,"Dock station" ,"dock" ,0x00ff }, + {0x0B00 ,"i386 cpu" ,"cpu" ,0x00ff }, + {0x0c00 ,"Fireware contorller" ,"fireware" }, + {0x0c01 ,"Access bus controller" ,"access-bus" }, + {0x0c02 ,"SSA controller" ,"ssa" }, + {0x0c03 ,"USB controller" ,"usb" }, + {0x0c04 ,"Fibre channel controller" ,"fibre-channel" }, + {0x0c05 ,"SMBus" }, + {0 ,NULL } +}; + +/* Whether a given bus number is in range of the secondary +* bus of the given bridge device. */ +static bool pci_secondary_bus_in_range (PCIDevice *dev,int bus_num) +{ +return !(pci_get_word (dev->config +PCI_BRIDGE_CONTROL ) & +PCI_BRIDGE_CTL_BUS_RESET )/* Don't walk the bus if it's reset. */ && + dev->config[PCI_SECONDARY_BUS ] < bus_num && + bus_num <= dev->config[PCI_SUBORDINATE_BUS ]; +} + +PCIBus *pci_find_bus_nr (PCIBus *bus,int bus_num) +{ +PCIBus *sec; + +if (!bus) { +return NULL ; + } + +if (pci_bus_num (bus) == bus_num) { +return bus; + } + +/* Consider all bus numbers in range for the host pci bridge. */ +if (!pci_bus_is_root (bus) && + !pci_secondary_bus_in_range (bus->parent_dev, bus_num)) { +return NULL ; + } + +/* try child bus */ +for (; bus; bus = sec) { + QLIST_FOREACH(sec, &bus->child, sibling) { +assert (!pci_bus_is_root (sec)); +if (sec->parent_dev->config[PCI_SECONDARY_BUS ] == bus_num) { +return sec; + } +if (pci_secondary_bus_in_range (sec->parent_dev, bus_num)) { +break ; + } + } + } + +return NULL ; +} + +static const pci_class_desc *get_class_desc (int class) +{ +const pci_class_desc *desc; + + desc = pci_class_descriptions; +while (desc->desc && class != desc->class) { + desc++; + } + +return desc; +} + +static PciMemoryRegionList *qmp_query_pci_regions (const PCIDevice *dev) +{ +PciMemoryRegionList *head =NULL , *cur_item =NULL ; +int i; + +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { +const PCIIORegion *r = &dev->io_regions[i]; +PciMemoryRegionList *region; + +if (!r->size) { +continue ; + } + + region =g_malloc0 (sizeof (*region)); + region->value =g_malloc0 (sizeof (*region->value)); + +if (r->type &PCI_BASE_ADDRESS_SPACE_IO ) { + region->value->type =g_strdup ("io" ); + }else { + region->value->type =g_strdup ("memory" ); + region->value->has_prefetch = true; + region->value->prefetch = !!(r->type &PCI_BASE_ADDRESS_MEM_PREFETCH ); + region->value->has_mem_type_64 = true; + region->value->mem_type_64 = !!(r->type &PCI_BASE_ADDRESS_MEM_TYPE_64 ); + } + + region->value->bar = i; + region->value->address = r->addr; + region->value->size = r->size; + +/* XXX: waiting for the qapi to support GSList */ +if (!cur_item) { + head = cur_item = region; + }else { + cur_item->next = region; + cur_item = region; + } + } + +return head; +} + +static PciBridgeInfo *qmp_query_pci_bridge (PCIDevice *dev,PCIBus *bus, +int bus_num) +{ +PciBridgeInfo *info; + + info =g_malloc0 (sizeof (*info)); + + info->bus.number = dev->config[PCI_PRIMARY_BUS ]; + info->bus.secondary = dev->config[PCI_SECONDARY_BUS ]; + info->bus.subordinate = dev->config[PCI_SUBORDINATE_BUS ]; + + info->bus.io_range =g_malloc0 (sizeof (*info->bus.io_range)); + info->bus.io_range->base =pci_bridge_get_base (dev, +PCI_BASE_ADDRESS_SPACE_IO ); + info->bus.io_range->limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_IO ); + + info->bus.memory_range =g_malloc0 (sizeof (*info->bus.memory_range)); + info->bus.memory_range->base = +pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); + info->bus.memory_range->limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); + + info->bus.prefetchable_range = +g_malloc0 (sizeof (*info->bus.prefetchable_range)); + info->bus.prefetchable_range->base = +pci_bridge_get_base (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); + info->bus.prefetchable_range->limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); + +if (dev->config[PCI_SECONDARY_BUS ] !=0 ) { +PCIBus *child_bus =pci_find_bus_nr (bus, dev->config[PCI_SECONDARY_BUS ]); +if (child_bus) { + info->has_devices = true; + info->devices =qmp_query_pci_devices (child_bus, + dev->config[PCI_SECONDARY_BUS ]); + } + } + +return info; +} + +static PciDeviceInfo *qmp_query_pci_device (PCIDevice *dev,PCIBus *bus, +int bus_num) +{ +const pci_class_desc *desc; +PciDeviceInfo *info; +uint8_t type; +int class; + + info =g_malloc0 (sizeof (*info)); + info->bus = bus_num; + info->slot =PCI_SLOT (dev->devfn); + info->function =PCI_FUNC (dev->devfn); + + class =pci_get_word (dev->config +PCI_CLASS_DEVICE ); + info->class_info.q_class = class; + desc =get_class_desc (class); +if (desc->desc) { + info->class_info.has_desc = true; + info->class_info.desc =g_strdup (desc->desc); + } + + info->id.vendor =pci_get_word (dev->config +PCI_VENDOR_ID ); + info->id.device =pci_get_word (dev->config +PCI_DEVICE_ID ); + info->regions =qmp_query_pci_regions (dev); + info->qdev_id =g_strdup (dev->qdev.id ? dev->qdev.id :"" ); + +if (dev->config[PCI_INTERRUPT_PIN ] !=0 ) { + info->has_irq = true; + info->irq = dev->config[PCI_INTERRUPT_LINE ]; + } + + type = dev->config[PCI_HEADER_TYPE ] & ~PCI_HEADER_TYPE_MULTI_FUNCTION ; +if (type ==PCI_HEADER_TYPE_BRIDGE ) { + info->has_pci_bridge = true; + info->pci_bridge =qmp_query_pci_bridge (dev, bus, bus_num); + } + +return info; +} + +PciDeviceInfoList *qmp_query_pci_devices (PCIBus *bus,int bus_num) +{ +PciDeviceInfoList *info, *head =NULL , *cur_item =NULL ; +PCIDevice *dev; +int devfn; + +for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { + dev = bus->devices[devfn]; +if (dev) { + info =g_malloc0 (sizeof (*info)); + info->value =qmp_query_pci_device (dev, bus, bus_num); + +/* XXX: waiting for the qapi to support GSList */ +if (!cur_item) { + head = cur_item = info; + }else { + cur_item->next = info; + cur_item = info; + } + } + } + +return head; +} + + +static void pcibus_dev_print (Monitor *mon,DeviceState *dev,int indent) +{ +PCIDevice *d = (PCIDevice *)dev; +const pci_class_desc *desc; +char ctxt[64 ]; +PCIIORegion *r; +int i, class; + + class =pci_get_word (d->config +PCI_CLASS_DEVICE ); + desc = pci_class_descriptions; +while (desc->desc && class != desc->class) { + desc++; + } +if (desc->desc) { +snprintf (ctxt,sizeof (ctxt),"%s" , desc->desc); + }else { +snprintf (ctxt,sizeof (ctxt),"Class %04x" , class); + } + +monitor_printf (mon,"%*sclass %s, addr %02x:%02x.%x, " +"pci id %04x:%04x (sub %04x:%04x)\n" , + indent,"" , ctxt,pci_bus_num (d->bus), +PCI_SLOT (d->devfn),PCI_FUNC (d->devfn), +pci_get_word (d->config +PCI_VENDOR_ID ), +pci_get_word (d->config +PCI_DEVICE_ID ), +pci_get_word (d->config +PCI_SUBSYSTEM_VENDOR_ID ), +pci_get_word (d->config +PCI_SUBSYSTEM_ID )); +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { + r = &d->io_regions[i]; +if (!r->size) { +continue ; + } +monitor_printf (mon,"%*sbar %d: %s at 0x%" FMT_PCIBUS +" [0x%" FMT_PCIBUS "]\n" , + indent,"" , + i, r->type &PCI_BASE_ADDRESS_SPACE_IO ?"i/o" :"mem" , + r->addr, r->addr + r->size -1 ); + } +} + +static char *pcibus_get_dev_path (DeviceState *dev) +{ +PCIDevice *d =container_of (dev, PCIDevice, qdev); +PCIDevice *t; +int slot_depth; +/* Path format: Domain:00:Slot.Function:Slot.Function....:Slot.Function. +* 00 is added here to make this format compatible with +* domain:Bus:Slot.Func for systems without nested PCI bridges. +* Slot.Function list specifies the slot and function numbers for all +* devices on the path from root to the specific device. */ +const char *root_bus_path; +int root_bus_len; +char slot[] =":SS.F" ; +int slot_len =sizeof slot -1 /* For '\0' */ ; +int path_len; +char *path, *p; +int s; + + root_bus_path =pci_root_bus_path (d); + root_bus_len =strlen (root_bus_path); + +/* Calculate # of slots on path between device and root. */ ; + slot_depth =0 ; +for (t = d; t; t = t->bus->parent_dev) { + ++slot_depth; + } + + path_len = root_bus_len + slot_len * slot_depth; + +/* Allocate memory, fill in the terminating null byte. */ + path =g_malloc (path_len +1 /* For '\0' */ ); + path[path_len] ='\0' ; + +memcpy (path, root_bus_path, root_bus_len); + +/* Fill in slot numbers. We walk up from device to root, so need to print +* them in the reverse order, last to first. */ + p = path + path_len; +for (t = d; t; t = t->bus->parent_dev) { + p -= slot_len; + s =snprintf (slot,sizeof slot,":%02x.%x" , +PCI_SLOT (t->devfn),PCI_FUNC (t->devfn)); +assert (s == slot_len); +memcpy (p, slot, slot_len); + } + +return path; +} + +static char *pci_dev_fw_name (DeviceState *dev,char *buf,int len) +{ +PCIDevice *d = (PCIDevice *)dev; +const char *name =NULL ; +const pci_class_desc *desc = pci_class_descriptions; +int class =pci_get_word (d->config +PCI_CLASS_DEVICE ); + +while (desc->desc && + (class & ~desc->fw_ign_bits) != + (desc->class & ~desc->fw_ign_bits)) { + desc++; + } + +if (desc->desc) { + name = desc->fw_name; + } + +if (name) { +pstrcpy (buf, len, name); + }else { +snprintf (buf, len,"pci%04x,%04x" , +pci_get_word (d->config +PCI_VENDOR_ID ), +pci_get_word (d->config +PCI_DEVICE_ID )); + } + +return buf; +} + +static char *pcibus_get_fw_dev_path (DeviceState *dev) +{ +PCIDevice *d = (PCIDevice *)dev; +char path[50 ], name[33 ]; +int off; + + off =snprintf (path,sizeof (path),"%s@%x" , +pci_dev_fw_name (dev, name,sizeof name), +PCI_SLOT (d->devfn)); +if (PCI_FUNC (d->devfn)) { +snprintf (path + off,sizeof (path) + off,",%x" ,PCI_FUNC (d->devfn)); + } +return g_strdup (path); +} + +static const VMStateDescription vmstate_pcibus = { + .name ="PCIBUS" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_INT32_EQUAL (nirq, PCIBus), +VMSTATE_VARRAY_INT32 (irq_count, PCIBus, + nirq,0 , vmstate_info_int32, + int32_t), +VMSTATE_END_OF_LIST () + } +}; + +static void pci_bus_realize (BusState *qbus,Error **errp) +{ +PCIBus *bus =PCI_BUS (qbus); + +vmstate_register (NULL ,-1 , &vmstate_pcibus, bus); +} + +static void pci_bus_unrealize (BusState *qbus,Error **errp) +{ +PCIBus *bus =PCI_BUS (qbus); + +vmstate_unregister (NULL , &vmstate_pcibus, bus); +} + +/* +* Trigger pci bus reset under a given bus. +* Called via qbus_reset_all on RST# assert, after the devices +* have been reset qdev_reset_all-ed already. +*/ +static void pcibus_reset (BusState *qbus) +{ +PCIBus *bus =DO_UPCAST (PCIBus, qbus, qbus); +int i; + +for (i =0 ; i <ARRAY_SIZE (bus->devices); ++i) { +if (bus->devices[i]) { +pci_do_device_reset (bus->devices[i]); + } + } + +for (i =0 ; i < bus->nirq; i++) { +assert (bus->irq_count[i] ==0 ); + } +} + +static void pci_bus_class_init (ObjectClass *klass,void *data) +{ +BusClass *k =BUS_CLASS (klass); + + k->print_dev = pcibus_dev_print; + k->get_dev_path = pcibus_get_dev_path; + k->get_fw_dev_path = pcibus_get_fw_dev_path; + k->realize = pci_bus_realize; + k->unrealize = pci_bus_unrealize; + k->reset = pcibus_reset; +} + +static const TypeInfo pci_bus_info = { + .name =TYPE_PCI_BUS , + .parent =TYPE_BUS , + .instance_size =sizeof (PCIBus), + .class_init = pci_bus_class_init, +}; + +static void pci_bus_register_types (void ) +{ +type_register_static (&pci_bus_info); +} + +type_init (pci_bus_register_types)hw/ppc/ppc4xx_pci.c +1
-0@@ -23,6 +23,7 @@#include "hw/ppc/ppc.h" #include "hw/ppc/ppc4xx.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "exec/address-spaces.h" hw/sh4/r2d.c +1
-0@@ -30,6 +30,7 @@#include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "net/net.h" #include "sh7750_regs.h" #include "hw/ide.h" hw/sh4/sh_pci.c +1
-0@@ -24,6 +24,7 @@#include "hw/sysbus.h" #include "hw/sh4/sh.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "qemu/bswap.h" #include "exec/address-spaces.h" include/hw/pci/pci.h +0
-2@@ -337,8 +337,6 @@ typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);typedef int (*pci_map_irq_fn )(PCIDevice *pci_dev,int irq_num);typedef PCIINTxRoute (*pci_route_irq_fn )(void *opaque,int pin); -#define TYPE_PCI_BUS "PCI" -#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)#define TYPE_PCIE_BUS "PCIE"bool pci_bus_is_express (PCIBus *bus);
include/hw/pci/pci.h void pci_bus_fire_intx_routing_notifier(PCIBus *bus); · line 371
Quoted 4 lines
include/hw/pci/pci.h +1
-0@@ -370,6 +368,7 @@ void pci_bus_fire_intx_routing_notifier(PCIBus *bus);void pci_device_set_intx_routing_notifier (PCIDevice *dev,PCIINTxRoutingNotifier notifier);void pci_device_reset (PCIDevice *dev); +void pci_do_device_reset (PCIDevice *dev);
I don't like it that there are two reset functions now.
Quoted 19 lines
include/hw/pci/pci.h +0
-0PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model,include/hw/pci/pci_bus.h +2
-0@@ -1,6 +1,8 @@#ifndef QEMU_PCI_BUS_H #define QEMU_PCI_BUS_H +#include "hw/pci/pci.h" +/* * PCI Bus and Bridge datastructures. * @@ -8,6 +10,12 @@* use accessor functions in pci.h, pci_bridge.h */
include/hw/pci/pci_bus.h line 21
Quoted 10 lines
include/hw/pci/pci_bus.h +6
-0+PCIBus *pci_find_bus_nr (PCIBus *bus,int bus_num); +PciDeviceInfoList *qmp_query_pci_devices (PCIBus *bus,int bus_num); + +#define TYPE_PCI_BUS "PCI" +#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +struct PCIBus {BusState qbus;PCIIOMMUFunc iommu_fn;
Can we drop this patch, do refactoring on top later?
Quoted 2 lines
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines
+ *
Quoted 2 lines
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.The file you are moving this from is GPL only.
It's BSD.
Quoted 2 lines
You will need to find who contributed this code you are moving and get ack from them ...
Simpler to keep BSD.
Paolo
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
Quoted 5 lines · Paolo Bonzini
Quoted 3 lines · Michael S. Tsirkin
Quoted 3 lines
+ *
Quoted 2 lines
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
Quoted 8 lines
Quoted 1 line
The file you are moving this from is GPL only.
It's BSD.
Quoted 2 lines
You will need to find who contributed this code you are moving and get ack from them ...
Simpler to keep BSD.
Sure, will do.
Thanks,
Marcel
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
Quoted 10 lines · Marcel Apfelbaum
Quoted 9 lines · Paolo Bonzini
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines
+ *
Quoted 2 lines
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.The file you are moving this from is GPL only.
It's BSD.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
You will need to find who contributed this code you are moving and get ack from them ...
Simpler to keep BSD.
Sure, will do.
Thanks,
Marcel
I'd say just keep it within pci.c for now, the smaller the patchset the better. Refactor later.
Quoted 3 lines
Quoted 3 lines
Paolo
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
In reply to Paolo BonziniQuoted 5 lines · Paolo Bonzini
Quoted 4 lines · Michael S. Tsirkin
Quoted 4 lines
+ *
Quoted 3 lines
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
Quoted 8 lines
Quoted 1 line
The file you are moving this from is GPL only.
It's BSD.
Quoted 2 lines
You will need to find who contributed this code you are moving and get ack from them ...
Simpler to keep BSD.
Just for completeness: you're free to GPL a derived work. The folks who BSD-licensed it to you may consider that offensive, but the law doesn't consider it wrong.
You may care a whole lot more for how these folks feel about you than what the law permits you to do.
I'd consider switching to GPL only if I made substantial changes.
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
Quoted 16 lines · Markus Armbruster
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Michael S. Tsirkin
Quoted 4 lines
+ *
Quoted 3 lines
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.Quoted 8 lines
Quoted 1 line
The file you are moving this from is GPL only.
It's BSD.
Quoted 2 lines
You will need to find who contributed this code you are moving and get ack from them ...
Simpler to keep BSD.
Quoted 9 lines
Just for completeness: you're free to GPL a derived work. The folks who BSD-licensed it to you may consider that offensive, but the law doesn't consider it wrong.
You may care a whole lot more for how these folks feel about you than what the law permits you to do.
I'd consider switching to GPL only if I made substantial changes.
Thanks Markus,
Since I only moved some code around, I'll keep it BSD.
Marcel
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
In reply to Michael S. TsirkinQuoted 11 lines · Michael S. Tsirkin
hw/pci/pci.c static const TypeInfo pci_device_type_info = { · line 1950
Quoted 8 lines · Marcel Apfelbaum
hw/pci/pci.c +0
-1@@ -2414,7 +1945,6 @@ static const TypeInfo pci_device_type_info = {static void pci_register_types (void ) { -type_register_static (&pci_bus_info);type_register_static (&pcie_bus_info);type_register_static (&pci_device_type_info); }So pcie bus is not moved. This seems pretty inconsistent.
There were a lot of code dependencies. I moved the minimum code in order to be able to add code specific to PCIBus.
Quoted 14 lines
hw/pci/pci_bus.c line 4
Quoted 12 lines
hw/pci/pci_bus.c new file +4
-0@@ -0,0 +1,491 @@ +/* +* PCI Bus +* +* Copyright (C) 2014 Red Hat Inc It's 2015 isn't it?
Well, now yes :)
Quoted 7 lines
hw/pci/pci_bus.c line 7
Quoted 4 lines
hw/pci/pci_bus.c new file +3
-0+* +* Authors: +* Marcel Apfelbaum <[email protected]> (split out from pci.c) You don't become the only Author just by moving code around. Better drop this line.
I was following an example of the latest code movement at that time in QEMU. Anyway, I will remove that line.
Quoted 10 lines
hw/pci/pci_bus.c line 10
Quoted 6 lines
hw/pci/pci_bus.c new file +3
-0+* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. The file you are moving this from is GPL only.
You will need to find who contributed this code you are moving and get ack from them ...
I'll keep it as BSD as Paolo suggested.
Quoted 530 lines
Quoted 530 lines
hw/pci/pci_bus.c new file +481
-0+*/ +#include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci_bridge.h" +#include "monitor/monitor.h" + +typedef struct { +uint16_t class; +const char *desc; +const char *fw_name; +uint16_t fw_ign_bits; +}pci_class_desc ; + +static const pci_class_desc pci_class_descriptions[] = { + {0x0001 ,"VGA controller" ,"display" }, + {0x0100 ,"SCSI controller" ,"scsi" }, + {0x0101 ,"IDE controller" ,"ide" }, + {0x0102 ,"Floppy controller" ,"fdc" }, + {0x0103 ,"IPI controller" ,"ipi" }, + {0x0104 ,"RAID controller" ,"raid" }, + {0x0106 ,"SATA controller" }, + {0x0107 ,"SAS controller" }, + {0x0180 ,"Storage controller" }, + {0x0200 ,"Ethernet controller" ,"ethernet" }, + {0x0201 ,"Token Ring controller" ,"token-ring" }, + {0x0202 ,"FDDI controller" ,"fddi" }, + {0x0203 ,"ATM controller" ,"atm" }, + {0x0280 ,"Network controller" }, + {0x0300 ,"VGA controller" ,"display" ,0x00ff }, + {0x0301 ,"XGA controller" }, + {0x0302 ,"3D controller" }, + {0x0380 ,"Display controller" }, + {0x0400 ,"Video controller" ,"video" }, + {0x0401 ,"Audio controller" ,"sound" }, + {0x0402 ,"Phone" }, + {0x0403 ,"Audio controller" ,"sound" }, + {0x0480 ,"Multimedia controller" }, + {0x0500 ,"RAM controller" ,"memory" }, + {0x0501 ,"Flash controller" ,"flash" }, + {0x0580 ,"Memory controller" }, + {0x0600 ,"Host bridge" ,"host" }, + {0x0601 ,"ISA bridge" ,"isa" }, + {0x0602 ,"EISA bridge" ,"eisa" }, + {0x0603 ,"MC bridge" ,"mca" }, + {0x0604 ,"PCI bridge" ,"pci-bridge" }, + {0x0605 ,"PCMCIA bridge" ,"pcmcia" }, + {0x0606 ,"NUBUS bridge" ,"nubus" }, + {0x0607 ,"CARDBUS bridge" ,"cardbus" }, + {0x0608 ,"RACEWAY bridge" }, + {0x0680 ,"Bridge" }, + {0x0700 ,"Serial port" ,"serial" }, + {0x0701 ,"Parallel port" ,"parallel" }, + {0x0800 ,"Interrupt controller" ,"interrupt-controller" }, + {0x0801 ,"DMA controller" ,"dma-controller" }, + {0x0802 ,"Timer" ,"timer" }, + {0x0803 ,"RTC" ,"rtc" }, + {0x0900 ,"Keyboard" ,"keyboard" }, + {0x0901 ,"Pen" ,"pen" }, + {0x0902 ,"Mouse" ,"mouse" }, + {0x0A00 ,"Dock station" ,"dock" ,0x00ff }, + {0x0B00 ,"i386 cpu" ,"cpu" ,0x00ff }, + {0x0c00 ,"Fireware contorller" ,"fireware" }, + {0x0c01 ,"Access bus controller" ,"access-bus" }, + {0x0c02 ,"SSA controller" ,"ssa" }, + {0x0c03 ,"USB controller" ,"usb" }, + {0x0c04 ,"Fibre channel controller" ,"fibre-channel" }, + {0x0c05 ,"SMBus" }, + {0 ,NULL } +}; + +/* Whether a given bus number is in range of the secondary +* bus of the given bridge device. */ +static bool pci_secondary_bus_in_range (PCIDevice *dev,int bus_num) +{ +return !(pci_get_word (dev->config +PCI_BRIDGE_CONTROL ) & +PCI_BRIDGE_CTL_BUS_RESET )/* Don't walk the bus if it's reset. */ && + dev->config[PCI_SECONDARY_BUS ] < bus_num && + bus_num <= dev->config[PCI_SUBORDINATE_BUS ]; +} + +PCIBus *pci_find_bus_nr (PCIBus *bus,int bus_num) +{ +PCIBus *sec; + +if (!bus) { +return NULL ; + } + +if (pci_bus_num (bus) == bus_num) { +return bus; + } + +/* Consider all bus numbers in range for the host pci bridge. */ +if (!pci_bus_is_root (bus) && + !pci_secondary_bus_in_range (bus->parent_dev, bus_num)) { +return NULL ; + } + +/* try child bus */ +for (; bus; bus = sec) { + QLIST_FOREACH(sec, &bus->child, sibling) { +assert (!pci_bus_is_root (sec)); +if (sec->parent_dev->config[PCI_SECONDARY_BUS ] == bus_num) { +return sec; + } +if (pci_secondary_bus_in_range (sec->parent_dev, bus_num)) { +break ; + } + } + } + +return NULL ; +} + +static const pci_class_desc *get_class_desc (int class) +{ +const pci_class_desc *desc; + + desc = pci_class_descriptions; +while (desc->desc && class != desc->class) { + desc++; + } + +return desc; +} + +static PciMemoryRegionList *qmp_query_pci_regions (const PCIDevice *dev) +{ +PciMemoryRegionList *head =NULL , *cur_item =NULL ; +int i; + +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { +const PCIIORegion *r = &dev->io_regions[i]; +PciMemoryRegionList *region; + +if (!r->size) { +continue ; + } + + region =g_malloc0 (sizeof (*region)); + region->value =g_malloc0 (sizeof (*region->value)); + +if (r->type &PCI_BASE_ADDRESS_SPACE_IO ) { + region->value->type =g_strdup ("io" ); + }else { + region->value->type =g_strdup ("memory" ); + region->value->has_prefetch = true; + region->value->prefetch = !!(r->type &PCI_BASE_ADDRESS_MEM_PREFETCH ); + region->value->has_mem_type_64 = true; + region->value->mem_type_64 = !!(r->type &PCI_BASE_ADDRESS_MEM_TYPE_64 ); + } + + region->value->bar = i; + region->value->address = r->addr; + region->value->size = r->size; + +/* XXX: waiting for the qapi to support GSList */ +if (!cur_item) { + head = cur_item = region; + }else { + cur_item->next = region; + cur_item = region; + } + } + +return head; +} + +static PciBridgeInfo *qmp_query_pci_bridge (PCIDevice *dev,PCIBus *bus, +int bus_num) +{ +PciBridgeInfo *info; + + info =g_malloc0 (sizeof (*info)); + + info->bus.number = dev->config[PCI_PRIMARY_BUS ]; + info->bus.secondary = dev->config[PCI_SECONDARY_BUS ]; + info->bus.subordinate = dev->config[PCI_SUBORDINATE_BUS ]; + + info->bus.io_range =g_malloc0 (sizeof (*info->bus.io_range)); + info->bus.io_range->base =pci_bridge_get_base (dev, +PCI_BASE_ADDRESS_SPACE_IO ); + info->bus.io_range->limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_IO ); + + info->bus.memory_range =g_malloc0 (sizeof (*info->bus.memory_range)); + info->bus.memory_range->base = +pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); + info->bus.memory_range->limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); + + info->bus.prefetchable_range = +g_malloc0 (sizeof (*info->bus.prefetchable_range)); + info->bus.prefetchable_range->base = +pci_bridge_get_base (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); + info->bus.prefetchable_range->limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); + +if (dev->config[PCI_SECONDARY_BUS ] !=0 ) { +PCIBus *child_bus =pci_find_bus_nr (bus, dev->config[PCI_SECONDARY_BUS ]); +if (child_bus) { + info->has_devices = true; + info->devices =qmp_query_pci_devices (child_bus, + dev->config[PCI_SECONDARY_BUS ]); + } + } + +return info; +} + +static PciDeviceInfo *qmp_query_pci_device (PCIDevice *dev,PCIBus *bus, +int bus_num) +{ +const pci_class_desc *desc; +PciDeviceInfo *info; +uint8_t type; +int class; + + info =g_malloc0 (sizeof (*info)); + info->bus = bus_num; + info->slot =PCI_SLOT (dev->devfn); + info->function =PCI_FUNC (dev->devfn); + + class =pci_get_word (dev->config +PCI_CLASS_DEVICE ); + info->class_info.q_class = class; + desc =get_class_desc (class); +if (desc->desc) { + info->class_info.has_desc = true; + info->class_info.desc =g_strdup (desc->desc); + } + + info->id.vendor =pci_get_word (dev->config +PCI_VENDOR_ID ); + info->id.device =pci_get_word (dev->config +PCI_DEVICE_ID ); + info->regions =qmp_query_pci_regions (dev); + info->qdev_id =g_strdup (dev->qdev.id ? dev->qdev.id :"" ); + +if (dev->config[PCI_INTERRUPT_PIN ] !=0 ) { + info->has_irq = true; + info->irq = dev->config[PCI_INTERRUPT_LINE ]; + } + + type = dev->config[PCI_HEADER_TYPE ] & ~PCI_HEADER_TYPE_MULTI_FUNCTION ; +if (type ==PCI_HEADER_TYPE_BRIDGE ) { + info->has_pci_bridge = true; + info->pci_bridge =qmp_query_pci_bridge (dev, bus, bus_num); + } + +return info; +} + +PciDeviceInfoList *qmp_query_pci_devices (PCIBus *bus,int bus_num) +{ +PciDeviceInfoList *info, *head =NULL , *cur_item =NULL ; +PCIDevice *dev; +int devfn; + +for (devfn =0 ; devfn <ARRAY_SIZE (bus->devices); devfn++) { + dev = bus->devices[devfn]; +if (dev) { + info =g_malloc0 (sizeof (*info)); + info->value =qmp_query_pci_device (dev, bus, bus_num); + +/* XXX: waiting for the qapi to support GSList */ +if (!cur_item) { + head = cur_item = info; + }else { + cur_item->next = info; + cur_item = info; + } + } + } + +return head; +} + + +static void pcibus_dev_print (Monitor *mon,DeviceState *dev,int indent) +{ +PCIDevice *d = (PCIDevice *)dev; +const pci_class_desc *desc; +char ctxt[64 ]; +PCIIORegion *r; +int i, class; + + class =pci_get_word (d->config +PCI_CLASS_DEVICE ); + desc = pci_class_descriptions; +while (desc->desc && class != desc->class) { + desc++; + } +if (desc->desc) { +snprintf (ctxt,sizeof (ctxt),"%s" , desc->desc); + }else { +snprintf (ctxt,sizeof (ctxt),"Class %04x" , class); + } + +monitor_printf (mon,"%*sclass %s, addr %02x:%02x.%x, " +"pci id %04x:%04x (sub %04x:%04x)\n" , + indent,"" , ctxt,pci_bus_num (d->bus), +PCI_SLOT (d->devfn),PCI_FUNC (d->devfn), +pci_get_word (d->config +PCI_VENDOR_ID ), +pci_get_word (d->config +PCI_DEVICE_ID ), +pci_get_word (d->config +PCI_SUBSYSTEM_VENDOR_ID ), +pci_get_word (d->config +PCI_SUBSYSTEM_ID )); +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { + r = &d->io_regions[i]; +if (!r->size) { +continue ; + } +monitor_printf (mon,"%*sbar %d: %s at 0x%" FMT_PCIBUS +" [0x%" FMT_PCIBUS "]\n" , + indent,"" , + i, r->type &PCI_BASE_ADDRESS_SPACE_IO ?"i/o" :"mem" , + r->addr, r->addr + r->size -1 ); + } +} + +static char *pcibus_get_dev_path (DeviceState *dev) +{ +PCIDevice *d =container_of (dev, PCIDevice, qdev); +PCIDevice *t; +int slot_depth; +/* Path format: Domain:00:Slot.Function:Slot.Function....:Slot.Function. +* 00 is added here to make this format compatible with +* domain:Bus:Slot.Func for systems without nested PCI bridges. +* Slot.Function list specifies the slot and function numbers for all +* devices on the path from root to the specific device. */ +const char *root_bus_path; +int root_bus_len; +char slot[] =":SS.F" ; +int slot_len =sizeof slot -1 /* For '\0' */ ; +int path_len; +char *path, *p; +int s; + + root_bus_path =pci_root_bus_path (d); + root_bus_len =strlen (root_bus_path); + +/* Calculate # of slots on path between device and root. */ ; + slot_depth =0 ; +for (t = d; t; t = t->bus->parent_dev) { + ++slot_depth; + } + + path_len = root_bus_len + slot_len * slot_depth; + +/* Allocate memory, fill in the terminating null byte. */ + path =g_malloc (path_len +1 /* For '\0' */ ); + path[path_len] ='\0' ; + +memcpy (path, root_bus_path, root_bus_len); + +/* Fill in slot numbers. We walk up from device to root, so need to print +* them in the reverse order, last to first. */ + p = path + path_len; +for (t = d; t; t = t->bus->parent_dev) { + p -= slot_len; + s =snprintf (slot,sizeof slot,":%02x.%x" , +PCI_SLOT (t->devfn),PCI_FUNC (t->devfn)); +assert (s == slot_len); +memcpy (p, slot, slot_len); + } + +return path; +} + +static char *pci_dev_fw_name (DeviceState *dev,char *buf,int len) +{ +PCIDevice *d = (PCIDevice *)dev; +const char *name =NULL ; +const pci_class_desc *desc = pci_class_descriptions; +int class =pci_get_word (d->config +PCI_CLASS_DEVICE ); + +while (desc->desc && + (class & ~desc->fw_ign_bits) != + (desc->class & ~desc->fw_ign_bits)) { + desc++; + } + +if (desc->desc) { + name = desc->fw_name; + } + +if (name) { +pstrcpy (buf, len, name); + }else { +snprintf (buf, len,"pci%04x,%04x" , +pci_get_word (d->config +PCI_VENDOR_ID ), +pci_get_word (d->config +PCI_DEVICE_ID )); + } + +return buf; +} + +static char *pcibus_get_fw_dev_path (DeviceState *dev) +{ +PCIDevice *d = (PCIDevice *)dev; +char path[50 ], name[33 ]; +int off; + + off =snprintf (path,sizeof (path),"%s@%x" , +pci_dev_fw_name (dev, name,sizeof name), +PCI_SLOT (d->devfn)); +if (PCI_FUNC (d->devfn)) { +snprintf (path + off,sizeof (path) + off,",%x" ,PCI_FUNC (d->devfn)); + } +return g_strdup (path); +} + +static const VMStateDescription vmstate_pcibus = { + .name ="PCIBUS" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_INT32_EQUAL (nirq, PCIBus), +VMSTATE_VARRAY_INT32 (irq_count, PCIBus, + nirq,0 , vmstate_info_int32, + int32_t), +VMSTATE_END_OF_LIST () + } +}; + +static void pci_bus_realize (BusState *qbus,Error **errp) +{ +PCIBus *bus =PCI_BUS (qbus); + +vmstate_register (NULL ,-1 , &vmstate_pcibus, bus); +} + +static void pci_bus_unrealize (BusState *qbus,Error **errp) +{ +PCIBus *bus =PCI_BUS (qbus); + +vmstate_unregister (NULL , &vmstate_pcibus, bus); +} + +/* +* Trigger pci bus reset under a given bus. +* Called via qbus_reset_all on RST# assert, after the devices +* have been reset qdev_reset_all-ed already. +*/ +static void pcibus_reset (BusState *qbus) +{ +PCIBus *bus =DO_UPCAST (PCIBus, qbus, qbus); +int i; + +for (i =0 ; i <ARRAY_SIZE (bus->devices); ++i) { +if (bus->devices[i]) { +pci_do_device_reset (bus->devices[i]); + } + } + +for (i =0 ; i < bus->nirq; i++) { +assert (bus->irq_count[i] ==0 ); + } +} + +static void pci_bus_class_init (ObjectClass *klass,void *data) +{ +BusClass *k =BUS_CLASS (klass); + + k->print_dev = pcibus_dev_print; + k->get_dev_path = pcibus_get_dev_path; + k->get_fw_dev_path = pcibus_get_fw_dev_path; + k->realize = pci_bus_realize; + k->unrealize = pci_bus_unrealize; + k->reset = pcibus_reset; +} + +static const TypeInfo pci_bus_info = { + .name =TYPE_PCI_BUS , + .parent =TYPE_BUS , + .instance_size =sizeof (PCIBus), + .class_init = pci_bus_class_init, +}; + +static void pci_bus_register_types (void ) +{ +type_register_static (&pci_bus_info); +} + +type_init (pci_bus_register_types)hw/ppc/ppc4xx_pci.c +1
-0@@ -23,6 +23,7 @@#include "hw/ppc/ppc.h" #include "hw/ppc/ppc4xx.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "exec/address-spaces.h" hw/sh4/r2d.c +1
-0@@ -30,6 +30,7 @@#include "sysemu/sysemu.h" #include "hw/boards.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "net/net.h" #include "sh7750_regs.h" #include "hw/ide.h" hw/sh4/sh_pci.c +1
-0@@ -24,6 +24,7 @@#include "hw/sysbus.h" #include "hw/sh4/sh.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "qemu/bswap.h" #include "exec/address-spaces.h" include/hw/pci/pci.h +0
-2@@ -337,8 +337,6 @@ typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);typedef int (*pci_map_irq_fn )(PCIDevice *pci_dev,int irq_num);typedef PCIINTxRoute (*pci_route_irq_fn )(void *opaque,int pin); -#define TYPE_PCI_BUS "PCI" -#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)#define TYPE_PCIE_BUS "PCIE"
Quoted 8 lines
include/hw/pci/pci.h void pci_bus_fire_intx_routing_notifier(PCIBus *bus); · line 371
Quoted 6 lines
include/hw/pci/pci.h +1
-0bool pci_bus_is_express (PCIBus *bus);@@ -370,6 +368,7 @@ void pci_bus_fire_intx_routing_notifier(PCIBus *bus);void pci_device_set_intx_routing_notifier (PCIDevice *dev,PCIINTxRoutingNotifier notifier);void pci_device_reset (PCIDevice *dev); +void pci_do_device_reset (PCIDevice *dev);I don't like it that there are two reset functions now.
It always was like that. We need this because of the code movement.
Quoted 21 lines
Quoted 21 lines
include/hw/pci/pci.h +0
-0PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model,include/hw/pci/pci_bus.h +2
-0@@ -1,6 +1,8 @@#ifndef QEMU_PCI_BUS_H #define QEMU_PCI_BUS_H +#include "hw/pci/pci.h" +/* * PCI Bus and Bridge datastructures. * @@ -8,6 +10,12 @@* use accessor functions in pci.h, pci_bridge.h */
Quoted 12 lines
include/hw/pci/pci_bus.h line 21
Quoted 9 lines
include/hw/pci/pci_bus.h +6
-0+PCIBus *pci_find_bus_nr (PCIBus *bus,int bus_num); +PciDeviceInfoList *qmp_query_pci_devices (PCIBus *bus,int bus_num); + +#define TYPE_PCI_BUS "PCI" +#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +struct PCIBus {BusState qbus;PCIIOMMUFunc iommu_fn;Can we drop this patch, do refactoring on top later?
There are several patches on this series depending on this. Of course I can manually apply them, does it worth it?
Thanks,
Marcel
Quoted 3 lines
Quoted 3 lines
--
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
Quoted 12 lines · Marcel Apfelbaum
Quoted 11 lines · Michael S. Tsirkin
hw/pci/pci.c static const TypeInfo pci_device_type_info = { · line 1950
Quoted 8 lines · Marcel Apfelbaum
hw/pci/pci.c +0
-1@@ -2414,7 +1945,6 @@ static const TypeInfo pci_device_type_info = {static void pci_register_types (void ) { -type_register_static (&pci_bus_info);type_register_static (&pcie_bus_info);type_register_static (&pci_device_type_info); }So pcie bus is not moved. This seems pretty inconsistent.
Quoted 2 lines
There were a lot of code dependencies. I moved the minimum code in order to be able to add code specific to PCIBus.
Interfaces need to make sense, this one feels like you randomly moved out parts that your patch happens to need.
Just keep it all in pci.c for now.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH V6 for-2.3 09/26] hw/pci: move pci bus related code to separate files
Quoted 13 lines · Michael S. Tsirkin
Quoted 12 lines · Marcel Apfelbaum
Quoted 11 lines · Michael S. Tsirkin
hw/pci/pci.c static const TypeInfo pci_device_type_info = { · line 1950
Quoted 8 lines · Marcel Apfelbaum
hw/pci/pci.c +0
-1@@ -2414,7 +1945,6 @@ static const TypeInfo pci_device_type_info = {static void pci_register_types (void ) { -type_register_static (&pci_bus_info);type_register_static (&pcie_bus_info);type_register_static (&pci_device_type_info); }So pcie bus is not moved. This seems pretty inconsistent.
Quoted 7 lines
Quoted 2 lines
There were a lot of code dependencies. I moved the minimum code in order to be able to add code specific to PCIBus.
Interfaces need to make sense, this one feels like you randomly moved out parts that your patch happens to need.
Just keep it all inpci.cfor now.
OK, I'll make the changes for next version.
Thanks,
Marcel
PATCH v6 10/26 hw/pci: made pci_bus_is_root a PCIBusClass method
In reply to Marcel ApfelbaumFrom: Marcel Apfelbaum <[email protected]>
Refactoring it as a method of PCIBusClass will allow different implementations for subclasses.
Removed the assumption that the root bus does not have a parent device because is specific only to the default class implementation.
--- hw/pci/pci.c | 11 ++++------- hw/pci/pci_bus.c | 9 +++++++++ hw/vfio/pci.c | 1 + include/hw/pci/pci.h | 1 - include/hw/pci/pci_bus.h | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 8 deletions(-)
hw/pci/pci.c +4 -7
@@ -205,7 +205,10 @@ PCIBus *pci_device_root_bus(const PCIDevice *d) {PCIBus *bus = d->bus; -while ((d = bus->parent_dev) !=NULL ) { +while (!pci_bus_is_root (bus)) { + d = bus->parent_dev; +assert (d !=NULL ); + bus = d->bus; }
@@ -218,7 +221,6 @@ const char *pci_root_bus_path(PCIDevice *dev)PCIHostState *host_bridge =PCI_HOST_BRIDGE (rootbus->qbus.parent);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); -assert (!rootbus->parent_dev);assert (host_bridge->bus == rootbus);if (hc->root_bus_path) {
@@ -250,11 +252,6 @@ bool pci_bus_is_express(PCIBus *bus)return object_dynamic_cast (OBJECT (bus),TYPE_PCIE_BUS ); } -bool pci_bus_is_root (PCIBus *bus) -{ -return !bus->parent_dev; -} - void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
hw/pci/pci_bus.c +9 -0
@@ -464,9 +464,15 @@ static void pcibus_reset(BusState *qbus) } } +static bool pcibus_is_root (PCIBus *bus) +{ +return !bus->parent_dev; +} +static void pci_bus_class_init (ObjectClass *klass,void *data) {BusClass *k =BUS_CLASS (klass); +PCIBusClass *pbc =PCI_BUS_CLASS (klass); k->print_dev = pcibus_dev_print; k->get_dev_path = pcibus_get_dev_path;
@@ -474,11 +480,14 @@ static void pci_bus_class_init(ObjectClass *klass, void *data) k->realize = pci_bus_realize; k->unrealize = pci_bus_unrealize; k->reset = pcibus_reset; + + pbc->is_root = pcibus_is_root; }static const TypeInfo pci_bus_info = { .name =TYPE_PCI_BUS , .parent =TYPE_BUS , + .class_size =sizeof (PCIBusClass), .instance_size =sizeof (PCIBus), .class_init = pci_bus_class_init, };
hw/vfio/pci.c +1 -0
@@ -32,6 +32,7 @@#include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/event_notifier.h"
include/hw/pci/pci.h +0 -1
@@ -340,7 +340,6 @@ typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);#define TYPE_PCIE_BUS "PCIE"bool pci_bus_is_express (PCIBus *bus); -bool pci_bus_is_root (PCIBus *bus); void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,
include/hw/pci/pci_bus.h +15 -0
@@ -15,6 +15,16 @@ PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num);#define TYPE_PCI_BUS "PCI"#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +#define PCI_BUS_CLASS (klass) OBJECT_CLASS_CHECK(PCIBusClass, (klass), TYPE_PCI_BUS) +#define PCI_BUS_GET_CLASS (obj) OBJECT_GET_CLASS(PCIBusClass, (obj), TYPE_PCI_BUS) + +typedef struct PCIBusClass { +/*< private >*/ +BusClass parent_class; +/*< public >*/ + +bool (*is_root)(PCIBus *bus); +}PCIBusClass ;struct PCIBus {BusState qbus;
@@ -39,6 +49,11 @@ struct PCIBus {int *irq_count; }; +static inline bool pci_bus_is_root (PCIBus *bus) +{ +return PCI_BUS_GET_CLASS (bus)->is_root (bus); +} +typedef struct PCIBridgeWindows PCIBridgeWindows ;/*
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 10/26] hw/pci: made pci_bus_is_root a PCIBusClass method
Quoted 10 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
Refactoring it as a method of PCIBusClass will allow different implementations for subclasses.
Removed the assumption that the root bus does not have a parent device because is specific only to the default class implementation.
Signed-off-by Marcel Apfelbaum <[email protected]>
Or just add bool is_root there?
Won't that be simpler?
Quoted 138 lines
--- hw/pci/pci.c | 11 ++++------- hw/pci/pci_bus.c | 9 +++++++++ hw/vfio/pci.c | 1 + include/hw/pci/pci.h | 1 - include/hw/pci/pci_bus.h | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 8 deletions(-)hw/pci/pci.c +4
-7@@ -205,7 +205,10 @@ PCIBus *pci_device_root_bus(const PCIDevice *d) {PCIBus *bus = d->bus; -while ((d = bus->parent_dev) !=NULL ) { +while (!pci_bus_is_root (bus)) { + d = bus->parent_dev; +assert (d !=NULL ); + bus = d->bus; }@@ -218,7 +221,6 @@ const char *pci_root_bus_path(PCIDevice *dev)PCIHostState *host_bridge =PCI_HOST_BRIDGE (rootbus->qbus.parent);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); -assert (!rootbus->parent_dev);assert (host_bridge->bus == rootbus);if (hc->root_bus_path) {@@ -250,11 +252,6 @@ bool pci_bus_is_express(PCIBus *bus)return object_dynamic_cast (OBJECT (bus),TYPE_PCIE_BUS ); } -bool pci_bus_is_root (PCIBus *bus) -{ -return !bus->parent_dev; -} - void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,hw/pci/pci_bus.c +9
-0@@ -464,9 +464,15 @@ static void pcibus_reset(BusState *qbus) } } +static bool pcibus_is_root (PCIBus *bus) +{ +return !bus->parent_dev; +} +static void pci_bus_class_init (ObjectClass *klass,void *data) {BusClass *k =BUS_CLASS (klass); +PCIBusClass *pbc =PCI_BUS_CLASS (klass); k->print_dev = pcibus_dev_print; k->get_dev_path = pcibus_get_dev_path;@@ -474,11 +480,14 @@ static void pci_bus_class_init(ObjectClass *klass, void *data) k->realize = pci_bus_realize; k->unrealize = pci_bus_unrealize; k->reset = pcibus_reset; + + pbc->is_root = pcibus_is_root; }static const TypeInfo pci_bus_info = { .name =TYPE_PCI_BUS , .parent =TYPE_BUS , + .class_size =sizeof (PCIBusClass), .instance_size =sizeof (PCIBus), .class_init = pci_bus_class_init, };hw/vfio/pci.c +1
-0@@ -32,6 +32,7 @@#include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/event_notifier.h" include/hw/pci/pci.h +0
-1@@ -340,7 +340,6 @@ typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);#define TYPE_PCIE_BUS "PCIE"bool pci_bus_is_express (PCIBus *bus); -bool pci_bus_is_root (PCIBus *bus); void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,include/hw/pci/pci_bus.h +15
-0@@ -15,6 +15,16 @@ PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num);#define TYPE_PCI_BUS "PCI"#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +#define PCI_BUS_CLASS (klass) OBJECT_CLASS_CHECK(PCIBusClass, (klass), TYPE_PCI_BUS) +#define PCI_BUS_GET_CLASS (obj) OBJECT_GET_CLASS(PCIBusClass, (obj), TYPE_PCI_BUS) + +typedef struct PCIBusClass { +/*< private >*/ +BusClass parent_class; +/*< public >*/ + +bool (*is_root)(PCIBus *bus); +}PCIBusClass ;struct PCIBus {BusState qbus;@@ -39,6 +49,11 @@ struct PCIBus {int *irq_count; }; +static inline bool pci_bus_is_root (PCIBus *bus) +{ +return PCI_BUS_GET_CLASS (bus)->is_root (bus); +} +typedef struct PCIBridgeWindows PCIBridgeWindows ;/* Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 10/26] hw/pci: made pci_bus_is_root a PCIBusClass method
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
Refactoring it as a method of PCIBusClass will allow different implementations for subclasses.
Quoted 8 lines
Quoted 5 lines
Removed the assumption that the root bus does not have a parent device because is specific only to the default class implementation.
Signed-off-by Marcel Apfelbaum <[email protected]>Or just add bool
is_rootthere?
Won't that be simpler?
A field instead of a method? I am not sure it will be less code lines.
Thanks,
Marcel
Quoted 139 lines
Quoted 139 lines
--- hw/pci/pci.c | 11 ++++------- hw/pci/pci_bus.c | 9 +++++++++ hw/vfio/pci.c | 1 + include/hw/pci/pci.h | 1 - include/hw/pci/pci_bus.h | 15 +++++++++++++++ 5 files changed, 29 insertions(+), 8 deletions(-)hw/pci/pci.c +4
-7@@ -205,7 +205,10 @@ PCIBus *pci_device_root_bus(const PCIDevice *d) {PCIBus *bus = d->bus; -while ((d = bus->parent_dev) !=NULL ) { +while (!pci_bus_is_root (bus)) { + d = bus->parent_dev; +assert (d !=NULL ); + bus = d->bus; }@@ -218,7 +221,6 @@ const char *pci_root_bus_path(PCIDevice *dev)PCIHostState *host_bridge =PCI_HOST_BRIDGE (rootbus->qbus.parent);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_GET_CLASS (host_bridge); -assert (!rootbus->parent_dev);assert (host_bridge->bus == rootbus);if (hc->root_bus_path) {@@ -250,11 +252,6 @@ bool pci_bus_is_express(PCIBus *bus)return object_dynamic_cast (OBJECT (bus),TYPE_PCIE_BUS ); } -bool pci_bus_is_root (PCIBus *bus) -{ -return !bus->parent_dev; -} - void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,hw/pci/pci_bus.c +9
-0@@ -464,9 +464,15 @@ static void pcibus_reset(BusState *qbus) } } +static bool pcibus_is_root (PCIBus *bus) +{ +return !bus->parent_dev; +} +static void pci_bus_class_init (ObjectClass *klass,void *data) {BusClass *k =BUS_CLASS (klass); +PCIBusClass *pbc =PCI_BUS_CLASS (klass); k->print_dev = pcibus_dev_print; k->get_dev_path = pcibus_get_dev_path;@@ -474,11 +480,14 @@ static void pci_bus_class_init(ObjectClass *klass, void *data) k->realize = pci_bus_realize; k->unrealize = pci_bus_unrealize; k->reset = pcibus_reset; + + pbc->is_root = pcibus_is_root; }static const TypeInfo pci_bus_info = { .name =TYPE_PCI_BUS , .parent =TYPE_BUS , + .class_size =sizeof (PCIBusClass), .instance_size =sizeof (PCIBus), .class_init = pci_bus_class_init, };hw/vfio/pci.c +1
-0@@ -32,6 +32,7 @@#include "hw/pci/msi.h" #include "hw/pci/msix.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/event_notifier.h" include/hw/pci/pci.h +0
-1@@ -340,7 +340,6 @@ typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);#define TYPE_PCIE_BUS "PCIE"bool pci_bus_is_express (PCIBus *bus); -bool pci_bus_is_root (PCIBus *bus); void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent, const char *name, MemoryRegion *address_space_mem,include/hw/pci/pci_bus.h +15
-1@@ -15,6 +15,16 @@ PciDeviceInfoList *qmp_query_pci_devices(PCIBus *bus, int bus_num);#define TYPE_PCI_BUS "PCI"#define PCI_BUS (obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS) +#define PCI_BUS_CLASS (klass) OBJECT_CLASS_CHECK(PCIBusClass, (klass), TYPE_PCI_BUS) +#define PCI_BUS_GET_CLASS (obj) OBJECT_GET_CLASS(PCIBusClass, (obj), TYPE_PCI_BUS) + +typedef struct PCIBusClass { +/*< private >*/ +BusClass parent_class; +/*< public >*/ + +bool (*is_root)(PCIBus *bus); +}PCIBusClass ;struct PCIBus {BusState qbus;@@ -39,6 +49,11 @@ struct PCIBus {int *irq_count; }; +static inline bool pci_bus_is_root (PCIBus *bus) +{ +return PCI_BUS_GET_CLASS (bus)->is_root (bus); +} +typedef struct PCIBridgeWindows PCIBridgeWindows ;/* -- 2.1.0
PATCH v6 11/26 hw/pci: made pci_bus_num a PCIBusClass method
In reply to Marcel ApfelbaumFrom: Marcel Apfelbaum <[email protected]>
Refactoring it as a method of PCIBusClass will allow different implementations for subclasses.
--- hw/i386/kvm/pci-assign.c | 1 + hw/pci/pci.c | 7 ------- hw/pci/pci_bus.c | 10 ++++++++++ hw/scsi/megasas.c | 1 + hw/xen/xen_pt.c | 1 + include/hw/pci/pci.h | 1 - include/hw/pci/pci_bus.h | 6 ++++++ 7 files changed, 19 insertions(+), 8 deletions(-)
hw/i386/kvm/pci-assign.c +1 -0
@@ -35,6 +35,7 @@#include "qemu/range.h" #include "sysemu/sysemu.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/pci/msi.h" #include "kvm_i386.h"
hw/pci/pci.c +0 -7
@@ -301,13 +301,6 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,return bus; } -int pci_bus_num (PCIBus *s) -{ -if (pci_bus_is_root (s)) -return 0 ;/* pci host bridge */ -return s->parent_dev->config[PCI_SECONDARY_BUS ]; -} -static int get_pci_config_device (QEMUFile *f,void *pv,size_t size) {PCIDevice *s =container_of (pv, PCIDevice, config);
hw/pci/pci_bus.c +10 -0
@@ -469,6 +469,15 @@ static bool pcibus_is_root(PCIBus *bus)return !bus->parent_dev; } +static int pcibus_num (PCIBus *bus) +{ +if (pcibus_is_root (bus)) { +return 0 ;/* pci host bridge */ + } + +return bus->parent_dev->config[PCI_SECONDARY_BUS ]; +} +static void pci_bus_class_init (ObjectClass *klass,void *data) {BusClass *k =BUS_CLASS (klass);
@@ -482,6 +491,7 @@ static void pci_bus_class_init(ObjectClass *klass, void *data) k->reset = pcibus_reset; pbc->is_root = pcibus_is_root; + pbc->bus_num = pcibus_num; }static const TypeInfo pci_bus_info = {
hw/scsi/megasas.c +1 -0
@@ -20,6 +20,7 @@#include "hw/hw.h" #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "sysemu/dma.h" #include "sysemu/block-backend.h" #include "hw/pci/msi.h"
hw/xen/xen_pt.c +1 -0
@@ -55,6 +55,7 @@#include <sys/ioctl.h> #include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" #include "hw/xen/xen.h" #include "hw/xen/xen_backend.h" #include "xen_pt.h"
include/hw/pci/pci.h +0 -1
@@ -375,7 +375,6 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,PCIDevice *pci_vga_init (PCIBus *bus); -int pci_bus_num (PCIBus *s);void pci_for_each_device (PCIBus *bus,int bus_num,void (*fn)(PCIBus *bus,PCIDevice *d,void *opaque),void *opaque);
include/hw/pci/pci_bus.h +6 -0
@@ -24,6 +24,7 @@ typedef struct PCIBusClass {/*< public >*/ bool (*is_root)(PCIBus *bus); +int (*bus_num)(PCIBus *bus); } PCIBusClass;struct PCIBus {
@@ -54,6 +55,11 @@ static inline bool pci_bus_is_root(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->is_root (bus); } +static inline int pci_bus_num (PCIBus *bus) +{ +return PCI_BUS_GET_CLASS (bus)->bus_num (bus); +} +typedef struct PCIBridgeWindows PCIBridgeWindows ;/*
Signature · 1 line
2.1.0
PATCH v6 12/26 hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface
In reply to Marcel ApfelbaumFrom: Marcel Apfelbaum <[email protected]>
This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.
--- hw/i386/acpi-build.c | 9 ++++++--- hw/pci-host/piix.c | 5 +++++ hw/pci-host/q35.c | 4 ++++ hw/pci/pci_host.c | 6 ++++++ include/hw/pci/pci_host.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-)
hw/i386/acpi-build.c +6 -3
@@ -249,7 +249,8 @@ static void acpi_get_pci_info(PcPciInfo *info)Object *pci_host;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);
@@ -993,7 +994,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIBus *bus =NULL ;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);if (!ambiguous && pci_host) { bus =PCI_HOST_BRIDGE (pci_host)->bus; }
@@ -1338,7 +1340,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)QObject *o;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);
hw/pci-host/piix.c +5 -0
@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = { .instance_size = sizeof(I440FXState), .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } + };static void i440fx_register_types (void )
hw/pci-host/q35.c +4 -0
@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = { .instance_size = sizeof(Q35PCIHost), .instance_init = q35_host_initfn, .class_init = q35_host_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } };/****************************************************************************
hw/pci/pci_host.c +6 -0
@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_main_host_interface_info = { + .name =TYPE_PCI_MAIN_HOST_BRIDGE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,
@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) { +type_register_static (&pci_main_host_interface_info);type_register_static (&pci_host_type_info); }
include/hw/pci/pci_host.h +7 -0
@@ -30,6 +30,13 @@#include "hw/sysbus.h" +/** +* Marker interface for classes whose instances can +* be main host bridges. It is intended to be used +* when the QOM tree includes multiple host bridges. +*/ +#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"#define PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE)
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 12/26] hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface
Quoted 8 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.
Signed-off-by Marcel Apfelbaum <[email protected]>
Fixing hotplug for pxb almost for sure means we'll need to drop this later. How about an interface to iterate over objects by type?
You can then blacklist pxbs for now.
Quoted 117 lines
--- hw/i386/acpi-build.c | 9 ++++++--- hw/pci-host/piix.c | 5 +++++ hw/pci-host/q35.c | 4 ++++ hw/pci/pci_host.c | 6 ++++++ include/hw/pci/pci_host.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-)hw/i386/acpi-build.c +6
-3@@ -249,7 +249,8 @@ static void acpi_get_pci_info(PcPciInfo *info)Object *pci_host;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);@@ -993,7 +994,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIBus *bus =NULL ;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);if (!ambiguous && pci_host) { bus =PCI_HOST_BRIDGE (pci_host)->bus; }@@ -1338,7 +1340,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)QObject *o;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);hw/pci-host/piix.c +5
-0@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = { .instance_size = sizeof(I440FXState), .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } + };static void i440fx_register_types (void )hw/pci-host/q35.c +4
-0@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = { .instance_size = sizeof(Q35PCIHost), .instance_init = q35_host_initfn, .class_init = q35_host_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } };/**************************************************************************** hw/pci/pci_host.c +6
-0@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_main_host_interface_info = { + .name =TYPE_PCI_MAIN_HOST_BRIDGE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) { +type_register_static (&pci_main_host_interface_info);type_register_static (&pci_host_type_info); }include/hw/pci/pci_host.h +7
-0@@ -30,6 +30,13 @@#include "hw/sysbus.h" +/** +* Marker interface for classes whose instances can +* be main host bridges. It is intended to be used +* when the QOM tree includes multiple host bridges. +*/ +#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"#define PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE)Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 12/26] hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.
Quoted 4 lines
Quoted 1 line
Signed-off-by Marcel Apfelbaum <[email protected]>Fixing hotplug for pxb almost for sure means we'll need to drop this later.
Not really, I am not sure how it is related. I'll go over the pxb pci devices for this hotplug. I have no intention to drop this later.
This interface denotes the main/default/bus 0 host bridge.
How about an interface to
Quoted 2 lines
iterate over objects by type?
You can then blacklist pxbs for now.
Less elegant in my opinion,
Quoted 118 lines
Quoted 118 lines
--- hw/i386/acpi-build.c | 9 ++++++--- hw/pci-host/piix.c | 5 +++++ hw/pci-host/q35.c | 4 ++++ hw/pci/pci_host.c | 6 ++++++ include/hw/pci/pci_host.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-)hw/i386/acpi-build.c +6
-3@@ -249,7 +249,8 @@ static void acpi_get_pci_info(PcPciInfo *info)Object *pci_host;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);@@ -993,7 +994,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIBus *bus =NULL ;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);if (!ambiguous && pci_host) { bus =PCI_HOST_BRIDGE (pci_host)->bus; }@@ -1338,7 +1340,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)QObject *o;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);hw/pci-host/piix.c +5
-0@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = { .instance_size = sizeof(I440FXState), .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } + };static void i440fx_register_types (void )hw/pci-host/q35.c +4
-0@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = { .instance_size = sizeof(Q35PCIHost), .instance_init = q35_host_initfn, .class_init = q35_host_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } };/**************************************************************************** hw/pci/pci_host.c +6
-0@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_main_host_interface_info = { + .name =TYPE_PCI_MAIN_HOST_BRIDGE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) { +type_register_static (&pci_main_host_interface_info);type_register_static (&pci_host_type_info); }include/hw/pci/pci_host.h +7
-1@@ -30,6 +30,13 @@#include "hw/sysbus.h" +/** +* Marker interface for classes whose instances can +* be main host bridges. It is intended to be used +* when the QOM tree includes multiple host bridges. +*/ +#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"#define PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE) --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 12/26] hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface
Quoted 9 lines · Marcel Apfelbaum
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Marcel Apfelbaum <[email protected]>Fixing hotplug for pxb almost for sure means we'll need to drop this later.
Not really, I am not sure how it is related. I'll go over the pxb pci devices for this hotplug. I have no intention to drop this later.
This interface denotes the main/default/bus 0 host bridge.
It's related since you will want to describe all host bridges in acpi.
Quoted 5 lines
How about an interface to
Quoted 2 lines
iterate over objects by type?
You can then blacklist pxbs for now.Less elegant in my opinion,
Right but it will be needed in the future anyway.
Quoted 118 lines
Quoted 118 lines
Quoted 118 lines
--- hw/i386/acpi-build.c | 9 ++++++--- hw/pci-host/piix.c | 5 +++++ hw/pci-host/q35.c | 4 ++++ hw/pci/pci_host.c | 6 ++++++ include/hw/pci/pci_host.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-)hw/i386/acpi-build.c +6
-3@@ -249,7 +249,8 @@ static void acpi_get_pci_info(PcPciInfo *info)Object *pci_host;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);@@ -993,7 +994,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIBus *bus =NULL ;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);if (!ambiguous && pci_host) { bus =PCI_HOST_BRIDGE (pci_host)->bus; }@@ -1338,7 +1340,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)QObject *o;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);hw/pci-host/piix.c +5
-0@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = { .instance_size = sizeof(I440FXState), .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } + };static void i440fx_register_types (void )hw/pci-host/q35.c +4
-0@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = { .instance_size = sizeof(Q35PCIHost), .instance_init = q35_host_initfn, .class_init = q35_host_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } };/**************************************************************************** hw/pci/pci_host.c +6
-0@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_main_host_interface_info = { + .name =TYPE_PCI_MAIN_HOST_BRIDGE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) { +type_register_static (&pci_main_host_interface_info);type_register_static (&pci_host_type_info); }include/hw/pci/pci_host.h +7
-1@@ -30,6 +30,13 @@#include "hw/sysbus.h" +/** +* Marker interface for classes whose instances can +* be main host bridges. It is intended to be used +* when the QOM tree includes multiple host bridges. +*/ +#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"#define PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE) --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 12/26] hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Marcel Apfelbaum
Quoted 10 lines · Michael S. Tsirkin
Quoted 8 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.
Signed-off-by Marcel Apfelbaum <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Fixing hotplug for pxb almost for sure means we'll need to drop this later.
Not really, I am not sure how it is related. I'll go over the pxb pci devices for this hotplug. I have no intention to drop this later.
This interface denotes the main/default/bus 0 host bridge.It's related since you will want to describe all host bridges in acpi.
When I'll submit the pxb hotplug support it will be more clear, Basically, I'll go over the pxbs leaving the default host bridge alone.
Quoted 8 lines
Quoted 6 lines
How about an interface to
Quoted 2 lines
iterate over objects by type?
You can then blacklist pxbs for now.Less elegant in my opinion,
Right but it will be needed in the future anyway.
I think we should leave this for when we'll need it, this series is already long enough without adding a new QOM iteration type.
Thanks,
Marcel
Quoted 119 lines
Quoted 119 lines
Quoted 119 lines
Quoted 119 lines
--- hw/i386/acpi-build.c | 9 ++++++--- hw/pci-host/piix.c | 5 +++++ hw/pci-host/q35.c | 4 ++++ hw/pci/pci_host.c | 6 ++++++ include/hw/pci/pci_host.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-)hw/i386/acpi-build.c +6
-3@@ -249,7 +249,8 @@ static void acpi_get_pci_info(PcPciInfo *info)Object *pci_host;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);@@ -993,7 +994,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIBus *bus =NULL ;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);if (!ambiguous && pci_host) { bus =PCI_HOST_BRIDGE (pci_host)->bus; }@@ -1338,7 +1340,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)QObject *o;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);hw/pci-host/piix.c +5
-0@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = { .instance_size = sizeof(I440FXState), .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } + };static void i440fx_register_types (void )hw/pci-host/q35.c +4
-0@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = { .instance_size = sizeof(Q35PCIHost), .instance_init = q35_host_initfn, .class_init = q35_host_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } };/**************************************************************************** hw/pci/pci_host.c +6
-0@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_main_host_interface_info = { + .name =TYPE_PCI_MAIN_HOST_BRIDGE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) { +type_register_static (&pci_main_host_interface_info);type_register_static (&pci_host_type_info); }include/hw/pci/pci_host.h +7
-1@@ -30,6 +30,13 @@#include "hw/sysbus.h" +/** +* Marker interface for classes whose instances can +* be main host bridges. It is intended to be used +* when the QOM tree includes multiple host bridges. +*/ +#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"#define PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE) --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 12/26] hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface
Quoted 15 lines · Marcel Apfelbaum
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Marcel Apfelbaum
Quoted 12 lines · Michael S. Tsirkin
Quoted 8 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.
Signed-off-by Marcel Apfelbaum <[email protected]>Fixing hotplug for pxb almost for sure means we'll need to drop this later.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Not really, I am not sure how it is related. I'll go over the pxb pci devices for this hotplug. I have no intention to drop this later.
This interface denotes the main/default/bus 0 host bridge.It's related since you will want to describe all host bridges in acpi.
When I'll submit the pxb hotplug support it will be more clear, Basically, I'll go over the pxbs leaving the default host bridge alone.
So instead, just go over all roots.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
How about an interface to
Quoted 2 lines
iterate over objects by type?
You can then blacklist pxbs for now.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Less elegant in my opinion,
Right but it will be needed in the future anyway.
I think we should leave this for when we'll need it, this series is already long enough without adding a new QOM iteration type.
Thanks,
Marcel
Do you have hotplug working?
Maybe wait until it's there, then we can discuss.
Quoted 119 lines
Quoted 119 lines
Quoted 119 lines
Quoted 119 lines
Quoted 119 lines
--- hw/i386/acpi-build.c | 9 ++++++--- hw/pci-host/piix.c | 5 +++++ hw/pci-host/q35.c | 4 ++++ hw/pci/pci_host.c | 6 ++++++ include/hw/pci/pci_host.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-)hw/i386/acpi-build.c +6
-3@@ -249,7 +249,8 @@ static void acpi_get_pci_info(PcPciInfo *info)Object *pci_host;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);@@ -993,7 +994,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIBus *bus =NULL ;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);if (!ambiguous && pci_host) { bus =PCI_HOST_BRIDGE (pci_host)->bus; }@@ -1338,7 +1340,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)QObject *o;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);hw/pci-host/piix.c +5
-0@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = { .instance_size = sizeof(I440FXState), .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } + };static void i440fx_register_types (void )hw/pci-host/q35.c +4
-0@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = { .instance_size = sizeof(Q35PCIHost), .instance_init = q35_host_initfn, .class_init = q35_host_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } };/**************************************************************************** hw/pci/pci_host.c +6
-0@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_main_host_interface_info = { + .name =TYPE_PCI_MAIN_HOST_BRIDGE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) { +type_register_static (&pci_main_host_interface_info);type_register_static (&pci_host_type_info); }include/hw/pci/pci_host.h +7
-1@@ -30,6 +30,13 @@#include "hw/sysbus.h" +/** +* Marker interface for classes whose instances can +* be main host bridges. It is intended to be used +* when the QOM tree includes multiple host bridges. +*/ +#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"#define PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE) --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 12/26] hw/pci: introduce TYPE_PCI_MAIN_HOST_BRIDGE interface
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Marcel Apfelbaum
Quoted 18 lines · Michael S. Tsirkin
Quoted 16 lines · Marcel Apfelbaum
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Marcel Apfelbaum
From: Marcel Apfelbaum <[email protected]>
This is a marker interface used to differentiate the "default" host bridge on a system with multiple host bridges. This differentiation is required only for pc machines for now by the ACPI subsystem.
Quoted 4 lines
Quoted 1 line
Signed-off-by Marcel Apfelbaum <[email protected]>Fixing hotplug for pxb almost for sure means we'll need to drop this later.
Not really, I am not sure how it is related. I'll go over the pxb pci devices for this hotplug. I have no intention to drop this later.
This interface denotes the main/default/bus 0 host bridge.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
It's related since you will want to describe all host bridges in acpi.
When I'll submit the pxb hotplug support it will be more clear, Basically, I'll go over the pxbs leaving the default host bridge alone.
So instead, just go over all roots.
I am not sure it will work that way. We'll know more after I will work on hotplug.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
How about an interface to
Quoted 2 lines
iterate over objects by type?
You can then blacklist pxbs for now.Less elegant in my opinion,
Right but it will be needed in the future anyway.
Quoted 8 lines
Quoted 5 lines
I think we should leave this for when we'll need it, this series is already long enough without adding a new QOM iteration type.
Thanks,
MarcelDo you have hotplug working?
Maybe wait until it's there, then we can discuss.
I agree, I hope I'll have something next week.
For next version I'll keep this around.
Thanks,
Marcel
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
Quoted 120 lines
--- hw/i386/acpi-build.c | 9 ++++++--- hw/pci-host/piix.c | 5 +++++ hw/pci-host/q35.c | 4 ++++ hw/pci/pci_host.c | 6 ++++++ include/hw/pci/pci_host.h | 7 +++++++ 5 files changed, 28 insertions(+), 3 deletions(-)hw/i386/acpi-build.c +6
-3@@ -249,7 +249,8 @@ static void acpi_get_pci_info(PcPciInfo *info)Object *pci_host;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);@@ -993,7 +994,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIBus *bus =NULL ;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);if (!ambiguous && pci_host) { bus =PCI_HOST_BRIDGE (pci_host)->bus; }@@ -1338,7 +1340,8 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)QObject *o;bool ambiguous; - pci_host =object_resolve_path_type ("" ,TYPE_PCI_HOST_BRIDGE , &ambiguous); + pci_host =object_resolve_path_type ("" ,TYPE_PCI_MAIN_HOST_BRIDGE , + &ambiguous);g_assert (!ambiguous);g_assert (pci_host);hw/pci-host/piix.c +5
-0@@ -766,6 +766,11 @@ static const TypeInfo i440fx_pcihost_info = { .instance_size = sizeof(I440FXState), .instance_init = i440fx_pcihost_initfn, .class_init = i440fx_pcihost_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } + };static void i440fx_register_types (void )hw/pci-host/q35.c +4
-0@@ -193,6 +193,10 @@ static const TypeInfo q35_host_info = { .instance_size = sizeof(Q35PCIHost), .instance_init = q35_host_initfn, .class_init = q35_host_class_init, + .interfaces = (InterfaceInfo []) { + {TYPE_PCI_MAIN_HOST_BRIDGE }, + { } + } };/**************************************************************************** hw/pci/pci_host.c +6
-0@@ -175,6 +175,11 @@ const MemoryRegionOps pci_host_data_be_ops = { .endianness = DEVICE_BIG_ENDIAN, }; +static const TypeInfo pci_main_host_interface_info = { + .name =TYPE_PCI_MAIN_HOST_BRIDGE , + .parent =TYPE_INTERFACE , +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -185,6 +190,7 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) { +type_register_static (&pci_main_host_interface_info);type_register_static (&pci_host_type_info); }include/hw/pci/pci_host.h +7
-1@@ -30,6 +30,13 @@#include "hw/sysbus.h" +/** +* Marker interface for classes whose instances can +* be main host bridges. It is intended to be used +* when the QOM tree includes multiple host bridges. +*/ +#define TYPE_PCI_MAIN_HOST_BRIDGE "pci-main-host-bridge" +#define TYPE_PCI_HOST_BRIDGE "pci-host-bridge"#define PCI_HOST_BRIDGE (obj) \ OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE) --2.1.0
PATCH v6 13/26 hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
In reply to Marcel ApfelbaumTYPE_PCI_HOST_BRIDGE_SNOOPED is a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.
The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
hw/pci/pci_host.c +8 -0
@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,
@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); + }type_init (pci_host_register_types)
include/hw/pci/pci_host.h +24 -0
@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass { +/* <private> */ +InterfaceClass parent_class; + +/* <public> */ +GPtrArray *(*snooping_hosts)(PCIHostState *); +}PCIHostBridgeSnoopedClass ; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len);
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 13/26] hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 39 lines · Marcel Apfelbaum
TYPE_PCI_HOST_BRIDGE_SNOOPEDis a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)hw/pci/pci_host.c +6
-0@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,
hw/pci/pci_host.c static const TypeInfo pci_host_type_info = { · line 202
Quoted 6 lines
hw/pci/pci_host.c +2
-0@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); +
extra empty line
Quoted 23 lines
hw/pci/pci_host.c +0
-0}type_init (pci_host_register_types)include/hw/pci/pci_host.h +12
-0@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED)
include/hw/pci/pci_host.h typedef struct PCIHostBridgeClass { · line 87
Quoted 10 lines
include/hw/pci/pci_host.h +10
-0+#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass { + /* <private> */ + InterfaceClass parent_class; + + /* <public> */ + GPtrArray *(*snooping_hosts)(PCIHostState *);
Why not just add GPtrArray here directly, and add an API to register/deregister?
Quoted 7 lines
include/hw/pci/pci_host.h +2
-0+} PCIHostBridgeSnoopedClass; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len);Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 13/26] hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Marcel Apfelbaum
TYPE_PCI_HOST_BRIDGE_SNOOPEDis a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)hw/pci/pci_host.c +6
-0@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {
Quoted 8 lines
hw/pci/pci_host.c static const TypeInfo pci_host_type_info = { · line 202
Quoted 6 lines
hw/pci/pci_host.c +2
-0static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); +extra empty line
Will take care of it, thanks.
Quoted 29 lines
Quoted 29 lines
hw/pci/pci_host.c +0
-0}type_init (pci_host_register_types)include/hw/pci/pci_host.h +17
-0@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass {
Quoted 8 lines
include/hw/pci/pci_host.h typedef struct PCIHostBridgeClass { · line 87
Quoted 5 lines
include/hw/pci/pci_host.h +5
-0+/* <private> */ +InterfaceClass parent_class; + +/* <public> */ +GPtrArray *(*snooping_hosts)(PCIHostState *);Why not just add GPtrArray here directly, and add an API to register/deregister?
The interface concentrates on usage, letting the way to fill the snooping hosts to the specific implementation.
Thanks,
Marcel
Quoted 8 lines
Quoted 8 lines
include/hw/pci/pci_host.h +2
-1+} PCIHostBridgeSnoopedClass; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len); --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 13/26] hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 88 lines · Marcel Apfelbaum
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Marcel Apfelbaum
TYPE_PCI_HOST_BRIDGE_SNOOPEDis a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)hw/pci/pci_host.c +6
-0@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {Quoted 8 lines
hw/pci/pci_host.c static const TypeInfo pci_host_type_info = { · line 202
Quoted 6 lines
hw/pci/pci_host.c +2
-0static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); +extra empty line
Will take care of it, thanks.
Quoted 29 lines
Quoted 29 lines
hw/pci/pci_host.c +0
-0}type_init (pci_host_register_types)include/hw/pci/pci_host.h +17
-0@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass {Quoted 8 lines
include/hw/pci/pci_host.h typedef struct PCIHostBridgeClass { · line 87
Quoted 5 lines
include/hw/pci/pci_host.h +5
-0+/* <private> */ +InterfaceClass parent_class; + +/* <public> */ +GPtrArray *(*snooping_hosts)(PCIHostState *);Why not just add GPtrArray here directly, and add an API to register/deregister?
Quoted 5 lines
The interface concentrates on usage, letting the way to fill the snooping hosts to the specific implementation.
Thanks,
Marcel
IMO this is overdoing abstractions.
But all this might be moot, it's probably better to just add everyone to the child bus list, and drop the concept of snooping config cycles.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/hw/pci/pci_host.h +2
-1+} PCIHostBridgeSnoopedClass; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len); --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 13/26] hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 89 lines · Michael S. Tsirkin
Quoted 88 lines · Marcel Apfelbaum
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Marcel Apfelbaum
TYPE_PCI_HOST_BRIDGE_SNOOPEDis a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)hw/pci/pci_host.c +6
-0@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {Quoted 8 lines
hw/pci/pci_host.c static const TypeInfo pci_host_type_info = { · line 202
Quoted 6 lines
hw/pci/pci_host.c +2
-0static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); +extra empty line
Will take care of it, thanks.
Quoted 37 lines
Quoted 24 lines
hw/pci/pci_host.c +0
-0}type_init (pci_host_register_types)include/hw/pci/pci_host.h +12
-0@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED)include/hw/pci/pci_host.h typedef struct PCIHostBridgeClass { · line 87
Quoted 10 lines
include/hw/pci/pci_host.h +10
-0+#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass { + /* <private> */ + InterfaceClass parent_class; + + /* <public> */ + GPtrArray *(*snooping_hosts)(PCIHostState *);Why not just add GPtrArray here directly, and add an API to register/deregister?
Quoted 7 lines
Quoted 5 lines
The interface concentrates on usage, letting the way to fill the snooping hosts to the specific implementation.
Thanks,
MarcelIMO this is overdoing abstractions.
It will provide us with enough elasticity when we'll try the same for Q35. Also this interface is used in several places and it will serve us when we'll go for Q35.
Quoted 4 lines
But all this might be moot, it's probably better to just add everyone to the child bus list, and drop the concept of snooping config cycles.
Well, this will be a problem, since the whole concept of the PXB is to snoop on the configuration cycles and this interface gives us a more easy way to understand the implementation.
We already discussed this approach and was accepted.
The code is small and concise and the use of QOM makes sense in my opinion. I prefer not to re-open it now.
Thanks,
Marcel
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
include/hw/pci/pci_host.h +2
-1+} PCIHostBridgeSnoopedClass; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len); --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 13/26] hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 93 lines · Marcel Apfelbaum
Quoted 92 lines · Michael S. Tsirkin
Quoted 91 lines · Marcel Apfelbaum
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Marcel Apfelbaum
TYPE_PCI_HOST_BRIDGE_SNOOPEDis a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)hw/pci/pci_host.c +6
-0@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {Quoted 8 lines
hw/pci/pci_host.c static const TypeInfo pci_host_type_info = { · line 202
Quoted 6 lines
hw/pci/pci_host.c +2
-0static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); +extra empty line
Will take care of it, thanks.
Quoted 29 lines
Quoted 29 lines
hw/pci/pci_host.c +0
-0}type_init (pci_host_register_types)include/hw/pci/pci_host.h +17
-0@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass {Quoted 8 lines
include/hw/pci/pci_host.h typedef struct PCIHostBridgeClass { · line 87
Quoted 5 lines
include/hw/pci/pci_host.h +5
-0+/* <private> */ +InterfaceClass parent_class; + +/* <public> */ +GPtrArray *(*snooping_hosts)(PCIHostState *);Why not just add GPtrArray here directly, and add an API to register/deregister?
The interface concentrates on usage, letting the way to fill the snooping hosts to the specific implementation.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Thanks,
MarcelIMO this is overdoing abstractions.
It will provide us with enough elasticity when we'll try the same for Q35. Also this interface is used in several places and it will serve us when we'll go for Q35.
I don't see how it helps, we don't just stick a virtual function in front of all new code we write on the assumption it helps elasticity.
Quoted 8 lines
Quoted 4 lines
But all this might be moot, it's probably better to just add everyone to the child bus list, and drop the concept of snooping config cycles.
Well, this will be a problem, since the whole concept of the PXB is to snoop on the configuration cycles and this interface gives us a more easy way to understand the implementation.
Quoted 6 lines
We already discussed this approach and was accepted.
The code is small and concise and the use of QOM makes sense in my opinion. I prefer not to re-open it now.Thanks,
Marcel
I'm talking about the implementation here.
We already scan the child bus list on config
transactions. Why not add your entry there,
then you can snoop to your heart's content.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
include/hw/pci/pci_host.h +2
-1+} PCIHostBridgeSnoopedClass; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len); --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 13/26] hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 97 lines · Michael S. Tsirkin
Quoted 96 lines · Marcel Apfelbaum
Quoted 95 lines · Michael S. Tsirkin
Quoted 93 lines · Marcel Apfelbaum
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Marcel Apfelbaum
TYPE_PCI_HOST_BRIDGE_SNOOPEDis a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)hw/pci/pci_host.c +6
-0@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {Quoted 8 lines
hw/pci/pci_host.c static const TypeInfo pci_host_type_info = { · line 202
Quoted 6 lines
hw/pci/pci_host.c +2
-0static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); +extra empty line
Will take care of it, thanks.
Quoted 29 lines
Quoted 29 lines
hw/pci/pci_host.c +0
-0}type_init (pci_host_register_types)include/hw/pci/pci_host.h +17
-0@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass {Quoted 8 lines
include/hw/pci/pci_host.h typedef struct PCIHostBridgeClass { · line 87
Quoted 5 lines
include/hw/pci/pci_host.h +5
-0+/* <private> */ +InterfaceClass parent_class; + +/* <public> */ +GPtrArray *(*snooping_hosts)(PCIHostState *);Why not just add GPtrArray here directly, and add an API to register/deregister?
The interface concentrates on usage, letting the way to fill the snooping hosts to the specific implementation.
Thanks,
Marcel
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
IMO this is overdoing abstractions.
It will provide us with enough elasticity when we'll try the same for Q35. Also this interface is used in several places and it will serve us when we'll go for Q35.
I don't see how it helps, we don't just stick a virtual function in front of all new code we write on the assumption it helps elasticity.
It helps by letting us querying the interface instead of asking:
Is this host-bridge PIIX ? look for child buses and see if there are roots
else: is this host-bridge ...
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
But all this might be moot, it's probably better to just add everyone to the child bus list, and drop the concept of snooping config cycles.
Well, this will be a problem, since the whole concept of the PXB is to snoop on the configuration cycles and this interface gives us a more easy way to understand the implementation.
We already discussed this approach and was accepted.
The code is small and concise and the use of QOM makes sense in my opinion. I prefer not to re-open it now.
Quoted 7 lines
Quoted 2 lines
Thanks,
MarcelI'm talking about the implementation here.
We already scan the child bus list on config
transactions. Why not add your entry there,
then you can snoop to your heart's content.
Maybe I didn't fully understand what you want.
Do you want to add the new root buses as child buses of root bus 0? This interface is not used in this context, is used in other scenarios:
[PATCH V6 for-2.3 21/26] hw/pci: inform bios if the system has extra pci root buses [PATCH V6 for-2.3 15/26] hw/acpi: add support for i440fx 'snooping' root busses
I can look for other usages, can you tell me how it will look without this interface?
Other thing, in config we have pci_data_write calling (in the end) pci_find_bus_nr that does not support multiple root buses.
Changing it could affect a lot of functionality and also looking at the function it will not be pretty or clear. Keeping it at host-bridge level (see [PATCH V6 for-2.3 14/26] hw/pci-host/piix: implement TYPE_PCI_HOST_BRIDGE_SNOOPED interface) and having piix query its pxbs for the extra root buses seems a good fit.
Thanks,
Marce
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
include/hw/pci/pci_host.h +2
-1+} PCIHostBridgeSnoopedClass; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len); --2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 13/26] hw/pci-host: introduce TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 102 lines · Marcel Apfelbaum
Quoted 101 lines · Michael S. Tsirkin
Quoted 99 lines · Marcel Apfelbaum
Quoted 89 lines · Michael S. Tsirkin
Quoted 88 lines · Marcel Apfelbaum
Quoted 40 lines · Michael S. Tsirkin
Quoted 39 lines · Marcel Apfelbaum
TYPE_PCI_HOST_BRIDGE_SNOOPEDis a special case of host bridge whose configuration registers are snooped by other host bridges to complete their configuration cycles.The interface exposes a list of snooping host bridges that shall be used by the hosts implementing this interface in order to emulate a snooping mechanism.
The way that the snooping hosts are registered or how the snooping is implemented are out of the interface scope, it only provides a way to determine if a host bridge has snooping hosts and list them.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci/pci_host.c | 8 ++++++++ include/hw/pci/pci_host.h | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+)hw/pci/pci_host.c +6
-0@@ -180,6 +180,12 @@ static const TypeInfo pci_main_host_interface_info = { .parent = TYPE_INTERFACE, }; +static const TypeInfo pci_host_bridge_snooped_interface_info = { + .name =TYPE_PCI_HOST_BRIDGE_SNOOPED , + .parent =TYPE_INTERFACE , + .class_size =sizeof (PCIHostBridgeSnoopedClass), +}; +static const TypeInfo pci_host_type_info = { .name =TYPE_PCI_HOST_BRIDGE , .parent =TYPE_SYS_BUS_DEVICE ,@@ -191,7 +197,9 @@ static const TypeInfo pci_host_type_info = {Quoted 8 lines
hw/pci/pci_host.c static const TypeInfo pci_host_type_info = { · line 202
Quoted 6 lines
hw/pci/pci_host.c +2
-0static void pci_host_register_types (void ) {type_register_static (&pci_main_host_interface_info); +type_register_static (&pci_host_bridge_snooped_interface_info);type_register_static (&pci_host_type_info); +extra empty line
Will take care of it, thanks.
Quoted 37 lines
Quoted 24 lines
hw/pci/pci_host.c +0
-0}type_init (pci_host_register_types)include/hw/pci/pci_host.h +12
-0@@ -63,6 +63,30 @@ typedef struct PCIHostBridgeClass {const char *(*root_bus_path)(PCIHostState *,PCIBus *); } PCIHostBridgeClass; +/** +* A special case of host bridge whose configuration registers +* are snooped by other host bridges to complete their +* configuration cycles. +*/ +#define TYPE_PCI_HOST_BRIDGE_SNOOPED "pci-host-bridge-snooped" +#define TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass) \ + OBJECT_CLASS_CHECK(PCIHostBridgeSnoopedClass, (klass), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) +#define PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (obj) \ + OBJECT_GET_CLASS(PCIHostBridgeSnoopedClass, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED)include/hw/pci/pci_host.h typedef struct PCIHostBridgeClass { · line 87
Quoted 10 lines
include/hw/pci/pci_host.h +10
-0+#define PCI_HOST_BRIDGE_SNOOPED (obj) \ + INTERFACE_CHECK(PCIHostState, (obj), \ + TYPE_PCI_HOST_BRIDGE_SNOOPED) + +typedef struct PCIHostBridgeSnoopedClass { + /* <private> */ + InterfaceClass parent_class; + + /* <public> */ + GPtrArray *(*snooping_hosts)(PCIHostState *);Why not just add GPtrArray here directly, and add an API to register/deregister?
Quoted 7 lines
Quoted 5 lines
The interface concentrates on usage, letting the way to fill the snooping hosts to the specific implementation.
Thanks,
MarcelIMO this is overdoing abstractions.
It will provide us with enough elasticity when we'll try the same for Q35. Also this interface is used in several places and it will serve us when we'll go for Q35.
Quoted 6 lines
Quoted 3 lines
I don't see how it helps, we don't just stick a virtual function in front of all new code we write on the assumption it helps elasticity.
It helps by letting us querying the interface instead of asking:
Is this host-bridge PIIX ? look for child buses and see if there are roots
else: is this host-bridge ...
But what does not help is all the indirection and hiding.
Quoted 35 lines
Quoted 13 lines
Quoted 13 lines
Quoted 5 lines
But all this might be moot, it's probably better to just add everyone to the child bus list, and drop the concept of snooping config cycles.
Well, this will be a problem, since the whole concept of the PXB is to snoop on the configuration cycles and this interface gives us a more easy way to understand the implementation.
We already discussed this approach and was accepted.
The code is small and concise and the use of QOM makes sense in my opinion. I prefer not to re-open it now.Quoted 7 lines
Quoted 2 lines
Thanks,
MarcelI'm talking about the implementation here.
We already scan the child bus list on config
transactions. Why not add your entry there,
then you can snoop to your heart's content.Maybe I didn't fully understand what you want.
Do you want to add the new root buses as child buses of root bus 0? This interface is not used in this context, is used in other scenarios:
[PATCH V6 for-2.3 21/26] hw/pci: inform bios if the system has extra pci root buses [PATCH V6 for-2.3 15/26] hw/acpi: add support for i440fx 'snooping' root bussesI can look for other usages, can you tell me how it will look without this interface?
Other thing, in config we have
pci_data_writecalling (in the end)pci_find_bus_nrthat does not support multiple root buses.
Changing it could affect a lot of functionality and also looking at the function it will not be pretty or clear. Keeping it at host-bridge level (see [PATCH V6 for-2.3 14/26] hw/pci-host/piix: implementTYPE_PCI_HOST_BRIDGE_SNOOPEDinterface) and having piix query its pxbs for the extra root buses seems a good fit.
Quoted 2 lines
Thanks,
Marce
Really ideally we would just have a P2P bridge.
This is what we wanted originally: declare a bridge as
a pci host in ACPI.
Unfortunately you tried, and said this confuses guests, so we don't make this device look like a bridge to guests. But it still can/should make it look just like a bridge to qemu, and all the machinery for forwarding config transactions will mostly work.
One thing that won't work is the funky unrolled recursion in pci_find_bus_nr, since that assumes each bridge has a bus range. I guess we'll just have to make it recursive.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
include/hw/pci/pci_host.h +2
-1+} PCIHostBridgeSnoopedClass; +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len); --2.1.0
PATCH v6 14/26 hw/pci-host/piix: implement TYPE_PCI_HOST_BRIDGE_SNOOPED interface
In reply to Marcel ApfelbaumThe PIIX holds a list of snooping host bridges that is populated by a registration function that shall be used by any host bridge that needs to use PIIX configuration space to complete their configuration cycles.
PIIX monitors acceses to configuration registers and passes them to the corresponding host bridge if the input bus number is in its bus range.
--- hw/pci-host/piix.c | 118 +++++++++++++++++++++++++++++++++++++++++++++- hw/pci/pci_host.c | 28 +++++++++++ include/hw/i386/pc.h | 6 +++ include/hw/pci/pci_host.h | 3 ++ 4 files changed, 154 insertions(+), 1 deletion(-)
hw/pci-host/piix.c +117 -1
@@ -50,6 +50,12 @@ typedef struct I440FXState {PcPciInfo pci_info;uint64_t pci_hole64_size;uint32_t short_root_bus; + +/* +* List of PCI host bridges listening to +* the same configuration registers. +*/ +GPtrArray *snooping_hosts; } I440FXState;#define PIIX_NUM_PIC_IRQS 16/* i8259 * 2 */
@@ -255,14 +261,80 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v,visit_type_uint64 (v, &w64.end, name, errp); } +static PCIBus *i440fx_find_target_bus (I440FXState *i440fx,uint8_t bus_num) +{ +PCIHostState *host =PCI_HOST_BRIDGE (i440fx); +PCIBus *target_bus =NULL ; + +if (bus_num ==pci_bus_num (host->bus)) { + target_bus = host->bus; + }else { +int i; + +for (i =0 ; i < i440fx->snooping_hosts->len; i++) { +PCIHostState *s_host =g_ptr_array_index (i440fx->snooping_hosts, i); +Range r =pci_host_get_buses_range (s_host); + +if (r.begin <= bus_num && r.end >= bus_num) { + target_bus = s_host->bus; + } + + } + } + +return target_bus; +} + +static void i440fx_pcihost_data_write (void *opaque,hwaddr addr, +uint64_t val,unsigned len) +{ +uint32_t config_reg =PCI_HOST_BRIDGE (opaque)->config_reg; + +if (config_reg & (1u <<31 )) { +uint8_t bus_num = (config_reg >>16 ) &0xFF ; +I440FXState *i440fx =I440FX_PCI_HOST_BRIDGE (opaque); +PCIBus *target_bus =i440fx_find_target_bus (i440fx, bus_num); + +if (target_bus) { +pci_data_write (target_bus, config_reg | (addr &3 ), val, len); + } + } +} + +static uint64_t i440fx_pcihost_data_read (void *opaque, +hwaddr addr,unsigned len) +{ +uint32_t config_reg =PCI_HOST_BRIDGE (opaque)->config_reg; + +if (config_reg & (1U <<31 )) { +int bus_num = (config_reg >>16 ) &0xFF ; +I440FXState *i440fx =I440FX_PCI_HOST_BRIDGE (opaque); +PCIBus *target_bus =i440fx_find_target_bus (i440fx, bus_num); + +if (target_bus) { +return pci_data_read (target_bus, config_reg | (addr &3 ), len); + } + } + +return 0xffffffff ; +} + +const MemoryRegionOps i440fx_pcihost_data_le_ops = { + .read = i440fx_pcihost_data_read, + .write = i440fx_pcihost_data_write, + .endianness =DEVICE_LITTLE_ENDIAN , +}; +static void i440fx_pcihost_initfn (Object *obj) {PCIHostState *s =PCI_HOST_BRIDGE (obj);I440FXState *d =I440FX_PCI_HOST_BRIDGE (obj); + d->snooping_hosts =g_ptr_array_new (); +memory_region_init_io (&s->conf_mem, obj, &pci_host_conf_le_ops, s,"pci-conf-idx" ,4 ); -memory_region_init_io (&s->data_mem, obj, &pci_host_data_le_ops, s, +memory_region_init_io (&s->data_mem, obj, &i440fx_pcihost_data_le_ops, s,"pci-conf-data" ,4 ); object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "int",
@@ -400,6 +472,40 @@ PCIBus *find_i440fx(void)return s ? s->bus :NULL ; } +/* +* Returns 0 on successs, -1 if i440fx host was not +* found or the bus number is already in use. +*/ +int i440fx_register_snooping_host (PCIHostState *host) +{ +I440FXState *s =OBJECT_CHECK (I440FXState, +object_resolve_path ("/machine/i440fx" ,NULL ), +TYPE_I440FX_PCI_HOST_BRIDGE ); +uint8_t bus_num =pci_bus_num (host->bus); +int i; + +/* i440fx host not found */ +if (!s) { +return -1 ; + } + +/* 0 is reserved for i440fx host bridge */ +if (bus_num ==0 ) { +return -1 ; + } + +/* check if the bus number is unique */ +for (i =0 ; i < s->snooping_hosts->len; i++) { +PCIHostState *s_host =g_ptr_array_index (s->snooping_hosts, i); +if (bus_num ==pci_bus_num (s_host->bus)) { +return -1 ; + } + } + +g_ptr_array_add (s->snooping_hosts, host); +return 0 ; +} +/* PIIX3 PCI to ISA bridge */ static void piix3_set_irq_pic (PIIX3State *piix3,int pic_irq) {
@@ -742,6 +848,13 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,return "0000:00" ; } +static GPtrArray *i440fx_snooping_hosts (PCIHostState *host_bridge) +{ +I440FXState *s =I440FX_PCI_HOST_BRIDGE (host_bridge); + +return s->snooping_hosts; +} +static Property i440fx_props[] = {DEFINE_PROP_SIZE (PCI_HOST_PROP_PCI_HOLE64_SIZE , I440FXState, pci_hole64_size,DEFAULT_PCI_HOLE64_SIZE ),
@@ -753,11 +866,13 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass); +PCIHostBridgeSnoopedClass *sc =TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass); hc->root_bus_path = i440fx_pcihost_root_bus_path; dc->realize = i440fx_pcihost_realize; dc->fw_name ="pci" ; dc->props = i440fx_props; + sc->snooping_hosts = i440fx_snooping_hosts; }static const TypeInfo i440fx_pcihost_info = {
@@ -768,6 +883,7 @@ static const TypeInfo i440fx_pcihost_info = { .class_init = i440fx_pcihost_class_init, .interfaces = (InterfaceInfo []) { {TYPE_PCI_MAIN_HOST_BRIDGE }, + {TYPE_PCI_HOST_BRIDGE_SNOOPED }, { } }
hw/pci/pci_host.c +28 -0
@@ -20,6 +20,8 @@#include "hw/pci/pci.h" #include "hw/pci/pci_host.h" +#include "hw/pci/pci_bus.h" +#include "qemu/range.h" #include "trace.h" /* debug PCI */
@@ -32,6 +34,32 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)#define PCI_DPRINTF (fmt, ...)#endif +Range pci_host_get_buses_range (PCIHostState *host) +{ +uint8_t root_bus_num =pci_bus_num (host->bus); +Range r = {root_bus_num, root_bus_num}; +int i; + +for (i =0 ; i <ARRAY_SIZE (host->bus->devices); ++i) { +PCIDevice *dev = host->bus->devices[i]; +PCIDeviceClass *pc; + +if (!dev) { +continue ; + } + + pc =PCI_DEVICE_GET_CLASS (dev); + +if (pc->is_bridge) { +uint8_t subordinate = dev->config[PCI_SUBORDINATE_BUS ]; +if (subordinate > r.end) { + r.end = subordinate; + } + } + } + +return r; +}/* * PCI address * bit 16 - 24: bus number
include/hw/i386/pc.h +6 -0
@@ -241,6 +241,12 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, MemoryRegion *ram_memory);PCIBus *find_i440fx (void ); +/* +* Register hosts without their own configuration registers +* to i440fx main PCI host bridge +*/ +int i440fx_register_snooping_host (PCIHostState *host); +/* piix4.c */ extern PCIDevice *piix4_dev;int piix4_init (PCIBus *bus,ISABus **isa_bus,int devfn);
include/hw/pci/pci_host.h +3 -0
@@ -87,6 +87,9 @@ typedef struct PCIHostBridgeSnoopedClass {GPtrArray *(*snooping_hosts)(PCIHostState *); } PCIHostBridgeSnoopedClass; +/* Returns the buses interval owned by the input host */ +Range pci_host_get_buses_range (PCIHostState *host); +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len);
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 14/26] hw/pci-host/piix: implement TYPE_PCI_HOST_BRIDGE_SNOOPED interface
Quoted 46 lines · Marcel Apfelbaum
The PIIX holds a list of snooping host bridges that is populated by a registration function that shall be used by any host bridge that needs to use PIIX configuration space to complete their configuration cycles.
PIIX monitors acceses to configuration registers and passes them to the corresponding host bridge if the input bus number is in its bus range.
Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/pci-host/piix.c | 118 +++++++++++++++++++++++++++++++++++++++++++++- hw/pci/pci_host.c | 28 +++++++++++ include/hw/i386/pc.h | 6 +++ include/hw/pci/pci_host.h | 3 ++ 4 files changed, 154 insertions(+), 1 deletion(-)hw/pci-host/piix.c +14
-0@@ -50,6 +50,12 @@ typedef struct I440FXState {PcPciInfo pci_info;uint64_t pci_hole64_size;uint32_t short_root_bus; + +/* +* List of PCI host bridges listening to +* the same configuration registers. +*/ +GPtrArray *snooping_hosts; } I440FXState;#define PIIX_NUM_PIC_IRQS 16/* i8259 * 2 */ @@ -255,14 +261,80 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v,visit_type_uint64 (v, &w64.end, name, errp); } +static PCIBus *i440fx_find_target_bus (I440FXState *i440fx,uint8_t bus_num) +{ +PCIHostState *host =PCI_HOST_BRIDGE (i440fx); +PCIBus *target_bus =NULL ; + +if (bus_num ==pci_bus_num (host->bus)) { + target_bus = host->bus; + }else {
hw/pci-host/piix.c static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v, · line 281
Quoted 10 lines
hw/pci-host/piix.c +10
-0+int i; + +for (i =0 ; i < i440fx->snooping_hosts->len; i++) { +PCIHostState *s_host =g_ptr_array_index (i440fx->snooping_hosts, i); +Range r =pci_host_get_buses_range (s_host); + +if (r.begin <= bus_num && r.end >= bus_num) { + target_bus = s_host->bus; + } +
extra empty line
Quoted 36 lines
hw/pci-host/piix.c +36
-0+ } + } + +return target_bus; +} + +static void i440fx_pcihost_data_write (void *opaque,hwaddr addr, +uint64_t val,unsigned len) +{ +uint32_t config_reg =PCI_HOST_BRIDGE (opaque)->config_reg; + +if (config_reg & (1u <<31 )) { +uint8_t bus_num = (config_reg >>16 ) &0xFF ; +I440FXState *i440fx =I440FX_PCI_HOST_BRIDGE (opaque); +PCIBus *target_bus =i440fx_find_target_bus (i440fx, bus_num); + +if (target_bus) { +pci_data_write (target_bus, config_reg | (addr &3 ), val, len); + } + } +} + +static uint64_t i440fx_pcihost_data_read (void *opaque, +hwaddr addr,unsigned len) +{ +uint32_t config_reg =PCI_HOST_BRIDGE (opaque)->config_reg; + +if (config_reg & (1U <<31 )) { +int bus_num = (config_reg >>16 ) &0xFF ; +I440FXState *i440fx =I440FX_PCI_HOST_BRIDGE (opaque); +PCIBus *target_bus =i440fx_find_target_bus (i440fx, bus_num); + +if (target_bus) { +return pci_data_read (target_bus, config_reg | (addr &3 ), len); + } + }
hw/pci-host/piix.c static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v, · line 327
Quoted 10 lines
hw/pci-host/piix.c +10
-0+ +return 0xffffffff ; +} + +const MemoryRegionOps i440fx_pcihost_data_le_ops = { + .read = i440fx_pcihost_data_read, + .write = i440fx_pcihost_data_write, + .endianness =DEVICE_LITTLE_ENDIAN , +}; +
Can't you just add pxb as a child bus?
If you do, pci_find_bus_nr will do the right thing more or less automatically, no?
Quoted 105 lines
hw/pci-host/piix.c +47
-1static void i440fx_pcihost_initfn (Object *obj) {PCIHostState *s =PCI_HOST_BRIDGE (obj);I440FXState *d =I440FX_PCI_HOST_BRIDGE (obj); + d->snooping_hosts =g_ptr_array_new (); +memory_region_init_io (&s->conf_mem, obj, &pci_host_conf_le_ops, s,"pci-conf-idx" ,4 ); -memory_region_init_io (&s->data_mem, obj, &pci_host_data_le_ops, s, +memory_region_init_io (&s->data_mem, obj, &i440fx_pcihost_data_le_ops, s,"pci-conf-data" ,4 ); object_property_add(obj, PCI_HOST_PROP_PCI_HOLE_START, "int",@@ -400,6 +472,40 @@ PCIBus *find_i440fx(void)return s ? s->bus :NULL ; } +/* +* Returns 0 on successs, -1 if i440fx host was not +* found or the bus number is already in use. +*/ +int i440fx_register_snooping_host (PCIHostState *host) +{ +I440FXState *s =OBJECT_CHECK (I440FXState, +object_resolve_path ("/machine/i440fx" ,NULL ), +TYPE_I440FX_PCI_HOST_BRIDGE ); +uint8_t bus_num =pci_bus_num (host->bus); +int i; + +/* i440fx host not found */ +if (!s) { +return -1 ; + } + +/* 0 is reserved for i440fx host bridge */ +if (bus_num ==0 ) { +return -1 ; + } + +/* check if the bus number is unique */ +for (i =0 ; i < s->snooping_hosts->len; i++) { +PCIHostState *s_host =g_ptr_array_index (s->snooping_hosts, i); +if (bus_num ==pci_bus_num (s_host->bus)) { +return -1 ; + } + } + +g_ptr_array_add (s->snooping_hosts, host); +return 0 ; +} +/* PIIX3 PCI to ISA bridge */ static void piix3_set_irq_pic (PIIX3State *piix3,int pic_irq) {@@ -742,6 +848,13 @@ static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,return "0000:00" ; } +static GPtrArray *i440fx_snooping_hosts (PCIHostState *host_bridge) +{ +I440FXState *s =I440FX_PCI_HOST_BRIDGE (host_bridge); + +return s->snooping_hosts; +} +static Property i440fx_props[] = {DEFINE_PROP_SIZE (PCI_HOST_PROP_PCI_HOLE64_SIZE , I440FXState, pci_hole64_size,DEFAULT_PCI_HOLE64_SIZE ),@@ -753,11 +866,13 @@ static void i440fx_pcihost_class_init(ObjectClass *klass, void *data) {DeviceClass *dc =DEVICE_CLASS (klass);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass); +PCIHostBridgeSnoopedClass *sc =TYPE_PCI_HOST_BRIDGE_SNOOPED_CLASS (klass); hc->root_bus_path = i440fx_pcihost_root_bus_path; dc->realize = i440fx_pcihost_realize; dc->fw_name ="pci" ; dc->props = i440fx_props; + sc->snooping_hosts = i440fx_snooping_hosts; }static const TypeInfo i440fx_pcihost_info = {@@ -768,6 +883,7 @@ static const TypeInfo i440fx_pcihost_info = { .class_init = i440fx_pcihost_class_init, .interfaces = (InterfaceInfo []) { {TYPE_PCI_MAIN_HOST_BRIDGE }, + {TYPE_PCI_HOST_BRIDGE_SNOOPED }, { } }hw/pci/pci_host.c +2
-0@@ -20,6 +20,8 @@#include "hw/pci/pci.h" #include "hw/pci/pci_host.h" +#include "hw/pci/pci_bus.h" +#include "qemu/range.h" #include "trace.h" /* debug PCI */
hw/pci/pci_host.c do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0) · line 37
Quoted 4 lines
hw/pci/pci_host.c +1
-0@@ -32,6 +34,32 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)#define PCI_DPRINTF (fmt, ...)#endif +Range pci_host_get_buses_range (PCIHostState *host)
new api, needs documentation.
Quoted 61 lines
hw/pci/pci_host.c +25
-0+{ +uint8_t root_bus_num =pci_bus_num (host->bus); +Range r = {root_bus_num, root_bus_num}; +int i; + +for (i =0 ; i <ARRAY_SIZE (host->bus->devices); ++i) { +PCIDevice *dev = host->bus->devices[i]; +PCIDeviceClass *pc; + +if (!dev) { +continue ; + } + + pc =PCI_DEVICE_GET_CLASS (dev); + +if (pc->is_bridge) { +uint8_t subordinate = dev->config[PCI_SUBORDINATE_BUS ]; +if (subordinate > r.end) { + r.end = subordinate; + } + } + } + +return r; +}/* * PCI address * bit 16 - 24: bus number include/hw/i386/pc.h +6
-0@@ -241,6 +241,12 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, MemoryRegion *ram_memory);PCIBus *find_i440fx (void ); +/* +* Register hosts without their own configuration registers +* to i440fx main PCI host bridge +*/ +int i440fx_register_snooping_host (PCIHostState *host); +/* piix4.c */ extern PCIDevice *piix4_dev;int piix4_init (PCIBus *bus,ISABus **isa_bus,int devfn);include/hw/pci/pci_host.h +3
-0@@ -87,6 +87,9 @@ typedef struct PCIHostBridgeSnoopedClass {GPtrArray *(*snooping_hosts)(PCIHostState *); } PCIHostBridgeSnoopedClass; +/* Returns the buses interval owned by the input host */ +Range pci_host_get_buses_range (PCIHostState *host); +/* common internal helpers for PCI/PCIe hosts, cut off overflows */ void pci_host_config_write_common (PCIDevice *pci_dev,uint32_t addr,uint32_t limit,uint32_t val,uint32_t len);Signature · 1 line
2.1.0
PATCH v6 15/26 hw/acpi: add support for i440fx 'snooping' root busses
In reply to Marcel ApfelbaumIf the machine has extra root busses that are snooping to the i440fx host bridge, we need to add them to acpi in order to be properly detected by guests.
--- hw/i386/acpi-build.c | 30 ++++++++++++++++++++++++++++-- hw/pci-host/piix.c | 4 ++-- include/hw/i386/pc.h | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-)
hw/i386/acpi-build.c +28 -2
@@ -60,6 +60,8 @@#include "qom/qom-qobject.h" #include "exec/ram_addr.h" +#include "qmp-commands.h" +/* These are used to size the ACPI tables for -M pc-i440fx-1.7 and * -M pc-i440fx-2.0. Even if the actual amount of AML generated grows * a little bit, there should be plenty of free space since the DSDT
@@ -491,10 +493,11 @@ static void *acpi_set_bsel(PCIBus *bus, void *opaque)static void acpi_set_pci_info (void ) { -PCIBus *bus =find_i440fx ();/* TODO: Q35 support */ +PCIHostState *host =find_i440fx ();unsigned bsel_alloc =0 ; -if (bus) { +if (host) { +PCIBus *bus = host->bus;/* TODO: Q35 support */ /* Scan all PCI buses. Set property to enable acpi based hotplug. */ pci_for_each_bus_depth_first (bus, acpi_set_bsel,NULL , &bsel_alloc); }
@@ -660,6 +663,7 @@ build_ssdt(GArray *table_data, GArray *linker,uint32_t nr_mem = machine->ram_slots;unsigned acpi_cpus = guest_info->apic_id_limit;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx; +PCIHostState *snooped_host;int i; ssdt =init_aml_allocator ();
@@ -671,6 +675,28 @@ build_ssdt(GArray *table_data, GArray *linker,/* Reserve space for header */ acpi_data_push (ssdt->buf,sizeof (AcpiTableHeader)); +/* Snooping mechanism is implemented only for i440fx */ + snooped_host =find_i440fx (); +if (snooped_host) { +PCIHostBridgeSnoopedClass *snooped_class = +PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (snooped_host); +GPtrArray *snooping_hosts = snooped_class->snooping_hosts (snooped_host); + +for (i =0 ; i < snooping_hosts->len; i++) { +PCIHostState *host =g_ptr_array_index (snooping_hosts, i); +uint8_t bus_num =pci_bus_num (host->bus); + + scope =aml_scope ("\\_SB" ); + dev =aml_device ("PC%.02X" , bus_num); +aml_append (dev, +aml_name_decl ("_UID" ,aml_string ("PC%.02X" , bus_num))); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A03" ))); +aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num))); +aml_append (scope, dev); +aml_append (ssdt, scope); + } + } + scope =aml_scope ("\\_SB.PCI0" );/* build PCI0._CRS */ crs =aml_resource_template ();
hw/pci-host/piix.c +2 -2
@@ -464,12 +464,12 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,return b; } -PCIBus *find_i440fx (void ) +PCIHostState *find_i440fx (void ) {PCIHostState *s =OBJECT_CHECK (PCIHostState,object_resolve_path ("/machine/i440fx" ,NULL ),TYPE_PCI_HOST_BRIDGE ); -return s ? s->bus :NULL ; +return s; }/*
include/hw/i386/pc.h +1 -1
@@ -240,7 +240,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, MemoryRegion *pci_memory, MemoryRegion *ram_memory); -PCIBus *find_i440fx (void ); +PCIHostState *find_i440fx (void );/* * Register hosts without their own configuration registers * to i440fx main PCI host bridge
Signature · 1 line
2.1.0
PATCH v6 16/26 hw/apci: add _PRT method for extra PCI root busses
In reply to Marcel Apfelbaum--- hw/i386/acpi-build.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
hw/i386/acpi-build.c +81 -0
@@ -654,6 +654,86 @@ static void build_append_pci_bus_devices(Aml *parent_scope, PCIBus *bus,aml_append (parent_scope, method); } +/* +* initialize_route - Initialize the interrupt routing rule +* through a specific LINK: +* if (lnk_idx == idx) +* route using link 'link_name' +*/ +static Aml *initialize_route (Aml *route,const char *link_name, +Aml *lnk_idx,int idx) +{ +Aml *if_ctx =aml_if (aml_equal (lnk_idx,aml_int (idx))); +Aml *pkg =aml_package (4 ); + +aml_append (pkg,aml_int (0 )); +aml_append (pkg,aml_int (0 )); +aml_append (pkg,aml_name ("%s" , link_name)); +aml_append (pkg,aml_int (0 )); +aml_append (if_ctx,aml_store (pkg, route)); + +return if_ctx; +} + +/* +* build_prt - Define interrupt rounting rules +* +* Returns an array of 128 routes, one for each device, +* based on device location. +* The main goal is to equaly distribute the interrupts +* over the 4 existing ACPI links (works only for i440fx). +* The hash function is (slot + pin) & 3 -> "LNK[D|A|B|C]". +* +*/ +static Aml *build_prt (void ) +{ +Aml *method, *while_ctx, *pin, *res; + + method =aml_method ("_PRT" ,0 ); + res =aml_local (0 ); + pin =aml_local (1 ); +aml_append (method,aml_store (aml_package (128 ), res)); +aml_append (method,aml_store (aml_int (0 ), pin)); + +/* while (pin < 128) */ + while_ctx =aml_while (aml_lless (pin,aml_int (128 ))); + { +Aml *slot =aml_local (2 ); +Aml *lnk_idx =aml_local (3 ); +Aml *route =aml_local (4 ); + +/* slot = pin >> 2 */ +aml_append (while_ctx, +aml_store (aml_shiftright (pin,aml_int (2 )), slot)); +/* lnk_idx = (slot + pin) & 3 */ +aml_append (while_ctx, +aml_store (aml_and (aml_add (pin, slot),aml_int (3 )), lnk_idx)); + +/* route[2] = "LNK[D|A|B|C]", selection based on pin % 3 */ +aml_append (while_ctx,initialize_route (route,"LNKD" , lnk_idx,0 )); +aml_append (while_ctx,initialize_route (route,"LNKA" , lnk_idx,1 )); +aml_append (while_ctx,initialize_route (route,"LNKB" , lnk_idx,2 )); +aml_append (while_ctx,initialize_route (route,"LNKC" , lnk_idx,3 )); + +/* route[0] = 0x[slot]FFFF */ +aml_append (while_ctx, +aml_store (aml_or (aml_shiftleft (slot,aml_int (16 )),aml_int (0xFFFF )), +aml_index (route,aml_int (0 )))); +/* route[1] = pin & 3 */ +aml_append (while_ctx, +aml_store (aml_and (pin,aml_int (3 )),aml_index (route,aml_int (1 )))); +/* res[pin] = route */ +aml_append (while_ctx,aml_store (route,aml_index (res, pin))); +/* pin++ */ +aml_append (while_ctx,aml_increment (pin)); + } +aml_append (method, while_ctx); +/* return res*/ +aml_append (method,aml_return (res)); + +return method; +} + static void build_ssdt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -692,6 +772,7 @@ build_ssdt(GArray *table_data, GArray *linker, aml_name_decl("_UID", aml_string("PC%.02X", bus_num)));aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A03" )));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num))); +aml_append (dev,build_prt ());aml_append (scope, dev);aml_append (ssdt, scope); }
Signature · 1 line
2.1.0
PATCH v6 17/26 hw/acpi: add _CRS method for extra root busses
In reply to Marcel ApfelbaumSave the IO/mem/bus numbers ranges assigned to the extra root busses to be removed from the root bus 0 range.
--- hw/i386/acpi-build.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+)
hw/i386/acpi-build.c +138 -0
@@ -734,6 +734,137 @@ static Aml *build_prt(void)return method; } +typedef struct CrsRangeEntry { +uint64_t base; +uint64_t limit; +}CrsRangeEntry ; + +static void crs_range_insert (GPtrArray *ranges,uint64_t base,uint64_t limit) +{ +CrsRangeEntry *entry; + + entry =g_malloc (sizeof (*entry)); + entry->base = base; + entry->limit = limit; + +g_ptr_array_add (ranges, entry); +} + +static void crs_range_free (gpointer data) +{ +CrsRangeEntry *entry = (CrsRangeEntry *)data; +g_free (entry); +} + +static Aml *build_crs (PCIHostState *host, +GPtrArray *io_ranges,GPtrArray *mem_ranges) +{ +Aml *crs =aml_resource_template (); +uint8_t max_bus =pci_bus_num (host->bus); +uint8_t type; +int devfn; + +for (devfn =0 ; devfn <ARRAY_SIZE (host->bus->devices); devfn++) { +int i; +uint64_t range_base, range_limit; +PCIDevice *dev = host->bus->devices[devfn]; + +if (!dev) { +continue ; + } + +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { +PCIIORegion *r = &dev->io_regions[i]; + + range_base = r->addr; + range_limit = r->addr + r->size -1 ; + +if (r->type &PCI_BASE_ADDRESS_SPACE_IO ) { +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (io_ranges, range_base, range_limit); + }else {/* "memory" */ +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, + aml_max_fixed, aml_non_cacheable, + aml_ReadWrite, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (mem_ranges, range_base, range_limit); + } + } + + type = dev->config[PCI_HEADER_TYPE ] & ~PCI_HEADER_TYPE_MULTI_FUNCTION ; +if (type ==PCI_HEADER_TYPE_BRIDGE ) { +uint8_t subordinate = dev->config[PCI_SUBORDINATE_BUS ]; +if (subordinate > max_bus) { + max_bus = subordinate; + } + + range_base =pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_IO ); + range_limit =pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_IO ); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (io_ranges, range_base, range_limit); + + range_base = +pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); + range_limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, + aml_max_fixed, aml_non_cacheable, + aml_ReadWrite, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (mem_ranges, range_base, range_limit); + + range_base = +pci_bridge_get_base (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); + range_limit = +pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, + aml_max_fixed, aml_non_cacheable, + aml_ReadWrite, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (mem_ranges, range_base, range_limit); + } + } + +aml_append (crs, +aml_word_bus_number (aml_min_fixed, aml_max_fixed, aml_pos_decode, +0 , +pci_bus_num (host->bus), + max_bus, +0 , + max_bus -pci_bus_num (host->bus) +1 )); + +return crs; +} + static void build_ssdt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -744,6 +875,8 @@ build_ssdt(GArray *table_data, GArray *linker,unsigned acpi_cpus = guest_info->apic_id_limit;Aml *ssdt, *sb_scope, *scope, *pkg, *dev, *method, *crs, *field, *ifctx;PCIHostState *snooped_host; +GPtrArray *io_ranges =g_ptr_array_new_with_free_func (crs_range_free); +GPtrArray *mem_ranges =g_ptr_array_new_with_free_func (crs_range_free);int i; ssdt =init_aml_allocator ();
@@ -773,9 +906,14 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A03" )));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num)));aml_append (dev,build_prt ()); + crs =build_crs (host, io_ranges, mem_ranges); +aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev);aml_append (ssdt, scope); } + +g_ptr_array_free (io_ranges, true); +g_ptr_array_free (mem_ranges, true); } scope =aml_scope ("\\_SB.PCI0" );
Signature · 1 line
2.1.0
PATCH v6 18/26 hw/acpi: remove from root bus 0 the crs resources used by other busses.
In reply to Marcel ApfelbaumIf multiple root busses are used, root bus 0 cannot use all the pci holes ranges. Remove the IO/mem ranges used by the other primary busses.
--- hw/i386/acpi-build.c | 90 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 13 deletions(-)
hw/i386/acpi-build.c +77 -13
@@ -756,6 +756,50 @@ static void crs_range_free(gpointer data)g_free (entry); } +static gint crs_range_compare (gconstpointer a,gconstpointer b) +{ +CrsRangeEntry *entry_a = *(CrsRangeEntry **)a; +CrsRangeEntry *entry_b = *(CrsRangeEntry **)b; + +return (int64_t )entry_a->base - (int64_t )entry_b->base; +} + +/* +* crs_replace_with_free_ranges - given the 'used' ranges within [start - end] +* interval, computes the 'free' ranges from the same interval. +* Example: If the input array is { [a1 - a2],[b1 - b2] }, the function +* will return { [base - a1], [a2 - b1], [b2 - limit] }. +*/ +static void crs_replace_with_free_ranges (GPtrArray *ranges, +uint64_t start,uint64_t end) +{ +GPtrArray *free_ranges =g_ptr_array_new_with_free_func (crs_range_free); +uint64_t free_base = start; +int i; + +g_ptr_array_sort (ranges, crs_range_compare); +for (i =0 ; i < ranges->len; i++) { +CrsRangeEntry *used =g_ptr_array_index (ranges, i); + +if (free_base < used->base) { +crs_range_insert (free_ranges, free_base, used->base -1 ); + } + + free_base = used->limit +1 ; + } + +if (free_base < end) { +crs_range_insert (free_ranges, free_base, end); + } + +g_ptr_array_set_size (ranges,0 ); +for (i =0 ; i < free_ranges->len; i++) { +g_ptr_array_add (ranges,g_ptr_array_index (free_ranges, i)); + } + +g_ptr_array_free (free_ranges, false); +} +static Aml *build_crs (PCIHostState *host,GPtrArray *io_ranges,GPtrArray *mem_ranges) {
@@ -877,6 +921,8 @@ build_ssdt(GArray *table_data, GArray *linker,PCIHostState *snooped_host;GPtrArray *io_ranges =g_ptr_array_new_with_free_func (crs_range_free);GPtrArray *mem_ranges =g_ptr_array_new_with_free_func (crs_range_free); +CrsRangeEntry *entry; +int root_bus_limit =0xFF ;int i; ssdt =init_aml_allocator ();
@@ -899,6 +945,10 @@ build_ssdt(GArray *table_data, GArray *linker,PCIHostState *host =g_ptr_array_index (snooping_hosts, i);uint8_t bus_num =pci_bus_num (host->bus); +if (bus_num < root_bus_limit) { + root_bus_limit = bus_num -1 ; + } + scope =aml_scope ("\\_SB" ); dev =aml_device ("PC%.02X" , bus_num); aml_append(dev,
@@ -911,9 +961,6 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (scope, dev);aml_append (ssdt, scope); } - -g_ptr_array_free (io_ranges, true); -g_ptr_array_free (mem_ranges, true); } scope =aml_scope ("\\_SB.PCI0" );
@@ -921,26 +968,40 @@ build_ssdt(GArray *table_data, GArray *linker, crs =aml_resource_template ();aml_append (crs,aml_word_bus_number (aml_min_fixed, aml_max_fixed, aml_pos_decode, -0x0000 ,0x0000 ,0x00FF ,0x0000 ,0x0100 )); +0x0000 ,0x0 , root_bus_limit, +0x0000 , root_bus_limit +1 ));aml_append (crs,aml_io (aml_decode16,0x0CF8 ,0x0CF8 ,0x01 ,0x08 ));aml_append (crs,aml_word_io (aml_min_fixed, aml_max_fixed, aml_pos_decode, aml_entire_range,0x0000 ,0x0000 ,0x0CF7 ,0x0000 ,0x0CF8 )); -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0x0000 ,0x0D00 ,0xFFFF ,0x0000 ,0xF300 )); + +crs_replace_with_free_ranges (io_ranges,0x0D00 ,0xFFFF ); +for (i =0 ; i < io_ranges->len; i++) { + entry =g_ptr_array_index (io_ranges, i); +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0x0000 , entry->base, entry->limit, +0x0000 , entry->limit - entry->base +1 )); + } +aml_append (crs,aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, aml_cacheable, aml_ReadWrite,0 ,0x000A0000 ,0x000BFFFF ,0 ,0x00020000 )); -aml_append (crs, -aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, - aml_non_cacheable, aml_ReadWrite, -0 , pci->w32.begin, pci->w32.end -1 ,0 , - pci->w32.end - pci->w32.begin)); + +crs_replace_with_free_ranges (mem_ranges, pci->w32.begin, pci->w32.end -1 ); +for (i =0 ; i < mem_ranges->len; i++) { + entry =g_ptr_array_index (mem_ranges, i); +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, aml_max_fixed, + aml_non_cacheable, aml_ReadWrite, +0 , entry->base, entry->limit, +0 , entry->limit - entry->base +1 )); + } +if (pci->w64.begin) { aml_append(crs, aml_qword_memory(aml_pos_decode, aml_min_fixed, aml_max_fixed,
@@ -963,6 +1024,9 @@ build_ssdt(GArray *table_data, GArray *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev); +g_ptr_array_free (io_ranges, true); +g_ptr_array_free (mem_ranges, true); +/* reserve PCIHP resources */ if (pm->pcihp_io_len) { dev =aml_device ("PHPR" );
Signature · 1 line
2.1.0
PATCH v6 19/26 hw/pci: removed 'rootbus nr is 0' assumption from qmp_pci_query
In reply to Marcel ApfelbaumFrom: Marcel Apfelbaum <[email protected]>
Use the newer pci_bus_num to correctly get the root bus number.
--- hw/pci/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/pci/pci.c +2 -1
@@ -1266,7 +1266,8 @@ PciInfoList *qmp_query_pci(Error **errp) QLIST_FOREACH(host_bridge, &pci_host_bridges, next) { info =g_malloc0 (sizeof (*info)); - info->value =qmp_query_pci_bus (host_bridge->bus,0 ); + info->value =qmp_query_pci_bus (host_bridge->bus, +pci_bus_num (host_bridge->bus));/* XXX: waiting for the qapi to support GSList */ if (!cur_item) {
Signature · 1 line
2.1.0
PATCH v6 20/26 hw/pci: introduce PCI Expander Bridge (PXB)
In reply to Marcel ApfelbaumFrom: Marcel Apfelbaum <[email protected]>
PXB is a "light-weight" host bridge whose purpose is to enable the main host bridge to support multiple PCI root buses for pc machines.
As oposed to PCI-2-PCI bridge's secondary bus, PXB's bus is a primary bus and can be associated with a NUMA node (different from the main host bridge) allowing the guest OS to recognize the proximity of a pass-through device to other resources as RAM and CPUs.
The PXB is composed from:
- A primary PCI bus (can be associated with a NUMA node) Acts like a normal pci bus and from the functionality point of view is an "expansion" of the bus behind the
main host bridge.
- A pci-2-pci bridge behind the primary PCI bus where the actual devices will be attached.
- A host-bridge PCI device
Situated on the bus behind the main host bridge, allows the BIOS to configure the bus number and IO/mem resources. It does not have its own config/data register for configuration cycles, this being handled by the main host bridge.
- A host-bridge sysbus to comply with QEMU current design.
--- hw/pci-bridge/Makefile.objs | 1 + hw/pci-bridge/pci_expander_bridge.c | 171 ++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + 3 files changed, 173 insertions(+) create mode 100644 hw/pci-bridge/pci_expander_bridge.c
hw/pci-bridge/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ common-obj-y += pci_bridge_dev.o +common-obj-y += pci_expander_bridge.o common-obj-$(CONFIG_XIO3130) += xio3130_upstream.o xio3130_downstream.o common-obj-$(CONFIG_IOH3420) += ioh3420.o common-obj-$(CONFIG_I82801B11) += i82801b11.o
hw/pci-bridge/pci_expander_bridge.c new file +171 -0
171 lines not on this page · raw message
include/hw/pci/pci.h +1 -0
@@ -90,6 +90,7 @@#define PCI_DEVICE_ID_REDHAT_TEST 0x0005#define PCI_DEVICE_ID_REDHAT_SDHCI 0x0007#define PCI_DEVICE_ID_REDHAT_PCIE_HOST 0x0008 +#define PCI_DEVICE_ID_REDHAT_PXB 0x0009#define PCI_DEVICE_ID_REDHAT_QXL 0x0100#define FMT_PCIBUS PRIx64
Signature · 1 line
2.1.0
PATCH v6 21/26 hw/pci: inform bios if the system has extra pci root buses
In reply to Marcel ApfelbaumFrom: Marcel Apfelbaum <[email protected]>
The bios looks for 'etc/extra-pci-roots' to decide if is going to scan further buses after bus 0 tree.
--- hw/i386/pc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/i386/pc.c +13 -0
@@ -1076,6 +1076,19 @@ void pc_guest_info_machine_done(Notifier *notifier, void *data)PcGuestInfoState *guest_info_state =container_of (notifier, PcGuestInfoState, machine_done); +PCIHostState *snooped_host =find_i440fx (); +PCIHostBridgeSnoopedClass *snooped_class = +PCI_HOST_BRIDGE_SNOOPED_GET_CLASS (snooped_host); +GPtrArray *snooping_hosts = snooped_class->snooping_hosts (snooped_host); +int extra_hosts = snooping_hosts->len; + +if (extra_hosts && guest_info_state->info.fw_cfg) { +uint64_t *val =g_malloc (sizeof (*val)); + *val =cpu_to_le64 (extra_hosts); +fw_cfg_add_file (guest_info_state->info.fw_cfg, +"etc/extra-pci-roots" , val,sizeof (*val)); + } +acpi_setup (&guest_info_state->info); }
Signature · 1 line
2.1.0
PATCH v6 22/26 hw/pxb: add map_irq func
In reply to Marcel ApfelbaumThe bios does not index the pxb slot number when it computes the IRQ because it resides on bus 0 and not on the current bus.
However Qemu routes the irq through bus 0 and adds the pxb slot to the IRQ computation of the PXB device.
Synchronize between bios and Qemu by canceling pxb's effect.
--- hw/pci-bridge/pci_expander_bridge.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
hw/pci-bridge/pci_expander_bridge.c +20 -1
@@ -93,6 +93,25 @@ static const TypeInfo pxb_host_info = { .class_init = pxb_host_class_init, }; + +static int pxb_map_irq_fn (PCIDevice *pci_dev,int pin) +{ +PCIDevice *pxb = pci_dev->bus->parent_dev; + +/* +* The bios does not index the pxb slot number when +* it computes the IRQ because it resides on bus 0 +* and not on the current bus. +* However QEMU routes the irq through bus 0 and adds +* the pxb slot to the IRQ computation of the PXB +* device. +* +* Synchronize between bios and QEMU by canceling +* pxb's effect. +*/ +return pin -PCI_SLOT (pxb->devfn); +} +static int pxb_dev_initfn (PCIDevice *dev) {PXBDev *pxb =PXB_DEV (dev);
@@ -110,7 +129,7 @@ static int pxb_dev_initfn(PCIDevice *dev) bus->parent_dev = dev; bus->address_space_mem = dev->bus->address_space_mem; bus->address_space_io = dev->bus->address_space_io; - bus->map_irq = pci_swizzle_map_irq_fn; + bus->map_irq = pxb_map_irq_fn; bds =qdev_create (BUS (bus),"pci-bridge" ); bds->id = dev_name;
Signature · 1 line
2.1.0
PATCH v6 23/26 hw/pci_bus: add support for NUMA nodes
In reply to Marcel ApfelbaumPCI root buses can be attached to a specific NUMA node. PCI buses are not attached be default to a NUMA node.
--- hw/pci/pci_bus.c | 7 +++++++ include/hw/pci/pci_bus.h | 6 ++++++ include/sysemu/sysemu.h | 1 + 3 files changed, 14 insertions(+)
hw/pci/pci_bus.c +7 -0
@@ -13,6 +13,7 @@#include "hw/pci/pci_bus.h" #include "hw/pci/pci_bridge.h" #include "monitor/monitor.h" +#include "sysemu/sysemu.h" typedef struct { uint16_t class;
@@ -478,6 +479,11 @@ static int pcibus_num(PCIBus *bus)return bus->parent_dev->config[PCI_SECONDARY_BUS ]; } +static uint16_t pcibus_numa_node (PCIBus *bus) +{ +return NUMA_NODE_UNASSIGNED ; +} +static void pci_bus_class_init (ObjectClass *klass,void *data) {BusClass *k =BUS_CLASS (klass);
@@ -492,6 +498,7 @@ static void pci_bus_class_init(ObjectClass *klass, void *data) pbc->is_root = pcibus_is_root; pbc->bus_num = pcibus_num; + pbc->numa_node = pcibus_numa_node; }static const TypeInfo pci_bus_info = {
include/hw/pci/pci_bus.h +6 -0
@@ -25,6 +25,7 @@ typedef struct PCIBusClass {bool (*is_root)(PCIBus *bus);int (*bus_num)(PCIBus *bus); +uint16_t (*numa_node)(PCIBus *bus); } PCIBusClass;struct PCIBus {
@@ -60,6 +61,11 @@ static inline int pci_bus_num(PCIBus *bus)return PCI_BUS_GET_CLASS (bus)->bus_num (bus); } +static inline int pci_bus_numa_node (PCIBus *bus) +{ +return PCI_BUS_GET_CLASS (bus)->numa_node (bus); +} +typedef struct PCIBridgeWindows PCIBridgeWindows ;/*
include/sysemu/sysemu.h +1 -0
@@ -136,6 +136,7 @@ extern const char *mem_path;extern int mem_prealloc;#define MAX_NODES 128 +#define NUMA_NODE_UNASSIGNED MAX_NODES/* The following shall be true for all CPUs: * cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS
Signature · 1 line
2.1.0
PATCH v6 24/26 hw/pxb: add numa_node parameter
In reply to Marcel ApfelbaumThe pxb can be attach to and existing numa node by specifying numa_node option that equals the desired numa nodeid.
--- hw/i386/acpi-build.c | 6 ++++++ hw/pci-bridge/pci_expander_bridge.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+)
hw/i386/acpi-build.c +6 -0
@@ -944,6 +944,7 @@ build_ssdt(GArray *table_data, GArray *linker,for (i =0 ; i < snooping_hosts->len; i++) {PCIHostState *host =g_ptr_array_index (snooping_hosts, i);uint8_t bus_num =pci_bus_num (host->bus); +uint8_t numa_node =pci_bus_numa_node (host->bus);if (bus_num < root_bus_limit) { root_bus_limit = bus_num -1 ;
@@ -955,6 +956,11 @@ build_ssdt(GArray *table_data, GArray *linker, aml_name_decl("_UID", aml_string("PC%.02X", bus_num)));aml_append (dev,aml_name_decl ("_HID" ,aml_string ("PNP0A03" )));aml_append (dev,aml_name_decl ("_BBN" ,aml_int (bus_num))); + +if (numa_node !=NUMA_NODE_UNASSIGNED ) { +aml_append (dev,aml_name_decl ("_PXM" ,aml_int (numa_node))); + } +aml_append (dev,build_prt ()); crs =build_crs (host, io_ranges, mem_ranges);aml_append (dev,aml_name_decl ("_CRS" , crs));
hw/pci-bridge/pci_expander_bridge.c +17 -0
@@ -17,6 +17,7 @@#include "hw/i386/pc.h" #include "qemu/range.h" #include "qemu/error-report.h" +#include "sysemu/numa.h" #define TYPE_PXB_BUS "pxb-bus"#define PXB_BUS (obj) OBJECT_CHECK(PXBBus, (obj), TYPE_PXB_BUS)
@@ -38,6 +39,7 @@ typedef struct PXBDev {/*< public >*/ uint8_t bus_nr; +uint16_t numa_node; } PXBDev;#define TYPE_PXB_HOST "pxb-host"
@@ -54,12 +56,20 @@ static bool pxb_is_root(PCIBus *bus)return true;/* by definition */ } +static uint16_t pxb_bus_numa_node (PCIBus *bus) +{ +PXBDev *pxb =PXB_DEV (bus->parent_dev); + +return pxb->numa_node; +} +static void pxb_bus_class_init (ObjectClass *class,void *data) {PCIBusClass *pbc =PCI_BUS_CLASS (class); pbc->bus_num = pxb_bus_num; pbc->is_root = pxb_is_root; + pbc->numa_node = pxb_bus_numa_node; }static const TypeInfo pxb_bus_info = {
@@ -119,6 +129,12 @@ static int pxb_dev_initfn(PCIDevice *dev)PCIBus *bus;const char *dev_name =NULL ; +if (pxb->numa_node !=NUMA_NODE_UNASSIGNED && + pxb->numa_node >= nb_numa_nodes) { +error_report ("Illegal numa node %d." , pxb->numa_node); +return -EINVAL ; + } +if (dev->qdev.id && *dev->qdev.id) { dev_name = dev->qdev.id; }
@@ -156,6 +172,7 @@ static int pxb_dev_initfn(PCIDevice *dev)static Property pxb_dev_properties[] = {/* Note: 0 is not a legal a PXB bus number. */ DEFINE_PROP_UINT8 ("bus_nr" , PXBDev, bus_nr,0 ), +DEFINE_PROP_UINT16 ("numa_node" , PXBDev, numa_node,NUMA_NODE_UNASSIGNED ),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
2.1.0
PATCH v6 25/26 apci: fix PXB behaviour if used with unsupported BIOS
In reply to Marcel ApfelbaumPXB does not work with unsupported bioses, but should not interfere with normal OS operation.
We don't ship them anymore, but it's reasonable to keep the work-around until we update the bios in qemu.
Fix this by not adding PXB mem/IO chunks to _CRS if they weren't configured by BIOS.
--- hw/i386/acpi-build.c | 87 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 29 deletions(-)
hw/i386/acpi-build.c +58 -29
@@ -823,6 +823,14 @@ static Aml *build_crs(PCIHostState *host, range_base = r->addr; range_limit = r->addr + r->size -1 ; +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (!range_base || range_base > range_limit) { +continue ; + } +if (r->type &PCI_BASE_ADDRESS_SPACE_IO ) { aml_append(crs, aml_word_io(aml_min_fixed, aml_max_fixed,
@@ -856,45 +864,66 @@ static Aml *build_crs(PCIHostState *host, range_base =pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_IO ); range_limit =pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_IO ); -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0 , - range_base, - range_limit, -0 , - range_limit - range_base +1 )); -crs_range_insert (io_ranges, range_base, range_limit); + +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (range_base || range_base > range_limit) { +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (io_ranges, range_base, range_limit); + } range_base =pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); range_limit =pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); -aml_append (crs, -aml_dword_memory (aml_pos_decode, aml_min_fixed, - aml_max_fixed, aml_non_cacheable, - aml_ReadWrite, -0 , - range_base, - range_limit, -0 , - range_limit - range_base +1 )); -crs_range_insert (mem_ranges, range_base, range_limit); + +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (range_base || range_base > range_limit) { +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, + aml_max_fixed, aml_non_cacheable, + aml_ReadWrite, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (mem_ranges, range_base, range_limit); + } range_base =pci_bridge_get_base (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); range_limit =pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); -aml_append (crs, -aml_dword_memory (aml_pos_decode, aml_min_fixed, - aml_max_fixed, aml_non_cacheable, - aml_ReadWrite, -0 , - range_base, - range_limit, -0 , - range_limit - range_base +1 )); -crs_range_insert (mem_ranges, range_base, range_limit); + +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (range_base || range_base > range_limit) { +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, + aml_max_fixed, aml_non_cacheable, + aml_ReadWrite, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (mem_ranges, range_base, range_limit); + } } }
Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 25/26] apci: fix PXB behaviour if used with unsupported BIOS
Quoted 4 lines · Marcel Apfelbaum
PXB does not work with unsupported bioses, but should not interfere with normal OS operation.
We don't ship them anymore, but it's reasonable to keep the work-around until we update the bios in qemu.
Can be dropped now we have updated the bios?
Quoted 125 lines
Fix this by not adding PXB mem/IO chunks to
_CRSif they weren't configured by BIOS.Signed-off-by Marcel Apfelbaum <[email protected]>--- hw/i386/acpi-build.c | 87 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 29 deletions(-)hw/i386/acpi-build.c +58
-29@@ -823,6 +823,14 @@ static Aml *build_crs(PCIHostState *host, range_base = r->addr; range_limit = r->addr + r->size -1 ; +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (!range_base || range_base > range_limit) { +continue ; + } +if (r->type &PCI_BASE_ADDRESS_SPACE_IO ) { aml_append(crs, aml_word_io(aml_min_fixed, aml_max_fixed,@@ -856,45 +864,66 @@ static Aml *build_crs(PCIHostState *host, range_base =pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_IO ); range_limit =pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_IO ); -aml_append (crs, -aml_word_io (aml_min_fixed, aml_max_fixed, - aml_pos_decode, aml_entire_range, -0 , - range_base, - range_limit, -0 , - range_limit - range_base +1 )); -crs_range_insert (io_ranges, range_base, range_limit); + +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (range_base || range_base > range_limit) { +aml_append (crs, +aml_word_io (aml_min_fixed, aml_max_fixed, + aml_pos_decode, aml_entire_range, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (io_ranges, range_base, range_limit); + } range_base =pci_bridge_get_base (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); range_limit =pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_SPACE_MEMORY ); -aml_append (crs, -aml_dword_memory (aml_pos_decode, aml_min_fixed, - aml_max_fixed, aml_non_cacheable, - aml_ReadWrite, -0 , - range_base, - range_limit, -0 , - range_limit - range_base +1 )); -crs_range_insert (mem_ranges, range_base, range_limit); + +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (range_base || range_base > range_limit) { +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, + aml_max_fixed, aml_non_cacheable, + aml_ReadWrite, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (mem_ranges, range_base, range_limit); + } range_base =pci_bridge_get_base (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); range_limit =pci_bridge_get_limit (dev,PCI_BASE_ADDRESS_MEM_PREFETCH ); -aml_append (crs, -aml_dword_memory (aml_pos_decode, aml_min_fixed, - aml_max_fixed, aml_non_cacheable, - aml_ReadWrite, -0 , - range_base, - range_limit, -0 , - range_limit - range_base +1 )); -crs_range_insert (mem_ranges, range_base, range_limit); + +/* +* Work-around for old bioses +* that do not support multiple root buses +*/ +if (range_base || range_base > range_limit) { +aml_append (crs, +aml_dword_memory (aml_pos_decode, aml_min_fixed, + aml_max_fixed, aml_non_cacheable, + aml_ReadWrite, +0 , + range_base, + range_limit, +0 , + range_limit - range_base +1 )); +crs_range_insert (mem_ranges, range_base, range_limit); + } } }Signature · 1 line
2.1.0
Re: [Qemu-devel] [PATCH V6 for-2.3 25/26] apci: fix PXB behaviour if used with unsupported BIOS
Quoted 7 lines · Michael S. Tsirkin
Quoted 4 lines · Marcel Apfelbaum
PXB does not work with unsupported bioses, but should not interfere with normal OS operation.
We don't ship them anymore, but it's reasonable to keep the work-around until we update the bios in qemu.Can be dropped now we have updated the bios?
I'd much prefer to keep it for robustness reasons.
cheers,
Gerd
PATCH v6 26/26 docs: Add PXB documentation
In reply to Marcel Apfelbaum--- docs/pci_expander_bridge.txt | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 docs/pci_expander_bridge.txt
docs/pci_expander_bridge.txt new file +52 -0
@@ -0,0 +1,52 @@ +PCI EXPANDER BRIDGE (PXB) +========================= + +Description +=========== +PXB is a "light-weight" host bridge in the same PCI domain +as the main host bridge whose purpose is to enable +the main host bridge to support multiple PCI root buses. +It is implemented only for i440fx. + +As opposed to PCI-2-PCI bridge's secondary bus, PXB's bus +is a primary bus and can be associated with a NUMA node +(different from the main host bridge) allowing the guest OS +to recognize the proximity of a pass-through device to +other resources as RAM and CPUs. + +Usage +===== +A detailed command line would be: + +[qemu-bin + storage options] +-bios [seabios-dir]/out/bios.bin -L [seabios-dir]/out/ +-m 2G +-object memory-backend-ram,size=1024M,policy=bind,host-nodes=0,id=ram-node0 -numa node,nodeid=0,cpus=0,memdev=ram-node0 +-object memory-backend-ram,size=1024M,policy=interleave,host-nodes=0,id=ram-node1 -numa node,nodeid=1,cpus=1,memdev=ram-node1 +-device pxb-device,id=bridge1,bus=pci.0,numa_node=1,bus_nr=4 -netdev user,id=nd-device e1000,bus=bridge1,addr=0x4,netdev=nd +-device pxb-device,id=bridge2,bus=pci.0,numa_node=0,bus_nr=8 -device e1000,bus=bridge2,addr=0x3 +-device pxb-device,id=bridge3,bus=pci.0,bus_nr=40 -drive if=none,id=drive0,file=[img] -device virtio-blk-pci,drive=drive0,scsi=off,bus=bridge3,addr=1 + +Here you have: + - 2 NUMA nodes for the guest, 0 and 1. (both mapped to the same NUMA node in host, but you can and should put it in different host NUMA nodes) + - a pxb host bridge attached to NUMA 1 with an e1000 behind it + - a pxb host bridge attached to NUMA 0 with an e1000 behind it + - a pxb host bridge not attached to any NUMA with a hard drive behind it. + +Implementation +============== +The PXB is composed by: +- HostBridge (TYPE_PXB_HOST) + The host bridge allows to register and query the PXB's rPCI root bus in QEMU. +- PXBDev(TYPE_PXB_DEVICE) + It is a regular PCI Device that resides on the piix host-bridge bus and its bus uses the same PCI domain. + However, the bus behind is exposed through ACPI as a primary PCI bus and starts a new PCI hierarchy. + The interrupts from devices behind the PXB are routed through this device the same as if it were a + PCI-2-PCI bridge. The _PRT follows the i440fx model. +- PCIBridgeDev(TYPE_PCI_BRIDGE_DEV) + Created automatically as part of init sequence. + When adding a device to PXB it is attached to the bridge for two reasons: + - Using the bridge will enable hotplug support + - All the devices behind the bridge will use bridge's IO/MEM windows compacting + the PCI address space. +
Signature · 1 line
2.1.0
Quoted 13 lines · Marcel Apfelbaum
hw/pci-host/piix.c | 128 ++++++++- hw/pci-host/ppce500.c | 1 + hw/pci-host/q35.c | 5 + hw/pci-host/uninorth.c | 1 + hw/pci/Makefile.objs | 2 +- hw/pci/pci.c | 493 +--------------------------------- hw/pci/pci_bus.c | 517 ++++++++++++++++++++++++++++++++++++ hw/pci/pci_host.c | 42 +++ hw/ppc/ppc4xx_pci.c | 1 + hw/scsi/megasas.c | 1 + hw/sh4/r2d.c | 1 + hw/sh4/sh_pci.c | 1 + hw/vfio/pci.c | 1 +
Quoted 8 lines
hw/xen/xen_pt.c | 1 + include/hw/acpi/aml-build.h | 8 + include/hw/i386/pc.h | 8 +- include/hw/pci/pci.h | 6 +- include/hw/pci/pci_bus.h | 35 +++ include/hw/pci/pci_host.h | 34 +++ include/sysemu/sysemu.h | 1 + 32 files changed, 1508 insertions(+), 510 deletions(-)
I think this should not be committed to 2.3 after -rc0.
Paolo
Quoted 25 lines · Paolo Bonzini
Quoted 13 lines · Marcel Apfelbaum
hw/pci-host/piix.c | 128 ++++++++- hw/pci-host/ppce500.c | 1 + hw/pci-host/q35.c | 5 + hw/pci-host/uninorth.c | 1 + hw/pci/Makefile.objs | 2 +- hw/pci/pci.c | 493 +--------------------------------- hw/pci/pci_bus.c | 517 ++++++++++++++++++++++++++++++++++++ hw/pci/pci_host.c | 42 +++ hw/ppc/ppc4xx_pci.c | 1 + hw/scsi/megasas.c | 1 + hw/sh4/r2d.c | 1 + hw/sh4/sh_pci.c | 1 + hw/vfio/pci.c | 1 +Quoted 8 lines
hw/xen/xen_pt.c | 1 + include/hw/acpi/aml-build.h | 8 + include/hw/i386/pc.h | 8 +- include/hw/pci/pci.h | 6 +- include/hw/pci/pci_bus.h | 35 +++ include/hw/pci/pci_host.h | 34 +++ include/sysemu/sysemu.h | 1 + 32 files changed, 1508 insertions(+), 510 deletions(-)
Quoted 1 line
I think this should not be committed to 2.3 after -rc0.
While I agree that looking at the above the series do not
fit for 2.3, I still think the risk is not big because:
- The biggest amount of modifications are in pci_bus/pci_host
and *is only* a movement of code into a new file,
no changes at all (This cover almost half of the series changes)
- The series does not intervene with usual process, meaning if pxb is not used, it will work exactly like before
- The bios already supports pxb for this release, is a pity to wait for another QEMU version.
- The series were in mailing list for more than a month before rc, but the real review process started at rc time.
(begging the question what a non-maintainer must do to get its code in time)
- The series is mature, rebased on the latest QEMU
and was reviewed in depth and tested by the community.
The above being said, I'll agree with whatever the maintainers will decide.
Thanks,
Marcel
Quoted 3 lines
Paolo
Quoted 16 lines · Marcel Apfelbaum
Quoted 1 line
I think this should not be committed to 2.3 after -rc0.
While I agree that looking at the above the series do not fit for 2.3, I still think the risk is not big because:
- The biggest amount of modifications are in pci_bus/pci_host and *is only* a movement of code into a new file,
no changes at all (This cover almost half of the series changes)
- The series does not intervene with usual process, meaning if pxb is not used, it will work exactly like before
- The bios already supports pxb for this release, is a pity to wait for another QEMU version.
- The series were in mailing list for more than a month before rc, but the real review process started at rc time.
(begging the question what a non-maintainer must do to get its code in
time)
- The series is mature, rebased on the latest QEMU
and was reviewed in depth and tested by the community.
I understand, but you have to draw a line somewhere. The easiest place to draw the line is 2.3.0-rc0.
Maintainers can already prepare branches with patches destined to 2.4, and these 26 can be included there. As far as you are concerned, if the code is ready you can stop worrying about it.
The problem isn't non-maintainer vs. maintainer. There was a dependency on Igor's series, which took some time to get in---partly because it was included in a 100-patch pull request, which isn't exactly the preferred way to send pull request in absence of a serious effort on continuous integration of maintainer branches.
Paolo
Quoted 2 lines · Paolo Bonzini
I understand, but you have to draw a line somewhere. The easiest place to draw the line is 2.3.0-rc0.
I definitely agree -- looking at the diffstat and the scope of the patch, this is definitely not suitable for committing to master after hardfreeze.
Yes, sometimes code doesn't get in for the release you were hoping for through no fault of the developers involved, and that sucks. But the release model we have is "every three to four months, time based", which means that (a) we need to avoid delays to releases, which means being fairly strict about what we permit into the tree during freeze, but also
(b) even if you do miss a release, the next one will be along fairly shortly.
-- PMM
Hi,
Quoted 2 lines
- You are more than welcome to try using:
-bios <patched with the above series>
Not needed any more, the seabios-1.8.1 release in master should work just fine.
cheers,
Gerd
Quoted 7 lines · Gerd Hoffmann
Hi,Quoted 2 lines
- You are more than welcome to try using:
-bios <patched with the above series>Not needed any more, the seabios-1.8.1 release in master should work just fine.
Good to know, thanks!
Marcel
Quoted 5 lines
cheers,
Gerd
Quoted 5 lines · Marcel Apfelbaum
Notes:
- I realize that this qualifies as a late submission, but the code was arround
a lot of time and got lots of reviews and it also tested (by Gerd), so should be mature enough.
- This series is not that big, patches 1-8 are really small and can be submitted separately, however I preferred to keep them here to get the whole picture.
Sorry, I have agree with other maintainers here: this doesn't look like 2.3 material to me, we are in a fixes only period now.
This doesn't mean I won't merge it though: this time around I opened pci-next and will queue patches there, so no extra effort on your side should be required.
Quoted 5 lines
The series is fully functional.
- Limitations:
- Pxb's bus does not support hotplug. It will be addressed on top of this series because is already getting to big.
Absolutely, and it's a reasonable thing to do normally, but not when we are trying to finalize a release.
Looks like another reason to defer this to 2.4.
Quoted 2 lines
- You are more than welcome to try using:
-device pxb-device,id=pxb,bus_nr=4,numa_node=1 -device e1000,bus=pxb,addr=0x1 -bios <patched with the above series>
Signature · 1 line
MST