pgtable-64.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 Regents of the University of California
  4. */
  5. #ifndef _ASM_RISCV_PGTABLE_64_H
  6. #define _ASM_RISCV_PGTABLE_64_H
  7. #include <linux/const.h>
  8. #define PGDIR_SHIFT 30
  9. /* Size of region mapped by a page global directory */
  10. #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
  11. #define PGDIR_MASK (~(PGDIR_SIZE - 1))
  12. #define PMD_SHIFT 21
  13. /* Size of region mapped by a page middle directory */
  14. #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
  15. #define PMD_MASK (~(PMD_SIZE - 1))
  16. /* Page Middle Directory entry */
  17. typedef struct {
  18. unsigned long pmd;
  19. } pmd_t;
  20. #define pmd_val(x) ((x).pmd)
  21. #define __pmd(x) ((pmd_t) { (x) })
  22. #define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t))
  23. static inline int pud_present(pud_t pud)
  24. {
  25. return (pud_val(pud) & _PAGE_PRESENT);
  26. }
  27. static inline int pud_none(pud_t pud)
  28. {
  29. return (pud_val(pud) == 0);
  30. }
  31. static inline int pud_bad(pud_t pud)
  32. {
  33. return !pud_present(pud);
  34. }
  35. #define pud_leaf pud_leaf
  36. static inline int pud_leaf(pud_t pud)
  37. {
  38. return pud_present(pud) &&
  39. (pud_val(pud) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
  40. }
  41. static inline void set_pud(pud_t *pudp, pud_t pud)
  42. {
  43. *pudp = pud;
  44. }
  45. static inline void pud_clear(pud_t *pudp)
  46. {
  47. set_pud(pudp, __pud(0));
  48. }
  49. static inline unsigned long pud_page_vaddr(pud_t pud)
  50. {
  51. return (unsigned long)pfn_to_virt((pud_val(pud) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT);
  52. }
  53. static inline struct page *pud_page(pud_t pud)
  54. {
  55. return pfn_to_page(pud_val(pud) >> _PAGE_PFN_SHIFT);
  56. }
  57. static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot)
  58. {
  59. return __pmd((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
  60. }
  61. static inline unsigned long _pmd_pfn(pmd_t pmd)
  62. {
  63. return pmd_val(pmd) >> _PAGE_PFN_SHIFT;
  64. }
  65. #define pmd_ERROR(e) \
  66. pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
  67. #endif /* _ASM_RISCV_PGTABLE_64_H */