diff options
author | Avi Kivity <avi@redhat.com> | 2009-11-22 14:20:10 +0200 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2009-11-22 14:20:10 +0200 |
commit | aa497966f785f16c379bf9064d15f7c4d3881075 (patch) | |
tree | f728fac02973ed870594406ab3132bb7c3af2a0e | |
parent | Merge commit '4f5e19e6c570459cd524b29b24374f03860f5149' into upstream-merge (diff) | |
parent | pci: typedef pcibus_t as uint64_t instead of uint32_t. (diff) | |
download | qemu-kvm-aa497966f785f16c379bf9064d15f7c4d3881075.tar.gz qemu-kvm-aa497966f785f16c379bf9064d15f7c4d3881075.tar.bz2 qemu-kvm-aa497966f785f16c379bf9064d15f7c4d3881075.zip |
Merge commit '4f8589e11558f1151d95a4a3e9fce902f042df3d' into upstream-merge
* commit '4f8589e11558f1151d95a4a3e9fce902f042df3d':
pci: typedef pcibus_t as uint64_t instead of uint32_t.
pci: introduce FMT_PCIBUS for printf format for pcibus_t.
pci: introduce pcibus_t to represent pci bus address/size instead of uint32_t
pci_host: consolidate pci config address access.
Fix up hw/device-assignment.c.
Signed-off-by: Avi Kivity <avi@redhat.com>
-rw-r--r-- | hw/ac97.c | 2 | ||||
-rw-r--r-- | hw/apb_pci.c | 43 | ||||
-rw-r--r-- | hw/cirrus_vga.c | 4 | ||||
-rw-r--r-- | hw/device-assignment.c | 8 | ||||
-rw-r--r-- | hw/device-assignment.h | 6 | ||||
-rw-r--r-- | hw/e1000.c | 12 | ||||
-rw-r--r-- | hw/eepro100.c | 10 | ||||
-rw-r--r-- | hw/es1370.c | 2 | ||||
-rw-r--r-- | hw/grackle_pci.c | 45 | ||||
-rw-r--r-- | hw/ide/cmd646.c | 4 | ||||
-rw-r--r-- | hw/ide/piix.c | 2 | ||||
-rw-r--r-- | hw/lsi53c895a.c | 6 | ||||
-rw-r--r-- | hw/macio.c | 2 | ||||
-rw-r--r-- | hw/msix.c | 2 | ||||
-rw-r--r-- | hw/msix.h | 3 | ||||
-rw-r--r-- | hw/ne2000.c | 2 | ||||
-rw-r--r-- | hw/openpic.c | 2 | ||||
-rw-r--r-- | hw/pci.c | 29 | ||||
-rw-r--r-- | hw/pci.h | 13 | ||||
-rw-r--r-- | hw/pci_host.c | 108 | ||||
-rw-r--r-- | hw/pci_host.h | 3 | ||||
-rw-r--r-- | hw/pcnet.c | 10 | ||||
-rw-r--r-- | hw/piix_pci.c | 15 | ||||
-rw-r--r-- | hw/ppce500_pci.c | 34 | ||||
-rw-r--r-- | hw/prep_pci.c | 15 | ||||
-rw-r--r-- | hw/rtl8139.c | 4 | ||||
-rw-r--r-- | hw/sun4u.c | 2 | ||||
-rw-r--r-- | hw/unin_pci.c | 81 | ||||
-rw-r--r-- | hw/usb-ohci.c | 2 | ||||
-rw-r--r-- | hw/usb-uhci.c | 2 | ||||
-rw-r--r-- | hw/vga-pci.c | 2 | ||||
-rw-r--r-- | hw/virtio-pci.c | 2 | ||||
-rw-r--r-- | hw/vmware_vga.c | 4 | ||||
-rw-r--r-- | hw/wdt_i6300esb.c | 5 |
34 files changed, 203 insertions, 283 deletions
@@ -1250,7 +1250,7 @@ static int ac97_load (QEMUFile *f, void *opaque, int version_id) } static void ac97_map (PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { AC97LinkState *s = DO_UPCAST (AC97LinkState, dev, pci_dev); PCIDevice *d = &s->dev; diff --git a/hw/apb_pci.c b/hw/apb_pci.c index 560617a1a..39998791f 100644 --- a/hw/apb_pci.c +++ b/hw/apb_pci.c @@ -54,46 +54,6 @@ typedef struct APBState { PCIHostState host_state; } APBState; -static void pci_apb_config_writel (void *opaque, target_phys_addr_t addr, - uint32_t val) -{ - APBState *s = opaque; - -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); -#endif - APB_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr, - val); - s->host_state.config_reg = val; -} - -static uint32_t pci_apb_config_readl (void *opaque, - target_phys_addr_t addr) -{ - APBState *s = opaque; - uint32_t val; - - val = s->host_state.config_reg; -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); -#endif - APB_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr, - val); - return val; -} - -static CPUWriteMemoryFunc * const pci_apb_config_write[] = { - &pci_apb_config_writel, - &pci_apb_config_writel, - &pci_apb_config_writel, -}; - -static CPUReadMemoryFunc * const pci_apb_config_read[] = { - &pci_apb_config_readl, - &pci_apb_config_readl, - &pci_apb_config_readl, -}; - static void apb_config_writel (void *opaque, target_phys_addr_t addr, uint32_t val) { @@ -275,8 +235,7 @@ static int pci_pbm_init_device(SysBusDevice *dev) pci_apb_iowrite, s); sysbus_init_mmio(dev, 0x10000ULL, pci_ioport); /* mem_config */ - pci_mem_config = cpu_register_io_memory(pci_apb_config_read, - pci_apb_config_write, s); + pci_mem_config = pci_host_config_register_io_memory(&s->host_state); sysbus_init_mmio(dev, 0x10ULL, pci_mem_config); /* mem_data */ pci_mem_data = pci_host_data_register_io_memory(&s->host_state); diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c index f4325918e..9bd017b71 100644 --- a/hw/cirrus_vga.c +++ b/hw/cirrus_vga.c @@ -3186,7 +3186,7 @@ void isa_cirrus_vga_init(void) ***************************************/ static void cirrus_pci_lfb_map(PCIDevice *d, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { CirrusVGAState *s = &DO_UPCAST(PCICirrusVGAState, dev, d)->cirrus_vga; @@ -3209,7 +3209,7 @@ static void cirrus_pci_lfb_map(PCIDevice *d, int region_num, } static void cirrus_pci_mmio_map(PCIDevice *d, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { CirrusVGAState *s = &DO_UPCAST(PCICirrusVGAState, dev, d)->cirrus_vga; diff --git a/hw/device-assignment.c b/hw/device-assignment.c index f7a6585b9..53da77227 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -149,13 +149,13 @@ static uint32_t assigned_dev_ioport_readl(void *opaque, uint32_t addr) } static void assigned_dev_iomem_map(PCIDevice *pci_dev, int region_num, - uint32_t e_phys, uint32_t e_size, int type) + pcibus_t e_phys, pcibus_t e_size, int type) { AssignedDevice *r_dev = container_of(pci_dev, AssignedDevice, dev); AssignedDevRegion *region = &r_dev->v_addrs[region_num]; PCIRegion *real_region = &r_dev->real_device.regions[region_num]; - uint32_t old_ephys = region->e_physbase; - uint32_t old_esize = region->e_size; + pcibus_t old_ephys = region->e_physbase; + pcibus_t old_esize = region->e_size; int first_map = (region->e_size == 0); int ret = 0; @@ -198,7 +198,7 @@ static void assigned_dev_iomem_map(PCIDevice *pci_dev, int region_num, } static void assigned_dev_ioport_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { AssignedDevice *r_dev = container_of(pci_dev, AssignedDevice, dev); AssignedDevRegion *region = &r_dev->v_addrs[region_num]; diff --git a/hw/device-assignment.h b/hw/device-assignment.h index 31696ba54..a23126099 100644 --- a/hw/device-assignment.h +++ b/hw/device-assignment.h @@ -61,15 +61,15 @@ typedef struct { } PCIDevRegions; typedef struct { - target_phys_addr_t e_physbase; + pcibus_t e_physbase; uint32_t memory_index; union { void *r_virtbase; /* mmapped access address for memory regions */ uint32_t r_baseport; /* the base guest port for I/O regions */ } u; int num; /* our index within v_addrs[] */ - uint32_t e_size; /* emulated size of region in bytes */ - uint32_t r_size; /* real size of region in bytes */ + pcibus_t e_size; /* emulated size of region in bytes */ + pcibus_t r_size; /* real size of region in bytes */ } AssignedDevRegion; typedef struct AssignedDevice { diff --git a/hw/e1000.c b/hw/e1000.c index 5759d6595..9df903ba4 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -145,10 +145,11 @@ static const char phy_regcap[0x20] = { }; static void -ioport_map(PCIDevice *pci_dev, int region_num, uint32_t addr, - uint32_t size, int type) +ioport_map(PCIDevice *pci_dev, int region_num, pcibus_t addr, + pcibus_t size, int type) { - DBGOUT(IO, "e1000_ioport_map addr=0x%04x size=0x%08x\n", addr, size); + DBGOUT(IO, "e1000_ioport_map addr=0x%04"FMT_PCIBUS + " size=0x%08"FMT_PCIBUS"\n", addr, size); } static void @@ -1011,7 +1012,7 @@ static CPUReadMemoryFunc * const e1000_mmio_read[] = { static void e1000_mmio_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { E1000State *d = DO_UPCAST(E1000State, dev, pci_dev); int i; @@ -1021,7 +1022,8 @@ e1000_mmio_map(PCIDevice *pci_dev, int region_num, }; - DBGOUT(MMIO, "e1000_mmio_map addr=0x%08x 0x%08x\n", addr, size); + DBGOUT(MMIO, "e1000_mmio_map addr=0x%08"FMT_PCIBUS" 0x%08"FMT_PCIBUS"\n", + addr, size); cpu_register_physical_memory(addr, PNPMMIO_SIZE, d->mmio_index); qemu_register_coalesced_mmio(addr, excluded_regs[0]); diff --git a/hw/eepro100.c b/hw/eepro100.c index 829731e16..ba8cdf6fa 100644 --- a/hw/eepro100.c +++ b/hw/eepro100.c @@ -1384,11 +1384,12 @@ static void ioport_write4(void *opaque, uint32_t addr, uint32_t val) /* PCI EEPRO100 definitions */ static void pci_map(PCIDevice * pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); - TRACE(OTHER, logout("region %d, addr=0x%08x, size=0x%08x, type=%d\n", + TRACE(OTHER, logout("region %d, addr=0x%08"FMT_PCIBUS", " + "size=0x%08"FMT_PCIBUS", type=%d\n", region_num, addr, size, type)); assert(region_num == 1); @@ -1463,11 +1464,12 @@ static CPUReadMemoryFunc * const pci_mmio_read[] = { }; static void pci_mmio_map(PCIDevice * pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, pci_dev); - TRACE(OTHER, logout("region %d, addr=0x%08x, size=0x%08x, type=%d\n", + TRACE(OTHER, logout("region %d, addr=0x%08"FMT_PCIBUS", " + "size=0x%08"FMT_PCIBUS", type=%d\n", region_num, addr, size, type)); if (region_num == 0) { diff --git a/hw/es1370.c b/hw/es1370.c index f04895163..10da250bc 100644 --- a/hw/es1370.c +++ b/hw/es1370.c @@ -907,7 +907,7 @@ static void es1370_adc_callback (void *opaque, int avail) } static void es1370_map (PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { ES1370State *s = DO_UPCAST (ES1370State, dev, pci_dev); diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c index 1facdf08e..f3a8a7da1 100644 --- a/hw/grackle_pci.c +++ b/hw/grackle_pci.c @@ -43,45 +43,6 @@ typedef struct GrackleState { PCIHostState host_state; } GrackleState; -static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr, - uint32_t val) -{ - GrackleState *s = opaque; - - GRACKLE_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr, - val); -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); -#endif - s->host_state.config_reg = val; -} - -static uint32_t pci_grackle_config_readl (void *opaque, target_phys_addr_t addr) -{ - GrackleState *s = opaque; - uint32_t val; - - val = s->host_state.config_reg; -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); -#endif - GRACKLE_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr, - val); - return val; -} - -static CPUWriteMemoryFunc * const pci_grackle_config_write[] = { - &pci_grackle_config_writel, - &pci_grackle_config_writel, - &pci_grackle_config_writel, -}; - -static CPUReadMemoryFunc * const pci_grackle_config_read[] = { - &pci_grackle_config_readl, - &pci_grackle_config_readl, - &pci_grackle_config_readl, -}; - /* Don't know if this matches real hardware, but it agrees with OHW. */ static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num) { @@ -147,8 +108,7 @@ static int pci_grackle_init_device(SysBusDevice *dev) s = FROM_SYSBUS(GrackleState, dev); - pci_mem_config = cpu_register_io_memory(pci_grackle_config_read, - pci_grackle_config_write, s); + pci_mem_config = pci_host_config_register_io_memory(&s->host_state); pci_mem_data = pci_host_data_register_io_memory(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); @@ -166,8 +126,7 @@ static int pci_dec_21154_init_device(SysBusDevice *dev) s = FROM_SYSBUS(GrackleState, dev); - pci_mem_config = cpu_register_io_memory(pci_grackle_config_read, - pci_grackle_config_write, s); + pci_mem_config = pci_host_config_register_io_memory(&s->host_state); pci_mem_data = pci_host_data_register_io_memory(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c index 9caeb78d9..3b7c60608 100644 --- a/hw/ide/cmd646.c +++ b/hw/ide/cmd646.c @@ -45,7 +45,7 @@ static void cmd646_update_irq(PCIIDEState *d); static void ide_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, pci_dev); IDEBus *bus; @@ -136,7 +136,7 @@ static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val) } static void bmdma_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, pci_dev); int i; diff --git a/hw/ide/piix.c b/hw/ide/piix.c index 6e50fc2cb..ec93f29b5 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -69,7 +69,7 @@ static void bmdma_writeb(void *opaque, uint32_t addr, uint32_t val) } static void bmdma_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, pci_dev); int i; diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index 60621925b..7e47fc9ab 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -1925,7 +1925,7 @@ static void lsi_io_writel(void *opaque, uint32_t addr, uint32_t val) } static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { LSIState *s = DO_UPCAST(LSIState, dev, pci_dev); @@ -1940,7 +1940,7 @@ static void lsi_io_mapfunc(PCIDevice *pci_dev, int region_num, } static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { LSIState *s = DO_UPCAST(LSIState, dev, pci_dev); @@ -1950,7 +1950,7 @@ static void lsi_ram_mapfunc(PCIDevice *pci_dev, int region_num, } static void lsi_mmio_mapfunc(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { LSIState *s = DO_UPCAST(LSIState, dev, pci_dev); diff --git a/hw/macio.c b/hw/macio.c index 0703abc7f..e92e82a73 100644 --- a/hw/macio.c +++ b/hw/macio.c @@ -40,7 +40,7 @@ struct macio_state_t { }; static void macio_map (PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { macio_state_t *macio_state; int i; @@ -320,7 +320,7 @@ static CPUReadMemoryFunc * const msix_mmio_read[] = { /* Should be called from device's map method. */ void msix_mmio_map(PCIDevice *d, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { uint8_t *config = d->config + d->msix_cap; uint32_t table = pci_get_long(config + MSIX_TABLE_OFFSET); @@ -2,6 +2,7 @@ #define QEMU_MSIX_H #include "qemu-common.h" +#include "pci.h" int msix_init(PCIDevice *pdev, unsigned short nentries, unsigned bar_nr, unsigned bar_size); @@ -10,7 +11,7 @@ void msix_write_config(PCIDevice *pci_dev, uint32_t address, uint32_t val, int len); void msix_mmio_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type); + pcibus_t addr, pcibus_t size, int type); int msix_uninit(PCIDevice *d); diff --git a/hw/ne2000.c b/hw/ne2000.c index 5fe388384..63efc3a1d 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -679,7 +679,7 @@ const VMStateDescription vmstate_pci_ne2000 = { /* PCI NE2000 definitions */ static void ne2000_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev); NE2000State *s = &d->ne2000; diff --git a/hw/openpic.c b/hw/openpic.c index f73fd6338..68af9c1de 100644 --- a/hw/openpic.c +++ b/hw/openpic.c @@ -1026,7 +1026,7 @@ static CPUReadMemoryFunc * const openpic_read[] = { }; static void openpic_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { openpic_t *opp; @@ -508,19 +508,19 @@ static int pci_unregister_device(DeviceState *dev) } void pci_register_bar(PCIDevice *pci_dev, int region_num, - uint32_t size, int type, + pcibus_t size, int type, PCIMapIORegionFunc *map_func) { PCIIORegion *r; uint32_t addr; - uint32_t wmask; + pcibus_t wmask; if ((unsigned int)region_num >= PCI_NUM_REGIONS) return; if (size & (size-1)) { fprintf(stderr, "ERROR: PCI region size must be pow2 " - "type=0x%x, size=0x%x\n", type, size); + "type=0x%x, size=0x%"FMT_PCIBUS"\n", type, size); exit(1); } @@ -537,7 +537,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, wmask |= PCI_ROM_ADDRESS_ENABLE; } pci_set_long(pci_dev->config + addr, type); - pci_set_long(pci_dev->wmask + addr, wmask); + pci_set_long(pci_dev->wmask + addr, wmask & 0xffffffff); pci_set_long(pci_dev->cmask + addr, 0xffffffff); } @@ -545,7 +545,7 @@ static void pci_update_mappings(PCIDevice *d) { PCIIORegion *r; int cmd, i; - uint32_t last_addr, new_addr; + pcibus_t last_addr, new_addr; cmd = pci_get_word(d->config + PCI_COMMAND); for(i = 0; i < PCI_NUM_REGIONS; i++) { @@ -577,7 +577,14 @@ static void pci_update_mappings(PCIDevice *d) mappings, we handle specific values as invalid mappings. */ if (last_addr <= new_addr || new_addr == 0 || - last_addr == PCI_BAR_UNMAPPED) { + last_addr == PCI_BAR_UNMAPPED || + + /* Now pcibus_t is 64bit. + * Check if 32 bit BAR wrap around explicitly. + * Without this, PC ide doesn't work well. + * TODO: remove this work around. + */ + last_addr >= UINT32_MAX) { new_addr = PCI_BAR_UNMAPPED; } } else { @@ -878,10 +885,12 @@ static void pci_info_device(PCIDevice *d) if (r->size != 0) { monitor_printf(mon, " BAR%d: ", i); if (r->type & PCI_BASE_ADDRESS_SPACE_IO) { - monitor_printf(mon, "I/O at 0x%04x [0x%04x].\n", + monitor_printf(mon, "I/O at 0x%04"FMT_PCIBUS + " [0x%04"FMT_PCIBUS"].\n", r->addr, r->addr + r->size - 1); } else { - monitor_printf(mon, "32 bit memory at 0x%08x [0x%08x].\n", + monitor_printf(mon, "32 bit memory at 0x%08"FMT_PCIBUS + " [0x%08"FMT_PCIBUS"].\n", r->addr, r->addr + r->size - 1); } } @@ -1271,7 +1280,9 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) r = &d->io_regions[i]; if (!r->size) continue; - monitor_printf(mon, "%*sbar %d: %s at 0x%x [0x%x]\n", indent, "", + monitor_printf(mon, "%*sbar %d: %s at 0x%"FMT_PCIBUS + " [0x%"FMT_PCIBUS"]\n", + indent, "", i, r->type & PCI_BASE_ADDRESS_SPACE_IO ? "i/o" : "mem", r->addr, r->addr + r->size - 1); } @@ -76,12 +76,15 @@ extern target_phys_addr_t pci_mem_base; #define PCI_DEVICE_ID_VIRTIO_BALLOON 0x1002 #define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003 +typedef uint64_t pcibus_t; +#define FMT_PCIBUS PRIx64 + typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, uint32_t address, uint32_t data, int len); typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, uint32_t address, int len); typedef void PCIMapIORegionFunc(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type); + pcibus_t addr, pcibus_t size, int type); typedef int PCIUnregisterFunc(PCIDevice *pci_dev); typedef void PCICapConfigWriteFunc(PCIDevice *pci_dev, @@ -91,9 +94,9 @@ typedef uint32_t PCICapConfigReadFunc(PCIDevice *pci_dev, typedef int PCICapConfigInitFunc(PCIDevice *pci_dev); typedef struct PCIIORegion { - uint32_t addr; /* current PCI mapping address. -1 means not mapped */ -#define PCI_BAR_UNMAPPED (~(uint32_t)0) - uint32_t size; + pcibus_t addr; /* current PCI mapping address. -1 means not mapped */ +#define PCI_BAR_UNMAPPED (~(pcibus_t)0) + pcibus_t size; uint8_t type; PCIMapIORegionFunc *map_func; } PCIIORegion; @@ -265,7 +268,7 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name, PCIConfigWriteFunc *config_write); void pci_register_bar(PCIDevice *pci_dev, int region_num, - uint32_t size, int type, + pcibus_t size, int type, PCIMapIORegionFunc *map_func); int pci_enable_capability_support(PCIDevice *pci_dev, diff --git a/hw/pci_host.c b/hw/pci_host.c index 45da1e7af..6009e376b 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -32,6 +32,114 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0) #define PCI_DPRINTF(fmt, ...) #endif +static void pci_host_config_writel(void *opaque, target_phys_addr_t addr, + uint32_t val) +{ + PCIHostState *s = opaque; + +#ifdef TARGET_WORDS_BIGENDIAN + val = bswap32(val); +#endif + PCI_DPRINTF("%s addr " TARGET_FMT_plx " val %"PRIx32"\n", + __func__, addr, val); + s->config_reg = val; +} + +static uint32_t pci_host_config_readl(void *opaque, target_phys_addr_t addr) +{ + PCIHostState *s = opaque; + uint32_t val = s->config_reg; + +#ifdef TARGET_WORDS_BIGENDIAN + val = bswap32(val); +#endif + PCI_DPRINTF("%s addr " TARGET_FMT_plx " val %"PRIx32"\n", + __func__, addr, val); + return val; +} + +static CPUWriteMemoryFunc * const pci_host_config_write[] = { + &pci_host_config_writel, + &pci_host_config_writel, + &pci_host_config_writel, +}; + +static CPUReadMemoryFunc * const pci_host_config_read[] = { + &pci_host_config_readl, + &pci_host_config_readl, + &pci_host_config_readl, +}; + +int pci_host_config_register_io_memory(PCIHostState *s) +{ + return cpu_register_io_memory(pci_host_config_read, + pci_host_config_write, s); +} + +static void pci_host_config_writel_noswap(void *opaque, + target_phys_addr_t addr, + uint32_t val) +{ + PCIHostState *s = opaque; + + PCI_DPRINTF("%s addr " TARGET_FMT_plx " val %"PRIx32"\n", + __func__, addr, val); + s->config_reg = val; +} + +static uint32_t pci_host_config_readl_noswap(void *opaque, + target_phys_addr_t addr) +{ + PCIHostState *s = opaque; + uint32_t val = s->config_reg; + + PCI_DPRINTF("%s addr " TARGET_FMT_plx " val %"PRIx32"\n", + __func__, addr, val); + return val; +} + +static CPUWriteMemoryFunc * const pci_host_config_write_noswap[] = { + &pci_host_config_writel_noswap, + &pci_host_config_writel_noswap, + &pci_host_config_writel_noswap, +}; + +static CPUReadMemoryFunc * const pci_host_config_read_noswap[] = { + &pci_host_config_readl_noswap, + &pci_host_config_readl_noswap, + &pci_host_config_readl_noswap, +}; + +int pci_host_config_register_io_memory_noswap(PCIHostState *s) +{ + return cpu_register_io_memory(pci_host_config_read_noswap, + pci_host_config_write_noswap, s); +} + +static void pci_host_config_writel_ioport(void *opaque, + uint32_t addr, uint32_t val) +{ + PCIHostState *s = opaque; + + PCI_DPRINTF("%s addr %"PRIx32 " val %"PRIx32"\n", __func__, addr, val); + s->config_reg = val; +} + +static uint32_t pci_host_config_readl_ioport(void *opaque, uint32_t addr) +{ + PCIHostState *s = opaque; + uint32_t val = s->config_reg; + + PCI_DPRINTF("%s addr %"PRIx32" val %"PRIx32"\n", __func__, addr, val); + return val; +} + +void pci_host_config_register_ioport(pio_addr_t ioport, PCIHostState *s) +{ + register_ioport_write(ioport, 4, 4, pci_host_config_writel_ioport, s); + register_ioport_read(ioport, 4, 4, pci_host_config_readl_ioport, s); +} + #define PCI_ADDR_T target_phys_addr_t #define PCI_HOST_SUFFIX _mmio diff --git a/hw/pci_host.h b/hw/pci_host.h index 92a35f9b0..e5e877f4c 100644 --- a/hw/pci_host.h +++ b/hw/pci_host.h @@ -37,9 +37,12 @@ typedef struct { } PCIHostState; /* for mmio */ +int pci_host_config_register_io_memory(PCIHostState *s); +int pci_host_config_register_io_memory_noswap(PCIHostState *s); int pci_host_data_register_io_memory(PCIHostState *s); /* for ioio */ +void pci_host_config_register_ioport(pio_addr_t ioport, PCIHostState *s); void pci_host_data_register_ioport(pio_addr_t ioport, PCIHostState *s); #endif /* PCI_HOST_H */ diff --git a/hw/pcnet.c b/hw/pcnet.c index a2bd5155e..ee3db0939 100644 --- a/hw/pcnet.c +++ b/hw/pcnet.c @@ -1727,12 +1727,13 @@ static uint32_t pcnet_ioport_readl(void *opaque, uint32_t addr) } static void pcnet_ioport_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { PCNetState *d = &DO_UPCAST(PCIPCNetState, pci_dev, pci_dev)->state; #ifdef PCNET_DEBUG_IO - printf("pcnet_ioport_map addr=0x%04x size=0x%04x\n", addr, size); + printf("pcnet_ioport_map addr=0x%04"FMT_PCIBUS" size=0x%04"FMT_PCIBUS"\n", + addr, size); #endif register_ioport_write(addr, 16, 1, pcnet_aprom_writeb, d); @@ -1920,12 +1921,13 @@ static CPUReadMemoryFunc * const pcnet_mmio_read[] = { }; static void pcnet_mmio_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { PCIPCNetState *d = DO_UPCAST(PCIPCNetState, pci_dev, pci_dev); #ifdef PCNET_DEBUG_IO - printf("pcnet_mmio_map addr=0x%08x 0x%08x\n", addr, size); + printf("pcnet_mmio_map addr=0x%08"FMT_PCIBUS" 0x%08"FMT_PCIBUS"\n", + addr, size); #endif cpu_register_physical_memory(addr, PCNET_PNPMMIO_SIZE, d->state.mmio_index); diff --git a/hw/piix_pci.c b/hw/piix_pci.c index ea75afe90..3c6de29b8 100644 --- a/hw/piix_pci.c +++ b/hw/piix_pci.c @@ -46,18 +46,6 @@ struct PCII440FXState { PIIX3State *piix3; }; -static void i440fx_addr_writel(void* opaque, uint32_t addr, uint32_t val) -{ - I440FXState *s = opaque; - s->config_reg = val; -} - -static uint32_t i440fx_addr_readl(void* opaque, uint32_t addr) -{ - I440FXState *s = opaque; - return s->config_reg; -} - static void piix3_set_irq(void *opaque, int irq_num, int level); /* return the global irq number corresponding to a given device irq @@ -198,8 +186,7 @@ static int i440fx_pcihost_initfn(SysBusDevice *dev) { I440FXState *s = FROM_SYSBUS(I440FXState, dev); - register_ioport_write(0xcf8, 4, 4, i440fx_addr_writel, s); - register_ioport_read(0xcf8, 4, 4, i440fx_addr_readl, s); + pci_host_config_register_ioport(0xcf8, s); pci_host_data_register_ioport(0xcfc, s); return 0; diff --git a/hw/ppce500_pci.c b/hw/ppce500_pci.c index 7c8cdada4..223de3ae3 100644 --- a/hw/ppce500_pci.c +++ b/hw/ppce500_pci.c @@ -84,37 +84,6 @@ struct PPCE500PCIState { typedef struct PPCE500PCIState PPCE500PCIState; -static uint32_t pcie500_cfgaddr_readl(void *opaque, target_phys_addr_t addr) -{ - PPCE500PCIState *pci = opaque; - - pci_debug("%s: (addr:" TARGET_FMT_plx ") -> value:%x\n", __func__, addr, - pci->pci_state.config_reg); - return pci->pci_state.config_reg; -} - -static CPUReadMemoryFunc * const pcie500_cfgaddr_read[] = { - &pcie500_cfgaddr_readl, - &pcie500_cfgaddr_readl, - &pcie500_cfgaddr_readl, -}; - -static void pcie500_cfgaddr_writel(void *opaque, target_phys_addr_t addr, - uint32_t value) -{ - PPCE500PCIState *controller = opaque; - - pci_debug("%s: value:%x -> (addr:" TARGET_FMT_plx ")\n", __func__, value, - addr); - controller->pci_state.config_reg = value & ~0x3; -} - -static CPUWriteMemoryFunc * const pcie500_cfgaddr_write[] = { - &pcie500_cfgaddr_writel, - &pcie500_cfgaddr_writel, - &pcie500_cfgaddr_writel, -}; - static uint32_t pci_reg_read4(void *opaque, target_phys_addr_t addr) { PPCE500PCIState *pci = opaque; @@ -324,8 +293,7 @@ PCIBus *ppce500_pci_init(qemu_irq pci_irqs[4], target_phys_addr_t registers) controller->pci_dev = d; /* CFGADDR */ - index = cpu_register_io_memory(pcie500_cfgaddr_read, - pcie500_cfgaddr_write, controller); + index = pci_host_config_register_io_memory_noswap(&controller->pci_state); if (index < 0) goto free; cpu_register_physical_memory(registers + PCIE500_CFGADDR, 4, index); diff --git a/hw/prep_pci.c b/hw/prep_pci.c index 5a5b3da79..a338f81e1 100644 --- a/hw/prep_pci.c +++ b/hw/prep_pci.c @@ -28,18 +28,6 @@ typedef PCIHostState PREPPCIState; -static void pci_prep_addr_writel(void* opaque, uint32_t addr, uint32_t val) -{ - PREPPCIState *s = opaque; - s->config_reg = val; -} - -static uint32_t pci_prep_addr_readl(void* opaque, uint32_t addr) -{ - PREPPCIState *s = opaque; - return s->config_reg; -} - static inline uint32_t PPC_PCIIO_config(target_phys_addr_t addr) { int i; @@ -139,8 +127,7 @@ PCIBus *pci_prep_init(qemu_irq *pic) s->bus = pci_register_bus(NULL, "pci", prep_set_irq, prep_map_irq, pic, 0, 4); - register_ioport_write(0xcf8, 4, 4, pci_prep_addr_writel, s); - register_ioport_read(0xcf8, 4, 4, pci_prep_addr_readl, s); + pci_host_config_register_ioport(0xcf8, s); pci_host_data_register_ioport(0xcfc, s); diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 26acbefb2..c166db074 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -3192,7 +3192,7 @@ static const VMStateDescription vmstate_rtl8139 = { /* PCI RTL8139 definitions */ static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { RTL8139State *s = DO_UPCAST(RTL8139State, dev, pci_dev); @@ -3200,7 +3200,7 @@ static void rtl8139_mmio_map(PCIDevice *pci_dev, int region_num, } static void rtl8139_ioport_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { RTL8139State *s = DO_UPCAST(RTL8139State, dev, pci_dev); diff --git a/hw/sun4u.c b/hw/sun4u.c index 6f98c4391..2189fa06a 100644 --- a/hw/sun4u.c +++ b/hw/sun4u.c @@ -344,7 +344,7 @@ void cpu_tick_set_limit(void *opaque, uint64_t limit) } static void ebus_mmio_mapfunc(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { DPRINTF("Mapping region %d registers at %08x\n", region_num, addr); switch (region_num) { diff --git a/hw/unin_pci.c b/hw/unin_pci.c index 2effb03bd..f089cbd07 100644 --- a/hw/unin_pci.c +++ b/hw/unin_pci.c @@ -41,74 +41,6 @@ typedef struct UNINState { PCIHostState host_state; } UNINState; -static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr, - uint32_t val) -{ - UNINState *s = opaque; - - UNIN_DPRINTF("config_writel addr " TARGET_FMT_plx " val %x\n", addr, val); -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); -#endif - - s->host_state.config_reg = val; -} - -static uint32_t pci_unin_main_config_readl (void *opaque, - target_phys_addr_t addr) -{ - UNINState *s = opaque; - uint32_t val; - - val = s->host_state.config_reg; -#ifdef TARGET_WORDS_BIGENDIAN - val = bswap32(val); -#endif - UNIN_DPRINTF("config_readl addr " TARGET_FMT_plx " val %x\n", addr, val); - - return val; -} - -static CPUWriteMemoryFunc * const pci_unin_main_config_write[] = { - &pci_unin_main_config_writel, - &pci_unin_main_config_writel, - &pci_unin_main_config_writel, -}; - -static CPUReadMemoryFunc * const pci_unin_main_config_read[] = { - &pci_unin_main_config_readl, - &pci_unin_main_config_readl, - &pci_unin_main_config_readl, -}; - -static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr, - uint32_t val) -{ - UNINState *s = opaque; - - s->host_state.config_reg = val; -} - -static uint32_t pci_unin_config_readl (void *opaque, - target_phys_addr_t addr) -{ - UNINState *s = opaque; - - return s->host_state.config_reg; -} - -static CPUWriteMemoryFunc * const pci_unin_config_write[] = { - &pci_unin_config_writel, - &pci_unin_config_writel, - &pci_unin_config_writel, -}; - -static CPUReadMemoryFunc * const pci_unin_config_read[] = { - &pci_unin_config_readl, - &pci_unin_config_readl, - &pci_unin_config_readl, -}; - /* Don't know if this matches real hardware, but it agrees with OHW. */ static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num) { @@ -152,10 +84,8 @@ static int pci_unin_main_init_device(SysBusDevice *dev) /* Uninorth main bus */ s = FROM_SYSBUS(UNINState, dev); - pci_mem_config = cpu_register_io_memory(pci_unin_main_config_read, - pci_unin_main_config_write, s); + pci_mem_config = pci_host_config_register_io_memory(&s->host_state); pci_mem_data = pci_host_data_register_io_memory(&s->host_state); - sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); @@ -173,8 +103,7 @@ static int pci_dec_21154_init_device(SysBusDevice *dev) s = FROM_SYSBUS(UNINState, dev); // XXX: s = &pci_bridge[2]; - pci_mem_config = cpu_register_io_memory(pci_unin_config_read, - pci_unin_config_write, s); + pci_mem_config = pci_host_config_register_io_memory_noswap(&s->host_state); pci_mem_data = pci_host_data_register_io_memory(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); @@ -189,8 +118,7 @@ static int pci_unin_agp_init_device(SysBusDevice *dev) /* Uninorth AGP bus */ s = FROM_SYSBUS(UNINState, dev); - pci_mem_config = cpu_register_io_memory(pci_unin_config_read, - pci_unin_config_write, s); + pci_mem_config = pci_host_config_register_io_memory_noswap(&s->host_state); pci_mem_data = pci_host_data_register_io_memory(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); @@ -205,8 +133,7 @@ static int pci_unin_internal_init_device(SysBusDevice *dev) /* Uninorth internal bus */ s = FROM_SYSBUS(UNINState, dev); - pci_mem_config = cpu_register_io_memory(pci_unin_config_read, - pci_unin_config_write, s); + pci_mem_config = pci_host_config_register_io_memory_noswap(&s->host_state); pci_mem_data = pci_host_data_register_io_memory(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 0cafbe636..0f7f4de15 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -1706,7 +1706,7 @@ typedef struct { } OHCIPCIState; static void ohci_mapfunc(PCIDevice *pci_dev, int i, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { OHCIPCIState *ohci = DO_UPCAST(OHCIPCIState, pci_dev, pci_dev); cpu_register_physical_memory(addr, size, ohci->state.mem); diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 21de2935e..8babb0265 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -1047,7 +1047,7 @@ static void uhci_frame_timer(void *opaque) } static void uhci_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { UHCIState *s = (UHCIState *)pci_dev; diff --git a/hw/vga-pci.c b/hw/vga-pci.c index 6e224667f..3976d4f20 100644 --- a/hw/vga-pci.c +++ b/hw/vga-pci.c @@ -48,7 +48,7 @@ static const VMStateDescription vmstate_vga_pci = { }; static void vga_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { PCIVGAState *d = (PCIVGAState *)pci_dev; VGACommonState *s = &d->vga; diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 1b0702a9f..aebcf9d0d 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -344,7 +344,7 @@ static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val) } static void virtio_map(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev); VirtIODevice *vdev = proxy->vdev; diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c index baafedde7..33e876e95 100644 --- a/hw/vmware_vga.c +++ b/hw/vmware_vga.c @@ -1126,7 +1126,7 @@ static void vmsvga_init(struct vmsvga_state_s *s, int vga_ram_size) } static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev; struct vmsvga_state_s *s = &d->chip; @@ -1146,7 +1146,7 @@ static void pci_vmsvga_map_ioport(PCIDevice *pci_dev, int region_num, } static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { struct pci_vmsvga_state_s *d = (struct pci_vmsvga_state_s *) pci_dev; struct vmsvga_state_s *s = &d->chip; diff --git a/hw/wdt_i6300esb.c b/hw/wdt_i6300esb.c index 75f1fc6ab..27fa09e41 100644 --- a/hw/wdt_i6300esb.c +++ b/hw/wdt_i6300esb.c @@ -343,7 +343,7 @@ static void i6300esb_mem_writel(void *vp, target_phys_addr_t addr, uint32_t val) } static void i6300esb_map(PCIDevice *dev, int region_num, - uint32_t addr, uint32_t size, int type) + pcibus_t addr, pcibus_t size, int type) { static CPUReadMemoryFunc * const mem_read[3] = { i6300esb_mem_readb, @@ -358,7 +358,8 @@ static void i6300esb_map(PCIDevice *dev, int region_num, I6300State *d = DO_UPCAST(I6300State, dev, dev); int io_mem; - i6300esb_debug("addr = %x, size = %x, type = %d\n", addr, size, type); + i6300esb_debug("addr = %"FMT_PCIBUS", size = %"FMT_PCIBUS", type = %d\n", + addr, size, type); io_mem = cpu_register_io_memory(mem_read, mem_write, d); cpu_register_physical_memory (addr, 0x10, io_mem); |