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

[Xen-devel] [patch] qemu-xen: pass-through: Make use of PCI_FUNC, PCI_SLOT and PCI_DEVFN macros



This is mostly cosmetic, but debug statements asside
I think that it does make things somewhat easier to work with.

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

--- 

 hw/pass-through.c |   57 ++++++++++++++++++++++++++---------------------------
 hw/pt-msi.c       |   23 ++++++++++-----------
 2 files changed, 39 insertions(+), 41 deletions(-)

Index: ioemu-remote/hw/pt-msi.c
===================================================================
--- ioemu-remote.orig/hw/pt-msi.c       2009-06-01 11:46:22.000000000 +1000
+++ ioemu-remote/hw/pt-msi.c    2009-06-01 12:20:39.000000000 +1000
@@ -73,7 +73,8 @@ int pt_msi_setup(struct pt_dev *dev)
     }
 
     if ( xc_physdev_map_pirq_msi(xc_handle, domid, AUTO_ASSIGN, &pirq,
-                                 dev->pci_dev->dev << 3 | dev->pci_dev->func,
+                                 PCI_DEVFN(dev->pci_dev->dev,
+                                           dev->pci_dev->func),
                                  dev->pci_dev->bus, 0, 0) )
     {
         PT_LOG("Error: Mapping of MSI failed.\n");
@@ -151,7 +152,7 @@ void pt_msi_disable(struct pt_dev *dev)
 
     msi_set_enable(dev, 0);
 
-    e_device = (dev->dev.devfn >> 3) & 0x1f;
+    e_device = PCI_SLOT(dev->dev.devfn);
     /* fix virtual interrupt pin to INTA# */
     e_intx = 0;
 
@@ -179,8 +180,7 @@ void pt_msi_disable(struct pt_dev *dev)
                                         dev->msi->pirq, gflags))
         {
             PT_LOG("Error: Unbinding of MSI failed. [%02x:%02x.%x]\n",
-                pci_bus_num(d->bus),
-                ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7));
+                pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
             goto out;
         }
     }
@@ -192,8 +192,7 @@ void pt_msi_disable(struct pt_dev *dev)
         if (xc_physdev_unmap_pirq(xc_handle, domid, dev->msi->pirq))
         {
             PT_LOG("Error: Unmapping of MSI failed. [%02x:%02x.%x]\n",
-               pci_bus_num(d->bus),
-               ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7));
+               pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
             goto out;
         }
     }
@@ -223,7 +222,7 @@ int pt_enable_msi_translate(struct pt_de
         return -1;
     }
 
-    e_device = (dev->dev.devfn >> 3) & 0x1f;
+    e_device = PCI_SLOT(dev->dev.devfn);
     /* fix virtual interrupt pin to INTA# */
     e_intx = 0;
 
@@ -253,7 +252,7 @@ void pt_disable_msi_translate(struct pt_
     /* MSI_ENABLE bit should be disabed until the new handler is set */
     msi_set_enable(dev, 0);
 
-    e_device = (dev->dev.devfn >> 3) & 0x1f;
+    e_device = PCI_SLOT(dev->dev.devfn);
     /* fix virtual interrupt pin to INTA# */
     e_intx = 0;
 
@@ -297,7 +296,8 @@ static int pt_msix_update_one(struct pt_
     if ( entry->pirq == -1 )
     {
         ret = xc_physdev_map_pirq_msi(xc_handle, domid, AUTO_ASSIGN, &pirq,
-                                dev->pci_dev->dev << 3 | dev->pci_dev->func,
+                                PCI_DEVFN(dev->pci_dev->dev,
+                                          dev->pci_dev->func),
                                 dev->pci_dev->bus, entry_nr,
                                 dev->msix->table_base);
         if ( ret )
@@ -369,8 +369,7 @@ void pt_msix_disable(struct pt_dev *dev)
         if (xc_domain_unbind_msi_irq(xc_handle, domid, gvec,
                                         entry->pirq, gflags))
             PT_LOG("Error: Unbinding of MSI-X failed. [%02x:%02x.%x]\n",
-                pci_bus_num(d->bus),
-                ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7));
+                pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
         else
         {
             PT_LOG("Unmap msix with pirq %x\n", entry->pirq);
@@ -379,7 +378,7 @@ void pt_msix_disable(struct pt_dev *dev)
                                          domid, entry->pirq))
                 PT_LOG("Error: Unmapping of MSI-X failed. [%02x:%02x.%x]\n",
                     pci_bus_num(d->bus),
-                    ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7));
+                    PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
         }
         /* clear msi-x info */
         entry->pirq = -1;
Index: ioemu-remote/hw/pass-through.c
===================================================================
--- ioemu-remote.orig/hw/pass-through.c 2009-06-01 12:19:59.000000000 +1000
+++ ioemu-remote/hw/pass-through.c      2009-06-01 12:20:39.000000000 +1000
@@ -911,7 +911,8 @@ static int __insert_to_pci_slot(int bus,
     /* preferred virt pci slot */
     if ( slot != AUTO_PHP_SLOT)
     {
-        if ( !test_pci_slot(slot) && !pci_devfn_in_use(e_bus, slot << 3) )
+        if ( !test_pci_slot(slot) &&
+             !pci_devfn_in_use(e_bus, PCI_DEVFN(slot, 0)) )
             goto found;
         if ( pci_slot_match(bus, dev, func, slot) )
             /* The slot is already here, just return */
@@ -922,7 +923,8 @@ static int __insert_to_pci_slot(int bus,
     /* slot == 0, pick up a free one */
     for ( slot = 0; slot < NR_PCI_DEV; slot++ )
     {
-        if ( !test_pci_slot(slot) && !pci_devfn_in_use(e_bus, slot << 3) )
+        if ( !test_pci_slot(slot) &&
+             !pci_devfn_in_use(e_bus, PCI_DEVFN(slot, 0)) )
             goto found;
     }
 
@@ -1184,7 +1186,7 @@ static void pt_pci_write_config(PCIDevic
 
 #ifdef PT_DEBUG_PCI_CONFIG_ACCESS
     PT_LOG("[%02x:%02x.%x]: address=%04x val=0x%08x len=%d\n",
-       pci_bus_num(d->bus), (d->devfn >> 3) & 0x1F, (d->devfn & 0x7),
+       pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
        address, val, len);
 #endif
 
@@ -1193,7 +1195,7 @@ static void pt_pci_write_config(PCIDevic
     {
         PT_LOG("Error: Failed to write register with offset exceeding FFh. "
             "[%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             address, len);
         goto exit;
     }
@@ -1203,7 +1205,7 @@ static void pt_pci_write_config(PCIDevic
     {
         PT_LOG("Error: Failed to write register with invalid access length. "
             "[%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             address, len);
         goto exit;
     }
@@ -1213,7 +1215,7 @@ static void pt_pci_write_config(PCIDevic
     {
         PT_LOG("Error: Failed to write register with invalid access size "
             "alignment. [%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             address, len);
         goto exit;
     }
@@ -1225,8 +1227,8 @@ static void pt_pci_write_config(PCIDevic
     {
         PT_LOG("Warning: Guest attempt to set address to unused Base Address "
             "Register. [%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F),
-            (d->devfn & 0x7), address, len);
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
+            address, len);
     }
 
     /* check power state transition flags */
@@ -1247,8 +1249,8 @@ static void pt_pci_write_config(PCIDevic
             /* ignore silently */
             PT_LOG("Warning: Access to 0 Hardwired register. "
                 "[%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-                pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F),
-                (d->devfn & 0x7), address, len);
+                pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
+                address, len);
             goto exit;
         }
     }
@@ -1376,7 +1378,7 @@ static uint32_t pt_pci_read_config(PCIDe
     {
         PT_LOG("Error: Failed to read register with offset exceeding FFh. "
             "[%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             address, len);
         goto exit;
     }
@@ -1386,7 +1388,7 @@ static uint32_t pt_pci_read_config(PCIDe
     {
         PT_LOG("Error: Failed to read register with invalid access length. "
             "[%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             address, len);
         goto exit;
     }
@@ -1396,7 +1398,7 @@ static uint32_t pt_pci_read_config(PCIDe
     {
         PT_LOG("Error: Failed to read register with invalid access size "
             "alignment. [%02x:%02x.%x][Offset:%02xh][Length:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             address, len);
         goto exit;
     }
@@ -1510,7 +1512,7 @@ exit:
 
 #ifdef PT_DEBUG_PCI_CONFIG_ACCESS
     PT_LOG("[%02x:%02x.%x]: address=%04x val=0x%08x len=%d\n",
-       pci_bus_num(d->bus), (d->devfn >> 3) & 0x1F, (d->devfn & 0x7),
+       pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
        address, val, len);
 #endif
 
@@ -1846,8 +1848,7 @@ static void pt_bar_mapping_one(struct pt
     if (ret > 0)
         PT_LOG("Warning: ptdev[%02x:%02x.%x][Region:%d][Address:%08xh]"
             "[Size:%08xh] is overlapped.\n", pci_bus_num(dev->bus),
-            (dev->devfn >> 3) & 0x1F, (dev->devfn & 0x7),
-            bar, r_addr, r_size);
+            PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), bar, r_addr, r_size);
 
     /* check whether we need to update the mapping or not */
     if (r_addr != ptdev->bases[bar].e_physbase)
@@ -1883,7 +1884,7 @@ static int check_power_state(struct pt_d
     {
         PT_LOG("Error: Failed to change power state. "
             "[%02x:%02x.%x][requested state:%d][current state:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             pm_state->req_state, cur_state);
         return -1;
     }
@@ -2045,7 +2046,7 @@ static void pt_config_restore(struct pt_
 
 #ifdef PT_DEBUG_PCI_CONFIG_ACCESS
             PT_LOG("[%02x:%02x.%x]: address=%04x val=0x%08x len=%d\n",
-                pci_bus_num(d->bus), (d->devfn >> 3) & 0x1F, (d->devfn & 0x7),
+                pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
                 real_offset, val, reg->size);
 #endif
 
@@ -2093,7 +2094,7 @@ static int pt_init_pci_config(struct pt_
 
     PT_LOG("Reinitialize PCI configuration registers "
         "due to power state transition with internal reset. [%02x:%02x.%x]\n",
-        pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7));
+        pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn));
 
     /* restore a part of I/O device register */
     pt_config_restore(ptdev);
@@ -2107,7 +2108,7 @@ static int pt_init_pci_config(struct pt_
     /* rebind machine_irq to device */
     if (ret < 0 && ptdev->machine_irq != 0)
     {
-        uint8_t e_device = (ptdev->dev.devfn >> 3) & 0x1f;
+        uint8_t e_device = PCI_SLOT(ptdev->dev.devfn);
         /* fix virtual interrupt pin to INTA# */
         uint8_t e_intx = 0;
 
@@ -3125,8 +3126,7 @@ static int pt_bar_reg_write(struct pt_de
                 PT_LOG("Warning: Guest attempt to set Base Address "
                     "over the 64KB. "
                     
"[%02x:%02x.%x][Offset:%02xh][Address:%08xh][Size:%08xh]\n",
-                    pci_bus_num(d->bus),
-                    ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+                    pci_bus_num(d->bus), PCI_SLOT(d->devfn), 
PCI_FUNC(d->devfn),
                     reg->offset, new_addr, r_size);
             }
             /* just remove mapping */
@@ -3142,9 +3142,8 @@ static int pt_bar_reg_write(struct pt_de
                 PT_LOG("Warning: Guest attempt to set high MMIO Base Address. "
                     "Ignore mapping. "
                     "[%02x:%02x.%x][Offset:%02xh][High Address:%08xh]\n",
-                    pci_bus_num(d->bus),
-                    ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
-                    reg->offset, cfg_entry->data);
+                    pci_bus_num(d->bus), PCI_SLOT(d->devfn),
+                    PCI_FUNC(d->devfn), reg->offset, cfg_entry->data);
             }
             /* clear lower address */
             d->io_regions[index-1].addr = -1;
@@ -3293,7 +3292,7 @@ static int pt_pmcsr_reg_write(struct pt_
     {
         PT_LOG("Error: Invalid power transition. "
             "[%02x:%02x.%x][requested state:%d][current state:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             pm_state->req_state, pm_state->cur_state);
 
         return 0;
@@ -3306,7 +3305,7 @@ static int pt_pmcsr_reg_write(struct pt_
     {
         PT_LOG("Error: Invalid power transition. "
             "[%02x:%02x.%x][requested state:%d][current state:%d]\n",
-            pci_bus_num(d->bus), ((d->devfn >> 3) & 0x1F), (d->devfn & 0x7),
+            pci_bus_num(d->bus), PCI_SLOT(d->devfn), PCI_FUNC(d->devfn),
             pm_state->req_state, pm_state->cur_state);
 
         return 0;
@@ -3904,7 +3903,7 @@ static struct pt_dev * register_real_dev
     /* bind machine_irq to device */
     if (rc < 0 && machine_irq != 0)
     {
-        e_device = (assigned_device->dev.devfn >> 3) & 0x1f;
+        e_device = PCI_SLOT(assigned_device->dev.devfn);
         /* fix virtual interrupt pin to INTA# */
         e_intx = 0;
 
@@ -3963,7 +3962,7 @@ static int unregister_real_device(int sl
     pci_hide_device((PCIDevice*)assigned_device);
 
     /* Unbind interrupt */
-    e_device = (assigned_device->dev.devfn >> 3) & 0x1f;
+    e_device = PCI_SLOT(assigned_device->dev.devfn);
     /* fix virtual interrupt pin to INTA# */
     e_intx = 0;
     machine_irq = assigned_device->machine_irq;

_______________________________________________
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®.