blob: 86bdeffe43ad69e3dba2781eeed06b8cbe847a69 [file] [log] [blame]
Thomas Gleixner1e19b162008-10-06 14:15:24 +02001#ifndef _LINUX_IOMMU_HELPER_H
2#define _LINUX_IOMMU_HELPER_H
3
Anton Blancharde269b082010-08-09 17:20:23 -07004#include <linux/kernel.h>
5
FUJITA Tomonorieecfffc2008-09-12 19:42:33 +09006static inline unsigned long iommu_device_max_index(unsigned long size,
7 unsigned long offset,
8 u64 dma_mask)
9{
10 if (size + offset > dma_mask)
11 return dma_mask - offset + 1;
12 else
13 return size;
14}
15
FUJITA Tomonori37158632008-03-04 14:29:27 -080016extern int iommu_is_span_boundary(unsigned int index, unsigned int nr,
17 unsigned long shift,
18 unsigned long boundary_size);
FUJITA Tomonori0291df82008-02-04 22:28:07 -080019extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size,
20 unsigned long start, unsigned int nr,
21 unsigned long shift,
22 unsigned long boundary_size,
23 unsigned long align_mask);
Thomas Gleixner1e19b162008-10-06 14:15:24 +020024
Anton Blancharde269b082010-08-09 17:20:23 -070025static inline unsigned long iommu_num_pages(unsigned long addr,
26 unsigned long len,
27 unsigned long io_page_size)
28{
29 unsigned long size = (addr & (io_page_size - 1)) + len;
30
31 return DIV_ROUND_UP(size, io_page_size);
32}
Joerg Roedel56d93662008-10-15 22:02:10 -070033
Thomas Gleixner1e19b162008-10-06 14:15:24 +020034#endif