pgtable.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  linux/include/asm-arm/proc-armv/pgtable.h
  3.  *
  4.  *  Copyright (C) 1995-2001 Russell King
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License version 2 as
  8.  * published by the Free Software Foundation.
  9.  *
  10.  *  12-Jan-1997 RMK Altered flushing routines to use function pointers
  11.  * now possible to combine ARM6, ARM7 and StrongARM versions.
  12.  *  17-Apr-1999 RMK Now pass an area size to clean_cache_area and
  13.  * flush_icache_area.
  14.  */
  15. #ifndef __ASM_PROC_PGTABLE_H
  16. #define __ASM_PROC_PGTABLE_H
  17. #include <asm/proc/domain.h>
  18. #include <asm/arch/vmalloc.h>
  19. /*
  20.  * entries per page directory level: they are two-level, so
  21.  * we don't really have any PMD directory.
  22.  */
  23. #define PTRS_PER_PTE 256
  24. #define PTRS_PER_PMD 1
  25. #define PTRS_PER_PGD 4096
  26. /****************
  27. * PMD functions *
  28. ****************/
  29. /* PMD types (actually level 1 descriptor) */
  30. #define PMD_TYPE_MASK 0x0003
  31. #define PMD_TYPE_FAULT 0x0000
  32. #define PMD_TYPE_TABLE 0x0001
  33. #define PMD_TYPE_SECT 0x0002
  34. #define PMD_UPDATABLE 0x0010
  35. #define PMD_SECT_CACHEABLE 0x0008
  36. #define PMD_SECT_BUFFERABLE 0x0004
  37. #define PMD_SECT_AP_WRITE 0x0400
  38. #define PMD_SECT_AP_READ 0x0800
  39. #define PMD_DOMAIN(x) ((x) << 5)
  40. #define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_DOMAIN(DOMAIN_USER))
  41. #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_DOMAIN(DOMAIN_KERNEL))
  42. #define pmd_bad(pmd) (pmd_val(pmd) & 2)
  43. #define set_pmd(pmdp,pmd) cpu_set_pmd(pmdp,pmd)
  44. static inline pmd_t __mk_pmd(pte_t *ptep, unsigned long prot)
  45. {
  46. unsigned long pte_ptr = (unsigned long)ptep;
  47. pmd_t pmd;
  48. pte_ptr -= PTRS_PER_PTE * sizeof(void *);
  49. /*
  50.  * The pmd must be loaded with the physical
  51.  * address of the PTE table
  52.  */
  53. pmd_val(pmd) = __virt_to_phys(pte_ptr) | prot;
  54. return pmd;
  55. }
  56. static inline unsigned long pmd_page(pmd_t pmd)
  57. {
  58. unsigned long ptr;
  59. ptr = pmd_val(pmd) & ~(PTRS_PER_PTE * sizeof(void *) - 1);
  60. ptr += PTRS_PER_PTE * sizeof(void *);
  61. return __phys_to_virt(ptr);
  62. }
  63. /****************
  64. * PTE functions *
  65. ****************/
  66. /* PTE types (actually level 2 descriptor) */
  67. #define PTE_TYPE_MASK 0x0003
  68. #define PTE_TYPE_FAULT 0x0000
  69. #define PTE_TYPE_LARGE 0x0001
  70. #define PTE_TYPE_SMALL 0x0002
  71. #define PTE_AP_READ 0x0aa0
  72. #define PTE_AP_WRITE 0x0550
  73. #define PTE_CACHEABLE 0x0008
  74. #define PTE_BUFFERABLE 0x0004
  75. #define set_pte(ptep, pte) cpu_set_pte(ptep,pte)
  76. /* We now keep two sets of ptes - the physical and the linux version.
  77.  * This gives us many advantages, and allows us greater flexibility.
  78.  *
  79.  * The Linux pte's contain:
  80.  *  bit   meaning
  81.  *   0    page present
  82.  *   1    young
  83.  *   2    bufferable - matches physical pte
  84.  *   3    cacheable - matches physical pte
  85.  *   4    user
  86.  *   5    write
  87.  *   6    execute
  88.  *   7    dirty
  89.  *  8-11  unused
  90.  *  12-31 virtual page address
  91.  *
  92.  * These are stored at the pte pointer; the physical PTE is at -1024bytes
  93.  */
  94. #define L_PTE_PRESENT (1 << 0)
  95. #define L_PTE_YOUNG (1 << 1)
  96. #define L_PTE_BUFFERABLE (1 << 2)
  97. #define L_PTE_CACHEABLE (1 << 3)
  98. #define L_PTE_USER (1 << 4)
  99. #define L_PTE_WRITE (1 << 5)
  100. #define L_PTE_EXEC (1 << 6)
  101. #define L_PTE_DIRTY (1 << 7)
  102. /*
  103.  * The following macros handle the cache and bufferable bits...
  104.  */
  105. #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
  106. #define _L_PTE_READ L_PTE_USER | L_PTE_CACHEABLE | L_PTE_BUFFERABLE
  107. #define PAGE_NONE       __pgprot(_L_PTE_DEFAULT)
  108. #define PAGE_COPY       __pgprot(_L_PTE_DEFAULT | _L_PTE_READ)
  109. #define PAGE_SHARED     __pgprot(_L_PTE_DEFAULT | _L_PTE_READ | L_PTE_WRITE)
  110. #define PAGE_READONLY   __pgprot(_L_PTE_DEFAULT | _L_PTE_READ)
  111. #define PAGE_KERNEL     __pgprot(_L_PTE_DEFAULT | L_PTE_CACHEABLE | L_PTE_BUFFERABLE | L_PTE_DIRTY | L_PTE_WRITE)
  112. #define _PAGE_CHG_MASK (PAGE_MASK | L_PTE_DIRTY | L_PTE_YOUNG)
  113. /*
  114.  * The following only work if pte_present() is true.
  115.  * Undefined behaviour if not..
  116.  */
  117. #define pte_present(pte) (pte_val(pte) & L_PTE_PRESENT)
  118. #define pte_read(pte) (pte_val(pte) & L_PTE_USER)
  119. #define pte_write(pte) (pte_val(pte) & L_PTE_WRITE)
  120. #define pte_exec(pte) (pte_val(pte) & L_PTE_EXEC)
  121. #define pte_dirty(pte) (pte_val(pte) & L_PTE_DIRTY)
  122. #define pte_young(pte) (pte_val(pte) & L_PTE_YOUNG)
  123. #define PTE_BIT_FUNC(fn,op)
  124. static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; }
  125. /*PTE_BIT_FUNC(rdprotect, &= ~L_PTE_USER);*/
  126. /*PTE_BIT_FUNC(mkread,    |= L_PTE_USER);*/
  127. PTE_BIT_FUNC(wrprotect, &= ~L_PTE_WRITE);
  128. PTE_BIT_FUNC(mkwrite,   |= L_PTE_WRITE);
  129. PTE_BIT_FUNC(exprotect, &= ~L_PTE_EXEC);
  130. PTE_BIT_FUNC(mkexec,    |= L_PTE_EXEC);
  131. PTE_BIT_FUNC(mkclean,   &= ~L_PTE_DIRTY);
  132. PTE_BIT_FUNC(mkdirty,   |= L_PTE_DIRTY);
  133. PTE_BIT_FUNC(mkold,     &= ~L_PTE_YOUNG);
  134. PTE_BIT_FUNC(mkyoung,   |= L_PTE_YOUNG);
  135. /*
  136.  * Mark the prot value as uncacheable and unbufferable.
  137.  */
  138. #define pgprot_noncached(prot) __pgprot(pgprot_val(prot) & ~(L_PTE_CACHEABLE | L_PTE_BUFFERABLE))
  139. #endif /* __ASM_PROC_PGTABLE_H */