linux/arch/powerpc/include/asm/book3s/32/pgalloc.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef _ASM_POWERPC_BOOK3S_32_PGALLOC_H
   3#define _ASM_POWERPC_BOOK3S_32_PGALLOC_H
   4
   5#include <linux/threads.h>
   6#include <linux/slab.h>
   7
   8/*
   9 * Functions that deal with pagetables that could be at any level of
  10 * the table need to be passed an "index_size" so they know how to
  11 * handle allocation.  For PTE pages (which are linked to a struct
  12 * page for now, and drawn from the main get_free_pages() pool), the
  13 * allocation size will be (2^index_size * sizeof(pointer)) and
  14 * allocations are drawn from the kmem_cache in PGT_CACHE(index_size).
  15 *
  16 * The maximum index size needs to be big enough to allow any
  17 * pagetable sizes we need, but small enough to fit in the low bits of
  18 * any page table pointer.  In other words all pagetables, even tiny
  19 * ones, must be aligned to allow at least enough low 0 bits to
  20 * contain this value.  This value is also used as a mask, so it must
  21 * be one less than a power of two.
  22 */
  23#define MAX_PGTABLE_INDEX_SIZE  0xf
  24
  25extern void __bad_pte(pmd_t *pmd);
  26
  27extern struct kmem_cache *pgtable_cache[];
  28#define PGT_CACHE(shift) pgtable_cache[shift]
  29
  30static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  31{
  32        return kmem_cache_alloc(PGT_CACHE(PGD_INDEX_SIZE),
  33                        pgtable_gfp_flags(mm, GFP_KERNEL));
  34}
  35
  36static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  37{
  38        kmem_cache_free(PGT_CACHE(PGD_INDEX_SIZE), pgd);
  39}
  40
  41/*
  42 * We don't have any real pmd's, and this code never triggers because
  43 * the pgd will always be present..
  44 */
  45/* #define pmd_alloc_one(mm,address)       ({ BUG(); ((pmd_t *)2); }) */
  46#define pmd_free(mm, x)                 do { } while (0)
  47#define __pmd_free_tlb(tlb,x,a)         do { } while (0)
  48/* #define pgd_populate(mm, pmd, pte)      BUG() */
  49
  50static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp,
  51                                       pte_t *pte)
  52{
  53        *pmdp = __pmd(__pa(pte) | _PMD_PRESENT);
  54}
  55
  56static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmdp,
  57                                pgtable_t pte_page)
  58{
  59        *pmdp = __pmd(__pa(pte_page) | _PMD_PRESENT);
  60}
  61
  62#define pmd_pgtable(pmd) ((pgtable_t)pmd_page_vaddr(pmd))
  63
  64extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm);
  65extern pgtable_t pte_alloc_one(struct mm_struct *mm);
  66void pte_frag_destroy(void *pte_frag);
  67pte_t *pte_fragment_alloc(struct mm_struct *mm, int kernel);
  68void pte_fragment_free(unsigned long *table, int kernel);
  69
  70static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  71{
  72        pte_fragment_free((unsigned long *)pte, 1);
  73}
  74
  75static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
  76{
  77        pte_fragment_free((unsigned long *)ptepage, 0);
  78}
  79
  80static inline void pgtable_free(void *table, unsigned index_size)
  81{
  82        if (!index_size) {
  83                pte_fragment_free((unsigned long *)table, 0);
  84        } else {
  85                BUG_ON(index_size > MAX_PGTABLE_INDEX_SIZE);
  86                kmem_cache_free(PGT_CACHE(index_size), table);
  87        }
  88}
  89
  90#define check_pgt_cache()       do { } while (0)
  91#define get_hugepd_cache_index(x)  (x)
  92
  93#ifdef CONFIG_SMP
  94static inline void pgtable_free_tlb(struct mmu_gather *tlb,
  95                                    void *table, int shift)
  96{
  97        unsigned long pgf = (unsigned long)table;
  98        BUG_ON(shift > MAX_PGTABLE_INDEX_SIZE);
  99        pgf |= shift;
 100        tlb_remove_table(tlb, (void *)pgf);
 101}
 102
 103static inline void __tlb_remove_table(void *_table)
 104{
 105        void *table = (void *)((unsigned long)_table & ~MAX_PGTABLE_INDEX_SIZE);
 106        unsigned shift = (unsigned long)_table & MAX_PGTABLE_INDEX_SIZE;
 107
 108        pgtable_free(table, shift);
 109}
 110#else
 111static inline void pgtable_free_tlb(struct mmu_gather *tlb,
 112                                    void *table, int shift)
 113{
 114        pgtable_free(table, shift);
 115}
 116#endif
 117
 118static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t table,
 119                                  unsigned long address)
 120{
 121        pgtable_free_tlb(tlb, table, 0);
 122}
 123#endif /* _ASM_POWERPC_BOOK3S_32_PGALLOC_H */
 124