From 4677d8ed9db8564fb0b02c1d012d4b25de633290 Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Thu, 12 Nov 2009 14:58:31 +0900 Subject: pci: simplify (pci_/pcie_mmcfg_)data_read() Remove switch on length: we don't care about high bits for value, so just return all ones if no device. And add one assert(). Signed-off-by: Michael S. Tsirkin Acked-by: Isaku Yamahata --- hw/pci_host.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'hw/pci_host.c') diff --git a/hw/pci_host.c b/hw/pci_host.c index f4518dce72..4a29f44904 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -71,25 +71,15 @@ uint32_t pci_data_read(PCIBus *s, uint32_t addr, int len) uint32_t config_addr = pci_addr_to_config(addr); uint32_t val; + assert(len == 1 || len == 2 || len == 4); if (!pci_dev) { - switch(len) { - case 1: - val = 0xff; - break; - case 2: - val = 0xffff; - break; - default: - case 4: - val = 0xffffffff; - break; - } - } else { - val = pci_dev->config_read(pci_dev, config_addr, len); - PCI_DPRINTF("%s: %s: addr=%02"PRIx32" val=%08"PRIx32" len=%d\n", - __func__, pci_dev->name, config_addr, val, len); + return ~0x0; } + val = pci_dev->config_read(pci_dev, config_addr, len); + PCI_DPRINTF("%s: %s: addr=%02"PRIx32" val=%08"PRIx32" len=%d\n", + __func__, pci_dev->name, config_addr, val, len); + return val; } -- cgit 1.4.1 From 7ac901cd18c382b9e7a07ac0b3a47f86d1ed4c1d Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 12 Nov 2009 14:58:32 +0900 Subject: pci: remove pci_addr_to_config() by open code This patch removes pci_addr_to_config() and open code it as suggested by Michael S. Tsirkin . Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci_host.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'hw/pci_host.c') diff --git a/hw/pci_host.c b/hw/pci_host.c index 4a29f44904..ccefa34a4a 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -47,15 +47,10 @@ static inline PCIDevice *pci_addr_to_dev(PCIBus *bus, uint32_t addr) return pci_find_device(bus, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn)); } -static inline uint32_t pci_addr_to_config(uint32_t addr) -{ - return addr & (PCI_CONFIG_SPACE_SIZE - 1); -} - void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len) { PCIDevice *pci_dev = pci_addr_to_dev(s, addr); - uint32_t config_addr = pci_addr_to_config(addr); + uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1); if (!pci_dev) return; @@ -68,7 +63,7 @@ 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) { PCIDevice *pci_dev = pci_addr_to_dev(s, addr); - uint32_t config_addr = pci_addr_to_config(addr); + uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1); uint32_t val; assert(len == 1 || len == 2 || len == 4); -- cgit 1.4.1 From 8d6514f8dd2a8102ec3d577b13cb565fb9cfe73c Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 12 Nov 2009 13:17:23 +0200 Subject: pci: rename (pci_/pcie_mmcfg_)addr_to_dev This patch renames pci_addr_to_dev(), pcie_mmcfg_addr_to_dev() to pci_dev_find_by_addr(), pcie_dev_find_by_mmcfg_addr() as "Michael S. Tsirkin" suggested. Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci_host.c | 6 +++--- hw/pcie_host.c | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'hw/pci_host.c') diff --git a/hw/pci_host.c b/hw/pci_host.c index ccefa34a4a..403d0408c6 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -40,7 +40,7 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0) */ /* the helper functio to get a PCIDeice* for a given pci address */ -static inline PCIDevice *pci_addr_to_dev(PCIBus *bus, uint32_t addr) +static inline PCIDevice *pci_dev_find_by_addr(PCIBus *bus, uint32_t addr) { uint8_t bus_num = (addr >> 16) & 0xff; uint8_t devfn = (addr >> 8) & 0xff; @@ -49,7 +49,7 @@ static inline PCIDevice *pci_addr_to_dev(PCIBus *bus, uint32_t addr) void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len) { - PCIDevice *pci_dev = pci_addr_to_dev(s, addr); + PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr); uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1); if (!pci_dev) @@ -62,7 +62,7 @@ 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) { - PCIDevice *pci_dev = pci_addr_to_dev(s, addr); + PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr); uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1); uint32_t val; diff --git a/hw/pcie_host.c b/hw/pcie_host.c index 1dbc94ef6e..fbd6c3759f 100644 --- a/hw/pcie_host.c +++ b/hw/pcie_host.c @@ -46,7 +46,8 @@ /* a helper function to get a PCIDevice for a given mmconfig address */ -static inline PCIDevice *pcie_mmcfg_addr_to_dev(PCIBus *s, uint32_t mmcfg_addr) +static inline PCIDevice *pcie_dev_find_by_mmcfg_addr(PCIBus *s, + uint32_t mmcfg_addr) { return pci_find_device(s, PCIE_MMCFG_BUS(mmcfg_addr), PCI_SLOT(PCIE_MMCFG_DEVFN(mmcfg_addr)), @@ -56,7 +57,7 @@ static inline PCIDevice *pcie_mmcfg_addr_to_dev(PCIBus *s, uint32_t mmcfg_addr) static void pcie_mmcfg_data_write(PCIBus *s, uint32_t mmcfg_addr, uint32_t val, int len) { - PCIDevice *pci_dev = pcie_mmcfg_addr_to_dev(s, mmcfg_addr); + PCIDevice *pci_dev = pcie_dev_find_by_mmcfg_addr(s, mmcfg_addr); if (!pci_dev) return; @@ -67,7 +68,7 @@ static void pcie_mmcfg_data_write(PCIBus *s, static uint32_t pcie_mmcfg_data_read(PCIBus *s, uint32_t addr, int len) { - PCIDevice *pci_dev = pcie_mmcfg_addr_to_dev(s, addr); + PCIDevice *pci_dev = pcie_dev_find_by_mmcfg_addr(s, addr); assert(len == 1 || len == 2 || len == 4); if (!pci_dev) { -- cgit 1.4.1 From f08b32fe959c157d3c3acdad9c7bfe56b5597af1 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 12 Nov 2009 14:58:34 +0900 Subject: pci: shorten pci_host_{conf, data}_register_xxx function a bit. pci_host_data_register_io_memory and its variants are too long a bit. So shorten them. Now they are pci_host_{conf, data}_register_{mmio, mmio_noswap, ioport}() Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/apb_pci.c | 4 ++-- hw/grackle_pci.c | 8 ++++---- hw/pci_host.c | 8 ++++---- hw/pci_host.h | 8 ++++---- hw/piix_pci.c | 2 +- hw/ppc4xx_pci.c | 2 +- hw/ppce500_pci.c | 4 ++-- hw/prep_pci.c | 2 +- hw/unin_pci.c | 16 ++++++++-------- 9 files changed, 27 insertions(+), 27 deletions(-) (limited to 'hw/pci_host.c') diff --git a/hw/apb_pci.c b/hw/apb_pci.c index 1748d8dc79..f2ed136fda 100644 --- a/hw/apb_pci.c +++ b/hw/apb_pci.c @@ -236,10 +236,10 @@ static int pci_pbm_init_device(SysBusDevice *dev) pci_apb_iowrite, s); sysbus_init_mmio(dev, 0x10000ULL, pci_ioport); /* mem_config */ - pci_mem_config = pci_host_config_register_io_memory(&s->host_state); + pci_mem_config = pci_host_conf_register_mmio(&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); + pci_mem_data = pci_host_data_register_mmio(&s->host_state); sysbus_init_mmio(dev, 0x10000000ULL, pci_mem_data); return 0; } diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c index f3a8a7da12..089d1fba01 100644 --- a/hw/grackle_pci.c +++ b/hw/grackle_pci.c @@ -108,8 +108,8 @@ static int pci_grackle_init_device(SysBusDevice *dev) s = FROM_SYSBUS(GrackleState, dev); - pci_mem_config = pci_host_config_register_io_memory(&s->host_state); - pci_mem_data = pci_host_data_register_io_memory(&s->host_state); + pci_mem_config = pci_host_conf_register_mmio(&s->host_state); + pci_mem_data = pci_host_data_register_mmio(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); @@ -126,8 +126,8 @@ static int pci_dec_21154_init_device(SysBusDevice *dev) s = FROM_SYSBUS(GrackleState, dev); - pci_mem_config = pci_host_config_register_io_memory(&s->host_state); - pci_mem_data = pci_host_data_register_io_memory(&s->host_state); + pci_mem_config = pci_host_conf_register_mmio(&s->host_state); + pci_mem_data = pci_host_data_register_mmio(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); return 0; diff --git a/hw/pci_host.c b/hw/pci_host.c index 403d0408c6..45ddcd1e8f 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -116,7 +116,7 @@ static CPUReadMemoryFunc * const pci_host_config_read[] = { &pci_host_config_readl, }; -int pci_host_config_register_io_memory(PCIHostState *s) +int pci_host_conf_register_mmio(PCIHostState *s) { return cpu_register_io_memory(pci_host_config_read, pci_host_config_write, s); @@ -156,7 +156,7 @@ static CPUReadMemoryFunc * const pci_host_config_read_noswap[] = { &pci_host_config_readl_noswap, }; -int pci_host_config_register_io_memory_noswap(PCIHostState *s) +int pci_host_conf_register_mmio_noswap(PCIHostState *s) { return cpu_register_io_memory(pci_host_config_read_noswap, pci_host_config_write_noswap, s); @@ -180,7 +180,7 @@ static uint32_t pci_host_config_readl_ioport(void *opaque, uint32_t addr) return val; } -void pci_host_config_register_ioport(pio_addr_t ioport, PCIHostState *s) +void pci_host_conf_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); @@ -203,7 +203,7 @@ static CPUReadMemoryFunc * const pci_host_data_read_mmio[] = { pci_host_data_readl_mmio, }; -int pci_host_data_register_io_memory(PCIHostState *s) +int pci_host_data_register_mmio(PCIHostState *s) { return cpu_register_io_memory(pci_host_data_read_mmio, pci_host_data_write_mmio, diff --git a/hw/pci_host.h b/hw/pci_host.h index 7cfa693563..cf3a3393d9 100644 --- a/hw/pci_host.h +++ b/hw/pci_host.h @@ -40,12 +40,12 @@ 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); /* 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); +int pci_host_conf_register_mmio(PCIHostState *s); +int pci_host_conf_register_mmio_noswap(PCIHostState *s); +int pci_host_data_register_mmio(PCIHostState *s); /* for ioio */ -void pci_host_config_register_ioport(pio_addr_t ioport, PCIHostState *s); +void pci_host_conf_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/piix_pci.c b/hw/piix_pci.c index 5fb7d7be93..a44f941dc2 100644 --- a/hw/piix_pci.c +++ b/hw/piix_pci.c @@ -180,7 +180,7 @@ static int i440fx_pcihost_initfn(SysBusDevice *dev) { I440FXState *s = FROM_SYSBUS(I440FXState, dev); - pci_host_config_register_ioport(0xcf8, s); + pci_host_conf_register_ioport(0xcf8, s); pci_host_data_register_ioport(0xcfc, s); return 0; diff --git a/hw/ppc4xx_pci.c b/hw/ppc4xx_pci.c index 3aa7489e28..2d00b61228 100644 --- a/hw/ppc4xx_pci.c +++ b/hw/ppc4xx_pci.c @@ -378,7 +378,7 @@ PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4], cpu_register_physical_memory(config_space + PCIC0_CFGADDR, 4, index); /* CFGDATA */ - index = pci_host_data_register_io_memory(&controller->pci_state); + index = pci_host_data_register_mmio(&controller->pci_state); if (index < 0) goto free; cpu_register_physical_memory(config_space + PCIC0_CFGDATA, 4, index); diff --git a/hw/ppce500_pci.c b/hw/ppce500_pci.c index 223de3ae34..a72fb86d2e 100644 --- a/hw/ppce500_pci.c +++ b/hw/ppce500_pci.c @@ -293,13 +293,13 @@ PCIBus *ppce500_pci_init(qemu_irq pci_irqs[4], target_phys_addr_t registers) controller->pci_dev = d; /* CFGADDR */ - index = pci_host_config_register_io_memory_noswap(&controller->pci_state); + index = pci_host_conf_register_mmio_noswap(&controller->pci_state); if (index < 0) goto free; cpu_register_physical_memory(registers + PCIE500_CFGADDR, 4, index); /* CFGDATA */ - index = pci_host_data_register_io_memory(&controller->pci_state); + index = pci_host_data_register_mmio(&controller->pci_state); if (index < 0) goto free; cpu_register_physical_memory(registers + PCIE500_CFGDATA, 4, index); diff --git a/hw/prep_pci.c b/hw/prep_pci.c index 80e20ac1ae..19f028c7b7 100644 --- a/hw/prep_pci.c +++ b/hw/prep_pci.c @@ -128,7 +128,7 @@ PCIBus *pci_prep_init(qemu_irq *pic) s->bus = pci_register_bus(NULL, "pci", prep_set_irq, prep_map_irq, pic, 0, 4); - pci_host_config_register_ioport(0xcf8, s); + pci_host_conf_register_ioport(0xcf8, s); pci_host_data_register_ioport(0xcfc, s); diff --git a/hw/unin_pci.c b/hw/unin_pci.c index fe13e7b3eb..5b3f118fc5 100644 --- a/hw/unin_pci.c +++ b/hw/unin_pci.c @@ -84,8 +84,8 @@ static int pci_unin_main_init_device(SysBusDevice *dev) /* Uninorth main bus */ s = FROM_SYSBUS(UNINState, dev); - pci_mem_config = pci_host_config_register_io_memory(&s->host_state); - pci_mem_data = pci_host_data_register_io_memory(&s->host_state); + pci_mem_config = pci_host_conf_register_mmio(&s->host_state); + pci_mem_data = pci_host_data_register_mmio(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); @@ -103,8 +103,8 @@ static int pci_dec_21154_init_device(SysBusDevice *dev) s = FROM_SYSBUS(UNINState, dev); // XXX: s = &pci_bridge[2]; - 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); + pci_mem_config = pci_host_conf_register_mmio_noswap(&s->host_state); + pci_mem_data = pci_host_data_register_mmio(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); return 0; @@ -118,8 +118,8 @@ static int pci_unin_agp_init_device(SysBusDevice *dev) /* Uninorth AGP bus */ s = FROM_SYSBUS(UNINState, dev); - 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); + pci_mem_config = pci_host_conf_register_mmio_noswap(&s->host_state); + pci_mem_data = pci_host_data_register_mmio(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); return 0; @@ -133,8 +133,8 @@ static int pci_unin_internal_init_device(SysBusDevice *dev) /* Uninorth internal bus */ s = FROM_SYSBUS(UNINState, dev); - 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); + pci_mem_config = pci_host_conf_register_mmio_noswap(&s->host_state); + pci_mem_data = pci_host_data_register_mmio(&s->host_state); sysbus_init_mmio(dev, 0x1000, pci_mem_config); sysbus_init_mmio(dev, 0x1000, pci_mem_data); return 0; -- cgit 1.4.1 From 42331e9f2fa2d98acc8faf31c4b04de8ea2d7129 Mon Sep 17 00:00:00 2001 From: Isaku Yamahata Date: Thu, 12 Nov 2009 14:58:37 +0900 Subject: pci_host: remove unnecessary & 0xff. This patch removes unnecessary & 0xff in pci_dev_find_by_addr(). Signed-off-by: Isaku Yamahata Signed-off-by: Michael S. Tsirkin --- hw/pci_host.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'hw/pci_host.c') diff --git a/hw/pci_host.c b/hw/pci_host.c index 45ddcd1e8f..eeb8deeafb 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -42,8 +42,9 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0) /* the helper functio to get a PCIDeice* for a given pci address */ static inline PCIDevice *pci_dev_find_by_addr(PCIBus *bus, uint32_t addr) { - uint8_t bus_num = (addr >> 16) & 0xff; - uint8_t devfn = (addr >> 8) & 0xff; + uint8_t bus_num = addr >> 16; + uint8_t devfn = addr >> 8; + return pci_find_device(bus, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn)); } -- cgit 1.4.1