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

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



commit 9ff4b6cf7ad4810d179b9330fe2afa2a9a0f1f89
Author: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Date:   Wed Jun 3 15:37:02 2009 +0100

    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(-)

diff --git a/hw/pass-through.c b/hw/pass-through.c
index 57c2c27..a5b34ff 100644
--- a/hw/pass-through.c
+++ b/hw/pass-through.c
@@ -914,7 +914,8 @@ static int __insert_to_pci_slot(int bus, int dev, int func, 
int slot,
     /* 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 */
@@ -925,7 +926,8 @@ static int __insert_to_pci_slot(int bus, int dev, int func, 
int slot,
     /* 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;
     }
 
@@ -1374,7 +1376,7 @@ static void pt_pci_write_config(PCIDevice *d, uint32_t 
address, uint32_t val,
 
 #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
 
@@ -1383,7 +1385,7 @@ static void pt_pci_write_config(PCIDevice *d, uint32_t 
address, uint32_t val,
     {
         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;
     }
@@ -1393,7 +1395,7 @@ static void pt_pci_write_config(PCIDevice *d, uint32_t 
address, uint32_t val,
     {
         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;
     }
@@ -1403,7 +1405,7 @@ static void pt_pci_write_config(PCIDevice *d, uint32_t 
address, uint32_t val,
     {
         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;
     }
@@ -1415,8 +1417,8 @@ static void pt_pci_write_config(PCIDevice *d, uint32_t 
address, uint32_t val,
     {
         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 */
@@ -1437,8 +1439,8 @@ static void pt_pci_write_config(PCIDevice *d, uint32_t 
address, uint32_t val,
             /* 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;
         }
     }
@@ -1566,7 +1568,7 @@ static uint32_t pt_pci_read_config(PCIDevice *d, uint32_t 
address, int len)
     {
         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;
     }
@@ -1576,7 +1578,7 @@ static uint32_t pt_pci_read_config(PCIDevice *d, uint32_t 
address, int len)
     {
         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;
     }
@@ -1586,7 +1588,7 @@ static uint32_t pt_pci_read_config(PCIDevice *d, uint32_t 
address, int len)
     {
         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;
     }
@@ -1700,7 +1702,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
 
@@ -2036,8 +2038,7 @@ static void pt_bar_mapping_one(struct pt_dev *ptdev, int 
bar, int io_enable,
     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)
@@ -2073,7 +2074,7 @@ static int check_power_state(struct pt_dev *ptdev)
     {
         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;
     }
@@ -2235,7 +2236,7 @@ static void pt_config_restore(struct pt_dev *ptdev)
 
 #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
 
@@ -2283,7 +2284,7 @@ static int pt_init_pci_config(struct pt_dev *ptdev)
 
     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);
@@ -2297,7 +2298,7 @@ static int pt_init_pci_config(struct pt_dev *ptdev)
     /* 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;
 
@@ -3327,8 +3328,7 @@ static int pt_bar_reg_write(struct pt_dev *ptdev,
                 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 */
@@ -3344,9 +3344,8 @@ static int pt_bar_reg_write(struct pt_dev *ptdev,
                 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;
@@ -3495,7 +3494,7 @@ static int pt_pmcsr_reg_write(struct pt_dev *ptdev,
     {
         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;
@@ -3508,7 +3507,7 @@ static int pt_pmcsr_reg_write(struct pt_dev *ptdev,
     {
         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;
@@ -4114,7 +4113,7 @@ static struct pt_dev * register_real_device(PCIBus *e_bus,
     /* 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;
 
@@ -4173,7 +4172,7 @@ static int unregister_real_device(int slot)
     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;
diff --git a/hw/pt-msi.c b/hw/pt-msi.c
index 9f4a3b3..be22e09 100644
--- a/hw/pt-msi.c
+++ b/hw/pt-msi.c
@@ -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_dev* dev)
         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_dev *dev)
     /* 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_dev *dev, int 
entry_nr)
     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;
--
generated by git-patchbot for /home/xen/git/qemu-xen-unstable.git

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


 


Rackspace

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