18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __MMU_H
38c2ecf20Sopenharmony_ci#define __MMU_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/cpumask.h>
68c2ecf20Sopenharmony_ci#include <linux/errno.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_citypedef struct {
98c2ecf20Sopenharmony_ci	spinlock_t lock;
108c2ecf20Sopenharmony_ci	cpumask_t cpu_attach_mask;
118c2ecf20Sopenharmony_ci	atomic_t flush_count;
128c2ecf20Sopenharmony_ci	unsigned int flush_mm;
138c2ecf20Sopenharmony_ci	struct list_head pgtable_list;
148c2ecf20Sopenharmony_ci	struct list_head gmap_list;
158c2ecf20Sopenharmony_ci	unsigned long gmap_asce;
168c2ecf20Sopenharmony_ci	unsigned long asce;
178c2ecf20Sopenharmony_ci	unsigned long asce_limit;
188c2ecf20Sopenharmony_ci	unsigned long vdso_base;
198c2ecf20Sopenharmony_ci	/* The mmu context belongs to a secure guest. */
208c2ecf20Sopenharmony_ci	atomic_t is_protected;
218c2ecf20Sopenharmony_ci	/*
228c2ecf20Sopenharmony_ci	 * The following bitfields need a down_write on the mm
238c2ecf20Sopenharmony_ci	 * semaphore when they are written to. As they are only
248c2ecf20Sopenharmony_ci	 * written once, they can be read without a lock.
258c2ecf20Sopenharmony_ci	 *
268c2ecf20Sopenharmony_ci	 * The mmu context allocates 4K page tables.
278c2ecf20Sopenharmony_ci	 */
288c2ecf20Sopenharmony_ci	unsigned int alloc_pgste:1;
298c2ecf20Sopenharmony_ci	/* The mmu context uses extended page tables. */
308c2ecf20Sopenharmony_ci	unsigned int has_pgste:1;
318c2ecf20Sopenharmony_ci	/* The mmu context uses storage keys. */
328c2ecf20Sopenharmony_ci	unsigned int uses_skeys:1;
338c2ecf20Sopenharmony_ci	/* The mmu context uses CMM. */
348c2ecf20Sopenharmony_ci	unsigned int uses_cmm:1;
358c2ecf20Sopenharmony_ci	/* The gmaps associated with this context are allowed to use huge pages. */
368c2ecf20Sopenharmony_ci	unsigned int allow_gmap_hpage_1m:1;
378c2ecf20Sopenharmony_ci} mm_context_t;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define INIT_MM_CONTEXT(name)						   \
408c2ecf20Sopenharmony_ci	.context.lock =	__SPIN_LOCK_UNLOCKED(name.context.lock),	   \
418c2ecf20Sopenharmony_ci	.context.pgtable_list = LIST_HEAD_INIT(name.context.pgtable_list), \
428c2ecf20Sopenharmony_ci	.context.gmap_list = LIST_HEAD_INIT(name.context.gmap_list),
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistatic inline int tprot(unsigned long addr)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	int rc = -EFAULT;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	asm volatile(
498c2ecf20Sopenharmony_ci		"	tprot	0(%1),0\n"
508c2ecf20Sopenharmony_ci		"0:	ipm	%0\n"
518c2ecf20Sopenharmony_ci		"	srl	%0,28\n"
528c2ecf20Sopenharmony_ci		"1:\n"
538c2ecf20Sopenharmony_ci		EX_TABLE(0b,1b)
548c2ecf20Sopenharmony_ci		: "+d" (rc) : "a" (addr) : "cc");
558c2ecf20Sopenharmony_ci	return rc;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#endif
59