Commit 83326063 authored by Bjorn Helgaas's avatar Bjorn Helgaas

Merge branch 'pci/shuah-defines' into next

* pci/shuah-defines:
  iommu/amd: Remove calc_devid() and use PCI_DEVID() from PCI
  iommu/amd: Remove local PCI_BUS() define and use PCI_BUS_NUM() from PCI
  PCI/AER: Remove local PCI_BUS() define and use PCI_BUS_NUM() from PCI
  PCI: Add PCI_BUS_NUM() and PCI_DEVID() interfaces
parents f6161aa1 6f2729ba
...@@ -173,7 +173,7 @@ static inline u16 get_device_id(struct device *dev) ...@@ -173,7 +173,7 @@ static inline u16 get_device_id(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
return calc_devid(pdev->bus->number, pdev->devfn); return PCI_DEVID(pdev->bus->number, pdev->devfn);
} }
static struct iommu_dev_data *get_dev_data(struct device *dev) static struct iommu_dev_data *get_dev_data(struct device *dev)
...@@ -649,26 +649,26 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt) ...@@ -649,26 +649,26 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
case EVENT_TYPE_ILL_DEV: case EVENT_TYPE_ILL_DEV:
printk("ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x " printk("ILLEGAL_DEV_TABLE_ENTRY device=%02x:%02x.%x "
"address=0x%016llx flags=0x%04x]\n", "address=0x%016llx flags=0x%04x]\n",
PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
address, flags); address, flags);
dump_dte_entry(devid); dump_dte_entry(devid);
break; break;
case EVENT_TYPE_IO_FAULT: case EVENT_TYPE_IO_FAULT:
printk("IO_PAGE_FAULT device=%02x:%02x.%x " printk("IO_PAGE_FAULT device=%02x:%02x.%x "
"domain=0x%04x address=0x%016llx flags=0x%04x]\n", "domain=0x%04x address=0x%016llx flags=0x%04x]\n",
PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
domid, address, flags); domid, address, flags);
break; break;
case EVENT_TYPE_DEV_TAB_ERR: case EVENT_TYPE_DEV_TAB_ERR:
printk("DEV_TAB_HARDWARE_ERROR device=%02x:%02x.%x " printk("DEV_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
"address=0x%016llx flags=0x%04x]\n", "address=0x%016llx flags=0x%04x]\n",
PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
address, flags); address, flags);
break; break;
case EVENT_TYPE_PAGE_TAB_ERR: case EVENT_TYPE_PAGE_TAB_ERR:
printk("PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x " printk("PAGE_TAB_HARDWARE_ERROR device=%02x:%02x.%x "
"domain=0x%04x address=0x%016llx flags=0x%04x]\n", "domain=0x%04x address=0x%016llx flags=0x%04x]\n",
PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
domid, address, flags); domid, address, flags);
break; break;
case EVENT_TYPE_ILL_CMD: case EVENT_TYPE_ILL_CMD:
...@@ -682,13 +682,13 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt) ...@@ -682,13 +682,13 @@ static void iommu_print_event(struct amd_iommu *iommu, void *__evt)
case EVENT_TYPE_IOTLB_INV_TO: case EVENT_TYPE_IOTLB_INV_TO:
printk("IOTLB_INV_TIMEOUT device=%02x:%02x.%x " printk("IOTLB_INV_TIMEOUT device=%02x:%02x.%x "
"address=0x%016llx]\n", "address=0x%016llx]\n",
PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
address); address);
break; break;
case EVENT_TYPE_INV_DEV_REQ: case EVENT_TYPE_INV_DEV_REQ:
printk("INVALID_DEVICE_REQUEST device=%02x:%02x.%x " printk("INVALID_DEVICE_REQUEST device=%02x:%02x.%x "
"address=0x%016llx flags=0x%04x]\n", "address=0x%016llx flags=0x%04x]\n",
PCI_BUS(devid), PCI_SLOT(devid), PCI_FUNC(devid), PCI_BUS_NUM(devid), PCI_SLOT(devid), PCI_FUNC(devid),
address, flags); address, flags);
break; break;
default: default:
......
...@@ -406,7 +406,7 @@ static int __init find_last_devid_on_pci(int bus, int dev, int fn, int cap_ptr) ...@@ -406,7 +406,7 @@ static int __init find_last_devid_on_pci(int bus, int dev, int fn, int cap_ptr)
u32 cap; u32 cap;
cap = read_pci_config(bus, dev, fn, cap_ptr+MMIO_RANGE_OFFSET); cap = read_pci_config(bus, dev, fn, cap_ptr+MMIO_RANGE_OFFSET);
update_last_devid(calc_devid(MMIO_GET_BUS(cap), MMIO_GET_LD(cap))); update_last_devid(PCI_DEVID(MMIO_GET_BUS(cap), MMIO_GET_LD(cap)));
return 0; return 0;
} }
...@@ -423,7 +423,7 @@ static int __init find_last_devid_from_ivhd(struct ivhd_header *h) ...@@ -423,7 +423,7 @@ static int __init find_last_devid_from_ivhd(struct ivhd_header *h)
p += sizeof(*h); p += sizeof(*h);
end += h->length; end += h->length;
find_last_devid_on_pci(PCI_BUS(h->devid), find_last_devid_on_pci(PCI_BUS_NUM(h->devid),
PCI_SLOT(h->devid), PCI_SLOT(h->devid),
PCI_FUNC(h->devid), PCI_FUNC(h->devid),
h->cap_ptr); h->cap_ptr);
...@@ -784,10 +784,10 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -784,10 +784,10 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_ALL\t\t\t first devid: %02x:%02x.%x" DUMP_printk(" DEV_ALL\t\t\t first devid: %02x:%02x.%x"
" last device %02x:%02x.%x flags: %02x\n", " last device %02x:%02x.%x flags: %02x\n",
PCI_BUS(iommu->first_device), PCI_BUS_NUM(iommu->first_device),
PCI_SLOT(iommu->first_device), PCI_SLOT(iommu->first_device),
PCI_FUNC(iommu->first_device), PCI_FUNC(iommu->first_device),
PCI_BUS(iommu->last_device), PCI_BUS_NUM(iommu->last_device),
PCI_SLOT(iommu->last_device), PCI_SLOT(iommu->last_device),
PCI_FUNC(iommu->last_device), PCI_FUNC(iommu->last_device),
e->flags); e->flags);
...@@ -801,7 +801,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -801,7 +801,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_SELECT\t\t\t devid: %02x:%02x.%x " DUMP_printk(" DEV_SELECT\t\t\t devid: %02x:%02x.%x "
"flags: %02x\n", "flags: %02x\n",
PCI_BUS(e->devid), PCI_BUS_NUM(e->devid),
PCI_SLOT(e->devid), PCI_SLOT(e->devid),
PCI_FUNC(e->devid), PCI_FUNC(e->devid),
e->flags); e->flags);
...@@ -813,7 +813,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -813,7 +813,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_SELECT_RANGE_START\t " DUMP_printk(" DEV_SELECT_RANGE_START\t "
"devid: %02x:%02x.%x flags: %02x\n", "devid: %02x:%02x.%x flags: %02x\n",
PCI_BUS(e->devid), PCI_BUS_NUM(e->devid),
PCI_SLOT(e->devid), PCI_SLOT(e->devid),
PCI_FUNC(e->devid), PCI_FUNC(e->devid),
e->flags); e->flags);
...@@ -827,11 +827,11 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -827,11 +827,11 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_ALIAS\t\t\t devid: %02x:%02x.%x " DUMP_printk(" DEV_ALIAS\t\t\t devid: %02x:%02x.%x "
"flags: %02x devid_to: %02x:%02x.%x\n", "flags: %02x devid_to: %02x:%02x.%x\n",
PCI_BUS(e->devid), PCI_BUS_NUM(e->devid),
PCI_SLOT(e->devid), PCI_SLOT(e->devid),
PCI_FUNC(e->devid), PCI_FUNC(e->devid),
e->flags, e->flags,
PCI_BUS(e->ext >> 8), PCI_BUS_NUM(e->ext >> 8),
PCI_SLOT(e->ext >> 8), PCI_SLOT(e->ext >> 8),
PCI_FUNC(e->ext >> 8)); PCI_FUNC(e->ext >> 8));
...@@ -846,11 +846,11 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -846,11 +846,11 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_ALIAS_RANGE\t\t " DUMP_printk(" DEV_ALIAS_RANGE\t\t "
"devid: %02x:%02x.%x flags: %02x " "devid: %02x:%02x.%x flags: %02x "
"devid_to: %02x:%02x.%x\n", "devid_to: %02x:%02x.%x\n",
PCI_BUS(e->devid), PCI_BUS_NUM(e->devid),
PCI_SLOT(e->devid), PCI_SLOT(e->devid),
PCI_FUNC(e->devid), PCI_FUNC(e->devid),
e->flags, e->flags,
PCI_BUS(e->ext >> 8), PCI_BUS_NUM(e->ext >> 8),
PCI_SLOT(e->ext >> 8), PCI_SLOT(e->ext >> 8),
PCI_FUNC(e->ext >> 8)); PCI_FUNC(e->ext >> 8));
...@@ -864,7 +864,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -864,7 +864,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_EXT_SELECT\t\t devid: %02x:%02x.%x " DUMP_printk(" DEV_EXT_SELECT\t\t devid: %02x:%02x.%x "
"flags: %02x ext: %08x\n", "flags: %02x ext: %08x\n",
PCI_BUS(e->devid), PCI_BUS_NUM(e->devid),
PCI_SLOT(e->devid), PCI_SLOT(e->devid),
PCI_FUNC(e->devid), PCI_FUNC(e->devid),
e->flags, e->ext); e->flags, e->ext);
...@@ -877,7 +877,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -877,7 +877,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_EXT_SELECT_RANGE\t devid: " DUMP_printk(" DEV_EXT_SELECT_RANGE\t devid: "
"%02x:%02x.%x flags: %02x ext: %08x\n", "%02x:%02x.%x flags: %02x ext: %08x\n",
PCI_BUS(e->devid), PCI_BUS_NUM(e->devid),
PCI_SLOT(e->devid), PCI_SLOT(e->devid),
PCI_FUNC(e->devid), PCI_FUNC(e->devid),
e->flags, e->ext); e->flags, e->ext);
...@@ -890,7 +890,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -890,7 +890,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
case IVHD_DEV_RANGE_END: case IVHD_DEV_RANGE_END:
DUMP_printk(" DEV_RANGE_END\t\t devid: %02x:%02x.%x\n", DUMP_printk(" DEV_RANGE_END\t\t devid: %02x:%02x.%x\n",
PCI_BUS(e->devid), PCI_BUS_NUM(e->devid),
PCI_SLOT(e->devid), PCI_SLOT(e->devid),
PCI_FUNC(e->devid)); PCI_FUNC(e->devid));
...@@ -924,7 +924,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu, ...@@ -924,7 +924,7 @@ static int __init init_iommu_from_acpi(struct amd_iommu *iommu,
DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %02x:%02x.%x\n", DUMP_printk(" DEV_SPECIAL(%s[%d])\t\tdevid: %02x:%02x.%x\n",
var, (int)handle, var, (int)handle,
PCI_BUS(devid), PCI_BUS_NUM(devid),
PCI_SLOT(devid), PCI_SLOT(devid),
PCI_FUNC(devid)); PCI_FUNC(devid));
...@@ -1086,7 +1086,7 @@ static int __init init_iommu_all(struct acpi_table_header *table) ...@@ -1086,7 +1086,7 @@ static int __init init_iommu_all(struct acpi_table_header *table)
DUMP_printk("device: %02x:%02x.%01x cap: %04x " DUMP_printk("device: %02x:%02x.%01x cap: %04x "
"seg: %d flags: %01x info %04x\n", "seg: %d flags: %01x info %04x\n",
PCI_BUS(h->devid), PCI_SLOT(h->devid), PCI_BUS_NUM(h->devid), PCI_SLOT(h->devid),
PCI_FUNC(h->devid), h->cap_ptr, PCI_FUNC(h->devid), h->cap_ptr,
h->pci_seg, h->flags, h->info); h->pci_seg, h->flags, h->info);
DUMP_printk(" mmio-addr: %016llx\n", DUMP_printk(" mmio-addr: %016llx\n",
...@@ -1116,7 +1116,7 @@ static int iommu_init_pci(struct amd_iommu *iommu) ...@@ -1116,7 +1116,7 @@ static int iommu_init_pci(struct amd_iommu *iommu)
int cap_ptr = iommu->cap_ptr; int cap_ptr = iommu->cap_ptr;
u32 range, misc, low, high; u32 range, misc, low, high;
iommu->dev = pci_get_bus_and_slot(PCI_BUS(iommu->devid), iommu->dev = pci_get_bus_and_slot(PCI_BUS_NUM(iommu->devid),
iommu->devid & 0xff); iommu->devid & 0xff);
if (!iommu->dev) if (!iommu->dev)
return -ENODEV; return -ENODEV;
...@@ -1128,9 +1128,9 @@ static int iommu_init_pci(struct amd_iommu *iommu) ...@@ -1128,9 +1128,9 @@ static int iommu_init_pci(struct amd_iommu *iommu)
pci_read_config_dword(iommu->dev, cap_ptr + MMIO_MISC_OFFSET, pci_read_config_dword(iommu->dev, cap_ptr + MMIO_MISC_OFFSET,
&misc); &misc);
iommu->first_device = calc_devid(MMIO_GET_BUS(range), iommu->first_device = PCI_DEVID(MMIO_GET_BUS(range),
MMIO_GET_FD(range)); MMIO_GET_FD(range));
iommu->last_device = calc_devid(MMIO_GET_BUS(range), iommu->last_device = PCI_DEVID(MMIO_GET_BUS(range),
MMIO_GET_LD(range)); MMIO_GET_LD(range));
if (!(iommu->cap & (1 << IOMMU_CAP_IOTLB))) if (!(iommu->cap & (1 << IOMMU_CAP_IOTLB)))
...@@ -1388,8 +1388,8 @@ static int __init init_unity_map_range(struct ivmd_header *m) ...@@ -1388,8 +1388,8 @@ static int __init init_unity_map_range(struct ivmd_header *m)
DUMP_printk("%s devid_start: %02x:%02x.%x devid_end: %02x:%02x.%x" DUMP_printk("%s devid_start: %02x:%02x.%x devid_end: %02x:%02x.%x"
" range_start: %016llx range_end: %016llx flags: %x\n", s, " range_start: %016llx range_end: %016llx flags: %x\n", s,
PCI_BUS(e->devid_start), PCI_SLOT(e->devid_start), PCI_BUS_NUM(e->devid_start), PCI_SLOT(e->devid_start),
PCI_FUNC(e->devid_start), PCI_BUS(e->devid_end), PCI_FUNC(e->devid_start), PCI_BUS_NUM(e->devid_end),
PCI_SLOT(e->devid_end), PCI_FUNC(e->devid_end), PCI_SLOT(e->devid_end), PCI_FUNC(e->devid_end),
e->address_start, e->address_end, m->flags); e->address_start, e->address_end, m->flags);
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/pci.h>
/* /*
* Maximum number of IOMMUs supported * Maximum number of IOMMUs supported
...@@ -315,9 +316,6 @@ ...@@ -315,9 +316,6 @@
#define MAX_DOMAIN_ID 65536 #define MAX_DOMAIN_ID 65536
/* FIXME: move this macro to <linux/pci.h> */
#define PCI_BUS(x) (((x) >> 8) & 0xff)
/* Protection domain flags */ /* Protection domain flags */
#define PD_DMA_OPS_MASK (1UL << 0) /* domain used for dma_ops */ #define PD_DMA_OPS_MASK (1UL << 0) /* domain used for dma_ops */
#define PD_DEFAULT_MASK (1UL << 1) /* domain is a default dma_ops #define PD_DEFAULT_MASK (1UL << 1) /* domain is a default dma_ops
...@@ -703,13 +701,6 @@ extern int amd_iommu_max_glx_val; ...@@ -703,13 +701,6 @@ extern int amd_iommu_max_glx_val;
*/ */
extern void iommu_flush_all_caches(struct amd_iommu *iommu); extern void iommu_flush_all_caches(struct amd_iommu *iommu);
/* takes bus and device/function and returns the device id
* FIXME: should that be in generic PCI code? */
static inline u16 calc_devid(u8 bus, u8 devfn)
{
return (((u16)bus) << 8) | devfn;
}
static inline int get_ioapic_devid(int id) static inline int get_ioapic_devid(int id)
{ {
struct devid_map *entry; struct devid_map *entry;
......
...@@ -89,8 +89,6 @@ static int add_error_device(struct aer_err_info *e_info, struct pci_dev *dev) ...@@ -89,8 +89,6 @@ static int add_error_device(struct aer_err_info *e_info, struct pci_dev *dev)
return -ENOSPC; return -ENOSPC;
} }
#define PCI_BUS(x) (((x) >> 8) & 0xff)
/** /**
* is_error_source - check whether the device is source of reported error * is_error_source - check whether the device is source of reported error
* @dev: pointer to pci_dev to be checked * @dev: pointer to pci_dev to be checked
...@@ -106,7 +104,7 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info) ...@@ -106,7 +104,7 @@ static bool is_error_source(struct pci_dev *dev, struct aer_err_info *e_info)
* When bus id is equal to 0, it might be a bad id * When bus id is equal to 0, it might be a bad id
* reported by root port. * reported by root port.
*/ */
if (!nosourceid && (PCI_BUS(e_info->id) != 0)) { if (!nosourceid && (PCI_BUS_NUM(e_info->id) != 0)) {
/* Device ID match? */ /* Device ID match? */
if (e_info->id == ((dev->bus->number << 8) | dev->devfn)) if (e_info->id == ((dev->bus->number << 8) | dev->devfn))
return true; return true;
......
...@@ -35,6 +35,21 @@ ...@@ -35,6 +35,21 @@
/* Include the ID list */ /* Include the ID list */
#include <linux/pci_ids.h> #include <linux/pci_ids.h>
/*
* The PCI interface treats multi-function devices as independent
* devices. The slot/function address of each device is encoded
* in a single byte as follows:
*
* 7:3 = slot
* 2:0 = function
* PCI_DEVFN(), PCI_SLOT(), and PCI_FUNC() are defined uapi/linux/pci.h
* In the interest of not exposing interfaces to user-space unnecessarily,
* the following kernel only defines are being added here.
*/
#define PCI_DEVID(bus, devfn) ((((u16)bus) << 8) | devfn)
/* return bus from PCI devid = ((u16)bus_number) << 8) | devfn */
#define PCI_BUS_NUM(x) (((x) >> 8) & 0xff)
/* pci_slot represents a physical slot */ /* pci_slot represents a physical slot */
struct pci_slot { struct pci_slot {
struct pci_bus *bus; /* The bus this slot is on */ struct pci_bus *bus; /* The bus this slot is on */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment