ia64/xen-unstable

changeset 18105:066ac1adb70c

amd iommu: support device add and remove for recent dom0 kernel
Signed-off-by: Wei Wang <wei.wang2@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jul 18 12:46:52 2008 +0100 (2008-07-18)
parents 27078831a864
children f4135a620f59
files xen/drivers/passthrough/amd/pci_amd_iommu.c
line diff
     1.1 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c	Fri Jul 18 12:44:58 2008 +0100
     1.2 +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c	Fri Jul 18 12:46:52 2008 +0100
     1.3 @@ -620,11 +620,49 @@ static int amd_iommu_return_device(
     1.4  
     1.5  static int amd_iommu_add_device(struct pci_dev *pdev)
     1.6  {
     1.7 +    struct amd_iommu *iommu;
     1.8 +    u16 bdf;
     1.9 +    if ( !pdev->domain )
    1.10 +        return -EINVAL;
    1.11 +
    1.12 +    bdf = (pdev->bus << 8) | pdev->devfn;
    1.13 +    iommu = (bdf < ivrs_bdf_entries) ?
    1.14 +    find_iommu_for_device(pdev->bus, pdev->devfn) : NULL;
    1.15 +
    1.16 +    if ( !iommu )
    1.17 +    {
    1.18 +        amd_iov_error("Fail to find iommu."
    1.19 +            " %x:%x.%x cannot be assigned to domain %d\n", 
    1.20 +            pdev->bus, PCI_SLOT(pdev->devfn),
    1.21 +            PCI_FUNC(pdev->devfn), pdev->domain->domain_id);
    1.22 +        return -ENODEV;
    1.23 +    }
    1.24 +
    1.25 +    amd_iommu_setup_domain_device(pdev->domain, iommu, bdf);
    1.26      return 0;
    1.27  }
    1.28  
    1.29  static int amd_iommu_remove_device(struct pci_dev *pdev)
    1.30  {
    1.31 +    struct amd_iommu *iommu;
    1.32 +    u16 bdf;
    1.33 +    if ( !pdev->domain )
    1.34 +        return -EINVAL;
    1.35 +
    1.36 +    bdf = (pdev->bus << 8) | pdev->devfn;
    1.37 +    iommu = (bdf < ivrs_bdf_entries) ?
    1.38 +    find_iommu_for_device(pdev->bus, pdev->devfn) : NULL;
    1.39 +
    1.40 +    if ( !iommu )
    1.41 +    {
    1.42 +        amd_iov_error("Fail to find iommu."
    1.43 +            " %x:%x.%x cannot be removed from domain %d\n", 
    1.44 +            pdev->bus, PCI_SLOT(pdev->devfn),
    1.45 +            PCI_FUNC(pdev->devfn), pdev->domain->domain_id);
    1.46 +        return -ENODEV;
    1.47 +    }
    1.48 +
    1.49 +    amd_iommu_disable_domain_device(pdev->domain, iommu, bdf);
    1.50      return 0;
    1.51  }
    1.52