hugetlbpage-radix.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/mm.h>
  3. #include <linux/hugetlb.h>
  4. #include <asm/pgtable.h>
  5. #include <asm/pgalloc.h>
  6. #include <asm/cacheflush.h>
  7. #include <asm/machdep.h>
  8. #include <asm/mman.h>
  9. #include <asm/tlb.h>
  10. void radix__flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  11. {
  12. int psize;
  13. struct hstate *hstate = hstate_file(vma->vm_file);
  14. psize = hstate_get_psize(hstate);
  15. radix__flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
  16. }
  17. void radix__local_flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  18. {
  19. int psize;
  20. struct hstate *hstate = hstate_file(vma->vm_file);
  21. psize = hstate_get_psize(hstate);
  22. radix__local_flush_tlb_page_psize(vma->vm_mm, vmaddr, psize);
  23. }
  24. void radix__flush_hugetlb_tlb_range(struct vm_area_struct *vma, unsigned long start,
  25. unsigned long end)
  26. {
  27. int psize;
  28. struct hstate *hstate = hstate_file(vma->vm_file);
  29. psize = hstate_get_psize(hstate);
  30. radix__flush_tlb_range_psize(vma->vm_mm, start, end, psize);
  31. }
  32. /*
  33. * A vairant of hugetlb_get_unmapped_area doing topdown search
  34. * FIXME!! should we do as x86 does or non hugetlb area does ?
  35. * ie, use topdown or not based on mmap_is_legacy check ?
  36. */
  37. unsigned long
  38. radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
  39. unsigned long len, unsigned long pgoff,
  40. unsigned long flags)
  41. {
  42. struct mm_struct *mm = current->mm;
  43. struct vm_area_struct *vma;
  44. struct hstate *h = hstate_file(file);
  45. int fixed = (flags & MAP_FIXED);
  46. unsigned long high_limit;
  47. struct vm_unmapped_area_info info;
  48. high_limit = DEFAULT_MAP_WINDOW;
  49. if (addr >= high_limit || (fixed && (addr + len > high_limit)))
  50. high_limit = TASK_SIZE;
  51. if (len & ~huge_page_mask(h))
  52. return -EINVAL;
  53. if (len > high_limit)
  54. return -ENOMEM;
  55. if (fixed) {
  56. if (addr > high_limit - len)
  57. return -ENOMEM;
  58. if (prepare_hugepage_range(file, addr, len))
  59. return -EINVAL;
  60. return addr;
  61. }
  62. if (addr) {
  63. addr = ALIGN(addr, huge_page_size(h));
  64. vma = find_vma(mm, addr);
  65. if (high_limit - len >= addr &&
  66. (!vma || addr + len <= vm_start_gap(vma)))
  67. return addr;
  68. }
  69. /*
  70. * We are always doing an topdown search here. Slice code
  71. * does that too.
  72. */
  73. info.flags = VM_UNMAPPED_AREA_TOPDOWN;
  74. info.length = len;
  75. info.low_limit = PAGE_SIZE;
  76. info.high_limit = mm->mmap_base + (high_limit - DEFAULT_MAP_WINDOW);
  77. info.align_mask = PAGE_MASK & ~huge_page_mask(h);
  78. info.align_offset = 0;
  79. return vm_unmapped_area(&info);
  80. }