pci: split out bridge code into pci_bridge
cover pci: split out bridge code into pci_bridge
Now pci.c has grown. So split bridge related code into dedicated file for further extension to pci bridge. Further clean up and pcie port emulator. This make patch conflict less possible in future.
Isaku Yamahata (2):
pci/bridge: allocate PCIBus dynamically for PCIBridge. pci/bridge: split out pci bridge code into pci_bridge.c from pci.c
Makefile.objs | 2 +- hw/apb_pci.c | 1 + hw/dec_pci.c | 1 + hw/pci.c | 177 ++++------------------------------------------------- hw/pci.h | 9 ++- hw/pci_bridge.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pci_bridge.h | 41 ++++++++++++ 7 files changed, 247 insertions(+), 168 deletions(-) create mode 100644 hw/pci_bridge.c create mode 100644 hw/pci_bridge.h
PATCH 1/2 pci/bridge: allocate PCIBus dynamically for PCIBridge.
allocate PCIBus dynamically for PCIBridge and bug fix of pci_unregister_secondary_bus().
This is a preparation for splitting out pci_bridge functions. Since PCIBus is private to pci.c, PCIBridge won't be able to contain PCIBus in its structure.
--- hw/pci.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)
hw/pci.c +14 -11
@@ -286,23 +286,27 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,return bus; } -static void pci_register_secondary_bus (PCIBus *parent, -PCIBus *bus, -PCIDevice *dev, -pci_map_irq_fn map_irq, -const char *name) +static PCIBus *pci_register_secondary_bus (PCIBus *parent, +PCIDevice *dev, +pci_map_irq_fn map_irq, +const char *name) { -qbus_create_inplace (&bus->qbus, &pci_bus_info, &dev->qdev, name); +PCIBus *bus; + bus =pci_bus_new (&dev->qdev, name,0 ); + bus->map_irq = map_irq; bus->parent_dev = dev;QLIST_INSERT_HEAD (&parent->child, bus, sibling); + +return bus; }static void pci_unregister_secondary_bus (PCIBus *bus) {assert (QLIST_EMPTY (&bus->child));QLIST_REMOVE (bus, sibling); +qbus_free (&bus->qbus); }int pci_bus_num (PCIBus *s)
@@ -1527,7 +1531,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,typedef struct {PCIDevice dev; -PCIBus bus; +PCIBus *bus;uint32_t vid;uint32_t did; }PCIBridge ;
@@ -1628,8 +1632,7 @@ static int pci_bridge_initfn(PCIDevice *dev)static int pci_bridge_exitfn (PCIDevice *pci_dev) {PCIBridge *s =DO_UPCAST (PCIBridge, dev, pci_dev); -PCIBus *bus = &s->bus; -pci_unregister_secondary_bus (bus); +pci_unregister_secondary_bus (s->bus);return 0 ; }
@@ -1646,8 +1649,8 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, bool multifunction,qdev_init_nofail (&dev->qdev); s =DO_UPCAST (PCIBridge, dev, dev); -pci_register_secondary_bus (bus, &s->bus, &s->dev, map_irq, name); -return &s->bus; + s->bus =pci_register_secondary_bus (bus, &s->dev, map_irq, name); +return s->bus; }PCIDevice *pci_bridge_get_device (PCIBus *bus)
Signature · 1 line
1.7.1.1
PATCH 2/2 pci/bridge: split out pci bridge code into pci_bridge.c from pci.c
In reply to Isaku YamahataMove pci bridge related code into pci_bridge.c from pci.c for further enhancement. pci.c is big enough now, so split it out. No code change but exporting some accesser functions.
In fact, some of pci bridge functions stays in pci.c because it accesses to PCIBus member. Unstatic the accessor functions and use them from pci_bridge.c
--- Makefile.objs | 2 +- hw/apb_pci.c | 1 + hw/dec_pci.c | 1 + hw/pci.c | 168 ++------------------------------------------------ hw/pci.h | 9 ++- hw/pci_bridge.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/pci_bridge.h | 41 ++++++++++++ 7 files changed, 241 insertions(+), 165 deletions(-) create mode 100644 hw/pci_bridge.c create mode 100644 hw/pci_bridge.h
Makefile.objs +1 -1
@@ -139,7 +139,7 @@ user-obj-y += cutils.o cache-utils.o hw-obj-y = hw-obj-y += vl.o loader.o hw-obj-y += virtio.o virtio-console.o -hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o +hw-obj-y += fw_cfg.o pci.o pci_host.o pcie_host.o pci_bridge.o hw-obj-y += watchdog.o hw-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o hw-obj-$(CONFIG_ECC) += ecc.o
hw/apb_pci.c +1 -0
@@ -29,6 +29,7 @@#include "sysbus.h" #include "pci.h" #include "pci_host.h" +#include "pci_bridge.h" #include "rwhandler.h" #include "apb_pci.h" #include "sysemu.h"
hw/dec_pci.c +1 -0
@@ -27,6 +27,7 @@#include "sysbus.h" #include "pci.h" #include "pci_host.h" +#include "pci_bridge.h" /* debug DEC */ //#define DEBUG_DEC
hw/pci.c +7 -161
218 lines not on this page · raw message
hw/pci.h +6 -3
@@ -213,6 +213,11 @@ void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *dev);PCIBus *pci_register_bus (DeviceState *parent,const char *name,pci_set_irq_fn set_irq,pci_map_irq_fn map_irq,void *irq_opaque,int devfn_min,int nirq); +PCIBus *pci_register_secondary_bus (PCIBus *parent, +PCIDevice *dev, +pci_map_irq_fn map_irq, +const char *name); +void pci_unregister_secondary_bus (PCIBus *bus);void pci_bus_set_mem_base (PCIBus *bus,target_phys_addr_t base);
@@ -234,10 +239,8 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,void do_pci_info_print (Monitor *mon,const QObject *data);void do_pci_info (Monitor *mon,QObject **ret_data); -PCIBus *pci_bridge_init (PCIBus *bus,int devfn,bool multifunction, -uint16_t vid,uint16_t did, -pci_map_irq_fn map_irq,const char *name);PCIDevice *pci_bridge_get_device (PCIBus *bus); +void pci_bridge_update_mappings (PCIBus *b);static inline void pci_set_byte (uint8_t *config,uint8_t val)
hw/pci_bridge.c new file +184 -0
184 lines not on this page · raw message
hw/pci_bridge.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.7.1.1
[Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
In reply to Isaku YamahataQuoted 2 lines · Isaku Yamahata
allocate PCIBus dynamically for PCIBridge and bug fix of
pci_unregister_secondary_bus().
could you make the bugfix a separate patch please?
Quoted 5 lines
This is a preparation for splitting out
pci_bridgefunctions. Since PCIBus is private topci.c, PCIBridge won't be able to contain PCIBus in its structure.Signed-off-by Isaku Yamahata <[email protected]>
I think this becomes too complex: as bridge configuration affects the bus operation, you might end up sticking a pointer to the device in the bus. A similar arrangement is in place in with piix_pci, and I would love to get rid of it, too.
Let's just put PCIBus in a header? It could be a new header named pci_internals.h or something like this.
Quoted 22 lines
--- hw/pci.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)hw/pci.c +4
-5@@ -286,23 +286,27 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,return bus; } -static void pci_register_secondary_bus (PCIBus *parent, -PCIBus *bus, -PCIDevice *dev, -pci_map_irq_fn map_irq, -const char *name) +static PCIBus *pci_register_secondary_bus (PCIBus *parent, +PCIDevice *dev, +pci_map_irq_fn map_irq, +const char *name) {
hw/pci.c PCIBus *pci_register_bus(DeviceState *parent, const char *name, · line 302
Quoted 10 lines
hw/pci.c +5
-1-qbus_create_inplace (&bus->qbus, &pci_bus_info, &dev->qdev, name); +PCIBus *bus; + bus =pci_bus_new (&dev->qdev, name,0 ); + bus->map_irq = map_irq; bus->parent_dev = dev;QLIST_INSERT_HEAD (&parent->child, bus, sibling); + +return bus;
This does more than we need: pci_bus_new
was created for host bus so it will also register in reset and vmstate lists.
Quoted 42 lines
hw/pci.c +5
-5}static void pci_unregister_secondary_bus (PCIBus *bus) {assert (QLIST_EMPTY (&bus->child));QLIST_REMOVE (bus, sibling); +qbus_free (&bus->qbus); }int pci_bus_num (PCIBus *s)@@ -1527,7 +1531,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,typedef struct {PCIDevice dev; -PCIBus bus; +PCIBus *bus;uint32_t vid;uint32_t did; }PCIBridge ;@@ -1628,8 +1632,7 @@ static int pci_bridge_initfn(PCIDevice *dev)static int pci_bridge_exitfn (PCIDevice *pci_dev) {PCIBridge *s =DO_UPCAST (PCIBridge, dev, pci_dev); -PCIBus *bus = &s->bus; -pci_unregister_secondary_bus (bus); +pci_unregister_secondary_bus (s->bus);return 0 ; }@@ -1646,8 +1649,8 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, bool multifunction,qdev_init_nofail (&dev->qdev); s =DO_UPCAST (PCIBridge, dev, dev); -pci_register_secondary_bus (bus, &s->bus, &s->dev, map_irq, name); -return &s->bus; + s->bus =pci_register_secondary_bus (bus, &s->dev, map_irq, name); +return s->bus; }PCIDevice *pci_bridge_get_device (PCIBus *bus)Signature · 1 line
1.7.1.1
[Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Isaku Yamahata
allocate PCIBus dynamically for PCIBridge and bug fix of
pci_unregister_secondary_bus().could you make the bugfix a separate patch please?
Will do.
Quoted 10 lines
Quoted 5 lines
This is a preparation for splitting out
pci_bridgefunctions. Since PCIBus is private topci.c, PCIBridge won't be able to contain PCIBus in its structure.Signed-off-by Isaku Yamahata <[email protected]>I think this becomes too complex: as bridge configuration affects the bus operation, you might end up sticking a pointer to the device in the bus. A similar arrangement is in place in with
piix_pci, and I would love to get rid of it, too.
I'd glad to look into it, but I'd like to make it sure before digging into it.
Do you mean i440fx_init() and I440FXState::bus = PCIHostState::bus? Please a bit more concrete explanation.
Quoted 2 lines
Let's just put PCIBus in a header? It could be a new header named
pci_internals.hor something like this.
Sounds a good idea. In fact I had thought the same idea. I'll go for that way.
Quoted 29 lines
Quoted 29 lines
--- hw/pci.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)hw/pci.c +7
-6@@ -286,23 +286,27 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,return bus; } -static void pci_register_secondary_bus (PCIBus *parent, -PCIBus *bus, -PCIDevice *dev, -pci_map_irq_fn map_irq, -const char *name) +static PCIBus *pci_register_secondary_bus (PCIBus *parent, +PCIDevice *dev, +pci_map_irq_fn map_irq, +const char *name) { -qbus_create_inplace (&bus->qbus, &pci_bus_info, &dev->qdev, name); +PCIBus *bus; + bus =pci_bus_new (&dev->qdev, name,0 ); + bus->map_irq = map_irq; bus->parent_dev = dev;
Quoted 7 lines
hw/pci.c PCIBus *pci_register_bus(DeviceState *parent, const char *name, · line 302
Quoted 3 lines
hw/pci.c +2
-0QLIST_INSERT_HEAD (&parent->child, bus, sibling); + +return bus;This does more than we need:
pci_bus_new
was created for host bus so it will also register in reset and vmstate lists.
I'm bit confused. I've thought that pci_bus_new() was for both root bus and secondary bus. So I've tried to move out root bus specific stuff from pci_bus_new().
But you claim it's only for root bus, not for secondary bus. Now I realized why you've rejected such patches so far. Then, you also mean the current pci_register_secondary_bus() is broken. I also think it's broken. So how do we want to fix it?
My idea is as follows.
- introduce something like pci_secondary_bus_new() (pci_sec_bus_new() for short?) for secondary bus. fix pci_register_secondary_bus() with it.
- introduce something like pci_host_bus_new() (or pci_root_bus_new()?) for pci host bus which is more generic than pci_bus_new(). It's for
- to avoid confusion.
- to eliminate assumption of pci_bus_new().
pci_bus_new() assumes that its pci segment is 0.
keep pci_bus_new() as a convenience wrapper of pci_host_bus_new(segment = 0). Thus we can avoid fixing up all the caller.
Quoted 43 lines
Quoted 42 lines
hw/pci.c +5
-5}static void pci_unregister_secondary_bus (PCIBus *bus) {assert (QLIST_EMPTY (&bus->child));QLIST_REMOVE (bus, sibling); +qbus_free (&bus->qbus); }int pci_bus_num (PCIBus *s)@@ -1527,7 +1531,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,typedef struct {PCIDevice dev; -PCIBus bus; +PCIBus *bus;uint32_t vid;uint32_t did; }PCIBridge ;@@ -1628,8 +1632,7 @@ static int pci_bridge_initfn(PCIDevice *dev)static int pci_bridge_exitfn (PCIDevice *pci_dev) {PCIBridge *s =DO_UPCAST (PCIBridge, dev, pci_dev); -PCIBus *bus = &s->bus; -pci_unregister_secondary_bus (bus); +pci_unregister_secondary_bus (s->bus);return 0 ; }@@ -1646,8 +1649,8 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, bool multifunction,qdev_init_nofail (&dev->qdev); s =DO_UPCAST (PCIBridge, dev, dev); -pci_register_secondary_bus (bus, &s->bus, &s->dev, map_irq, name); -return &s->bus; + s->bus =pci_register_secondary_bus (bus, &s->dev, map_irq, name); +return s->bus; }PCIDevice *pci_bridge_get_device (PCIBus *bus)Signature · 1 line
1.7.1.1
Signature · 1 line
yamahata
[Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
Quoted 21 lines · Isaku Yamahata
Quoted 5 lines · Michael S. Tsirkin
Quoted 2 lines · Isaku Yamahata
allocate PCIBus dynamically for PCIBridge and bug fix of
pci_unregister_secondary_bus().could you make the bugfix a separate patch please?
Will do.
Quoted 10 lines
Quoted 5 lines
This is a preparation for splitting out
pci_bridgefunctions. Since PCIBus is private topci.c, PCIBridge won't be able to contain PCIBus in its structure.Signed-off-by Isaku Yamahata <[email protected]>I think this becomes too complex: as bridge configuration affects the bus operation, you might end up sticking a pointer to the device in the bus. A similar arrangement is in place in with
piix_pci, and I would love to get rid of it, too.
Quoted 4 lines
I'd glad to look into it, but I'd like to make it sure before digging into it.
Do you meani440fx_init()andI440FXState::bus=PCIHostState::bus? Please a bit more concrete explanation.
I am not sure myself yet. Generally I'm not very happy with how interrupts are handled.
Specifically:
- lots of indirect calls through qemu_irq
not type-safe, hard to debug and can not be good for performance need to find a way to chase these pointers at setup time
- lots of loops over irq pins and over buses
need to precompute and store at setup time, and use bits for booleans
- information is duplicated, e.g. piix duplicates irq states need to use from a single place
with the last issue, be careful not to break migration:
we need to compute and store old data on migration
In case of piix_pci interrupts are controlled through PIIX3 device, so we create the host bus, the device on it, and finally make another call to make interrupts on the bus get device as the opaque pointer. All this looks very convoluted.
Quoted 114 lines
Quoted 3 lines
Let's just put PCIBus in a header? It could be a new header named
pci_internals.hor something like this.Sounds a good idea. In fact I had thought the same idea. I'll go for that way.
Quoted 29 lines
Quoted 29 lines
--- hw/pci.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)hw/pci.c +7
-6@@ -286,23 +286,27 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,return bus; } -static void pci_register_secondary_bus (PCIBus *parent, -PCIBus *bus, -PCIDevice *dev, -pci_map_irq_fn map_irq, -const char *name) +static PCIBus *pci_register_secondary_bus (PCIBus *parent, +PCIDevice *dev, +pci_map_irq_fn map_irq, +const char *name) { -qbus_create_inplace (&bus->qbus, &pci_bus_info, &dev->qdev, name); +PCIBus *bus; + bus =pci_bus_new (&dev->qdev, name,0 ); + bus->map_irq = map_irq; bus->parent_dev = dev;Quoted 7 lines
hw/pci.c PCIBus *pci_register_bus(DeviceState *parent, const char *name, · line 302
Quoted 3 lines
hw/pci.c +2
-0QLIST_INSERT_HEAD (&parent->child, bus, sibling); + +return bus;This does more than we need:
pci_bus_new
was created for host bus so it will also register in reset and vmstate lists.I'm bit confused. I've thought that
pci_bus_new()was for both root bus and secondary bus. So I've tried to move out root bus specific stuff frompci_bus_new().But you claim it's only for root bus, not for secondary bus. Now I realized why you've rejected such patches so far. Then, you also mean the current
pci_register_secondary_bus()is broken. I also think it's broken. So how do we want to fix it?
My idea is as follows.- introduce something like
pci_secondary_bus_new()(pci_sec_bus_new()for short?) for secondary bus. fixpci_register_secondary_bus()with it.- introduce something like
pci_host_bus_new()(orpci_root_bus_new()?) for pci host bus which is more generic thanpci_bus_new(). It's for
- to avoid confusion.
- to eliminate assumption ofpci_bus_new().
pci_bus_new()assumes that its pci segment is 0.
keeppci_bus_new()as a convenience wrapper ofpci_host_bus_new(segment = 0). Thus we can avoid fixing up all the caller.Quoted 43 lines
Quoted 42 lines
hw/pci.c +5
-5}static void pci_unregister_secondary_bus (PCIBus *bus) {assert (QLIST_EMPTY (&bus->child));QLIST_REMOVE (bus, sibling); +qbus_free (&bus->qbus); }int pci_bus_num (PCIBus *s)@@ -1527,7 +1531,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, const char *default_model,typedef struct {PCIDevice dev; -PCIBus bus; +PCIBus *bus;uint32_t vid;uint32_t did; }PCIBridge ;@@ -1628,8 +1632,7 @@ static int pci_bridge_initfn(PCIDevice *dev)static int pci_bridge_exitfn (PCIDevice *pci_dev) {PCIBridge *s =DO_UPCAST (PCIBridge, dev, pci_dev); -PCIBus *bus = &s->bus; -pci_unregister_secondary_bus (bus); +pci_unregister_secondary_bus (s->bus);return 0 ; }@@ -1646,8 +1649,8 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, bool multifunction,qdev_init_nofail (&dev->qdev); s =DO_UPCAST (PCIBridge, dev, dev); -pci_register_secondary_bus (bus, &s->bus, &s->dev, map_irq, name); -return &s->bus; + s->bus =pci_register_secondary_bus (bus, &s->dev, map_irq, name); +return s->bus; }PCIDevice *pci_bridge_get_device (PCIBus *bus)Signature · 1 line
1.7.1.1Signature · 1 line
yamahata
Re: [Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
Quoted 24 lines · Michael S. Tsirkin
Quoted 9 lines
Quoted 4 lines
I think this becomes too complex: as bridge configuration affects the bus operation, you might end up sticking a pointer to the device in the bus. A similar arrangement is in place in with
piix_pci, and I would love to get rid of it, too.I'd glad to look into it, but I'd like to make it sure before digging into it.
Do you meani440fx_init()andI440FXState::bus=PCIHostState::bus? Please a bit more concrete explanation.I am not sure myself yet. Generally I'm not very happy with how interrupts are handled.
Specifically:
- lots of indirect calls throughqemu_irq
not type-safe, hard to debug and can not be good for performance need to find a way to chase these pointers at setup time
- lots of loops over irq pins and over buses
need to precompute and store at setup time, and use bits for booleans
- information is duplicated, e.g. piix duplicates irq states need to use from a single place
with the last issue, be careful not to break migration:
we need to compute and store old data on migration
Quoted 4 lines
In case of
piix_pciinterrupts are controlled through PIIX3 device, so we create the host bus, the device on it, and finally make another call to make interrupts on the bus get device as the opaque pointer. All this looks very convoluted.
I see, it's concern about over all piix_pci.
Can you please comment on pci_bus_new() issue below? I'm afraid that you missed it.
Quoted 60 lines
Quoted 60 lines
Quoted 29 lines
Quoted 29 lines
--- hw/pci.c | 25 ++++++++++++++----------- 1 files changed, 14 insertions(+), 11 deletions(-)hw/pci.c +7
-6@@ -286,23 +286,27 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,return bus; } -static void pci_register_secondary_bus (PCIBus *parent, -PCIBus *bus, -PCIDevice *dev, -pci_map_irq_fn map_irq, -const char *name) +static PCIBus *pci_register_secondary_bus (PCIBus *parent, +PCIDevice *dev, +pci_map_irq_fn map_irq, +const char *name) { -qbus_create_inplace (&bus->qbus, &pci_bus_info, &dev->qdev, name); +PCIBus *bus; + bus =pci_bus_new (&dev->qdev, name,0 ); + bus->map_irq = map_irq; bus->parent_dev = dev;Quoted 7 lines
hw/pci.c PCIBus *pci_register_bus(DeviceState *parent, const char *name, · line 302
Quoted 3 lines
hw/pci.c +2
-0QLIST_INSERT_HEAD (&parent->child, bus, sibling); + +return bus;This does more than we need:
pci_bus_new
was created for host bus so it will also register in reset and vmstate lists.I'm bit confused. I've thought that
pci_bus_new()was for both root bus and secondary bus. So I've tried to move out root bus specific stuff frompci_bus_new().But you claim it's only for root bus, not for secondary bus. Now I realized why you've rejected such patches so far. Then, you also mean the current
pci_register_secondary_bus()is broken. I also think it's broken. So how do we want to fix it?
My idea is as follows.- introduce something like
pci_secondary_bus_new()(pci_sec_bus_new()for short?) for secondary bus. fixpci_register_secondary_bus()with it.- introduce something like
pci_host_bus_new()(orpci_root_bus_new()?) for pci host bus which is more generic thanpci_bus_new(). It's for
- to avoid confusion.
- to eliminate assumption ofpci_bus_new().
pci_bus_new()assumes that its pci segment is 0.
keeppci_bus_new()as a convenience wrapper ofpci_host_bus_new(segment = 0). Thus we can avoid fixing up all the caller.
Signature · 1 line
yamahata
[Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
In reply to Isaku YamahataQuoted 1 line · Isaku Yamahata
But you claim it's only for root bus, not for secondary bus.
It is currently, isn't it?
Quoted 2 lines
Now I realized why you've rejected such patches so far. Then, you also mean the current
pci_register_secondary_bus()is broken.
Sorry about being dense, what is broken?
Quoted 11 lines
I also think it's broken. So how do we want to fix it? My idea is as follows.
- introduce something like
pci_secondary_bus_new()(pci_sec_bus_new()for short?) for secondary bus. fixpci_register_secondary_bus()with it.- introduce something like
pci_host_bus_new()(orpci_root_bus_new()?) for pci host bus which is more generic thanpci_bus_new(). It's for
- to avoid confusion.
IMHO the confusion comes from the fact we have too many functions that do almost, but not quite, the same thing, and the function names do not say anything.
We have a ton of 5 line functions with names like_allocate_inplace, _new, _register, _simple
Quoted 5 lines
- to eliminate assumption of
pci_bus_new().pci_bus_new()assumes that its pci segment is 0. keeppci_bus_new()as a convenience wrapper ofpci_host_bus_new(segment = 0). Thus we can avoid fixing up all the caller.
We have a single caller, right? I think you mean pci_register_bus? So IIUC, you propose that we add pci_register_host_bus, and make pci_register_bus a compatibility wrapper? Sure, let's just add a comment this is deprecated.
I am not sure why do we need an API to deal with secondary bus:
it is always a part of the bridge, so all users can and should call pci_bridge_init?
Signature · 1 line
MST
Re: [Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
Quoted 9 lines · Michael S. Tsirkin
Quoted 1 line · Isaku Yamahata
But you claim it's only for root bus, not for secondary bus.
It is currently, isn't it?
Quoted 2 lines
Now I realized why you've rejected such patches so far. Then, you also mean the current
pci_register_secondary_bus()is broken.Sorry about being dense, what is broken?
I've regarded pci_bus_new() (or _inplace) as new qdev style API. And pci_register_bus() (or pci_register_secondary_bus()) as old (so deprecated) API.
So pci_reguster_bus() would be replaced with pci_bus_new() gradually like the changeset of 7cd9eee0f6fd6953114068dd98d91fca1237880b I've thought that pci_bus_new() is for both root and secondary bus. However, according to your comment, the situation seems different.
Quoted 12 lines
Quoted 11 lines
I also think it's broken. So how do we want to fix it? My idea is as follows.
- introduce something like
pci_secondary_bus_new()(pci_sec_bus_new()for short?) for secondary bus. fixpci_register_secondary_bus()with it.- introduce something like
pci_host_bus_new()(orpci_root_bus_new()?) for pci host bus which is more generic thanpci_bus_new(). It's for
- to avoid confusion.
Quoted 6 lines
IMHO the confusion comes from the fact we have too many functions that do almost, but not quite, the same thing, and the function names do not say anything.
We have a ton of 5 line functions with names like
_allocate_inplace,_new,_register,_simple
Fully Agreed. Some clean up is necessary.
Quoted 6 lines
Quoted 5 lines
- to eliminate assumption of
pci_bus_new().pci_bus_new()assumes that its pci segment is 0. keeppci_bus_new()as a convenience wrapper ofpci_host_bus_new(segment = 0). Thus we can avoid fixing up all the caller.
Quoted 8 lines
We have a single caller, right? I think you mean
pci_register_bus? So IIUC, you propose that we addpci_register_host_bus, and makepci_register_busa compatibility wrapper? Sure, let's just add a comment this is deprecated.I am not sure why do we need an API to deal with secondary bus:
it is always a part of the bridge, so all users can and should callpci_bridge_init?
Okay, then how about the following?
For root bus:
- pci_host_bus_new()/pci_host_bus_new_inplace()
qbus style api. pci segment must be specified.
New code should use this.
- pci_bus_new()
qbus style API.
convenience wrapper for compatibility of pci_host_bus_new(pci segment = 0)
In fact, the only current user piix_pci.c. It's easy to remove it.
- pci_register_bus()
old style API. deprecated.
It has been kept for compatibility so far. This will be gradually replaced with pci_host_bus_new()
For secondary bus:
- pci_bridge_init()
qdev style API.
New code should use this.
- pci_{register, unregister}_secondary_bus():
old stype API. deprecated.
Keep them only for internal use in pci.c
or they can be easily removed or renamed for qdev style.
For pci device:
- pci_create()
qdev style API.
The transitional function until completion of qdev conversion. If the creation of a device tree from config file is implemented, this function will be unnecessary.
- pci_create_simple()
qdev style API.
convenience function = pci_create() + qdev_init_nofail()
Signature · 1 line
yamahata
Re: [Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
Quoted 4 lines · Isaku Yamahata
Quoted 3 lines · Michael S. Tsirkin
Quoted 1 line · Isaku Yamahata
But you claim it's only for root bus, not for secondary bus.
Quoted 8 lines
Quoted 6 lines
It is currently, isn't it?
Quoted 2 lines
Now I realized why you've rejected such patches so far. Then, you also mean the current
pci_register_secondary_bus()is broken.Sorry about being dense, what is broken?
I've regarded
pci_bus_new()(or_inplace) as new qdev style API.
The names are pretty bad btw, aren't they? Would pci_bus_init/pci_bus_cleanup be better? And whoever wants to allocate memory, can do it with malloc, right?
Quoted 6 lines
And
pci_register_bus()(orpci_register_secondary_bus()) as old (so deprecated) API.
Sopci_reguster_bus()would be replaced withpci_bus_new()gradually like the changeset of7cd9eee0f6fd6953114068dd98d91fca1237880bI've thought thatpci_bus_new()is for both root and secondary bus. However, according to your comment, the situation seems different.
Forget my comment, it's different according to the code, isn't it?
Quoted 37 lines
Quoted 12 lines
Quoted 11 lines
I also think it's broken. So how do we want to fix it? My idea is as follows.
- introduce something like
pci_secondary_bus_new()(pci_sec_bus_new()for short?) for secondary bus. fixpci_register_secondary_bus()with it.- introduce something like
pci_host_bus_new()(orpci_root_bus_new()?) for pci host bus which is more generic thanpci_bus_new(). It's for
- to avoid confusion.Quoted 6 lines
IMHO the confusion comes from the fact we have too many functions that do almost, but not quite, the same thing, and the function names do not say anything.
We have a ton of 5 line functions with names like
_allocate_inplace,_new,_register,_simpleFully Agreed. Some clean up is necessary.
Quoted 6 lines
Quoted 5 lines
- to eliminate assumption of
pci_bus_new().pci_bus_new()assumes that its pci segment is 0. keeppci_bus_new()as a convenience wrapper ofpci_host_bus_new(segment = 0). Thus we can avoid fixing up all the caller.Quoted 8 lines
We have a single caller, right? I think you mean
pci_register_bus? So IIUC, you propose that we addpci_register_host_bus, and makepci_register_busa compatibility wrapper? Sure, let's just add a comment this is deprecated.I am not sure why do we need an API to deal with secondary bus:
it is always a part of the bridge, so all users can and should callpci_bridge_init?
Quoted 6 lines
Okay, then how about the following?
For root bus:
- pci_host_bus_new()/pci_host_bus_new_inplace()
qbus style api. pci segment must be specified.
New code should use this.
I'd prefer a simple _init which works like _inplace. Allocating memory is simple enough for users.
Quoted 9 lines
-
pci_bus_new()
qbus style API.
convenience wrapper for compatibility ofpci_host_bus_new(pci segment = 0)
In fact, the only current userpiix_pci.c. It's easy to remove it.
-pci_register_bus()
old style API. deprecated.
It has been kept for compatibility so far.
This will be gradually replaced withpci_host_bus_new()
Also, let's make these helpers inline: will make it possible to check code by comparing binary after changes.
Quoted 4 lines
For secondary bus:
-pci_bridge_init()
qdev style API.
New code should use this.
Well - isn't the way we do this a bit backwards?
I thought the idea was that each device has its own PCIDeviceInfo qdev structure, instead of the common pci-bridge.
And then pci_bridge_init (or _setup to avoid reusing existing names) would be a common function that devices can reuse in their init functions..
Quoted 18 lines
- pci_{register, unregister}_secondary_bus():
old stype API. deprecated.
Keep them only for internal use inpci.c
or they can be easily removed or renamed for qdev style.For pci device:
-pci_create()
qdev style API.
The transitional function until completion of qdev conversion. If the creation of a device tree from config file is implemented, this function will be unnecessary.-
pci_create_simple()
qdev style API.
convenience function =pci_create()+qdev_init_nofail()Signature · 1 line
yamahata
Re: [Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
Quoted 17 lines · Michael S. Tsirkin
Quoted 17 lines
Quoted 6 lines
Quoted 5 lines
- to eliminate assumption of
pci_bus_new().pci_bus_new()assumes that its pci segment is 0. keeppci_bus_new()as a convenience wrapper ofpci_host_bus_new(segment = 0). Thus we can avoid fixing up all the caller.Quoted 8 lines
We have a single caller, right? I think you mean
pci_register_bus? So IIUC, you propose that we addpci_register_host_bus, and makepci_register_busa compatibility wrapper? Sure, let's just add a comment this is deprecated.I am not sure why do we need an API to deal with secondary bus:
it is always a part of the bridge, so all users can and should callpci_bridge_init?Okay, then how about the following?
Quoted 7 lines
Quoted 4 lines
For root bus:
- pci_host_bus_new()/pci_host_bus_new_inplace()
qbus style api. pci segment must be specified.
New code should use this.I'd prefer a simple
_initwhich works like_inplace. Allocating memory is simple enough for users.
I see. Then
- export PCIBus. This is necessary to tell its size.
- pci_host_bus_init()/pci_host_bus_cleanup() which don't allocate memory.
Quoted 10 lines
Quoted 9 lines
-
pci_bus_new()
qbus style API.
convenience wrapper for compatibility ofpci_host_bus_new(pci segment = 0)
In fact, the only current userpiix_pci.c. It's easy to remove it.
-pci_register_bus()
old style API. deprecated.
It has been kept for compatibility so far.
This will be gradually replaced withpci_host_bus_new()
Quoted 2 lines
Also, let's make these helpers inline: will make it possible to check code by comparing binary after changes.
Agreed.
Quoted 6 lines
Quoted 5 lines
For secondary bus:
-pci_bridge_init()
qdev style API.
New code should use this.
Quoted 7 lines
Well - isn't the way we do this a bit backwards?
I thought the idea was that each device has its own PCIDeviceInfo qdev structure, instead of the common pci-bridge.And then
pci_bridge_init(or_setupto avoid reusing existing names) would be a common function that devices can reuse in their init functions..
Agreed and in fact I'm having such a patch.
Just I think it's next phase of clean up.
The patch series creates a library for pci bridge as you suggested before and converts apb_pci.c and dec_pci.c into qdev.
Quoted 20 lines
Quoted 19 lines
- pci_{register, unregister}_secondary_bus():
old stype API. deprecated.
Keep them only for internal use inpci.c
or they can be easily removed or renamed for qdev style.For pci device:
-pci_create()
qdev style API.
The transitional function until completion of qdev conversion. If the creation of a device tree from config file is implemented, this function will be unnecessary.-
pci_create_simple()
qdev style API.
convenience function =pci_create()+qdev_init_nofail()Signature · 1 line
yamahata
Signature · 1 line
yamahata
Re: [Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
In reply to Michael S. TsirkinQuoted 7 lines · Michael S. Tsirkin
Quoted 4 lines
For root bus:
- pci_host_bus_new()/pci_host_bus_new_inplace()
qbus style api. pci segment must be specified.
New code should use this.I'd prefer a simple
_initwhich works like_inplace. Allocating memory is simple enough for users.
How about the following patch?
- replaced pci_bus_new(), pci_bus_new_inplace() with
pci_host_bus_init()/pci_host_bus_cleanup()
- eliminated memory allocation by embedding PCIBus into PCIHostState.
I've tested it with only piix4 yet.
If this direction is okay, I'll give it more tests and post it.
Quoted 1 line
From
d54dffc884c93bc4f71c506a933891d404e5bf81Mon Sep 17 00:00:00 2001
Message-Id: <d54dffc884c93bc4f71c506a933891d404e5bf81.1279244480.git.yamahata@valinux.co.jp>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: Isaku Yamahata <[email protected]>
Date: Tue, 13 Jul 2010 17:35:00 +0900
Subject: [PATCH] pci/pci_host: pci host bus initialization clean up.
Embed PCIBus into PCIHostState and clean up of pci host bus initialization. And Embed PCIHostState into each devices.
Especially pci host bus creation must be aware of pci segment, usually 0. Although some boards doesn't use PCIHostState at the moment,
in long term enhance PCIHostState and convert them.
--- hw/apb_pci.c | 21 ++++++++--------- hw/bonito.c | 25 +++++++++++---------- hw/grackle_pci.c | 11 ++++----- hw/gt64xxx.c | 14 ++++++------ hw/pci.c | 61 ++++++++++++++++++++++++++++++++++------------------ hw/pci.h | 18 ++++++++++----- hw/pci_host.c | 14 ++++------- hw/pci_host.h | 13 ++++++++++- hw/pcie_host.c | 12 +++++----- hw/piix_pci.c | 5 ++- hw/ppc4xx_pci.c | 11 ++++----- hw/ppce500_pci.c | 12 ++++------ hw/prep_pci.c | 20 ++++++++-------- hw/sh_pci.c | 14 ++++++------ hw/unin_pci.c | 30 ++++++++++++------------ hw/versatile_pci.c | 8 ++++-- 16 files changed, 160 insertions(+), 129 deletions(-)
hw/apb_pci.c +10 -11
@@ -68,7 +68,7 @@ do { printf("APB: " fmt , ## __VA_ARGS__); } while (0) typedef struct APBState { SysBusDevice busdev; - PCIBus *bus; + PCIHostState pci; ReadWriteHandler pci_config_handler; uint32_t iommu[4]; uint32_t pci_control[16];
@@ -194,7 +194,7 @@ static void apb_pci_config_write(ReadWriteHandler *h, pcibus_t addr, val =qemu_bswap_len (val, size);APB_DPRINTF ("%s: addr " TARGET_FMT_lx" val %x\n" , __func__, addr, val); -pci_data_write (s->bus, addr, val, size); +pci_data_write (&s->pci.bus, addr, val, size); } static uint32_t apb_pci_config_read(ReadWriteHandler *h, pcibus_t addr,
@@ -203,7 +203,7 @@ static uint32_t apb_pci_config_read(ReadWriteHandler *h, pcibus_t addr,uint32_t ret;APBState *s =container_of (h, APBState, pci_config_handler); - ret =pci_data_read (s->bus, addr, size); + ret =pci_data_read (&s->pci.bus, addr, size); ret =qemu_bswap_len (ret, size);APB_DPRINTF ("%s: addr " TARGET_FMT_lx" -> %x\n" , __func__, addr, ret);return ret;
@@ -347,29 +347,28 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base,sysbus_mmio_map (s,2 , special_base +0x2000000ULL ); d =FROM_SYSBUS (APBState, s); - d->bus =pci_register_bus (&d->busdev.qdev,"pci" , - pci_apb_set_irq, pci_pbm_map_irq, d, -0 ,32 ); -pci_bus_set_mem_base (d->bus, mem_base); +pci_host_bus_init_simple (&d->pci, &d->busdev.qdev,0 ,"pci" , + pci_apb_set_irq, pci_pbm_map_irq, d,0 ,32 ); +pci_bus_set_mem_base (&d->pci.bus, mem_base);for (i =0 ; i <32 ; i++) {sysbus_connect_irq (s, i, pic[i]); } -pci_create_simple (d->bus,0 ,"pbm" ); +pci_create_simple (&d->pci.bus,0 ,"pbm" );/* APB secondary busses */ - br =pci_bridge_create_simple (d->bus,PCI_DEVFN (1 ,0 ), true, + br =pci_bridge_create_simple (&d->pci.bus,PCI_DEVFN (1 ,0 ), true, pci_apb_map_irq,"pbm-bridge" ,"Advanced PCI Bus secondary bridge 1" ); *bus2 =pci_bridge_get_sec_bus (br); - br =pci_bridge_create_simple (d->bus,PCI_DEVFN (1 ,1 ), true, + br =pci_bridge_create_simple (&d->pci.bus,PCI_DEVFN (1 ,1 ), true, pci_apb_map_irq,"pbm-bridge" ,"Advanced PCI Bus secondary bridge 2" ); *bus3 =pci_bridge_get_sec_bus (br); -return d->bus; +return &d->pci.bus; }static void pci_pbm_reset (DeviceState *d)
hw/bonito.c +13 -12
@@ -444,9 +444,9 @@ static uint32_t bonito_sbridge_pciaddr(void *opaque, target_phys_addr_t addr) ",pcimap_cfg=%x\n", addr, s->regs[BONITO_PCIMAP_CFG]);exit (1 ); } - pciaddr =PCI_ADDR (pci_bus_num (s->pcihost->bus), devno, funno, regno); + pciaddr =PCI_ADDR (pci_bus_num (&s->pcihost->bus), devno, funno, regno);DPRINTF ("cfgaddr %x pciaddr %x busno %x devno %d funno %d regno %d \n" , - cfgaddr, pciaddr,pci_bus_num (s->pcihost->bus), devno, funno, regno); + cfgaddr, pciaddr,pci_bus_num (&s->pcihost->bus), devno, funno, regno);return pciaddr; }
@@ -467,7 +467,7 @@ static void bonito_spciconf_writeb(void *opaque, target_phys_addr_t addr,/* set the pci address in s->config_reg */ s->pcihost->config_reg = (pciaddr) | (1u <<31 ); -pci_data_write (s->pcihost->bus, s->pcihost->config_reg, val &0xff ,1 ); +pci_data_write (&s->pcihost->bus, s->pcihost->config_reg, val &0xff ,1 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ status =pci_get_word (s->dev.config +PCI_STATUS );
@@ -493,7 +493,7 @@ static void bonito_spciconf_writew(void *opaque, target_phys_addr_t addr,/* set the pci address in s->config_reg */ s->pcihost->config_reg = (pciaddr) | (1u <<31 ); -pci_data_write (s->pcihost->bus, s->pcihost->config_reg, val,2 ); +pci_data_write (&s->pcihost->bus, s->pcihost->config_reg, val,2 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ status =pci_get_word (s->dev.config +PCI_STATUS );
@@ -519,7 +519,7 @@ static void bonito_spciconf_writel(void *opaque, target_phys_addr_t addr,/* set the pci address in s->config_reg */ s->pcihost->config_reg = (pciaddr) | (1u <<31 ); -pci_data_write (s->pcihost->bus, s->pcihost->config_reg, val,4 ); +pci_data_write (&s->pcihost->bus, s->pcihost->config_reg, val,4 );/* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */ status =pci_get_word (s->dev.config +PCI_STATUS );
@@ -548,7 +548,7 @@ static uint32_t bonito_spciconf_readb(void *opaque, target_phys_addr_t addr) status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT );pci_set_word (s->dev.config +PCI_STATUS , status); -return pci_data_read (s->pcihost->bus, s->pcihost->config_reg,1 ); +return pci_data_read (&s->pcihost->bus, s->pcihost->config_reg,1 ); }static uint32_t bonito_spciconf_readw (void *opaque,target_phys_addr_t addr)
@@ -574,7 +574,7 @@ static uint32_t bonito_spciconf_readw(void *opaque, target_phys_addr_t addr) status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT );pci_set_word (s->dev.config +PCI_STATUS , status); -return pci_data_read (s->pcihost->bus, s->pcihost->config_reg,2 ); +return pci_data_read (&s->pcihost->bus, s->pcihost->config_reg,2 ); }static uint32_t bonito_spciconf_readl (void *opaque,target_phys_addr_t addr)
@@ -600,7 +600,7 @@ static uint32_t bonito_spciconf_readl(void *opaque, target_phys_addr_t addr) status &= ~(PCI_STATUS_REC_MASTER_ABORT |PCI_STATUS_REC_TARGET_ABORT );pci_set_word (s->dev.config +PCI_STATUS , status); -return pci_data_read (s->pcihost->bus, s->pcihost->config_reg,4 ); +return pci_data_read (&s->pcihost->bus, s->pcihost->config_reg,4 ); }/* south bridge PCI configure space. 0x1fe8 0000 - 0x1fef ffff */
@@ -774,11 +774,12 @@ PCIBus *bonito_init(qemu_irq *pic) dev =qdev_create (NULL ,"Bonito-pcihost" ); pcihost =FROM_SYSBUS (BonitoState,sysbus_from_qdev (dev)); - b =pci_register_bus (&pcihost->busdev.qdev,"pci" , pci_bonito_set_irq, - pci_bonito_map_irq, pic,0x28 ,32 ); - pcihost->pci.bus = b; +pci_host_bus_init_simple (&pcihost->pci, &pcihost->busdev.qdev,0 ,"pci" , + pci_bonito_set_irq, pci_bonito_map_irq, + pic,0x28 ,32 );qdev_init_nofail (dev); -pci_bus_set_mem_base (pcihost->pci.bus,0x10000000 ); + b = &pcihost->pci.bus; +pci_bus_set_mem_base (b,0x10000000 ); d =pci_create_simple (b,PCI_DEVFN (0 ,0 ),"Bonito" ); s =DO_UPCAST (PCIBonitoState, dev, d);
hw/grackle_pci.c +5 -6
@@ -88,17 +88,16 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic)qdev_init_nofail (dev); s =sysbus_from_qdev (dev); d =FROM_SYSBUS (GrackleState, s); - d->host_state.bus =pci_register_bus (&d->busdev.qdev,"pci" , - pci_grackle_set_irq, - pci_grackle_map_irq, - pic,0 ,4 ); +pci_host_bus_init_simple (&d->host_state, &d->busdev.qdev,0 ,"pci" , + pci_grackle_set_irq, pci_grackle_map_irq, + pic,0 ,4 ); -pci_create_simple (d->host_state.bus,0 ,"grackle" ); +pci_create_simple (&d->host_state.bus,0 ,"grackle" );sysbus_mmio_map (s,0 , base);sysbus_mmio_map (s,1 , base +0x00200000 ); -return d->host_state.bus; +return &d->host_state.bus; }static int pci_grackle_init_device (SysBusDevice *dev)
hw/gt64xxx.c +7 -7
@@ -535,7 +535,7 @@ static void gt64120_writel (void *opaque, target_phys_addr_t addr,if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci->config_reg &0x00fff800 )) val =bswap32 (val);if (s->pci->config_reg & (1u <<31 )) -pci_data_write (s->pci->bus, s->pci->config_reg, val,4 ); +pci_data_write (&s->pci->bus, s->pci->config_reg, val,4 );break ;/* Interrupts */
@@ -775,7 +775,7 @@ static uint32_t gt64120_readl (void *opaque,if (!(s->pci->config_reg & (1 <<31 ))) val =0xffffffff ;else - val =pci_data_read (s->pci->bus, s->pci->config_reg,4 ); + val =pci_data_read (&s->pci->bus, s->pci->config_reg,4 );if (!(s->regs[GT_PCI0_CMD ] &1 ) && (s->pci->config_reg &0x00fff800 )) val =bswap32 (val);break ;
@@ -1113,11 +1113,11 @@ PCIBus *pci_gt64120_init(qemu_irq *pic) s =qemu_mallocz (sizeof (GT64120State)); s->pci =qemu_mallocz (sizeof (GT64120PCIState)); - s->pci->bus =pci_register_bus (NULL ,"pci" , - pci_gt64120_set_irq, pci_gt64120_map_irq, - pic,PCI_DEVFN (18 ,0 ),4 ); +pci_host_bus_init_simple (s->pci,NULL ,0 ,"pci" , + pci_gt64120_set_irq, pci_gt64120_map_irq, + pic,PCI_DEVFN (18 ,0 ),4 ); s->ISD_handle =cpu_register_io_memory (gt64120_read, gt64120_write, s); - d =pci_register_device (s->pci->bus,"GT64120 PCI Bus" ,sizeof (PCIDevice), + d =pci_register_device (&s->pci->bus,"GT64120 PCI Bus" ,sizeof (PCIDevice),0 ,NULL ,NULL );/* FIXME: Malta specific hw assumptions ahead */
@@ -1149,5 +1149,5 @@ PCIBus *pci_gt64120_init(qemu_irq *pic)register_savevm (&d->qdev,"GT64120 PCI Bus" ,0 ,1 , gt64120_save, gt64120_load, d); -return s->pci->bus; +return &s->pci->bus; }
hw/pci.c +40 -21
98 lines not on this page · raw message
hw/pci.h +12 -6
@@ -204,15 +204,21 @@ int pci_device_load(PCIDevice *s, QEMUFile *f);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 int (*pci_hotplug_fn )(DeviceState *qdev,PCIDevice *pci_dev,int state); -void pci_bus_new_inplace (PCIBus *bus,DeviceState *parent, -const char *name,int devfn_min); -PCIBus *pci_bus_new (DeviceState *parent,const char *name,int devfn_min); + +void pci_host_bus_init (PCIHostState *pci_host,DeviceState *parent, +uint16_t segment,const char *name,int devfn_min); +void pci_host_bus_cleanup (PCIHostState *pci_host); + +/* convenience function to ease conversion from pci_register_bus(). += pci_host_bus_init() + pci_bus_irqs() */ +void pci_host_bus_init_simple (PCIHostState *pci_host,DeviceState *parent, +uint16_t segment,const char *name, +pci_set_irq_fn set_irq,pci_map_irq_fn map_irq, +void *irq_opaque,int devfn_min,int nirq); +void pci_bus_irqs (PCIBus *bus,pci_set_irq_fn set_irq,pci_map_irq_fn map_irq,void *irq_opaque,int nirq);void pci_bus_hotplug (PCIBus *bus,pci_hotplug_fn hotplug,DeviceState *dev); -PCIBus *pci_register_bus (DeviceState *parent,const char *name, -pci_set_irq_fn set_irq,pci_map_irq_fn map_irq, -void *irq_opaque,int devfn_min,int nirq);void pci_bus_set_mem_base (PCIBus *bus,target_phys_addr_t base);
hw/pci_host.c +5 -9
@@ -131,7 +131,7 @@ static void pci_host_data_write_swap(ReadWriteHandler *handler,PCI_DPRINTF ("write addr %" FMT_PCIBUS " len %d val %x\n" , addr, len, val);if (s->config_reg & (1u <<31 )) -pci_data_write (s->bus, s->config_reg | (addr &3 ), val, len); +pci_data_write (&s->bus, s->config_reg | (addr &3 ), val, len); } static uint32_t pci_host_data_read_swap(ReadWriteHandler *handler,
@@ -141,7 +141,7 @@ static uint32_t pci_host_data_read_swap(ReadWriteHandler *handler,uint32_t val;if (!(s->config_reg & (1 <<31 )))return 0xffffffff ; - val =pci_data_read (s->bus, s->config_reg | (addr &3 ), len); + val =pci_data_read (&s->bus, s->config_reg | (addr &3 ), len);PCI_DPRINTF ("read addr %" FMT_PCIBUS " len %d val %x\n" , addr, len, val); val =qemu_bswap_len (val, len);
@@ -155,7 +155,7 @@ static void pci_host_data_write_noswap(ReadWriteHandler *handler,PCI_DPRINTF ("write addr %" FMT_PCIBUS " len %d val %x\n" , addr, len, val);if (s->config_reg & (1u <<31 )) -pci_data_write (s->bus, s->config_reg | (addr &3 ), val, len); +pci_data_write (&s->bus, s->config_reg | (addr &3 ), val, len); } static uint32_t pci_host_data_read_noswap(ReadWriteHandler *handler,
@@ -165,13 +165,13 @@ static uint32_t pci_host_data_read_noswap(ReadWriteHandler *handler,uint32_t val;if (!(s->config_reg & (1 <<31 )))return 0xffffffff ; - val =pci_data_read (s->bus, s->config_reg | (addr &3 ), len); + val =pci_data_read (&s->bus, s->config_reg | (addr &3 ), len);PCI_DPRINTF ("read addr %" FMT_PCIBUS " len %d val %x\n" , addr, len, val);return val; } -static void pci_host_init (PCIHostState *s) +void pci_host_init (PCIHostState *s) { s->conf_handler.write = pci_host_config_write_swap; s->conf_handler.read = pci_host_config_read_swap;
@@ -185,7 +185,6 @@ static void pci_host_init(PCIHostState *s)int pci_host_conf_register_mmio (PCIHostState *s,int swap) { -pci_host_init (s);if (swap) {return cpu_register_io_memory_simple (&s->conf_handler); }else {
@@ -195,13 +194,11 @@ int pci_host_conf_register_mmio(PCIHostState *s, int swap)void pci_host_conf_register_ioport (pio_addr_t ioport,PCIHostState *s) { -pci_host_init (s);register_ioport_simple (&s->conf_noswap_handler, ioport,4 ,4 ); }int pci_host_data_register_mmio (PCIHostState *s,int swap) { -pci_host_init (s);if (swap) {return cpu_register_io_memory_simple (&s->data_handler); }else {
@@ -211,7 +208,6 @@ int pci_host_data_register_mmio(PCIHostState *s, int swap)void pci_host_data_register_ioport (pio_addr_t ioport,PCIHostState *s) { -pci_host_init (s);register_ioport_simple (&s->data_noswap_handler, ioport,4 ,1 );register_ioport_simple (&s->data_noswap_handler, ioport,4 ,2 );register_ioport_simple (&s->data_noswap_handler, ioport,4 ,4 );
hw/pci_host.h +12 -1
@@ -25,11 +25,20 @@/* Worker routines for a PCI host controller that uses an {address,data} register pair to access PCI configuration space. */ +/* +* TODO: there remains some boards which doesn't use PCIHostState. +* Enhance PCIHostState API and convert remaining boards. +* - allow custom address decoder which doesn't match with +* 24:16 bus, 15:8 defn, 7:0 offset. +* - allow MMIO mapped direct access to configuration space +*/ + #ifndef PCI_HOST_H #define PCI_HOST_H #include "sysbus.h" #include "rwhandler.h" +#include "pci_internals.h" struct PCIHostState { ReadWriteHandler conf_noswap_handler;
@@ -37,9 +46,11 @@ struct PCIHostState {ReadWriteHandler data_noswap_handler;ReadWriteHandler data_handler;uint32_t config_reg; -PCIBus *bus; +PCIBus bus; }; +void pci_host_init (PCIHostState *s); +void pci_data_write (PCIBus *s,uint32_t addr,uint32_t val,int len);uint32_t pci_data_read (PCIBus *s,uint32_t addr,int len);
hw/pcie_host.c +6 -6
@@ -80,39 +80,39 @@ static void pcie_mmcfg_data_writeb(void *opaque, target_phys_addr_t addr, uint32_t value) {PCIExpressHost *e = opaque; -pcie_mmcfg_data_write (e->pci.bus, addr - e->base_addr, value,1 ); +pcie_mmcfg_data_write (&e->pci.bus, addr - e->base_addr, value,1 ); }static void pcie_mmcfg_data_writew (void *opaque,target_phys_addr_t addr,uint32_t value) {PCIExpressHost *e = opaque; -pcie_mmcfg_data_write (e->pci.bus, addr - e->base_addr, value,2 ); +pcie_mmcfg_data_write (&e->pci.bus, addr - e->base_addr, value,2 ); }static void pcie_mmcfg_data_writel (void *opaque,target_phys_addr_t addr,uint32_t value) {PCIExpressHost *e = opaque; -pcie_mmcfg_data_write (e->pci.bus, addr - e->base_addr, value,4 ); +pcie_mmcfg_data_write (&e->pci.bus, addr - e->base_addr, value,4 ); }static uint32_t pcie_mmcfg_data_readb (void *opaque,target_phys_addr_t addr) {PCIExpressHost *e = opaque; -return pcie_mmcfg_data_read (e->pci.bus, addr - e->base_addr,1 ); +return pcie_mmcfg_data_read (&e->pci.bus, addr - e->base_addr,1 ); }static uint32_t pcie_mmcfg_data_readw (void *opaque,target_phys_addr_t addr) {PCIExpressHost *e = opaque; -return pcie_mmcfg_data_read (e->pci.bus, addr - e->base_addr,2 ); +return pcie_mmcfg_data_read (&e->pci.bus, addr - e->base_addr,2 ); }static uint32_t pcie_mmcfg_data_readl (void *opaque,target_phys_addr_t addr) {PCIExpressHost *e = opaque; -return pcie_mmcfg_data_read (e->pci.bus, addr - e->base_addr,4 ); +return pcie_mmcfg_data_read (&e->pci.bus, addr - e->base_addr,4 ); }
hw/piix_pci.c +3 -2
@@ -228,9 +228,10 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq * dev =qdev_create (NULL ,"i440FX-pcihost" ); s =FROM_SYSBUS (I440FXState,sysbus_from_qdev (dev)); - b =pci_bus_new (&s->busdev.qdev,NULL ,0 ); - s->pci_host.bus = b; + +pci_host_bus_init (&s->pci_host, &s->busdev.qdev,0 ,NULL ,0 );qdev_init_nofail (dev); + b = &s->pci_host.bus; d =pci_create_simple (b,0 ,"i440FX" ); *pi440fx_state =DO_UPCAST (PCII440FXState, dev, d);
hw/ppc4xx_pci.c +5 -6
@@ -357,12 +357,11 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4], controller =qemu_mallocz (sizeof (PPC4xxPCIState)); - controller->pci_state.bus =pci_register_bus (NULL ,"pci" , - ppc4xx_pci_set_irq, - ppc4xx_pci_map_irq, - pci_irqs,0 ,4 ); +pci_host_bus_init_simple (&controller->pci_state,NULL ,0 ,"pci" , + ppc4xx_pci_set_irq, ppc4xx_pci_map_irq, + pci_irqs,0 ,4 ); - controller->pci_dev =pci_register_device (controller->pci_state.bus, + controller->pci_dev =pci_register_device (&controller->pci_state.bus,"host bridge" ,sizeof (PCIDevice),0 ,NULL ,NULL ); pci_conf = controller->pci_dev->config;
@@ -395,7 +394,7 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],register_savevm (&controller->pci_dev->qdev,"ppc4xx_pci" , ppc4xx_pci_id++,1 , ppc4xx_pci_save, ppc4xx_pci_load, controller); -return controller->pci_state.bus; +return &controller->pci_state.bus; free:printf ("%s error\n" , __func__);
hw/ppce500_pci.c +5 -7
@@ -276,12 +276,10 @@ PCIBus *ppce500_pci_init(qemu_irq pci_irqs[4], target_phys_addr_t registers) controller =qemu_mallocz (sizeof (PPCE500PCIState)); - controller->pci_state.bus =pci_register_bus (NULL ,"pci" , - mpc85xx_pci_set_irq, - mpc85xx_pci_map_irq, - pci_irqs,PCI_DEVFN (0x11 ,0 ), -4 ); - d =pci_register_device (controller->pci_state.bus, +pci_host_bus_init_simple (&controller->pci_state,NULL ,0 ,"pci" , + mpc85xx_pci_set_irq, mpc85xx_pci_map_irq, + pci_irqs,PCI_DEVFN (0x11 ,0 ),4 ); + d =pci_register_device (&controller->pci_state.bus,"host bridge" ,sizeof (PCIDevice),0 ,NULL ,NULL );
@@ -314,7 +312,7 @@ PCIBus *ppce500_pci_init(qemu_irq pci_irqs[4], target_phys_addr_t registers)register_savevm (&d->qdev,"ppce500_pci" , ppce500_pci_id++,1 , ppce500_pci_save, ppce500_pci_load, controller); -return controller->pci_state.bus; +return &controller->pci_state.bus; free:printf ("%s error\n" , __func__);
hw/prep_pci.c +10 -10
@@ -43,28 +43,28 @@ static inline uint32_t PPC_PCIIO_config(target_phys_addr_t addr)static void PPC_PCIIO_writeb (void *opaque,target_phys_addr_t addr,uint32_t val) {PREPPCIState *s = opaque; -pci_data_write (s->bus,PPC_PCIIO_config (addr), val,1 ); +pci_data_write (&s->bus,PPC_PCIIO_config (addr), val,1 ); }static void PPC_PCIIO_writew (void *opaque,target_phys_addr_t addr,uint32_t val) {PREPPCIState *s = opaque; val =bswap16 (val); -pci_data_write (s->bus,PPC_PCIIO_config (addr), val,2 ); +pci_data_write (&s->bus,PPC_PCIIO_config (addr), val,2 ); }static void PPC_PCIIO_writel (void *opaque,target_phys_addr_t addr,uint32_t val) {PREPPCIState *s = opaque; val =bswap32 (val); -pci_data_write (s->bus,PPC_PCIIO_config (addr), val,4 ); +pci_data_write (&s->bus,PPC_PCIIO_config (addr), val,4 ); }static uint32_t PPC_PCIIO_readb (void *opaque,target_phys_addr_t addr) {PREPPCIState *s = opaque;uint32_t val; - val =pci_data_read (s->bus,PPC_PCIIO_config (addr),1 ); + val =pci_data_read (&s->bus,PPC_PCIIO_config (addr),1 );return val; }
@@ -72,7 +72,7 @@ static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr) {PREPPCIState *s = opaque;uint32_t val; - val =pci_data_read (s->bus,PPC_PCIIO_config (addr),2 ); + val =pci_data_read (&s->bus,PPC_PCIIO_config (addr),2 ); val =bswap16 (val);return val; }
@@ -81,7 +81,7 @@ static uint32_t PPC_PCIIO_readl (void *opaque, target_phys_addr_t addr) {PREPPCIState *s = opaque;uint32_t val; - val =pci_data_read (s->bus,PPC_PCIIO_config (addr),4 ); + val =pci_data_read (&s->bus,PPC_PCIIO_config (addr),4 ); val =bswap32 (val);return val; }
@@ -117,8 +117,8 @@ PCIBus *pci_prep_init(qemu_irq *pic)int PPC_io_memory; s =qemu_mallocz (sizeof (PREPPCIState)); - s->bus =pci_register_bus (NULL ,"pci" , - prep_set_irq, prep_map_irq, pic,0 ,4 ); +pci_host_bus_init_simple (s,NULL ,0 ,"pci" , + prep_set_irq, prep_map_irq, pic,0 ,4 );pci_host_conf_register_ioport (0xcf8 , s);
@@ -129,7 +129,7 @@ PCIBus *pci_prep_init(qemu_irq *pic)cpu_register_physical_memory (0x80800000 ,0x00400000 , PPC_io_memory);/* PCI host bridge */ - d =pci_register_device (s->bus,"PREP Host Bridge - Motorola Raven" , + d =pci_register_device (&s->bus,"PREP Host Bridge - Motorola Raven" ,sizeof (PCIDevice),0 ,NULL ,NULL );pci_config_set_vendor_id (d->config,PCI_VENDOR_ID_MOTOROLA );pci_config_set_device_id (d->config,PCI_DEVICE_ID_MOTOROLA_RAVEN );
@@ -139,5 +139,5 @@ PCIBus *pci_prep_init(qemu_irq *pic) d->config[0x0D ] =0x10 ;// latency_timer d->config[0x34 ] =0x00 ;// capabilities_pointer -return s->bus; +return &s->bus; }
hw/sh_pci.c +7 -7
@@ -29,7 +29,7 @@#include "bswap.h" typedef struct { - PCIBus *bus; + PCIHostState pci; PCIDevice *dev; uint32_t par; uint32_t mbr;
@@ -58,7 +58,7 @@ static void sh_pci_reg_write (void *p, target_phys_addr_t addr, uint32_t val) }break ;case 0x220 : -pci_data_write (pcic->bus, pcic->par, val,4 ); +pci_data_write (&pcic->pci.bus, pcic->par, val,4 );break ; } }
@@ -76,7 +76,7 @@ static uint32_t sh_pci_reg_read (void *p, target_phys_addr_t addr)case 0x1c8 :return pcic->iobr;case 0x220 : -return pci_data_read (pcic->bus, pcic->par,4 ); +return pci_data_read (&pcic->pci.bus, pcic->par,4 ); }return 0 ; }
@@ -98,10 +98,10 @@ PCIBus *sh_pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,int reg; p =qemu_mallocz (sizeof (SHPCIC )); - p->bus =pci_register_bus (NULL ,"pci" , - set_irq, map_irq, opaque, devfn_min, nirq); +pci_host_bus_init_simple (&p->pci,NULL ,0 ,"pci" , + set_irq, map_irq, opaque, devfn_min, nirq); - p->dev =pci_register_device (p->bus,"SH PCIC" ,sizeof (PCIDevice), + p->dev =pci_register_device (&p->pci.bus,"SH PCIC" ,sizeof (PCIDevice),-1 ,NULL ,NULL ); reg =cpu_register_io_memory (sh_pci_reg.r, sh_pci_reg.w, p);cpu_register_physical_memory (0x1e200000 ,0x224 , reg);
@@ -117,5 +117,5 @@ PCIBus *sh_pci_register_bus(pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, p->dev->config[0x06 ] =0x90 ; p->dev->config[0x07 ] =0x02 ; -return p->bus; +return &p->pci.bus; }
hw/unin_pci.c +15 -15
@@ -123,7 +123,7 @@ static void unin_data_write(ReadWriteHandler *handler,UNINState *s =container_of (handler, UNINState, data_handler); val =qemu_bswap_len (val, len);UNIN_DPRINTF ("write addr %" FMT_PCIBUS " len %d val %x\n" , addr, len, val); -pci_data_write (s->host_state.bus, +pci_data_write (&s->host_state.bus,unin_get_config_reg (s->host_state.config_reg, addr), val, len); }
@@ -134,7 +134,7 @@ static uint32_t unin_data_read(ReadWriteHandler *handler,UNINState *s =container_of (handler, UNINState, data_handler);uint32_t val; - val =pci_data_read (s->host_state.bus, + val =pci_data_read (&s->host_state.bus,unin_get_config_reg (s->host_state.config_reg, addr), len);UNIN_DPRINTF ("read addr %" FMT_PCIBUS " len %d val %x\n" , addr, len, val);
@@ -228,12 +228,12 @@ PCIBus *pci_pmac_init(qemu_irq *pic)qdev_init_nofail (dev); s =sysbus_from_qdev (dev); d =FROM_SYSBUS (UNINState, s); - d->host_state.bus =pci_register_bus (&d->busdev.qdev,"pci" , - pci_unin_set_irq, pci_unin_map_irq, - pic,PCI_DEVFN (11 ,0 ),4 ); +pci_host_bus_init_simple (&d->host_state, &d->busdev.qdev,0 ,"pci" , + pci_unin_set_irq, pci_unin_map_irq, + pic,PCI_DEVFN (11 ,0 ),4 );#if 0 -pci_create_simple (d->host_state.bus,PCI_DEVFN (11 ,0 ),"uni-north" ); +pci_create_simple (&d->host_state.bus,PCI_DEVFN (11 ,0 ),"uni-north" );#endif sysbus_mmio_map (s,0 ,0xf2800000 );
@@ -242,11 +242,11 @@ PCIBus *pci_pmac_init(qemu_irq *pic)/* DEC 21154 bridge */ #if 0 /* XXX: not activated as PPC BIOS doesn't handle multiple buses properly */ -pci_create_simple (d->host_state.bus,PCI_DEVFN (12 ,0 ),"dec-21154" ); +pci_create_simple (&d->host_state.bus,PCI_DEVFN (12 ,0 ),"dec-21154" );#endif /* Uninorth AGP bus */ -pci_create_simple (d->host_state.bus,PCI_DEVFN (11 ,0 ),"uni-north-agp" ); +pci_create_simple (&d->host_state.bus,PCI_DEVFN (11 ,0 ),"uni-north-agp" ); dev =qdev_create (NULL ,"uni-north-agp" );qdev_init_nofail (dev); s =sysbus_from_qdev (dev);
@@ -256,7 +256,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic)/* Uninorth internal bus */ #if 0 /* XXX: not needed for now */ -pci_create_simple (d->host_state.bus,PCI_DEVFN (14 ,0 ),"uni-north-pci" ); +pci_create_simple (&d->host_state.bus,PCI_DEVFN (14 ,0 ),"uni-north-pci" ); dev =qdev_create (NULL ,"uni-north-pci" );qdev_init_nofail (dev); s =sysbus_from_qdev (dev);
@@ -264,7 +264,7 @@ PCIBus *pci_pmac_init(qemu_irq *pic)sysbus_mmio_map (s,1 ,0xf4c00000 );#endif -return d->host_state.bus; +return &d->host_state.bus; }PCIBus *pci_pmac_u3_init (qemu_irq *pic)
@@ -280,16 +280,16 @@ PCIBus *pci_pmac_u3_init(qemu_irq *pic) s =sysbus_from_qdev (dev); d =FROM_SYSBUS (UNINState, s); - d->host_state.bus =pci_register_bus (&d->busdev.qdev,"pci" , - pci_unin_set_irq, pci_unin_map_irq, - pic,PCI_DEVFN (11 ,0 ),4 ); +pci_host_bus_init_simple (&d->host_state, &d->busdev.qdev,0 ,"pci" , + pci_unin_set_irq, pci_unin_map_irq, + pic,PCI_DEVFN (11 ,0 ),4 );sysbus_mmio_map (s,0 ,0xf0800000 );sysbus_mmio_map (s,1 ,0xf0c00000 ); -pci_create_simple (d->host_state.bus,11 <<3 ,"u3-agp" ); +pci_create_simple (&d->host_state.bus,11 <<3 ,"u3-agp" ); -return d->host_state.bus; +return &d->host_state.bus; }static int unin_main_pci_host_init (PCIDevice *d)
hw/versatile_pci.c +5 -3
@@ -16,6 +16,7 @@ typedef struct {qemu_irq irq[4 ];int realview;int mem_config; +PCIHostState pci; } PCIVPBState;static inline uint32_t vpb_pci_config_addr (target_phys_addr_t addr)
@@ -125,9 +126,10 @@ static int pci_vpb_init(SysBusDevice *dev)for (i =0 ; i <4 ; i++) {sysbus_init_irq (dev, &s->irq[i]); } - bus =pci_register_bus (&dev->qdev,"pci" , - pci_vpb_set_irq, pci_vpb_map_irq, s->irq, -PCI_DEVFN (11 ,0 ),4 ); +pci_host_bus_init_simple (&s->pci, &dev->qdev,0 ,"pci" , + pci_vpb_set_irq, pci_vpb_map_irq, s->irq, +PCI_DEVFN (11 ,0 ),4 ); + bus = &s->pci.bus;/* ??? Register memory space. */
Signature · 5 lines
1.7.1.1 -- yamahata
Re: [Qemu-devel] Re: [PATCH 1/2] pci/bridge: allocate PCIBus dynamically for PCIBridge.
Quoted 10 lines · Isaku Yamahata
Quoted 7 lines · Michael S. Tsirkin
Quoted 4 lines
For root bus:
- pci_host_bus_new()/pci_host_bus_new_inplace()
qbus style api. pci segment must be specified.
New code should use this.I'd prefer a simple
_initwhich works like_inplace. Allocating memory is simple enough for users.
Quoted 7 lines
How about the following patch?
- replacedpci_bus_new(),pci_bus_new_inplace()withpci_host_bus_init()/pci_host_bus_cleanup()- eliminated memory allocation by embedding PCIBus into PCIHostState.
I've tested it with only piix4 yet.
If this direction is okay, I'll give it more tests and post it.
Looks good to me. What do others think? Let's also make pci_host_bus_init_simple inline.
Signature · 1 line
MST