4 * Linux architectural port borrowing liberally from similar works of
5 * others. All original copyrights apply as per the original source
8 * OpenRISC implementation:
9 * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
10 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
19 #ifndef __ASM_OPENRISC_PGALLOC_H
20 #define __ASM_OPENRISC_PGALLOC_H
23 #include <linux/threads.h>
25 #include <linux/memblock.h>
27 extern int mem_init_done
;
29 #define pmd_populate_kernel(mm, pmd, pte) \
30 set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte)))
32 static inline void pmd_populate(struct mm_struct
*mm
, pmd_t
*pmd
,
35 set_pmd(pmd
, __pmd(_KERNPG_TABLE
+
36 ((unsigned long)page_to_pfn(pte
) <<
37 (unsigned long) PAGE_SHIFT
)));
41 * Allocate and free page tables.
43 static inline pgd_t
*pgd_alloc(struct mm_struct
*mm
)
45 pgd_t
*ret
= (pgd_t
*)__get_free_page(GFP_KERNEL
);
48 memset(ret
, 0, USER_PTRS_PER_PGD
* sizeof(pgd_t
));
49 memcpy(ret
+ USER_PTRS_PER_PGD
,
50 swapper_pg_dir
+ USER_PTRS_PER_PGD
,
51 (PTRS_PER_PGD
- USER_PTRS_PER_PGD
) * sizeof(pgd_t
));
58 /* FIXME: This seems to be the preferred style, but we are using
59 * current_pgd (from mm->pgd) to load kernel pages so we need it
60 * initialized. This needs to be looked into.
62 extern inline pgd_t
*pgd_alloc(struct mm_struct
*mm
)
64 return (pgd_t
*)get_zeroed_page(GFP_KERNEL
);
68 static inline void pgd_free(struct mm_struct
*mm
, pgd_t
*pgd
)
70 free_page((unsigned long)pgd
);
73 extern pte_t
*pte_alloc_one_kernel(struct mm_struct
*mm
, unsigned long address
);
75 static inline struct page
*pte_alloc_one(struct mm_struct
*mm
,
76 unsigned long address
)
79 pte
= alloc_pages(GFP_KERNEL
, 0);
82 clear_page(page_address(pte
));
83 if (!pgtable_page_ctor(pte
)) {
90 static inline void pte_free_kernel(struct mm_struct
*mm
, pte_t
*pte
)
92 free_page((unsigned long)pte
);
95 static inline void pte_free(struct mm_struct
*mm
, struct page
*pte
)
97 pgtable_page_dtor(pte
);
101 #define __pte_free_tlb(tlb, pte, addr) \
103 pgtable_page_dtor(pte); \
104 tlb_remove_page((tlb), (pte)); \
107 #define pmd_pgtable(pmd) pmd_page(pmd)
109 #define check_pgt_cache() do { } while (0)