PXB changes
v7 cover PXB changes
I tried hard to address the two sets of comments I got for v6:
- in the first half of the series, I reworked the new pci-bridge property
- in the second half, I implemented the agreed upon OFW format
I also adapted the OVMF series to the changes in the second half (locally only, for now), and retested QEMU+OVMF with my Windows Server 2012 r2 guest.
In any case, this is my swan song for QEMU as far as this feature is concerned.
Thanks
Laszlo
Laszlo Ersek (10):
migration: introduce VMSTATE_BUFFER_UNSAFE_INFO_TEST() hw/pci-bridge: expose _test parameter in SHPC_VMSTATE() hw/pci-bridge: add macro for "chassis_nr" property hw/pci-bridge: add macro for "msi" property
hw/pci: introduce shpc_present() helper function hw/pci-bridge: introduce "shpc" property hw/pci-bridge: disable SHPC in PXB
hw/core: rebase sysbus_get_fw_dev_path() to g_strdup_printf() hw/core: explicit OFW unit address callback for SysBusDeviceClass hw/pci-bridge: format special OFW unit address for PXB host
include/hw/pci/pci_bridge.h | 4 ++ include/hw/pci/shpc.h | 11 ++++- include/hw/sysbus.h | 17 +++++++ include/migration/vmstate.h | 7 ++- hw/core/sysbus.c | 27 +++++++---- hw/pci-bridge/pci_bridge_dev.c | 92 +++++++++++++++++++++++++++++-------- hw/pci-bridge/pci_expander_bridge.c | 57 ++++++++++++++++++++++- 7 files changed, 183 insertions(+), 32 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v7 1/10 migration: introduce VMSTATE_BUFFER_UNSAFE_INFO_TEST()
There is no _TEST() variant of VMSTATE_BUFFER_UNSAFE_INFO() yet, but we'll soon need it. Introduce it and rebase the original VMSTATE_BUFFER_UNSAFE_INFO() on top.
The parameter order of the new function-like macro follows that of VMSTATE_SINGLE_TEST(): "_test" is introduced between "_state" and "_version".
---
Notes:
v7:
- no changes
v6:
- new in v6
include/migration/vmstate.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/migration/vmstate.h +6 -1
@@ -500,9 +500,10 @@ extern const VMStateInfo vmstate_info_bitmap; .start = (_start), \ } -#define VMSTATE_BUFFER_UNSAFE_INFO (_field, _state, _version, _info, _size) { \ +#define VMSTATE_BUFFER_UNSAFE_INFO_TEST (_field, _state, _test, _version, _info, _size) { \ .name = (stringify(_field)), \ .version_id = (_version), \ + .field_exists = (_test), \ .size = (_size), \ .info = &(_info), \ .flags = VMS_BUFFER, \
@@ -562,6 +563,10 @@ extern const VMStateInfo vmstate_info_bitmap;VMSTATE_STRUCT_ARRAY_TEST (_field, _state, _num,NULL , _version, \ _vmsd, _type) +#define VMSTATE_BUFFER_UNSAFE_INFO (_field, _state, _version, _info, _size) \ + VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _state, NULL, _version, _info, \ + _size) +#define VMSTATE_BOOL_V (_f, _s, _v) \ VMSTATE_SINGLE(_f, _s, _v, vmstate_info_bool, bool)
Signature · 1 line
1.8.3.1
PATCH v7 2/10 hw/pci-bridge: expose _test parameter in SHPC_VMSTATE()
In reply to Laszlo ErsekChange the signature of the function-like macro SHPC_VMSTATE(), so that we can produce and expect this field conditionally in the migration stream, starting with an upcoming patch.
---
Notes:
v7:
- no changes
v6:
- new in v6 (replaces "hw/pci-bridge: create interrupt-less, hotplug-less bridge for PXB" from v5) [Michael]
include/hw/pci/shpc.h | 5 +++-- hw/pci-bridge/pci_bridge_dev.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
include/hw/pci/shpc.h +3 -2
@@ -51,7 +51,8 @@ void shpc_device_hot_unplug_request_cb(HotplugHandler *hotplug_dev, DeviceState *dev, Error **errp);extern VMStateInfo shpc_vmstate_info; -#define SHPC_VMSTATE (_field, _type) \ - VMSTATE_BUFFER_UNSAFE_INFO(_field, _type, 0, shpc_vmstate_info, 0) +#define SHPC_VMSTATE (_field, _type, _test) \ + VMSTATE_BUFFER_UNSAFE_INFO_TEST(_field, _type, _test, 0, \ + shpc_vmstate_info, 0)#endif
hw/pci-bridge/pci_bridge_dev.c +1 -1
@@ -131,7 +131,7 @@ static const VMStateDescription pci_bridge_dev_vmstate = { .name = "pci_bridge", .fields = (VMStateField []) {VMSTATE_PCI_DEVICE (parent_obj, PCIBridge), -SHPC_VMSTATE (shpc, PCIDevice), +SHPC_VMSTATE (shpc, PCIDevice,NULL ),VMSTATE_END_OF_LIST () } };
Signature · 1 line
1.8.3.1
PATCH v7 3/10 hw/pci-bridge: add macro for "chassis_nr" property
In reply to Laszlo ErsekThis should help catch property name typos at compile time.
---
Notes:
v7:
- new in v7
include/hw/pci/pci_bridge.h | 2 ++ hw/pci-bridge/pci_bridge_dev.c | 3 ++- hw/pci-bridge/pci_expander_bridge.c | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-)
include/hw/pci/pci_bridge.h +2 -0
@@ -28,6 +28,8 @@#include "hw/pci/pci.h" +#define PCI_BRIDGE_DEV_PROP_CHASSIS_NR "chassis_nr" +int pci_bridge_ssvid_init (PCIDevice *dev,uint8_t offset,uint16_t svid,uint16_t ssid);
hw/pci-bridge/pci_bridge_dev.c +2 -1
@@ -122,7 +122,8 @@ static void qdev_pci_bridge_dev_reset(DeviceState *qdev)static Property pci_bridge_dev_properties[] = {/* Note: 0 is not a legal chassis number. */ -DEFINE_PROP_UINT8 ("chassis_nr" , PCIBridgeDev, chassis_nr,0 ), +DEFINE_PROP_UINT8 (PCI_BRIDGE_DEV_PROP_CHASSIS_NR , PCIBridgeDev, chassis_nr, +0 ),DEFINE_PROP_BIT ("msi" , PCIBridgeDev, flags,PCI_BRIDGE_DEV_F_MSI_REQ , true),DEFINE_PROP_END_OF_LIST (), };
hw/pci-bridge/pci_expander_bridge.c +2 -1
@@ -14,6 +14,7 @@#include "hw/pci/pci_bus.h" #include "hw/pci/pci_host.h" #include "hw/pci/pci_bus.h" +#include "hw/pci/pci_bridge.h" #include "hw/i386/pc.h" #include "qemu/range.h" #include "qemu/error-report.h"
@@ -175,7 +176,7 @@ static int pxb_dev_initfn(PCIDevice *dev) bds =qdev_create (BUS (bus),"pci-bridge" ); bds->id = dev_name; -qdev_prop_set_uint8 (bds,"chassis_nr" , pxb->bus_nr); +qdev_prop_set_uint8 (bds,PCI_BRIDGE_DEV_PROP_CHASSIS_NR , pxb->bus_nr);PCI_HOST_BRIDGE (ds)->bus = bus;
Signature · 1 line
1.8.3.1
PATCH v7 4/10 hw/pci-bridge: add macro for "msi" property
In reply to Laszlo ErsekThis should help catch property name typos at compile time.
---
Notes:
v7:
- new in v7
include/hw/pci/pci_bridge.h | 1 + hw/pci-bridge/pci_bridge_dev.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-)
include/hw/pci/pci_bridge.h +1 -0
@@ -29,6 +29,7 @@#include "hw/pci/pci.h" #define PCI_BRIDGE_DEV_PROP_CHASSIS_NR "chassis_nr" +#define PCI_BRIDGE_DEV_PROP_MSI "msi"int pci_bridge_ssvid_init (PCIDevice *dev,uint8_t offset,uint16_t svid,uint16_t ssid);
hw/pci-bridge/pci_bridge_dev.c +2 -1
@@ -124,7 +124,8 @@ static Property pci_bridge_dev_properties[] = {/* Note: 0 is not a legal chassis number. */ DEFINE_PROP_UINT8 (PCI_BRIDGE_DEV_PROP_CHASSIS_NR , PCIBridgeDev, chassis_nr,0 ), -DEFINE_PROP_BIT ("msi" , PCIBridgeDev, flags,PCI_BRIDGE_DEV_F_MSI_REQ , true), +DEFINE_PROP_BIT (PCI_BRIDGE_DEV_PROP_MSI , PCIBridgeDev, flags, +PCI_BRIDGE_DEV_F_MSI_REQ , true), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
1.8.3.1
PATCH v7 5/10 hw/pci: introduce shpc_present() helper function
In reply to Laszlo ErsekIt follows msi_present() in "include/hw/pci/msi.h".
---
Notes:
v7:
- new in v7 [Michael]
include/hw/pci/shpc.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/hw/pci/shpc.h +6 -0
@@ -6,6 +6,7 @@#include "migration/vmstate.h" #include "qapi/error.h" #include "hw/hotplug.h" +#include "hw/pci/pci.h" struct SHPCDevice {/* Capability offset in device's config space */
@@ -55,4 +56,9 @@ extern VMStateInfo shpc_vmstate_info;VMSTATE_BUFFER_UNSAFE_INFO_TEST (_field, _type, _test,0 , \ shpc_vmstate_info, 0) +static inline bool shpc_present (const PCIDevice *dev) +{ +return dev->cap_present &QEMU_PCI_CAP_SHPC ; +} +#endif
Signature · 1 line
1.8.3.1
PATCH v7 6/10 hw/pci-bridge: introduce "shpc" property
In reply to Laszlo ErsekIn the PCI expander bridge, we will want to disable those features of pci-bridge that relate to SHPC (standard hotplug controller):
- SHPC bar and underlying MemoryRegion
- interrupt (INTx or MSI)
- effective hotplug callbacks
- other SHPC hooks (initialization, cleanup, migration etc)
Introduce a new feature request bit in the PCIBridgeDev.flags field, and turn off the above if the bit is explicitly cleared.
---
Notes:
v7:
- call the new property "shpc" rather than "hotplug" [Michael]
- use macro for property name [Michael]
- rename PCI_BRIDGE_DEV_F_HOTPLUG to PCI_BRIDGE_DEV_F_SHPC_REQ [Michael]
- clear "msi" when "shpc" is clear [Michael]
- check SHPC presence with shpc_present(), paralleling msi_present() [Michael]
v6:
- new in v6 (replaces "hw/pci-bridge: create interrupt-less, hotplug-less bridge for PXB" from v5) [Michael]
- I tested migration-to-file and migration-from-file, with a single PXB behind which a virtio-scsi HBA lived
- No idea how to test the hotplug callbacks. I tried the device_add and device_del HMP commands with a virtio-scsi HBA behind the PXB, and the monitor reports no error at all; the callbacks don't seem to be reached.
- Retested with windows 2012; it works
include/hw/pci/pci_bridge.h | 1 + hw/pci-bridge/pci_bridge_dev.c | 86 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 16 deletions(-)
include/hw/pci/pci_bridge.h +1 -0
@@ -30,6 +30,7 @@#define PCI_BRIDGE_DEV_PROP_CHASSIS_NR "chassis_nr"#define PCI_BRIDGE_DEV_PROP_MSI "msi" +#define PCI_BRIDGE_DEV_PROP_SHPC "shpc"int pci_bridge_ssvid_init (PCIDevice *dev,uint8_t offset,uint16_t svid,uint16_t ssid);
hw/pci-bridge/pci_bridge_dev.c +70 -16
154 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v7 7/10 hw/pci-bridge: disable SHPC in PXB
In reply to Laszlo ErsekOVMF downloads the ACPI linker/loader script from QEMU when the edk2 PCI Bus driver globally signals the firmware that PCI enumeration and resource allocation have completed. At this point QEMU regenerates the ACPI payload in an fw_cfg read callback, and this is when the PXB's _CRS gets populated.
Unfortunately, when this happens, the PCI_COMMAND_MEMORY bit is clear in the root bus's command register, *unlike* under SeaBIOS. The consequences unfold as follows:
- When build_crs() fetches dev->io_regions[i].addr, it is all-bits-one, because pci_update_mappings() --> pci_bar_address() calculated it as PCI_BAR_UNMAPPED, due to the PCI_COMMAND_MEMORY bit being clear.
- Consequently, the SHPC MMIO BAR (bar 0) of the bridge is not added to the _CRS, *despite* having been programmed in PCI config space.
- Similarly, the SHPC MMIO BAR of the PXB is not removed from the main root bus's DWordMemory descriptor.
- Guest OSes (Linux and Windows alike) notice the pre-programmed SHPC BAR within the PXB's config space, and notice that it conflicts with the main root bus's memory resource descriptors. Linux reports
pci 0000:04:00.0: BAR 0: can't assign mem (size 0x100) pci 0000:04:00.0: BAR 0: trying firmware assignment [mem
0x88200000-0x882000ff 64bit]
pci 0000:04:00.0: BAR 0: [mem 0x88200000-0x882000ff 64bit] conflicts
with PCI Bus 0000:00 [mem
0x88200000-0xfebfffff]While Windows Server 2012 R2 reports
https://technet.microsoft.com/en-us/library/cc732199%28v=ws.10%29.aspx
This device cannot find enough free resources that it can use. If you want to use this device, you will need to disable one of the other devices on this system. (Code 12)
This issue was apparently encountered earlier, see the "hack" in:
https://lists.nongnu.org/archive/html/qemu-devel/2015-01/msg02983.html
and the current hole-punching logic in build_crs() and build_ssdt() is probably supposed to remedy exactly that problem -- however, for OVMF they don't work, because at the end of the PCI enumeration and resource allocation, which cues the ACPI linker/loader client, the command register is clear.
The "shpc" property of "pci-bridge", introduced in the previous patches, allows us to disable the standard hotplug controller cleanly, eliminating the SHPC bar and the conflict.
---
Notes:
v7:
- reference "shpc" property by macro PCI_BRIDGE_DEV_PROP_SHPC
v6:
- new in v6 (replaces "hw/pci-bridge: create interrupt-less, hotplug-less bridge for PXB" from v5) [Michael]
hw/pci-bridge/pci_expander_bridge.c | 1 + 1 file changed, 1 insertion(+)
hw/pci-bridge/pci_expander_bridge.c +1 -0
@@ -177,6 +177,7 @@ static int pxb_dev_initfn(PCIDevice *dev) bds =qdev_create (BUS (bus),"pci-bridge" ); bds->id = dev_name;qdev_prop_set_uint8 (bds,PCI_BRIDGE_DEV_PROP_CHASSIS_NR , pxb->bus_nr); +qdev_prop_set_bit (bds,PCI_BRIDGE_DEV_PROP_SHPC , false);PCI_HOST_BRIDGE (ds)->bus = bus;
Signature · 1 line
1.8.3.1
PATCH v7 8/10 hw/core: rebase sysbus_get_fw_dev_path() to g_strdup_printf()
In reply to Laszlo ErsekThis is done mainly for improving readability, and in preparation for the next patch, but Markus pointed out another bonus for the string being returned:
"No arbitrary length limit. Before the patch, it's 39 characters, and the code breaks catastrophically when qdev_fw_name() is longer: the second snprintf() is called with its first argument pointing beyond path[], and its second argument underflowing to a huge size."
---
Notes:
v7:
- no changes
- already part of a pending pull request:
http://thread.gmane.org/gmane.comp.emulators.qemu/344941/focus=344948
v6:
- no changes
v5:
- separate "%s@" from TARGET_FMT_plx with a space [Markus]
- copied Markus's note about "no arbitrary length limit" on the retval into the commit message
v4:
- unchanged
v3:
- new in v3
hw/core/sysbus.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
hw/core/sysbus.c +6 -10
@@ -281,19 +281,15 @@ static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)static char *sysbus_get_fw_dev_path (DeviceState *dev) {SysBusDevice *s =SYS_BUS_DEVICE (dev); -char path[40 ]; -int off; - - off =snprintf (path,sizeof (path),"%s" ,qdev_fw_name (dev));if (s->num_mmio) { -snprintf (path + off,sizeof (path) - off,"@" TARGET_FMT_plx, - s->mmio[0 ].addr); - }else if (s->num_pio) { -snprintf (path + off,sizeof (path) - off,"@i%04x" , s->pio[0 ]); +return g_strdup_printf ("%s@" TARGET_FMT_plx,qdev_fw_name (dev), + s->mmio[0 ].addr); } - -return g_strdup (path); +if (s->num_pio) { +return g_strdup_printf ("%s@i%04x" ,qdev_fw_name (dev), s->pio[0 ]); + } +return g_strdup (qdev_fw_name (dev)); } void sysbus_add_io(SysBusDevice *dev, hwaddr addr,
Signature · 1 line
1.8.3.1
PATCH v7 9/10 hw/core: explicit OFW unit address callback for SysBusDeviceClass
In reply to Laszlo ErsekThe sysbus_get_fw_dev_path() function formats OpenFirmware device path nodes ("driver-name@unit-address") for sysbus devices. The first choice for "unit-address" is the base address of the device's first MMIO region. The second choice is its first IO port.
However, if two sysbus devices with the same "driver-name" lack both MMIO and PIO resources, then there is no good way to distinguish them based on their OFW nodes, because in this case unit-address is omitted completely for both devices. An example is TYPE_PXB_HOST ("pxb-host").
For the sake of such devices, introduce the explicit_ofw_unit_address() "virtual member function". With this function, each sysbus device in the same SysBusDeviceClass can state its own address.
---
Notes:
v7:
- no changes
v6:
- no changes
v5:
- mention "pxb-host" as an example device in the commit message [Markus]
- reword documentation on explicit_ofw_unit_address(), specifying headline, preconditions / goal, side effects, retval, errors separately. [Markus]
- constify parameter of explicit_ofw_unit_address(), after focusing on side effects [Markus]
- move declaration of "addr" and "fw_dev_path" to the top level block in sysbus_get_fw_dev_path() [Markus]
- no functional changes, add / keep Markus's R-b
v4:
- Yet another approach. Instead of allowing the creator of the device to set a string property statically, introduce a class level callback.
v3:
- new in v3
- new approach
include/hw/sysbus.h | 17 +++++++++++++++++ hw/core/sysbus.c | 11 +++++++++++ 2 files changed, 28 insertions(+)
include/hw/sysbus.h +17 -0
@@ -41,6 +41,23 @@ typedef struct SysBusDeviceClass {/*< public >*/ int (*init)(SysBusDevice *dev); + +/* +* Let the sysbus device format its own non-PIO, non-MMIO unit address. +* +* Sometimes a class of SysBusDevices has neither MMIO nor PIO resources, +* yet instances of it would like to distinguish themselves, in +* OpenFirmware device paths, from other instances of the same class on the +* sysbus. For that end we expose this callback. +* +* The implementation is not supposed to change *@dev, or incur other +* observable change. +* +* The function returns a dynamically allocated string. On error, NULL +* should be returned; the unit address portion of the OFW node will be +* omitted then. (This is not considered a fatal error.) +*/ +char *(*explicit_ofw_unit_address)(const SysBusDevice *dev); } SysBusDeviceClass;struct SysBusDevice {
hw/core/sysbus.c +11 -0
@@ -281,6 +281,9 @@ static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent)static char *sysbus_get_fw_dev_path (DeviceState *dev) {SysBusDevice *s =SYS_BUS_DEVICE (dev); +SysBusDeviceClass *sbc =SYS_BUS_DEVICE_GET_CLASS (s); +/* for the explicit unit address fallback case: */ +char *addr, *fw_dev_path;if (s->num_mmio) { return g_strdup_printf("%s@" TARGET_FMT_plx, qdev_fw_name(dev),
@@ -289,6 +292,14 @@ static char *sysbus_get_fw_dev_path(DeviceState *dev)if (s->num_pio) {return g_strdup_printf ("%s@i%04x" ,qdev_fw_name (dev), s->pio[0 ]); } +if (sbc->explicit_ofw_unit_address) { + addr = sbc->explicit_ofw_unit_address (s); +if (addr) { + fw_dev_path =g_strdup_printf ("%s@%s" ,qdev_fw_name (dev), addr); +g_free (addr); +return fw_dev_path; + } + }return g_strdup (qdev_fw_name (dev)); }
Signature · 1 line
1.8.3.1
PATCH v7 10/10 hw/pci-bridge: format special OFW unit address for PXB host
In reply to Laszlo ErsekWe have agreed that OpenFirmware device paths in the "bootorder" fw_cfg file should follow the pattern
/pci@i0cf8,%x/...
for devices that live behind an extra root bus. The extra root bus in question is the %x'th among the extra root buses. (In other words, %x gives the position of the affected extra root bus relative to the other extra root buses, in bus_nr order.) %x starts at 1, and is formatted in hex.
The portion of the unit address that comes before the comma is dynamically taken from the main host bridge, similarly to sysbus_get_fw_dev_path().
---
Notes:
v7:
- implement the format that both Kevin and Michael agreed with. Example:
/pci@i0cf8,1/pci-bridge@0/scsi@0/channel@0/disk@0,0
- I updated the OVMF patchset accordingly, but I won't post it until this QEMU patch is applied
- Someone please write the SeaBIOS patch
v6:
- no changes
v5:
- constify parameter and local variables of pxb_host_ofw_unit_address(), in accord with the previous patch
v4:
- new in v4
hw/pci-bridge/pci_expander_bridge.c | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
hw/pci-bridge/pci_expander_bridge.c +53 -0
@@ -43,6 +43,8 @@ typedef struct PXBDev {uint16_t numa_node; } PXBDev; +static GList *pxb_dev_list; +#define TYPE_PXB_HOST "pxb-host"static int pxb_bus_num (PCIBus *bus)
@@ -89,12 +91,45 @@ static const char *pxb_host_root_bus_path(PCIHostState *host_bridge,return bus->bus_path; } +static char *pxb_host_ofw_unit_address (const SysBusDevice *dev) +{ +const PCIHostState *pxb_host; +const PCIBus *pxb_bus; +const PXBDev *pxb_dev; +int position; +const DeviceState *pxb_dev_base; +const PCIHostState *main_host; +const SysBusDevice *main_host_sbd; + + pxb_host =PCI_HOST_BRIDGE (dev); + pxb_bus = pxb_host->bus; + pxb_dev =PXB_DEV (pxb_bus->parent_dev); + position =g_list_index (pxb_dev_list, pxb_dev); +assert (position >=0 ); + + pxb_dev_base =DEVICE (pxb_dev); + main_host =PCI_HOST_BRIDGE (pxb_dev_base->parent_bus->parent); + main_host_sbd =SYS_BUS_DEVICE (main_host); + +if (main_host_sbd->num_mmio >0 ) { +return g_strdup_printf (TARGET_FMT_plx",%x" , + main_host_sbd->mmio[0 ].addr, position +1 ); + } +if (main_host_sbd->num_pio >0 ) { +return g_strdup_printf ("i%04x,%x" , + main_host_sbd->pio[0 ], position +1 ); + } +return NULL ; +} +static void pxb_host_class_init (ObjectClass *class,void *data) {DeviceClass *dc =DEVICE_CLASS (class); +SysBusDeviceClass *sbc =SYS_BUS_DEVICE_CLASS (class);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); dc->fw_name ="pci" ; + sbc->explicit_ofw_unit_address = pxb_host_ofw_unit_address; hc->root_bus_path = pxb_host_root_bus_path; }
@@ -149,6 +184,15 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)return pin -PCI_SLOT (pxb->devfn); } +static gint pxb_compare (gconstpointer a,gconstpointer b) +{ +const PXBDev *pxb_a = a, *pxb_b = b; + +return pxb_a->bus_nr < pxb_b->bus_nr ?-1 : + pxb_a->bus_nr > pxb_b->bus_nr ?1 : +0 ; +} +static int pxb_dev_initfn (PCIDevice *dev) {PXBDev *pxb =PXB_DEV (dev);
@@ -192,9 +236,17 @@ static int pxb_dev_initfn(PCIDevice *dev) PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK);pci_config_set_class (dev->config,PCI_CLASS_BRIDGE_HOST ); + pxb_dev_list =g_list_insert_sorted (pxb_dev_list, pxb, pxb_compare);return 0 ; } +static void pxb_dev_exitfn (PCIDevice *pci_dev) +{ +PXBDev *pxb =PXB_DEV (pci_dev); + + pxb_dev_list =g_list_remove (pxb_dev_list, pxb); +} +static Property pxb_dev_properties[] = {/* Note: 0 is not a legal a PXB bus number. */ DEFINE_PROP_UINT8 ("bus_nr" , PXBDev, bus_nr,0 ),
@@ -208,6 +260,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void *data)PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); k->init = pxb_dev_initfn; + k->exit = pxb_dev_exitfn; k->vendor_id =PCI_VENDOR_ID_REDHAT ; k->device_id =PCI_DEVICE_ID_REDHAT_PXB ; k->class_id =PCI_CLASS_BRIDGE_HOST ;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v7 10/10] hw/pci-bridge: format special OFW unit address for PXB host
Quoted 11 lines · Laszlo Ersek
We have agreed that OpenFirmware device paths in the "bootorder"
fw_cfgfile should follow the pattern/pci@i0cf8,%x/...
for devices that live behind an extra root bus. The extra root bus in question is the %x'th among the extra root buses. (In other words, %x gives the position of the affected extra root bus relative to the other extra root buses, in
bus_nrorder.) %x starts at 1, and is formatted in hex.
Quoted 7 lines
The portion of the unit address that comes before the comma is dynamically taken from the main host bridge, similarly to
sysbus_get_fw_dev_path().Cc Kevin O'Connor <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Marcel Apfelbaum <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>
So as I said, a global pxb_dev_list is ugly, and we do not want duplicate data structures - please scan child devices of parent instead. Functionally correct, so can be a patch on top.
Quoted 126 lines
---
Notes:
v7:
- implement the format that both Kevin and Michael agreed with. Example:
/pci@i0cf8,1/pci-bridge@0/scsi@0/channel@0/disk@0,0
- I updated the OVMF patchset accordingly, but I won't post it until this QEMU patch is applied
- Someone please write the SeaBIOS patchv6:
- no changesv5:
- constify parameter and local variables ofpxb_host_ofw_unit_address(), in accord with the previous patchv4:
- new in v4hw/pci-bridge/pci_expander_bridge.c | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)hw/pci-bridge/pci_expander_bridge.c +53
-0@@ -43,6 +43,8 @@ typedef struct PXBDev {uint16_t numa_node; } PXBDev; +static GList *pxb_dev_list; +#define TYPE_PXB_HOST "pxb-host"static int pxb_bus_num (PCIBus *bus)@@ -89,12 +91,45 @@ static const char *pxb_host_root_bus_path(PCIHostState *host_bridge,return bus->bus_path; } +static char *pxb_host_ofw_unit_address (const SysBusDevice *dev) +{ +const PCIHostState *pxb_host; +const PCIBus *pxb_bus; +const PXBDev *pxb_dev; +int position; +const DeviceState *pxb_dev_base; +const PCIHostState *main_host; +const SysBusDevice *main_host_sbd; + + pxb_host =PCI_HOST_BRIDGE (dev); + pxb_bus = pxb_host->bus; + pxb_dev =PXB_DEV (pxb_bus->parent_dev); + position =g_list_index (pxb_dev_list, pxb_dev); +assert (position >=0 ); + + pxb_dev_base =DEVICE (pxb_dev); + main_host =PCI_HOST_BRIDGE (pxb_dev_base->parent_bus->parent); + main_host_sbd =SYS_BUS_DEVICE (main_host); + +if (main_host_sbd->num_mmio >0 ) { +return g_strdup_printf (TARGET_FMT_plx",%x" , + main_host_sbd->mmio[0 ].addr, position +1 ); + } +if (main_host_sbd->num_pio >0 ) { +return g_strdup_printf ("i%04x,%x" , + main_host_sbd->pio[0 ], position +1 ); + } +return NULL ; +} +static void pxb_host_class_init (ObjectClass *class,void *data) {DeviceClass *dc =DEVICE_CLASS (class); +SysBusDeviceClass *sbc =SYS_BUS_DEVICE_CLASS (class);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); dc->fw_name ="pci" ; + sbc->explicit_ofw_unit_address = pxb_host_ofw_unit_address; hc->root_bus_path = pxb_host_root_bus_path; }@@ -149,6 +184,15 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)return pin -PCI_SLOT (pxb->devfn); } +static gint pxb_compare (gconstpointer a,gconstpointer b) +{ +const PXBDev *pxb_a = a, *pxb_b = b; + +return pxb_a->bus_nr < pxb_b->bus_nr ?-1 : + pxb_a->bus_nr > pxb_b->bus_nr ?1 : +0 ; +} +static int pxb_dev_initfn (PCIDevice *dev) {PXBDev *pxb =PXB_DEV (dev);@@ -192,9 +236,17 @@ static int pxb_dev_initfn(PCIDevice *dev) PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK);pci_config_set_class (dev->config,PCI_CLASS_BRIDGE_HOST ); + pxb_dev_list =g_list_insert_sorted (pxb_dev_list, pxb, pxb_compare);return 0 ; } +static void pxb_dev_exitfn (PCIDevice *pci_dev) +{ +PXBDev *pxb =PXB_DEV (pci_dev); + + pxb_dev_list =g_list_remove (pxb_dev_list, pxb); +} +static Property pxb_dev_properties[] = {/* Note: 0 is not a legal a PXB bus number. */ DEFINE_PROP_UINT8 ("bus_nr" , PXBDev, bus_nr,0 ),@@ -208,6 +260,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void *data)PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); k->init = pxb_dev_initfn; + k->exit = pxb_dev_exitfn; k->vendor_id =PCI_VENDOR_ID_REDHAT ; k->device_id =PCI_DEVICE_ID_REDHAT_PXB ; k->class_id =PCI_CLASS_BRIDGE_HOST ;Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v7 10/10] hw/pci-bridge: format special OFW unit address for PXB host
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Laszlo Ersek
We have agreed that OpenFirmware device paths in the "bootorder"
fw_cfgfile should follow the pattern/pci@i0cf8,%x/...
for devices that live behind an extra root bus. The extra root bus in question is the %x'th among the extra root buses. (In other words, %x gives the position of the affected extra root bus relative to the other extra root buses, in
bus_nrorder.) %x starts at 1, and is formatted in hex.The portion of the unit address that comes before the comma is dynamically taken from the main host bridge, similarly to
sysbus_get_fw_dev_path().
Quoted 8 lines
Quoted 4 lines
Cc Kevin O'Connor <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Marcel Apfelbaum <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>So as I said, a global
pxb_dev_listis ugly, and we do not want duplicate data structures - please scan child devices of parent instead. Functionally correct, so can be a patch on top.
Marcel, can you pick this up please?
Thanks
Laszlo
Quoted 128 lines
Quoted 128 lines
---
Notes:
v7:
- implement the format that both Kevin and Michael agreed with. Example:
/pci@i0cf8,1/pci-bridge@0/scsi@0/channel@0/disk@0,0
- I updated the OVMF patchset accordingly, but I won't post it until this QEMU patch is applied
- Someone please write the SeaBIOS patchv6:
- no changesv5:
- constify parameter and local variables ofpxb_host_ofw_unit_address(), in accord with the previous patchv4:
- new in v4hw/pci-bridge/pci_expander_bridge.c | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)hw/pci-bridge/pci_expander_bridge.c +53
-0@@ -43,6 +43,8 @@ typedef struct PXBDev {uint16_t numa_node; } PXBDev; +static GList *pxb_dev_list; +#define TYPE_PXB_HOST "pxb-host"static int pxb_bus_num (PCIBus *bus)@@ -89,12 +91,45 @@ static const char *pxb_host_root_bus_path(PCIHostState *host_bridge,return bus->bus_path; } +static char *pxb_host_ofw_unit_address (const SysBusDevice *dev) +{ +const PCIHostState *pxb_host; +const PCIBus *pxb_bus; +const PXBDev *pxb_dev; +int position; +const DeviceState *pxb_dev_base; +const PCIHostState *main_host; +const SysBusDevice *main_host_sbd; + + pxb_host =PCI_HOST_BRIDGE (dev); + pxb_bus = pxb_host->bus; + pxb_dev =PXB_DEV (pxb_bus->parent_dev); + position =g_list_index (pxb_dev_list, pxb_dev); +assert (position >=0 ); + + pxb_dev_base =DEVICE (pxb_dev); + main_host =PCI_HOST_BRIDGE (pxb_dev_base->parent_bus->parent); + main_host_sbd =SYS_BUS_DEVICE (main_host); + +if (main_host_sbd->num_mmio >0 ) { +return g_strdup_printf (TARGET_FMT_plx",%x" , + main_host_sbd->mmio[0 ].addr, position +1 ); + } +if (main_host_sbd->num_pio >0 ) { +return g_strdup_printf ("i%04x,%x" , + main_host_sbd->pio[0 ], position +1 ); + } +return NULL ; +} +static void pxb_host_class_init (ObjectClass *class,void *data) {DeviceClass *dc =DEVICE_CLASS (class); +SysBusDeviceClass *sbc =SYS_BUS_DEVICE_CLASS (class);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); dc->fw_name ="pci" ; + sbc->explicit_ofw_unit_address = pxb_host_ofw_unit_address; hc->root_bus_path = pxb_host_root_bus_path; }@@ -149,6 +184,15 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)return pin -PCI_SLOT (pxb->devfn); } +static gint pxb_compare (gconstpointer a,gconstpointer b) +{ +const PXBDev *pxb_a = a, *pxb_b = b; + +return pxb_a->bus_nr < pxb_b->bus_nr ?-1 : + pxb_a->bus_nr > pxb_b->bus_nr ?1 : +0 ; +} +static int pxb_dev_initfn (PCIDevice *dev) {PXBDev *pxb =PXB_DEV (dev);@@ -192,9 +236,17 @@ static int pxb_dev_initfn(PCIDevice *dev) PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK);pci_config_set_class (dev->config,PCI_CLASS_BRIDGE_HOST ); + pxb_dev_list =g_list_insert_sorted (pxb_dev_list, pxb, pxb_compare);return 0 ; } +static void pxb_dev_exitfn (PCIDevice *pci_dev) +{ +PXBDev *pxb =PXB_DEV (pci_dev); + + pxb_dev_list =g_list_remove (pxb_dev_list, pxb); +} +static Property pxb_dev_properties[] = {/* Note: 0 is not a legal a PXB bus number. */ DEFINE_PROP_UINT8 ("bus_nr" , PXBDev, bus_nr,0 ),@@ -208,6 +260,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void *data)PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); k->init = pxb_dev_initfn; + k->exit = pxb_dev_exitfn; k->vendor_id =PCI_VENDOR_ID_REDHAT ; k->device_id =PCI_DEVICE_ID_REDHAT_PXB ; k->class_id =PCI_CLASS_BRIDGE_HOST ;Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v7 10/10] hw/pci-bridge: format special OFW unit address for PXB host
Quoted 21 lines · Laszlo Ersek
Quoted 20 lines · Michael S. Tsirkin
Quoted 18 lines · Laszlo Ersek
We have agreed that OpenFirmware device paths in the "bootorder"
fw_cfgfile should follow the pattern/pci@i0cf8,%x/...for devices that live behind an extra root bus. The extra root bus in question is the %x'th among the extra root buses. (In other words, %x gives the position of the affected extra root bus relative to the other extra root buses, in
bus_nrorder.) %x starts at 1, and is formatted in hex.The portion of the unit address that comes before the comma is dynamically taken from the main host bridge, similarly to
sysbus_get_fw_dev_path().Cc Kevin O'Connor <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Marcel Apfelbaum <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>
Quoted 5 lines
Quoted 3 lines
So as I said, a global
pxb_dev_listis ugly, and we do not want duplicate data structures - please scan child devices of parent instead. Functionally correct, so can be a patch on top.Marcel, can you pick this up please?
Sure thing, thank you for your patches!
I'll take care of this,
Marcel
Quoted 133 lines
Thanks
LaszloQuoted 128 lines
Quoted 128 lines
---
Notes:
v7:
- implement the format that both Kevin and Michael agreed with. Example:
/pci@i0cf8,1/pci-bridge@0/scsi@0/channel@0/disk@0,0
- I updated the OVMF patchset accordingly, but I won't post it until this QEMU patch is applied
- Someone please write the SeaBIOS patchv6:
- no changesv5:
- constify parameter and local variables ofpxb_host_ofw_unit_address(), in accord with the previous patchv4:
- new in v4hw/pci-bridge/pci_expander_bridge.c | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)hw/pci-bridge/pci_expander_bridge.c +53
-1@@ -43,6 +43,8 @@ typedef struct PXBDev {uint16_t numa_node; } PXBDev; +static GList *pxb_dev_list; +#define TYPE_PXB_HOST "pxb-host"static int pxb_bus_num (PCIBus *bus)@@ -89,12 +91,45 @@ static const char *pxb_host_root_bus_path(PCIHostState *host_bridge,return bus->bus_path; } +static char *pxb_host_ofw_unit_address (const SysBusDevice *dev) +{ +const PCIHostState *pxb_host; +const PCIBus *pxb_bus; +const PXBDev *pxb_dev; +int position; +const DeviceState *pxb_dev_base; +const PCIHostState *main_host; +const SysBusDevice *main_host_sbd; + + pxb_host =PCI_HOST_BRIDGE (dev); + pxb_bus = pxb_host->bus; + pxb_dev =PXB_DEV (pxb_bus->parent_dev); + position =g_list_index (pxb_dev_list, pxb_dev); +assert (position >=0 ); + + pxb_dev_base =DEVICE (pxb_dev); + main_host =PCI_HOST_BRIDGE (pxb_dev_base->parent_bus->parent); + main_host_sbd =SYS_BUS_DEVICE (main_host); + +if (main_host_sbd->num_mmio >0 ) { +return g_strdup_printf (TARGET_FMT_plx",%x" , + main_host_sbd->mmio[0 ].addr, position +1 ); + } +if (main_host_sbd->num_pio >0 ) { +return g_strdup_printf ("i%04x,%x" , + main_host_sbd->pio[0 ], position +1 ); + } +return NULL ; +} +static void pxb_host_class_init (ObjectClass *class,void *data) {DeviceClass *dc =DEVICE_CLASS (class); +SysBusDeviceClass *sbc =SYS_BUS_DEVICE_CLASS (class);PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (class); dc->fw_name ="pci" ; + sbc->explicit_ofw_unit_address = pxb_host_ofw_unit_address; hc->root_bus_path = pxb_host_root_bus_path; }@@ -149,6 +184,15 @@ static int pxb_map_irq_fn(PCIDevice *pci_dev, int pin)return pin -PCI_SLOT (pxb->devfn); } +static gint pxb_compare (gconstpointer a,gconstpointer b) +{ +const PXBDev *pxb_a = a, *pxb_b = b; + +return pxb_a->bus_nr < pxb_b->bus_nr ?-1 : + pxb_a->bus_nr > pxb_b->bus_nr ?1 : +0 ; +} +static int pxb_dev_initfn (PCIDevice *dev) {PXBDev *pxb =PXB_DEV (dev);@@ -192,9 +236,17 @@ static int pxb_dev_initfn(PCIDevice *dev) PCI_STATUS_66MHZ | PCI_STATUS_FAST_BACK);pci_config_set_class (dev->config,PCI_CLASS_BRIDGE_HOST ); + pxb_dev_list =g_list_insert_sorted (pxb_dev_list, pxb, pxb_compare);return 0 ; } +static void pxb_dev_exitfn (PCIDevice *pci_dev) +{ +PXBDev *pxb =PXB_DEV (pci_dev); + + pxb_dev_list =g_list_remove (pxb_dev_list, pxb); +} +static Property pxb_dev_properties[] = {/* Note: 0 is not a legal a PXB bus number. */ DEFINE_PROP_UINT8 ("bus_nr" , PXBDev, bus_nr,0 ),@@ -208,6 +260,7 @@ static void pxb_dev_class_init(ObjectClass *klass, void *data)PCIDeviceClass *k =PCI_DEVICE_CLASS (klass); k->init = pxb_dev_initfn; + k->exit = pxb_dev_exitfn; k->vendor_id =PCI_VENDOR_ID_REDHAT ; k->device_id =PCI_DEVICE_ID_REDHAT_PXB ; k->class_id =PCI_CLASS_BRIDGE_HOST ; --1.8.3.1
Re: [Qemu-devel] [PATCH v7 10/10] hw/pci-bridge: format special OFW unit address for PXB host
In reply to Laszlo ErsekQuoted 20 lines · Laszlo Ersek
We have agreed that OpenFirmware device paths in the "bootorder"
fw_cfgfile should follow the pattern/pci@i0cf8,%x/...
for devices that live behind an extra root bus. The extra root bus in question is the %x'th among the extra root buses. (In other words, %x gives the position of the affected extra root bus relative to the other extra root buses, in
bus_nrorder.) %x starts at 1, and is formatted in hex.The portion of the unit address that comes before the comma is dynamically taken from the main host bridge, similarly to
sysbus_get_fw_dev_path().Cc Kevin O'Connor <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Marcel Apfelbaum <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>---
Quoted 7 lines
Notes:
v7:
- implement the format that both Kevin and Michael agreed with. Example:
/pci@i0cf8,1/pci-bridge@0/scsi@0/channel@0/disk@0,0
- I updated the OVMF patchset accordingly, but I won't post it until this QEMU patch is applied
- Someone please write the SeaBIOS patch
The associated SeaBIOS patch is below.
Does anyone have a qemu command line handy to test with the PXB bus?
-Kevin
src/boot.c +2 -2
@@ -112,9 +112,9 @@ build_pci_path(char *buf, int max, const char *devname, struct pci_device *pci)if (pci->parent) { p =build_pci_path (p, max,"pci-bridge" , pci->parent); }else { -if (pci->rootbus) - p +=snprintf (p, max,"/pci-root@%x" , pci->rootbus); p +=snprintf (p, buf+max-p,"%s" ,FW_PCI_DOMAIN ); +if (pci->rootbus) + p +=snprintf (p, buf+max-p,",%x" , pci->rootbus); }int dev =pci_bdf_to_dev (pci->bdf), fn =pci_bdf_to_fn (pci->bdf);
Re: [Qemu-devel] [PATCH v7 10/10] hw/pci-bridge: format special OFW unit address for PXB host
Quoted 29 lines · Kevin O'Connor
Quoted 20 lines · Laszlo Ersek
We have agreed that OpenFirmware device paths in the "bootorder"
fw_cfgfile should follow the pattern/pci@i0cf8,%x/...for devices that live behind an extra root bus. The extra root bus in question is the %x'th among the extra root buses. (In other words, %x gives the position of the affected extra root bus relative to the other extra root buses, in
bus_nrorder.) %x starts at 1, and is formatted in hex.The portion of the unit address that comes before the comma is dynamically taken from the main host bridge, similarly to
sysbus_get_fw_dev_path().Cc Kevin O'Connor <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Marcel Apfelbaum <[email protected]>Signed-off-by Laszlo Ersek <[email protected]>---
Quoted 7 lines
Notes:
v7:
- implement the format that both Kevin and Michael agreed with. Example:
/pci@i0cf8,1/pci-bridge@0/scsi@0/channel@0/disk@0,0
- I updated the OVMF patchset accordingly, but I won't post it until this QEMU patch is applied
- Someone please write the SeaBIOS patch
Quoted 3 lines
The associated SeaBIOS patch is below.
Does anyone have a qemu command line handy to test with the PXB bus?
-device pxb,id=bridge1,bus_nr=10 -netdev user,id=u -device e1000,id=net2,bus=bridge1,netdev=u
Let me know if you have any issues with it.
Thanks,
Marcel
Quoted 19 lines
(quoted diff) +0
-1-Kevinsrc/boot.c +2
-2@@ -112,9 +112,9 @@ build_pci_path(char *buf, int max, const char *devname, struct pci_device *pci)if (pci->parent) { p =build_pci_path (p, max,"pci-bridge" , pci->parent); }else { -if (pci->rootbus) - p +=snprintf (p, max,"/pci-root@%x" , pci->rootbus); p +=snprintf (p, buf+max-p,"%s" ,FW_PCI_DOMAIN ); +if (pci->rootbus) + p +=snprintf (p, buf+max-p,",%x" , pci->rootbus); }int dev =pci_bdf_to_dev (pci->bdf), fn =pci_bdf_to_fn (pci->bdf);