Jonas Bonn | 61e85e3 | 2011-06-04 11:06:11 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OpenRISC Linux |
| 3 | * |
| 4 | * Linux architectural port borrowing liberally from similar works of |
| 5 | * others. All original copyrights apply as per the original source |
| 6 | * declaration. |
| 7 | * |
| 8 | * OpenRISC implementation: |
| 9 | * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com> |
| 10 | * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se> |
| 11 | * et al. |
| 12 | * |
| 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. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __ASM_OPENRISC_PGALLOC_H |
| 20 | #define __ASM_OPENRISC_PGALLOC_H |
| 21 | |
| 22 | #include <asm/page.h> |
| 23 | #include <linux/threads.h> |
| 24 | #include <linux/mm.h> |
| 25 | #include <linux/memblock.h> |
| 26 | #include <linux/bootmem.h> |
| 27 | |
| 28 | extern int mem_init_done; |
| 29 | |
| 30 | #define pmd_populate_kernel(mm, pmd, pte) \ |
| 31 | set_pmd(pmd, __pmd(_KERNPG_TABLE + __pa(pte))) |
| 32 | |
| 33 | static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, |
| 34 | struct page *pte) |
| 35 | { |
| 36 | set_pmd(pmd, __pmd(_KERNPG_TABLE + |
| 37 | ((unsigned long)page_to_pfn(pte) << |
| 38 | (unsigned long) PAGE_SHIFT))); |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * Allocate and free page tables. |
| 43 | */ |
| 44 | static inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 45 | { |
| 46 | pgd_t *ret = (pgd_t *)__get_free_page(GFP_KERNEL); |
| 47 | |
| 48 | if (ret) { |
| 49 | memset(ret, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); |
| 50 | memcpy(ret + USER_PTRS_PER_PGD, |
| 51 | swapper_pg_dir + USER_PTRS_PER_PGD, |
| 52 | (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); |
| 53 | |
| 54 | } |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | #if 0 |
| 59 | /* FIXME: This seems to be the preferred style, but we are using |
| 60 | * current_pgd (from mm->pgd) to load kernel pages so we need it |
| 61 | * initialized. This needs to be looked into. |
| 62 | */ |
| 63 | extern inline pgd_t *pgd_alloc(struct mm_struct *mm) |
| 64 | { |
| 65 | return (pgd_t *)get_zeroed_page(GFP_KERNEL); |
| 66 | } |
| 67 | #endif |
| 68 | |
| 69 | static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) |
| 70 | { |
| 71 | free_page((unsigned long)pgd); |
| 72 | } |
| 73 | |
| 74 | extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address); |
| 75 | |
| 76 | static inline struct page *pte_alloc_one(struct mm_struct *mm, |
| 77 | unsigned long address) |
| 78 | { |
| 79 | struct page *pte; |
| 80 | pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0); |
| 81 | if (pte) |
| 82 | clear_page(page_address(pte)); |
| 83 | return pte; |
| 84 | } |
| 85 | |
| 86 | static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) |
| 87 | { |
| 88 | free_page((unsigned long)pte); |
| 89 | } |
| 90 | |
| 91 | static inline void pte_free(struct mm_struct *mm, struct page *pte) |
| 92 | { |
| 93 | __free_page(pte); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | #define __pte_free_tlb(tlb, pte, addr) tlb_remove_page((tlb), (pte)) |
| 98 | #define pmd_pgtable(pmd) pmd_page(pmd) |
| 99 | |
| 100 | #define check_pgt_cache() do { } while (0) |
| 101 | |
| 102 | #endif |