]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - include/asm-arm/arch-omap/mmu.h
ARM: OMAP: Fix omap mmu framework for omap1
[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 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 struct omap_mmu_ops {
63         int (*startup)(struct omap_mmu *mmu);
64         void (*shutdown)(struct omap_mmu *mmu);
65
66         /* TLB operations */
67         void (*read_tlb)(struct omap_mmu *, struct cam_ram_regset *);
68         void (*load_tlb)(struct omap_mmu *, struct cam_ram_regset *);
69         ssize_t (*show)(struct omap_mmu *, char *, struct omap_mmu_tlb_lock *);
70
71         /* CAM / RAM operations */
72         struct cam_ram_regset *(*cam_ram_alloc)(struct omap_mmu_tlb_entry *);
73         int (*cam_ram_valid)(struct cam_ram_regset *);
74         unsigned long (*cam_va)(struct cam_ram_regset *);
75
76         /* Memory operations */
77         int (*mem_enable)(struct omap_mmu *, void *);
78         int (*mem_disable)(struct omap_mmu *, void *);
79
80         void (*interrupt)(struct omap_mmu *);
81
82         /* PTE attribute operations */
83         pgprot_t (*pte_get_attr)(struct omap_mmu_tlb_entry *);
84 };
85
86 struct omap_mmu {
87         const char *name;
88         unsigned long base;
89         struct clk *clk;
90
91         unsigned long membase, memsize;
92         struct clk *memclk;
93
94         enum omap_mmu_type type;
95
96         struct device dev;
97
98         struct rw_semaphore exmap_sem;
99         struct exmap_tbl *exmap_tbl;
100
101         unsigned int nr_tlb_entries;
102         unsigned int nr_exmap_preserved;
103
104         struct mm_struct *twl_mm;
105
106         /* Size of virtual address space, in bits */
107         unsigned int addrspace;
108
109         /* Interrupt */
110         unsigned int irq;
111         unsigned long fault_address;
112         struct work_struct irq_work;
113
114         struct omap_mmu_ops *ops;
115 };
116
117 #define omap_mmu_internal_memory(mmu, addr)                                     \
118         (likely(mmu->membase) && (((unsigned long)(addr) >= mmu->membase) &&    \
119                  ((unsigned long)(addr) < mmu->membase + mmu->memsize)))
120
121 #define INIT_EXMAP_TBL_ENTRY(ent,b,v,typ,od)    \
122 do {                                            \
123         (ent)->buf              = (b);          \
124         (ent)->vadr             = (v);          \
125         (ent)->valid            = 1;            \
126         (ent)->prsvd            = 0;            \
127         (ent)->usecount         = 0;            \
128         (ent)->type             = (typ);        \
129         (ent)->order            = (od);         \
130         (ent)->link.next        = -1;           \
131         (ent)->link.prev        = -1;           \
132 } while (0)
133
134 #define INIT_EXMAP_TBL_ENTRY_4KB_PRESERVED(ent,b,v)     \
135 do {                                                    \
136         (ent)->buf              = (b);                  \
137         (ent)->vadr             = (v);                  \
138         (ent)->valid            = 1;                    \
139         (ent)->prsvd            = 1;                    \
140         (ent)->usecount         = 0;                    \
141         (ent)->type             = EXMAP_TYPE_MEM;       \
142         (ent)->order            = 0;                    \
143         (ent)->link.next        = -1;                   \
144         (ent)->link.prev        = -1;                   \
145 } while (0)
146
147 #define omap_mmu_to_virt(mmu, db)       ((void *)((mmu)->membase + (db)))
148 #define virt_to_omap_mmu(mmu, va) \
149         (((unsigned long)(va) - (mmu)->membase))
150
151 /* arch/arm/plat-omap/mmu.c */
152 int omap_mmu_register(struct omap_mmu *mmu);
153 void omap_mmu_unregister(struct omap_mmu *mmu);
154
155 void omap_mmu_enable(struct omap_mmu *mmu, int reset);
156 void omap_mmu_disable(struct omap_mmu *mmu);
157
158 int omap_mmu_mem_enable(struct omap_mmu *mmu, void *addr);
159 void omap_mmu_mem_disable(struct omap_mmu *mmu, void *addr);
160
161 void omap_mmu_read_tlb(struct omap_mmu *mmu, struct omap_mmu_tlb_lock *lock,
162                        struct cam_ram_regset *cr);
163
164 int omap_mmu_load_tlb_entry(struct omap_mmu *, struct omap_mmu_tlb_entry *);
165 int omap_mmu_clear_tlb_entry(struct omap_mmu *, unsigned long vadr);
166
167 int omap_mmu_load_pte_entry(struct omap_mmu *mmu,
168                             struct omap_mmu_tlb_entry *entry);
169 int omap_mmu_clear_pte_entry(struct omap_mmu *mmu, unsigned long vadr);
170
171 int omap_mmu_kmem_reserve(struct omap_mmu *mmu, unsigned long size);
172 void omap_mmu_kmem_release(void);
173
174 unsigned long omap_mmu_virt_to_phys(struct omap_mmu *mmu, void *vadr,
175                                     size_t *len);
176
177 int omap_mmu_exmap(struct omap_mmu *mmu, unsigned long dspadr,
178                    unsigned long padr, unsigned long size,
179                    enum exmap_type type);
180 int omap_mmu_exunmap(struct omap_mmu *mmu, unsigned long dspadr);
181 void omap_mmu_exmap_flush(struct omap_mmu *mmu);
182 void omap_mmu_exmap_use(struct omap_mmu *mmu, void *vadr, size_t len);
183 void omap_mmu_exmap_unuse(struct omap_mmu *mmu, void *vadr, size_t len);
184
185 int exmap_set_armmmu(unsigned long virt, unsigned long phys, unsigned long size);
186 void exmap_clear_armmmu(unsigned long virt, unsigned long size);
187 void exmap_setup_preserved_mem_page(struct omap_mmu *mmu, void *buf,
188                                     unsigned long dspadr, int index);
189 void exmap_clear_mem_page(struct omap_mmu *mmu, unsigned long dspadr);
190 int exmap_valid(struct omap_mmu *mmu, void *vadr, size_t len);
191
192 /* To be obsolete for backward compatibility */
193 ssize_t __omap_mmu_mem_read(struct omap_mmu *mmu, char *buf, loff_t offset, size_t count);
194 ssize_t __omap_mmu_mem_write(struct omap_mmu *mmu, char *buf, loff_t offset, size_t count);
195
196 #endif /* __ARCH_OMAP_MMU_H */