ia64/xen-unstable

changeset 16084:56f158c8644b

vt-d: Clean up iommu code.
Signed-off-by: Weidong Han <weidong.han@intel.com>
author Keir Fraser <keir@xensource.com>
date Tue Oct 09 16:42:42 2007 +0100 (2007-10-09)
parents dcab07f0776d
children dc0199ff3968
files xen/arch/x86/hvm/vmx/vtd/intel-iommu.c
line diff
     1.1 --- a/xen/arch/x86/hvm/vmx/vtd/intel-iommu.c	Tue Oct 09 16:06:50 2007 +0100
     1.2 +++ b/xen/arch/x86/hvm/vmx/vtd/intel-iommu.c	Tue Oct 09 16:42:42 2007 +0100
     1.3 @@ -412,14 +412,8 @@ static int __iommu_flush_iotlb(struct io
     1.4          BUG();
     1.5      }
     1.6      /* Note: set drain read/write */
     1.7 -#if 0
     1.8 -    /*
     1.9 -     * This is probably to be super secure.. Looks like we can
    1.10 -     * ignore it without any impact.
    1.11 -     */
    1.12      if ( cap_read_drain(iommu->cap) )
    1.13          val |= DMA_TLB_READ_DRAIN;
    1.14 -#endif
    1.15      if ( cap_write_drain(iommu->cap) )
    1.16          val |= DMA_TLB_WRITE_DRAIN;
    1.17  
    1.18 @@ -641,8 +635,11 @@ static int iommu_set_root_entry(struct i
    1.19      unsigned long flags;
    1.20  
    1.21      if ( iommu == NULL )
    1.22 +    {
    1.23          gdprintk(XENLOG_ERR VTDPREFIX,
    1.24                   "iommu_set_root_entry: iommu == NULL\n");
    1.25 +        return -EINVAL;
    1.26 +    }
    1.27  
    1.28      if ( unlikely(!iommu->root_entry) )
    1.29      {
    1.30 @@ -1156,8 +1153,9 @@ static int domain_context_mapping(
    1.31      u32 type;
    1.32  
    1.33      type = pdev_type(pdev);
    1.34 -    if ( type == DEV_TYPE_PCI_BRIDGE )
    1.35 +    switch ( type )
    1.36      {
    1.37 +    case DEV_TYPE_PCI_BRIDGE:
    1.38          sec_bus = read_pci_config_byte(
    1.39              pdev->bus, PCI_SLOT(pdev->devfn),
    1.40              PCI_FUNC(pdev->devfn), PCI_SECONDARY_BUS);
    1.41 @@ -1181,20 +1179,15 @@ static int domain_context_mapping(
    1.42                      pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
    1.43                      sec_bus, sub_bus);
    1.44          }
    1.45 -    }
    1.46 -
    1.47 -    if ( type == DEV_TYPE_PCIe_ENDPOINT )
    1.48 -    {
    1.49 +        break;
    1.50 +    case DEV_TYPE_PCIe_ENDPOINT:
    1.51          gdprintk(XENLOG_INFO VTDPREFIX,
    1.52                   "domain_context_mapping:PCIe : bdf = %x:%x:%x\n",
    1.53                   pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
    1.54          ret = domain_context_mapping_one(domain, iommu,
    1.55 -                                         (u8)(pdev->bus), (u8) (pdev->devfn));
    1.56 -    }
    1.57 -
    1.58 -    /* PCI devices */
    1.59 -    if ( type == DEV_TYPE_PCI )
    1.60 -    {
    1.61 +                                         (u8)(pdev->bus), (u8)(pdev->devfn));
    1.62 +        break;
    1.63 +    case DEV_TYPE_PCI:
    1.64          gdprintk(XENLOG_INFO VTDPREFIX,
    1.65                   "domain_context_mapping:PCI: bdf = %x:%x:%x\n",
    1.66                   pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
    1.67 @@ -1202,14 +1195,14 @@ static int domain_context_mapping(
    1.68          if ( pdev->bus == 0 )
    1.69          {
    1.70              ret = domain_context_mapping_one(
    1.71 -                domain, iommu, (u8)(pdev->bus), (u8) (pdev->devfn));
    1.72 +                domain, iommu, (u8)(pdev->bus), (u8)(pdev->devfn));
    1.73          }
    1.74          else
    1.75          {
    1.76              if ( bus2bridge[pdev->bus].bus != 0 )
    1.77                  gdprintk(XENLOG_ERR VTDPREFIX,
    1.78                           "domain_context_mapping:bus2bridge"
    1.79 -                         "[pdev->bus].bus==0\n");
    1.80 +                         "[pdev->bus].bus != 0\n");
    1.81  
    1.82              ret = domain_context_mapping_one(
    1.83                  domain, iommu,
    1.84 @@ -1229,6 +1222,13 @@ static int domain_context_mapping(
    1.85                  }
    1.86              }
    1.87          }
    1.88 +        break;
    1.89 +    default:
    1.90 +        gdprintk(XENLOG_ERR VTDPREFIX,
    1.91 +                 "domain_context_mapping:unknown type : bdf = %x:%x:%x\n",
    1.92 +                 pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
    1.93 +        ret = -EINVAL;
    1.94 +        break;
    1.95      }
    1.96  
    1.97      return ret;
    1.98 @@ -1290,8 +1290,9 @@ static int domain_context_unmap(
    1.99      u32 type;
   1.100  
   1.101      type = pdev_type(pdev);
   1.102 -    if ( type == DEV_TYPE_PCI_BRIDGE )
   1.103 +    switch ( type )
   1.104      {
   1.105 +    case DEV_TYPE_PCI_BRIDGE:
   1.106          sec_bus = read_pci_config_byte(
   1.107              pdev->bus, PCI_SLOT(pdev->devfn),
   1.108              PCI_FUNC(pdev->devfn), PCI_SECONDARY_BUS);
   1.109 @@ -1304,20 +1305,15 @@ static int domain_context_unmap(
   1.110                   "sec_bus=%x sub_bus=%x\n",
   1.111                   pdev->bus, PCI_SLOT(pdev->devfn),
   1.112                   PCI_FUNC(pdev->devfn), sec_bus, sub_bus);
   1.113 -    }
   1.114 -
   1.115 -    if ( type == DEV_TYPE_PCIe_ENDPOINT )
   1.116 -    {
   1.117 +        break;
   1.118 +    case DEV_TYPE_PCIe_ENDPOINT:
   1.119          gdprintk(XENLOG_INFO VTDPREFIX,
   1.120                   "domain_context_unmap:PCIe : bdf = %x:%x:%x\n",
   1.121                   pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
   1.122          ret = domain_context_unmap_one(domain, iommu,
   1.123 -                                       (u8)(pdev->bus), (u8) (pdev->devfn));
   1.124 -    }
   1.125 -
   1.126 -    /* PCI devices */
   1.127 -    if ( type == DEV_TYPE_PCI )
   1.128 -    {
   1.129 +                                       (u8)(pdev->bus), (u8)(pdev->devfn));
   1.130 +        break;
   1.131 +    case DEV_TYPE_PCI:
   1.132          gdprintk(XENLOG_INFO VTDPREFIX,
   1.133                   "domain_context_unmap:PCI: bdf = %x:%x:%x\n",
   1.134                   pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
   1.135 @@ -1325,14 +1321,14 @@ static int domain_context_unmap(
   1.136          {
   1.137              ret = domain_context_unmap_one(
   1.138                  domain, iommu,
   1.139 -                (u8)(pdev->bus), (u8) (pdev->devfn));
   1.140 +                (u8)(pdev->bus), (u8)(pdev->devfn));
   1.141          }
   1.142          else
   1.143          {
   1.144              if ( bus2bridge[pdev->bus].bus != 0 )
   1.145                  gdprintk(XENLOG_INFO VTDPREFIX,
   1.146                           "domain_context_mapping:"
   1.147 -                         "bus2bridge[pdev->bus].bus==0\n");
   1.148 +                         "bus2bridge[pdev->bus].bus != 0\n");
   1.149  
   1.150              ret = domain_context_unmap_one(domain, iommu,
   1.151                                             (u8)(bus2bridge[pdev->bus].bus),
   1.152 @@ -1351,6 +1347,13 @@ static int domain_context_unmap(
   1.153                  }
   1.154              }
   1.155          }
   1.156 +        break;
   1.157 +    default:
   1.158 +        gdprintk(XENLOG_ERR VTDPREFIX,
   1.159 +                 "domain_context_unmap:unknown type: bdf = %x:%x:%x\n",
   1.160 +                 pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
   1.161 +        ret = -EINVAL;
   1.162 +        break;
   1.163      }
   1.164  
   1.165      return ret;
   1.166 @@ -1447,6 +1450,8 @@ void iommu_domain_teardown(struct domain
   1.167                  if ( pgd[0].val != 0 )
   1.168                      free_xenheap_page((void*)maddr_to_virt(
   1.169                          dma_pte_addr(pgd[0])));
   1.170 +
   1.171 +                free_xenheap_page((void *)hd->pgd);
   1.172              }
   1.173              break;
   1.174          default:
   1.175 @@ -1602,11 +1607,6 @@ void iommu_flush(struct domain *d, dma_a
   1.176      iommu_flush_cache_entry(iommu, pte);
   1.177  }
   1.178  
   1.179 -int prepare_device(struct domain *domain, struct pci_dev dev)
   1.180 -{
   1.181 -    return 0;
   1.182 -}
   1.183 -
   1.184  static int iommu_prepare_rmrr_dev(
   1.185      struct domain *d,
   1.186      struct acpi_rmrr_unit *rmrr,