Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 1 | /* |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 2 | * include/asm-xtensa/pgalloc.h |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 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 | * |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 8 | * Copyright (C) 2001-2007 Tensilica Inc. |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #ifndef _XTENSA_PGALLOC_H |
| 12 | #define _XTENSA_PGALLOC_H |
| 13 | |
| 14 | #ifdef __KERNEL__ |
| 15 | |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 16 | #include <linux/highmem.h> |
Chris Zankel | 4573e39 | 2010-05-02 01:05:13 -0700 | [diff] [blame] | 17 | #include <linux/slab.h> |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Allocating and freeing a pmd is trivial: the 1-entry pmd is |
| 21 | * inside the pgd, so has no extra memory associated with it. |
| 22 | */ |
| 23 | |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 24 | #define pmd_populate_kernel(mm, pmdp, ptep) \ |
| 25 | (pmd_val(*(pmdp)) = ((unsigned long)ptep)) |
| 26 | #define pmd_populate(mm, pmdp, page) \ |
| 27 | (pmd_val(*(pmdp)) = ((unsigned long)page_to_virt(page))) |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 28 | #define pmd_pgtable(pmd) pmd_page(pmd) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 29 | |
| 30 | static inline pgd_t* |
| 31 | pgd_alloc(struct mm_struct *mm) |
| 32 | { |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 33 | return (pgd_t*) __get_free_pages(GFP_KERNEL | __GFP_ZERO, PGD_ORDER); |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 36 | static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 37 | { |
| 38 | free_page((unsigned long)pgd); |
| 39 | } |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 40 | |
Chris Zankel | c4c4594 | 2012-11-28 16:53:51 -0800 | [diff] [blame] | 41 | static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 42 | unsigned long address) |
| 43 | { |
Kirill A. Shutemov | f820e28 | 2013-11-14 14:31:50 -0800 | [diff] [blame] | 44 | pte_t *ptep; |
| 45 | int i; |
| 46 | |
Michal Hocko | 32d6bd9 | 2016-06-24 14:48:47 -0700 | [diff] [blame] | 47 | ptep = (pte_t *)__get_free_page(GFP_KERNEL); |
Kirill A. Shutemov | f820e28 | 2013-11-14 14:31:50 -0800 | [diff] [blame] | 48 | if (!ptep) |
| 49 | return NULL; |
| 50 | for (i = 0; i < 1024; i++) |
| 51 | pte_clear(NULL, 0, ptep + i); |
| 52 | return ptep; |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Chris Zankel | e584d85 | 2008-02-13 16:25:09 -0800 | [diff] [blame] | 55 | static inline pgtable_t pte_alloc_one(struct mm_struct *mm, |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 56 | unsigned long addr) |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 57 | { |
Kirill A. Shutemov | f8c6d30 | 2013-11-14 14:31:19 -0800 | [diff] [blame] | 58 | pte_t *pte; |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 59 | struct page *page; |
| 60 | |
Kirill A. Shutemov | f8c6d30 | 2013-11-14 14:31:19 -0800 | [diff] [blame] | 61 | pte = pte_alloc_one_kernel(mm, addr); |
| 62 | if (!pte) |
| 63 | return NULL; |
| 64 | page = virt_to_page(pte); |
Kirill A. Shutemov | 8f43123 | 2013-11-14 14:31:48 -0800 | [diff] [blame] | 65 | if (!pgtable_page_ctor(page)) { |
Kirill A. Shutemov | f820e28 | 2013-11-14 14:31:50 -0800 | [diff] [blame] | 66 | __free_page(page); |
Kirill A. Shutemov | 8f43123 | 2013-11-14 14:31:48 -0800 | [diff] [blame] | 67 | return NULL; |
| 68 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 69 | return page; |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Benjamin Herrenschmidt | 5e54197 | 2008-02-04 22:29:14 -0800 | [diff] [blame] | 72 | static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 73 | { |
Kirill A. Shutemov | f820e28 | 2013-11-14 14:31:50 -0800 | [diff] [blame] | 74 | free_page((unsigned long)pte); |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 77 | static inline void pte_free(struct mm_struct *mm, pgtable_t pte) |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 78 | { |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 79 | pgtable_page_dtor(pte); |
Kirill A. Shutemov | f820e28 | 2013-11-14 14:31:50 -0800 | [diff] [blame] | 80 | __free_page(pte); |
Chris Zankel | 6656920 | 2007-08-22 10:14:51 -0700 | [diff] [blame] | 81 | } |
Martin Schwidefsky | 2f569af | 2008-02-08 04:22:04 -0800 | [diff] [blame] | 82 | #define pmd_pgtable(pmd) pmd_page(pmd) |
Chris Zankel | 9a8fd55 | 2005-06-23 22:01:26 -0700 | [diff] [blame] | 83 | |
| 84 | #endif /* __KERNEL__ */ |
| 85 | #endif /* _XTENSA_PGALLOC_H */ |