Linux Audio

Check our new training course

Embedded Linux training

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