blob: f4c491044882886b5687af1d91f75ba548eaa61c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _ASM_IA64_PGALLOC_H
3#define _ASM_IA64_PGALLOC_H
4
5/*
6 * This file contains the functions and defines necessary to allocate
7 * page tables.
8 *
9 * This hopefully works with any (fixed) ia-64 page-size, as defined
10 * in <asm/page.h> (currently 8192).
11 *
12 * Copyright (C) 1998-2001 Hewlett-Packard Co
13 * David Mosberger-Tang <davidm@hpl.hp.com>
14 * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
15 */
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#include <linux/compiler.h>
19#include <linux/mm.h>
20#include <linux/page-flags.h>
21#include <linux/threads.h>
22
Mike Rapoport01319922019-09-23 15:35:22 -070023#include <asm-generic/pgalloc.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/mmu_context.h>
26
Robin Holtfde740e2005-04-25 13:13:16 -070027static inline pgd_t *pgd_alloc(struct mm_struct *mm)
28{
Nicholas Piggin13224792019-09-23 15:35:19 -070029 return (pgd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
Robin Holtfde740e2005-04-25 13:13:16 -070030}
31
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080032static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Robin Holtfde740e2005-04-25 13:13:16 -070033{
Nicholas Piggin13224792019-09-23 15:35:19 -070034 free_page((unsigned long)pgd);
Robin Holtfde740e2005-04-25 13:13:16 -070035}
36
Kirill A. Shutemov4d66bcc2015-04-14 15:45:45 -070037#if CONFIG_PGTABLE_LEVELS == 4
Robin Holt837cd0b2005-11-11 09:35:43 -060038static inline void
39pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
40{
41 pgd_val(*pgd_entry) = __pa(pud);
42}
43
44static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
45{
Nicholas Piggin13224792019-09-23 15:35:19 -070046 return (pud_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
Robin Holt837cd0b2005-11-11 09:35:43 -060047}
48
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080049static inline void pud_free(struct mm_struct *mm, pud_t *pud)
Robin Holt837cd0b2005-11-11 09:35:43 -060050{
Nicholas Piggin13224792019-09-23 15:35:19 -070051 free_page((unsigned long)pud);
Robin Holt837cd0b2005-11-11 09:35:43 -060052}
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100053#define __pud_free_tlb(tlb, pud, address) pud_free((tlb)->mm, pud)
Kirill A. Shutemov4d66bcc2015-04-14 15:45:45 -070054#endif /* CONFIG_PGTABLE_LEVELS == 4 */
Robin Holt837cd0b2005-11-11 09:35:43 -060055
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static inline void
Robin Holtfde740e2005-04-25 13:13:16 -070057pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 pud_val(*pud_entry) = __pa(pmd);
60}
61
Robin Holtfde740e2005-04-25 13:13:16 -070062static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Nicholas Piggin13224792019-09-23 15:35:19 -070064 return (pmd_t *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080067static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Nicholas Piggin13224792019-09-23 15:35:19 -070069 free_page((unsigned long)pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070}
71
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100072#define __pmd_free_tlb(tlb, pmd, address) pmd_free((tlb)->mm, pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74static inline void
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080075pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 pmd_val(*pmd_entry) = page_to_phys(pte);
78}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080079#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81static inline void
Robin Holtfde740e2005-04-25 13:13:16 -070082pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 pmd_val(*pmd_entry) = __pa(pte);
85}
86
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100087#define __pte_free_tlb(tlb, pte, address) pte_free((tlb)->mm, pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Robin Holtfde740e2005-04-25 13:13:16 -070089#endif /* _ASM_IA64_PGALLOC_H */