/* 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 */
/* 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;
}
#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
{
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;
}
{
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;
}
{
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;
}
{
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 */
/* 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;
}
}
{
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;
}
{
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;
}
{
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;
}
#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
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)
{
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;
}
#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
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);
/* 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;
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 */
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;
{
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;
{
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;
/* 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;
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;
}
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");
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;
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;
}
}
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;
}
}
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;
/* 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;
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 )
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);
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;