175 lines
5.2 KiB
Diff
175 lines
5.2 KiB
Diff
|
# HG changeset patch
|
||
|
# User Jan Beulich <jbeulich@novell.com>
|
||
|
# Date 1311081248 -3600
|
||
|
# Node ID 4dc6a9ba90d60fdf0cc0898fc9a8fe84ae9030fc
|
||
|
# Parent b3434f24b0827c5ef34e4b4a72893288e2ffbe40
|
||
|
PCI: consolidate interface for adding devices
|
||
|
|
||
|
The functionality of pci_add_device_ext() can be easily folded into
|
||
|
pci_add_device(), and eliminates the need to change two functions for
|
||
|
future adjustments.
|
||
|
|
||
|
Signed-off-by: Jan Beulich <jbeulich@novell.com>
|
||
|
|
||
|
--- a/xen/arch/ia64/xen/hypercall.c
|
||
|
+++ b/xen/arch/ia64/xen/hypercall.c
|
||
|
@@ -662,8 +662,8 @@ long do_physdev_op(int cmd, XEN_GUEST_HA
|
||
|
if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
|
||
|
break;
|
||
|
|
||
|
- ret = pci_add_device(manage_pci.bus, manage_pci.devfn);
|
||
|
- break;
|
||
|
+ ret = pci_add_device(manage_pci.bus, manage_pci.devfn, NULL);
|
||
|
+ break;
|
||
|
}
|
||
|
|
||
|
case PHYSDEVOP_manage_pci_remove: {
|
||
|
@@ -695,10 +695,10 @@ long do_physdev_op(int cmd, XEN_GUEST_HA
|
||
|
pdev_info.is_virtfn = manage_pci_ext.is_virtfn;
|
||
|
pdev_info.physfn.bus = manage_pci_ext.physfn.bus;
|
||
|
pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
|
||
|
- ret = pci_add_device_ext(manage_pci_ext.bus,
|
||
|
- manage_pci_ext.devfn,
|
||
|
- &pdev_info);
|
||
|
- break;
|
||
|
+ ret = pci_add_device(manage_pci_ext.bus,
|
||
|
+ manage_pci_ext.devfn,
|
||
|
+ &pdev_info);
|
||
|
+ break;
|
||
|
}
|
||
|
|
||
|
default:
|
||
|
--- a/xen/arch/x86/physdev.c
|
||
|
+++ b/xen/arch/x86/physdev.c
|
||
|
@@ -472,7 +472,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
|
||
|
if ( copy_from_guest(&manage_pci, arg, 1) != 0 )
|
||
|
break;
|
||
|
|
||
|
- ret = pci_add_device(manage_pci.bus, manage_pci.devfn);
|
||
|
+ ret = pci_add_device(manage_pci.bus, manage_pci.devfn, NULL);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
@@ -509,9 +509,9 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_H
|
||
|
pdev_info.is_virtfn = manage_pci_ext.is_virtfn;
|
||
|
pdev_info.physfn.bus = manage_pci_ext.physfn.bus;
|
||
|
pdev_info.physfn.devfn = manage_pci_ext.physfn.devfn;
|
||
|
- ret = pci_add_device_ext(manage_pci_ext.bus,
|
||
|
- manage_pci_ext.devfn,
|
||
|
- &pdev_info);
|
||
|
+ ret = pci_add_device(manage_pci_ext.bus,
|
||
|
+ manage_pci_ext.devfn,
|
||
|
+ &pdev_info);
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
--- a/xen/drivers/passthrough/pci.c
|
||
|
+++ b/xen/drivers/passthrough/pci.c
|
||
|
@@ -142,16 +142,29 @@ void pci_enable_acs(struct pci_dev *pdev
|
||
|
pci_conf_write16(bus, dev, func, pos + PCI_ACS_CTRL, ctrl);
|
||
|
}
|
||
|
|
||
|
-int pci_add_device(u8 bus, u8 devfn)
|
||
|
+int pci_add_device(u8 bus, u8 devfn, const struct pci_dev_info *info)
|
||
|
{
|
||
|
struct pci_dev *pdev;
|
||
|
+ const char *pdev_type;
|
||
|
int ret = -ENOMEM;
|
||
|
|
||
|
+ if (!info)
|
||
|
+ pdev_type = "device";
|
||
|
+ else if (info->is_extfn)
|
||
|
+ pdev_type = "extended function";
|
||
|
+ else if (info->is_virtfn)
|
||
|
+ pdev_type = "virtual function";
|
||
|
+ else
|
||
|
+ return -EINVAL;
|
||
|
+
|
||
|
spin_lock(&pcidevs_lock);
|
||
|
pdev = alloc_pdev(bus, devfn);
|
||
|
if ( !pdev )
|
||
|
goto out;
|
||
|
|
||
|
+ if ( info )
|
||
|
+ pdev->info = *info;
|
||
|
+
|
||
|
ret = 0;
|
||
|
if ( !pdev->domain )
|
||
|
{
|
||
|
@@ -169,8 +182,8 @@ int pci_add_device(u8 bus, u8 devfn)
|
||
|
|
||
|
out:
|
||
|
spin_unlock(&pcidevs_lock);
|
||
|
- printk(XENLOG_DEBUG "PCI add device %02x:%02x.%x\n", bus,
|
||
|
- PCI_SLOT(devfn), PCI_FUNC(devfn));
|
||
|
+ printk(XENLOG_DEBUG "PCI add %s %02x:%02x.%x\n", pdev_type,
|
||
|
+ bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
@@ -197,51 +210,6 @@ int pci_remove_device(u8 bus, u8 devfn)
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
-int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info)
|
||
|
-{
|
||
|
- int ret;
|
||
|
- char *pdev_type;
|
||
|
- struct pci_dev *pdev;
|
||
|
-
|
||
|
- if (info->is_extfn)
|
||
|
- pdev_type = "Extended Function";
|
||
|
- else if (info->is_virtfn)
|
||
|
- pdev_type = "Virtual Function";
|
||
|
- else
|
||
|
- return -EINVAL;
|
||
|
-
|
||
|
-
|
||
|
- ret = -ENOMEM;
|
||
|
- spin_lock(&pcidevs_lock);
|
||
|
- pdev = alloc_pdev(bus, devfn);
|
||
|
- if ( !pdev )
|
||
|
- goto out;
|
||
|
-
|
||
|
- pdev->info = *info;
|
||
|
-
|
||
|
- ret = 0;
|
||
|
- if ( !pdev->domain )
|
||
|
- {
|
||
|
- pdev->domain = dom0;
|
||
|
- ret = iommu_add_device(pdev);
|
||
|
- if ( ret )
|
||
|
- {
|
||
|
- pdev->domain = NULL;
|
||
|
- goto out;
|
||
|
- }
|
||
|
-
|
||
|
- list_add(&pdev->domain_list, &dom0->arch.pdev_list);
|
||
|
- pci_enable_acs(pdev);
|
||
|
- }
|
||
|
-
|
||
|
-out:
|
||
|
- spin_unlock(&pcidevs_lock);
|
||
|
- printk(XENLOG_DEBUG "PCI add %s %02x:%02x.%x\n", pdev_type,
|
||
|
- bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
|
||
|
-
|
||
|
- return ret;
|
||
|
-}
|
||
|
-
|
||
|
static void pci_clean_dpci_irqs(struct domain *d)
|
||
|
{
|
||
|
struct hvm_irq_dpci *hvm_irq_dpci = NULL;
|
||
|
--- a/xen/include/xen/pci.h
|
||
|
+++ b/xen/include/xen/pci.h
|
||
|
@@ -86,9 +86,8 @@ struct pci_dev *pci_lock_pdev(int bus, i
|
||
|
struct pci_dev *pci_lock_domain_pdev(struct domain *d, int bus, int devfn);
|
||
|
|
||
|
void pci_release_devices(struct domain *d);
|
||
|
-int pci_add_device(u8 bus, u8 devfn);
|
||
|
+int pci_add_device(u8 bus, u8 devfn, const struct pci_dev_info *);
|
||
|
int pci_remove_device(u8 bus, u8 devfn);
|
||
|
-int pci_add_device_ext(u8 bus, u8 devfn, struct pci_dev_info *info);
|
||
|
struct pci_dev *pci_get_pdev(int bus, int devfn);
|
||
|
struct pci_dev *pci_get_pdev_by_domain(struct domain *d, int bus, int devfn);
|
||
|
|