pgtable-2level.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef _ASM_X86_PGTABLE_2LEVEL_H
  2. #define _ASM_X86_PGTABLE_2LEVEL_H
  3. #define pte_ERROR(e) \
  4. pr_err("%s:%d: bad pte %08lx\n", __FILE__, __LINE__, (e).pte_low)
  5. #define pgd_ERROR(e) \
  6. pr_err("%s:%d: bad pgd %08lx\n", __FILE__, __LINE__, pgd_val(e))
  7. /*
  8. * Certain architectures need to do special things when PTEs
  9. * within a page table are directly modified. Thus, the following
  10. * hook is made available.
  11. */
  12. static inline void native_set_pte(pte_t *ptep , pte_t pte)
  13. {
  14. *ptep = pte;
  15. }
  16. static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
  17. {
  18. *pmdp = pmd;
  19. }
  20. static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
  21. {
  22. native_set_pte(ptep, pte);
  23. }
  24. static inline void native_pmd_clear(pmd_t *pmdp)
  25. {
  26. native_set_pmd(pmdp, __pmd(0));
  27. }
  28. static inline void native_pte_clear(struct mm_struct *mm,
  29. unsigned long addr, pte_t *xp)
  30. {
  31. *xp = native_make_pte(0);
  32. }
  33. #ifdef CONFIG_SMP
  34. static inline pte_t native_ptep_get_and_clear(pte_t *xp)
  35. {
  36. return __pte(xchg(&xp->pte_low, 0));
  37. }
  38. #else
  39. #define native_ptep_get_and_clear(xp) native_local_ptep_get_and_clear(xp)
  40. #endif
  41. #ifdef CONFIG_SMP
  42. static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
  43. {
  44. return __pmd(xchg((pmdval_t *)xp, 0));
  45. }
  46. #else
  47. #define native_pmdp_get_and_clear(xp) native_local_pmdp_get_and_clear(xp)
  48. #endif
  49. /* Bit manipulation helper on pte/pgoff entry */
  50. static inline unsigned long pte_bitop(unsigned long value, unsigned int rightshift,
  51. unsigned long mask, unsigned int leftshift)
  52. {
  53. return ((value >> rightshift) & mask) << leftshift;
  54. }
  55. /* Encode and de-code a swap entry */
  56. #define SWP_TYPE_BITS 5
  57. #define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1)
  58. #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
  59. #define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \
  60. & ((1U << SWP_TYPE_BITS) - 1))
  61. #define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT)
  62. #define __swp_entry(type, offset) ((swp_entry_t) { \
  63. ((type) << (_PAGE_BIT_PRESENT + 1)) \
  64. | ((offset) << SWP_OFFSET_SHIFT) })
  65. #define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low })
  66. #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
  67. #endif /* _ASM_X86_PGTABLE_2LEVEL_H */