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 | |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/fs.h> |
| 16 | #include <linux/mm.h> |
| 17 | #include <linux/hugetlb.h> |
| 18 | #include <linux/pagemap.h> |
| 19 | #include <linux/smp_lock.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/sysctl.h> |
| 23 | #include <asm/mman.h> |
| 24 | #include <asm/tlb.h> |
| 25 | #include <asm/tlbflush.h> |
| 26 | |
| 27 | pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr, |
| 28 | unsigned long sz) |
| 29 | { |
| 30 | pgd_t *pgd; |
| 31 | pud_t *pud; |
| 32 | pte_t *pte = NULL; |
| 33 | |
| 34 | pgd = pgd_offset(mm, addr); |
| 35 | pud = pud_alloc(mm, pgd, addr); |
| 36 | if (pud) |
| 37 | pte = (pte_t *)pmd_alloc(mm, pud, addr); |
| 38 | |
| 39 | return pte; |
| 40 | } |
| 41 | |
| 42 | pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr) |
| 43 | { |
| 44 | pgd_t *pgd; |
| 45 | pud_t *pud; |
| 46 | pmd_t *pmd = NULL; |
| 47 | |
| 48 | pgd = pgd_offset(mm, addr); |
| 49 | if (pgd_present(*pgd)) { |
| 50 | pud = pud_offset(pgd, addr); |
| 51 | if (pud_present(*pud)) |
| 52 | pmd = pmd_offset(pud, addr); |
| 53 | } |
| 54 | return (pte_t *) pmd; |
| 55 | } |
| 56 | |
| 57 | int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep) |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * This function checks for proper alignment of input addr and len parameters. |
| 64 | */ |
| 65 | int is_aligned_hugepage_range(unsigned long addr, unsigned long len) |
| 66 | { |
| 67 | if (len & ~HPAGE_MASK) |
| 68 | return -EINVAL; |
| 69 | if (addr & ~HPAGE_MASK) |
| 70 | return -EINVAL; |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | struct page * |
| 75 | follow_huge_addr(struct mm_struct *mm, unsigned long address, int write) |
| 76 | { |
| 77 | return ERR_PTR(-EINVAL); |
| 78 | } |
| 79 | |
| 80 | int pmd_huge(pmd_t pmd) |
| 81 | { |
| 82 | return (pmd_val(pmd) & _PAGE_HUGE) != 0; |
| 83 | } |
| 84 | |
| 85 | int pud_huge(pud_t pud) |
| 86 | { |
| 87 | return (pud_val(pud) & _PAGE_HUGE) != 0; |
| 88 | } |
| 89 | |
| 90 | struct page * |
| 91 | follow_huge_pmd(struct mm_struct *mm, unsigned long address, |
| 92 | pmd_t *pmd, int write) |
| 93 | { |
| 94 | struct page *page; |
| 95 | |
| 96 | page = pte_page(*(pte_t *)pmd); |
| 97 | if (page) |
| 98 | page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT); |
| 99 | return page; |
| 100 | } |
| 101 | |