blob: b9ac1a6fc21694a55e2771e471ab8cc90ab997cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ASM_IA64_PGALLOC_H
2#define _ASM_IA64_PGALLOC_H
3
4/*
5 * This file contains the functions and defines necessary to allocate
6 * page tables.
7 *
8 * This hopefully works with any (fixed) ia-64 page-size, as defined
9 * in <asm/page.h> (currently 8192).
10 *
11 * Copyright (C) 1998-2001 Hewlett-Packard Co
12 * David Mosberger-Tang <davidm@hpl.hp.com>
13 * Copyright (C) 2000, Goutham Rao <goutham.rao@intel.com>
14 */
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include <linux/compiler.h>
18#include <linux/mm.h>
19#include <linux/page-flags.h>
20#include <linux/threads.h>
Christoph Lameter2bd62a42007-05-10 22:42:53 -070021#include <linux/quicklist.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include <asm/mmu_context.h>
24
Robin Holtfde740e2005-04-25 13:13:16 -070025static inline pgd_t *pgd_alloc(struct mm_struct *mm)
26{
Christoph Lameter2bd62a42007-05-10 22:42:53 -070027 return quicklist_alloc(0, GFP_KERNEL, NULL);
Robin Holtfde740e2005-04-25 13:13:16 -070028}
29
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080030static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Robin Holtfde740e2005-04-25 13:13:16 -070031{
Christoph Lameter2bd62a42007-05-10 22:42:53 -070032 quicklist_free(0, NULL, pgd);
Robin Holtfde740e2005-04-25 13:13:16 -070033}
34
Robin Holt837cd0b2005-11-11 09:35:43 -060035#ifdef CONFIG_PGTABLE_4
36static inline void
37pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
38{
39 pgd_val(*pgd_entry) = __pa(pud);
40}
41
42static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
43{
Christoph Lameter2bd62a42007-05-10 22:42:53 -070044 return quicklist_alloc(0, GFP_KERNEL, NULL);
Robin Holt837cd0b2005-11-11 09:35:43 -060045}
46
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080047static inline void pud_free(struct mm_struct *mm, pud_t *pud)
Robin Holt837cd0b2005-11-11 09:35:43 -060048{
Christoph Lameter2bd62a42007-05-10 22:42:53 -070049 quicklist_free(0, NULL, pud);
Robin Holt837cd0b2005-11-11 09:35:43 -060050}
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080051#define __pud_free_tlb(tlb, pud) pud_free((tlb)->mm, pud)
Robin Holt837cd0b2005-11-11 09:35:43 -060052#endif /* CONFIG_PGTABLE_4 */
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054static inline void
Robin Holtfde740e2005-04-25 13:13:16 -070055pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 pud_val(*pud_entry) = __pa(pmd);
58}
59
Robin Holtfde740e2005-04-25 13:13:16 -070060static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Christoph Lameter2bd62a42007-05-10 22:42:53 -070062 return quicklist_alloc(0, GFP_KERNEL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080065static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Christoph Lameter2bd62a42007-05-10 22:42:53 -070067 quicklist_free(0, NULL, pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080070#define __pmd_free_tlb(tlb, pmd) pmd_free((tlb)->mm, pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72static inline void
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080073pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
75 pmd_val(*pmd_entry) = page_to_phys(pte);
76}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080077#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79static inline void
Robin Holtfde740e2005-04-25 13:13:16 -070080pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 pmd_val(*pmd_entry) = __pa(pte);
83}
84
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080085static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080087 struct page *page;
88 void *pg;
89
90 pg = quicklist_alloc(0, GFP_KERNEL, NULL);
91 if (!pg)
92 return NULL;
93 page = virt_to_page(pg);
94 pgtable_page_ctor(page);
95 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
Robin Holtfde740e2005-04-25 13:13:16 -070098static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
99 unsigned long addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
Christoph Lameter2bd62a42007-05-10 22:42:53 -0700101 return quicklist_alloc(0, GFP_KERNEL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800104static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800106 pgtable_page_dtor(pte);
Christoph Lameter2bd62a42007-05-10 22:42:53 -0700107 quicklist_free_page(0, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108}
109
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -0800110static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
Christoph Lameter2bd62a42007-05-10 22:42:53 -0700112 quicklist_free(0, NULL, pte);
113}
114
115static inline void check_pgt_cache(void)
116{
117 quicklist_trim(0, NULL, 25, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -0800120#define __pte_free_tlb(tlb, pte) pte_free((tlb)->mm, pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Robin Holtfde740e2005-04-25 13:13:16 -0700122#endif /* _ASM_IA64_PGALLOC_H */