page.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef _ASM_X86_PAGE_H_
  2. #define _ASM_X86_PAGE_H_
  3. /*
  4. * Copyright (C) 2016, Red Hat Inc, Alexander Gordeev <agordeev@redhat.com>
  5. *
  6. * This work is licensed under the terms of the GNU LGPL, version 2.
  7. */
  8. #include <linux/const.h>
  9. #include <bitops.h>
  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. #ifdef __x86_64__
  15. #define LARGE_PAGE_SIZE (512 * PAGE_SIZE)
  16. #else
  17. #define LARGE_PAGE_SIZE (1024 * PAGE_SIZE)
  18. #endif
  19. #define PT_PRESENT_MASK (1ull << 0)
  20. #define PT_WRITABLE_MASK (1ull << 1)
  21. #define PT_USER_MASK (1ull << 2)
  22. #define PT_ACCESSED_MASK (1ull << 5)
  23. #define PT_DIRTY_MASK (1ull << 6)
  24. #define PT_PAGE_SIZE_MASK (1ull << 7)
  25. #define PT64_NX_MASK (1ull << 63)
  26. #define PT_ADDR_MASK GENMASK_ULL(51, 12)
  27. #define PT_AD_MASK (PT_ACCESSED_MASK | PT_DIRTY_MASK)
  28. #ifdef __x86_64__
  29. #define PAGE_LEVEL 4
  30. #define PGDIR_WIDTH 9
  31. #define PGDIR_MASK 511
  32. #else
  33. #define PAGE_LEVEL 2
  34. #define PGDIR_WIDTH 10
  35. #define PGDIR_MASK 1023
  36. #endif
  37. #define PGDIR_BITS(lvl) (((lvl) - 1) * PGDIR_WIDTH + PAGE_SHIFT)
  38. #define PGDIR_OFFSET(va, lvl) (((va) >> PGDIR_BITS(lvl)) & PGDIR_MASK)
  39. #endif /* !__ASSEMBLY__ */
  40. #endif