[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 27/61] pci: clean up of pci_update_mappings()
From: |
Isaku Yamahata |
Subject: |
[Qemu-devel] [PATCH 27/61] pci: clean up of pci_update_mappings() |
Date: |
Wed, 30 Sep 2009 19:18:03 +0900 |
This patch cleans up pci_update_mappings() making it more readable.
- reduce indent level by one or two
- remove duplicated logic.
Signed-off-by: Isaku Yamahata <address@hidden>
---
hw/pci.c | 142 ++++++++++++++++++++++++++++++++-----------------------------
1 files changed, 74 insertions(+), 68 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index beda5ef..6a28fa5 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -440,91 +440,97 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
static void pci_update_mappings(PCIDevice *d)
{
PCIIORegion *r;
- int cmd, i;
+ int i;
+ uint16_t cmd;
+ uint64_t bar;
+ uint64_t max_addr;
uint64_t last_addr, new_addr;
uint32_t config_ofs;
cmd = le16_to_cpu(*(uint16_t *)(d->config + PCI_COMMAND));
for(i = 0; i < PCI_NUM_REGIONS; i++) {
r = &d->io_regions[i];
+ if (r->size == 0)
+ continue;
+
if (i == PCI_ROM_SLOT) {
config_ofs = 0x30;
} else {
config_ofs = 0x10 + i * 4;
}
- if (r->size != 0) {
+
+ if (pci_bar_is_64bit(r)) {
+ bar = le64_to_cpu(*(uint64_t *)(d->config + config_ofs));
+ } else {
+ bar = le32_to_cpu(*(uint32_t *)(d->config + config_ofs));
+ }
+
+ new_addr = PCI_BAR_UNMAPPED;
+ last_addr = 0;
+ max_addr = 0;
+ if (r->type & PCI_ADDRESS_SPACE_IO) {
+ if (cmd & PCI_COMMAND_IO) {
+ new_addr = bar;
+ }
+
+ /* NOTE: we have only 64K ioports on PC */
+ max_addr = 0x10000;
+ } else {
+ if (cmd & PCI_COMMAND_MEMORY) {
+ new_addr = bar;
+ }
+
+ /* the ROM slot has a specific enable bit */
+ if (i == PCI_ROM_SLOT && !(bar & 1)) {
+ new_addr = PCI_BAR_UNMAPPED;
+ }
+
+ max_addr = PCI_BAR_UNMAPPED;
+ if (!pci_bar_is_64bit(r)) {
+ /* keep old behaviour
+ without this, PC ide doesn't work well. */
+ max_addr = UINT32_MAX;
+ }
+ }
+
+ new_addr = new_addr & ~(r->size - 1);
+ last_addr = new_addr + r->size - 1;
+
+ /* NOTE: we do not support wrapping */
+ /* XXX: as we cannot support really dynamic
+ mappings, we handle specific values as invalid
+ mappings. */
+ if (last_addr <= new_addr || new_addr == 0 || last_addr >= max_addr) {
+ new_addr = PCI_BAR_UNMAPPED;
+ }
+
+ if (new_addr == r->addr) {
+ continue;
+ }
+
+ /* now do the real mapping */
+ if (r->addr != PCI_BAR_UNMAPPED) {
if (r->type & PCI_ADDRESS_SPACE_IO) {
- if (cmd & PCI_COMMAND_IO) {
- new_addr = le32_to_cpu(*(uint32_t *)(d->config +
- config_ofs));
- new_addr = new_addr & ~(r->size - 1);
- last_addr = new_addr + r->size - 1;
- /* NOTE: we have only 64K ioports on PC */
- if (last_addr <= new_addr || new_addr == 0 ||
- last_addr >= 0x10000) {
- new_addr = PCI_BAR_UNMAPPED;
- }
+ int class;
+ /* NOTE: specific hack for IDE in PC case:
+ only one byte must be mapped. */
+ class = d->config[0x0a] | (d->config[0x0b] << 8);
+ if (class == 0x0101 && r->size == 4) {
+ isa_unassign_ioport(r->addr + 2, 1);
} else {
- new_addr = PCI_BAR_UNMAPPED;
+ isa_unassign_ioport(r->addr, r->size);
}
} else {
- if (cmd & PCI_COMMAND_MEMORY) {
-
- if (pci_bar_is_64bit(r)) {
- new_addr = le64_to_cpu(*(uint64_t *)(d->config +
- config_ofs));
- } else {
- new_addr = le32_to_cpu(*(uint32_t *)(d->config +
- config_ofs));
- }
- /* the ROM slot has a specific enable bit */
- if (i == PCI_ROM_SLOT && !(new_addr & 1))
- goto no_mem_map;
- new_addr = new_addr & ~(r->size - 1);
- last_addr = new_addr + r->size - 1;
- /* NOTE: we do not support wrapping */
- /* XXX: as we cannot support really dynamic
- mappings, we handle specific values as invalid
- mappings. */
- if (last_addr <= new_addr || new_addr == 0 ||
- last_addr == PCI_BAR_UNMAPPED ||
-
- /* keep old behaviour
- * without this, PC ide doesn't work well. */
- (!pci_bar_is_64bit(r) && last_addr >= UINT32_MAX)) {
- new_addr = PCI_BAR_UNMAPPED;
- }
- } else {
- no_mem_map:
- new_addr = PCI_BAR_UNMAPPED;
- }
- }
- /* now do the real mapping */
- if (new_addr != r->addr) {
- if (r->addr != PCI_BAR_UNMAPPED) {
- if (r->type & PCI_ADDRESS_SPACE_IO) {
- int class;
- /* NOTE: specific hack for IDE in PC case:
- only one byte must be mapped. */
- class = d->config[0x0a] | (d->config[0x0b] << 8);
- if (class == 0x0101 && r->size == 4) {
- isa_unassign_ioport(r->addr + 2, 1);
- } else {
- isa_unassign_ioport(r->addr, r->size);
- }
- } else {
- cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
- r->size,
- IO_MEM_UNASSIGNED);
- qemu_unregister_coalesced_mmio(r->addr, r->size);
- }
- }
- r->addr = new_addr;
- if (r->addr != PCI_BAR_UNMAPPED) {
- r->map_func(d, i, r->addr, r->size, r->type);
- }
+ cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
+ r->size,
+ IO_MEM_UNASSIGNED);
+ qemu_unregister_coalesced_mmio(r->addr, r->size);
}
}
+ r->addr = new_addr;
+ if (r->addr != PCI_BAR_UNMAPPED) {
+ r->map_func(d, i, r->addr, r->size, r->type);
+ }
}
}
--
1.6.0.2
- [Qemu-devel] [PATCH 00/61] Q35 chip set and stuff., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 07/61] pc, i440fx: Make smm enable/disable function i440fx independent., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 05/61] acpi_piix4: remove unused variable in get_pmsts()., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 32/61] pci: helper functions to access PCIDevice::config, Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 50/61] pci hotadd, acpi_piix4: remove global variables., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 27/61] pci: clean up of pci_update_mappings(),
Isaku Yamahata <=
- [Qemu-devel] [PATCH 06/61] pc: fix file stream leak in multiboot loader., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 20/61] pci: fix PCI_DPRINTF() wrt variadic macro., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 19/61] pc_piix: initialize ioapic before use., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 31/61] pci: pcie host and mmcfg support., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 02/61] acpi: split out apm register emulation from acpi.c, Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 26/61] pci: 64bit bar support., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 04/61] acpi: split acpi.c into the common part and the piix4 part., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 28/61] pci: factor out while(bus) bus->next loop logic into pci_find_bus_from()., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 21/61] pci: introduce constant PCI_NUM_PINS for the number of interrupt pins, 4., Isaku Yamahata, 2009/09/30
- [Qemu-devel] [PATCH 17/61] pc: split out pci device init from pc_init1() into pc_pci_device_init(), Isaku Yamahata, 2009/09/30