diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2009-05-25 05:15:59 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2009-05-25 05:20:21 -0400 |
commit | 56a459314a982bae75b9bce64bcca853d378ca7e (patch) | |
tree | 07d9121fb08229ebe2ac2f4420cec70434c7bbba /arch/arm/plat-omap/include | |
parent | fc05505b77f7900a1bb74fb3f3a4343dee4265a4 (diff) | |
parent | 5c651ffaee6f07aa1f5e6d0763845a2ee606b6bd (diff) |
Merge branch 'iommu' of git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap-2.6.git into devel
Diffstat (limited to 'arch/arm/plat-omap/include')
-rw-r--r-- | arch/arm/plat-omap/include/mach/iommu.h | 168 | ||||
-rw-r--r-- | arch/arm/plat-omap/include/mach/iommu2.h | 96 | ||||
-rw-r--r-- | arch/arm/plat-omap/include/mach/iovmm.h | 94 |
3 files changed, 358 insertions, 0 deletions
diff --git a/arch/arm/plat-omap/include/mach/iommu.h b/arch/arm/plat-omap/include/mach/iommu.h new file mode 100644 index 000000000000..769b00b4c34a --- /dev/null +++ b/arch/arm/plat-omap/include/mach/iommu.h | |||
@@ -0,0 +1,168 @@ | |||
1 | /* | ||
2 | * omap iommu: main structures | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Nokia Corporation | ||
5 | * | ||
6 | * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #ifndef __MACH_IOMMU_H | ||
14 | #define __MACH_IOMMU_H | ||
15 | |||
16 | struct iotlb_entry { | ||
17 | u32 da; | ||
18 | u32 pa; | ||
19 | u32 pgsz, prsvd, valid; | ||
20 | union { | ||
21 | u16 ap; | ||
22 | struct { | ||
23 | u32 endian, elsz, mixed; | ||
24 | }; | ||
25 | }; | ||
26 | }; | ||
27 | |||
28 | struct iommu { | ||
29 | const char *name; | ||
30 | struct module *owner; | ||
31 | struct clk *clk; | ||
32 | void __iomem *regbase; | ||
33 | struct device *dev; | ||
34 | |||
35 | unsigned int refcount; | ||
36 | struct mutex iommu_lock; /* global for this whole object */ | ||
37 | |||
38 | /* | ||
39 | * We don't change iopgd for a situation like pgd for a task, | ||
40 | * but share it globally for each iommu. | ||
41 | */ | ||
42 | u32 *iopgd; | ||
43 | spinlock_t page_table_lock; /* protect iopgd */ | ||
44 | |||
45 | int nr_tlb_entries; | ||
46 | |||
47 | struct list_head mmap; | ||
48 | struct mutex mmap_lock; /* protect mmap */ | ||
49 | |||
50 | int (*isr)(struct iommu *obj); | ||
51 | |||
52 | void *ctx; /* iommu context: registres saved area */ | ||
53 | }; | ||
54 | |||
55 | struct cr_regs { | ||
56 | union { | ||
57 | struct { | ||
58 | u16 cam_l; | ||
59 | u16 cam_h; | ||
60 | }; | ||
61 | u32 cam; | ||
62 | }; | ||
63 | union { | ||
64 | struct { | ||
65 | u16 ram_l; | ||
66 | u16 ram_h; | ||
67 | }; | ||
68 | u32 ram; | ||
69 | }; | ||
70 | }; | ||
71 | |||
72 | struct iotlb_lock { | ||
73 | short base; | ||
74 | short vict; | ||
75 | }; | ||
76 | |||
77 | /* architecture specific functions */ | ||
78 | struct iommu_functions { | ||
79 | unsigned long version; | ||
80 | |||
81 | int (*enable)(struct iommu *obj); | ||
82 | void (*disable)(struct iommu *obj); | ||
83 | u32 (*fault_isr)(struct iommu *obj, u32 *ra); | ||
84 | |||
85 | void (*tlb_read_cr)(struct iommu *obj, struct cr_regs *cr); | ||
86 | void (*tlb_load_cr)(struct iommu *obj, struct cr_regs *cr); | ||
87 | |||
88 | struct cr_regs *(*alloc_cr)(struct iommu *obj, struct iotlb_entry *e); | ||
89 | int (*cr_valid)(struct cr_regs *cr); | ||
90 | u32 (*cr_to_virt)(struct cr_regs *cr); | ||
91 | void (*cr_to_e)(struct cr_regs *cr, struct iotlb_entry *e); | ||
92 | ssize_t (*dump_cr)(struct iommu *obj, struct cr_regs *cr, char *buf); | ||
93 | |||
94 | u32 (*get_pte_attr)(struct iotlb_entry *e); | ||
95 | |||
96 | void (*save_ctx)(struct iommu *obj); | ||
97 | void (*restore_ctx)(struct iommu *obj); | ||
98 | ssize_t (*dump_ctx)(struct iommu *obj, char *buf); | ||
99 | }; | ||
100 | |||
101 | struct iommu_platform_data { | ||
102 | const char *name; | ||
103 | const char *clk_name; | ||
104 | const int nr_tlb_entries; | ||
105 | }; | ||
106 | |||
107 | #if defined(CONFIG_ARCH_OMAP1) | ||
108 | #error "iommu for this processor not implemented yet" | ||
109 | #else | ||
110 | #include <mach/iommu2.h> | ||
111 | #endif | ||
112 | |||
113 | /* | ||
114 | * utilities for super page(16MB, 1MB, 64KB and 4KB) | ||
115 | */ | ||
116 | |||
117 | #define iopgsz_max(bytes) \ | ||
118 | (((bytes) >= SZ_16M) ? SZ_16M : \ | ||
119 | ((bytes) >= SZ_1M) ? SZ_1M : \ | ||
120 | ((bytes) >= SZ_64K) ? SZ_64K : \ | ||
121 | ((bytes) >= SZ_4K) ? SZ_4K : 0) | ||
122 | |||
123 | #define bytes_to_iopgsz(bytes) \ | ||
124 | (((bytes) == SZ_16M) ? MMU_CAM_PGSZ_16M : \ | ||
125 | ((bytes) == SZ_1M) ? MMU_CAM_PGSZ_1M : \ | ||
126 | ((bytes) == SZ_64K) ? MMU_CAM_PGSZ_64K : \ | ||
127 | ((bytes) == SZ_4K) ? MMU_CAM_PGSZ_4K : -1) | ||
128 | |||
129 | #define iopgsz_to_bytes(iopgsz) \ | ||
130 | (((iopgsz) == MMU_CAM_PGSZ_16M) ? SZ_16M : \ | ||
131 | ((iopgsz) == MMU_CAM_PGSZ_1M) ? SZ_1M : \ | ||
132 | ((iopgsz) == MMU_CAM_PGSZ_64K) ? SZ_64K : \ | ||
133 | ((iopgsz) == MMU_CAM_PGSZ_4K) ? SZ_4K : 0) | ||
134 | |||
135 | #define iopgsz_ok(bytes) (bytes_to_iopgsz(bytes) >= 0) | ||
136 | |||
137 | /* | ||
138 | * global functions | ||
139 | */ | ||
140 | extern u32 iommu_arch_version(void); | ||
141 | |||
142 | extern void iotlb_cr_to_e(struct cr_regs *cr, struct iotlb_entry *e); | ||
143 | extern u32 iotlb_cr_to_virt(struct cr_regs *cr); | ||
144 | |||
145 | extern int load_iotlb_entry(struct iommu *obj, struct iotlb_entry *e); | ||
146 | extern void flush_iotlb_page(struct iommu *obj, u32 da); | ||
147 | extern void flush_iotlb_range(struct iommu *obj, u32 start, u32 end); | ||
148 | extern void flush_iotlb_all(struct iommu *obj); | ||
149 | |||
150 | extern int iopgtable_store_entry(struct iommu *obj, struct iotlb_entry *e); | ||
151 | extern size_t iopgtable_clear_entry(struct iommu *obj, u32 iova); | ||
152 | |||
153 | extern struct iommu *iommu_get(const char *name); | ||
154 | extern void iommu_put(struct iommu *obj); | ||
155 | |||
156 | extern void iommu_save_ctx(struct iommu *obj); | ||
157 | extern void iommu_restore_ctx(struct iommu *obj); | ||
158 | |||
159 | extern int install_iommu_arch(const struct iommu_functions *ops); | ||
160 | extern void uninstall_iommu_arch(const struct iommu_functions *ops); | ||
161 | |||
162 | extern int foreach_iommu_device(void *data, | ||
163 | int (*fn)(struct device *, void *)); | ||
164 | |||
165 | extern ssize_t iommu_dump_ctx(struct iommu *obj, char *buf); | ||
166 | extern size_t dump_tlb_entries(struct iommu *obj, char *buf); | ||
167 | |||
168 | #endif /* __MACH_IOMMU_H */ | ||
diff --git a/arch/arm/plat-omap/include/mach/iommu2.h b/arch/arm/plat-omap/include/mach/iommu2.h new file mode 100644 index 000000000000..10ad05f410e9 --- /dev/null +++ b/arch/arm/plat-omap/include/mach/iommu2.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * omap iommu: omap2 architecture specific definitions | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Nokia Corporation | ||
5 | * | ||
6 | * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #ifndef __MACH_IOMMU2_H | ||
14 | #define __MACH_IOMMU2_H | ||
15 | |||
16 | #include <linux/io.h> | ||
17 | |||
18 | /* | ||
19 | * MMU Register offsets | ||
20 | */ | ||
21 | #define MMU_REVISION 0x00 | ||
22 | #define MMU_SYSCONFIG 0x10 | ||
23 | #define MMU_SYSSTATUS 0x14 | ||
24 | #define MMU_IRQSTATUS 0x18 | ||
25 | #define MMU_IRQENABLE 0x1c | ||
26 | #define MMU_WALKING_ST 0x40 | ||
27 | #define MMU_CNTL 0x44 | ||
28 | #define MMU_FAULT_AD 0x48 | ||
29 | #define MMU_TTB 0x4c | ||
30 | #define MMU_LOCK 0x50 | ||
31 | #define MMU_LD_TLB 0x54 | ||
32 | #define MMU_CAM 0x58 | ||
33 | #define MMU_RAM 0x5c | ||
34 | #define MMU_GFLUSH 0x60 | ||
35 | #define MMU_FLUSH_ENTRY 0x64 | ||
36 | #define MMU_READ_CAM 0x68 | ||
37 | #define MMU_READ_RAM 0x6c | ||
38 | #define MMU_EMU_FAULT_AD 0x70 | ||
39 | |||
40 | #define MMU_REG_SIZE 256 | ||
41 | |||
42 | /* | ||
43 | * MMU Register bit definitions | ||
44 | */ | ||
45 | #define MMU_LOCK_BASE_SHIFT 10 | ||
46 | #define MMU_LOCK_BASE_MASK (0x1f << MMU_LOCK_BASE_SHIFT) | ||
47 | #define MMU_LOCK_BASE(x) \ | ||
48 | ((x & MMU_LOCK_BASE_MASK) >> MMU_LOCK_BASE_SHIFT) | ||
49 | |||
50 | #define MMU_LOCK_VICT_SHIFT 4 | ||
51 | #define MMU_LOCK_VICT_MASK (0x1f << MMU_LOCK_VICT_SHIFT) | ||
52 | #define MMU_LOCK_VICT(x) \ | ||
53 | ((x & MMU_LOCK_VICT_MASK) >> MMU_LOCK_VICT_SHIFT) | ||
54 | |||
55 | #define MMU_CAM_VATAG_SHIFT 12 | ||
56 | #define MMU_CAM_VATAG_MASK \ | ||
57 | ((~0UL >> MMU_CAM_VATAG_SHIFT) << MMU_CAM_VATAG_SHIFT) | ||
58 | #define MMU_CAM_P (1 << 3) | ||
59 | #define MMU_CAM_V (1 << 2) | ||
60 | #define MMU_CAM_PGSZ_MASK 3 | ||
61 | #define MMU_CAM_PGSZ_1M (0 << 0) | ||
62 | #define MMU_CAM_PGSZ_64K (1 << 0) | ||
63 | #define MMU_CAM_PGSZ_4K (2 << 0) | ||
64 | #define MMU_CAM_PGSZ_16M (3 << 0) | ||
65 | |||
66 | #define MMU_RAM_PADDR_SHIFT 12 | ||
67 | #define MMU_RAM_PADDR_MASK \ | ||
68 | ((~0UL >> MMU_RAM_PADDR_SHIFT) << MMU_RAM_PADDR_SHIFT) | ||
69 | #define MMU_RAM_ENDIAN_SHIFT 9 | ||
70 | #define MMU_RAM_ENDIAN_MASK (1 << MMU_RAM_ENDIAN_SHIFT) | ||
71 | #define MMU_RAM_ENDIAN_BIG (1 << MMU_RAM_ENDIAN_SHIFT) | ||
72 | #define MMU_RAM_ENDIAN_LITTLE (0 << MMU_RAM_ENDIAN_SHIFT) | ||
73 | #define MMU_RAM_ELSZ_SHIFT 7 | ||
74 | #define MMU_RAM_ELSZ_MASK (3 << MMU_RAM_ELSZ_SHIFT) | ||
75 | #define MMU_RAM_ELSZ_8 (0 << MMU_RAM_ELSZ_SHIFT) | ||
76 | #define MMU_RAM_ELSZ_16 (1 << MMU_RAM_ELSZ_SHIFT) | ||
77 | #define MMU_RAM_ELSZ_32 (2 << MMU_RAM_ELSZ_SHIFT) | ||
78 | #define MMU_RAM_ELSZ_NONE (3 << MMU_RAM_ELSZ_SHIFT) | ||
79 | #define MMU_RAM_MIXED_SHIFT 6 | ||
80 | #define MMU_RAM_MIXED_MASK (1 << MMU_RAM_MIXED_SHIFT) | ||
81 | #define MMU_RAM_MIXED MMU_RAM_MIXED_MASK | ||
82 | |||
83 | /* | ||
84 | * register accessors | ||
85 | */ | ||
86 | static inline u32 iommu_read_reg(struct iommu *obj, size_t offs) | ||
87 | { | ||
88 | return __raw_readl(obj->regbase + offs); | ||
89 | } | ||
90 | |||
91 | static inline void iommu_write_reg(struct iommu *obj, u32 val, size_t offs) | ||
92 | { | ||
93 | __raw_writel(val, obj->regbase + offs); | ||
94 | } | ||
95 | |||
96 | #endif /* __MACH_IOMMU2_H */ | ||
diff --git a/arch/arm/plat-omap/include/mach/iovmm.h b/arch/arm/plat-omap/include/mach/iovmm.h new file mode 100644 index 000000000000..bdc7ce5d7a4a --- /dev/null +++ b/arch/arm/plat-omap/include/mach/iovmm.h | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * omap iommu: simple virtual address space management | ||
3 | * | ||
4 | * Copyright (C) 2008-2009 Nokia Corporation | ||
5 | * | ||
6 | * Written by Hiroshi DOYU <Hiroshi.DOYU@nokia.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License version 2 as | ||
10 | * published by the Free Software Foundation. | ||
11 | */ | ||
12 | |||
13 | #ifndef __IOMMU_MMAP_H | ||
14 | #define __IOMMU_MMAP_H | ||
15 | |||
16 | struct iovm_struct { | ||
17 | struct iommu *iommu; /* iommu object which this belongs to */ | ||
18 | u32 da_start; /* area definition */ | ||
19 | u32 da_end; | ||
20 | u32 flags; /* IOVMF_: see below */ | ||
21 | struct list_head list; /* linked in ascending order */ | ||
22 | const struct sg_table *sgt; /* keep 'page' <-> 'da' mapping */ | ||
23 | void *va; /* mpu side mapped address */ | ||
24 | }; | ||
25 | |||
26 | /* | ||
27 | * IOVMF_FLAGS: attribute for iommu virtual memory area(iovma) | ||
28 | * | ||
29 | * lower 16 bit is used for h/w and upper 16 bit is for s/w. | ||
30 | */ | ||
31 | #define IOVMF_SW_SHIFT 16 | ||
32 | #define IOVMF_HW_SIZE (1 << IOVMF_SW_SHIFT) | ||
33 | #define IOVMF_HW_MASK (IOVMF_HW_SIZE - 1) | ||
34 | #define IOVMF_SW_MASK (~IOVMF_HW_MASK)UL | ||
35 | |||
36 | /* | ||
37 | * iovma: h/w flags derived from cam and ram attribute | ||
38 | */ | ||
39 | #define IOVMF_CAM_MASK (~((1 << 10) - 1)) | ||
40 | #define IOVMF_RAM_MASK (~IOVMF_CAM_MASK) | ||
41 | |||
42 | #define IOVMF_PGSZ_MASK (3 << 0) | ||
43 | #define IOVMF_PGSZ_1M MMU_CAM_PGSZ_1M | ||
44 | #define IOVMF_PGSZ_64K MMU_CAM_PGSZ_64K | ||
45 | #define IOVMF_PGSZ_4K MMU_CAM_PGSZ_4K | ||
46 | #define IOVMF_PGSZ_16M MMU_CAM_PGSZ_16M | ||
47 | |||
48 | #define IOVMF_ENDIAN_MASK (1 << 9) | ||
49 | #define IOVMF_ENDIAN_BIG MMU_RAM_ENDIAN_BIG | ||
50 | #define IOVMF_ENDIAN_LITTLE MMU_RAM_ENDIAN_LITTLE | ||
51 | |||
52 | #define IOVMF_ELSZ_MASK (3 << 7) | ||
53 | #define IOVMF_ELSZ_8 MMU_RAM_ELSZ_8 | ||
54 | #define IOVMF_ELSZ_16 MMU_RAM_ELSZ_16 | ||
55 | #define IOVMF_ELSZ_32 MMU_RAM_ELSZ_32 | ||
56 | #define IOVMF_ELSZ_NONE MMU_RAM_ELSZ_NONE | ||
57 | |||
58 | #define IOVMF_MIXED_MASK (1 << 6) | ||
59 | #define IOVMF_MIXED MMU_RAM_MIXED | ||
60 | |||
61 | /* | ||
62 | * iovma: s/w flags, used for mapping and umapping internally. | ||
63 | */ | ||
64 | #define IOVMF_MMIO (1 << IOVMF_SW_SHIFT) | ||
65 | #define IOVMF_ALLOC (2 << IOVMF_SW_SHIFT) | ||
66 | #define IOVMF_ALLOC_MASK (3 << IOVMF_SW_SHIFT) | ||
67 | |||
68 | /* "superpages" is supported just with physically linear pages */ | ||
69 | #define IOVMF_DISCONT (1 << (2 + IOVMF_SW_SHIFT)) | ||
70 | #define IOVMF_LINEAR (2 << (2 + IOVMF_SW_SHIFT)) | ||
71 | #define IOVMF_LINEAR_MASK (3 << (2 + IOVMF_SW_SHIFT)) | ||
72 | |||
73 | #define IOVMF_DA_FIXED (1 << (4 + IOVMF_SW_SHIFT)) | ||
74 | #define IOVMF_DA_ANON (2 << (4 + IOVMF_SW_SHIFT)) | ||
75 | #define IOVMF_DA_MASK (3 << (4 + IOVMF_SW_SHIFT)) | ||
76 | |||
77 | |||
78 | extern struct iovm_struct *find_iovm_area(struct iommu *obj, u32 da); | ||
79 | extern u32 iommu_vmap(struct iommu *obj, u32 da, | ||
80 | const struct sg_table *sgt, u32 flags); | ||
81 | extern struct sg_table *iommu_vunmap(struct iommu *obj, u32 da); | ||
82 | extern u32 iommu_vmalloc(struct iommu *obj, u32 da, size_t bytes, | ||
83 | u32 flags); | ||
84 | extern void iommu_vfree(struct iommu *obj, const u32 da); | ||
85 | extern u32 iommu_kmap(struct iommu *obj, u32 da, u32 pa, size_t bytes, | ||
86 | u32 flags); | ||
87 | extern void iommu_kunmap(struct iommu *obj, u32 da); | ||
88 | extern u32 iommu_kmalloc(struct iommu *obj, u32 da, size_t bytes, | ||
89 | u32 flags); | ||
90 | extern void iommu_kfree(struct iommu *obj, u32 da); | ||
91 | |||
92 | extern void *da_to_va(struct iommu *obj, u32 da); | ||
93 | |||
94 | #endif /* __IOMMU_MMAP_H */ | ||