page.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _PARISC_PAGE_H
  3. #define _PARISC_PAGE_H
  4. #include <linux/const.h>
  5. #if defined(CONFIG_PARISC_PAGE_SIZE_4KB)
  6. # define PAGE_SHIFT 12
  7. #elif defined(CONFIG_PARISC_PAGE_SIZE_16KB)
  8. # define PAGE_SHIFT 14
  9. #elif defined(CONFIG_PARISC_PAGE_SIZE_64KB)
  10. # define PAGE_SHIFT 16
  11. #else
  12. # error "unknown default kernel page size"
  13. #endif
  14. #define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
  15. #define PAGE_MASK (~(PAGE_SIZE-1))
  16. #ifndef __ASSEMBLY__
  17. #include <asm/types.h>
  18. #include <asm/cache.h>
  19. #define clear_page(page) clear_page_asm((void *)(page))
  20. #define copy_page(to, from) copy_page_asm((void *)(to), (void *)(from))
  21. struct page;
  22. void clear_page_asm(void *page);
  23. void copy_page_asm(void *to, void *from);
  24. #define clear_user_page(vto, vaddr, page) clear_page_asm(vto)
  25. void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
  26. struct page *pg);
  27. /*
  28. * These are used to make use of C type-checking..
  29. */
  30. #define STRICT_MM_TYPECHECKS
  31. #ifdef STRICT_MM_TYPECHECKS
  32. typedef struct { unsigned long pte; } pte_t; /* either 32 or 64bit */
  33. /* NOTE: even on 64 bits, these entries are __u32 because we allocate
  34. * the pmd and pgd in ZONE_DMA (i.e. under 4GB) */
  35. typedef struct { __u32 pmd; } pmd_t;
  36. typedef struct { __u32 pgd; } pgd_t;
  37. typedef struct { unsigned long pgprot; } pgprot_t;
  38. #define pte_val(x) ((x).pte)
  39. /* These do not work lvalues, so make sure we don't use them as such. */
  40. #define pmd_val(x) ((x).pmd + 0)
  41. #define pgd_val(x) ((x).pgd + 0)
  42. #define pgprot_val(x) ((x).pgprot)
  43. #define __pte(x) ((pte_t) { (x) } )
  44. #define __pmd(x) ((pmd_t) { (x) } )
  45. #define __pgd(x) ((pgd_t) { (x) } )
  46. #define __pgprot(x) ((pgprot_t) { (x) } )
  47. #define __pmd_val_set(x,n) (x).pmd = (n)
  48. #define __pgd_val_set(x,n) (x).pgd = (n)
  49. #else
  50. /*
  51. * .. while these make it easier on the compiler
  52. */
  53. typedef unsigned long pte_t;
  54. typedef __u32 pmd_t;
  55. typedef __u32 pgd_t;
  56. typedef unsigned long pgprot_t;
  57. #define pte_val(x) (x)
  58. #define pmd_val(x) (x)
  59. #define pgd_val(x) (x)
  60. #define pgprot_val(x) (x)
  61. #define __pte(x) (x)
  62. #define __pmd(x) (x)
  63. #define __pgd(x) (x)
  64. #define __pgprot(x) (x)
  65. #define __pmd_val_set(x,n) (x) = (n)
  66. #define __pgd_val_set(x,n) (x) = (n)
  67. #endif /* STRICT_MM_TYPECHECKS */
  68. typedef struct page *pgtable_t;
  69. typedef struct __physmem_range {
  70. unsigned long start_pfn;
  71. unsigned long pages; /* PAGE_SIZE pages */
  72. } physmem_range_t;
  73. extern physmem_range_t pmem_ranges[];
  74. extern int npmem_ranges;
  75. #endif /* !__ASSEMBLY__ */
  76. /* WARNING: The definitions below must match exactly to sizeof(pte_t)
  77. * etc
  78. */
  79. #ifdef CONFIG_64BIT
  80. #define BITS_PER_PTE_ENTRY 3
  81. #define BITS_PER_PMD_ENTRY 2
  82. #define BITS_PER_PGD_ENTRY 2
  83. #else
  84. #define BITS_PER_PTE_ENTRY 2
  85. #define BITS_PER_PMD_ENTRY 2
  86. #define BITS_PER_PGD_ENTRY BITS_PER_PMD_ENTRY
  87. #endif
  88. #define PGD_ENTRY_SIZE (1UL << BITS_PER_PGD_ENTRY)
  89. #define PMD_ENTRY_SIZE (1UL << BITS_PER_PMD_ENTRY)
  90. #define PTE_ENTRY_SIZE (1UL << BITS_PER_PTE_ENTRY)
  91. #define LINUX_GATEWAY_SPACE 0
  92. /* This governs the relationship between virtual and physical addresses.
  93. * If you alter it, make sure to take care of our various fixed mapping
  94. * segments in fixmap.h */
  95. #if defined(BOOTLOADER)
  96. #define __PAGE_OFFSET (0) /* bootloader uses physical addresses */
  97. #else
  98. #ifdef CONFIG_64BIT
  99. #define __PAGE_OFFSET (0x40000000) /* 1GB */
  100. #else
  101. #define __PAGE_OFFSET (0x10000000) /* 256MB */
  102. #endif
  103. #endif /* BOOTLOADER */
  104. #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
  105. /* The size of the gateway page (we leave lots of room for expansion) */
  106. #define GATEWAY_PAGE_SIZE 0x4000
  107. /* The start of the actual kernel binary---used in vmlinux.lds.S
  108. * Leave some space after __PAGE_OFFSET for detecting kernel null
  109. * ptr derefs */
  110. #define KERNEL_BINARY_TEXT_START (__PAGE_OFFSET + 0x100000)
  111. /* These macros don't work for 64-bit C code -- don't allow in C at all */
  112. #ifdef __ASSEMBLY__
  113. # define PA(x) ((x)-__PAGE_OFFSET)
  114. # define VA(x) ((x)+__PAGE_OFFSET)
  115. #endif
  116. #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
  117. #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
  118. #ifndef CONFIG_DISCONTIGMEM
  119. #define pfn_valid(pfn) ((pfn) < max_mapnr)
  120. #endif /* CONFIG_DISCONTIGMEM */
  121. #ifdef CONFIG_HUGETLB_PAGE
  122. #define HPAGE_SHIFT PMD_SHIFT /* fixed for transparent huge pages */
  123. #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
  124. #define HPAGE_MASK (~(HPAGE_SIZE - 1))
  125. #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
  126. #if defined(CONFIG_64BIT) && defined(CONFIG_PARISC_PAGE_SIZE_4KB)
  127. # define REAL_HPAGE_SHIFT 20 /* 20 = 1MB */
  128. # define _HUGE_PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_1M
  129. #elif !defined(CONFIG_64BIT) && defined(CONFIG_PARISC_PAGE_SIZE_4KB)
  130. # define REAL_HPAGE_SHIFT 22 /* 22 = 4MB */
  131. # define _HUGE_PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_4M
  132. #else
  133. # define REAL_HPAGE_SHIFT 24 /* 24 = 16MB */
  134. # define _HUGE_PAGE_SIZE_ENCODING_DEFAULT _PAGE_SIZE_ENCODING_16M
  135. #endif
  136. #endif /* CONFIG_HUGETLB_PAGE */
  137. #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
  138. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  139. #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
  140. #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
  141. VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  142. #include <asm-generic/memory_model.h>
  143. #include <asm-generic/getorder.h>
  144. #include <asm/pdc.h>
  145. #define PAGE0 ((struct zeropage *)__PAGE_OFFSET)
  146. /* DEFINITION OF THE ZERO-PAGE (PAG0) */
  147. /* based on work by Jason Eckhardt (jason@equator.com) */
  148. #endif /* _PARISC_PAGE_H */