page.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_GENERIC_PAGE_H
  3. #define __ASM_GENERIC_PAGE_H
  4. /*
  5. * Generic page.h implementation, for NOMMU architectures.
  6. * This provides the dummy definitions for the memory management.
  7. */
  8. #ifdef CONFIG_MMU
  9. #error need to prove a real asm/page.h
  10. #endif
  11. /* PAGE_SHIFT determines the page size */
  12. #define PAGE_SHIFT 12
  13. #ifdef __ASSEMBLY__
  14. #define PAGE_SIZE (1 << PAGE_SHIFT)
  15. #else
  16. #define PAGE_SIZE (1UL << PAGE_SHIFT)
  17. #endif
  18. #define PAGE_MASK (~(PAGE_SIZE-1))
  19. #include <asm/setup.h>
  20. #ifndef __ASSEMBLY__
  21. #define clear_page(page) memset((page), 0, PAGE_SIZE)
  22. #define copy_page(to,from) memcpy((to), (from), PAGE_SIZE)
  23. #define clear_user_page(page, vaddr, pg) clear_page(page)
  24. #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
  25. /*
  26. * These are used to make use of C type-checking..
  27. */
  28. typedef struct {
  29. unsigned long pte;
  30. } pte_t;
  31. typedef struct {
  32. unsigned long pmd[16];
  33. } pmd_t;
  34. typedef struct {
  35. unsigned long pgd;
  36. } pgd_t;
  37. typedef struct {
  38. unsigned long pgprot;
  39. } pgprot_t;
  40. typedef struct page *pgtable_t;
  41. #define pte_val(x) ((x).pte)
  42. #define pmd_val(x) ((&x)->pmd[0])
  43. #define pgd_val(x) ((x).pgd)
  44. #define pgprot_val(x) ((x).pgprot)
  45. #define __pte(x) ((pte_t) { (x) } )
  46. #define __pmd(x) ((pmd_t) { (x) } )
  47. #define __pgd(x) ((pgd_t) { (x) } )
  48. #define __pgprot(x) ((pgprot_t) { (x) } )
  49. extern unsigned long memory_start;
  50. extern unsigned long memory_end;
  51. #endif /* !__ASSEMBLY__ */
  52. #ifdef CONFIG_KERNEL_RAM_BASE_ADDRESS
  53. #define PAGE_OFFSET (CONFIG_KERNEL_RAM_BASE_ADDRESS)
  54. #else
  55. #define PAGE_OFFSET (0)
  56. #endif
  57. #ifndef ARCH_PFN_OFFSET
  58. #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT)
  59. #endif
  60. #ifndef __ASSEMBLY__
  61. #define __va(x) ((void *)((unsigned long) (x)))
  62. #define __pa(x) ((unsigned long) (x))
  63. #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
  64. #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
  65. #define virt_to_page(addr) pfn_to_page(virt_to_pfn(addr))
  66. #define page_to_virt(page) pfn_to_virt(page_to_pfn(page))
  67. #ifndef page_to_phys
  68. #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
  69. #endif
  70. #define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && ((pfn) - ARCH_PFN_OFFSET) < max_mapnr)
  71. #define virt_addr_valid(kaddr) (((void *)(kaddr) >= (void *)PAGE_OFFSET) && \
  72. ((void *)(kaddr) < (void *)memory_end))
  73. #endif /* __ASSEMBLY__ */
  74. #include <asm-generic/memory_model.h>
  75. #include <asm-generic/getorder.h>
  76. #endif /* __ASM_GENERIC_PAGE_H */