18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_32_PTE_8xx_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_NOHASH_32_PTE_8xx_H
48c2ecf20Sopenharmony_ci#ifdef __KERNEL__
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/*
78c2ecf20Sopenharmony_ci * The PowerPC MPC8xx uses a TLB with hardware assisted, software tablewalk.
88c2ecf20Sopenharmony_ci * We also use the two level tables, but we can put the real bits in them
98c2ecf20Sopenharmony_ci * needed for the TLB and tablewalk.  These definitions require Mx_CTR.PPM = 0,
108c2ecf20Sopenharmony_ci * Mx_CTR.PPCS = 0, and MD_CTR.TWAM = 1.  The level 2 descriptor has
118c2ecf20Sopenharmony_ci * additional page protection (when Mx_CTR.PPCS = 1) that allows TLB hit
128c2ecf20Sopenharmony_ci * based upon user/super access.  The TLB does not have accessed nor write
138c2ecf20Sopenharmony_ci * protect.  We assume that if the TLB get loaded with an entry it is
148c2ecf20Sopenharmony_ci * accessed, and overload the changed bit for write protect.  We use
158c2ecf20Sopenharmony_ci * two bits in the software pte that are supposed to be set to zero in
168c2ecf20Sopenharmony_ci * the TLB entry (24 and 25) for these indicators.  Although the level 1
178c2ecf20Sopenharmony_ci * descriptor contains the guarded and writethrough/copyback bits, we can
188c2ecf20Sopenharmony_ci * set these at the page level since they get copied from the Mx_TWC
198c2ecf20Sopenharmony_ci * register when the TLB entry is loaded.  We will use bit 27 for guard, since
208c2ecf20Sopenharmony_ci * that is where it exists in the MD_TWC, and bit 26 for writethrough.
218c2ecf20Sopenharmony_ci * These will get masked from the level 2 descriptor at TLB load time, and
228c2ecf20Sopenharmony_ci * copied to the MD_TWC before it gets loaded.
238c2ecf20Sopenharmony_ci * Large page sizes added.  We currently support two sizes, 4K and 8M.
248c2ecf20Sopenharmony_ci * This also allows a TLB hander optimization because we can directly
258c2ecf20Sopenharmony_ci * load the PMD into MD_TWC.  The 8M pages are only used for kernel
268c2ecf20Sopenharmony_ci * mapping of well known areas.  The PMD (PGD) entries contain control
278c2ecf20Sopenharmony_ci * flags in addition to the address, so care must be taken that the
288c2ecf20Sopenharmony_ci * software no longer assumes these are only pointers.
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/* Definitions for 8xx embedded chips. */
328c2ecf20Sopenharmony_ci#define _PAGE_PRESENT	0x0001	/* V: Page is valid */
338c2ecf20Sopenharmony_ci#define _PAGE_NO_CACHE	0x0002	/* CI: cache inhibit */
348c2ecf20Sopenharmony_ci#define _PAGE_SH	0x0004	/* SH: No ASID (context) compare */
358c2ecf20Sopenharmony_ci#define _PAGE_SPS	0x0008	/* SPS: Small Page Size (1 if 16k, 512k or 8M)*/
368c2ecf20Sopenharmony_ci#define _PAGE_DIRTY	0x0100	/* C: page changed */
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* These 4 software bits must be masked out when the L2 entry is loaded
398c2ecf20Sopenharmony_ci * into the TLB.
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci#define _PAGE_GUARDED	0x0010	/* Copied to L1 G entry in DTLB */
428c2ecf20Sopenharmony_ci#define _PAGE_ACCESSED	0x0020	/* Copied to L1 APG 1 entry in I/DTLB */
438c2ecf20Sopenharmony_ci#define _PAGE_EXEC	0x0040	/* Copied to PP (bit 21) in ITLB */
448c2ecf20Sopenharmony_ci#define _PAGE_SPECIAL	0x0080	/* SW entry */
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define _PAGE_NA	0x0200	/* Supervisor NA, User no access */
478c2ecf20Sopenharmony_ci#define _PAGE_RO	0x0600	/* Supervisor RO, User no access */
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define _PAGE_HUGE	0x0800	/* Copied to L1 PS bit 29 */
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* cache related flags non existing on 8xx */
528c2ecf20Sopenharmony_ci#define _PAGE_COHERENT	0
538c2ecf20Sopenharmony_ci#define _PAGE_WRITETHRU	0
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RO		(_PAGE_SH | _PAGE_RO)
568c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_ROX	(_PAGE_SH | _PAGE_RO | _PAGE_EXEC)
578c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RW		(_PAGE_SH | _PAGE_DIRTY)
588c2ecf20Sopenharmony_ci#define _PAGE_KERNEL_RWX	(_PAGE_SH | _PAGE_DIRTY | _PAGE_EXEC)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define _PMD_PRESENT	0x0001
618c2ecf20Sopenharmony_ci#define _PMD_PRESENT_MASK	_PMD_PRESENT
628c2ecf20Sopenharmony_ci#define _PMD_BAD	0x0f90
638c2ecf20Sopenharmony_ci#define _PMD_PAGE_MASK	0x000c
648c2ecf20Sopenharmony_ci#define _PMD_PAGE_8M	0x000c
658c2ecf20Sopenharmony_ci#define _PMD_PAGE_512K	0x0004
668c2ecf20Sopenharmony_ci#define _PMD_ACCESSED	0x0020	/* APG 1 */
678c2ecf20Sopenharmony_ci#define _PMD_USER	0x0040	/* APG 2 */
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define _PTE_NONE_MASK	0
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_16K_PAGES
728c2ecf20Sopenharmony_ci#define _PAGE_PSIZE	_PAGE_SPS
738c2ecf20Sopenharmony_ci#else
748c2ecf20Sopenharmony_ci#define _PAGE_PSIZE		0
758c2ecf20Sopenharmony_ci#endif
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define _PAGE_BASE_NC	(_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_PSIZE)
788c2ecf20Sopenharmony_ci#define _PAGE_BASE	(_PAGE_BASE_NC)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* Permission masks used to generate the __P and __S table */
818c2ecf20Sopenharmony_ci#define PAGE_NONE	__pgprot(_PAGE_BASE | _PAGE_NA)
828c2ecf20Sopenharmony_ci#define PAGE_SHARED	__pgprot(_PAGE_BASE)
838c2ecf20Sopenharmony_ci#define PAGE_SHARED_X	__pgprot(_PAGE_BASE | _PAGE_EXEC)
848c2ecf20Sopenharmony_ci#define PAGE_COPY	__pgprot(_PAGE_BASE | _PAGE_RO)
858c2ecf20Sopenharmony_ci#define PAGE_COPY_X	__pgprot(_PAGE_BASE | _PAGE_RO | _PAGE_EXEC)
868c2ecf20Sopenharmony_ci#define PAGE_READONLY	__pgprot(_PAGE_BASE | _PAGE_RO)
878c2ecf20Sopenharmony_ci#define PAGE_READONLY_X	__pgprot(_PAGE_BASE | _PAGE_RO | _PAGE_EXEC)
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
908c2ecf20Sopenharmony_cistatic inline pte_t pte_wrprotect(pte_t pte)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	return __pte(pte_val(pte) | _PAGE_RO);
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define pte_wrprotect pte_wrprotect
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistatic inline int pte_read(pte_t pte)
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci	return (pte_val(pte) & _PAGE_RO) != _PAGE_NA;
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define pte_read pte_read
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic inline int pte_write(pte_t pte)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	return !(pte_val(pte) & _PAGE_RO);
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define pte_write pte_write
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic inline pte_t pte_mkwrite(pte_t pte)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	return __pte(pte_val(pte) & ~_PAGE_RO);
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define pte_mkwrite pte_mkwrite
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic inline bool pte_user(pte_t pte)
1198c2ecf20Sopenharmony_ci{
1208c2ecf20Sopenharmony_ci	return !(pte_val(pte) & _PAGE_SH);
1218c2ecf20Sopenharmony_ci}
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define pte_user pte_user
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistatic inline pte_t pte_mkprivileged(pte_t pte)
1268c2ecf20Sopenharmony_ci{
1278c2ecf20Sopenharmony_ci	return __pte(pte_val(pte) | _PAGE_SH);
1288c2ecf20Sopenharmony_ci}
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define pte_mkprivileged pte_mkprivileged
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline pte_t pte_mkuser(pte_t pte)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	return __pte(pte_val(pte) & ~_PAGE_SH);
1358c2ecf20Sopenharmony_ci}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define pte_mkuser pte_mkuser
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistatic inline pte_t pte_mkhuge(pte_t pte)
1408c2ecf20Sopenharmony_ci{
1418c2ecf20Sopenharmony_ci	return __pte(pte_val(pte) | _PAGE_SPS | _PAGE_HUGE);
1428c2ecf20Sopenharmony_ci}
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#define pte_mkhuge pte_mkhuge
1458c2ecf20Sopenharmony_ci#endif
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1488c2ecf20Sopenharmony_ci#endif /*  _ASM_POWERPC_NOHASH_32_PTE_8xx_H */
149