162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_32_PTE_44x_H
362306a36Sopenharmony_ci#define _ASM_POWERPC_NOHASH_32_PTE_44x_H
462306a36Sopenharmony_ci#ifdef __KERNEL__
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci/*
762306a36Sopenharmony_ci * Definitions for PPC440
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Because of the 3 word TLB entries to support 36-bit addressing,
1062306a36Sopenharmony_ci * the attribute are difficult to map in such a fashion that they
1162306a36Sopenharmony_ci * are easily loaded during exception processing.  I decided to
1262306a36Sopenharmony_ci * organize the entry so the ERPN is the only portion in the
1362306a36Sopenharmony_ci * upper word of the PTE and the attribute bits below are packed
1462306a36Sopenharmony_ci * in as sensibly as they can be in the area below a 4KB page size
1562306a36Sopenharmony_ci * oriented RPN.  This at least makes it easy to load the RPN and
1662306a36Sopenharmony_ci * ERPN fields in the TLB. -Matt
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci * This isn't entirely true anymore, at least some bits are now
1962306a36Sopenharmony_ci * easier to move into the TLB from the PTE. -BenH.
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci * Note that these bits preclude future use of a page size
2262306a36Sopenharmony_ci * less than 4KB.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci *
2562306a36Sopenharmony_ci * PPC 440 core has following TLB attribute fields;
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci *   TLB1:
2862306a36Sopenharmony_ci *   0  1  2  3  4  ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
2962306a36Sopenharmony_ci *   RPN.................................  -  -  -  -  -  - ERPN.......
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci *   TLB2:
3262306a36Sopenharmony_ci *   0  1  2  3  4  ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
3362306a36Sopenharmony_ci *   -  -  -  -  -    - U0 U1 U2 U3 W  I  M  G  E   - UX UW UR SX SW SR
3462306a36Sopenharmony_ci *
3562306a36Sopenharmony_ci * Newer 440 cores (440x6 as used on AMCC 460EX/460GT) have additional
3662306a36Sopenharmony_ci * TLB2 storage attribute fields. Those are:
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci *   TLB2:
3962306a36Sopenharmony_ci *   0...10    11   12   13   14   15   16...31
4062306a36Sopenharmony_ci *   no change WL1  IL1I IL1D IL2I IL2D no change
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * There are some constrains and options, to decide mapping software bits
4362306a36Sopenharmony_ci * into TLB entry.
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci *   - PRESENT *must* be in the bottom three bits because swap cache
4662306a36Sopenharmony_ci *     entries use the top 29 bits for TLB2.
4762306a36Sopenharmony_ci *
4862306a36Sopenharmony_ci *   - CACHE COHERENT bit (M) has no effect on original PPC440 cores,
4962306a36Sopenharmony_ci *     because it doesn't support SMP. However, some later 460 variants
5062306a36Sopenharmony_ci *     have -some- form of SMP support and so I keep the bit there for
5162306a36Sopenharmony_ci *     future use
5262306a36Sopenharmony_ci *
5362306a36Sopenharmony_ci * With the PPC 44x Linux implementation, the 0-11th LSBs of the PTE are used
5462306a36Sopenharmony_ci * for memory protection related functions (see PTE structure in
5562306a36Sopenharmony_ci * include/asm-ppc/mmu.h).  The _PAGE_XXX definitions in this file map to the
5662306a36Sopenharmony_ci * above bits.  Note that the bit values are CPU specific, not architecture
5762306a36Sopenharmony_ci * specific.
5862306a36Sopenharmony_ci *
5962306a36Sopenharmony_ci * The kernel PTE entry can be an ordinary PTE mapping a page or a special swap
6062306a36Sopenharmony_ci * PTE. In case of a swap PTE, LSB 2-24 are used to store information regarding
6162306a36Sopenharmony_ci * the swap entry. However LSB 0-1 still hold protection values, for example,
6262306a36Sopenharmony_ci * to distinguish swap PTEs from ordinary PTEs, and must be used with care.
6362306a36Sopenharmony_ci */
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define _PAGE_PRESENT	0x00000001		/* S: PTE valid */
6662306a36Sopenharmony_ci#define _PAGE_RW	0x00000002		/* S: Write permission */
6762306a36Sopenharmony_ci#define _PAGE_EXEC	0x00000004		/* H: Execute permission */
6862306a36Sopenharmony_ci#define _PAGE_ACCESSED	0x00000008		/* S: Page referenced */
6962306a36Sopenharmony_ci#define _PAGE_DIRTY	0x00000010		/* S: Page dirty */
7062306a36Sopenharmony_ci#define _PAGE_SPECIAL	0x00000020		/* S: Special page */
7162306a36Sopenharmony_ci#define _PAGE_USER	0x00000040		/* S: User page */
7262306a36Sopenharmony_ci#define _PAGE_ENDIAN	0x00000080		/* H: E bit */
7362306a36Sopenharmony_ci#define _PAGE_GUARDED	0x00000100		/* H: G bit */
7462306a36Sopenharmony_ci#define _PAGE_COHERENT	0x00000200		/* H: M bit */
7562306a36Sopenharmony_ci#define _PAGE_NO_CACHE	0x00000400		/* H: I bit */
7662306a36Sopenharmony_ci#define _PAGE_WRITETHRU	0x00000800		/* H: W bit */
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci/* No page size encoding in the linux PTE */
7962306a36Sopenharmony_ci#define _PAGE_PSIZE		0
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define _PAGE_KERNEL_RO		0
8262306a36Sopenharmony_ci#define _PAGE_KERNEL_ROX	_PAGE_EXEC
8362306a36Sopenharmony_ci#define _PAGE_KERNEL_RW		(_PAGE_DIRTY | _PAGE_RW)
8462306a36Sopenharmony_ci#define _PAGE_KERNEL_RWX	(_PAGE_DIRTY | _PAGE_RW | _PAGE_EXEC)
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* TODO: Add large page lowmem mapping support */
8762306a36Sopenharmony_ci#define _PMD_PRESENT	0
8862306a36Sopenharmony_ci#define _PMD_PRESENT_MASK (PAGE_MASK)
8962306a36Sopenharmony_ci#define _PMD_BAD	(~PAGE_MASK)
9062306a36Sopenharmony_ci#define _PMD_USER	0
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci/* ERPN in a PTE never gets cleared, ignore it */
9362306a36Sopenharmony_ci#define _PTE_NONE_MASK	0xffffffff00000000ULL
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci/*
9662306a36Sopenharmony_ci * We define 2 sets of base prot bits, one for basic pages (ie,
9762306a36Sopenharmony_ci * cacheable kernel and user pages) and one for non cacheable
9862306a36Sopenharmony_ci * pages. We always set _PAGE_COHERENT when SMP is enabled or
9962306a36Sopenharmony_ci * the processor might need it for DMA coherency.
10062306a36Sopenharmony_ci */
10162306a36Sopenharmony_ci#define _PAGE_BASE_NC	(_PAGE_PRESENT | _PAGE_ACCESSED)
10262306a36Sopenharmony_ci#if defined(CONFIG_SMP)
10362306a36Sopenharmony_ci#define _PAGE_BASE	(_PAGE_BASE_NC | _PAGE_COHERENT)
10462306a36Sopenharmony_ci#else
10562306a36Sopenharmony_ci#define _PAGE_BASE	(_PAGE_BASE_NC)
10662306a36Sopenharmony_ci#endif
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci/* Permission masks used to generate the __P and __S table */
10962306a36Sopenharmony_ci#define PAGE_NONE	__pgprot(_PAGE_BASE)
11062306a36Sopenharmony_ci#define PAGE_SHARED	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
11162306a36Sopenharmony_ci#define PAGE_SHARED_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
11262306a36Sopenharmony_ci#define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_USER)
11362306a36Sopenharmony_ci#define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
11462306a36Sopenharmony_ci#define PAGE_READONLY	__pgprot(_PAGE_BASE | _PAGE_USER)
11562306a36Sopenharmony_ci#define PAGE_READONLY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#endif /* __KERNEL__ */
11862306a36Sopenharmony_ci#endif /*  _ASM_POWERPC_NOHASH_32_PTE_44x_H */
119