162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_PTE_E500_H
362306a36Sopenharmony_ci#define _ASM_POWERPC_NOHASH_PTE_E500_H
462306a36Sopenharmony_ci#ifdef __KERNEL__
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci/* PTE bit definitions for processors compliant to the Book3E
762306a36Sopenharmony_ci * architecture 2.06 or later. The position of the PTE bits
862306a36Sopenharmony_ci * matches the HW definition of the optional Embedded Page Table
962306a36Sopenharmony_ci * category.
1062306a36Sopenharmony_ci */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci/* Architected bits */
1362306a36Sopenharmony_ci#define _PAGE_PRESENT	0x000001 /* software: pte contains a translation */
1462306a36Sopenharmony_ci#define _PAGE_SW1	0x000002
1562306a36Sopenharmony_ci#define _PAGE_BAP_SR	0x000004
1662306a36Sopenharmony_ci#define _PAGE_BAP_UR	0x000008
1762306a36Sopenharmony_ci#define _PAGE_BAP_SW	0x000010
1862306a36Sopenharmony_ci#define _PAGE_BAP_UW	0x000020
1962306a36Sopenharmony_ci#define _PAGE_BAP_SX	0x000040
2062306a36Sopenharmony_ci#define _PAGE_BAP_UX	0x000080
2162306a36Sopenharmony_ci#define _PAGE_PSIZE_MSK	0x000f00
2262306a36Sopenharmony_ci#define _PAGE_PSIZE_4K	0x000200
2362306a36Sopenharmony_ci#define _PAGE_PSIZE_8K	0x000300
2462306a36Sopenharmony_ci#define _PAGE_PSIZE_16K	0x000400
2562306a36Sopenharmony_ci#define _PAGE_PSIZE_32K	0x000500
2662306a36Sopenharmony_ci#define _PAGE_PSIZE_64K	0x000600
2762306a36Sopenharmony_ci#define _PAGE_PSIZE_128K	0x000700
2862306a36Sopenharmony_ci#define _PAGE_PSIZE_256K	0x000800
2962306a36Sopenharmony_ci#define _PAGE_PSIZE_512K	0x000900
3062306a36Sopenharmony_ci#define _PAGE_PSIZE_1M	0x000a00
3162306a36Sopenharmony_ci#define _PAGE_PSIZE_2M	0x000b00
3262306a36Sopenharmony_ci#define _PAGE_PSIZE_4M	0x000c00
3362306a36Sopenharmony_ci#define _PAGE_PSIZE_8M	0x000d00
3462306a36Sopenharmony_ci#define _PAGE_PSIZE_16M	0x000e00
3562306a36Sopenharmony_ci#define _PAGE_PSIZE_32M	0x000f00
3662306a36Sopenharmony_ci#define _PAGE_DIRTY	0x001000 /* C: page changed */
3762306a36Sopenharmony_ci#define _PAGE_SW0	0x002000
3862306a36Sopenharmony_ci#define _PAGE_U3	0x004000
3962306a36Sopenharmony_ci#define _PAGE_U2	0x008000
4062306a36Sopenharmony_ci#define _PAGE_U1	0x010000
4162306a36Sopenharmony_ci#define _PAGE_U0	0x020000
4262306a36Sopenharmony_ci#define _PAGE_ACCESSED	0x040000
4362306a36Sopenharmony_ci#define _PAGE_ENDIAN	0x080000
4462306a36Sopenharmony_ci#define _PAGE_GUARDED	0x100000
4562306a36Sopenharmony_ci#define _PAGE_COHERENT	0x200000 /* M: enforce memory coherence */
4662306a36Sopenharmony_ci#define _PAGE_NO_CACHE	0x400000 /* I: cache inhibit */
4762306a36Sopenharmony_ci#define _PAGE_WRITETHRU	0x800000 /* W: cache write-through */
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/* "Higher level" linux bit combinations */
5062306a36Sopenharmony_ci#define _PAGE_EXEC		(_PAGE_BAP_SX | _PAGE_BAP_UX) /* .. and was cache cleaned */
5162306a36Sopenharmony_ci#define _PAGE_RW		(_PAGE_BAP_SW | _PAGE_BAP_UW) /* User write permission */
5262306a36Sopenharmony_ci#define _PAGE_KERNEL_RW		(_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY)
5362306a36Sopenharmony_ci#define _PAGE_KERNEL_RO		(_PAGE_BAP_SR)
5462306a36Sopenharmony_ci#define _PAGE_KERNEL_RWX	(_PAGE_BAP_SW | _PAGE_BAP_SR | _PAGE_DIRTY | _PAGE_BAP_SX)
5562306a36Sopenharmony_ci#define _PAGE_KERNEL_ROX	(_PAGE_BAP_SR | _PAGE_BAP_SX)
5662306a36Sopenharmony_ci#define _PAGE_USER		(_PAGE_BAP_UR | _PAGE_BAP_SR) /* Can be read */
5762306a36Sopenharmony_ci#define _PAGE_PRIVILEGED	(_PAGE_BAP_SR)
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define _PAGE_SPECIAL	_PAGE_SW0
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* Base page size */
6262306a36Sopenharmony_ci#define _PAGE_PSIZE	_PAGE_PSIZE_4K
6362306a36Sopenharmony_ci#define	PTE_RPN_SHIFT	(24)
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define PTE_WIMGE_SHIFT (19)
6662306a36Sopenharmony_ci#define PTE_BAP_SHIFT	(2)
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci/* On 32-bit, we never clear the top part of the PTE */
6962306a36Sopenharmony_ci#ifdef CONFIG_PPC32
7062306a36Sopenharmony_ci#define _PTE_NONE_MASK	0xffffffff00000000ULL
7162306a36Sopenharmony_ci#define _PMD_PRESENT	0
7262306a36Sopenharmony_ci#define _PMD_PRESENT_MASK (PAGE_MASK)
7362306a36Sopenharmony_ci#define _PMD_BAD	(~PAGE_MASK)
7462306a36Sopenharmony_ci#define _PMD_USER	0
7562306a36Sopenharmony_ci#else
7662306a36Sopenharmony_ci#define _PTE_NONE_MASK	0
7762306a36Sopenharmony_ci#endif
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci/*
8062306a36Sopenharmony_ci * We define 2 sets of base prot bits, one for basic pages (ie,
8162306a36Sopenharmony_ci * cacheable kernel and user pages) and one for non cacheable
8262306a36Sopenharmony_ci * pages. We always set _PAGE_COHERENT when SMP is enabled or
8362306a36Sopenharmony_ci * the processor might need it for DMA coherency.
8462306a36Sopenharmony_ci */
8562306a36Sopenharmony_ci#define _PAGE_BASE_NC	(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
8662306a36Sopenharmony_ci#if defined(CONFIG_SMP)
8762306a36Sopenharmony_ci#define _PAGE_BASE	(_PAGE_BASE_NC | _PAGE_COHERENT)
8862306a36Sopenharmony_ci#else
8962306a36Sopenharmony_ci#define _PAGE_BASE	(_PAGE_BASE_NC)
9062306a36Sopenharmony_ci#endif
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* Permission masks used to generate the __P and __S table */
9362306a36Sopenharmony_ci#define PAGE_NONE	__pgprot(_PAGE_BASE)
9462306a36Sopenharmony_ci#define PAGE_SHARED	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
9562306a36Sopenharmony_ci#define PAGE_SHARED_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_BAP_UX)
9662306a36Sopenharmony_ci#define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_USER)
9762306a36Sopenharmony_ci#define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_BAP_UX)
9862306a36Sopenharmony_ci#define PAGE_READONLY	__pgprot(_PAGE_BASE | _PAGE_USER)
9962306a36Sopenharmony_ci#define PAGE_READONLY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_BAP_UX)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#ifndef __ASSEMBLY__
10262306a36Sopenharmony_cistatic inline pte_t pte_mkprivileged(pte_t pte)
10362306a36Sopenharmony_ci{
10462306a36Sopenharmony_ci	return __pte((pte_val(pte) & ~_PAGE_USER) | _PAGE_PRIVILEGED);
10562306a36Sopenharmony_ci}
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci#define pte_mkprivileged pte_mkprivileged
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_cistatic inline pte_t pte_mkuser(pte_t pte)
11062306a36Sopenharmony_ci{
11162306a36Sopenharmony_ci	return __pte((pte_val(pte) & ~_PAGE_PRIVILEGED) | _PAGE_USER);
11262306a36Sopenharmony_ci}
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#define pte_mkuser pte_mkuser
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_cistatic inline pte_t pte_mkexec(pte_t pte)
11762306a36Sopenharmony_ci{
11862306a36Sopenharmony_ci	if (pte_val(pte) & _PAGE_BAP_UR)
11962306a36Sopenharmony_ci		return __pte((pte_val(pte) & ~_PAGE_BAP_SX) | _PAGE_BAP_UX);
12062306a36Sopenharmony_ci	else
12162306a36Sopenharmony_ci		return __pte((pte_val(pte) & ~_PAGE_BAP_UX) | _PAGE_BAP_SX);
12262306a36Sopenharmony_ci}
12362306a36Sopenharmony_ci#define pte_mkexec pte_mkexec
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci#endif /* __KERNEL__ */
12862306a36Sopenharmony_ci#endif /*  _ASM_POWERPC_NOHASH_PTE_E500_H */
129