26 #include <linux/kernel.h>
31 #include <asm/pgtable.h>
32 #include <asm/machdep.h>
38 #define DBG_LOW(fmt...) do { udbg_printf(fmt); } while (0)
40 #define DBG_LOW(fmt...) do { } while (0)
45 static inline unsigned int beat_read_mask(
unsigned hpte_group)
47 unsigned long rmask = 0;
50 beat_read_htab_entries(0, hpte_group + 0, hpte_v);
53 if (!(hpte_v[1] & HPTE_V_BOLTED))
55 if (!(hpte_v[2] & HPTE_V_BOLTED))
57 if (!(hpte_v[3] & HPTE_V_BOLTED))
59 beat_read_htab_entries(0, hpte_group + 4, hpte_v);
60 if (!(hpte_v[0] & HPTE_V_BOLTED))
62 if (!(hpte_v[1] & HPTE_V_BOLTED))
64 if (!(hpte_v[2] & HPTE_V_BOLTED))
66 if (!(hpte_v[3] & HPTE_V_BOLTED))
69 beat_read_htab_entries(0, hpte_group + 0, hpte_v);
70 if (!(hpte_v[0] & HPTE_V_BOLTED))
72 if (!(hpte_v[1] & HPTE_V_BOLTED))
74 if (!(hpte_v[2] & HPTE_V_BOLTED))
76 if (!(hpte_v[3] & HPTE_V_BOLTED))
78 beat_read_htab_entries(0, hpte_group + 4, hpte_v);
79 if (!(hpte_v[0] & HPTE_V_BOLTED))
81 if (!(hpte_v[1] & HPTE_V_BOLTED))
83 if (!(hpte_v[2] & HPTE_V_BOLTED))
85 if (!(hpte_v[3] & HPTE_V_BOLTED))
90 static long beat_lpar_hpte_insert(
unsigned long hpte_group,
91 unsigned long vpn,
unsigned long pa,
92 unsigned long rflags,
unsigned long vflags,
95 unsigned long lpar_rc;
101 if (!(vflags & HPTE_V_BOLTED))
102 DBG_LOW(
"hpte_insert(group=%lx, va=%016lx, pa=%016lx, "
103 "rflags=%lx, vflags=%lx, psize=%d)\n",
104 hpte_group,
va, pa, rflags, vflags, psize);
108 hpte_r = hpte_encode_r(pa, psize) |
rflags;
110 if (!(vflags & HPTE_V_BOLTED))
111 DBG_LOW(
" hpte_v=%016lx, hpte_r=%016lx\n", hpte_v, hpte_r);
117 lpar_rc = beat_read_mask(hpte_group);
119 if (!(vflags & HPTE_V_BOLTED))
125 lpar_rc = beat_insert_htab_entry(0, hpte_group, lpar_rc << 48,
126 hpte_v, hpte_r, &slot);
135 if (!(vflags & HPTE_V_BOLTED))
136 DBG_LOW(
" lpar err %lx\n", lpar_rc);
139 if (!(vflags & HPTE_V_BOLTED))
140 DBG_LOW(
" -> slot: %lx\n", slot);
143 return (slot ^ hpte_group) & 15;
146 static long beat_lpar_hpte_remove(
unsigned long hpte_group)
148 DBG_LOW(
"hpte_remove(group=%lx)\n", hpte_group);
152 static unsigned long beat_lpar_hpte_getword0(
unsigned long slot)
154 unsigned long dword0;
155 unsigned long lpar_rc;
158 lpar_rc = beat_read_htab_entries(0, slot & ~3
UL, dword);
160 dword0 = dword[slot&3];
167 static void beat_lpar_hptab_clear(
void)
170 unsigned long hpte_count = size_bytes >> 4;
175 for (i = 0; i < hpte_count; i++)
176 beat_write_htab_entry(0, i, 0, 0, -1
UL, -1
UL, &dummy0, &dummy1);
185 static long beat_lpar_hpte_updatepp(
unsigned long slot,
188 int psize,
int ssize,
int local)
190 unsigned long lpar_rc;
192 unsigned long want_v;
197 "avpnv=%016lx, slot=%016lx, psize: %d, newpp %016lx ... ",
201 dummy0 = beat_lpar_hpte_getword0(slot);
202 if ((dummy0 & ~0x7FUL) != (want_v & ~0x7FUL)) {
208 lpar_rc = beat_write_htab_entry(0, slot, 0, newpp, 0, 7, &dummy0,
211 if (lpar_rc != 0 || dummy0 == 0) {
216 DBG_LOW(
"ok %lx %lx\n", dummy0, dummy1);
223 static long beat_lpar_hpte_find(
unsigned long vpn,
int psize)
228 unsigned long want_v, hpte_v;
233 for (j = 0; j < 2; j++) {
236 hpte_v = beat_lpar_hpte_getword0(slot);
240 && (!!(hpte_v & HPTE_V_SECONDARY) == j)) {
254 static void beat_lpar_hpte_updateboltedpp(
unsigned long newpp,
256 int psize,
int ssize)
259 unsigned long lpar_rc,
slot, vsid;
266 slot = beat_lpar_hpte_find(vpn, psize);
269 lpar_rc = beat_write_htab_entry(0, slot, 0, newpp, 0, 7,
276 static void beat_lpar_hpte_invalidate(
unsigned long slot,
unsigned long vpn,
277 int psize,
int ssize,
int local)
279 unsigned long want_v;
280 unsigned long lpar_rc;
284 DBG_LOW(
" inval : slot=%lx, va=%016lx, psize: %d, local: %d\n",
285 slot,
va, psize, local);
289 dummy1 = beat_lpar_hpte_getword0(slot);
291 if ((dummy1 & ~0x7FUL) != (want_v & ~0x7FUL)) {
297 lpar_rc = beat_write_htab_entry(0, slot, 0, 0, HPTE_V_VALID, 0,
306 ppc_md.hpte_invalidate = beat_lpar_hpte_invalidate;
307 ppc_md.hpte_updatepp = beat_lpar_hpte_updatepp;
308 ppc_md.hpte_updateboltedpp = beat_lpar_hpte_updateboltedpp;
309 ppc_md.hpte_insert = beat_lpar_hpte_insert;
310 ppc_md.hpte_remove = beat_lpar_hpte_remove;
311 ppc_md.hpte_clear_all = beat_lpar_hptab_clear;
314 static long beat_lpar_hpte_insert_v3(
unsigned long hpte_group,
315 unsigned long vpn,
unsigned long pa,
316 unsigned long rflags,
unsigned long vflags,
317 int psize,
int ssize)
319 unsigned long lpar_rc;
322 if (vflags & HPTE_V_SECONDARY)
325 if (!(vflags & HPTE_V_BOLTED))
326 DBG_LOW(
"hpte_insert(group=%lx, vpn=%016lx, pa=%016lx, "
327 "rflags=%lx, vflags=%lx, psize=%d)\n",
328 hpte_group, vpn, pa, rflags, vflags, psize);
332 hpte_r = hpte_encode_r(pa, psize) |
rflags;
334 if (!(vflags & HPTE_V_BOLTED))
335 DBG_LOW(
" hpte_v=%016lx, hpte_r=%016lx\n", hpte_v, hpte_r);
337 if (rflags & _PAGE_NO_CACHE)
341 lpar_rc = beat_insert_htab_entry3(0, hpte_group, hpte_v, hpte_r,
342 HPTE_V_BOLTED, 0, &slot);
349 if (!(vflags & HPTE_V_BOLTED))
350 DBG_LOW(
" lpar err %lx\n", lpar_rc);
353 if (!(vflags & HPTE_V_BOLTED))
354 DBG_LOW(
" -> slot: %lx\n", slot);
357 return (slot ^ hpte_group) & 15;
366 static long beat_lpar_hpte_updatepp_v3(
unsigned long slot,
369 int psize,
int ssize,
int local)
371 unsigned long lpar_rc;
372 unsigned long want_v;
379 "avpnv=%016lx, slot=%016lx, psize: %d, newpp %016lx ... ",
382 lpar_rc = beat_update_htab_permission3(0, slot, want_v, pss, 7, newpp);
384 if (lpar_rc == 0xfffffff7) {
396 static void beat_lpar_hpte_invalidate_v3(
unsigned long slot,
unsigned long vpn,
397 int psize,
int ssize,
int local)
399 unsigned long want_v;
400 unsigned long lpar_rc;
403 DBG_LOW(
" inval : slot=%lx, vpn=%016lx, psize: %d, local: %d\n",
404 slot, vpn, psize, local);
408 lpar_rc = beat_invalidate_htab_entry3(0, slot, want_v, pss);
411 BUG_ON(lpar_rc != 0 && lpar_rc != 0xfffffff7);
414 static int64_t _beat_lpar_hptab_clear_v3(
void)
416 return beat_clear_htab3(0);
419 static void beat_lpar_hptab_clear_v3(
void)
421 _beat_lpar_hptab_clear_v3();
426 if (_beat_lpar_hptab_clear_v3() == 0) {
427 ppc_md.hpte_invalidate = beat_lpar_hpte_invalidate_v3;
428 ppc_md.hpte_updatepp = beat_lpar_hpte_updatepp_v3;
429 ppc_md.hpte_updateboltedpp = beat_lpar_hpte_updateboltedpp;
430 ppc_md.hpte_insert = beat_lpar_hpte_insert_v3;
431 ppc_md.hpte_remove = beat_lpar_hpte_remove;
432 ppc_md.hpte_clear_all = beat_lpar_hptab_clear_v3;
434 ppc_md.hpte_invalidate = beat_lpar_hpte_invalidate;
435 ppc_md.hpte_updatepp = beat_lpar_hpte_updatepp;
436 ppc_md.hpte_updateboltedpp = beat_lpar_hpte_updateboltedpp;
437 ppc_md.hpte_insert = beat_lpar_hpte_insert;
438 ppc_md.hpte_remove = beat_lpar_hpte_remove;
439 ppc_md.hpte_clear_all = beat_lpar_hptab_clear;