162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _ASM_POWERPC_MMU_44X_H_
362306a36Sopenharmony_ci#define _ASM_POWERPC_MMU_44X_H_
462306a36Sopenharmony_ci/*
562306a36Sopenharmony_ci * PPC440 support
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <asm/asm-const.h>
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define PPC44x_MMUCR_TID	0x000000ff
1162306a36Sopenharmony_ci#define PPC44x_MMUCR_STS	0x00010000
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#define	PPC44x_TLB_PAGEID	0
1462306a36Sopenharmony_ci#define	PPC44x_TLB_XLAT		1
1562306a36Sopenharmony_ci#define	PPC44x_TLB_ATTRIB	2
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* Page identification fields */
1862306a36Sopenharmony_ci#define PPC44x_TLB_EPN_MASK	0xfffffc00      /* Effective Page Number */
1962306a36Sopenharmony_ci#define	PPC44x_TLB_VALID	0x00000200      /* Valid flag */
2062306a36Sopenharmony_ci#define PPC44x_TLB_TS		0x00000100	/* Translation address space */
2162306a36Sopenharmony_ci#define PPC44x_TLB_1K		0x00000000	/* Page sizes */
2262306a36Sopenharmony_ci#define PPC44x_TLB_4K		0x00000010
2362306a36Sopenharmony_ci#define PPC44x_TLB_16K		0x00000020
2462306a36Sopenharmony_ci#define PPC44x_TLB_64K		0x00000030
2562306a36Sopenharmony_ci#define PPC44x_TLB_256K		0x00000040
2662306a36Sopenharmony_ci#define PPC44x_TLB_1M		0x00000050
2762306a36Sopenharmony_ci#define PPC44x_TLB_16M		0x00000070
2862306a36Sopenharmony_ci#define	PPC44x_TLB_256M		0x00000090
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/* Translation fields */
3162306a36Sopenharmony_ci#define PPC44x_TLB_RPN_MASK	0xfffffc00      /* Real Page Number */
3262306a36Sopenharmony_ci#define	PPC44x_TLB_ERPN_MASK	0x0000000f
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* Storage attribute and access control fields */
3562306a36Sopenharmony_ci#define PPC44x_TLB_ATTR_MASK	0x0000ff80
3662306a36Sopenharmony_ci#define PPC44x_TLB_U0		0x00008000      /* User 0 */
3762306a36Sopenharmony_ci#define PPC44x_TLB_U1		0x00004000      /* User 1 */
3862306a36Sopenharmony_ci#define PPC44x_TLB_U2		0x00002000      /* User 2 */
3962306a36Sopenharmony_ci#define PPC44x_TLB_U3		0x00001000      /* User 3 */
4062306a36Sopenharmony_ci#define PPC44x_TLB_W		0x00000800      /* Caching is write-through */
4162306a36Sopenharmony_ci#define PPC44x_TLB_I		0x00000400      /* Caching is inhibited */
4262306a36Sopenharmony_ci#define PPC44x_TLB_M		0x00000200      /* Memory is coherent */
4362306a36Sopenharmony_ci#define PPC44x_TLB_G		0x00000100      /* Memory is guarded */
4462306a36Sopenharmony_ci#define PPC44x_TLB_E		0x00000080      /* Memory is little endian */
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define PPC44x_TLB_PERM_MASK	0x0000003f
4762306a36Sopenharmony_ci#define PPC44x_TLB_UX		0x00000020      /* User execution */
4862306a36Sopenharmony_ci#define PPC44x_TLB_UW		0x00000010      /* User write */
4962306a36Sopenharmony_ci#define PPC44x_TLB_UR		0x00000008      /* User read */
5062306a36Sopenharmony_ci#define PPC44x_TLB_SX		0x00000004      /* Super execution */
5162306a36Sopenharmony_ci#define PPC44x_TLB_SW		0x00000002      /* Super write */
5262306a36Sopenharmony_ci#define PPC44x_TLB_SR		0x00000001      /* Super read */
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/* Number of TLB entries */
5562306a36Sopenharmony_ci#define PPC44x_TLB_SIZE		64
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* 47x bits */
5862306a36Sopenharmony_ci#define PPC47x_MMUCR_TID	0x0000ffff
5962306a36Sopenharmony_ci#define PPC47x_MMUCR_STS	0x00010000
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* Page identification fields */
6262306a36Sopenharmony_ci#define PPC47x_TLB0_EPN_MASK	0xfffff000      /* Effective Page Number */
6362306a36Sopenharmony_ci#define PPC47x_TLB0_VALID	0x00000800      /* Valid flag */
6462306a36Sopenharmony_ci#define PPC47x_TLB0_TS		0x00000400	/* Translation address space */
6562306a36Sopenharmony_ci#define PPC47x_TLB0_4K		0x00000000
6662306a36Sopenharmony_ci#define PPC47x_TLB0_16K		0x00000010
6762306a36Sopenharmony_ci#define PPC47x_TLB0_64K		0x00000030
6862306a36Sopenharmony_ci#define PPC47x_TLB0_1M		0x00000070
6962306a36Sopenharmony_ci#define PPC47x_TLB0_16M		0x000000f0
7062306a36Sopenharmony_ci#define PPC47x_TLB0_256M	0x000001f0
7162306a36Sopenharmony_ci#define PPC47x_TLB0_1G		0x000003f0
7262306a36Sopenharmony_ci#define PPC47x_TLB0_BOLTED_R	0x00000008	/* tlbre only */
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/* Translation fields */
7562306a36Sopenharmony_ci#define PPC47x_TLB1_RPN_MASK	0xfffff000      /* Real Page Number */
7662306a36Sopenharmony_ci#define PPC47x_TLB1_ERPN_MASK	0x000003ff
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/* Storage attribute and access control fields */
7962306a36Sopenharmony_ci#define PPC47x_TLB2_ATTR_MASK	0x0003ff80
8062306a36Sopenharmony_ci#define PPC47x_TLB2_IL1I	0x00020000      /* Memory is guarded */
8162306a36Sopenharmony_ci#define PPC47x_TLB2_IL1D	0x00010000      /* Memory is guarded */
8262306a36Sopenharmony_ci#define PPC47x_TLB2_U0		0x00008000      /* User 0 */
8362306a36Sopenharmony_ci#define PPC47x_TLB2_U1		0x00004000      /* User 1 */
8462306a36Sopenharmony_ci#define PPC47x_TLB2_U2		0x00002000      /* User 2 */
8562306a36Sopenharmony_ci#define PPC47x_TLB2_U3		0x00001000      /* User 3 */
8662306a36Sopenharmony_ci#define PPC47x_TLB2_W		0x00000800      /* Caching is write-through */
8762306a36Sopenharmony_ci#define PPC47x_TLB2_I		0x00000400      /* Caching is inhibited */
8862306a36Sopenharmony_ci#define PPC47x_TLB2_M		0x00000200      /* Memory is coherent */
8962306a36Sopenharmony_ci#define PPC47x_TLB2_G		0x00000100      /* Memory is guarded */
9062306a36Sopenharmony_ci#define PPC47x_TLB2_E		0x00000080      /* Memory is little endian */
9162306a36Sopenharmony_ci#define PPC47x_TLB2_PERM_MASK	0x0000003f
9262306a36Sopenharmony_ci#define PPC47x_TLB2_UX		0x00000020      /* User execution */
9362306a36Sopenharmony_ci#define PPC47x_TLB2_UW		0x00000010      /* User write */
9462306a36Sopenharmony_ci#define PPC47x_TLB2_UR		0x00000008      /* User read */
9562306a36Sopenharmony_ci#define PPC47x_TLB2_SX		0x00000004      /* Super execution */
9662306a36Sopenharmony_ci#define PPC47x_TLB2_SW		0x00000002      /* Super write */
9762306a36Sopenharmony_ci#define PPC47x_TLB2_SR		0x00000001      /* Super read */
9862306a36Sopenharmony_ci#define PPC47x_TLB2_U_RWX	(PPC47x_TLB2_UX|PPC47x_TLB2_UW|PPC47x_TLB2_UR)
9962306a36Sopenharmony_ci#define PPC47x_TLB2_S_RWX	(PPC47x_TLB2_SX|PPC47x_TLB2_SW|PPC47x_TLB2_SR)
10062306a36Sopenharmony_ci#define PPC47x_TLB2_S_RW	(PPC47x_TLB2_SW | PPC47x_TLB2_SR)
10162306a36Sopenharmony_ci#define PPC47x_TLB2_IMG		(PPC47x_TLB2_I | PPC47x_TLB2_M | PPC47x_TLB2_G)
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#ifndef __ASSEMBLY__
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ciextern unsigned int tlb_44x_hwater;
10662306a36Sopenharmony_ciextern unsigned int tlb_44x_index;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_citypedef struct {
10962306a36Sopenharmony_ci	unsigned int	id;
11062306a36Sopenharmony_ci	unsigned int	active;
11162306a36Sopenharmony_ci	void __user	*vdso;
11262306a36Sopenharmony_ci} mm_context_t;
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci/* patch sites */
11562306a36Sopenharmony_ciextern s32 patch__tlb_44x_hwater_D, patch__tlb_44x_hwater_I;
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci#ifndef CONFIG_PPC_EARLY_DEBUG_44x
12062306a36Sopenharmony_ci#define PPC44x_EARLY_TLBS	1
12162306a36Sopenharmony_ci#else
12262306a36Sopenharmony_ci#define PPC44x_EARLY_TLBS	2
12362306a36Sopenharmony_ci#define PPC44x_EARLY_DEBUG_VIRTADDR	(ASM_CONST(0xf0000000) \
12462306a36Sopenharmony_ci	| (ASM_CONST(CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW) & 0xffff))
12562306a36Sopenharmony_ci#endif
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/* Size of the TLBs used for pinning in lowmem */
12862306a36Sopenharmony_ci#define PPC_PIN_SIZE	(1 << 28)	/* 256M */
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#if defined(CONFIG_PPC_4K_PAGES)
13162306a36Sopenharmony_ci#define PPC44x_TLBE_SIZE	PPC44x_TLB_4K
13262306a36Sopenharmony_ci#define PPC47x_TLBE_SIZE	PPC47x_TLB0_4K
13362306a36Sopenharmony_ci#define mmu_virtual_psize	MMU_PAGE_4K
13462306a36Sopenharmony_ci#elif defined(CONFIG_PPC_16K_PAGES)
13562306a36Sopenharmony_ci#define PPC44x_TLBE_SIZE	PPC44x_TLB_16K
13662306a36Sopenharmony_ci#define PPC47x_TLBE_SIZE	PPC47x_TLB0_16K
13762306a36Sopenharmony_ci#define mmu_virtual_psize	MMU_PAGE_16K
13862306a36Sopenharmony_ci#elif defined(CONFIG_PPC_64K_PAGES)
13962306a36Sopenharmony_ci#define PPC44x_TLBE_SIZE	PPC44x_TLB_64K
14062306a36Sopenharmony_ci#define PPC47x_TLBE_SIZE	PPC47x_TLB0_64K
14162306a36Sopenharmony_ci#define mmu_virtual_psize	MMU_PAGE_64K
14262306a36Sopenharmony_ci#elif defined(CONFIG_PPC_256K_PAGES)
14362306a36Sopenharmony_ci#define PPC44x_TLBE_SIZE	PPC44x_TLB_256K
14462306a36Sopenharmony_ci#define mmu_virtual_psize	MMU_PAGE_256K
14562306a36Sopenharmony_ci#else
14662306a36Sopenharmony_ci#error "Unsupported PAGE_SIZE"
14762306a36Sopenharmony_ci#endif
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#define mmu_linear_psize	MMU_PAGE_256M
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define PPC44x_PGD_OFF_SHIFT	(32 - PGDIR_SHIFT + PGD_T_LOG2)
15262306a36Sopenharmony_ci#define PPC44x_PGD_OFF_MASK_BIT	(PGDIR_SHIFT - PGD_T_LOG2)
15362306a36Sopenharmony_ci#define PPC44x_PTE_ADD_SHIFT	(32 - PGDIR_SHIFT + PTE_SHIFT + PTE_T_LOG2)
15462306a36Sopenharmony_ci#define PPC44x_PTE_ADD_MASK_BIT	(32 - PTE_T_LOG2 - PTE_SHIFT)
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci#endif /* _ASM_POWERPC_MMU_44X_H_ */
157