hw/pci: PCI resource reserve capability
v2 cover hw/pci: PCI resource reserve capability
This patch serial is about PCI resource reserve capability.
First patch refactors the resource reserve fields in GenPCIERoorPort structure out to another new structure, called "PCIResReserve". Modify the parameter list of pci_bridge_qemu_reserve_cap_init().
Then we add the teardown function called pci_bridge_qemu_reserve_cap_uninit().
Last we enable the resource reserve capability for legacy PCI bridge so that firmware can reserve additional resources for the bridge.
Change Log:
v2 -> v1
* add refactoring patch
* add teardown function
* some other fixes
Jing Liu (3):
hw/pci: factor PCI reserve resources to a separate structure hw/pci: add teardown function for PCI resource reserve capability hw/pci: add PCI resource reserve capability to legacy PCI bridge
hw/pci-bridge/gen_pcie_root_port.c | 32 +++++++++++++------------- hw/pci-bridge/pci_bridge_dev.c | 25 ++++++++++++++++++++ hw/pci/pci_bridge.c | 47 +++++++++++++++++++++----------------- include/hw/pci/pci_bridge.h | 18 +++++++++++---- 4 files changed, 80 insertions(+), 42 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v2 1/3 hw/pci: factor PCI reserve resources to a separate structure
Factor "bus_reserve", "io_reserve", "mem_reserve", "pref32_reserve" and "pref64_reserve" fields of the "GenPCIERootPort" structure out to "PCIResReserve" structure, so that other PCI bridges can reuse it to add resource reserve capability.
--- hw/pci-bridge/gen_pcie_root_port.c | 32 ++++++++++++++++---------------- hw/pci/pci_bridge.c | 38 +++++++++++++++++--------------------- include/hw/pci/pci_bridge.h | 17 ++++++++++++----- 3 files changed, 45 insertions(+), 42 deletions(-)
hw/pci-bridge/gen_pcie_root_port.c +16 -16
@@ -29,12 +29,7 @@ typedef struct GenPCIERootPort {bool migrate_msix; -/* additional resources to reserve on firmware init */ -uint32_t bus_reserve; -uint64_t io_reserve; -uint64_t mem_reserve; -uint64_t pref32_reserve; -uint64_t pref64_reserve; +PCIResReserve res_reserve; } GenPCIERootPort;static uint8_t gen_rp_aer_vector (const PCIDevice *d)
@@ -82,16 +77,15 @@ static void gen_rp_realize(DeviceState *dev, Error **errp)return ; } -int rc =pci_bridge_qemu_reserve_cap_init (d,0 , grp->bus_reserve, - grp->io_reserve, grp->mem_reserve, grp->pref32_reserve, - grp->pref64_reserve, errp); +int rc =pci_bridge_qemu_reserve_cap_init (d,0 , + grp->res_reserve, errp);if (rc <0 ) { rpc->parent_class.exit (d);return ; } -if (!grp->io_reserve) { +if (!grp->res_reserve.io_reserve) {pci_word_test_and_clear_mask (d->wmask +PCI_COMMAND ,PCI_COMMAND_IO ); d->wmask[PCI_IO_BASE ] =0 ;
@@ -117,12 +111,18 @@ static const VMStateDescription vmstate_rp_dev = { };static Property gen_rp_props[] = { -DEFINE_PROP_BOOL ("x-migrate-msix" , GenPCIERootPort, migrate_msix, true), -DEFINE_PROP_UINT32 ("bus-reserve" , GenPCIERootPort, bus_reserve,-1 ), -DEFINE_PROP_SIZE ("io-reserve" , GenPCIERootPort, io_reserve,-1 ), -DEFINE_PROP_SIZE ("mem-reserve" , GenPCIERootPort, mem_reserve,-1 ), -DEFINE_PROP_SIZE ("pref32-reserve" , GenPCIERootPort, pref32_reserve,-1 ), -DEFINE_PROP_SIZE ("pref64-reserve" , GenPCIERootPort, pref64_reserve,-1 ), +DEFINE_PROP_BOOL ("x-migrate-msix" , GenPCIERootPort, + migrate_msix, true), +DEFINE_PROP_UINT32 ("bus-reserve" , GenPCIERootPort, + res_reserve.bus_reserve,-1 ), +DEFINE_PROP_SIZE ("io-reserve" , GenPCIERootPort, + res_reserve.io_reserve,-1 ), +DEFINE_PROP_SIZE ("mem-reserve" , GenPCIERootPort, + res_reserve.mem_reserve,-1 ), +DEFINE_PROP_SIZE ("pref32-reserve" , GenPCIERootPort, + res_reserve.pref32_reserve,-1 ), +DEFINE_PROP_SIZE ("pref64-reserve" , GenPCIERootPort, + res_reserve.pref64_reserve,-1 ),DEFINE_PROP_END_OF_LIST () };
hw/pci/pci_bridge.c +17 -21
@@ -411,38 +411,34 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,int pci_bridge_qemu_reserve_cap_init (PCIDevice *dev,int cap_offset, -uint32_t bus_reserve,uint64_t io_reserve, -uint64_t mem_non_pref_reserve, -uint64_t mem_pref_32_reserve, -uint64_t mem_pref_64_reserve, -Error **errp) +PCIResReserve res,Error **errp) { -if (mem_pref_32_reserve != (uint64_t )-1 && - mem_pref_64_reserve != (uint64_t )-1 ) { +if (res.pref32_reserve != (uint64_t )-1 && + res.pref64_reserve != (uint64_t )-1 ) {error_setg (errp,"PCI resource reserve cap: PREF32 and PREF64 conflict" );return -EINVAL ; } -if (mem_non_pref_reserve != (uint64_t )-1 && - mem_non_pref_reserve >= (1ULL <<32 )) { +if (res.mem_reserve != (uint64_t )-1 && + res.mem_reserve >= (1ULL <<32 )) {error_setg (errp,"PCI resource reserve cap: mem-reserve must be less than 4G" );return -EINVAL ; } -if (mem_pref_32_reserve != (uint64_t )-1 && - mem_pref_32_reserve >= (1ULL <<32 )) { +if (res.pref32_reserve != (uint64_t )-1 && + res.pref32_reserve >= (1ULL <<32 )) {error_setg (errp,"PCI resource reserve cap: pref32-reserve must be less than 4G" );return -EINVAL ; } -if (bus_reserve == (uint32_t )-1 && - io_reserve == (uint64_t )-1 && - mem_non_pref_reserve == (uint64_t )-1 && - mem_pref_32_reserve == (uint64_t )-1 && - mem_pref_64_reserve == (uint64_t )-1 ) { +if (res.bus_reserve == (uint32_t )-1 && + res.io_reserve == (uint64_t )-1 && + res.mem_reserve == (uint64_t )-1 && + res.pref32_reserve == (uint64_t )-1 && + res.pref64_reserve == (uint64_t )-1 ) {return 0 ; }
@@ -450,11 +446,11 @@ int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,PCIBridgeQemuCap cap = { .len = cap_len, .type =REDHAT_PCI_CAP_RESOURCE_RESERVE , - .bus_res = bus_reserve, - .io = io_reserve, - .mem = mem_non_pref_reserve, - .mem_pref_32 = mem_pref_32_reserve, - .mem_pref_64 = mem_pref_64_reserve + .bus_res = res.bus_reserve, + .io = res.io_reserve, + .mem = res.mem_reserve, + .mem_pref_32 = res.pref32_reserve, + .mem_pref_64 = res.pref64_reserve }; int offset = pci_add_capability(dev, PCI_CAP_ID_VNDR,
include/hw/pci/pci_bridge.h +12 -5
@@ -133,11 +133,18 @@ typedef struct PCIBridgeQemuCap {#define REDHAT_PCI_CAP_RESOURCE_RESERVE 1 +/* +* additional resources to reserve on firmware init +*/ +typedef struct PCIResReserve { +uint32_t bus_reserve; +uint64_t io_reserve; +uint64_t mem_reserve; +uint64_t pref32_reserve; +uint64_t pref64_reserve; +}PCIResReserve ; +int pci_bridge_qemu_reserve_cap_init (PCIDevice *dev,int cap_offset, -uint32_t bus_reserve,uint64_t io_reserve, -uint64_t mem_non_pref_reserve, -uint64_t mem_pref_32_reserve, -uint64_t mem_pref_64_reserve, -Error **errp); +PCIResReserve res_reserve,Error **errp);#endif /* QEMU_PCI_BRIDGE_H */
Signature · 1 line
1.8.3.1
PATCH v2 2/3 hw/pci: add teardown function for PCI resource reserve capability
In reply to Jing LiuClean up the PCI config space of resource reserve capability.
--- hw/pci/pci_bridge.c | 9 +++++++++ include/hw/pci/pci_bridge.h | 1 + 2 files changed, 10 insertions(+)
hw/pci/pci_bridge.c +9 -0
@@ -465,6 +465,15 @@ int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,return 0 ; } +void pci_bridge_qemu_reserve_cap_uninit (PCIDevice *dev) +{ +uint8_t pos =pci_find_capability (dev,PCI_CAP_ID_VNDR ); + +pci_del_capability (dev,PCI_CAP_ID_VNDR ,sizeof (PCIBridgeQemuCap)); +memset (dev->config + pos +PCI_CAP_FLAGS ,0 , +sizeof (PCIBridgeQemuCap) -PCI_CAP_FLAGS ); +} +static const TypeInfo pci_bridge_type_info = { .name =TYPE_PCI_BRIDGE , .parent =TYPE_PCI_DEVICE ,
include/hw/pci/pci_bridge.h +1 -0
@@ -147,4 +147,5 @@ typedef struct PCIResReserve {int pci_bridge_qemu_reserve_cap_init (PCIDevice *dev,int cap_offset,PCIResReserve res_reserve,Error **errp); +void pci_bridge_qemu_reserve_cap_uninit (PCIDevice *dev);#endif /* QEMU_PCI_BRIDGE_H */
Signature · 1 line
1.8.3.1
PATCH v2 3/3 hw/pci: add PCI resource reserve capability to legacy PCI bridge
In reply to Jing LiuAdd hint to firmware (e.g. SeaBIOS) to reserve addtional BUS/IO/MEM/PREF resource for legacy pci-pci bridge.
--- hw/pci-bridge/pci_bridge_dev.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
hw/pci-bridge/pci_bridge_dev.c +25 -0
@@ -46,6 +46,8 @@ struct PCIBridgeDev {uint32_t flags;OnOffAuto msi; + +PCIResReserve res_reserve; };typedef struct PCIBridgeDev PCIBridgeDev ;
@@ -95,6 +97,12 @@ static void pci_bridge_dev_realize(PCIDevice *dev, Error **errp)error_free (local_err); } + err =pci_bridge_qemu_reserve_cap_init (dev,0 , + bridge_dev->res_reserve, errp); +if (err) { + goto cap_error; + } +if (shpc_present (dev)) {/* TODO: spec recommends using 64 bit prefetcheable BAR. * Check whether that works well. */
@@ -103,6 +111,10 @@ static void pci_bridge_dev_realize(PCIDevice *dev, Error **errp) }return ; +cap_error: +if (msi_present (dev)) { +msi_uninit (dev); + } msi_error:slotid_cap_cleanup (dev); slotid_error:
@@ -116,6 +128,8 @@ shpc_error:static void pci_bridge_dev_exitfn (PCIDevice *dev) {PCIBridgeDev *bridge_dev =PCI_BRIDGE_DEV (dev); + +pci_bridge_qemu_reserve_cap_uninit (dev);if (msi_present (dev)) {msi_uninit (dev); }
@@ -162,6 +176,17 @@ static Property pci_bridge_dev_properties[] = { ON_OFF_AUTO_AUTO),DEFINE_PROP_BIT (PCI_BRIDGE_DEV_PROP_SHPC , PCIBridgeDev, flags,PCI_BRIDGE_DEV_F_SHPC_REQ , true), +DEFINE_PROP_UINT32 ("bus-reserve" , PCIBridgeDev, + res_reserve.bus_reserve,-1 ), +DEFINE_PROP_SIZE ("io-reserve" , PCIBridgeDev, + res_reserve.io_reserve,-1 ), +DEFINE_PROP_SIZE ("mem-reserve" , PCIBridgeDev, + res_reserve.mem_reserve,-1 ), +DEFINE_PROP_SIZE ("pref32-reserve" , PCIBridgeDev, + res_reserve.pref32_reserve,-1 ), +DEFINE_PROP_SIZE ("pref64-reserve" , PCIBridgeDev, + res_reserve.pref64_reserve,-1 ), + DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
1.8.3.1
Hi,
Quoted 22 lines · Jing Liu
This patch serial is about PCI resource reserve capability.
First patch refactors the resource reserve fields in GenPCIERoorPort structure out to another new structure, called "PCIResReserve". Modify the parameter list of
pci_bridge_qemu_reserve_cap_init().Then we add the teardown function called
pci_bridge_qemu_reserve_cap_uninit().Last we enable the resource reserve capability for legacy PCI bridge so that firmware can reserve additional resources for the bridge.
Change Log:
v2 -> v1
* add refactoring patch
* add teardown function
* some other fixesJing Liu (3):
hw/pci: factor PCI reserve resources to a separate structure hw/pci: add teardown function for PCI resource reserve capability hw/pci: add PCI resource reserve capability to legacy PCI bridge
Quoted 6 lines
hw/pci-bridge/gen_pcie_root_port.c | 32 +++++++++++++------------- hw/pci-bridge/pci_bridge_dev.c | 25 ++++++++++++++++++++ hw/pci/pci_bridge.c | 47 +++++++++++++++++++++----------------- include/hw/pci/pci_bridge.h | 18 +++++++++++---- 4 files changed, 80 insertions(+), 42 deletions(-)
just some meta comments for now:
- I've added Marcel; please keep him CC'd on this set (and the SeaBIOS counterpart, [SeaBIOS] [PATCH v2 0/3] pci: resource reserve capability found)
- my task queue has blown up and I'm unsure when I'll get to reviewing this set. The same applies to the SeaBIOS counterpart.
This is just to say that you should feel free to go ahead and work with the (sub)maintainers; I'll try to get back to this as time allows, but don't wait for me.
If further versions are necessary, I'd appreciate being CC'd on those, just so I know what to look at when I find the time again.
Thanks!
Laszlo
Hi Laszlo,
Thanks very much for your reminder.
Looking forward to comments from all!
Thanks,
Jing
Quoted 51 lines · Laszlo Ersek
Hi,
Quoted 22 lines · Jing Liu
This patch serial is about PCI resource reserve capability.
First patch refactors the resource reserve fields in GenPCIERoorPort structure out to another new structure, called "PCIResReserve". Modify the parameter list of
pci_bridge_qemu_reserve_cap_init().Then we add the teardown function called
pci_bridge_qemu_reserve_cap_uninit().Last we enable the resource reserve capability for legacy PCI bridge so that firmware can reserve additional resources for the bridge.
Change Log:
v2 -> v1
* add refactoring patch
* add teardown function
* some other fixesJing Liu (3):
hw/pci: factor PCI reserve resources to a separate structure hw/pci: add teardown function for PCI resource reserve capability hw/pci: add PCI resource reserve capability to legacy PCI bridgeQuoted 6 lines
hw/pci-bridge/gen_pcie_root_port.c | 32 +++++++++++++------------- hw/pci-bridge/pci_bridge_dev.c | 25 ++++++++++++++++++++ hw/pci/pci_bridge.c | 47 +++++++++++++++++++++----------------- include/hw/pci/pci_bridge.h | 18 +++++++++++---- 4 files changed, 80 insertions(+), 42 deletions(-)just some meta comments for now:
- I've added Marcel; please keep him CC'd on this set (and the SeaBIOS counterpart, [SeaBIOS] [PATCH v2 0/3] pci: resource reserve capability found)
- my task queue has blown up and I'm unsure when I'll get to reviewing this set. The same applies to the SeaBIOS counterpart.
This is just to say that you should feel free to go ahead and work with the (sub)maintainers; I'll try to get back to this as time allows, but don't wait for me.
If further versions are necessary, I'd appreciate being CC'd on those, just so I know what to look at when I find the time again.
Thanks!
Laszlo
Re: [Qemu-devel] [PATCH v2 1/3] hw/pci: factor PCI reserve resources to a separate structure
In reply to Jing LiuHi Jing,
Quoted 152 lines · Jing Liu
Factor "
bus_reserve", "io_reserve", "mem_reserve", "pref32_reserve" and "pref64_reserve" fields of the "GenPCIERootPort" structure out to "PCIResReserve" structure, so that other PCI bridges can reuse it to add resource reserve capability.Signed-off-by Jing Liu <[email protected]>--- hw/pci-bridge/gen_pcie_root_port.c | 32 ++++++++++++++++---------------- hw/pci/pci_bridge.c | 38 +++++++++++++++++--------------------- include/hw/pci/pci_bridge.h | 17 ++++++++++++----- 3 files changed, 45 insertions(+), 42 deletions(-)hw/pci-bridge/gen_pcie_root_port.c +16
-16@@ -29,12 +29,7 @@ typedef struct GenPCIERootPort {bool migrate_msix; -/* additional resources to reserve on firmware init */ -uint32_t bus_reserve; -uint64_t io_reserve; -uint64_t mem_reserve; -uint64_t pref32_reserve; -uint64_t pref64_reserve; +PCIResReserve res_reserve; } GenPCIERootPort;static uint8_t gen_rp_aer_vector (const PCIDevice *d)@@ -82,16 +77,15 @@ static void gen_rp_realize(DeviceState *dev, Error **errp)return ; } -int rc =pci_bridge_qemu_reserve_cap_init (d,0 , grp->bus_reserve, - grp->io_reserve, grp->mem_reserve, grp->pref32_reserve, - grp->pref64_reserve, errp); +int rc =pci_bridge_qemu_reserve_cap_init (d,0 , + grp->res_reserve, errp);if (rc <0 ) { rpc->parent_class.exit (d);return ; } -if (!grp->io_reserve) { +if (!grp->res_reserve.io_reserve) {pci_word_test_and_clear_mask (d->wmask +PCI_COMMAND ,PCI_COMMAND_IO ); d->wmask[PCI_IO_BASE ] =0 ;@@ -117,12 +111,18 @@ static const VMStateDescription vmstate_rp_dev = { };static Property gen_rp_props[] = { -DEFINE_PROP_BOOL ("x-migrate-msix" , GenPCIERootPort, migrate_msix, true), -DEFINE_PROP_UINT32 ("bus-reserve" , GenPCIERootPort, bus_reserve,-1 ), -DEFINE_PROP_SIZE ("io-reserve" , GenPCIERootPort, io_reserve,-1 ), -DEFINE_PROP_SIZE ("mem-reserve" , GenPCIERootPort, mem_reserve,-1 ), -DEFINE_PROP_SIZE ("pref32-reserve" , GenPCIERootPort, pref32_reserve,-1 ), -DEFINE_PROP_SIZE ("pref64-reserve" , GenPCIERootPort, pref64_reserve,-1 ), +DEFINE_PROP_BOOL ("x-migrate-msix" , GenPCIERootPort, + migrate_msix, true), +DEFINE_PROP_UINT32 ("bus-reserve" , GenPCIERootPort, + res_reserve.bus_reserve,-1 ), +DEFINE_PROP_SIZE ("io-reserve" , GenPCIERootPort, + res_reserve.io_reserve,-1 ), +DEFINE_PROP_SIZE ("mem-reserve" , GenPCIERootPort, + res_reserve.mem_reserve,-1 ), +DEFINE_PROP_SIZE ("pref32-reserve" , GenPCIERootPort, + res_reserve.pref32_reserve,-1 ), +DEFINE_PROP_SIZE ("pref64-reserve" , GenPCIERootPort, + res_reserve.pref64_reserve,-1 ),DEFINE_PROP_END_OF_LIST () };hw/pci/pci_bridge.c +17
-21@@ -411,38 +411,34 @@ void pci_bridge_map_irq(PCIBridge *br, const char* bus_name,int pci_bridge_qemu_reserve_cap_init (PCIDevice *dev,int cap_offset, -uint32_t bus_reserve,uint64_t io_reserve, -uint64_t mem_non_pref_reserve, -uint64_t mem_pref_32_reserve, -uint64_t mem_pref_64_reserve, -Error **errp) +PCIResReserve res,Error **errp) { -if (mem_pref_32_reserve != (uint64_t )-1 && - mem_pref_64_reserve != (uint64_t )-1 ) { +if (res.pref32_reserve != (uint64_t )-1 && + res.pref64_reserve != (uint64_t )-1 ) {error_setg (errp,"PCI resource reserve cap: PREF32 and PREF64 conflict" );return -EINVAL ; } -if (mem_non_pref_reserve != (uint64_t )-1 && - mem_non_pref_reserve >= (1ULL <<32 )) { +if (res.mem_reserve != (uint64_t )-1 && + res.mem_reserve >= (1ULL <<32 )) {error_setg (errp,"PCI resource reserve cap: mem-reserve must be less than 4G" );return -EINVAL ; } -if (mem_pref_32_reserve != (uint64_t )-1 && - mem_pref_32_reserve >= (1ULL <<32 )) { +if (res.pref32_reserve != (uint64_t )-1 && + res.pref32_reserve >= (1ULL <<32 )) {error_setg (errp,"PCI resource reserve cap: pref32-reserve must be less than 4G" );return -EINVAL ; } -if (bus_reserve == (uint32_t )-1 && - io_reserve == (uint64_t )-1 && - mem_non_pref_reserve == (uint64_t )-1 && - mem_pref_32_reserve == (uint64_t )-1 && - mem_pref_64_reserve == (uint64_t )-1 ) { +if (res.bus_reserve == (uint32_t )-1 && + res.io_reserve == (uint64_t )-1 && + res.mem_reserve == (uint64_t )-1 && + res.pref32_reserve == (uint64_t )-1 && + res.pref64_reserve == (uint64_t )-1 ) {return 0 ; }@@ -450,11 +446,11 @@ int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,PCIBridgeQemuCap cap = { .len = cap_len, .type =REDHAT_PCI_CAP_RESOURCE_RESERVE , - .bus_res = bus_reserve, - .io = io_reserve, - .mem = mem_non_pref_reserve, - .mem_pref_32 = mem_pref_32_reserve, - .mem_pref_64 = mem_pref_64_reserve + .bus_res = res.bus_reserve, + .io = res.io_reserve, + .mem = res.mem_reserve, + .mem_pref_32 = res.pref32_reserve, + .mem_pref_64 = res.pref64_reserve }; int offset = pci_add_capability(dev, PCI_CAP_ID_VNDR,include/hw/pci/pci_bridge.h +0
-0
include/hw/pci/pci_bridge.h typedef struct PCIBridgeQemuCap { · line 142
Quoted 10 lines
include/hw/pci/pci_bridge.h +7
-0@@ -133,11 +133,18 @@ typedef struct PCIBridgeQemuCap {#define REDHAT_PCI_CAP_RESOURCE_RESERVE 1 +/* +* additional resources to reserve on firmware init +*/ +typedef struct PCIResReserve { + uint32_t bus_reserve; + uint64_t io_reserve; + uint64_t mem_reserve;
The patch looks good to me, I noticed you renamed 'mem_no_pref_reserve' to 'mem reserve'.
I remember we had a lot of discussions about the naming, so they would be clear and consistent with the firmware counterpart.
Please add a least a comment in the PCIResReserve. Also, since you encapsulated the fields into a new struct, you could remove the "_reserve" suffix so we remain with clear "bus", "io", "mem" ...
Thanks,
Marcel
Quoted 13 lines
include/hw/pci/pci_bridge.h +5
-5+uint64_t pref32_reserve; + uint64_t pref64_reserve; +} PCIResReserve; +int pci_bridge_qemu_reserve_cap_init (PCIDevice *dev,int cap_offset, -uint32_t bus_reserve,uint64_t io_reserve, -uint64_t mem_non_pref_reserve, -uint64_t mem_pref_32_reserve, -uint64_t mem_pref_64_reserve, -Error **errp); +PCIResReserve res_reserve,Error **errp);#endif /* QEMU_PCI_BRIDGE_H */
Re: [Qemu-devel] [PATCH v2 2/3] hw/pci: add teardown function for PCI resource reserve capability
In reply to Jing LiuHi Jing,
Quoted 13 lines · Jing Liu
Clean up the PCI config space of resource reserve capability.
Signed-off-by Jing Liu <[email protected]>--- hw/pci/pci_bridge.c | 9 +++++++++ include/hw/pci/pci_bridge.h | 1 + 2 files changed, 10 insertions(+)hw/pci/pci_bridge.c +0
-0
hw/pci/pci_bridge.c int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, · line 472
Quoted 8 lines
hw/pci/pci_bridge.c +5
-0@@ -465,6 +465,15 @@ int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset,return 0 ; } +void pci_bridge_qemu_reserve_cap_uninit (PCIDevice *dev) +{ +uint8_t pos =pci_find_capability (dev,PCI_CAP_ID_VNDR ); + +pci_del_capability (dev,PCI_CAP_ID_VNDR ,sizeof (PCIBridgeQemuCap));
I think that you only need to call pci_del_capability,
hw/pci/pci_bridge.c int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, · line 475
Quoted 3 lines
hw/pci/pci_bridge.c +3
-0+memset (dev->config + pos +PCI_CAP_FLAGS ,0 , +sizeof (PCIBridgeQemuCap) -PCI_CAP_FLAGS ); +}
... no need for the above line. The reason is pci_del_capability will "unlink" the capability, and even if the data remains in the configuration space array, it will not be used.
Do you agree? If yes, just call pci_del_capability and you don't need this patch.
Thanks,
Marcel
Quoted 14 lines
hw/pci/pci_bridge.c +1
-0+static const TypeInfo pci_bridge_type_info = { .name =TYPE_PCI_BRIDGE , .parent =TYPE_PCI_DEVICE ,include/hw/pci/pci_bridge.h +1
-0@@ -147,4 +147,5 @@ typedef struct PCIResReserve {int pci_bridge_qemu_reserve_cap_init (PCIDevice *dev,int cap_offset,PCIResReserve res_reserve,Error **errp); +void pci_bridge_qemu_reserve_cap_uninit (PCIDevice *dev);#endif /* QEMU_PCI_BRIDGE_H */
Re: [Qemu-devel] [PATCH v2 3/3] hw/pci: add PCI resource reserve capability to legacy PCI bridge
In reply to Jing LiuHi Jing,
Quoted 35 lines · Jing Liu
Add hint to firmware (e.g. SeaBIOS) to reserve addtional BUS/IO/MEM/PREF resource for legacy pci-pci bridge.
Signed-off-by Jing Liu <[email protected]>--- hw/pci-bridge/pci_bridge_dev.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)hw/pci-bridge/pci_bridge_dev.c +8
-0@@ -46,6 +46,8 @@ struct PCIBridgeDev {uint32_t flags;OnOffAuto msi; + +PCIResReserve res_reserve; };typedef struct PCIBridgeDev PCIBridgeDev ;@@ -95,6 +97,12 @@ static void pci_bridge_dev_realize(PCIDevice *dev, Error **errp)error_free (local_err); } + err =pci_bridge_qemu_reserve_cap_init (dev,0 , + bridge_dev->res_reserve, errp); +if (err) { + goto cap_error; + } +if (shpc_present (dev)) {/* TODO: spec recommends using 64 bit prefetcheable BAR. * Check whether that works well. */
hw/pci-bridge/pci_bridge_dev.c static void pci_bridge_dev_realize(PCIDevice *dev, Error **errp) · line 116
Quoted 6 lines
hw/pci-bridge/pci_bridge_dev.c +3
-0@@ -103,6 +111,10 @@ static void pci_bridge_dev_realize(PCIDevice *dev, Error **errp) }return ; +cap_error: +if (msi_present (dev)) { +msi_uninit (dev);
You were right. Since msi_uninit checks msi_present inside, you don;t need this check, sorry for misleading you.
hw/pci-bridge/pci_bridge_dev.c shpc_error: · line 132
Quoted 10 lines
hw/pci-bridge/pci_bridge_dev.c +3
-0+ } msi_error:slotid_cap_cleanup (dev); slotid_error:@@ -116,6 +128,8 @@ shpc_error:static void pci_bridge_dev_exitfn (PCIDevice *dev) {PCIBridgeDev *bridge_dev =PCI_BRIDGE_DEV (dev); + +pci_bridge_qemu_reserve_cap_uninit (dev);
Here you should have only the "delete_cap" function.
Quoted 11 lines
hw/pci-bridge/pci_bridge_dev.c +4
-0if (msi_present (dev)) {msi_uninit (dev); }@@ -162,6 +176,17 @@ static Property pci_bridge_dev_properties[] = { ON_OFF_AUTO_AUTO),DEFINE_PROP_BIT (PCI_BRIDGE_DEV_PROP_SHPC , PCIBridgeDev, flags,PCI_BRIDGE_DEV_F_SHPC_REQ , true), +DEFINE_PROP_UINT32 ("bus-reserve" , PCIBridgeDev, + res_reserve.bus_reserve,-1 ), +DEFINE_PROP_SIZE ("io-reserve" , PCIBridgeDev, + res_reserve.io_reserve, -1),
hw/pci-bridge/pci_bridge_dev.c static Property pci_bridge_dev_properties[] = { · line 192
Quoted 10 lines
hw/pci-bridge/pci_bridge_dev.c +7
-0+DEFINE_PROP_SIZE ("mem-reserve" , PCIBridgeDev, + res_reserve.mem_reserve,-1 ), +DEFINE_PROP_SIZE ("pref32-reserve" , PCIBridgeDev, + res_reserve.pref32_reserve,-1 ), +DEFINE_PROP_SIZE ("pref64-reserve" , PCIBridgeDev, + res_reserve.pref64_reserve,-1 ), + DEFINE_PROP_END_OF_LIST(), };
Thanks,
Marcel
Hi Jing,
Quoted 10 lines · Jing Liu
This patch serial is about PCI resource reserve capability.
First patch refactors the resource reserve fields in GenPCIERoorPort structure out to another new structure, called "PCIResReserve". Modify the parameter list of
pci_bridge_qemu_reserve_cap_init().Then we add the teardown function called
pci_bridge_qemu_reserve_cap_uninit().Last we enable the resource reserve capability for legacy PCI bridge so that firmware can reserve additional resources for the bridge.
The series looks good to me, please see some minor comments in the patches.
Can you please point me to the SeaBIOS / OVMF counterpart?
Thanks,
Marcel
Quoted 17 lines
Change Log:
v2 -> v1
* add refactoring patch
* add teardown function
* some other fixesJing Liu (3):
hw/pci: factor PCI reserve resources to a separate structure hw/pci: add teardown function for PCI resource reserve capability hw/pci: add PCI resource reserve capability to legacy PCI bridgehw/pci-bridge/gen_pcie_root_port.c | 32 +++++++++++++------------- hw/pci-bridge/pci_bridge_dev.c | 25 ++++++++++++++++++++ hw/pci/pci_bridge.c | 47 +++++++++++++++++++++----------------- include/hw/pci/pci_bridge.h | 18 +++++++++++---- 4 files changed, 80 insertions(+), 42 deletions(-)
Hi Marcel,
Quoted 9 lines · Marcel Apfelbaum
Hi Jing,
Quoted 6 lines · Jing Liu
This patch serial is about PCI resource reserve capability.
First patch refactors the resource reserve fields in GenPCIERoorPort structure out to another new structure, called "PCIResReserve". Modify the parameter list of
pci_bridge_qemu_reserve_cap_init().
Quoted 8 lines
Quoted 4 lines
Then we add the teardown function called
pci_bridge_qemu_reserve_cap_uninit().Last we enable the resource reserve capability for legacy PCI bridge so that firmware can reserve additional resources for the bridge.
The series looks good to me, please see some minor comments in the patches.
Thanks very much for your reviewing. I will improve the codes and send new version then.
Quoted 2 lines
Can you please point me to the SeaBIOS / OVMF counterpart?
Sure. SeaBIOS patch serial is here:
https://patchew.org/Seabios/[email protected]/
Thanks,
Jing
Quoted 23 lines
Thanks,
MarcelQuoted 18 lines
Change Log:
v2 -> v1
* add refactoring patch
* add teardown function
* some other fixesJing Liu (3):
hw/pci: factor PCI reserve resources to a separate structure hw/pci: add teardown function for PCI resource reserve capability hw/pci: add PCI resource reserve capability to legacy PCI bridge
hw/pci-bridge/gen_pcie_root_port.c| 32 +++++++++++++------------- hw/pci-bridge/pci_bridge_dev.c | 25 ++++++++++++++++++++ hw/pci/pci_bridge.c | 47
+++++++++++++++++++++-----------------
include/hw/pci/pci_bridge.h | 18 +++++++++++----4 files changed, 80 insertions(+), 42 deletions(-)
Re: [Qemu-devel] [PATCH v2 2/3] hw/pci: add teardown function for PCI resource reserve capability
In reply to Marcel ApfelbaumHi Marcel,
Quoted 27 lines · Marcel Apfelbaum
Hi Jing,
Quoted 13 lines · Jing Liu
Clean up the PCI config space of resource reserve capability.
Signed-off-by Jing Liu <[email protected]>---
hw/pci/pci_bridge.c | 9 +++++++++
include/hw/pci/pci_bridge.h| 1 +2 files changed, 10 insertions(+)hw/pci/pci_bridge.c +0
-0hw/pci/pci_bridge.c int pci_bridge_qemu_reserve_cap_init(PCIDevice · line 472
Quoted 8 lines
hw/pci/pci_bridge.c +5
-0@@ -465,6 +465,15 @@ int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, return 0; } +void pci_bridge_qemu_reserve_cap_uninit (PCIDevice *dev) +{ + uint8_t pos = pci_find_capability(dev, PCI_CAP_ID_VNDR); + + pci_del_capability(dev, PCI_CAP_ID_VNDR, sizeof(PCIBridgeQemuCap));I think that you only need to call
pci_del_capability,
Quoted 8 lines
hw/pci/pci_bridge.c int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, · line 475
Quoted 3 lines
hw/pci/pci_bridge.c +3
-0+ memset(dev->config + pos + PCI_CAP_FLAGS, 0, + sizeof(PCIBridgeQemuCap) - PCI_CAP_FLAGS); +}... no need for the above line. The reason is
pci_del_capabilitywill "unlink" the capability, and even if the data remains in the configuration space array, it will not be used.
I think I got it: pci_del_capability "unlink" by set the tag pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST; so that pdev->config will not be used, right?
Quoted 3 lines
Do you agree? If yes, just call
pci_del_capabilityand you don't need this patch.
Yup, I agree with you. And let me remove this patch in next version.
Thanks,
Jing
Quoted 4 lines
Thanks,
Marcel
[...]
Re: [Qemu-devel] [PATCH v2 1/3] hw/pci: factor PCI reserve resources to a separate structure
In reply to Marcel ApfelbaumHi Marcel,
Quoted 2 lines · Marcel Apfelbaum
Hi Jing,
[...]
Quoted 4 lines
Quoted 4 lines
include/hw/pci/pci_bridge.h +4
-0+/* +* additional resources to reserve on firmware init +*/ +typedef struct PCIResReserve {
Quoted 9 lines
Quoted 3 lines
+
uint32_tbus_reserve;
+uint64_tio_reserve;
+uint64_tmem_reserve;The patch looks good to me, I noticed you renamed '
mem_no_pref_reserve' to 'mem reserve'.
I remember we had a lot of discussions about the naming, so they would be clear and consistent with the firmware counterpart.
OK, will change 'mem_no_pref_reserve' to 'mem_no_pref' and also for others.
Quoted 1 line
Please add a least a comment in the PCIResReserve.
Will add a comment to the structure definition, and where it's called.
Quoted 4 lines
Also, since you encapsulated the fields into a new struct, you could remove the "
_reserve" suffix so we remain with clear "bus", "io", "mem" ...
Got it.
Thanks,
Jing
Quoted 16 lines
Thanks,
MarcelQuoted 12 lines
+
uint64_tpref32_reserve;
+uint64_tpref64_reserve;include/hw/pci/pci_bridge.h +2
-0+} PCIResReserve; +int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int
cap_offset, -uint32_tbus_reserve,uint64_tio_reserve, -uint64_tmem_non_pref_reserve, -uint64_tmem_pref_32_reserve, -uint64_tmem_pref_64_reserve, - Error **errp);
+ PCIResReserveres_reserve, Error **errp); #endif /*QEMU_PCI_BRIDGE_H*/
Re: [Qemu-devel] [PATCH v2 2/3] hw/pci: add teardown function for PCI resource reserve capability
In reply to Liu, Jing2Hi Jing,
Quoted 35 lines · On 08/20/2018 05:58 AM, Liu, Jing2 wrote:
Hi Marcel,
Quoted 32 lines · Marcel Apfelbaum
Hi Jing,
Quoted 13 lines · Jing Liu
Clean up the PCI config space of resource reserve capability.
Signed-off-by Jing Liu <[email protected]>---
hw/pci/pci_bridge.c | 9 +++++++++
include/hw/pci/pci_bridge.h| 1 +2 files changed, 10 insertions(+)hw/pci/pci_bridge.c +0
-0hw/pci/pci_bridge.c int pci_bridge_qemu_reserve_cap_init(PCIDevice · line 473
Quoted 9 lines
hw/pci/pci_bridge.c +5
-0@@ -465,6 +465,15 @@ int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, return 0; } +void pci_bridge_qemu_reserve_cap_uninit (PCIDevice *dev) +{ + uint8_t pos = pci_find_capability(dev, PCI_CAP_ID_VNDR); + + pci_del_capability(dev, PCI_CAP_ID_VNDR,sizeof (PCIBridgeQemuCap));I think that you only need to call
pci_del_capability,Quoted 3 lines
hw/pci/pci_bridge.c +3
-0+ memset(dev->config + pos + PCI_CAP_FLAGS, 0, + sizeof(PCIBridgeQemuCap) - PCI_CAP_FLAGS); +}
Quoted 7 lines
Quoted 4 lines
... no need for the above line. The reason is
pci_del_capabilitywill "unlink" the capability, and even if the data remains in the configuration space array, it will not be used.I think I got it:
pci_del_capability"unlink" by set the tag pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST; so thatpdev->configwill not be used, right?
If is the latest capability in the list, yes.
Otherwise it will simply link 'prev' with 'next' using config array offsets.
Thanks,
Marcel
Quoted 15 lines
Quoted 4 lines
Do you agree? If yes, just call
pci_del_capabilityand you don't need this patch.Yup, I agree with you. And let me remove this patch in next version.
Thanks,
JingQuoted 4 lines
Thanks,
Marcel[...]
Re: [Qemu-devel] [PATCH v2 2/3] hw/pci: add teardown function for PCI resource reserve capability
Hi Marcel,
Quoted 42 lines · Marcel Apfelbaum
Hi Jing,
Quoted 39 lines · On 08/20/2018 05:58 AM, Liu, Jing2 wrote:
Hi Marcel,
Quoted 36 lines · Marcel Apfelbaum
Hi Jing,
Quoted 13 lines · Jing Liu
Clean up the PCI config space of resource reserve capability.
Signed-off-by Jing Liu <[email protected]>---
hw/pci/pci_bridge.c | 9 +++++++++
include/hw/pci/pci_bridge.h| 1 +2 files changed, 10 insertions(+)hw/pci/pci_bridge.c +0
-0hw/pci/pci_bridge.c int pci_bridge_qemu_reserve_cap_init(PCIDevice · line 473
Quoted 9 lines
hw/pci/pci_bridge.c +5
-0@@ -465,6 +465,15 @@ int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, return 0; } +void pci_bridge_qemu_reserve_cap_uninit (PCIDevice *dev) +{ + uint8_t pos = pci_find_capability(dev, PCI_CAP_ID_VNDR); + + pci_del_capability(dev, PCI_CAP_ID_VNDR,sizeof (PCIBridgeQemuCap));I think that you only need to call
pci_del_capability,hw/pci/pci_bridge.c int pci_bridge_qemu_reserve_cap_init(PCIDevice *dev, int cap_offset, · line 475
Quoted 3 lines
hw/pci/pci_bridge.c +3
-0+ memset(dev->config + pos + PCI_CAP_FLAGS, 0, + sizeof(PCIBridgeQemuCap) - PCI_CAP_FLAGS); +}... no need for the above line. The reason is
pci_del_capabilitywill "unlink" the capability, and even if the data remains in the configuration space array, it will not be used.
Quoted 6 lines
Quoted 3 lines
I think I got it:
pci_del_capability"unlink" by set the tag pdev->config[PCI_STATUS] &= ~PCI_STATUS_CAP_LIST; so thatpdev->configwill not be used, right?If is the latest capability in the list, yes.
Otherwise it will simply link 'prev' with 'next' using config array offsets.
I got it! Thanks very much for the details!
Jing
Quoted 20 lines
Thanks,
MarcelQuoted 15 lines
Quoted 4 lines
Do you agree? If yes, just call
pci_del_capabilityand you don't need this patch.Yup, I agree with you. And let me remove this patch in next version.
Thanks,
JingQuoted 4 lines
Thanks,
Marcel[...]