]> err.no Git - linux-2.6/commitdiff
x86, AMD IOMMU: add address allocation and deallocation functions
authorJoerg Roedel <joerg.roedel@amd.com>
Thu, 26 Jun 2008 19:27:57 +0000 (21:27 +0200)
committerIngo Molnar <mingo@elte.hu>
Fri, 27 Jun 2008 08:12:16 +0000 (10:12 +0200)
This patch adds the address allocator to the AMD IOMMU code.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Cc: iommu@lists.linux-foundation.org
Cc: bhavna.sarathy@amd.com
Cc: Sebastian.Biemueller@amd.com
Cc: robert.richter@amd.com
Cc: joro@8bytes.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/kernel/amd_iommu.c

index 1d70f5e6f4385994dfe9343bc488bf0bcdbf175f..69d8d024387e34337d6d34bbfb02c24247cd77a6 100644 (file)
@@ -266,3 +266,51 @@ static int init_unity_mappings_for_device(struct dma_ops_domain *dma_dom,
        return 0;
 }
 
+static unsigned long dma_mask_to_pages(unsigned long mask)
+{
+       return (mask >> PAGE_SHIFT) +
+               (PAGE_ALIGN(mask & ~PAGE_MASK) >> PAGE_SHIFT);
+}
+
+static unsigned long dma_ops_alloc_addresses(struct device *dev,
+                                            struct dma_ops_domain *dom,
+                                            unsigned int pages)
+{
+       unsigned long limit = dma_mask_to_pages(*dev->dma_mask);
+       unsigned long address;
+       unsigned long size = dom->aperture_size >> PAGE_SHIFT;
+       unsigned long boundary_size;
+
+       boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
+                       PAGE_SIZE) >> PAGE_SHIFT;
+       limit = limit < size ? limit : size;
+
+       if (dom->next_bit >= limit)
+               dom->next_bit = 0;
+
+       address = iommu_area_alloc(dom->bitmap, limit, dom->next_bit, pages,
+                       0 , boundary_size, 0);
+       if (address == -1)
+               address = iommu_area_alloc(dom->bitmap, limit, 0, pages,
+                               0, boundary_size, 0);
+
+       if (likely(address != -1)) {
+               set_bit_string(dom->bitmap, address, pages);
+               dom->next_bit = address + pages;
+               address <<= PAGE_SHIFT;
+       } else
+               address = bad_dma_address;
+
+       WARN_ON((address + (PAGE_SIZE*pages)) > dom->aperture_size);
+
+       return address;
+}
+
+static void dma_ops_free_addresses(struct dma_ops_domain *dom,
+                                  unsigned long address,
+                                  unsigned int pages)
+{
+       address >>= PAGE_SHIFT;
+       iommu_area_free(dom->bitmap, address, pages);
+}
+