page.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (C) 2000 - 2003 Jeff Dike (jdike@addtoit.com)
  3. * Copyright 2003 PathScale, Inc.
  4. * Licensed under the GPL
  5. */
  6. #ifndef __UM_PAGE_H
  7. #define __UM_PAGE_H
  8. #include <linux/const.h>
  9. /* PAGE_SHIFT determines the page size */
  10. #define PAGE_SHIFT 12
  11. #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
  12. #define PAGE_MASK (~(PAGE_SIZE-1))
  13. #ifndef __ASSEMBLY__
  14. struct page;
  15. #include <linux/types.h>
  16. #include <asm/vm-flags.h>
  17. /*
  18. * These are used to make use of C type-checking..
  19. */
  20. #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
  21. #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
  22. #define clear_user_page(page, vaddr, pg) clear_page(page)
  23. #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
  24. #if defined(CONFIG_3_LEVEL_PGTABLES) && !defined(CONFIG_64BIT)
  25. typedef struct { unsigned long pte_low, pte_high; } pte_t;
  26. typedef struct { unsigned long pmd; } pmd_t;
  27. typedef struct { unsigned long pgd; } pgd_t;
  28. #define pte_val(x) ((x).pte_low | ((unsigned long long) (x).pte_high << 32))
  29. #define pte_get_bits(pte, bits) ((pte).pte_low & (bits))
  30. #define pte_set_bits(pte, bits) ((pte).pte_low |= (bits))
  31. #define pte_clear_bits(pte, bits) ((pte).pte_low &= ~(bits))
  32. #define pte_copy(to, from) ({ (to).pte_high = (from).pte_high; \
  33. smp_wmb(); \
  34. (to).pte_low = (from).pte_low; })
  35. #define pte_is_zero(pte) (!((pte).pte_low & ~_PAGE_NEWPAGE) && !(pte).pte_high)
  36. #define pte_set_val(pte, phys, prot) \
  37. ({ (pte).pte_high = (phys) >> 32; \
  38. (pte).pte_low = (phys) | pgprot_val(prot); })
  39. #define pmd_val(x) ((x).pmd)
  40. #define __pmd(x) ((pmd_t) { (x) } )
  41. typedef unsigned long long pfn_t;
  42. typedef unsigned long long phys_t;
  43. #else
  44. typedef struct { unsigned long pte; } pte_t;
  45. typedef struct { unsigned long pgd; } pgd_t;
  46. #ifdef CONFIG_3_LEVEL_PGTABLES
  47. typedef struct { unsigned long pmd; } pmd_t;
  48. #define pmd_val(x) ((x).pmd)
  49. #define __pmd(x) ((pmd_t) { (x) } )
  50. #endif
  51. #define pte_val(x) ((x).pte)
  52. #define pte_get_bits(p, bits) ((p).pte & (bits))
  53. #define pte_set_bits(p, bits) ((p).pte |= (bits))
  54. #define pte_clear_bits(p, bits) ((p).pte &= ~(bits))
  55. #define pte_copy(to, from) ((to).pte = (from).pte)
  56. #define pte_is_zero(p) (!((p).pte & ~_PAGE_NEWPAGE))
  57. #define pte_set_val(p, phys, prot) (p).pte = (phys | pgprot_val(prot))
  58. typedef unsigned long pfn_t;
  59. typedef unsigned long phys_t;
  60. #endif
  61. typedef struct { unsigned long pgprot; } pgprot_t;
  62. typedef struct page *pgtable_t;
  63. #define pgd_val(x) ((x).pgd)
  64. #define pgprot_val(x) ((x).pgprot)
  65. #define __pte(x) ((pte_t) { (x) } )
  66. #define __pgd(x) ((pgd_t) { (x) } )
  67. #define __pgprot(x) ((pgprot_t) { (x) } )
  68. extern unsigned long uml_physmem;
  69. #define PAGE_OFFSET (uml_physmem)
  70. #define KERNELBASE PAGE_OFFSET
  71. #define __va_space (8*1024*1024)
  72. #include <mem.h>
  73. /* Cast to unsigned long before casting to void * to avoid a warning from
  74. * mmap_kmem about cutting a long long down to a void *. Not sure that
  75. * casting is the right thing, but 32-bit UML can't have 64-bit virtual
  76. * addresses
  77. */
  78. #define __pa(virt) to_phys((void *) (unsigned long) (virt))
  79. #define __va(phys) to_virt((unsigned long) (phys))
  80. #define phys_to_pfn(p) ((pfn_t) ((p) >> PAGE_SHIFT))
  81. #define pfn_to_phys(pfn) ((phys_t) ((pfn) << PAGE_SHIFT))
  82. #define pfn_valid(pfn) ((pfn) < max_mapnr)
  83. #define virt_addr_valid(v) pfn_valid(phys_to_pfn(__pa(v)))
  84. #include <asm-generic/memory_model.h>
  85. #include <asm-generic/getorder.h>
  86. #endif /* __ASSEMBLY__ */
  87. #ifdef CONFIG_X86_32
  88. #define __HAVE_ARCH_GATE_AREA 1
  89. #endif
  90. #endif /* __UM_PAGE_H */