blob: 24bcba496c7505e94d5c45512c399e773106b029 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _MOTOROLA_PGALLOC_H
2#define _MOTOROLA_PGALLOC_H
3
4#include <asm/tlb.h>
5#include <asm/tlbflush.h>
6
7extern pmd_t *get_pointer_table(void);
8extern int free_pointer_table(pmd_t *);
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
11{
12 pte_t *pte;
13
14 pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
15 if (pte) {
16 __flush_page_to_ram(pte);
17 flush_tlb_kernel_page(pte);
18 nocache_page(pte);
19 }
20
21 return pte;
22}
23
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080024static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
26 cache_page(pte);
27 free_page((unsigned long) pte);
28}
29
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080030static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Kirill A. Shutemovf84c9142013-11-14 14:31:34 -080032 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 pte_t *pte;
34
Kirill A. Shutemovf84c9142013-11-14 14:31:34 -080035 page = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 if(!page)
37 return NULL;
Kirill A. Shutemovf84c9142013-11-14 14:31:34 -080038 if (!pgtable_page_ctor(page)) {
39 __free_page(page);
40 return NULL;
41 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43 pte = kmap(page);
Andrew Mortondc71c7d2009-06-17 13:13:58 -070044 __flush_page_to_ram(pte);
45 flush_tlb_kernel_page(pte);
46 nocache_page(pte);
47 kunmap(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return page;
49}
50
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080051static inline void pte_free(struct mm_struct *mm, pgtable_t page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080053 pgtable_page_dtor(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 cache_page(kmap(page));
55 kunmap(page);
56 __free_page(page);
57}
58
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100059static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t page,
60 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080062 pgtable_page_dtor(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 cache_page(kmap(page));
64 kunmap(page);
65 __free_page(page);
66}
67
68
69static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
70{
71 return get_pointer_table();
72}
73
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080074static inline int pmd_free(struct mm_struct *mm, pmd_t *pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 return free_pointer_table(pmd);
77}
78
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100079static inline int __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
80 unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
82 return free_pointer_table(pmd);
83}
84
85
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080086static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080088 pmd_free(mm, (pmd_t *)pgd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
91static inline pgd_t *pgd_alloc(struct mm_struct *mm)
92{
93 return (pgd_t *)get_pointer_table();
94}
95
96
97static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
98{
99 pmd_set(pmd, pte);
100}
101
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800102static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 pmd_set(pmd, page_address(page));
105}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800106#define pmd_pgtable(pmd) pmd_page(pmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
109{
110 pgd_set(pgd, pmd);
111}
112
113#endif /* _MOTOROLA_PGALLOC_H */