blob: 1065bc8bcae56bba87f8d1a55b2c5155d489777d [file] [log] [blame]
Chris Zankel9a8fd552005-06-23 22:01:26 -07001/*
Chris Zankel66569202007-08-22 10:14:51 -07002 * include/asm-xtensa/pgalloc.h
Chris Zankel9a8fd552005-06-23 22:01:26 -07003 *
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 Zankel66569202007-08-22 10:14:51 -07008 * Copyright (C) 2001-2007 Tensilica Inc.
Chris Zankel9a8fd552005-06-23 22:01:26 -07009 */
10
11#ifndef _XTENSA_PGALLOC_H
12#define _XTENSA_PGALLOC_H
13
14#ifdef __KERNEL__
15
Chris Zankel9a8fd552005-06-23 22:01:26 -070016#include <linux/highmem.h>
Chris Zankel4573e392010-05-02 01:05:13 -070017#include <linux/slab.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070018
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 Zankel66569202007-08-22 10:14:51 -070024#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 Schwidefsky2f569af2008-02-08 04:22:04 -080028#define pmd_pgtable(pmd) pmd_page(pmd)
Chris Zankel9a8fd552005-06-23 22:01:26 -070029
30static inline pgd_t*
31pgd_alloc(struct mm_struct *mm)
32{
Chris Zankel66569202007-08-22 10:14:51 -070033 return (pgd_t*) __get_free_pages(GFP_KERNEL | __GFP_ZERO, PGD_ORDER);
Chris Zankel9a8fd552005-06-23 22:01:26 -070034}
35
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080036static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Chris Zankel66569202007-08-22 10:14:51 -070037{
38 free_page((unsigned long)pgd);
39}
Chris Zankel9a8fd552005-06-23 22:01:26 -070040
Chris Zankelc4c45942012-11-28 16:53:51 -080041static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
Chris Zankel66569202007-08-22 10:14:51 -070042 unsigned long address)
43{
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080044 pte_t *ptep;
45 int i;
46
Michal Hocko32d6bd92016-06-24 14:48:47 -070047 ptep = (pte_t *)__get_free_page(GFP_KERNEL);
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080048 if (!ptep)
49 return NULL;
50 for (i = 0; i < 1024; i++)
51 pte_clear(NULL, 0, ptep + i);
52 return ptep;
Chris Zankel66569202007-08-22 10:14:51 -070053}
54
Chris Zankele584d852008-02-13 16:25:09 -080055static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080056 unsigned long addr)
Chris Zankel66569202007-08-22 10:14:51 -070057{
Kirill A. Shutemovf8c6d302013-11-14 14:31:19 -080058 pte_t *pte;
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080059 struct page *page;
60
Kirill A. Shutemovf8c6d302013-11-14 14:31:19 -080061 pte = pte_alloc_one_kernel(mm, addr);
62 if (!pte)
63 return NULL;
64 page = virt_to_page(pte);
Kirill A. Shutemov8f431232013-11-14 14:31:48 -080065 if (!pgtable_page_ctor(page)) {
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080066 __free_page(page);
Kirill A. Shutemov8f431232013-11-14 14:31:48 -080067 return NULL;
68 }
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080069 return page;
Chris Zankel66569202007-08-22 10:14:51 -070070}
71
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080072static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Chris Zankel66569202007-08-22 10:14:51 -070073{
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080074 free_page((unsigned long)pte);
Chris Zankel66569202007-08-22 10:14:51 -070075}
76
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080077static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Chris Zankel66569202007-08-22 10:14:51 -070078{
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080079 pgtable_page_dtor(pte);
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080080 __free_page(pte);
Chris Zankel66569202007-08-22 10:14:51 -070081}
Martin Schwidefsky2f569af2008-02-08 04:22:04 -080082#define pmd_pgtable(pmd) pmd_page(pmd)
Chris Zankel9a8fd552005-06-23 22:01:26 -070083
84#endif /* __KERNEL__ */
85#endif /* _XTENSA_PGALLOC_H */