diff options
author | Joerg Roedel <joerg.roedel@amd.com> | 2008-06-26 15:27:57 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-06-27 04:12:16 -0400 |
commit | d3086444b2988659a50af09462261c78d3012cb4 (patch) | |
tree | e684ebabf4b74ef3735d7055b84bf5127f2072e3 /arch/x86/kernel/amd_iommu.c | |
parent | bd0e521158af407ec816aea070831d4ca7ae65e9 (diff) |
x86, AMD IOMMU: add address allocation and deallocation functions
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>
Diffstat (limited to 'arch/x86/kernel/amd_iommu.c')
-rw-r--r-- | arch/x86/kernel/amd_iommu.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/arch/x86/kernel/amd_iommu.c b/arch/x86/kernel/amd_iommu.c index 1d70f5e6f438..69d8d024387e 100644 --- a/arch/x86/kernel/amd_iommu.c +++ b/arch/x86/kernel/amd_iommu.c | |||
@@ -266,3 +266,51 @@ static int init_unity_mappings_for_device(struct dma_ops_domain *dma_dom, | |||
266 | return 0; | 266 | return 0; |
267 | } | 267 | } |
268 | 268 | ||
269 | static unsigned long dma_mask_to_pages(unsigned long mask) | ||
270 | { | ||
271 | return (mask >> PAGE_SHIFT) + | ||
272 | (PAGE_ALIGN(mask & ~PAGE_MASK) >> PAGE_SHIFT); | ||
273 | } | ||
274 | |||
275 | static unsigned long dma_ops_alloc_addresses(struct device *dev, | ||
276 | struct dma_ops_domain *dom, | ||
277 | unsigned int pages) | ||
278 | { | ||
279 | unsigned long limit = dma_mask_to_pages(*dev->dma_mask); | ||
280 | unsigned long address; | ||
281 | unsigned long size = dom->aperture_size >> PAGE_SHIFT; | ||
282 | unsigned long boundary_size; | ||
283 | |||
284 | boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1, | ||
285 | PAGE_SIZE) >> PAGE_SHIFT; | ||
286 | limit = limit < size ? limit : size; | ||
287 | |||
288 | if (dom->next_bit >= limit) | ||
289 | dom->next_bit = 0; | ||
290 | |||
291 | address = iommu_area_alloc(dom->bitmap, limit, dom->next_bit, pages, | ||
292 | 0 , boundary_size, 0); | ||
293 | if (address == -1) | ||
294 | address = iommu_area_alloc(dom->bitmap, limit, 0, pages, | ||
295 | 0, boundary_size, 0); | ||
296 | |||
297 | if (likely(address != -1)) { | ||
298 | set_bit_string(dom->bitmap, address, pages); | ||
299 | dom->next_bit = address + pages; | ||
300 | address <<= PAGE_SHIFT; | ||
301 | } else | ||
302 | address = bad_dma_address; | ||
303 | |||
304 | WARN_ON((address + (PAGE_SIZE*pages)) > dom->aperture_size); | ||
305 | |||
306 | return address; | ||
307 | } | ||
308 | |||
309 | static void dma_ops_free_addresses(struct dma_ops_domain *dom, | ||
310 | unsigned long address, | ||
311 | unsigned int pages) | ||
312 | { | ||
313 | address >>= PAGE_SHIFT; | ||
314 | iommu_area_free(dom->bitmap, address, pages); | ||
315 | } | ||
316 | |||