hugetlbpage.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * IBM System z Huge TLB Page Support for Kernel.
  3. *
  4. * Copyright 2007 IBM Corp.
  5. * Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com>
  6. */
  7. #include <linux/mm.h>
  8. #include <linux/hugetlb.h>
  9. void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  10. pte_t *pteptr, pte_t pteval)
  11. {
  12. pmd_t *pmdp = (pmd_t *) pteptr;
  13. unsigned long mask;
  14. if (!MACHINE_HAS_HPAGE) {
  15. pteptr = (pte_t *) pte_page(pteval)[1].index;
  16. mask = pte_val(pteval) &
  17. (_SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO);
  18. pte_val(pteval) = (_SEGMENT_ENTRY + __pa(pteptr)) | mask;
  19. }
  20. pmd_val(*pmdp) = pte_val(pteval);
  21. }
  22. int arch_prepare_hugepage(struct page *page)
  23. {
  24. unsigned long addr = page_to_phys(page);
  25. pte_t pte;
  26. pte_t *ptep;
  27. int i;
  28. if (MACHINE_HAS_HPAGE)
  29. return 0;
  30. ptep = (pte_t *) pte_alloc_one(&init_mm, address);
  31. if (!ptep)
  32. return -ENOMEM;
  33. pte = mk_pte(page, PAGE_RW);
  34. for (i = 0; i < PTRS_PER_PTE; i++) {
  35. set_pte_at(&init_mm, addr + i * PAGE_SIZE, ptep + i, pte);
  36. pte_val(pte) += PAGE_SIZE;
  37. }
  38. page[1].index = (unsigned long) ptep;
  39. return 0;
  40. }
  41. void arch_release_hugepage(struct page *page)
  42. {
  43. pte_t *ptep;
  44. if (MACHINE_HAS_HPAGE)
  45. return;
  46. ptep = (pte_t *) page[1].index;
  47. if (!ptep)
  48. return;
  49. page_table_free(&init_mm, (unsigned long *) ptep);
  50. page[1].index = 0;
  51. }
  52. pte_t *huge_pte_alloc(struct mm_struct *mm,
  53. unsigned long addr, unsigned long sz)
  54. {
  55. pgd_t *pgdp;
  56. pud_t *pudp;
  57. pmd_t *pmdp = NULL;
  58. pgdp = pgd_offset(mm, addr);
  59. pudp = pud_alloc(mm, pgdp, addr);
  60. if (pudp)
  61. pmdp = pmd_alloc(mm, pudp, addr);
  62. return (pte_t *) pmdp;
  63. }
  64. pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
  65. {
  66. pgd_t *pgdp;
  67. pud_t *pudp;
  68. pmd_t *pmdp = NULL;
  69. pgdp = pgd_offset(mm, addr);
  70. if (pgd_present(*pgdp)) {
  71. pudp = pud_offset(pgdp, addr);
  72. if (pud_present(*pudp))
  73. pmdp = pmd_offset(pudp, addr);
  74. }
  75. return (pte_t *) pmdp;
  76. }
  77. int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
  78. {
  79. return 0;
  80. }
  81. struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
  82. int write)
  83. {
  84. return ERR_PTR(-EINVAL);
  85. }
  86. int pmd_huge(pmd_t pmd)
  87. {
  88. if (!MACHINE_HAS_HPAGE)
  89. return 0;
  90. return !!(pmd_val(pmd) & _SEGMENT_ENTRY_LARGE);
  91. }
  92. int pud_huge(pud_t pud)
  93. {
  94. return 0;
  95. }
  96. struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
  97. pmd_t *pmdp, int write)
  98. {
  99. struct page *page;
  100. if (!MACHINE_HAS_HPAGE)
  101. return NULL;
  102. page = pmd_page(*pmdp);
  103. if (page)
  104. page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
  105. return page;
  106. }