[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [rfc 07/18] iommu: Define PCI_DEVFN_AUTO and use it



Rather than using -1 to signify autodetection from non-pass-through
and PT_MACHINE_IRQ_AUTO for pass-through, always use PCI_DEVFN_AUTO.

Signed-off-by: Simon Horman <horms@xxxxxxxxxxxx>

Index: ioemu-remote/hw/pci.c
===================================================================
--- ioemu-remote.orig/hw/pci.c  2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/pci.c       2009-02-17 17:28:20.000000000 +0900
@@ -130,7 +130,6 @@ int pci_device_load(PCIDevice *s, QEMUFi
     return 0;
 }
 
-/* -1 for devfn means auto assign */
 PCIDevice *pci_register_device(PCIBus *bus, const char *name,
                                int instance_size, int devfn,
                                PCIConfigReadFunc *config_read,
@@ -138,7 +137,7 @@ PCIDevice *pci_register_device(PCIBus *b
 {
     PCIDevice *pci_dev;
 
-    if (devfn < 0) {
+    if (devfn == PCI_DEVFN_AUTO) {
         for(devfn = bus->devfn_min ; devfn < 256; devfn += 8) {
             if ( !bus->devices[devfn] &&
                  !( devfn >= PHP_DEVFN_START && devfn < PHP_DEVFN_END ) )
Index: ioemu-remote/hw/ac97.c
===================================================================
--- ioemu-remote.orig/hw/ac97.c 2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/ac97.c      2009-02-17 17:28:20.000000000 +0900
@@ -1326,7 +1326,7 @@ int ac97_init (PCIBus *bus, AudioState *
 
     d = (PCIAC97LinkState *) pci_register_device (bus, "AC97",
                                                   sizeof (PCIAC97LinkState),
-                                                  -1, NULL, NULL);
+                                                  PCI_DEVFN_AUTO, NULL, NULL);
 
     if (!d) {
         AUD_log ("ac97", "Failed to register PCI device\n");
Index: ioemu-remote/hw/cirrus_vga.c
===================================================================
--- ioemu-remote.orig/hw/cirrus_vga.c   2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/cirrus_vga.c        2009-02-17 17:28:20.000000000 +0900
@@ -3361,7 +3361,7 @@ void pci_cirrus_vga_init(PCIBus *bus, Di
     /* setup PCI configuration registers */
     d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA",
                                                  sizeof(PCICirrusVGAState),
-                                                 -1, NULL, NULL);
+                                                 PCI_DEVFN_AUTO, NULL, NULL);
     pci_conf = d->dev.config;
     pci_conf[0x00] = (uint8_t) (PCI_VENDOR_CIRRUS & 0xff);
     pci_conf[0x01] = (uint8_t) (PCI_VENDOR_CIRRUS >> 8);
Index: ioemu-remote/hw/eepro100.c
===================================================================
--- ioemu-remote.orig/hw/eepro100.c     2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/eepro100.c  2009-02-17 17:28:20.000000000 +0900
@@ -1750,8 +1750,8 @@ static void nic_init(PCIBus * bus, NICIn
     logout("\n");
 
     d = (PCIEEPRO100State *) pci_register_device(bus, name,
-                                                 sizeof(PCIEEPRO100State), -1,
-                                                 NULL, NULL);
+                                                 sizeof(PCIEEPRO100State),
+                                                 PCI_DEVFN_AUTO, NULL, NULL);
 
     s = &d->eepro100;
     s->device = device;
Index: ioemu-remote/hw/es1370.c
===================================================================
--- ioemu-remote.orig/hw/es1370.c       2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/es1370.c    2009-02-17 17:28:20.000000000 +0900
@@ -1023,7 +1023,7 @@ int es1370_init (PCIBus *bus, AudioState
 
     d = (PCIES1370State *) pci_register_device (bus, "ES1370",
                                                 sizeof (PCIES1370State),
-                                                -1, NULL, NULL);
+                                                PCI_DEVFN_AUTO, NULL, NULL);
 
     if (!d) {
         AUD_log (NULL, "Failed to register PCI device for ES1370\n");
Index: ioemu-remote/hw/ide.c
===================================================================
--- ioemu-remote.orig/hw/ide.c  2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/ide.c       2009-02-17 17:28:20.000000000 +0900
@@ -3463,7 +3463,7 @@ void pci_cmd646_ide_init(PCIBus *bus, Bl
 
     d = (PCIIDEState *)pci_register_device(bus, "CMD646 IDE",
                                            sizeof(PCIIDEState),
-                                           -1,
+                                           PCI_DEVFN_AUTO,
                                            NULL, NULL);
     if (principal_ide_controller)
        abort();
Index: ioemu-remote/hw/macio.c
===================================================================
--- ioemu-remote.orig/hw/macio.c        2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/macio.c     2009-02-17 17:28:20.000000000 +0900
@@ -83,7 +83,7 @@ void macio_init (PCIBus *bus, int device
 
     d = pci_register_device(bus, "macio",
                             sizeof(PCIDevice) + sizeof(macio_state_t),
-                            -1, NULL, NULL);
+                            PCI_DEVFN_AUTO, NULL, NULL);
     macio_state = (macio_state_t *)(d + 1);
     macio_state->is_oldworld = is_oldworld;
     macio_state->pic_mem_index = pic_mem_index;
Index: ioemu-remote/hw/openpic.c
===================================================================
--- ioemu-remote.orig/hw/openpic.c      2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/openpic.c   2009-02-17 17:28:20.000000000 +0900
@@ -1013,7 +1013,7 @@ qemu_irq *openpic_init (PCIBus *bus, int
         return NULL;
     if (bus) {
         opp = (openpic_t *)pci_register_device(bus, "OpenPIC", 
sizeof(openpic_t),
-                                               -1, NULL, NULL);
+                                               PCI_DEVFN_AUTO, NULL, NULL);
         if (opp == NULL)
             return NULL;
         pci_conf = opp->pci_dev.config;
Index: ioemu-remote/hw/pass-through.c
===================================================================
--- ioemu-remote.orig/hw/pass-through.c 2009-02-17 17:28:11.000000000 +0900
+++ ioemu-remote/hw/pass-through.c      2009-02-17 17:28:23.000000000 +0900
@@ -3101,7 +3101,7 @@ static struct pt_dev * register_real_dev
     pci_fill_info(pci_dev, PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | 
PCI_FILL_SIZES);
     pt_libpci_fixup(pci_dev);
 
-    if ( e_devfn == PT_VIRT_DEVFN_AUTO ) {
+    if ( e_devfn == PCI_DEVFN_AUTO ) {
         /*indicate a static assignment(not hotplug), so find a free PCI hot 
plug slot */
         free_pci_slot = __insert_to_pci_slot(r_bus, r_dev, r_func, 0, NULL);
         if ( free_pci_slot > 0 )
@@ -3395,7 +3395,7 @@ int pt_init(PCIBus *e_bus, const char *d
     while ( next_bdf(&direct_pci_p, &seg, &b, &d, &f, &opt) )
     {
         /* Register real device with the emulated bus */
-        pt_dev = register_real_device(e_bus, "DIRECT PCI", PT_VIRT_DEVFN_AUTO,
+        pt_dev = register_real_device(e_bus, "DIRECT PCI", PCI_DEVFN_AUTO,
             b, d, f, PT_MACHINE_IRQ_AUTO, pci_access, opt);
         if ( pt_dev == NULL )
         {
Index: ioemu-remote/hw/pass-through.h
===================================================================
--- ioemu-remote.orig/hw/pass-through.h 2009-02-17 17:28:06.000000000 +0900
+++ ioemu-remote/hw/pass-through.h      2009-02-17 17:28:20.000000000 +0900
@@ -38,7 +38,6 @@
 // #define PT_DEBUG_PCI_CONFIG_ACCESS
 
 #define PT_MACHINE_IRQ_AUTO (0xFFFFFFFF)
-#define PT_VIRT_DEVFN_AUTO  (-1)
 
 /* Misc PCI constants that should be moved to a separate library :) */
 #define PCI_CONFIG_SIZE         (256)
Index: ioemu-remote/hw/pci.h
===================================================================
--- ioemu-remote.orig/hw/pci.h  2009-02-17 17:28:19.000000000 +0900
+++ ioemu-remote/hw/pci.h       2009-02-17 17:28:20.000000000 +0900
@@ -29,6 +29,8 @@ typedef struct PCIIORegion {
 #define PCI_ROM_SLOT 6
 #define PCI_NUM_REGIONS 7
 
+#define PCI_DEVFN_AUTO -1
+
 #define PCI_DEVICES_MAX 64
 
 #define PCI_VENDOR_ID          0x00    /* 16 bits */
Index: ioemu-remote/hw/pci_emulation.c
===================================================================
--- ioemu-remote.orig/hw/pci_emulation.c        2009-02-17 17:26:38.000000000 
+0900
+++ ioemu-remote/hw/pci_emulation.c     2009-02-17 17:28:20.000000000 +0900
@@ -90,7 +90,7 @@ void pci_emulation_init(PCIBus *bus, PCI
     d = (PCI_EMULATION_State *)pci_register_device(bus,
                                                    pci_emulation_info->name, 
                                                    sizeof(PCI_EMULATION_State),
-                                                   -1, 
+                                                   PCI_DEVFN_AUTO,
                                                     NULL, NULL);
     pci_conf = d->dev.config;
     pci_conf[0x00] = pci_emulation_info->vendorid & 0xff;
Index: ioemu-remote/hw/versatile_pci.c
===================================================================
--- ioemu-remote.orig/hw/versatile_pci.c        2009-02-17 17:26:38.000000000 
+0900
+++ ioemu-remote/hw/versatile_pci.c     2009-02-17 17:28:20.000000000 +0900
@@ -117,7 +117,8 @@ PCIBus *pci_vpb_init(qemu_irq *pic, int 
     /* Normal config area.  */
     cpu_register_physical_memory(base + 0x02000000, 0x1000000, mem_config);
 
-    d = pci_register_device(s, name, sizeof(PCIDevice), -1, NULL, NULL);
+    d = pci_register_device(s, name, sizeof(PCIDevice), PCI_DEVFN_AUTO,
+                            NULL, NULL);
 
     if (realview) {
         /* IO memory area.  */
Index: ioemu-remote/hw/vga.c
===================================================================
--- ioemu-remote.orig/hw/vga.c  2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/vga.c       2009-02-17 17:28:20.000000000 +0900
@@ -2638,7 +2638,7 @@ int pci_vga_init(PCIBus *bus, DisplaySta
 
     d = (PCIVGAState *)pci_register_device(bus, "VGA",
                                            sizeof(PCIVGAState),
-                                           -1, NULL, NULL);
+                                           PCI_DEVFN_AUTO, NULL, NULL);
     if (!d)
         return -1;
     s = &d->vga_state;
Index: ioemu-remote/hw/vmware_vga.c
===================================================================
--- ioemu-remote.orig/hw/vmware_vga.c   2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/vmware_vga.c        2009-02-17 17:28:20.000000000 +0900
@@ -1229,7 +1229,7 @@ void pci_vmsvga_init(PCIBus *bus, Displa
     /* 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), PCI_DEVFN_AUTO, 0, 0);
     s->card.config[PCI_VENDOR_ID]      = PCI_VENDOR_ID_VMWARE & 0xff;
     s->card.config[PCI_VENDOR_ID + 1]  = PCI_VENDOR_ID_VMWARE >> 8;
     s->card.config[PCI_DEVICE_ID]      = SVGA_PCI_DEVICE_ID & 0xff;
Index: ioemu-remote/hw/xen_platform.c
===================================================================
--- ioemu-remote.orig/hw/xen_platform.c 2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/xen_platform.c      2009-02-17 17:28:20.000000000 +0900
@@ -401,7 +401,8 @@ void pci_xen_platform_init(PCIBus *bus)
 
     printf("Register xen platform.\n");
     d = (PCIXenPlatformState *)pci_register_device(
-        bus, "xen-platform", sizeof(PCIXenPlatformState), -1, NULL, NULL);
+        bus, "xen-platform", sizeof(PCIXenPlatformState),
+        PCI_DEVFN_AUTO, NULL, NULL);
     pch = (struct pci_config_header *)d->pci_dev.config;
     pch->vendor_id = 0x5853;
     pch->device_id = 0x0001;
Index: ioemu-remote/hw/lsi53c895a.c
===================================================================
--- ioemu-remote.orig/hw/lsi53c895a.c   2009-02-17 17:28:17.000000000 +0900
+++ ioemu-remote/hw/lsi53c895a.c        2009-02-17 17:28:20.000000000 +0900
@@ -1863,7 +1863,7 @@ void *lsi_scsi_init(PCIBus *bus)
     LSIState *s;
 
     s = (LSIState *)pci_register_device(bus, "LSI53C895A SCSI HBA",
-                                        sizeof(*s), -1, NULL, NULL);
+                                        sizeof(*s), PCI_DEVFN_AUTO, NULL, 
NULL);
     if (s == NULL) {
         fprintf(stderr, "lsi-scsi: Failed to register PCI device\n");
         return NULL;
Index: ioemu-remote/hw/mips_malta.c
===================================================================
--- ioemu-remote.orig/hw/mips_malta.c   2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/mips_malta.c        2009-02-17 17:28:23.000000000 +0900
@@ -497,7 +497,7 @@ static void network_init (PCIBus *pci_bu
             /* The malta board has a PCNet card using PCI SLOT 11 */
             pci_nic_init(pci_bus, nd, 88);
         } else {
-            pci_nic_init(pci_bus, nd, -1);
+            pci_nic_init(pci_bus, nd, PCI_DEVFN_AUTO);
         }
     }
 }
Index: ioemu-remote/hw/pc.c
===================================================================
--- ioemu-remote.orig/hw/pc.c   2009-02-17 17:28:18.000000000 +0900
+++ ioemu-remote/hw/pc.c        2009-02-17 17:28:20.000000000 +0900
@@ -1044,7 +1044,7 @@ static void pc_init1(ram_addr_t ram_size
         } else if (pci_enabled) {
             if (strcmp(nd->model, "?") == 0)
                 fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n");
-            pci_nic_init(pci_bus, nd, -1);
+            pci_nic_init(pci_bus, nd, PCI_DEVFN_AUTO);
         } else if (strcmp(nd->model, "?") == 0) {
             fprintf(stderr, "qemu: Supported ISA NICs: ne2k_isa\n");
             exit(1);
Index: ioemu-remote/hw/ppc_chrp.c
===================================================================
--- ioemu-remote.orig/hw/ppc_chrp.c     2009-02-17 17:28:19.000000000 +0900
+++ ioemu-remote/hw/ppc_chrp.c  2009-02-17 17:28:20.000000000 +0900
@@ -267,7 +267,7 @@ static void ppc_core99_init (ram_addr_t 
     for(i = 0; i < nb_nics; i++) {
         if (!nd_table[i].model)
             nd_table[i].model = "ne2k_pci";
-        pci_nic_init(pci_bus, &nd_table[i], -1);
+        pci_nic_init(pci_bus, &nd_table[i], PCI_DEVFN_AUTO);
     }
     if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
         fprintf(stderr, "qemu: too many IDE bus\n");
Index: ioemu-remote/hw/ppc_oldworld.c
===================================================================
--- ioemu-remote.orig/hw/ppc_oldworld.c 2009-02-17 17:28:19.000000000 +0900
+++ ioemu-remote/hw/ppc_oldworld.c      2009-02-17 17:28:20.000000000 +0900
@@ -291,7 +291,7 @@ static void ppc_heathrow_init (ram_addr_
     for(i = 0; i < nb_nics; i++) {
         if (!nd_table[i].model)
             nd_table[i].model = "ne2k_pci";
-        pci_nic_init(pci_bus, &nd_table[i], -1);
+        pci_nic_init(pci_bus, &nd_table[i], PCI_DEVFN_AUTO);
     }
 
     /* First IDE channel is a CMD646 on the PCI bus */
Index: ioemu-remote/hw/ppc_prep.c
===================================================================
--- ioemu-remote.orig/hw/ppc_prep.c     2009-02-17 17:28:19.000000000 +0900
+++ ioemu-remote/hw/ppc_prep.c  2009-02-17 17:28:20.000000000 +0900
@@ -673,7 +673,7 @@ static void ppc_prep_init (ram_addr_t ra
             || strcmp(nd_table[i].model, "ne2k_isa") == 0) {
             isa_ne2000_init(ne2000_io[i], i8259[ne2000_irq[i]], &nd_table[i]);
         } else {
-            pci_nic_init(pci_bus, &nd_table[i], -1);
+            pci_nic_init(pci_bus, &nd_table[i], PCI_DEVFN__AUTO);
         }
     }
 
Index: ioemu-remote/hw/realview.c
===================================================================
--- ioemu-remote.orig/hw/realview.c     2009-02-17 17:28:19.000000000 +0900
+++ ioemu-remote/hw/realview.c  2009-02-17 17:28:20.000000000 +0900
@@ -126,7 +126,7 @@ static void realview_init(ram_addr_t ram
         if (strcmp(nd->model, "smc91c111") == 0) {
             smc91c111_init(nd, 0x4e000000, pic[28]);
         } else {
-            pci_nic_init(pci_bus, nd, -1);
+            pci_nic_init(pci_bus, nd, PCI_DEVFN_AUTO);
         }
     }
 
Index: ioemu-remote/hw/sun4u.c
===================================================================
--- ioemu-remote.orig/hw/sun4u.c        2009-02-17 17:26:38.000000000 +0900
+++ ioemu-remote/hw/sun4u.c     2009-02-17 17:28:20.000000000 +0900
@@ -478,7 +478,7 @@ static void sun4uv_init(ram_addr_t RAM_s
     for(i = 0; i < nb_nics; i++) {
         if (!nd_table[i].model)
             nd_table[i].model = "ne2k_pci";
-        pci_nic_init(pci_bus, &nd_table[i], -1);
+        pci_nic_init(pci_bus, &nd_table[i], PCI_DEVFN_AUTO);
     }
 
     irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
@@ -496,7 +496,7 @@ static void sun4uv_init(ram_addr_t RAM_s
     }
 
     // XXX pci_cmd646_ide_init(pci_bus, hd, 1);
-    pci_piix3_ide_init(pci_bus, hd, -1, irq);
+    pci_piix3_ide_init(pci_bus, hd, PCI_DEVFN_AUTO, irq);
     /* FIXME: wire up interrupts.  */
     i8042_init(NULL/*1*/, NULL/*12*/, 0x60);
     for(i = 0; i < MAX_FD; i++) {
Index: ioemu-remote/hw/versatilepb.c
===================================================================
--- ioemu-remote.orig/hw/versatilepb.c  2009-02-17 17:28:19.000000000 +0900
+++ ioemu-remote/hw/versatilepb.c       2009-02-17 17:28:20.000000000 +0900
@@ -203,7 +203,7 @@ static void versatile_init(ram_addr_t ra
         if (strcmp(nd->model, "smc91c111") == 0) {
             smc91c111_init(nd, 0x10010000, sic[25]);
         } else {
-            pci_nic_init(pci_bus, nd, -1);
+            pci_nic_init(pci_bus, nd, PCI_DEVFN_AUTO);
         }
     }
     if (usb_enabled) {
Index: ioemu-remote/hw/piix_pci.c
===================================================================
--- ioemu-remote.orig/hw/piix_pci.c     2009-02-17 17:28:18.000000000 +0900
+++ ioemu-remote/hw/piix_pci.c  2009-02-17 17:28:20.000000000 +0900
@@ -354,7 +354,7 @@ int piix3_init(PCIBus *bus)
     uint8_t *pci_conf;
 
     d = pci_register_device(bus, "PIIX3", sizeof(PCIDevice),
-                                    -1, NULL, piix3_write_config);
+                                    PCI_DEVFN_AUTO, NULL, piix3_write_config);
     register_savevm("PIIX3", 0, 2, piix_save, piix_load, d);
 
     piix3_dev = d;
Index: ioemu-remote/hw/usb-ohci.c
===================================================================
--- ioemu-remote.orig/hw/usb-ohci.c     2009-02-17 17:28:19.000000000 +0900
+++ ioemu-remote/hw/usb-ohci.c  2009-02-17 17:28:20.000000000 +0900
@@ -1649,7 +1649,7 @@ void usb_ohci_init_pci(struct PCIBus *bu
     int did = 0x003f;
 
     ohci = (OHCIPCIState *)pci_register_device(bus, "OHCI USB", sizeof(*ohci),
-                                               -1, NULL, NULL);
+                                               PCI_DEVFN_AUTO, NULL, NULL);
     if (ohci == NULL) {
         fprintf(stderr, "usb-ohci: Failed to register PCI device\n");
         return;

-- 

-- 
Simon Horman
  VA Linux Systems Japan K.K., Sydney, Australia Satellite Office
  H: www.vergenet.net/~horms/             W: www.valinux.co.jp/en


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.