blob: e9c39352cee11f90450e4f48d095efbd32158ac3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Russell King4baa9922008-08-02 10:55:55 +01002 * arch/arm/include/asm/pgalloc.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 2000-2001 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef _ASMARM_PGALLOC_H
11#define _ASMARM_PGALLOC_H
12
Russell King74945c82006-03-16 14:44:36 +000013#include <asm/domain.h>
14#include <asm/pgtable-hwdef.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/processor.h>
16#include <asm/cacheflush.h>
17#include <asm/tlbflush.h>
18
Russell King002547b2006-06-20 20:46:52 +010019#define check_pgt_cache() do { } while (0)
20
21#ifdef CONFIG_MMU
22
Russell King74945c82006-03-16 14:44:36 +000023#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
24#define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/*
27 * Since we have only two-level page tables, these are trivial
28 */
29#define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080030#define pmd_free(mm, pmd) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define pgd_populate(mm,pmd,pte) BUG()
32
Russell Kingb0d03742010-11-21 11:00:56 +000033extern pgd_t *pgd_alloc(struct mm_struct *mm);
34extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Russell King65cec8e2009-08-17 20:02:06 +010036#define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * Allocate one PTE table.
40 *
41 * This actually allocates two hardware PTE tables, but we wrap this up
42 * into one table thus:
43 *
44 * +------------+
45 * | h/w pt 0 |
46 * +------------+
47 * | h/w pt 1 |
48 * +------------+
49 * | Linux pt 0 |
50 * +------------+
51 * | Linux pt 1 |
52 * +------------+
53 */
54static inline pte_t *
55pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
56{
57 pte_t *pte;
58
Russell King65cec8e2009-08-17 20:02:06 +010059 pte = (pte_t *)__get_free_page(PGALLOC_GFP);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 if (pte) {
61 clean_dcache_area(pte, sizeof(pte_t) * PTRS_PER_PTE);
62 pte += PTRS_PER_PTE;
63 }
64
65 return pte;
66}
67
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080068static inline pgtable_t
Linus Torvalds1da177e2005-04-16 15:20:36 -070069pte_alloc_one(struct mm_struct *mm, unsigned long addr)
70{
71 struct page *pte;
72
Russell King65cec8e2009-08-17 20:02:06 +010073#ifdef CONFIG_HIGHPTE
74 pte = alloc_pages(PGALLOC_GFP | __GFP_HIGHMEM, 0);
75#else
76 pte = alloc_pages(PGALLOC_GFP, 0);
77#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (pte) {
Russell King65cec8e2009-08-17 20:02:06 +010079 if (!PageHighMem(pte)) {
80 void *page = page_address(pte);
81 clean_dcache_area(page, sizeof(pte_t) * PTRS_PER_PTE);
82 }
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080083 pgtable_page_ctor(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85
86 return pte;
87}
88
89/*
90 * Free one PTE table.
91 */
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080092static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
94 if (pte) {
95 pte -= PTRS_PER_PTE;
96 free_page((unsigned long)pte);
97 }
98}
99
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800100static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800102 pgtable_page_dtor(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 __free_page(pte);
104}
105
Russell Kingbdf04242005-06-22 20:58:29 +0100106static inline void __pmd_populate(pmd_t *pmdp, unsigned long pmdval)
107{
108 pmdp[0] = __pmd(pmdval);
109 pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
110 flush_pmd_entry(pmdp);
111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*
114 * Populate the pmdp entry with a pointer to the pte. This pmd is part
115 * of the mm address space.
116 *
117 * Ensure that we always set both PMD entries.
118 */
119static inline void
120pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
121{
122 unsigned long pte_ptr = (unsigned long)ptep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /*
125 * The pmd must be loaded with the physical
126 * address of the PTE table
127 */
128 pte_ptr -= PTRS_PER_PTE * sizeof(void *);
Russell Kingbdf04242005-06-22 20:58:29 +0100129 __pmd_populate(pmdp, __pa(pte_ptr) | _PAGE_KERNEL_TABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130}
131
132static inline void
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800133pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Russell Kingbdf04242005-06-22 20:58:29 +0100135 __pmd_populate(pmdp, page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800137#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Russell King002547b2006-06-20 20:46:52 +0100139#endif /* CONFIG_MMU */
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif