From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LtDFb-0008NJ-TS for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:28 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LtDFW-0008L1-JC for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:26 -0400 Received: from [199.232.76.173] (port=34771 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LtDFW-0008Kn-A4 for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:22 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45114) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LtDFV-0000iK-JM for qemu-devel@nongnu.org; Sun, 12 Apr 2009 23:54:22 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3D3sKLx022918 for ; Sun, 12 Apr 2009 23:54:20 -0400 Message-Id: <20090413035340.296329700@amt.cnet> Date: Mon, 13 Apr 2009 00:53:13 -0300 From: Marcelo Tosatti References: <20090413035311.009617911@amt.cnet> Content-Disposition: inline; filename=pci-refactor-devfn Subject: [Qemu-devel] [patch 2/2] qemu: switch pci device init functions to accept devfn Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster Some pci device initialization functions do not accept a devfn parameter, but instead use "-1", which caused pci_register_device to find the first free slot on the given bus. Have them accept a "devfn" parameter, and use the newly introduced pci_bus_assign_dev_addr function on platform init code to perform the "first free" enumeration. Some pci init functions still hardcode devfn (usually the host bridge of the bus with devfn 0), those will have be to changed later. Index: trunk/hw/cirrus_vga.c =================================================================== --- trunk.orig/hw/cirrus_vga.c +++ trunk/hw/cirrus_vga.c @@ -3358,7 +3358,7 @@ static void pci_cirrus_write_config(PCID vga_dirty_log_start((VGAState *)s); } -void pci_cirrus_vga_init(PCIBus *bus, uint8_t *vga_ram_base, +void pci_cirrus_vga_init(PCIBus *bus, int devfn, uint8_t *vga_ram_base, ram_addr_t vga_ram_offset, int vga_ram_size) { PCICirrusVGAState *d; @@ -3371,7 +3371,8 @@ void pci_cirrus_vga_init(PCIBus *bus, ui /* setup PCI configuration registers */ d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA", sizeof(PCICirrusVGAState), - -1, NULL, pci_cirrus_write_config); + devfn, NULL, + pci_cirrus_write_config); pci_conf = d->dev.config; pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS); pci_config_set_device_id(pci_conf, device_id); Index: trunk/hw/pc.c =================================================================== --- trunk.orig/hw/pc.c +++ trunk/hw/pc.c @@ -946,7 +946,7 @@ vga_bios_error: if (pci_enabled) { pci_bus = i440fx_init(&i440fx_state, i8259); - piix3_devfn = piix3_init(pci_bus, -1); + piix3_devfn = piix3_init(pci_bus, pci_bus_assign_dev_addr(pci_bus)); } else { pci_bus = NULL; } @@ -959,6 +959,7 @@ vga_bios_error: if (cirrus_vga_enabled) { if (pci_enabled) { pci_cirrus_vga_init(pci_bus, + pci_bus_assign_dev_addr(pci_bus), phys_ram_base + vga_ram_addr, vga_ram_addr, vga_ram_size); } else { @@ -967,13 +968,15 @@ vga_bios_error: } } else if (vmsvga_enabled) { if (pci_enabled) - pci_vmsvga_init(pci_bus, phys_ram_base + vga_ram_addr, + pci_vmsvga_init(pci_bus, pci_bus_assign_dev_addr(pci_bus), + phys_ram_base + vga_ram_addr, vga_ram_addr, vga_ram_size); else fprintf(stderr, "%s: vmware_vga: no PCI bus\n", __FUNCTION__); } else if (std_vga_enabled) { if (pci_enabled) { - pci_vga_init(pci_bus, phys_ram_base + vga_ram_addr, + pci_vga_init(pci_bus, pci_bus_assign_dev_addr(pci_bus), + phys_ram_base + vga_ram_addr, vga_ram_addr, vga_ram_size, 0, 0); } else { isa_vga_init(phys_ram_base + vga_ram_addr, @@ -1020,7 +1023,8 @@ vga_bios_error: if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) pc_init_ne2k_isa(nd, i8259); else - pci_nic_init(pci_bus, nd, -1, "ne2k_pci"); + pci_nic_init(pci_bus, nd, pci_bus_assign_dev_addr(pci_bus), + "ne2k_pci"); } qemu_system_hot_add_init(); @@ -1091,7 +1095,7 @@ vga_bios_error: max_bus = drive_get_max_bus(IF_SCSI); for (bus = 0; bus <= max_bus; bus++) { - scsi = lsi_scsi_init(pci_bus, -1); + scsi = lsi_scsi_init(pci_bus, pci_bus_assign_dev_addr(pci_bus)); for (unit = 0; unit < LSI_MAX_DEVS; unit++) { index = drive_get_index(IF_SCSI, bus, unit); if (index == -1) Index: trunk/hw/pc.h =================================================================== --- trunk.orig/hw/pc.h +++ trunk/hw/pc.h @@ -146,7 +146,7 @@ extern enum vga_retrace_method vga_retra int isa_vga_init(uint8_t *vga_ram_base, unsigned long vga_ram_offset, int vga_ram_size); -int pci_vga_init(PCIBus *bus, uint8_t *vga_ram_base, +int pci_vga_init(PCIBus *bus, int devfn, uint8_t *vga_ram_base, unsigned long vga_ram_offset, int vga_ram_size, unsigned long vga_bios_offset, int vga_bios_size); int isa_vga_mm_init(uint8_t *vga_ram_base, @@ -155,7 +155,7 @@ int isa_vga_mm_init(uint8_t *vga_ram_bas int it_shift); /* cirrus_vga.c */ -void pci_cirrus_vga_init(PCIBus *bus, uint8_t *vga_ram_base, +void pci_cirrus_vga_init(PCIBus *bus, int devfn, uint8_t *vga_ram_base, ram_addr_t vga_ram_offset, int vga_ram_size); void isa_cirrus_vga_init(uint8_t *vga_ram_base, ram_addr_t vga_ram_offset, int vga_ram_size); Index: trunk/hw/pci.h =================================================================== --- trunk.orig/hw/pci.h +++ trunk/hw/pci.h @@ -220,7 +220,7 @@ void lsi_scsi_attach(void *opaque, Block void *lsi_scsi_init(PCIBus *bus, int devfn); /* vmware_vga.c */ -void pci_vmsvga_init(PCIBus *bus, uint8_t *vga_ram_base, +void pci_vmsvga_init(PCIBus *bus, int devfn, uint8_t *vga_ram_base, unsigned long vga_ram_offset, int vga_ram_size); /* usb-uhci.c */ Index: trunk/hw/vga.c =================================================================== --- trunk.orig/hw/vga.c +++ trunk/hw/vga.c @@ -2500,7 +2500,7 @@ static void pci_vga_write_config(PCIDevi vga_dirty_log_start(s); } -int pci_vga_init(PCIBus *bus, uint8_t *vga_ram_base, +int pci_vga_init(PCIBus *bus, int devfn, uint8_t *vga_ram_base, unsigned long vga_ram_offset, int vga_ram_size, unsigned long vga_bios_offset, int vga_bios_size) { @@ -2510,7 +2510,7 @@ int pci_vga_init(PCIBus *bus, uint8_t *v d = (PCIVGAState *)pci_register_device(bus, "VGA", sizeof(PCIVGAState), - -1, NULL, pci_vga_write_config); + devfn, NULL, pci_vga_write_config); if (!d) return -1; s = &d->vga_state; Index: trunk/hw/vmware_vga.c =================================================================== --- trunk.orig/hw/vmware_vga.c +++ trunk/hw/vmware_vga.c @@ -1215,7 +1215,7 @@ static void pci_vmsvga_map_mem(PCIDevice #define PCI_CLASS_HEADERTYPE_00h 0x00 -void pci_vmsvga_init(PCIBus *bus, uint8_t *vga_ram_base, +void pci_vmsvga_init(PCIBus *bus, int devfn, uint8_t *vga_ram_base, unsigned long vga_ram_offset, int vga_ram_size) { struct pci_vmsvga_state_s *s; @@ -1223,7 +1223,7 @@ void pci_vmsvga_init(PCIBus *bus, uint8_ /* Setup PCI configuration */ s = (struct pci_vmsvga_state_s *) pci_register_device(bus, "QEMUware SVGA", - sizeof(struct pci_vmsvga_state_s), -1, 0, 0); + sizeof(struct pci_vmsvga_state_s), devfn, 0, 0); pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE); pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID); s->card.config[PCI_COMMAND] = 0x07; /* I/O + Memory */