18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_BOOK3S_32_MMU_HASH_H_
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_BOOK3S_32_MMU_HASH_H_
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci * 32-bit hash table MMU support
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * BATs
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* Block size masks */
148c2ecf20Sopenharmony_ci#define BL_128K	0x000
158c2ecf20Sopenharmony_ci#define BL_256K 0x001
168c2ecf20Sopenharmony_ci#define BL_512K 0x003
178c2ecf20Sopenharmony_ci#define BL_1M   0x007
188c2ecf20Sopenharmony_ci#define BL_2M   0x00F
198c2ecf20Sopenharmony_ci#define BL_4M   0x01F
208c2ecf20Sopenharmony_ci#define BL_8M   0x03F
218c2ecf20Sopenharmony_ci#define BL_16M  0x07F
228c2ecf20Sopenharmony_ci#define BL_32M  0x0FF
238c2ecf20Sopenharmony_ci#define BL_64M  0x1FF
248c2ecf20Sopenharmony_ci#define BL_128M 0x3FF
258c2ecf20Sopenharmony_ci#define BL_256M 0x7FF
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* BAT Access Protection */
288c2ecf20Sopenharmony_ci#define BPP_XX	0x00		/* No access */
298c2ecf20Sopenharmony_ci#define BPP_RX	0x01		/* Read only */
308c2ecf20Sopenharmony_ci#define BPP_RW	0x02		/* Read/write */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
338c2ecf20Sopenharmony_ci/* Contort a phys_addr_t into the right format/bits for a BAT */
348c2ecf20Sopenharmony_ci#ifdef CONFIG_PHYS_64BIT
358c2ecf20Sopenharmony_ci#define BAT_PHYS_ADDR(x) ((u32)((x & 0x00000000fffe0000ULL) | \
368c2ecf20Sopenharmony_ci				((x & 0x0000000e00000000ULL) >> 24) | \
378c2ecf20Sopenharmony_ci				((x & 0x0000000100000000ULL) >> 30)))
388c2ecf20Sopenharmony_ci#define PHYS_BAT_ADDR(x) (((u64)(x) & 0x00000000fffe0000ULL) | \
398c2ecf20Sopenharmony_ci			  (((u64)(x) << 24) & 0x0000000e00000000ULL) | \
408c2ecf20Sopenharmony_ci			  (((u64)(x) << 30) & 0x0000000100000000ULL))
418c2ecf20Sopenharmony_ci#else
428c2ecf20Sopenharmony_ci#define BAT_PHYS_ADDR(x) (x)
438c2ecf20Sopenharmony_ci#define PHYS_BAT_ADDR(x) ((x) & 0xfffe0000)
448c2ecf20Sopenharmony_ci#endif
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct ppc_bat {
478c2ecf20Sopenharmony_ci	u32 batu;
488c2ecf20Sopenharmony_ci	u32 batl;
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/*
538c2ecf20Sopenharmony_ci * Hash table
548c2ecf20Sopenharmony_ci */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* Values for PP (assumes Ks=0, Kp=1) */
578c2ecf20Sopenharmony_ci#define PP_RWXX	0	/* Supervisor read/write, User none */
588c2ecf20Sopenharmony_ci#define PP_RWRX 1	/* Supervisor read/write, User read */
598c2ecf20Sopenharmony_ci#define PP_RWRW 2	/* Supervisor read/write, User read/write */
608c2ecf20Sopenharmony_ci#define PP_RXRX 3	/* Supervisor read,       User read */
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/* Values for Segment Registers */
638c2ecf20Sopenharmony_ci#define SR_NX	0x10000000	/* No Execute */
648c2ecf20Sopenharmony_ci#define SR_KP	0x20000000	/* User key */
658c2ecf20Sopenharmony_ci#define SR_KS	0x40000000	/* Supervisor key */
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/*
708c2ecf20Sopenharmony_ci * Hardware Page Table Entry
718c2ecf20Sopenharmony_ci * Note that the xpn and x bitfields are used only by processors that
728c2ecf20Sopenharmony_ci * support extended addressing; otherwise, those bits are reserved.
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_cistruct hash_pte {
758c2ecf20Sopenharmony_ci	unsigned long v:1;	/* Entry is valid */
768c2ecf20Sopenharmony_ci	unsigned long vsid:24;	/* Virtual segment identifier */
778c2ecf20Sopenharmony_ci	unsigned long h:1;	/* Hash algorithm indicator */
788c2ecf20Sopenharmony_ci	unsigned long api:6;	/* Abbreviated page index */
798c2ecf20Sopenharmony_ci	unsigned long rpn:20;	/* Real (physical) page number */
808c2ecf20Sopenharmony_ci	unsigned long xpn:3;	/* Real page number bits 0-2, optional */
818c2ecf20Sopenharmony_ci	unsigned long r:1;	/* Referenced */
828c2ecf20Sopenharmony_ci	unsigned long c:1;	/* Changed */
838c2ecf20Sopenharmony_ci	unsigned long w:1;	/* Write-thru cache mode */
848c2ecf20Sopenharmony_ci	unsigned long i:1;	/* Cache inhibited */
858c2ecf20Sopenharmony_ci	unsigned long m:1;	/* Memory coherence */
868c2ecf20Sopenharmony_ci	unsigned long g:1;	/* Guarded */
878c2ecf20Sopenharmony_ci	unsigned long x:1;	/* Real page number bit 3, optional */
888c2ecf20Sopenharmony_ci	unsigned long pp:2;	/* Page protection */
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_citypedef struct {
928c2ecf20Sopenharmony_ci	unsigned long id;
938c2ecf20Sopenharmony_ci	unsigned long vdso_base;
948c2ecf20Sopenharmony_ci} mm_context_t;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_civoid update_bats(void);
978c2ecf20Sopenharmony_cistatic inline void cleanup_cpu_mmu_context(void) { };
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* patch sites */
1008c2ecf20Sopenharmony_ciextern s32 patch__hash_page_A0, patch__hash_page_A1, patch__hash_page_A2;
1018c2ecf20Sopenharmony_ciextern s32 patch__hash_page_B, patch__hash_page_C;
1028c2ecf20Sopenharmony_ciextern s32 patch__flush_hash_A0, patch__flush_hash_A1, patch__flush_hash_A2;
1038c2ecf20Sopenharmony_ciextern s32 patch__flush_hash_B;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ciint __init find_free_bat(void);
1068c2ecf20Sopenharmony_ciunsigned int bat_block_size(unsigned long base, unsigned long top);
1078c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* We happily ignore the smaller BATs on 601, we don't actually use
1108c2ecf20Sopenharmony_ci * those definitions on hash32 at the moment anyway
1118c2ecf20Sopenharmony_ci */
1128c2ecf20Sopenharmony_ci#define mmu_virtual_psize	MMU_PAGE_4K
1138c2ecf20Sopenharmony_ci#define mmu_linear_psize	MMU_PAGE_256M
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_BOOK3S_32_MMU_HASH_H_ */
116