[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] 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@xxxxxxxxxx> --- a/xen/arch/ia64/xen/hypercall.c +++ b/xen/arch/ia64/xen/hypercall.c @@ -665,8 +665,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: { @@ -698,10 +698,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 @@ -483,7 +483,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; } @@ -520,9 +520,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 @@ -143,16 +143,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 ) { @@ -170,8 +183,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; } @@ -198,51 +211,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 int pci_clean_dpci_irq(struct domain *d, struct hvm_pirq_dpci *pirq_dpci, void *arg) { --- 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); Attachment:
pci-add-device-unify.patch _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |