Merge branch 'iommu-fixes-2.6.28' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorIngo Molnar <mingo@elte.hu>
Thu, 6 Nov 2008 14:23:35 +0000 (15:23 +0100)
committerIngo Molnar <mingo@elte.hu>
Thu, 6 Nov 2008 14:23:35 +0000 (15:23 +0100)
1  2 
arch/x86/kernel/amd_iommu.c

@@@ -50,7 -50,7 +50,7 @@@ static int dma_ops_unity_map(struct dma
  /* returns !0 if the IOMMU is caching non-present entries in its TLB */
  static int iommu_has_npcache(struct amd_iommu *iommu)
  {
-       return iommu->cap & IOMMU_CAP_NPCACHE;
+       return iommu->cap & (1UL << IOMMU_CAP_NPCACHE);
  }
  
  /****************************************************************************
@@@ -201,10 -201,10 +201,10 @@@ static int iommu_queue_command(struct a
   */
  static int iommu_completion_wait(struct amd_iommu *iommu)
  {
 -      int ret, ready = 0;
 +      int ret = 0, ready = 0;
        unsigned status = 0;
        struct iommu_cmd cmd;
 -      unsigned long i = 0;
 +      unsigned long flags, i = 0;
  
        memset(&cmd, 0, sizeof(cmd));
        cmd.data[0] = CMD_COMPL_WAIT_INT_MASK;
  
        iommu->need_sync = 0;
  
 -      ret = iommu_queue_command(iommu, &cmd);
 +      spin_lock_irqsave(&iommu->lock, flags);
 +
 +      ret = __iommu_queue_command(iommu, &cmd);
  
        if (ret)
 -              return ret;
 +              goto out;
  
        while (!ready && (i < EXIT_LOOP_COUNT)) {
                ++i;
  
        if (unlikely((i == EXIT_LOOP_COUNT) && printk_ratelimit()))
                printk(KERN_WARNING "AMD IOMMU: Completion wait loop failed\n");
 +out:
 +      spin_unlock_irqrestore(&iommu->lock, flags);
  
        return 0;
  }
  static int iommu_queue_inv_dev_entry(struct amd_iommu *iommu, u16 devid)
  {
        struct iommu_cmd cmd;
 +      int ret;
  
        BUG_ON(iommu == NULL);
  
        CMD_SET_TYPE(&cmd, CMD_INV_DEV_ENTRY);
        cmd.data[0] = devid;
  
 +      ret = iommu_queue_command(iommu, &cmd);
 +
        iommu->need_sync = 1;
  
 -      return iommu_queue_command(iommu, &cmd);
 +      return ret;
  }
  
  /*
@@@ -266,7 -259,6 +266,7 @@@ static int iommu_queue_inv_iommu_pages(
                u64 address, u16 domid, int pde, int s)
  {
        struct iommu_cmd cmd;
 +      int ret;
  
        memset(&cmd, 0, sizeof(cmd));
        address &= PAGE_MASK;
        if (pde) /* PDE bit - we wan't flush everything not only the PTEs */
                cmd.data[2] |= CMD_INV_IOMMU_PAGES_PDE_MASK;
  
 +      ret = iommu_queue_command(iommu, &cmd);
 +
        iommu->need_sync = 1;
  
 -      return iommu_queue_command(iommu, &cmd);
 +      return ret;
  }
  
  /*
@@@ -295,7 -285,7 +295,7 @@@ static int iommu_flush_pages(struct amd
                u64 address, size_t size)
  {
        int s = 0;
 -      unsigned pages = iommu_num_pages(address, size);
 +      unsigned pages = iommu_num_pages(address, size, PAGE_SIZE);
  
        address &= PAGE_MASK;
  
@@@ -536,6 -526,9 +536,9 @@@ static void dma_ops_free_addresses(stru
  {
        address >>= PAGE_SHIFT;
        iommu_area_free(dom->bitmap, address, pages);
+       if (address + pages >= dom->next_bit)
+               dom->need_flush = true;
  }
  
  /****************************************************************************
@@@ -680,8 -673,7 +683,8 @@@ static struct dma_ops_domain *dma_ops_d
            iommu->exclusion_start < dma_dom->aperture_size) {
                unsigned long startpage = iommu->exclusion_start >> PAGE_SHIFT;
                int pages = iommu_num_pages(iommu->exclusion_start,
 -                                          iommu->exclusion_length);
 +                                          iommu->exclusion_length,
 +                                          PAGE_SIZE);
                dma_ops_reserve_addresses(dma_dom, startpage, pages);
        }
  
@@@ -936,7 -928,7 +939,7 @@@ static dma_addr_t __map_single(struct d
        unsigned long align_mask = 0;
        int i;
  
 -      pages = iommu_num_pages(paddr, size);
 +      pages = iommu_num_pages(paddr, size, PAGE_SIZE);
        paddr &= PAGE_MASK;
  
        if (align)
@@@ -981,7 -973,7 +984,7 @@@ static void __unmap_single(struct amd_i
        if ((dma_addr == 0) || (dma_addr + size > dma_dom->aperture_size))
                return;
  
 -      pages = iommu_num_pages(dma_addr, size);
 +      pages = iommu_num_pages(dma_addr, size, PAGE_SIZE);
        dma_addr &= PAGE_MASK;
        start = dma_addr;
  
  
        dma_ops_free_addresses(dma_dom, dma_addr, pages);
  
-       if (amd_iommu_unmap_flush)
+       if (amd_iommu_unmap_flush || dma_dom->need_flush) {
                iommu_flush_pages(iommu, dma_dom->domain.id, dma_addr, size);
+               dma_dom->need_flush = false;
+       }
  }
  
  /*