Path: blob/master/arch/powerpc/include/asm/book3s/64/mmu.h
26519 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _ASM_POWERPC_BOOK3S_64_MMU_H_2#define _ASM_POWERPC_BOOK3S_64_MMU_H_34#include <asm/page.h>56#ifndef __ASSEMBLY__7/*8* Page size definition9*10* shift : is the "PAGE_SHIFT" value for that page size11* sllp : is a bit mask with the value of SLB L || LP to be or'ed12* directly to a slbmte "vsid" value13* penc : is the HPTE encoding mask for the "LP" field:14*15*/16struct mmu_psize_def {17unsigned int shift; /* number of bits */18int penc[MMU_PAGE_COUNT]; /* HPTE encoding */19unsigned int tlbiel; /* tlbiel supported for that page size */20unsigned long avpnm; /* bits to mask out in AVPN in the HPTE */21unsigned long h_rpt_pgsize; /* H_RPT_INVALIDATE page size encoding */22union {23unsigned long sllp; /* SLB L||LP (exact mask to use in slbmte) */24unsigned long ap; /* Ap encoding used by PowerISA 3.0 */25};26};27extern struct mmu_psize_def mmu_psize_defs[MMU_PAGE_COUNT];28#endif /* __ASSEMBLY__ */2930/* 64-bit classic hash table MMU */31#include <asm/book3s/64/mmu-hash.h>3233#ifndef __ASSEMBLY__34/*35* ISA 3.0 partition and process table entry format36*/37struct prtb_entry {38__be64 prtb0;39__be64 prtb1;40};41extern struct prtb_entry *process_tb;4243struct patb_entry {44__be64 patb0;45__be64 patb1;46};47extern struct patb_entry *partition_tb;4849/* Bits in patb0 field */50#define PATB_HR (1UL << 63)51#define RPDB_MASK 0x0fffffffffffff00UL52#define RPDB_SHIFT (1UL << 8)53#define RTS1_SHIFT 61 /* top 2 bits of radix tree size */54#define RTS1_MASK (3UL << RTS1_SHIFT)55#define RTS2_SHIFT 5 /* bottom 3 bits of radix tree size */56#define RTS2_MASK (7UL << RTS2_SHIFT)57#define RPDS_MASK 0x1f /* root page dir. size field */5859/* Bits in patb1 field */60#define PATB_GR (1UL << 63) /* guest uses radix; must match HR */61#define PRTS_MASK 0x1f /* process table size field */62#define PRTB_MASK 0x0ffffffffffff000UL6364/* Number of supported LPID bits */65extern unsigned int mmu_lpid_bits;6667/* Number of supported PID bits */68extern unsigned int mmu_pid_bits;6970/* Base PID to allocate from */71extern unsigned int mmu_base_pid;7273extern unsigned long __ro_after_init memory_block_size;7475#define PRTB_SIZE_SHIFT (mmu_pid_bits + 4)76#define PRTB_ENTRIES (1ul << mmu_pid_bits)7778#define PATB_SIZE_SHIFT (mmu_lpid_bits + 4)79#define PATB_ENTRIES (1ul << mmu_lpid_bits)8081typedef unsigned long mm_context_id_t;82struct spinlock;8384/* Maximum possible number of NPUs in a system. */85#define NV_MAX_NPUS 88687typedef struct {88union {89/*90* We use id as the PIDR content for radix. On hash we can use91* more than one id. The extended ids are used when we start92* having address above 512TB. We allocate one extended id93* for each 512TB. The new id is then used with the 49 bit94* EA to build a new VA. We always use ESID_BITS_1T_MASK bits95* from EA and new context ids to build the new VAs.96*/97mm_context_id_t id;98#ifdef CONFIG_PPC_64S_HASH_MMU99mm_context_id_t extended_id[TASK_SIZE_USER64/TASK_CONTEXT_SIZE];100#endif101};102103/* Number of bits in the mm_cpumask */104atomic_t active_cpus;105106/* Number of users of the external (Nest) MMU */107atomic_t copros;108109/* Number of user space windows opened in process mm_context */110atomic_t vas_windows;111112#ifdef CONFIG_PPC_64S_HASH_MMU113struct hash_mm_context *hash_context;114#endif115116void __user *vdso;117/*118* pagetable fragment support119*/120void *pte_frag;121void *pmd_frag;122#ifdef CONFIG_SPAPR_TCE_IOMMU123struct list_head iommu_group_mem_list;124#endif125126#ifdef CONFIG_PPC_MEM_KEYS127/*128* Each bit represents one protection key.129* bit set -> key allocated130* bit unset -> key available for allocation131*/132u32 pkey_allocation_map;133s16 execute_only_pkey; /* key holding execute-only protection */134#endif135} mm_context_t;136137#ifdef CONFIG_PPC_64S_HASH_MMU138static inline u16 mm_ctx_user_psize(mm_context_t *ctx)139{140return ctx->hash_context->user_psize;141}142143static inline void mm_ctx_set_user_psize(mm_context_t *ctx, u16 user_psize)144{145ctx->hash_context->user_psize = user_psize;146}147148static inline unsigned char *mm_ctx_low_slices(mm_context_t *ctx)149{150return ctx->hash_context->low_slices_psize;151}152153static inline unsigned char *mm_ctx_high_slices(mm_context_t *ctx)154{155return ctx->hash_context->high_slices_psize;156}157158static inline unsigned long mm_ctx_slb_addr_limit(mm_context_t *ctx)159{160return ctx->hash_context->slb_addr_limit;161}162163static inline void mm_ctx_set_slb_addr_limit(mm_context_t *ctx, unsigned long limit)164{165ctx->hash_context->slb_addr_limit = limit;166}167168static inline struct slice_mask *slice_mask_for_size(mm_context_t *ctx, int psize)169{170#ifdef CONFIG_PPC_64K_PAGES171if (psize == MMU_PAGE_64K)172return &ctx->hash_context->mask_64k;173#endif174#ifdef CONFIG_HUGETLB_PAGE175if (psize == MMU_PAGE_16M)176return &ctx->hash_context->mask_16m;177if (psize == MMU_PAGE_16G)178return &ctx->hash_context->mask_16g;179#endif180BUG_ON(psize != MMU_PAGE_4K);181182return &ctx->hash_context->mask_4k;183}184185#ifdef CONFIG_PPC_SUBPAGE_PROT186static inline struct subpage_prot_table *mm_ctx_subpage_prot(mm_context_t *ctx)187{188return ctx->hash_context->spt;189}190#endif191192/*193* The current system page and segment sizes194*/195extern int mmu_virtual_psize;196extern int mmu_vmalloc_psize;197extern int mmu_io_psize;198#else /* CONFIG_PPC_64S_HASH_MMU */199#ifdef CONFIG_PPC_64K_PAGES200#define mmu_virtual_psize MMU_PAGE_64K201#else202#define mmu_virtual_psize MMU_PAGE_4K203#endif204#endif205extern int mmu_linear_psize;206extern int mmu_vmemmap_psize;207208/* MMU initialization */209void mmu_early_init_devtree(void);210void hash__early_init_devtree(void);211void radix__early_init_devtree(void);212#ifdef CONFIG_PPC_PKEY213void pkey_early_init_devtree(void);214#else215static inline void pkey_early_init_devtree(void) {}216#endif217218extern void hash__early_init_mmu(void);219extern void radix__early_init_mmu(void);220static inline void __init early_init_mmu(void)221{222if (radix_enabled())223return radix__early_init_mmu();224return hash__early_init_mmu();225}226extern void hash__early_init_mmu_secondary(void);227extern void radix__early_init_mmu_secondary(void);228static inline void early_init_mmu_secondary(void)229{230if (radix_enabled())231return radix__early_init_mmu_secondary();232return hash__early_init_mmu_secondary();233}234235extern void hash__setup_initial_memory_limit(phys_addr_t first_memblock_base,236phys_addr_t first_memblock_size);237static inline void setup_initial_memory_limit(phys_addr_t first_memblock_base,238phys_addr_t first_memblock_size)239{240/*241* Hash has more strict restrictions. At this point we don't242* know which translations we will pick. Hence go with hash243* restrictions.244*/245if (!early_radix_enabled())246hash__setup_initial_memory_limit(first_memblock_base,247first_memblock_size);248}249250#ifdef CONFIG_PPC_PSERIES251void __init radix_init_pseries(void);252#else253static inline void radix_init_pseries(void) { }254#endif255256#ifdef CONFIG_HOTPLUG_CPU257#define arch_clear_mm_cpumask_cpu(cpu, mm) \258do { \259if (cpumask_test_cpu(cpu, mm_cpumask(mm))) { \260dec_mm_active_cpus(mm); \261cpumask_clear_cpu(cpu, mm_cpumask(mm)); \262} \263} while (0)264265void cleanup_cpu_mmu_context(void);266#endif267268#ifdef CONFIG_PPC_64S_HASH_MMU269static inline int get_user_context(mm_context_t *ctx, unsigned long ea)270{271int index = ea >> MAX_EA_BITS_PER_CONTEXT;272273if (likely(index < ARRAY_SIZE(ctx->extended_id)))274return ctx->extended_id[index];275276/* should never happen */277WARN_ON(1);278return 0;279}280281static inline unsigned long get_user_vsid(mm_context_t *ctx,282unsigned long ea, int ssize)283{284unsigned long context = get_user_context(ctx, ea);285286return get_vsid(context, ea, ssize);287}288#endif289290#endif /* __ASSEMBLY__ */291#endif /* _ASM_POWERPC_BOOK3S_64_MMU_H_ */292293294