pgtable-64.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2012 Regents of the University of California
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #ifndef _ASM_RISCV_PGTABLE_64_H
  14. #define _ASM_RISCV_PGTABLE_64_H
  15. #include <linux/const.h>
  16. #define PGDIR_SHIFT 30
  17. /* Size of region mapped by a page global directory */
  18. #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
  19. #define PGDIR_MASK (~(PGDIR_SIZE - 1))
  20. #define PMD_SHIFT 21
  21. /* Size of region mapped by a page middle directory */
  22. #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
  23. #define PMD_MASK (~(PMD_SIZE - 1))
  24. /* Page Middle Directory entry */
  25. typedef struct {
  26. unsigned long pmd;
  27. } pmd_t;
  28. #define pmd_val(x) ((x).pmd)
  29. #define __pmd(x) ((pmd_t) { (x) })
  30. #define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t))
  31. static inline int pud_present(pud_t pud)
  32. {
  33. return (pud_val(pud) & _PAGE_PRESENT);
  34. }
  35. static inline int pud_none(pud_t pud)
  36. {
  37. return (pud_val(pud) == 0);
  38. }
  39. static inline int pud_bad(pud_t pud)
  40. {
  41. return !pud_present(pud);
  42. }
  43. static inline void set_pud(pud_t *pudp, pud_t pud)
  44. {
  45. *pudp = pud;
  46. }
  47. static inline void pud_clear(pud_t *pudp)
  48. {
  49. set_pud(pudp, __pud(0));
  50. }
  51. static inline unsigned long pud_page_vaddr(pud_t pud)
  52. {
  53. return (unsigned long)pfn_to_virt(pud_val(pud) >> _PAGE_PFN_SHIFT);
  54. }
  55. #define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
  56. static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
  57. {
  58. return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(addr);
  59. }
  60. static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot)
  61. {
  62. return __pmd((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
  63. }
  64. #define pmd_ERROR(e) \
  65. pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
  66. #endif /* _ASM_RISCV_PGTABLE_64_H */