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