OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [linux-2.6/] [linux-2.6.24/] [include/] [asm-or32/] [pgtable.h] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 xianfeng
/* or32 pgtable.h - macros and functions to manipulate page tables
2
 *
3
 * Based on:
4
 * include/asm-cris/pgtable.h
5
 */
6
 
7
#ifndef _OR32_PGTABLE_H
8
#define _OR32_PGTABLE_H
9
 
10
#include <asm-generic/4level-fixup.h>
11
 
12
#ifndef __ASSEMBLY__
13
#include <asm/mmu.h>
14
 
15
/*
16
 * The Linux memory management assumes a three-level page table setup. On
17
 * or32, we use that, but "fold" the mid level into the top-level page
18
 * table. Since the MMU TLB is software loaded through an interrupt, it
19
 * supports any page table structure, so we could have used a three-level
20
 * setup, but for the amounts of memory we normally use, a two-level is
21
 * probably more efficient.
22
 *
23
 * This file contains the functions and defines necessary to modify and use
24
 * the or32 page table tree.
25
 */
26
 
27
extern void paging_init(void);
28
 
29
/* Certain architectures need to do special things when pte's
30
 * within a page table are directly modified.  Thus, the following
31
 * hook is made available.
32
 */
33
#define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
34
#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval)
35
/*
36
 * (pmds are folded into pgds so this doesn't get actually called,
37
 * but the define is needed for a generic inline function.)
38
 */
39
#define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)
40
#define set_pgd(pgdptr, pgdval) (*(pgdptr) = pgdval)
41
 
42
/* PMD_SHIFT determines the size of the area a second-level page table can
43
 * map. It is equal to the page size times the number of PTE's that fit in
44
 * a PMD page. A PTE is 4-bytes in or32. Hence the following number.
45
 */
46
 
47
#define PMD_SHIFT       (PAGE_SHIFT + (PAGE_SHIFT-2))
48
#define PMD_SIZE        (1UL << PMD_SHIFT)
49
#define PMD_MASK        (~(PMD_SIZE-1))
50
 
51
/* PGDIR_SHIFT determines what a third-level page table entry can map.
52
 * Since we fold into a two-level structure, this is the same as PMD_SHIFT.
53
 */
54
 
55
#define PGDIR_SHIFT     PMD_SHIFT
56
#define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
57
#define PGDIR_MASK      (~(PGDIR_SIZE-1))
58
 
59
/*
60
 * entries per page directory level: we use a two-level, so
61
 * we don't really have any PMD directory physically.
62
 * pointers are 4 bytes so we can use the page size and
63
 * divide it by 4 (shift by 2).
64
 */
65
#define PTRS_PER_PTE    (1UL << (PAGE_SHIFT-2))
66
#define PTRS_PER_PMD    1
67
#define PTRS_PER_PGD    (1UL << (PAGE_SHIFT-2))
68
 
69
/* calculate how many PGD entries a user-level program can use
70
 * the first mappable virtual address is 0
71
 * (TASK_SIZE is the maximum virtual address space)
72
 */
73
 
74
#define USER_PTRS_PER_PGD       (TASK_SIZE/PGDIR_SIZE)
75
#define FIRST_USER_ADDRESS      0
76
 
77
/*
78
 * Kernels own virtual memory area.
79
 */
80
 
81
#define VMALLOC_START     0xd0000000
82
#define VMALLOC_VMADDR(x) ((unsigned long)(x))
83
#define VMALLOC_END       0xe0000000
84
 
85
/* Define some higher level generic page attributes.
86
 *
87
 * If you change _PAGE_CI definition be sure to change it in
88
 * io.h for ioremap_nocache() too.
89
 */
90
 
91
#define _PAGE_CC       0x001 /* software: pte contains a translation */
92
#define _PAGE_CI       0x002 /* cache inhibit          */
93
#define _PAGE_WBC      0x004 /* write back cache       */
94
#define _PAGE_FILE     0x004 /* set: pagecache, unset: swap (when !PRESENT) */
95
#define _PAGE_WOM      0x008 /* weakly ordered memory  */
96
 
97
#define _PAGE_A        0x010 /* accessed               */
98
#define _PAGE_D        0x020 /* dirty                  */
99
#define _PAGE_URE      0x040 /* user read enable       */
100
#define _PAGE_UWE      0x080 /* user write enable      */
101
 
102
#define _PAGE_SRE      0x100 /* superuser read enable  */
103
#define _PAGE_SWE      0x200 /* superuser write enable */
104
#define _PAGE_EXEC     0x400 /* software: page is executable */
105
#define _PAGE_U_SHARED 0x800 /* software: page is shared in user space */
106
 
107
/* 0x001 is cache coherency bit, which should always be set to
108
 *       1 - for SMP (when we support it)
109
 *       0 - otherwise
110
 *
111
 * we just reuse this bit in software for _PAGE_PRESENT and
112
 * force it to 0 when loading it into TLB.
113
 */
114
#define _PAGE_PRESENT  _PAGE_CC
115
#define _PAGE_USER     _PAGE_URE
116
#define _PAGE_WRITE    (_PAGE_UWE | _PAGE_SWE)
117
#define _PAGE_DIRTY    _PAGE_D
118
#define _PAGE_ACCESSED _PAGE_A
119
#define _PAGE_NO_CACHE _PAGE_CI
120
#define _PAGE_SHARED   _PAGE_U_SHARED
121
#define _PAGE_READ     (_PAGE_URE | _PAGE_SRE)
122
 
123
#define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
124
#define _PAGE_BASE     (_PAGE_PRESENT | _PAGE_ACCESSED)
125
#define _PAGE_ALL      (_PAGE_PRESENT | _PAGE_ACCESSED)
126
#define _KERNPG_TABLE   (_PAGE_BASE | _PAGE_SRE | _PAGE_SWE | _PAGE_ACCESSED | _PAGE_DIRTY)
127
 
128
#define PAGE_NONE       __pgprot(_PAGE_ALL)
129
#define PAGE_READONLY   __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE )
130
#define PAGE_READONLY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC)
131
#define PAGE_SHARED     __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE | _PAGE_SHARED)
132
#define PAGE_SHARED_X   __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_UWE | _PAGE_SWE | _PAGE_SHARED | _PAGE_EXEC)
133
#define PAGE_COPY       __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE )
134
#define PAGE_COPY_X     __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC)
135
 
136
#define PAGE_KERNEL     __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC)
137
#define PAGE_KERNEL_NOCACHE __pgprot(_PAGE_ALL | _PAGE_SRE | _PAGE_SWE | _PAGE_SHARED | _PAGE_DIRTY | _PAGE_EXEC | _PAGE_CI)
138
 
139
#define __P000  PAGE_NONE
140
#define __P001  PAGE_READONLY_X
141
#define __P010  PAGE_COPY
142
#define __P011  PAGE_COPY_X
143
#define __P100  PAGE_READONLY
144
#define __P101  PAGE_READONLY_X
145
#define __P110  PAGE_COPY
146
#define __P111  PAGE_COPY_X
147
 
148
#define __S000  PAGE_NONE
149
#define __S001  PAGE_READONLY_X
150
#define __S010  PAGE_SHARED
151
#define __S011  PAGE_SHARED_X
152
#define __S100  PAGE_READONLY
153
#define __S101  PAGE_READONLY_X
154
#define __S110  PAGE_SHARED
155
#define __S111  PAGE_SHARED_X
156
 
157
/* zero page used for uninitialized stuff */
158
extern unsigned long empty_zero_page[2048];
159
#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
160
 
161
/* number of bits that fit into a memory pointer */
162
#define BITS_PER_PTR                    (8*sizeof(unsigned long))
163
 
164
/* to align the pointer to a pointer address */
165
#define PTR_MASK                        (~(sizeof(void*)-1))
166
 
167
/* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
168
/* 64-bit machines, beware!  SRB. */
169
#define SIZEOF_PTR_LOG2                 2
170
 
171
/* to find an entry in a page-table */
172
#define PAGE_PTR(address) \
173
((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
174
 
175
/* to set the page-dir */
176
#define SET_PAGE_DIR(tsk,pgdir)
177
 
178
#define pte_none(x)     (!pte_val(x))
179
#define pte_present(x)  (pte_val(x) & _PAGE_PRESENT)
180
#define pte_clear(mm,addr,xp)   do { pte_val(*(xp)) = 0; } while (0)
181
 
182
#define pmd_none(x)     (!pmd_val(x))
183
#define pmd_bad(x)      ((pmd_val(x) & (~PAGE_MASK)) != _KERNPG_TABLE)
184
#define pmd_present(x)  (pmd_val(x) & _PAGE_PRESENT)
185
#define pmd_clear(xp)   do { pmd_val(*(xp)) = 0; } while (0)
186
 
187
/*
188
 * The "pgd_xxx()" functions here are trivial for a folded two-level
189
 * setup: the pgd is never bad, and a pmd always exists (as it's folded
190
 * into the pgd entry)
191
 */
192
static inline int pgd_none(pgd_t pgd)           { return 0; }
193
static inline int pgd_bad(pgd_t pgd)            { return 0; }
194
static inline int pgd_present(pgd_t pgd)        { return 1; }
195
static inline void pgd_clear(pgd_t * pgdp)      { }
196
 
197
/*
198
 * The following only work if pte_present() is true.
199
 * Undefined behaviour if not..
200
 */
201
 
202
static inline int pte_read(pte_t pte)           { return pte_val(pte) & _PAGE_READ; }
203
static inline int pte_write(pte_t pte)          { return pte_val(pte) & _PAGE_WRITE; }
204
static inline int pte_exec(pte_t pte)           { return pte_val(pte) & _PAGE_EXEC; }
205
static inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_DIRTY; }
206
static inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_ACCESSED; }
207
static inline int pte_file(pte_t pte)           { return pte_val(pte) & _PAGE_FILE; }
208
 
209
static inline pte_t pte_wrprotect(pte_t pte)
210
{
211
        pte_val(pte) &= ~(_PAGE_WRITE);
212
        return pte;
213
}
214
 
215
static inline pte_t pte_rdprotect(pte_t pte)
216
{
217
        pte_val(pte) &= ~(_PAGE_READ);
218
        return pte;
219
}
220
 
221
static inline pte_t pte_exprotect(pte_t pte)
222
{
223
        pte_val(pte) &= ~(_PAGE_EXEC);
224
        return pte;
225
}
226
 
227
static inline pte_t pte_mkclean(pte_t pte)
228
{
229
        pte_val(pte) &= ~(_PAGE_DIRTY);
230
        return pte;
231
}
232
 
233
static inline pte_t pte_mkold(pte_t pte)
234
{
235
        pte_val(pte) &= ~(_PAGE_ACCESSED);
236
        return pte;
237
}
238
 
239
static inline pte_t pte_mkwrite(pte_t pte)
240
{
241
        pte_val(pte) |= _PAGE_WRITE;
242
        return pte;
243
}
244
 
245
static inline pte_t pte_mkread(pte_t pte)
246
{
247
        pte_val(pte) |= _PAGE_READ;
248
        return pte;
249
}
250
 
251
static inline pte_t pte_mkexec(pte_t pte)
252
{
253
        pte_val(pte) |= _PAGE_EXEC;
254
        return pte;
255
}
256
 
257
static inline pte_t pte_mkdirty(pte_t pte)
258
{
259
        pte_val(pte) |= _PAGE_DIRTY;
260
        return pte;
261
}
262
 
263
static inline pte_t pte_mkyoung(pte_t pte)
264
{
265
        pte_val(pte) |= _PAGE_ACCESSED;
266
        return pte;
267
}
268
 
269
/*
270
 * Conversion functions: convert a page and protection to a page entry,
271
 * and a page entry and page directory to the page they refer to.
272
 */
273
 
274
/* What actually goes as arguments to the various functions is less than
275
 * obvious, but a rule of thumb is that struct page's goes as struct page *,
276
 * really physical DRAM addresses are unsigned long's, and DRAM "virtual"
277
 * addresses (the 0xc0xxxxxx's) goes as void *'s.
278
 */
279
 
280
static inline pte_t __mk_pte(void * page, pgprot_t pgprot)
281
{
282
        pte_t pte;
283
        /* the PTE needs a physical address */
284
        pte_val(pte) = __pa(page) | pgprot_val(pgprot);
285
        return pte;
286
}
287
 
288
#define mk_pte(page, pgprot) __mk_pte(page_address(page), (pgprot))
289
 
290
#define mk_pte_phys(physpage, pgprot) \
291
({                                                                      \
292
        pte_t __pte;                                                    \
293
                                                                        \
294
        pte_val(__pte) = (physpage) + pgprot_val(pgprot);               \
295
        __pte;                                                          \
296
})
297
 
298
static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
299
{ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
300
 
301
 
302
/* pte_val refers to a page in the 0x0xxxxxxx physical DRAM interval
303
 * __pte_page(pte_val) refers to the "virtual" DRAM interval
304
 * pte_pagenr refers to the page-number counted starting from the virtual DRAM start
305
 */
306
 
307
static inline unsigned long __pte_page(pte_t pte)
308
{
309
        /* the PTE contains a physical address */
310
        return (unsigned long)__va(pte_val(pte) & PAGE_MASK);
311
}
312
 
313
#define pte_pagenr(pte)         ((__pte_page(pte) - PAGE_OFFSET) >> PAGE_SHIFT)
314
 
315
/* permanent address of a page */
316
 
317
#define __page_address(page)    (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))
318
#define pte_page(pte)           (mem_map+pte_pagenr(pte))
319
 
320
/* only the pte's themselves need to point to physical DRAM (see above)
321
 * the pagetable links are purely handled within the kernel SW and thus
322
 * don't need the __pa and __va transformations.
323
 */
324
 
325
extern inline void pmd_set(pmd_t * pmdp, pte_t * ptep)
326
{ pmd_val(*pmdp) = _KERNPG_TABLE | (unsigned long) ptep; }
327
 
328
#define pmd_page(pmd)           (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
329
#define pmd_page_kernel(pmd)    ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
330
 
331
/* to find an entry in a page-table-directory. */
332
#define pgd_index(address)      ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
333
 
334
#define __pgd_offset(address)   pgd_index(address)
335
 
336
#define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
337
 
338
/* to find an entry in a kernel page-table-directory */
339
#define pgd_offset_k(address) pgd_offset(&init_mm, address)
340
 
341
#define __pmd_offset(address) \
342
                (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
343
 
344
static inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
345
{
346
        return (pmd_t *) dir;
347
}
348
 
349
/*
350
 * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
351
 *
352
 * this macro returns the index of the entry in the pte page which would
353
 * control the given virtual address
354
 */
355
#define __pte_offset(address)                   \
356
        (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
357
#define pte_offset_kernel(dir, address)         \
358
        ((pte_t *) pmd_page_kernel(*(dir)) +  __pte_offset(address))
359
#define pte_offset_map(dir, address)            \
360
        ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
361
#define pte_offset_map_nested(dir, address)     \
362
        pte_offset_map(dir, address)
363
 
364
#define pte_unmap(pte)          do { } while (0)
365
#define pte_unmap_nested(pte)   do { } while (0)
366
#define pte_pfn(x)              ((unsigned long)(((x).pte)) >> PAGE_SHIFT)
367
#define pfn_pte(pfn, prot)      __pte((((pfn) << PAGE_SHIFT)) | pgprot_val(prot))
368
 
369
#define pte_ERROR(e) \
370
        printk("%s:%d: bad pte %p(%08lx).\n", __FILE__, __LINE__, &(e), pte_val(e))
371
#define pmd_ERROR(e) \
372
        printk("%s:%d: bad pmd %p(%08lx).\n", __FILE__, __LINE__, &(e), pmd_val(e))
373
#define pgd_ERROR(e) \
374
        printk("%s:%d: bad pgd %p(%08lx).\n", __FILE__, __LINE__, &(e), pgd_val(e))
375
 
376
extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; /* defined in head.S */
377
 
378
/*
379
 * or32 doesn't have any external MMU info: the kernel page
380
 * tables contain all the necessary information.
381
 *
382
 * Actually I am not sure on what this could be used for.
383
 */
384
static inline void update_mmu_cache(struct vm_area_struct * vma,
385
        unsigned long address, pte_t pte)
386
{
387
}
388
 
389
#define __pgd_offset(address)   pgd_index(address)
390
 
391
#define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
392
 
393
/* to find an entry in a kernel page-table-directory */
394
#define pgd_offset_k(address)   pgd_offset(&init_mm, address)
395
 
396
#define __pmd_offset(address) \
397
                (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
398
 
399
/* __PHX__ FIXME, SWAP, this probably doesn't work */
400
 
401
/* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */
402
/* Since the PAGE_PRESENT bit is bit 4, we can use the bits above */
403
 
404
#define __swp_type(x)                   (((x).val >> 5) & 0x7f)
405
#define __swp_offset(x)                 ((x).val >> 12)
406
#define __swp_entry(type, offset)       ((swp_entry_t) { ((type) << 5) | ((offset) << 12) })
407
#define __pte_to_swp_entry(pte)         ((swp_entry_t) { pte_val(pte) })
408
#define __swp_entry_to_pte(x)           ((pte_t) { (x).val })
409
 
410
/* Encode and decode a nonlinear file mapping entry */
411
 
412
#define PTE_FILE_MAX_BITS               26
413
#define pte_to_pgoff(x)                 (pte_val(x) >> 6)
414
#define pgoff_to_pte(x)                 __pte(((x) << 6) | _PAGE_FILE)
415
 
416
#define kern_addr_valid(addr)           (1)
417
 
418
#include <asm-generic/pgtable.h>
419
 
420
/*
421
 * No page table caches to initialise
422
 */
423
#define pgtable_cache_init()            do { } while (0)
424
#define io_remap_page_range             remap_page_range
425
 
426
typedef pte_t *pte_addr_t;
427
 
428
#endif /* __ASSEMBLY__ */
429
#endif /* _OR32_PGTABLE_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.