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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [asm-i386/] [pgtable.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
#ifndef _I386_PGTABLE_H
2
#define _I386_PGTABLE_H
3
 
4
#include <linux/config.h>
5
 
6
/*
7
 * Define USE_PENTIUM_MM if you want the 4MB page table optimizations.
8
 * This works only on a intel Pentium.
9
 */
10
#define USE_PENTIUM_MM 1
11
 
12
/*
13
 * The Linux memory management assumes a three-level page table setup. On
14
 * the i386, we use that, but "fold" the mid level into the top-level page
15
 * table, so that we physically have the same two-level page table as the
16
 * i386 mmu expects.
17
 *
18
 * This file contains the functions and defines necessary to modify and use
19
 * the i386 page table tree.
20
 */
21
 
22
#ifndef __ASSEMBLY__
23
 
24
/* Caches aren't brain-dead on the intel. */
25
#define flush_cache_all()                       do { } while (0)
26
#define flush_cache_mm(mm)                      do { } while (0)
27
#define flush_cache_range(mm, start, end)       do { } while (0)
28
#define flush_cache_page(vma, vmaddr)           do { } while (0)
29
#define flush_page_to_ram(page)                 do { } while (0)
30
#define flush_pages_to_ram(page,n)              do { } while (0)
31
 
32
/*
33
 * TLB flushing:
34
 *
35
 *  - flush_tlb() flushes the current mm struct TLBs
36
 *  - flush_tlb_all() flushes all processes TLBs
37
 *  - flush_tlb_mm(mm) flushes the specified mm context TLB's
38
 *  - flush_tlb_page(vma, vmaddr) flushes one page
39
 *  - flush_tlb_range(mm, start, end) flushes a range of pages
40
 *
41
 * ..but the i386 has somewhat limited tlb flushing capabilities,
42
 * and page-granular flushes are available only on i486 and up.
43
 */
44
 
45
#define __flush_tlb() \
46
do { unsigned long tmpreg; __asm__ __volatile__("movl %%cr3,%0\n\tmovl %0,%%cr3":"=r" (tmpreg) : :"memory"); } while (0)
47
 
48
/*
49
 * NOTE! The intel "invlpg" semantics are extremely strange. The
50
 * chip will add the segment base to the memory address, even though
51
 * no segment checking is done. We correct for this by using an
52
 * offset of -__PAGE_OFFSET that will wrap around the kernel segment base
53
 * of __PAGE_OFFSET to get the correct address (it will always be outside
54
 * the kernel segment, but we're only interested in the final linear
55
 * address.
56
 */
57
#define __invlpg_mem(addr) \
58
        (*((char *)(addr)-__PAGE_OFFSET))
59
#define __invlpg(addr) \
60
        __asm__ __volatile__("invlpg %0": :"m" (__invlpg_mem(addr)))
61
 
62
/*
63
 * The i386 doesn't have a page-granular invalidate. Invalidate
64
 * everything for it.
65
 */
66
#ifdef CONFIG_M386
67
  #define __flush_tlb_one(addr) __flush_tlb()
68
#else
69
  #define __flush_tlb_one(addr) __invlpg(addr)
70
#endif
71
 
72
#ifndef __SMP__
73
 
74
#define flush_tlb() __flush_tlb()
75
#define flush_tlb_all() __flush_tlb()
76
#define local_flush_tlb() __flush_tlb()
77
 
78
static inline void flush_tlb_mm(struct mm_struct *mm)
79
{
80
        if (mm == current->mm)
81
                __flush_tlb();
82
}
83
 
84
static inline void flush_tlb_page(struct vm_area_struct *vma,
85
        unsigned long addr)
86
{
87
        if (vma->vm_mm == current->mm)
88
                __flush_tlb_one(addr);
89
}
90
 
91
static inline void flush_tlb_range(struct mm_struct *mm,
92
        unsigned long start, unsigned long end)
93
{
94
        if (mm == current->mm)
95
                __flush_tlb();
96
}
97
 
98
#else
99
 
100
/*
101
 * We aren't very clever about this yet -  SMP could certainly
102
 * avoid some global flushes..
103
 */
104
 
105
#include <asm/smp.h>
106
 
107
#define local_flush_tlb() \
108
        __flush_tlb()
109
 
110
 
111
#define CLEVER_SMP_INVALIDATE
112
#ifdef CLEVER_SMP_INVALIDATE
113
 
114
/*
115
 *      Smarter SMP flushing macros.
116
 *              c/o Linus Torvalds.
117
 *
118
 *      These mean you can really definitely utterly forget about
119
 *      writing to user space from interrupts. (Its not allowed anyway).
120
 */
121
 
122
static inline void flush_tlb_current_task(void)
123
{
124
        if (current->mm->count == 1)    /* just one copy of this mm */
125
                local_flush_tlb();      /* and that's us, so.. */
126
        else
127
                smp_flush_tlb();
128
}
129
 
130
#define flush_tlb() flush_tlb_current_task()
131
 
132
#define flush_tlb_all() smp_flush_tlb()
133
 
134
static inline void flush_tlb_mm(struct mm_struct * mm)
135
{
136
        if (mm == current->mm && mm->count == 1)
137
                local_flush_tlb();
138
        else
139
                smp_flush_tlb();
140
}
141
 
142
static inline void flush_tlb_page(struct vm_area_struct * vma,
143
        unsigned long va)
144
{
145
        if (vma->vm_mm == current->mm && current->mm->count == 1)
146
                __flush_tlb_one(va);
147
        else
148
                smp_flush_tlb();
149
}
150
 
151
static inline void flush_tlb_range(struct mm_struct * mm,
152
        unsigned long start, unsigned long end)
153
{
154
        flush_tlb_mm(mm);
155
}
156
 
157
 
158
#else
159
 
160
#define flush_tlb() \
161
        smp_flush_tlb()
162
 
163
#define flush_tlb_all() flush_tlb()
164
 
165
static inline void flush_tlb_mm(struct mm_struct *mm)
166
{
167
        flush_tlb();
168
}
169
 
170
static inline void flush_tlb_page(struct vm_area_struct *vma,
171
        unsigned long addr)
172
{
173
        flush_tlb();
174
}
175
 
176
static inline void flush_tlb_range(struct mm_struct *mm,
177
        unsigned long start, unsigned long end)
178
{
179
        flush_tlb();
180
}
181
#endif
182
#endif
183
#endif /* !__ASSEMBLY__ */
184
 
185
 
186
/* Certain architectures need to do special things when pte's
187
 * within a page table are directly modified.  Thus, the following
188
 * hook is made available.
189
 */
190
#define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval))
191
 
192
/* PMD_SHIFT determines the size of the area a second-level page table can map */
193
#define PMD_SHIFT       22
194
#define PMD_SIZE        (1UL << PMD_SHIFT)
195
#define PMD_MASK        (~(PMD_SIZE-1))
196
 
197
/* PGDIR_SHIFT determines what a third-level page table entry can map */
198
#define PGDIR_SHIFT     22
199
#define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
200
#define PGDIR_MASK      (~(PGDIR_SIZE-1))
201
 
202
/*
203
 * entries per page directory level: the i386 is two-level, so
204
 * we don't really have any PMD directory physically.
205
 */
206
#define PTRS_PER_PTE    1024
207
#define PTRS_PER_PMD    1
208
#define PTRS_PER_PGD    1024
209
 
210
/*
211
 * pgd entries used up by user/kernel:
212
 */
213
 
214
#if CONFIG_MAX_MEMSIZE & 3
215
#error Invalid max physical memory size requested
216
#endif
217
 
218
#define USER_PGD_PTRS ((unsigned long)__PAGE_OFFSET >> PGDIR_SHIFT)
219
#define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS)
220
#define __USER_PGD_PTRS (__PAGE_OFFSET >> PGDIR_SHIFT)
221
#define __KERNEL_PGD_PTRS (PTRS_PER_PGD-__USER_PGD_PTRS)
222
 
223
#ifndef __ASSEMBLY__
224
 
225
/* Just any arbitrary offset to the start of the vmalloc VM area: the
226
 * current 8MB value just means that there will be a 8MB "hole" after the
227
 * physical memory until the kernel virtual memory starts.  That means that
228
 * any out-of-bounds memory accesses will hopefully be caught.
229
 * The vmalloc() routines leaves a hole of 4kB between each vmalloced
230
 * area for the same reason. ;)
231
 */
232
#define VMALLOC_OFFSET  (8*1024*1024)
233
#define VMALLOC_START ((high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1))
234
#define VMALLOC_VMADDR(x) (TASK_SIZE + (unsigned long)(x))
235
 
236
/*
237
 * The 4MB page is guessing..  Detailed in the infamous "Chapter H"
238
 * of the Pentium details, but assuming intel did the straightforward
239
 * thing, this bit set in the page directory entry just means that
240
 * the page directory entry points directly to a 4MB-aligned block of
241
 * memory.
242
 */
243
#define _PAGE_PRESENT   0x001
244
#define _PAGE_RW        0x002
245
#define _PAGE_USER      0x004
246
#define _PAGE_PCD       0x010
247
#define _PAGE_ACCESSED  0x020
248
#define _PAGE_DIRTY     0x040
249
#define _PAGE_4M        0x080   /* 4 MB page, Pentium+.. */
250
 
251
#define _PAGE_TABLE     (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED | _PAGE_DIRTY)
252
#define _PAGE_CHG_MASK  (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
253
 
254
#define PAGE_NONE       __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED)
255
#define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | _PAGE_ACCESSED)
256
#define PAGE_COPY       __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
257
#define PAGE_READONLY   __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_ACCESSED)
258
#define PAGE_KERNEL     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
259
 
260
/*
261
 * The i386 can't do page protection for execute, and considers that the same are read.
262
 * Also, write permissions imply read permissions. This is the closest we can get..
263
 */
264
#define __P000  PAGE_NONE
265
#define __P001  PAGE_READONLY
266
#define __P010  PAGE_COPY
267
#define __P011  PAGE_COPY
268
#define __P100  PAGE_READONLY
269
#define __P101  PAGE_READONLY
270
#define __P110  PAGE_COPY
271
#define __P111  PAGE_COPY
272
 
273
#define __S000  PAGE_NONE
274
#define __S001  PAGE_READONLY
275
#define __S010  PAGE_SHARED
276
#define __S011  PAGE_SHARED
277
#define __S100  PAGE_READONLY
278
#define __S101  PAGE_READONLY
279
#define __S110  PAGE_SHARED
280
#define __S111  PAGE_SHARED
281
 
282
/*
283
 * Define this if things work differently on a i386 and a i486:
284
 * it will (on a i486) warn about kernel memory accesses that are
285
 * done without a 'verify_area(VERIFY_WRITE,..)'
286
 */
287
#undef TEST_VERIFY_AREA
288
 
289
/* page table for 0-4MB for everybody */
290
extern unsigned long pg0[1024];
291
/* zero page used for uninitialized stuff */
292
extern unsigned long empty_zero_page[1024];
293
 
294
/*
295
 * BAD_PAGETABLE is used when we need a bogus page-table, while
296
 * BAD_PAGE is used for a bogus page.
297
 *
298
 * ZERO_PAGE is a global shared page that is always zero: used
299
 * for zero-mapped memory areas etc..
300
 */
301
extern pte_t __bad_page(void);
302
extern pte_t * __bad_pagetable(void);
303
 
304
#define BAD_PAGETABLE __bad_pagetable()
305
#define BAD_PAGE __bad_page()
306
#define ZERO_PAGE ((unsigned long) empty_zero_page)
307
 
308
/* number of bits that fit into a memory pointer */
309
#define BITS_PER_PTR                    (8*sizeof(unsigned long))
310
 
311
/* to align the pointer to a pointer address */
312
#define PTR_MASK                        (~(sizeof(void*)-1))
313
 
314
/* sizeof(void*)==1<<SIZEOF_PTR_LOG2 */
315
/* 64-bit machines, beware!  SRB. */
316
#define SIZEOF_PTR_LOG2                 2
317
 
318
/* to find an entry in a page-table */
319
#define PAGE_PTR(address) \
320
((unsigned long)(address)>>(PAGE_SHIFT-SIZEOF_PTR_LOG2)&PTR_MASK&~PAGE_MASK)
321
 
322
/* to set the page-dir */
323
#define SET_PAGE_DIR(tsk,pgdir) \
324
do { \
325
        (tsk)->tss.cr3 = (unsigned long) (pgdir); \
326
        if ((tsk) == current) \
327
                __asm__ __volatile__("movl %0,%%cr3": :"r" (pgdir)); \
328
} while (0)
329
 
330
#define pte_none(x)     (!pte_val(x))
331
#define pte_present(x)  (pte_val(x) & _PAGE_PRESENT)
332
#define pte_clear(xp)   do { pte_val(*(xp)) = 0; } while (0)
333
 
334
#define pmd_none(x)     (!pmd_val(x))
335
#define pmd_bad(x)      ((pmd_val(x) & ~PAGE_MASK) != _PAGE_TABLE)
336
#define pmd_present(x)  (pmd_val(x) & _PAGE_PRESENT)
337
#define pmd_clear(xp)   do { pmd_val(*(xp)) = 0; } while (0)
338
 
339
/*
340
 * The "pgd_xxx()" functions here are trivial for a folded two-level
341
 * setup: the pgd is never bad, and a pmd always exists (as it's folded
342
 * into the pgd entry)
343
 */
344
extern inline int pgd_none(pgd_t pgd)           { return 0; }
345
extern inline int pgd_bad(pgd_t pgd)            { return 0; }
346
extern inline int pgd_present(pgd_t pgd)        { return 1; }
347
extern inline void pgd_clear(pgd_t * pgdp)      { }
348
 
349
/*
350
 * The following only work if pte_present() is true.
351
 * Undefined behaviour if not..
352
 */
353
extern inline int pte_read(pte_t pte)           { return pte_val(pte) & _PAGE_USER; }
354
extern inline int pte_write(pte_t pte)          { return pte_val(pte) & _PAGE_RW; }
355
extern inline int pte_exec(pte_t pte)           { return pte_val(pte) & _PAGE_USER; }
356
extern inline int pte_dirty(pte_t pte)          { return pte_val(pte) & _PAGE_DIRTY; }
357
extern inline int pte_young(pte_t pte)          { return pte_val(pte) & _PAGE_ACCESSED; }
358
 
359
extern inline pte_t pte_wrprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_RW; return pte; }
360
extern inline pte_t pte_rdprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
361
extern inline pte_t pte_exprotect(pte_t pte)    { pte_val(pte) &= ~_PAGE_USER; return pte; }
362
extern inline pte_t pte_mkclean(pte_t pte)      { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
363
extern inline pte_t pte_mkold(pte_t pte)        { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
364
extern inline pte_t pte_mkwrite(pte_t pte)      { pte_val(pte) |= _PAGE_RW; return pte; }
365
extern inline pte_t pte_mkread(pte_t pte)       { pte_val(pte) |= _PAGE_USER; return pte; }
366
extern inline pte_t pte_mkexec(pte_t pte)       { pte_val(pte) |= _PAGE_USER; return pte; }
367
extern inline pte_t pte_mkdirty(pte_t pte)      { pte_val(pte) |= _PAGE_DIRTY; return pte; }
368
extern inline pte_t pte_mkyoung(pte_t pte)      { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
369
 
370
/*
371
 * Conversion functions: convert a page and protection to a page entry,
372
 * and a page entry and page directory to the page they refer to.
373
 */
374
extern inline pte_t mk_pte(unsigned long page, pgprot_t pgprot)
375
{ pte_t pte; pte_val(pte) = page | pgprot_val(pgprot); return pte; }
376
 
377
extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
378
{ pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); return pte; }
379
 
380
extern inline unsigned long pte_page(pte_t pte)
381
{ return pte_val(pte) & PAGE_MASK; }
382
 
383
extern inline unsigned long pmd_page(pmd_t pmd)
384
{ return pmd_val(pmd) & PAGE_MASK; }
385
 
386
/* to find an entry in a page-table-directory */
387
extern inline pgd_t * pgd_offset(struct mm_struct * mm, unsigned long address)
388
{
389
        return mm->pgd + (address >> PGDIR_SHIFT);
390
}
391
 
392
/* Find an entry in the second-level page table.. */
393
extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
394
{
395
        return (pmd_t *) dir;
396
}
397
 
398
/* Find an entry in the third-level page table.. */
399
extern inline pte_t * pte_offset(pmd_t * dir, unsigned long address)
400
{
401
        return (pte_t *) pmd_page(*dir) + ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
402
}
403
 
404
/*
405
 * Allocate and free page tables. The xxx_kernel() versions are
406
 * used to allocate a kernel page table - this turns on ASN bits
407
 * if any.
408
 */
409
extern inline void pte_free_kernel(pte_t * pte)
410
{
411
        free_page((unsigned long) pte);
412
}
413
 
414
extern const char bad_pmd_string[];
415
 
416
extern inline pte_t * pte_alloc_kernel(pmd_t * pmd, unsigned long address)
417
{
418
        address = (address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1);
419
        if (pmd_none(*pmd)) {
420
                pte_t * page = (pte_t *) get_free_page(GFP_KERNEL);
421
                if (pmd_none(*pmd)) {
422
                        if (page) {
423
                                pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) page;
424
                                return page + address;
425
                        }
426
                        pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
427
                        return NULL;
428
                }
429
                free_page((unsigned long) page);
430
        }
431
        if (pmd_bad(*pmd)) {
432
                printk(bad_pmd_string, pmd_val(*pmd));
433
                pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
434
                return NULL;
435
        }
436
        return (pte_t *) pmd_page(*pmd) + address;
437
}
438
 
439
/*
440
 * allocating and freeing a pmd is trivial: the 1-entry pmd is
441
 * inside the pgd, so has no extra memory associated with it.
442
 */
443
extern inline void pmd_free_kernel(pmd_t * pmd)
444
{
445
        pmd_val(*pmd) = 0;
446
}
447
 
448
extern inline pmd_t * pmd_alloc_kernel(pgd_t * pgd, unsigned long address)
449
{
450
        return (pmd_t *) pgd;
451
}
452
 
453
extern inline void pte_free(pte_t * pte)
454
{
455
        free_page((unsigned long) pte);
456
}
457
 
458
extern inline pte_t * pte_alloc(pmd_t * pmd, unsigned long address)
459
{
460
        address = (address >> (PAGE_SHIFT-2)) & 4*(PTRS_PER_PTE - 1);
461
 
462
repeat:
463
        if (pmd_none(*pmd))
464
                goto getnew;
465
        if (pmd_bad(*pmd))
466
                goto fix;
467
        return (pte_t *) (pmd_page(*pmd) + address);
468
 
469
getnew:
470
{
471
        unsigned long page = __get_free_page(GFP_KERNEL);
472
        if (!pmd_none(*pmd))
473
                goto freenew;
474
        if (!page)
475
                goto oom;
476
        memset((void *) page, 0, PAGE_SIZE);
477
        pmd_val(*pmd) = _PAGE_TABLE | page;
478
        return (pte_t *) (page + address);
479
freenew:
480
        free_page(page);
481
        goto repeat;
482
}
483
 
484
fix:
485
        printk(bad_pmd_string, pmd_val(*pmd));
486
oom:
487
        pmd_val(*pmd) = _PAGE_TABLE | (unsigned long) BAD_PAGETABLE;
488
        return NULL;
489
}
490
 
491
/*
492
 * allocating and freeing a pmd is trivial: the 1-entry pmd is
493
 * inside the pgd, so has no extra memory associated with it.
494
 */
495
extern inline void pmd_free(pmd_t * pmd)
496
{
497
        pmd_val(*pmd) = 0;
498
}
499
 
500
extern inline pmd_t * pmd_alloc(pgd_t * pgd, unsigned long address)
501
{
502
        return (pmd_t *) pgd;
503
}
504
 
505
extern inline void pgd_free(pgd_t * pgd)
506
{
507
        free_page((unsigned long) pgd);
508
}
509
 
510
extern inline pgd_t * pgd_alloc(void)
511
{
512
        return (pgd_t *) get_free_page(GFP_KERNEL);
513
}
514
 
515
extern pgd_t swapper_pg_dir[1024];
516
 
517
/*
518
 * The i386 doesn't have any external MMU info: the kernel page
519
 * tables contain all the necessary information.
520
 */
521
extern inline void update_mmu_cache(struct vm_area_struct * vma,
522
        unsigned long address, pte_t pte)
523
{
524
}
525
 
526
#define SWP_TYPE(entry) (((entry) >> 1) & 0x7f)
527
#define SWP_OFFSET(entry) ((entry) >> 8)
528
#define SWP_ENTRY(type,offset) (((type) << 1) | ((offset) << 8))
529
 
530
#endif /* !__ASSEMBLY__ */
531
 
532
#endif /* _I386_PAGE_H */

powered by: WebSVN 2.1.0

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