blob: 368284c972e7ccd83650b2f6f5a2ab725db00939 [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
Chris Zankel9a8fd552005-06-23 22:01:26 -070014#include <linux/highmem.h>
Chris Zankel4573e392010-05-02 01:05:13 -070015#include <linux/slab.h>
Chris Zankel9a8fd552005-06-23 22:01:26 -070016
17/*
18 * Allocating and freeing a pmd is trivial: the 1-entry pmd is
19 * inside the pgd, so has no extra memory associated with it.
20 */
21
Chris Zankel66569202007-08-22 10:14:51 -070022#define pmd_populate_kernel(mm, pmdp, ptep) \
23 (pmd_val(*(pmdp)) = ((unsigned long)ptep))
24#define pmd_populate(mm, pmdp, page) \
25 (pmd_val(*(pmdp)) = ((unsigned long)page_to_virt(page)))
Martin Schwidefsky2f569afd2008-02-08 04:22:04 -080026#define pmd_pgtable(pmd) pmd_page(pmd)
Chris Zankel9a8fd552005-06-23 22:01:26 -070027
28static inline pgd_t*
29pgd_alloc(struct mm_struct *mm)
30{
Chris Zankel66569202007-08-22 10:14:51 -070031 return (pgd_t*) __get_free_pages(GFP_KERNEL | __GFP_ZERO, PGD_ORDER);
Chris Zankel9a8fd552005-06-23 22:01:26 -070032}
33
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080034static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
Chris Zankel66569202007-08-22 10:14:51 -070035{
36 free_page((unsigned long)pgd);
37}
Chris Zankel9a8fd552005-06-23 22:01:26 -070038
Joel Fernandes (Google)4cf58922019-01-03 15:28:34 -080039static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
Chris Zankel66569202007-08-22 10:14:51 -070040{
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080041 pte_t *ptep;
42 int i;
43
Michal Hocko32d6bd92016-06-24 14:48:47 -070044 ptep = (pte_t *)__get_free_page(GFP_KERNEL);
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080045 if (!ptep)
46 return NULL;
47 for (i = 0; i < 1024; i++)
48 pte_clear(NULL, 0, ptep + i);
49 return ptep;
Chris Zankel66569202007-08-22 10:14:51 -070050}
51
Joel Fernandes (Google)4cf58922019-01-03 15:28:34 -080052static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
Chris Zankel66569202007-08-22 10:14:51 -070053{
Kirill A. Shutemovf8c6d302013-11-14 14:31:19 -080054 pte_t *pte;
Martin Schwidefsky2f569afd2008-02-08 04:22:04 -080055 struct page *page;
56
Joel Fernandes (Google)4cf58922019-01-03 15:28:34 -080057 pte = pte_alloc_one_kernel(mm);
Kirill A. Shutemovf8c6d302013-11-14 14:31:19 -080058 if (!pte)
59 return NULL;
60 page = virt_to_page(pte);
Kirill A. Shutemov8f431232013-11-14 14:31:48 -080061 if (!pgtable_page_ctor(page)) {
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080062 __free_page(page);
Kirill A. Shutemov8f431232013-11-14 14:31:48 -080063 return NULL;
64 }
Martin Schwidefsky2f569afd2008-02-08 04:22:04 -080065 return page;
Chris Zankel66569202007-08-22 10:14:51 -070066}
67
Benjamin Herrenschmidt5e541972008-02-04 22:29:14 -080068static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
Chris Zankel66569202007-08-22 10:14:51 -070069{
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080070 free_page((unsigned long)pte);
Chris Zankel66569202007-08-22 10:14:51 -070071}
72
Martin Schwidefsky2f569afd2008-02-08 04:22:04 -080073static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
Chris Zankel66569202007-08-22 10:14:51 -070074{
Martin Schwidefsky2f569afd2008-02-08 04:22:04 -080075 pgtable_page_dtor(pte);
Kirill A. Shutemovf820e282013-11-14 14:31:50 -080076 __free_page(pte);
Chris Zankel66569202007-08-22 10:14:51 -070077}
Martin Schwidefsky2f569afd2008-02-08 04:22:04 -080078#define pmd_pgtable(pmd) pmd_page(pmd)
Chris Zankel9a8fd552005-06-23 22:01:26 -070079
Chris Zankel9a8fd552005-06-23 22:01:26 -070080#endif /* _XTENSA_PGALLOC_H */