David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * MIPS Huge TLB Page Support for Kernel. |
| 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
| 8 | * Copyright (C) 2002, Rohit Seth <rohit.seth@intel.com> |
| 9 | * Copyright 2005, Embedded Alley Solutions, Inc. |
| 10 | * Matt Porter <mporter@embeddedalley.com> |
| 11 | * Copyright (C) 2008, 2009 Cavium Networks, Inc. |
| 12 | */ |
| 13 | |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 14 | #include <linux/fs.h> |
| 15 | #include <linux/mm.h> |
| 16 | #include <linux/hugetlb.h> |
| 17 | #include <linux/pagemap.h> |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 18 | #include <linux/err.h> |
| 19 | #include <linux/sysctl.h> |
| 20 | #include <asm/mman.h> |
| 21 | #include <asm/tlb.h> |
| 22 | #include <asm/tlbflush.h> |
| 23 | |
| 24 | pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, |
| 25 | unsigned long sz) |
| 26 | { |
| 27 | pgd_t *pgd; |
Mike Rapoport | 2bee1b5 | 2019-11-21 18:21:33 +0200 | [diff] [blame] | 28 | p4d_t *p4d; |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 29 | pud_t *pud; |
| 30 | pte_t *pte = NULL; |
| 31 | |
| 32 | pgd = pgd_offset(mm, addr); |
Mike Rapoport | 2bee1b5 | 2019-11-21 18:21:33 +0200 | [diff] [blame] | 33 | p4d = p4d_alloc(mm, pgd, addr); |
| 34 | pud = pud_alloc(mm, p4d, addr); |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 35 | if (pud) |
| 36 | pte = (pte_t *)pmd_alloc(mm, pud, addr); |
| 37 | |
| 38 | return pte; |
| 39 | } |
| 40 | |
Punit Agrawal | 7868a20 | 2017-07-06 15:39:42 -0700 | [diff] [blame] | 41 | pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, |
| 42 | unsigned long sz) |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 43 | { |
| 44 | pgd_t *pgd; |
Mike Rapoport | 2bee1b5 | 2019-11-21 18:21:33 +0200 | [diff] [blame] | 45 | p4d_t *p4d; |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 46 | pud_t *pud; |
| 47 | pmd_t *pmd = NULL; |
| 48 | |
| 49 | pgd = pgd_offset(mm, addr); |
| 50 | if (pgd_present(*pgd)) { |
Mike Rapoport | 2bee1b5 | 2019-11-21 18:21:33 +0200 | [diff] [blame] | 51 | p4d = p4d_offset(pgd, addr); |
| 52 | if (p4d_present(*p4d)) { |
| 53 | pud = pud_offset(p4d, addr); |
| 54 | if (pud_present(*pud)) |
| 55 | pmd = pmd_offset(pud, addr); |
| 56 | } |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 57 | } |
| 58 | return (pte_t *) pmd; |
| 59 | } |
| 60 | |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 61 | /* |
| 62 | * This function checks for proper alignment of input addr and len parameters. |
| 63 | */ |
| 64 | int is_aligned_hugepage_range(unsigned long addr, unsigned long len) |
| 65 | { |
| 66 | if (len & ~HPAGE_MASK) |
| 67 | return -EINVAL; |
| 68 | if (addr & ~HPAGE_MASK) |
| 69 | return -EINVAL; |
| 70 | return 0; |
| 71 | } |
| 72 | |
David Daney | 50a41ff | 2009-05-27 17:47:42 -0700 | [diff] [blame] | 73 | int pmd_huge(pmd_t pmd) |
| 74 | { |
| 75 | return (pmd_val(pmd) & _PAGE_HUGE) != 0; |
| 76 | } |
| 77 | |
| 78 | int pud_huge(pud_t pud) |
| 79 | { |
| 80 | return (pud_val(pud) & _PAGE_HUGE) != 0; |
| 81 | } |