1fcf5ef2aSThomas Huth #ifndef MMU_HASH64_H
2fcf5ef2aSThomas Huth #define MMU_HASH64_H
3fcf5ef2aSThomas Huth
4fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
5fcf5ef2aSThomas Huth
6fcf5ef2aSThomas Huth #ifdef TARGET_PPC64
7fad866daSMarkus Armbruster void dump_slb(PowerPCCPU *cpu);
8fcf5ef2aSThomas Huth int ppc_store_slb(PowerPCCPU *cpu, target_ulong slot,
9fcf5ef2aSThomas Huth target_ulong esid, target_ulong vsid);
1051806b54SRichard Henderson bool ppc_hash64_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
1103695a98SBruno Larsen (billionai) hwaddr *raddrp, int *psizep, int *protp, int mmu_idx,
1251806b54SRichard Henderson bool guest_visible);
13fcf5ef2aSThomas Huth void ppc_hash64_tlb_flush_hpte(PowerPCCPU *cpu,
14fcf5ef2aSThomas Huth target_ulong pte_index,
15fcf5ef2aSThomas Huth target_ulong pte0, target_ulong pte1);
16fcf5ef2aSThomas Huth unsigned ppc_hash64_hpte_page_shift_noslb(PowerPCCPU *cpu,
17fcf5ef2aSThomas Huth uint64_t pte0, uint64_t pte1);
18a059471dSDavid Gibson void ppc_hash64_init(PowerPCCPU *cpu);
19a059471dSDavid Gibson void ppc_hash64_finalize(PowerPCCPU *cpu);
20fcf5ef2aSThomas Huth #endif
21fcf5ef2aSThomas Huth
22fcf5ef2aSThomas Huth /*
23fcf5ef2aSThomas Huth * SLB definitions
24fcf5ef2aSThomas Huth */
25fcf5ef2aSThomas Huth
26fcf5ef2aSThomas Huth /* Bits in the SLB ESID word */
27fcf5ef2aSThomas Huth #define SLB_ESID_ESID 0xFFFFFFFFF0000000ULL
28fcf5ef2aSThomas Huth #define SLB_ESID_V 0x0000000008000000ULL /* valid */
29fcf5ef2aSThomas Huth
30fcf5ef2aSThomas Huth /* Bits in the SLB VSID word */
31fcf5ef2aSThomas Huth #define SLB_VSID_SHIFT 12
32fcf5ef2aSThomas Huth #define SLB_VSID_SHIFT_1T 24
33fcf5ef2aSThomas Huth #define SLB_VSID_SSIZE_SHIFT 62
34fcf5ef2aSThomas Huth #define SLB_VSID_B 0xc000000000000000ULL
35fcf5ef2aSThomas Huth #define SLB_VSID_B_256M 0x0000000000000000ULL
36fcf5ef2aSThomas Huth #define SLB_VSID_B_1T 0x4000000000000000ULL
37fcf5ef2aSThomas Huth #define SLB_VSID_VSID 0x3FFFFFFFFFFFF000ULL
38fcf5ef2aSThomas Huth #define SLB_VSID_VRMA (0x0001FFFFFF000000ULL | SLB_VSID_B_1T)
39fcf5ef2aSThomas Huth #define SLB_VSID_PTEM (SLB_VSID_B | SLB_VSID_VSID)
40fcf5ef2aSThomas Huth #define SLB_VSID_KS 0x0000000000000800ULL
41fcf5ef2aSThomas Huth #define SLB_VSID_KP 0x0000000000000400ULL
42fcf5ef2aSThomas Huth #define SLB_VSID_N 0x0000000000000200ULL /* no-execute */
43fcf5ef2aSThomas Huth #define SLB_VSID_L 0x0000000000000100ULL
440e2a3ec3SNicholas Piggin #define SLB_VSID_L_SHIFT PPC_BIT_NR(55)
45fcf5ef2aSThomas Huth #define SLB_VSID_C 0x0000000000000080ULL /* class */
46fcf5ef2aSThomas Huth #define SLB_VSID_LP 0x0000000000000030ULL
470e2a3ec3SNicholas Piggin #define SLB_VSID_LP_SHIFT PPC_BIT_NR(59)
48fcf5ef2aSThomas Huth #define SLB_VSID_ATTR 0x0000000000000FFFULL
49fcf5ef2aSThomas Huth #define SLB_VSID_LLP_MASK (SLB_VSID_L | SLB_VSID_LP)
50fcf5ef2aSThomas Huth #define SLB_VSID_4K 0x0000000000000000ULL
51fcf5ef2aSThomas Huth #define SLB_VSID_64K 0x0000000000000110ULL
52fcf5ef2aSThomas Huth #define SLB_VSID_16M 0x0000000000000100ULL
53fcf5ef2aSThomas Huth #define SLB_VSID_16G 0x0000000000000120ULL
54fcf5ef2aSThomas Huth
55fcf5ef2aSThomas Huth /*
56fcf5ef2aSThomas Huth * Hash page table definitions
57fcf5ef2aSThomas Huth */
58fcf5ef2aSThomas Huth
59e78308fdSDavid Gibson #define SDR_64_HTABORG 0x0FFFFFFFFFFC0000ULL
6036778660SDavid Gibson #define SDR_64_HTABSIZE 0x000000000000001FULL
6136778660SDavid Gibson
623367c62fSBenjamin Herrenschmidt #define PATE0_HTABORG 0x0FFFFFFFFFFC0000ULL
630e2a3ec3SNicholas Piggin #define PATE0_PS PPC_BITMASK(56, 58)
640e2a3ec3SNicholas Piggin #define PATE0_GET_PS(dw0) (((dw0) & PATE0_PS) >> PPC_BIT_NR(58))
650e2a3ec3SNicholas Piggin
66fcf5ef2aSThomas Huth #define HPTES_PER_GROUP 8
67fcf5ef2aSThomas Huth #define HASH_PTE_SIZE_64 16
68fcf5ef2aSThomas Huth #define HASH_PTEG_SIZE_64 (HASH_PTE_SIZE_64 * HPTES_PER_GROUP)
69fcf5ef2aSThomas Huth
700b0b8310SDavid Gibson #define HPTE64_V_SSIZE SLB_VSID_B
710b0b8310SDavid Gibson #define HPTE64_V_SSIZE_256M SLB_VSID_B_256M
720b0b8310SDavid Gibson #define HPTE64_V_SSIZE_1T SLB_VSID_B_1T
73fcf5ef2aSThomas Huth #define HPTE64_V_SSIZE_SHIFT 62
74fcf5ef2aSThomas Huth #define HPTE64_V_AVPN_SHIFT 7
75fcf5ef2aSThomas Huth #define HPTE64_V_AVPN 0x3fffffffffffff80ULL
76fcf5ef2aSThomas Huth #define HPTE64_V_AVPN_VAL(x) (((x) & HPTE64_V_AVPN) >> HPTE64_V_AVPN_SHIFT)
77fcf5ef2aSThomas Huth #define HPTE64_V_COMPARE(x, y) (!(((x) ^ (y)) & 0xffffffffffffff83ULL))
780b0b8310SDavid Gibson #define HPTE64_V_BOLTED 0x0000000000000010ULL
79fcf5ef2aSThomas Huth #define HPTE64_V_LARGE 0x0000000000000004ULL
80fcf5ef2aSThomas Huth #define HPTE64_V_SECONDARY 0x0000000000000002ULL
81fcf5ef2aSThomas Huth #define HPTE64_V_VALID 0x0000000000000001ULL
82fcf5ef2aSThomas Huth
83fcf5ef2aSThomas Huth #define HPTE64_R_PP0 0x8000000000000000ULL
84fcf5ef2aSThomas Huth #define HPTE64_R_TS 0x4000000000000000ULL
85fcf5ef2aSThomas Huth #define HPTE64_R_KEY_HI 0x3000000000000000ULL
86fcf5ef2aSThomas Huth #define HPTE64_R_RPN_SHIFT 12
87fcf5ef2aSThomas Huth #define HPTE64_R_RPN 0x0ffffffffffff000ULL
88fcf5ef2aSThomas Huth #define HPTE64_R_FLAGS 0x00000000000003ffULL
89fcf5ef2aSThomas Huth #define HPTE64_R_PP 0x0000000000000003ULL
90fcf5ef2aSThomas Huth #define HPTE64_R_N 0x0000000000000004ULL
91fcf5ef2aSThomas Huth #define HPTE64_R_G 0x0000000000000008ULL
92fcf5ef2aSThomas Huth #define HPTE64_R_M 0x0000000000000010ULL
93fcf5ef2aSThomas Huth #define HPTE64_R_I 0x0000000000000020ULL
94fcf5ef2aSThomas Huth #define HPTE64_R_W 0x0000000000000040ULL
95fcf5ef2aSThomas Huth #define HPTE64_R_WIMG 0x0000000000000078ULL
96fcf5ef2aSThomas Huth #define HPTE64_R_C 0x0000000000000080ULL
97fcf5ef2aSThomas Huth #define HPTE64_R_R 0x0000000000000100ULL
98fcf5ef2aSThomas Huth #define HPTE64_R_KEY_LO 0x0000000000000e00ULL
996925f12fSSuraj Jitindar Singh #define HPTE64_R_KEY(x) ((((x) & HPTE64_R_KEY_HI) >> 57) | \
100fcf5ef2aSThomas Huth (((x) & HPTE64_R_KEY_LO) >> 9))
101fcf5ef2aSThomas Huth
102fcf5ef2aSThomas Huth #define HPTE64_V_1TB_SEG 0x4000000000000000ULL
103fcf5ef2aSThomas Huth #define HPTE64_V_VRMA_MASK 0x4001ffffff000000ULL
104fcf5ef2aSThomas Huth
1057bf00dfbSLeandro Lupori /* PTE offsets */
1067bf00dfbSLeandro Lupori #define HPTE64_DW1 (HASH_PTE_SIZE_64 / 2)
1077bf00dfbSLeandro Lupori #define HPTE64_DW1_R (HPTE64_DW1 + 6)
1087bf00dfbSLeandro Lupori #define HPTE64_DW1_C (HPTE64_DW1 + 7)
1097bf00dfbSLeandro Lupori
11034525595SBenjamin Herrenschmidt /* Format changes for ARCH v3 */
11134525595SBenjamin Herrenschmidt #define HPTE64_V_COMMON_BITS 0x000fffffffffffffULL
11234525595SBenjamin Herrenschmidt #define HPTE64_R_3_0_SSIZE_SHIFT 58
11334525595SBenjamin Herrenschmidt #define HPTE64_R_3_0_SSIZE_MASK (3ULL << HPTE64_R_3_0_SSIZE_SHIFT)
11434525595SBenjamin Herrenschmidt
1157222b94aSDavid Gibson struct ppc_hash_pte64 {
116fcf5ef2aSThomas Huth uint64_t pte0, pte1;
1177222b94aSDavid Gibson };
1187222b94aSDavid Gibson
1197222b94aSDavid Gibson const ppc_hash_pte64_t *ppc_hash64_map_hptes(PowerPCCPU *cpu,
1207222b94aSDavid Gibson hwaddr ptex, int n);
1217222b94aSDavid Gibson void ppc_hash64_unmap_hptes(PowerPCCPU *cpu, const ppc_hash_pte64_t *hptes,
1227222b94aSDavid Gibson hwaddr ptex, int n);
123*14a43ab3SBALATON Zoltan bool ppc_hash64_valid_ptex(PowerPCCPU *cpu, target_ulong ptex);
1247222b94aSDavid Gibson
ppc_hash64_hpte0(PowerPCCPU * cpu,const ppc_hash_pte64_t * hptes,int i)1257222b94aSDavid Gibson static inline uint64_t ppc_hash64_hpte0(PowerPCCPU *cpu,
1267222b94aSDavid Gibson const ppc_hash_pte64_t *hptes, int i)
1277222b94aSDavid Gibson {
1287222b94aSDavid Gibson return ldq_p(&(hptes[i].pte0));
1297222b94aSDavid Gibson }
1307222b94aSDavid Gibson
ppc_hash64_hpte1(PowerPCCPU * cpu,const ppc_hash_pte64_t * hptes,int i)1317222b94aSDavid Gibson static inline uint64_t ppc_hash64_hpte1(PowerPCCPU *cpu,
1327222b94aSDavid Gibson const ppc_hash_pte64_t *hptes, int i)
1337222b94aSDavid Gibson {
1347222b94aSDavid Gibson return ldq_p(&(hptes[i].pte1));
1357222b94aSDavid Gibson }
136fcf5ef2aSThomas Huth
137b07c59f7SDavid Gibson /*
138b07c59f7SDavid Gibson * MMU Options
139b07c59f7SDavid Gibson */
140b07c59f7SDavid Gibson
141b07c59f7SDavid Gibson struct PPCHash64PageSize {
142b07c59f7SDavid Gibson uint32_t page_shift; /* Page shift (or 0) */
143b07c59f7SDavid Gibson uint32_t pte_enc; /* Encoding in the HPTE (>>12) */
144b07c59f7SDavid Gibson };
145b07c59f7SDavid Gibson typedef struct PPCHash64PageSize PPCHash64PageSize;
146b07c59f7SDavid Gibson
147b07c59f7SDavid Gibson struct PPCHash64SegmentPageSizes {
148b07c59f7SDavid Gibson uint32_t page_shift; /* Base page shift of segment (or 0) */
149b07c59f7SDavid Gibson uint32_t slb_enc; /* SLB encoding for BookS */
150b07c59f7SDavid Gibson PPCHash64PageSize enc[PPC_PAGE_SIZES_MAX_SZ];
151b07c59f7SDavid Gibson };
152b07c59f7SDavid Gibson
153b07c59f7SDavid Gibson struct PPCHash64Options {
15458969eeeSDavid Gibson #define PPC_HASH64_1TSEG 0x00001
15558969eeeSDavid Gibson #define PPC_HASH64_AMR 0x00002
15626cd35b8SDavid Gibson #define PPC_HASH64_CI_LARGEPAGE 0x00004
15758969eeeSDavid Gibson unsigned flags;
15867d7d66fSDavid Gibson unsigned slb_size;
159b07c59f7SDavid Gibson PPCHash64SegmentPageSizes sps[PPC_PAGE_SIZES_MAX_SZ];
160b07c59f7SDavid Gibson };
161b07c59f7SDavid Gibson
16221e405f1SDavid Gibson extern const PPCHash64Options ppc_hash64_opts_basic;
163b07c59f7SDavid Gibson extern const PPCHash64Options ppc_hash64_opts_POWER7;
164b07c59f7SDavid Gibson
ppc_hash64_has(PowerPCCPU * cpu,unsigned feature)16558969eeeSDavid Gibson static inline bool ppc_hash64_has(PowerPCCPU *cpu, unsigned feature)
16658969eeeSDavid Gibson {
16758969eeeSDavid Gibson return !!(cpu->hash64_opts->flags & feature);
16858969eeeSDavid Gibson }
16958969eeeSDavid Gibson
170fcf5ef2aSThomas Huth #endif /* CONFIG_USER_ONLY */
171fcf5ef2aSThomas Huth
172a059471dSDavid Gibson #if defined(CONFIG_USER_ONLY) || !defined(TARGET_PPC64)
ppc_hash64_init(PowerPCCPU * cpu)173a059471dSDavid Gibson static inline void ppc_hash64_init(PowerPCCPU *cpu)
174a059471dSDavid Gibson {
175a059471dSDavid Gibson }
ppc_hash64_finalize(PowerPCCPU * cpu)176a059471dSDavid Gibson static inline void ppc_hash64_finalize(PowerPCCPU *cpu)
177a059471dSDavid Gibson {
178a059471dSDavid Gibson }
179a059471dSDavid Gibson #endif
180a059471dSDavid Gibson
181fcf5ef2aSThomas Huth #endif /* MMU_HASH64_H */
182