blob: bc7e8ae479ee4f7f9be717cbcd38d0731773a6f9 [file] [log] [blame]
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -07001/*
2 * Copyright (C) 2004-2006 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8#ifndef __ASM_AVR32_PGALLOC_H
9#define __ASM_AVR32_PGALLOC_H
10
Hans-Christian Egtvedt6cb8e872011-01-24 13:51:58 +010011#include <linux/mm.h>
Haavard Skinnemoen5a4d5292008-01-14 23:33:44 +010012#include <linux/quicklist.h>
13#include <asm/page.h>
14#include <asm/pgtable.h>
15
16#define QUICK_PGD 0 /* Preserve kernel mappings over free */
Haavard Skinnemoen38510752008-01-14 23:35:32 +010017#define QUICK_PT 1 /* Zero on free */
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070018
Haavard Skinnemoencfd23e92008-01-14 22:15:05 +010019static inline void pmd_populate_kernel(struct mm_struct *mm,
20 pmd_t *pmd, pte_t *pte)
21{
22 set_pmd(pmd, __pmd((unsigned long)pte));
23}
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070024
Haavard Skinnemoencfd23e92008-01-14 22:15:05 +010025static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080026 pgtable_t pte)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070027{
Haavard Skinnemoencfd23e92008-01-14 22:15:05 +010028 set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070029}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080030#define pmd_pgtable(pmd) pmd_page(pmd)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070031
Haavard Skinnemoen5a4d5292008-01-14 23:33:44 +010032static inline void pgd_ctor(void *x)
33{
34 pgd_t *pgd = x;
35
36 memcpy(pgd + USER_PTRS_PER_PGD,
37 swapper_pg_dir + USER_PTRS_PER_PGD,
38 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
39}
40
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070041/*
42 * Allocate and free page tables
43 */
Haavard Skinnemoencfd23e92008-01-14 22:15:05 +010044static inline pgd_t *pgd_alloc(struct mm_struct *mm)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070045{
Haavard Skinnemoen5a4d5292008-01-14 23:33:44 +010046 return quicklist_alloc(QUICK_PGD, GFP_KERNEL | __GFP_REPEAT, pgd_ctor);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070047}
48
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080049static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070050{
Haavard Skinnemoen5a4d5292008-01-14 23:33:44 +010051 quicklist_free(QUICK_PGD, NULL, pgd);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070052}
53
54static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
55 unsigned long address)
56{
Haavard Skinnemoen38510752008-01-14 23:35:32 +010057 return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070058}
59
Haavard Skinnemoen38510752008-01-14 23:35:32 +010060static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070061 unsigned long address)
62{
Haavard Skinnemoen38510752008-01-14 23:35:32 +010063 struct page *page;
64 void *pg;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070065
Haavard Skinnemoen38510752008-01-14 23:35:32 +010066 pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
67 if (!pg)
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080068 return NULL;
Haavard Skinnemoen38510752008-01-14 23:35:32 +010069
70 page = virt_to_page(pg);
71 pgtable_page_ctor(page);
72
73 return page;
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070074}
75
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080076static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070077{
Haavard Skinnemoen38510752008-01-14 23:35:32 +010078 quicklist_free(QUICK_PT, NULL, pte);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070079}
80
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080081static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070082{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080083 pgtable_page_dtor(pte);
Haavard Skinnemoen38510752008-01-14 23:35:32 +010084 quicklist_free_page(QUICK_PT, NULL, pte);
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070085}
86
Benjamin Herrenschmidt9e1b32c2009-07-22 15:44:28 +100087#define __pte_free_tlb(tlb,pte,addr) \
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080088do { \
89 pgtable_page_dtor(pte); \
90 tlb_remove_page((tlb), pte); \
91} while (0)
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070092
Haavard Skinnemoen5a4d5292008-01-14 23:33:44 +010093static inline void check_pgt_cache(void)
94{
95 quicklist_trim(QUICK_PGD, NULL, 25, 16);
Haavard Skinnemoen38510752008-01-14 23:35:32 +010096 quicklist_trim(QUICK_PT, NULL, 25, 16);
Haavard Skinnemoen5a4d5292008-01-14 23:33:44 +010097}
Haavard Skinnemoen5f97f7f2006-09-25 23:32:13 -070098
99#endif /* __ASM_AVR32_PGALLOC_H */