1fcf5ef2aSThomas Huth #ifndef MMU_HASH32_H
2fcf5ef2aSThomas Huth #define MMU_HASH32_H
3fcf5ef2aSThomas Huth
4fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY
5fcf5ef2aSThomas Huth
651806b54SRichard Henderson bool ppc_hash32_xlate(PowerPCCPU *cpu, vaddr eaddr, MMUAccessType access_type,
7d423baf9SBruno Larsen (billionai) hwaddr *raddrp, int *psizep, int *protp, int mmu_idx,
851806b54SRichard Henderson bool guest_visible);
9fcf5ef2aSThomas Huth
10fcf5ef2aSThomas Huth /*
11fcf5ef2aSThomas Huth * Segment register definitions
12fcf5ef2aSThomas Huth */
13fcf5ef2aSThomas Huth
14fcf5ef2aSThomas Huth #define SR32_T 0x80000000
15fcf5ef2aSThomas Huth #define SR32_KS 0x40000000
16fcf5ef2aSThomas Huth #define SR32_KP 0x20000000
17fcf5ef2aSThomas Huth #define SR32_NX 0x10000000
18fcf5ef2aSThomas Huth #define SR32_VSID 0x00ffffff
19fcf5ef2aSThomas Huth
20fcf5ef2aSThomas Huth /*
21fcf5ef2aSThomas Huth * Block Address Translation (BAT) definitions
22fcf5ef2aSThomas Huth */
23fcf5ef2aSThomas Huth
24ba1b5df0SFabiano Rosas #define BATU32_BEPIU 0xf0000000
25ba1b5df0SFabiano Rosas #define BATU32_BEPIL 0x0ffe0000
26fcf5ef2aSThomas Huth #define BATU32_BEPI 0xfffe0000
27fcf5ef2aSThomas Huth #define BATU32_BL 0x00001ffc
28fcf5ef2aSThomas Huth #define BATU32_VS 0x00000002
29fcf5ef2aSThomas Huth #define BATU32_VP 0x00000001
30fcf5ef2aSThomas Huth
31fcf5ef2aSThomas Huth
32fcf5ef2aSThomas Huth #define BATL32_BRPN 0xfffe0000
33fcf5ef2aSThomas Huth #define BATL32_WIMG 0x00000078
34fcf5ef2aSThomas Huth #define BATL32_PP 0x00000003
35fcf5ef2aSThomas Huth
36fcf5ef2aSThomas Huth /*
37fcf5ef2aSThomas Huth * Hash page table definitions
38fcf5ef2aSThomas Huth */
3936778660SDavid Gibson #define SDR_32_HTABORG 0xFFFF0000UL
4036778660SDavid Gibson #define SDR_32_HTABMASK 0x000001FFUL
41fcf5ef2aSThomas Huth
42fcf5ef2aSThomas Huth #define HPTES_PER_GROUP 8
43fcf5ef2aSThomas Huth #define HASH_PTE_SIZE_32 8
44fcf5ef2aSThomas Huth #define HASH_PTEG_SIZE_32 (HASH_PTE_SIZE_32 * HPTES_PER_GROUP)
45fcf5ef2aSThomas Huth
46fcf5ef2aSThomas Huth #define HPTE32_V_VALID 0x80000000
47fcf5ef2aSThomas Huth #define HPTE32_V_VSID 0x7fffff80
48fcf5ef2aSThomas Huth #define HPTE32_V_SECONDARY 0x00000040
49fcf5ef2aSThomas Huth #define HPTE32_V_API 0x0000003f
50fcf5ef2aSThomas Huth #define HPTE32_V_COMPARE(x, y) (!(((x) ^ (y)) & 0x7fffffbf))
51fcf5ef2aSThomas Huth
52fcf5ef2aSThomas Huth #define HPTE32_R_RPN 0xfffff000
53fcf5ef2aSThomas Huth #define HPTE32_R_R 0x00000100
54fcf5ef2aSThomas Huth #define HPTE32_R_C 0x00000080
55fcf5ef2aSThomas Huth #define HPTE32_R_W 0x00000040
56fcf5ef2aSThomas Huth #define HPTE32_R_I 0x00000020
57fcf5ef2aSThomas Huth #define HPTE32_R_M 0x00000010
58fcf5ef2aSThomas Huth #define HPTE32_R_G 0x00000008
59fcf5ef2aSThomas Huth #define HPTE32_R_WIMG 0x00000078
60fcf5ef2aSThomas Huth #define HPTE32_R_PP 0x00000003
61fcf5ef2aSThomas Huth
ppc_hash32_hpt_base(PowerPCCPU * cpu)6236778660SDavid Gibson static inline hwaddr ppc_hash32_hpt_base(PowerPCCPU *cpu)
6336778660SDavid Gibson {
6436778660SDavid Gibson return cpu->env.spr[SPR_SDR1] & SDR_32_HTABORG;
6536778660SDavid Gibson }
6636778660SDavid Gibson
ppc_hash32_hpt_mask(PowerPCCPU * cpu)6736778660SDavid Gibson static inline hwaddr ppc_hash32_hpt_mask(PowerPCCPU *cpu)
6836778660SDavid Gibson {
6936778660SDavid Gibson return ((cpu->env.spr[SPR_SDR1] & SDR_32_HTABMASK) << 16) | 0xFFFF;
7036778660SDavid Gibson }
7136778660SDavid Gibson
ppc_hash32_load_hpte0(PowerPCCPU * cpu,hwaddr pte_offset)72fcf5ef2aSThomas Huth static inline target_ulong ppc_hash32_load_hpte0(PowerPCCPU *cpu,
73fcf5ef2aSThomas Huth hwaddr pte_offset)
74fcf5ef2aSThomas Huth {
7536778660SDavid Gibson target_ulong base = ppc_hash32_hpt_base(cpu);
76fcf5ef2aSThomas Huth
7736778660SDavid Gibson return ldl_phys(CPU(cpu)->as, base + pte_offset);
78fcf5ef2aSThomas Huth }
79fcf5ef2aSThomas Huth
ppc_hash32_load_hpte1(PowerPCCPU * cpu,hwaddr pte_offset)80fcf5ef2aSThomas Huth static inline target_ulong ppc_hash32_load_hpte1(PowerPCCPU *cpu,
81fcf5ef2aSThomas Huth hwaddr pte_offset)
82fcf5ef2aSThomas Huth {
8336778660SDavid Gibson target_ulong base = ppc_hash32_hpt_base(cpu);
84fcf5ef2aSThomas Huth
8536778660SDavid Gibson return ldl_phys(CPU(cpu)->as, base + pte_offset + HASH_PTE_SIZE_32 / 2);
86fcf5ef2aSThomas Huth }
87fcf5ef2aSThomas Huth
ppc_hash32_store_hpte0(PowerPCCPU * cpu,hwaddr pte_offset,target_ulong pte0)88fcf5ef2aSThomas Huth static inline void ppc_hash32_store_hpte0(PowerPCCPU *cpu,
89fcf5ef2aSThomas Huth hwaddr pte_offset, target_ulong pte0)
90fcf5ef2aSThomas Huth {
9136778660SDavid Gibson target_ulong base = ppc_hash32_hpt_base(cpu);
92fcf5ef2aSThomas Huth
9336778660SDavid Gibson stl_phys(CPU(cpu)->as, base + pte_offset, pte0);
94fcf5ef2aSThomas Huth }
95fcf5ef2aSThomas Huth
ppc_hash32_store_hpte1(PowerPCCPU * cpu,hwaddr pte_offset,target_ulong pte1)96fcf5ef2aSThomas Huth static inline void ppc_hash32_store_hpte1(PowerPCCPU *cpu,
97fcf5ef2aSThomas Huth hwaddr pte_offset, target_ulong pte1)
98fcf5ef2aSThomas Huth {
9936778660SDavid Gibson target_ulong base = ppc_hash32_hpt_base(cpu);
100fcf5ef2aSThomas Huth
10136778660SDavid Gibson stl_phys(CPU(cpu)->as, base + pte_offset + HASH_PTE_SIZE_32 / 2, pte1);
102fcf5ef2aSThomas Huth }
103fcf5ef2aSThomas Huth
get_pteg_offset32(PowerPCCPU * cpu,hwaddr hash)104*9eb05300SBALATON Zoltan static inline hwaddr get_pteg_offset32(PowerPCCPU *cpu, hwaddr hash)
105*9eb05300SBALATON Zoltan {
106*9eb05300SBALATON Zoltan return (hash * HASH_PTEG_SIZE_32) & ppc_hash32_hpt_mask(cpu);
107*9eb05300SBALATON Zoltan }
108*9eb05300SBALATON Zoltan
ppc_hash32_key(bool pr,target_ulong sr)109719a1da1SBALATON Zoltan static inline bool ppc_hash32_key(bool pr, target_ulong sr)
110719a1da1SBALATON Zoltan {
111719a1da1SBALATON Zoltan return pr ? (sr & SR32_KP) : (sr & SR32_KS);
112719a1da1SBALATON Zoltan }
113719a1da1SBALATON Zoltan
ppc_hash32_prot(bool key,int pp,bool nx)114698faf33SBALATON Zoltan static inline int ppc_hash32_prot(bool key, int pp, bool nx)
115e48fb4c5SBALATON Zoltan {
116e48fb4c5SBALATON Zoltan int prot;
117e48fb4c5SBALATON Zoltan
118698faf33SBALATON Zoltan if (key) {
119e48fb4c5SBALATON Zoltan switch (pp) {
120e48fb4c5SBALATON Zoltan case 0x0:
121e48fb4c5SBALATON Zoltan prot = 0;
122e48fb4c5SBALATON Zoltan break;
123e48fb4c5SBALATON Zoltan case 0x1:
124e48fb4c5SBALATON Zoltan case 0x3:
125e48fb4c5SBALATON Zoltan prot = PAGE_READ;
126e48fb4c5SBALATON Zoltan break;
127e48fb4c5SBALATON Zoltan case 0x2:
128e48fb4c5SBALATON Zoltan prot = PAGE_READ | PAGE_WRITE;
129e48fb4c5SBALATON Zoltan break;
130e48fb4c5SBALATON Zoltan default:
131698faf33SBALATON Zoltan g_assert_not_reached();
132698faf33SBALATON Zoltan }
133698faf33SBALATON Zoltan } else {
134698faf33SBALATON Zoltan switch (pp) {
135698faf33SBALATON Zoltan case 0x0:
136698faf33SBALATON Zoltan case 0x1:
137698faf33SBALATON Zoltan case 0x2:
138698faf33SBALATON Zoltan prot = PAGE_READ | PAGE_WRITE;
139698faf33SBALATON Zoltan break;
140698faf33SBALATON Zoltan case 0x3:
141698faf33SBALATON Zoltan prot = PAGE_READ;
142698faf33SBALATON Zoltan break;
143698faf33SBALATON Zoltan default:
144698faf33SBALATON Zoltan g_assert_not_reached();
145e48fb4c5SBALATON Zoltan }
146e48fb4c5SBALATON Zoltan }
147698faf33SBALATON Zoltan return nx ? prot : prot | PAGE_EXEC;
148e48fb4c5SBALATON Zoltan }
149e48fb4c5SBALATON Zoltan
ppc_hash32_bat_prot(target_ulong batu,target_ulong batl)150d3233386SBALATON Zoltan static inline int ppc_hash32_bat_prot(target_ulong batu, target_ulong batl)
151d3233386SBALATON Zoltan {
152d3233386SBALATON Zoltan int prot = 0;
153d3233386SBALATON Zoltan int pp = batl & BATL32_PP;
154d3233386SBALATON Zoltan
155d3233386SBALATON Zoltan if (pp) {
156d3233386SBALATON Zoltan prot = PAGE_READ | PAGE_EXEC;
157d3233386SBALATON Zoltan if (pp == 0x2) {
158d3233386SBALATON Zoltan prot |= PAGE_WRITE;
159d3233386SBALATON Zoltan }
160d3233386SBALATON Zoltan }
161d3233386SBALATON Zoltan return prot;
162d3233386SBALATON Zoltan }
163d3233386SBALATON Zoltan
164fcf5ef2aSThomas Huth typedef struct {
165fcf5ef2aSThomas Huth uint32_t pte0, pte1;
166fcf5ef2aSThomas Huth } ppc_hash_pte32_t;
167fcf5ef2aSThomas Huth
168fcf5ef2aSThomas Huth #endif /* CONFIG_USER_ONLY */
169fcf5ef2aSThomas Huth
170fcf5ef2aSThomas Huth #endif /* MMU_HASH32_H */
171