]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/arm/plat-omap/include/mach/mmu.h
d970b71a4905cfbe6e964094145e13a0c7908343
[linux-2.6-omap-h63xx.git] / arch / arm / plat-omap / include / mach / mmu.h
1 #ifndef __ARCH_OMAP_MMU_H
2 #define __ARCH_OMAP_MMU_H
3
4 #include <linux/device.h>
5 #include <linux/workqueue.h>
6
7 enum exmap_type {
8         EXMAP_TYPE_MEM,
9         EXMAP_TYPE_FB
10 };
11
12 enum omap_mmu_type {
13         OMAP_MMU_DSP,
14         OMAP_MMU_IVA1,
15         OMAP_MMU_CAMERA,
16 };
17
18 struct exmap_tbl {
19         unsigned int valid:1;
20         unsigned int prsvd:1;
21         int usecount;           /* reference count by mmap */
22         enum exmap_type type;
23         void *buf;              /* virtual address of the buffer,
24                                  * i.e. 0xc0000000 - */
25         void *vadr;             /* DSP shadow space,
26                                  * i.e. 0xe0000000 - 0xe0ffffff */
27         unsigned int order;
28         struct {
29                 int prev;
30                 int next;
31         } link;                 /* grouping */
32 };
33
34 struct cam_ram_regset {
35         union {
36                 struct {
37                         u16 cam_l;
38                         u16 cam_h;
39                 };
40
41                 u32 cam;
42         };
43
44         union {
45                 struct {
46                         u16 ram_l;
47                         u16 ram_h;
48                 };
49
50                 u32 ram;
51         };
52 };
53
54 struct omap_mmu_tlb_lock {
55         int base;
56         int victim;
57 };
58
59 struct omap_mmu;
60 struct omap_mmu_tlb_entry;
61
62 #ifdef CONFIG_ARCH_OMAP1
63 extern struct omap_mmu_ops omap1_mmu_ops;
64 extern void omap_mmu_itack(struct omap_mmu *mmu);
65 #elif defined(CONFIG_ARCH_OMAP2)
66 extern struct omap_mmu_ops omap2_mmu_ops;
67 static inline void omap_mmu_itack(struct omap_mmu *mmu)
68 {
69 }
70 #endif
71
72 struct omap_mmu_ops {
73         int (*startup)(struct omap_mmu *mmu);
74         void (*shutdown)(struct omap_mmu *mmu);
75
76         /* TLB operations */
77         void (*read_tlb)(struct omap_mmu *, struct cam_ram_regset *);
78         void (*load_tlb)(struct omap_mmu *, struct cam_ram_regset *);
79         ssize_t (*show)(struct omap_mmu *, char *, struct omap_mmu_tlb_lock *);
80
81         /* CAM / RAM operations */
82         struct cam_ram_regset *(*cam_ram_alloc)(struct omap_mmu *,
83                                                 struct omap_mmu_tlb_entry *);
84         int (*cam_ram_valid)(struct cam_ram_regset *);
85         unsigned long (*cam_va)(struct cam_ram_regset *);
86
87         /* Memory operations */
88         int (*mem_enable)(struct omap_mmu *, void *);
89         int (*mem_disable)(struct omap_mmu *, void *);
90
91         void (*interrupt)(struct omap_mmu *);
92
93         /* PTE attribute operations */
94         pgprot_t (*pte_get_attr)(struct omap_mmu_tlb_entry *);
95 };
96
97 struct omap_mmu {
98         const char *name;
99         unsigned long base;
100         struct clk *clk;
101
102         unsigned long membase, memsize;
103         struct clk *memclk;
104
105         enum omap_mmu_type type;
106
107         struct device *dev;
108
109         struct rw_semaphore exmap_sem;
110         struct exmap_tbl *exmap_tbl;
111
112         unsigned int nr_tlb_entries;
113         unsigned int nr_exmap_preserved;
114
115         struct mm_struct *twl_mm;
116
117         /* Size of virtual address space, in bits */
118         unsigned int addrspace;
119
120         /* Interrupt */
121         unsigned int irq;
122         unsigned long fault_address;
123         struct work_struct irq_work;
124
125         struct omap_mmu_ops *ops;
126 };
127
128 #define omap_mmu_internal_memory(mmu, addr)                                     \
129         (likely(mmu->membase) && (((unsigned long)(addr) >= mmu->membase) &&    \
130                  ((unsigned long)(addr) < mmu->membase + mmu->memsize)))
131
132 #define INIT_EXMAP_TBL_ENTRY(ent, b, v, typ, od)        \
133 do {                                            \
134         (ent)->buf              = (b);          \
135         (ent)->vadr             = (v);          \
136         (ent)->valid            = 1;            \
137         (ent)->prsvd            = 0;            \
138         (ent)->usecount         = 0;            \
139         (ent)->type             = (typ);        \
140         (ent)->order            = (od);         \
141         (ent)->link.next        = -1;           \
142         (ent)->link.prev        = -1;           \
143 } while (0)
144
145 #define INIT_EXMAP_TBL_ENTRY_4KB_PRESERVED(ent, b, v)   \
146 do {                                                    \
147         (ent)->buf              = (b);                  \
148         (ent)->vadr             = (v);                  \
149         (ent)->valid            = 1;                    \
150         (ent)->prsvd            = 1;                    \
151         (ent)->usecount         = 0;                    \
152         (ent)->type             = EXMAP_TYPE_MEM;       \
153         (ent)->order            = 0;                    \
154         (ent)->link.next        = -1;                   \
155         (ent)->link.prev        = -1;                   \
156 } while (0)
157
158 #define omap_mmu_to_virt(mmu, db)       ((void *)((mmu)->membase + (db)))
159 #define virt_to_omap_mmu(mmu, va) \
160         (((unsigned long)(va) - (mmu)->membase))
161
162 /* arch/arm/plat-omap/mmu.c */
163 int omap_mmu_register(struct omap_mmu *mmu);
164 void omap_mmu_unregister(struct omap_mmu *mmu);
165
166 void omap_mmu_enable(struct omap_mmu *mmu, int reset);
167 void omap_mmu_disable(struct omap_mmu *mmu);
168
169 int omap_mmu_mem_enable(struct omap_mmu *mmu, void *addr);
170 void omap_mmu_mem_disable(struct omap_mmu *mmu, void *addr);
171
172 void omap_mmu_read_tlb(struct omap_mmu *mmu, struct omap_mmu_tlb_lock *lock,
173                        struct cam_ram_regset *cr);
174
175 int omap_mmu_load_tlb_entry(struct omap_mmu *, struct omap_mmu_tlb_entry *);
176 int omap_mmu_clear_tlb_entry(struct omap_mmu *, unsigned long vadr);
177
178 int omap_mmu_load_pte_entry(struct omap_mmu *mmu,
179                             struct omap_mmu_tlb_entry *entry);
180 int omap_mmu_clear_pte_entry(struct omap_mmu *mmu, unsigned long vadr);
181
182 int omap_mmu_kmem_reserve(struct omap_mmu *mmu, unsigned long size);
183 void omap_mmu_kmem_release(void);
184
185 unsigned long omap_mmu_virt_to_phys(struct omap_mmu *mmu, void *vadr,
186                                     size_t *len);
187
188 int omap_mmu_exmap(struct omap_mmu *mmu, unsigned long dspadr,
189                    unsigned long padr, unsigned long size,
190                    enum exmap_type type);
191 int omap_mmu_exunmap(struct omap_mmu *mmu, unsigned long dspadr);
192 void omap_mmu_exmap_flush(struct omap_mmu *mmu);
193 void omap_mmu_exmap_use(struct omap_mmu *mmu, void *vadr, size_t len);
194 void omap_mmu_exmap_unuse(struct omap_mmu *mmu, void *vadr, size_t len);
195
196 int exmap_set_armmmu(struct omap_mmu *mmu, unsigned long virt,
197                      unsigned long phys, unsigned long size);
198 void exmap_clear_armmmu(struct omap_mmu *mmu, unsigned long virt,
199                         unsigned long size);
200 void exmap_setup_preserved_mem_page(struct omap_mmu *mmu, void *buf,
201                                     unsigned long dspadr, int index);
202 void exmap_clear_mem_page(struct omap_mmu *mmu, unsigned long dspadr);
203 int exmap_valid(struct omap_mmu *mmu, void *vadr, size_t len);
204
205 /* To be obsolete for backward compatibility */
206 ssize_t __omap_mmu_mem_read(struct omap_mmu *mmu, struct bin_attribute *,
207                             char *buf, loff_t offset, size_t count);
208 ssize_t __omap_mmu_mem_write(struct omap_mmu *mmu, struct bin_attribute *,
209                             char *buf, loff_t offset, size_t count);
210
211 #endif /* __ARCH_OMAP_MMU_H */