18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_32_PTE_44x_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_NOHASH_32_PTE_44x_H
48c2ecf20Sopenharmony_ci#ifdef __KERNEL__
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/*
78c2ecf20Sopenharmony_ci * Definitions for PPC440
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Because of the 3 word TLB entries to support 36-bit addressing,
108c2ecf20Sopenharmony_ci * the attribute are difficult to map in such a fashion that they
118c2ecf20Sopenharmony_ci * are easily loaded during exception processing.  I decided to
128c2ecf20Sopenharmony_ci * organize the entry so the ERPN is the only portion in the
138c2ecf20Sopenharmony_ci * upper word of the PTE and the attribute bits below are packed
148c2ecf20Sopenharmony_ci * in as sensibly as they can be in the area below a 4KB page size
158c2ecf20Sopenharmony_ci * oriented RPN.  This at least makes it easy to load the RPN and
168c2ecf20Sopenharmony_ci * ERPN fields in the TLB. -Matt
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * This isn't entirely true anymore, at least some bits are now
198c2ecf20Sopenharmony_ci * easier to move into the TLB from the PTE. -BenH.
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * Note that these bits preclude future use of a page size
228c2ecf20Sopenharmony_ci * less than 4KB.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * PPC 440 core has following TLB attribute fields;
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci *   TLB1:
288c2ecf20Sopenharmony_ci *   0  1  2  3  4  ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
298c2ecf20Sopenharmony_ci *   RPN.................................  -  -  -  -  -  - ERPN.......
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci *   TLB2:
328c2ecf20Sopenharmony_ci *   0  1  2  3  4  ... 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
338c2ecf20Sopenharmony_ci *   -  -  -  -  -    - U0 U1 U2 U3 W  I  M  G  E   - UX UW UR SX SW SR
348c2ecf20Sopenharmony_ci *
358c2ecf20Sopenharmony_ci * Newer 440 cores (440x6 as used on AMCC 460EX/460GT) have additional
368c2ecf20Sopenharmony_ci * TLB2 storage attribute fields. Those are:
378c2ecf20Sopenharmony_ci *
388c2ecf20Sopenharmony_ci *   TLB2:
398c2ecf20Sopenharmony_ci *   0...10    11   12   13   14   15   16...31
408c2ecf20Sopenharmony_ci *   no change WL1  IL1I IL1D IL2I IL2D no change
418c2ecf20Sopenharmony_ci *
428c2ecf20Sopenharmony_ci * There are some constrains and options, to decide mapping software bits
438c2ecf20Sopenharmony_ci * into TLB entry.
448c2ecf20Sopenharmony_ci *
458c2ecf20Sopenharmony_ci *   - PRESENT *must* be in the bottom three bits because swap cache
468c2ecf20Sopenharmony_ci *     entries use the top 29 bits for TLB2.
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci *   - CACHE COHERENT bit (M) has no effect on original PPC440 cores,
498c2ecf20Sopenharmony_ci *     because it doesn't support SMP. However, some later 460 variants
508c2ecf20Sopenharmony_ci *     have -some- form of SMP support and so I keep the bit there for
518c2ecf20Sopenharmony_ci *     future use
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * With the PPC 44x Linux implementation, the 0-11th LSBs of the PTE are used
548c2ecf20Sopenharmony_ci * for memory protection related functions (see PTE structure in
558c2ecf20Sopenharmony_ci * include/asm-ppc/mmu.h).  The _PAGE_XXX definitions in this file map to the
568c2ecf20Sopenharmony_ci * above bits.  Note that the bit values are CPU specific, not architecture
578c2ecf20Sopenharmony_ci * specific.
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * The kernel PTE entry holds an arch-dependent swp_entry structure under
608c2ecf20Sopenharmony_ci * certain situations. In other words, in such situations some portion of
618c2ecf20Sopenharmony_ci * the PTE bits are used as a swp_entry. In the PPC implementation, the
628c2ecf20Sopenharmony_ci * 3-24th LSB are shared with swp_entry, however the 0-2nd three LSB still
638c2ecf20Sopenharmony_ci * hold protection values. That means the three protection bits are
648c2ecf20Sopenharmony_ci * reserved for both PTE and SWAP entry at the most significant three
658c2ecf20Sopenharmony_ci * LSBs.
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci * There are three protection bits available for SWAP entry:
688c2ecf20Sopenharmony_ci *	_PAGE_PRESENT
698c2ecf20Sopenharmony_ci *	_PAGE_HASHPTE (if HW has)
708c2ecf20Sopenharmony_ci *
718c2ecf20Sopenharmony_ci * So those three bits have to be inside of 0-2nd LSB of PTE.
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define _PAGE_PRESENT	0x00000001		/* S: PTE valid */
768c2ecf20Sopenharmony_ci#define _PAGE_RW	0x00000002		/* S: Write permission */
778c2ecf20Sopenharmony_ci#define _PAGE_EXEC	0x00000004		/* H: Execute permission */
788c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED	0x00000008		/* S: Page referenced */
798c2ecf20Sopenharmony_ci#define _PAGE_DIRTY	0x00000010		/* S: Page dirty */
808c2ecf20Sopenharmony_ci#define _PAGE_SPECIAL	0x00000020		/* S: Special page */
818c2ecf20Sopenharmony_ci#define _PAGE_USER	0x00000040		/* S: User page */
828c2ecf20Sopenharmony_ci#define _PAGE_ENDIAN	0x00000080		/* H: E bit */
838c2ecf20Sopenharmony_ci#define _PAGE_GUARDED	0x00000100		/* H: G bit */
848c2ecf20Sopenharmony_ci#define _PAGE_COHERENT	0x00000200		/* H: M bit */
858c2ecf20Sopenharmony_ci#define _PAGE_NO_CACHE	0x00000400		/* H: I bit */
868c2ecf20Sopenharmony_ci#define _PAGE_WRITETHRU	0x00000800		/* H: W bit */
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* No page size encoding in the linux PTE */
898c2ecf20Sopenharmony_ci#define _PAGE_PSIZE		0
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RO		0
928c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_ROX	_PAGE_EXEC
938c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RW		(_PAGE_DIRTY | _PAGE_RW)
948c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RWX	(_PAGE_DIRTY | _PAGE_RW | _PAGE_EXEC)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* TODO: Add large page lowmem mapping support */
978c2ecf20Sopenharmony_ci#define _PMD_PRESENT	0
988c2ecf20Sopenharmony_ci#define _PMD_PRESENT_MASK (PAGE_MASK)
998c2ecf20Sopenharmony_ci#define _PMD_BAD	(~PAGE_MASK)
1008c2ecf20Sopenharmony_ci#define _PMD_USER	0
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/* ERPN in a PTE never gets cleared, ignore it */
1038c2ecf20Sopenharmony_ci#define _PTE_NONE_MASK	0xffffffff00000000ULL
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/*
1068c2ecf20Sopenharmony_ci * We define 2 sets of base prot bits, one for basic pages (ie,
1078c2ecf20Sopenharmony_ci * cacheable kernel and user pages) and one for non cacheable
1088c2ecf20Sopenharmony_ci * pages. We always set _PAGE_COHERENT when SMP is enabled or
1098c2ecf20Sopenharmony_ci * the processor might need it for DMA coherency.
1108c2ecf20Sopenharmony_ci */
1118c2ecf20Sopenharmony_ci#define _PAGE_BASE_NC	(_PAGE_PRESENT | _PAGE_ACCESSED)
1128c2ecf20Sopenharmony_ci#if defined(CONFIG_SMP)
1138c2ecf20Sopenharmony_ci#define _PAGE_BASE	(_PAGE_BASE_NC | _PAGE_COHERENT)
1148c2ecf20Sopenharmony_ci#else
1158c2ecf20Sopenharmony_ci#define _PAGE_BASE	(_PAGE_BASE_NC)
1168c2ecf20Sopenharmony_ci#endif
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* Permission masks used to generate the __P and __S table */
1198c2ecf20Sopenharmony_ci#define PAGE_NONE	__pgprot(_PAGE_BASE)
1208c2ecf20Sopenharmony_ci#define PAGE_SHARED	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW)
1218c2ecf20Sopenharmony_ci#define PAGE_SHARED_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC)
1228c2ecf20Sopenharmony_ci#define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_USER)
1238c2ecf20Sopenharmony_ci#define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
1248c2ecf20Sopenharmony_ci#define PAGE_READONLY	__pgprot(_PAGE_BASE | _PAGE_USER)
1258c2ecf20Sopenharmony_ci#define PAGE_READONLY_X	__pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC)
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1288c2ecf20Sopenharmony_ci#endif /*  _ASM_POWERPC_NOHASH_32_PTE_44x_H */
129