blob: 6eccab770a6d9a05582041c782bc365a5b8bdb39 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SH64_PGALLOC_H
2#define __ASM_SH64_PGALLOC_H
3
4/*
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 *
9 * include/asm-sh64/pgalloc.h
10 *
11 * Copyright (C) 2000, 2001 Paolo Alberelli
12 * Copyright (C) 2003, 2004 Paul Mundt
13 * Copyright (C) 2003, 2004 Richard Curnow
14 *
15 */
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/mm.h>
Paul Mundt6c645ac2007-05-14 09:55:35 +090018#include <linux/quicklist.h>
19#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21static inline void pgd_init(unsigned long page)
22{
23 unsigned long *pgd = (unsigned long *)page;
24 extern pte_t empty_bad_pte_table[PTRS_PER_PTE];
25 int i;
26
27 for (i = 0; i < USER_PTRS_PER_PGD; i++)
28 pgd[i] = (unsigned long)empty_bad_pte_table;
29}
30
31/*
32 * Allocate and free page tables. The xxx_kernel() versions are
33 * used to allocate a kernel page table - this turns on ASN bits
34 * if any.
35 */
36
Adrian Bunkca5ed2f2006-01-09 20:54:47 -080037static inline pgd_t *get_pgd_slow(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 unsigned int pgd_size = (USER_PTRS_PER_PGD * sizeof(pgd_t));
Robert P. J. Day5cbded52006-12-13 00:35:56 -080040 pgd_t *ret = kmalloc(pgd_size, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 return ret;
42}
43
Paul Mundt6c645ac2007-05-14 09:55:35 +090044static inline pgd_t *pgd_alloc(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Paul Mundt6c645ac2007-05-14 09:55:35 +090046 return quicklist_alloc(0, GFP_KERNEL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
Paul Mundt6c645ac2007-05-14 09:55:35 +090049static inline void pgd_free(pgd_t *pgd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Paul Mundt6c645ac2007-05-14 09:55:35 +090051 quicklist_free(0, NULL, pgd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Paul Mundt6c645ac2007-05-14 09:55:35 +090054static inline struct page *pte_alloc_one(struct mm_struct *mm,
55 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Paul Mundt6c645ac2007-05-14 09:55:35 +090057 void *pg = quicklist_alloc(0, GFP_KERNEL, NULL);
58 return pg ? virt_to_page(pg) : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61static inline void pte_free_kernel(pte_t *pte)
62{
Paul Mundt6c645ac2007-05-14 09:55:35 +090063 quicklist_free(0, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
66static inline void pte_free(struct page *pte)
67{
Paul Mundt6c645ac2007-05-14 09:55:35 +090068 quicklist_free_page(0, NULL, pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
72 unsigned long address)
73{
Paul Mundt6c645ac2007-05-14 09:55:35 +090074 return quicklist_alloc(0, GFP_KERNEL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
78
79/*
80 * allocating and freeing a pmd is trivial: the 1-entry pmd is
81 * inside the pgd, so has no extra memory associated with it.
82 */
83
84#if defined(CONFIG_SH64_PGTABLE_2_LEVEL)
85
86#define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
87#define pmd_free(x) do { } while (0)
88#define pgd_populate(mm, pmd, pte) BUG()
89#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
90#define __pmd_free_tlb(tlb,pmd) do { } while (0)
91
92#elif defined(CONFIG_SH64_PGTABLE_3_LEVEL)
93
Paul Mundt6c645ac2007-05-14 09:55:35 +090094static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Paul Mundt6c645ac2007-05-14 09:55:35 +090096 return quicklist_alloc(0, GFP_KERNEL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Paul Mundt6c645ac2007-05-14 09:55:35 +090099static inline void pmd_free(pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
Paul Mundt6c645ac2007-05-14 09:55:35 +0900101 quicklist_free(0, NULL, pmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
Paul Mundt6c645ac2007-05-14 09:55:35 +0900104#define pgd_populate(mm, pgd, pmd) pgd_set(pgd, pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#define __pmd_free_tlb(tlb,pmd) pmd_free(pmd)
106
107#else
108#error "No defined page table size"
109#endif
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define pmd_populate_kernel(mm, pmd, pte) \
112 set_pmd(pmd, __pmd(_PAGE_TABLE + (unsigned long) (pte)))
113
114static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
115 struct page *pte)
116{
117 set_pmd(pmd, __pmd(_PAGE_TABLE + (unsigned long) page_address (pte)));
118}
119
Paul Mundt6c645ac2007-05-14 09:55:35 +0900120static inline void check_pgt_cache(void)
121{
122 quicklist_trim(0, NULL, 25, 16);
123}
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif /* __ASM_SH64_PGALLOC_H */