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

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  *  include/asm-s390/pgtable.h
  3.  *
  4.  *  S390 version
  5.  *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
  6.  *    Author(s): Hartmut Penner (hp@de.ibm.com)
  7.  *               Ulrich Weigand (weigand@de.ibm.com)
  8.  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
  9.  *
  10.  *  Derived from "include/asm-i386/pgtable.h"
  11.  */
  12. #ifndef _ASM_S390_PGTABLE_H
  13. #define _ASM_S390_PGTABLE_H
  14. /*
  15.  * The Linux memory management assumes a three-level page table setup. On
  16.  * the S390, we use that, but "fold" the mid level into the top-level page
  17.  * table, so that we physically have the same two-level page table as the
  18.  * S390 mmu expects.
  19.  *
  20.  * The "pgd_xxx()" functions are trivial for a folded two-level
  21.  * setup: the pgd is never bad, and a pmd always exists (as it's folded
  22.  * into the pgd entry)
  23.  *
  24.  * This file contains the functions and defines necessary to modify and use
  25.  * the S390 page table tree.
  26.  */
  27. #ifndef __ASSEMBLY__
  28. #include <asm/processor.h>
  29. #include <linux/threads.h>
  30. extern pgd_t swapper_pg_dir[] __attribute__ ((aligned (4096)));
  31. extern void paging_init(void);
  32. /* Caches aren't brain-dead on S390. */
  33. #define flush_cache_all()                       do { } while (0)
  34. #define flush_cache_mm(mm)                      do { } while (0)
  35. #define flush_cache_range(mm, start, end)       do { } while (0)
  36. #define flush_cache_page(vma, vmaddr)           do { } while (0)
  37. #define flush_page_to_ram(page)                 do { } while (0)
  38. #define flush_dcache_page(page) do { } while (0)
  39. #define flush_icache_range(start, end)          do { } while (0)
  40. #define flush_icache_page(vma,pg)               do { } while (0)
  41. #define flush_icache_user_range(vma,pg,adr,len) do { } while (0)
  42. /*
  43.  * The S390 doesn't have any external MMU info: the kernel page
  44.  * tables contain all the necessary information.
  45.  */
  46. #define update_mmu_cache(vma, address, pte)     do { } while (0)
  47. /*
  48.  * ZERO_PAGE is a global shared page that is always zero: used
  49.  * for zero-mapped memory areas etc..
  50.  */
  51. extern char empty_zero_page[PAGE_SIZE];
  52. #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  53. #endif /* !__ASSEMBLY__ */
  54. /*
  55.  * PMD_SHIFT determines the size of the area a second-level page
  56.  * table can map
  57.  */
  58. #define PMD_SHIFT       22
  59. #define PMD_SIZE        (1UL << PMD_SHIFT)
  60. #define PMD_MASK        (~(PMD_SIZE-1))
  61. /* PGDIR_SHIFT determines what a third-level page table entry can map */
  62. #define PGDIR_SHIFT     22
  63. #define PGDIR_SIZE      (1UL << PGDIR_SHIFT)
  64. #define PGDIR_MASK      (~(PGDIR_SIZE-1))
  65. /*
  66.  * entries per page directory level: the S390 is two-level, so
  67.  * we don't really have any PMD directory physically.
  68.  * for S390 segment-table entries are combined to one PGD
  69.  * that leads to 1024 pte per pgd
  70.  */
  71. #define PTRS_PER_PTE    1024
  72. #define PTRS_PER_PMD    1
  73. #define PTRS_PER_PGD    512
  74. /*
  75.  * pgd entries used up by user/kernel:
  76.  */
  77. #define USER_PTRS_PER_PGD  512
  78. #define USER_PGD_PTRS      512
  79. #define KERNEL_PGD_PTRS    512
  80. #define FIRST_USER_PGD_NR  0
  81. #define pte_ERROR(e) 
  82. printk("%s:%d: bad pte %08lx.n", __FILE__, __LINE__, pte_val(e))
  83. #define pmd_ERROR(e) 
  84. printk("%s:%d: bad pmd %08lx.n", __FILE__, __LINE__, pmd_val(e))
  85. #define pgd_ERROR(e) 
  86. printk("%s:%d: bad pgd %08lx.n", __FILE__, __LINE__, pgd_val(e))
  87. #ifndef __ASSEMBLY__
  88. /*
  89.  * Just any arbitrary offset to the start of the vmalloc VM area: the
  90.  * current 8MB value just means that there will be a 8MB "hole" after the
  91.  * physical memory until the kernel virtual memory starts.  That means that
  92.  * any out-of-bounds memory accesses will hopefully be caught.
  93.  * The vmalloc() routines leaves a hole of 4kB between each vmalloced
  94.  * area for the same reason. ;)
  95.  */
  96. #define VMALLOC_OFFSET  (8*1024*1024)
  97. #define VMALLOC_START   (((unsigned long) high_memory + VMALLOC_OFFSET) 
  98.  & ~(VMALLOC_OFFSET-1))
  99. #define VMALLOC_VMADDR(x) ((unsigned long)(x))
  100. #define VMALLOC_END     (0x7fffffffL)
  101. /*
  102.  * A pagetable entry of S390 has following format:
  103.  *  |   PFRA          |    |  OS  |
  104.  * 0                   0IP0
  105.  * 00000000001111111111222222222233
  106.  * 01234567890123456789012345678901
  107.  *
  108.  * I Page-Invalid Bit:    Page is not available for address-translation
  109.  * P Page-Protection Bit: Store access not possible for page
  110.  *
  111.  * A segmenttable entry of S390 has following format:
  112.  *  |   P-table origin      |  |PTL
  113.  * 0                         IC
  114.  * 00000000001111111111222222222233
  115.  * 01234567890123456789012345678901
  116.  *
  117.  * I Segment-Invalid Bit:    Segment is not available for address-translation
  118.  * C Common-Segment Bit:     Segment is not private (PoP 3-30)
  119.  * PTL Page-Table-Length:    Page-table length (PTL+1*16 entries -> up to 256)
  120.  *
  121.  * The segmenttable origin of S390 has following format:
  122.  *
  123.  *  |S-table origin   |     | STL |
  124.  * X                   **GPS
  125.  * 00000000001111111111222222222233
  126.  * 01234567890123456789012345678901
  127.  *
  128.  * X Space-Switch event:
  129.  * G Segment-Invalid Bit:     *
  130.  * P Private-Space Bit:       Segment is not private (PoP 3-30)
  131.  * S Storage-Alteration:
  132.  * STL Segment-Table-Length:  Segment-table length (STL+1*16 entries -> up to 2048)
  133.  *
  134.  * A storage key has the following format:
  135.  * | ACC |F|R|C|0|
  136.  *  0   3 4 5 6 7
  137.  * ACC: access key
  138.  * F  : fetch protection bit
  139.  * R  : referenced bit
  140.  * C  : changed bit
  141.  */
  142. /* Bits in the page table entry */
  143. #define _PAGE_PRESENT   0x001          /* Software                         */
  144. #define _PAGE_MKCLEAN   0x002          /* Software                         */
  145. #define _PAGE_ISCLEAN   0x004        /* Software    */
  146. #define _PAGE_RO        0x200          /* HW read-only                     */
  147. #define _PAGE_INVALID   0x400          /* HW invalid                       */
  148. /* Bits in the segment table entry */
  149. #define _PAGE_TABLE_LEN 0xf            /* only full page-tables            */
  150. #define _PAGE_TABLE_COM 0x10           /* common page-table                */
  151. #define _PAGE_TABLE_INV 0x20           /* invalid page-table               */
  152. #define _SEG_PRESENT    0x001          /* Software (overlap with PTL)      */
  153. /* Bits int the storage key */
  154. #define _PAGE_CHANGED    0x02          /* HW changed bit                   */
  155. #define _PAGE_REFERENCED 0x04          /* HW referenced bit                */
  156. #define _USER_SEG_TABLE_LEN    0x7f    /* user-segment-table up to 2 GB    */
  157. #define _KERNEL_SEG_TABLE_LEN  0x7f    /* kernel-segment-table up to 2 GB  */
  158. /*
  159.  * User and Kernel pagetables are identical
  160.  */
  161. #define _PAGE_TABLE     (_PAGE_TABLE_LEN )
  162. #define _KERNPG_TABLE   (_PAGE_TABLE_LEN )
  163. /*
  164.  * The Kernel segment-tables includes the User segment-table
  165.  */
  166. #define _SEGMENT_TABLE  (_USER_SEG_TABLE_LEN|0x80000000|0x100)
  167. #define _KERNSEG_TABLE  (_KERNEL_SEG_TABLE_LEN)
  168. /*
  169.  * No mapping available
  170.  */
  171. #define PAGE_INVALID   __pgprot(_PAGE_INVALID)
  172. #define PAGE_NONE_SHARED  __pgprot(_PAGE_PRESENT|_PAGE_INVALID)
  173. #define PAGE_NONE_PRIVATE __pgprot(_PAGE_PRESENT|_PAGE_INVALID|_PAGE_ISCLEAN)
  174. #define PAGE_RO_SHARED   __pgprot(_PAGE_PRESENT|_PAGE_RO)
  175. #define PAGE_RO_PRIVATE   __pgprot(_PAGE_PRESENT|_PAGE_RO|_PAGE_ISCLEAN)
  176. #define PAGE_COPY   __pgprot(_PAGE_PRESENT|_PAGE_RO|_PAGE_ISCLEAN)
  177. #define PAGE_SHARED   __pgprot(_PAGE_PRESENT)
  178. #define PAGE_KERNEL   __pgprot(_PAGE_PRESENT)
  179. /*
  180.  * The S390 can't do page protection for execute, and considers that the
  181.  * same are read. Also, write permissions imply read permissions. This is
  182.  * the closest we can get..
  183.  */
  184.          /*xwr*/
  185. #define __P000  PAGE_NONE_PRIVATE
  186. #define __P001  PAGE_RO_PRIVATE
  187. #define __P010  PAGE_COPY
  188. #define __P011  PAGE_COPY
  189. #define __P100  PAGE_RO_PRIVATE
  190. #define __P101  PAGE_RO_PRIVATE
  191. #define __P110  PAGE_COPY
  192. #define __P111  PAGE_COPY
  193. #define __S000  PAGE_NONE_SHARED
  194. #define __S001  PAGE_RO_SHARED
  195. #define __S010  PAGE_SHARED
  196. #define __S011  PAGE_SHARED
  197. #define __S100  PAGE_RO_SHARED
  198. #define __S101  PAGE_RO_SHARED
  199. #define __S110  PAGE_SHARED
  200. #define __S111  PAGE_SHARED
  201. /*
  202.  * Certain architectures need to do special things when PTEs
  203.  * within a page table are directly modified.  Thus, the following
  204.  * hook is made available.
  205.  */
  206. extern inline void set_pte(pte_t *pteptr, pte_t pteval)
  207. {
  208. if ((pte_val(pteval) & (_PAGE_MKCLEAN|_PAGE_INVALID))
  209.     == _PAGE_MKCLEAN) 
  210. {
  211. pte_val(pteval) &= ~_PAGE_MKCLEAN;
  212.                
  213. asm volatile ("sske %0,%1" 
  214. : : "d" (0), "a" (pte_val(pteval)));
  215. }
  216. *pteptr = pteval;
  217. }
  218. #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
  219. /*
  220.  * pgd/pmd/pte query functions
  221.  */
  222. extern inline int pgd_present(pgd_t pgd) { return 1; }
  223. extern inline int pgd_none(pgd_t pgd)    { return 0; }
  224. extern inline int pgd_bad(pgd_t pgd)     { return 0; }
  225. extern inline int pmd_present(pmd_t pmd) { return pmd_val(pmd) & _SEG_PRESENT; }
  226. extern inline int pmd_none(pmd_t pmd)    { return pmd_val(pmd) & _PAGE_TABLE_INV; }
  227. extern inline int pmd_bad(pmd_t pmd)
  228. {
  229. return (pmd_val(pmd) & (~PAGE_MASK & ~_PAGE_TABLE_INV)) != _PAGE_TABLE;
  230. }
  231. extern inline int pte_present(pte_t pte) { return pte_val(pte) & _PAGE_PRESENT; }
  232. extern inline int pte_none(pte_t pte)
  233. {
  234. return ((pte_val(pte) & 
  235.                 (_PAGE_INVALID | _PAGE_RO | _PAGE_PRESENT)) == _PAGE_INVALID);
  236. }
  237. #define pte_same(a,b) (pte_val(a) == pte_val(b))
  238. /*
  239.  * query functions pte_write/pte_dirty/pte_young only work if
  240.  * pte_present() is true. Undefined behaviour if not..
  241.  */
  242. extern inline int pte_write(pte_t pte)
  243. {
  244. return (pte_val(pte) & _PAGE_RO) == 0;
  245. }
  246. extern inline int pte_dirty(pte_t pte)
  247. {
  248. int skey;
  249. if (pte_val(pte) & _PAGE_ISCLEAN)
  250. return 0;
  251. asm volatile ("iske %0,%1" : "=d" (skey) : "a" (pte_val(pte)));
  252. return skey & _PAGE_CHANGED;
  253. }
  254. extern inline int pte_young(pte_t pte)
  255. {
  256. int skey;
  257. asm volatile ("iske %0,%1" : "=d" (skey) : "a" (pte_val(pte)));
  258. return skey & _PAGE_REFERENCED;
  259. }
  260. /*
  261.  * pgd/pmd/pte modification functions
  262.  */
  263. extern inline void pgd_clear(pgd_t * pgdp)      { }
  264. extern inline void pmd_clear(pmd_t * pmdp)
  265. {
  266. pmd_val(pmdp[0]) = _PAGE_TABLE_INV;
  267. pmd_val(pmdp[1]) = _PAGE_TABLE_INV;
  268. pmd_val(pmdp[2]) = _PAGE_TABLE_INV;
  269. pmd_val(pmdp[3]) = _PAGE_TABLE_INV;
  270. }
  271. extern inline void pte_clear(pte_t *ptep)
  272. {
  273. pte_val(*ptep) = _PAGE_INVALID; 
  274. }
  275. #define PTE_INIT(x) pte_clear(x)
  276. /*
  277.  * The following pte modification functions only work if
  278.  * pte_present() is true. Undefined behaviour if not..
  279.  */
  280. extern inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  281. {
  282. pte_val(pte) &= PAGE_MASK | _PAGE_ISCLEAN;
  283. pte_val(pte) |= pgprot_val(newprot) & ~_PAGE_ISCLEAN;
  284. return pte;
  285. }
  286. extern inline pte_t pte_wrprotect(pte_t pte)
  287. {
  288. pte_val(pte) |= _PAGE_RO;
  289. return pte;
  290. }
  291. extern inline pte_t pte_mkwrite(pte_t pte) 
  292. {
  293. pte_val(pte) &= ~_PAGE_RO;
  294. return pte;
  295. }
  296. extern inline pte_t pte_mkclean(pte_t pte)
  297. {
  298. /* The only user of pte_mkclean is the fork() code.
  299.    We must *not* clear the *physical* page dirty bit
  300.    just because fork() wants to clear the dirty bit in
  301.    *one* of the page's mappings.  So we just do nothing. */
  302. return pte;
  303. }
  304. extern inline pte_t pte_mkdirty(pte_t pte)
  305. {
  306. /* We do not explicitly set the dirty bit because the
  307.  * sske instruction is slow. It is faster to let the
  308.  * next instruction set the dirty bit.
  309.  */
  310. pte_val(pte) &= ~(_PAGE_MKCLEAN | _PAGE_ISCLEAN);
  311. return pte;
  312. }
  313. extern inline pte_t pte_mkold(pte_t pte)
  314. {
  315. asm volatile ("rrbe 0,%0" : : "a" (pte_val(pte)) : "cc" );
  316. return pte;
  317. }
  318. extern inline pte_t pte_mkyoung(pte_t pte)
  319. {
  320. /* To set the referenced bit we read the first word from the real
  321.  * page with a special instruction: load using real address (lura).
  322.  * Isn't S/390 a nice architecture ?! */
  323. asm volatile ("lura 0,%0" : : "a" (pte_val(pte) & PAGE_MASK) : "0" );
  324. return pte;
  325. }
  326. static inline int ptep_test_and_clear_young(pte_t *ptep)
  327. {
  328. int ccode;
  329. asm volatile ("rrbe 0,%1nt"
  330.       "ipm  %0nt"
  331.       "srl  %0,28nt" 
  332.                       : "=d" (ccode) : "a" (pte_val(*ptep)) : "cc" );
  333. return ccode & 2;
  334. }
  335. static inline int ptep_test_and_clear_dirty(pte_t *ptep)
  336. {
  337. int skey;
  338. if (pte_val(*ptep) & _PAGE_ISCLEAN)
  339. return 0;
  340. asm volatile ("iske %0,%1" : "=d" (skey) : "a" (*ptep));
  341. if ((skey & _PAGE_CHANGED) == 0)
  342. return 0;
  343. /* We can't clear the changed bit atomically. For now we
  344.          * clear (!) the page referenced bit. */
  345. asm volatile ("sske %0,%1" 
  346.               : : "d" (0), "a" (*ptep));
  347. return 1;
  348. }
  349. static inline pte_t ptep_get_and_clear(pte_t *ptep)
  350. {
  351. pte_t pte = *ptep;
  352. pte_clear(ptep);
  353. return pte;
  354. }
  355. static inline void ptep_set_wrprotect(pte_t *ptep)
  356. {
  357. pte_t old_pte = *ptep;
  358. set_pte(ptep, pte_wrprotect(old_pte));
  359. }
  360. static inline void ptep_mkdirty(pte_t *ptep)
  361. {
  362. pte_mkdirty(*ptep);
  363. }
  364. /*
  365.  * Conversion functions: convert a page and protection to a page entry,
  366.  * and a page entry and page directory to the page they refer to.
  367.  */
  368. static inline pte_t mk_pte_phys(unsigned long physpage, pgprot_t pgprot)
  369. {
  370. pte_t __pte;
  371. pte_val(__pte) = physpage + pgprot_val(pgprot);
  372. return __pte;
  373. }
  374. #define mk_pte(pg, pgprot)                                                
  375. ({                                                                        
  376. struct page *__page = (pg);                                       
  377. pgprot_t __pgprot = (pgprot);   
  378. unsigned long __physpage = __pa((__page-mem_map) << PAGE_SHIFT);  
  379. pte_t __pte = mk_pte_phys(__physpage, __pgprot);                  
  380.                                                                   
  381. if (!(pgprot_val(__pgprot) & _PAGE_ISCLEAN)) {   
  382. int __users = !!__page->buffers + !!__page->mapping;      
  383. if (__users + page_count(__page) == 1)                    
  384. pte_val(__pte) |= _PAGE_MKCLEAN;                  
  385. }   
  386. __pte;                                                            
  387. })
  388. #define pte_page(x) (mem_map+(unsigned long)((pte_val(x) >> PAGE_SHIFT)))
  389. #define pmd_page(pmd) 
  390.         ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
  391. /* to find an entry in a page-table-directory */
  392. #define pgd_index(address) ((address >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
  393. #define pgd_offset(mm, address) ((mm)->pgd+pgd_index(address))
  394. /* to find an entry in a kernel page-table-directory */
  395. #define pgd_offset_k(address) pgd_offset(&init_mm, address)
  396. /* Find an entry in the second-level page table.. */
  397. extern inline pmd_t * pmd_offset(pgd_t * dir, unsigned long address)
  398. {
  399.         return (pmd_t *) dir;
  400. }
  401. /* Find an entry in the third-level page table.. */
  402. #define pte_offset(pmd, address) 
  403.         ((pte_t *) (pmd_page(*pmd) + ((address>>10) & ((PTRS_PER_PTE-1)<<2))))
  404. /*
  405.  * A page-table entry has some bits we have to treat in a special way.
  406.  * Bits 0, 20 and bit 23 have to be zero, otherwise an specification
  407.  * exception will occur instead of a page translation exception. The
  408.  * specifiation exception has the bad habit not to store necessary
  409.  * information in the lowcore.
  410.  * Bit 21 and bit 22 are the page invalid bit and the page protection
  411.  * bit. We set both to indicate a swapped page.
  412.  * Bit 31 is used as the software page present bit. If a page is
  413.  * swapped this obviously has to be zero.
  414.  * This leaves the bits 1-19 and bits 24-30 to store type and offset.
  415.  * We use the 7 bits from 24-30 for the type and the 19 bits from 1-19
  416.  * for the offset.
  417.  * 0|     offset      |0110|type |0
  418.  * 00000000001111111111222222222233
  419.  * 01234567890123456789012345678901
  420.  */
  421. extern inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
  422. {
  423. pte_t pte;
  424. pte_val(pte) = (type << 1) | (offset << 12) | _PAGE_INVALID | _PAGE_RO;
  425. pte_val(pte) &= 0x7ffff6fe;  /* better to be paranoid */
  426. return pte;
  427. }
  428. #define SWP_TYPE(entry) (((entry).val >> 1) & 0x3f)
  429. #define SWP_OFFSET(entry) (((entry).val >> 12) & 0x7FFFF )
  430. #define SWP_ENTRY(type,offset) ((swp_entry_t) { pte_val(mk_swap_pte((type),(offset))) })
  431. #define pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  432. #define swp_entry_to_pte(x) ((pte_t) { (x).val })
  433. #endif /* !__ASSEMBLY__ */
  434. /* Needs to be defined here and not in linux/mm.h, as it is arch dependent */
  435. #define PageSkip(page)          (0)
  436. #define kern_addr_valid(addr)   (1)
  437. /*
  438.  * No page table caches to initialise
  439.  */
  440. #define pgtable_cache_init() do { } while (0)
  441. #endif /* _S390_PAGE_H */