blob: d96bcfe4c6f6c2ed38f6c55afeb7e7809c6bd37c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * native hashtable management.
3 *
4 * SMP scalability work:
5 * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110012
13#undef DEBUG_LOW
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/spinlock.h>
16#include <linux/bitops.h>
17#include <linux/threads.h>
18#include <linux/smp.h>
19
20#include <asm/abs_addr.h>
21#include <asm/machdep.h>
22#include <asm/mmu.h>
23#include <asm/mmu_context.h>
24#include <asm/pgtable.h>
25#include <asm/tlbflush.h>
26#include <asm/tlb.h>
27#include <asm/cputable.h>
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110028#include <asm/udbg.h>
29
30#ifdef DEBUG_LOW
31#define DBG_LOW(fmt...) udbg_printf(fmt)
32#else
33#define DBG_LOW(fmt...)
34#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#define HPTE_LOCK_BIT 3
37
38static DEFINE_SPINLOCK(native_tlbie_lock);
39
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +110040static inline void __tlbie(unsigned long va, unsigned int psize)
41{
42 unsigned int penc;
43
44 /* clear top 16 bits, non SLS segment */
45 va &= ~(0xffffULL << 48);
46
47 switch (psize) {
48 case MMU_PAGE_4K:
49 va &= ~0xffful;
50 asm volatile("tlbie %0,0" : : "r" (va) : "memory");
51 break;
52 default:
53 penc = mmu_psize_defs[psize].penc;
54 va &= ~((1ul << mmu_psize_defs[psize].shift) - 1);
55 va |= (0x7f >> (8 - penc)) << 12;
56 asm volatile("tlbie %0,1" : : "r" (va) : "memory");
57 break;
58 }
59}
60
61static inline void __tlbiel(unsigned long va, unsigned int psize)
62{
63 unsigned int penc;
64
65 /* clear top 16 bits, non SLS segment */
66 va &= ~(0xffffULL << 48);
67
68 switch (psize) {
69 case MMU_PAGE_4K:
70 va &= ~0xffful;
71 asm volatile(".long 0x7c000224 | (%0 << 11) | (0 << 21)"
72 : : "r"(va) : "memory");
73 break;
74 default:
75 penc = mmu_psize_defs[psize].penc;
76 va &= ~((1ul << mmu_psize_defs[psize].shift) - 1);
77 va |= (0x7f >> (8 - penc)) << 12;
78 asm volatile(".long 0x7c000224 | (%0 << 11) | (1 << 21)"
79 : : "r"(va) : "memory");
80 break;
81 }
82
83}
84
85static inline void tlbie(unsigned long va, int psize, int local)
86{
87 unsigned int use_local = local && cpu_has_feature(CPU_FTR_TLBIEL);
88 int lock_tlbie = !cpu_has_feature(CPU_FTR_LOCKLESS_TLBIE);
89
90 if (use_local)
91 use_local = mmu_psize_defs[psize].tlbiel;
92 if (lock_tlbie && !use_local)
93 spin_lock(&native_tlbie_lock);
94 asm volatile("ptesync": : :"memory");
95 if (use_local) {
96 __tlbiel(va, psize);
97 asm volatile("ptesync": : :"memory");
98 } else {
99 __tlbie(va, psize);
100 asm volatile("eieio; tlbsync; ptesync": : :"memory");
101 }
102 if (lock_tlbie && !use_local)
103 spin_unlock(&native_tlbie_lock);
104}
105
David Gibson96e28442005-07-13 01:11:42 -0700106static inline void native_lock_hpte(hpte_t *hptep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
David Gibson96e28442005-07-13 01:11:42 -0700108 unsigned long *word = &hptep->v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 while (1) {
111 if (!test_and_set_bit(HPTE_LOCK_BIT, word))
112 break;
113 while(test_bit(HPTE_LOCK_BIT, word))
114 cpu_relax();
115 }
116}
117
David Gibson96e28442005-07-13 01:11:42 -0700118static inline void native_unlock_hpte(hpte_t *hptep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
David Gibson96e28442005-07-13 01:11:42 -0700120 unsigned long *word = &hptep->v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 asm volatile("lwsync":::"memory");
123 clear_bit(HPTE_LOCK_BIT, word);
124}
125
126long native_hpte_insert(unsigned long hpte_group, unsigned long va,
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100127 unsigned long pa, unsigned long rflags,
128 unsigned long vflags, int psize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
David Gibson96e28442005-07-13 01:11:42 -0700130 hpte_t *hptep = htab_address + hpte_group;
131 unsigned long hpte_v, hpte_r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 int i;
133
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100134 if (!(vflags & HPTE_V_BOLTED)) {
135 DBG_LOW(" insert(group=%lx, va=%016lx, pa=%016lx,"
136 " rflags=%lx, vflags=%lx, psize=%d)\n",
137 hpte_group, va, pa, rflags, vflags, psize);
138 }
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 for (i = 0; i < HPTES_PER_GROUP; i++) {
David Gibson96e28442005-07-13 01:11:42 -0700141 if (! (hptep->v & HPTE_V_VALID)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 /* retry with lock held */
143 native_lock_hpte(hptep);
David Gibson96e28442005-07-13 01:11:42 -0700144 if (! (hptep->v & HPTE_V_VALID))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 break;
146 native_unlock_hpte(hptep);
147 }
148
149 hptep++;
150 }
151
152 if (i == HPTES_PER_GROUP)
153 return -1;
154
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100155 hpte_v = hpte_encode_v(va, psize) | vflags | HPTE_V_VALID;
156 hpte_r = hpte_encode_r(pa, psize) | rflags;
157
158 if (!(vflags & HPTE_V_BOLTED)) {
159 DBG_LOW(" i=%x hpte_v=%016lx, hpte_r=%016lx\n",
160 i, hpte_v, hpte_r);
161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
David Gibson96e28442005-07-13 01:11:42 -0700163 hptep->r = hpte_r;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 /* Guarantee the second dword is visible before the valid bit */
165 __asm__ __volatile__ ("eieio" : : : "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /*
167 * Now set the first dword including the valid bit
168 * NOTE: this also unlocks the hpte
169 */
David Gibson96e28442005-07-13 01:11:42 -0700170 hptep->v = hpte_v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 __asm__ __volatile__ ("ptesync" : : : "memory");
173
David Gibson96e28442005-07-13 01:11:42 -0700174 return i | (!!(vflags & HPTE_V_SECONDARY) << 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175}
176
177static long native_hpte_remove(unsigned long hpte_group)
178{
David Gibson96e28442005-07-13 01:11:42 -0700179 hpte_t *hptep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 int i;
181 int slot_offset;
David Gibson96e28442005-07-13 01:11:42 -0700182 unsigned long hpte_v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100184 DBG_LOW(" remove(group=%lx)\n", hpte_group);
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 /* pick a random entry to start at */
187 slot_offset = mftb() & 0x7;
188
189 for (i = 0; i < HPTES_PER_GROUP; i++) {
190 hptep = htab_address + hpte_group + slot_offset;
David Gibson96e28442005-07-13 01:11:42 -0700191 hpte_v = hptep->v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
David Gibson96e28442005-07-13 01:11:42 -0700193 if ((hpte_v & HPTE_V_VALID) && !(hpte_v & HPTE_V_BOLTED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 /* retry with lock held */
195 native_lock_hpte(hptep);
David Gibson96e28442005-07-13 01:11:42 -0700196 hpte_v = hptep->v;
197 if ((hpte_v & HPTE_V_VALID)
198 && !(hpte_v & HPTE_V_BOLTED))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200 native_unlock_hpte(hptep);
201 }
202
203 slot_offset++;
204 slot_offset &= 0x7;
205 }
206
207 if (i == HPTES_PER_GROUP)
208 return -1;
209
210 /* Invalidate the hpte. NOTE: this also unlocks it */
David Gibson96e28442005-07-13 01:11:42 -0700211 hptep->v = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 return i;
214}
215
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100216static long native_hpte_updatepp(unsigned long slot, unsigned long newpp,
217 unsigned long va, int psize, int local)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100219 hpte_t *hptep = htab_address + slot;
220 unsigned long hpte_v, want_v;
221 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100223 want_v = hpte_encode_v(va, psize);
224
225 DBG_LOW(" update(va=%016lx, avpnv=%016lx, hash=%016lx, newpp=%x)",
226 va, want_v & HPTE_V_AVPN, slot, newpp);
227
228 native_lock_hpte(hptep);
229
230 hpte_v = hptep->v;
231
232 /* Even if we miss, we need to invalidate the TLB */
233 if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID)) {
234 DBG_LOW(" -> miss\n");
235 native_unlock_hpte(hptep);
236 ret = -1;
237 } else {
238 DBG_LOW(" -> hit\n");
239 /* Update the HPTE */
240 hptep->r = (hptep->r & ~(HPTE_R_PP | HPTE_R_N)) |
241 (newpp & (HPTE_R_PP | HPTE_R_N));
242 native_unlock_hpte(hptep);
243 }
244
245 /* Ensure it is out of the tlb too. */
246 tlbie(va, psize, local);
247
248 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100251static long native_hpte_find(unsigned long va, int psize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
David Gibson96e28442005-07-13 01:11:42 -0700253 hpte_t *hptep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 unsigned long hash;
255 unsigned long i, j;
256 long slot;
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100257 unsigned long want_v, hpte_v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100259 hash = hpt_hash(va, mmu_psize_defs[psize].shift);
260 want_v = hpte_encode_v(va, psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 for (j = 0; j < 2; j++) {
263 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
264 for (i = 0; i < HPTES_PER_GROUP; i++) {
265 hptep = htab_address + slot;
David Gibson96e28442005-07-13 01:11:42 -0700266 hpte_v = hptep->v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100268 if (HPTE_V_COMPARE(hpte_v, want_v)
David Gibson96e28442005-07-13 01:11:42 -0700269 && (hpte_v & HPTE_V_VALID)
270 && ( !!(hpte_v & HPTE_V_SECONDARY) == j)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 /* HPTE matches */
272 if (j)
273 slot = -slot;
274 return slot;
275 }
276 ++slot;
277 }
278 hash = ~hash;
279 }
280
281 return -1;
282}
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284/*
285 * Update the page protection bits. Intended to be used to create
286 * guard pages for kernel data structures on pages which are bolted
287 * in the HPT. Assumes pages being operated on will not be stolen.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 *
289 * No need to lock here because we should be the only user.
290 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100291static void native_hpte_updateboltedpp(unsigned long newpp, unsigned long ea,
292 int psize)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100294 unsigned long vsid, va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 long slot;
David Gibson96e28442005-07-13 01:11:42 -0700296 hpte_t *hptep;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 vsid = get_kernel_vsid(ea);
299 va = (vsid << 28) | (ea & 0x0fffffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100301 slot = native_hpte_find(va, psize);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (slot == -1)
303 panic("could not find page to bolt\n");
304 hptep = htab_address + slot;
305
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100306 /* Update the HPTE */
307 hptep->r = (hptep->r & ~(HPTE_R_PP | HPTE_R_N)) |
308 (newpp & (HPTE_R_PP | HPTE_R_N));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100310 /* Ensure it is out of the tlb too. */
311 tlbie(va, psize, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
314static void native_hpte_invalidate(unsigned long slot, unsigned long va,
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100315 int psize, int local)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
David Gibson96e28442005-07-13 01:11:42 -0700317 hpte_t *hptep = htab_address + slot;
318 unsigned long hpte_v;
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100319 unsigned long want_v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 local_irq_save(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100324 DBG_LOW(" invalidate(va=%016lx, hash: %x)\n", va, slot);
325
326 want_v = hpte_encode_v(va, psize);
327 native_lock_hpte(hptep);
David Gibson96e28442005-07-13 01:11:42 -0700328 hpte_v = hptep->v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /* Even if we miss, we need to invalidate the TLB */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100331 if (!HPTE_V_COMPARE(hpte_v, want_v) || !(hpte_v & HPTE_V_VALID))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 native_unlock_hpte(hptep);
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100333 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 /* Invalidate the hpte. NOTE: this also unlocks it */
David Gibson96e28442005-07-13 01:11:42 -0700335 hptep->v = 0;
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100336
337 /* Invalidate the TLB */
338 tlbie(va, psize, local);
339
340 local_irq_restore(flags);
341}
342
343/*
344 * XXX This need fixing based on page size. It's only used by
345 * native_hpte_clear() for now which needs fixing too so they
346 * make a good pair...
347 */
348static unsigned long slot2va(unsigned long hpte_v, unsigned long slot)
349{
350 unsigned long avpn = HPTE_V_AVPN_VAL(hpte_v);
351 unsigned long va;
352
353 va = avpn << 23;
354
355 if (! (hpte_v & HPTE_V_LARGE)) {
356 unsigned long vpi, pteg;
357
358 pteg = slot / HPTES_PER_GROUP;
359 if (hpte_v & HPTE_V_SECONDARY)
360 pteg = ~pteg;
361
362 vpi = ((va >> 28) ^ pteg) & htab_hash_mask;
363
364 va |= vpi << PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100367 return va;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
R Sharadaf4c82d52005-06-25 14:58:08 -0700370/*
371 * clear all mappings on kexec. All cpus are in real mode (or they will
372 * be when they isi), and we are the only one left. We rely on our kernel
373 * mapping being 0xC0's and the hardware ignoring those two real bits.
374 *
375 * TODO: add batching support when enabled. remember, no dynamic memory here,
376 * athough there is the control page available...
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100377 *
378 * XXX FIXME: 4k only for now !
R Sharadaf4c82d52005-06-25 14:58:08 -0700379 */
380static void native_hpte_clear(void)
381{
382 unsigned long slot, slots, flags;
David Gibson96e28442005-07-13 01:11:42 -0700383 hpte_t *hptep = htab_address;
384 unsigned long hpte_v;
R Sharadaf4c82d52005-06-25 14:58:08 -0700385 unsigned long pteg_count;
386
387 pteg_count = htab_hash_mask + 1;
388
389 local_irq_save(flags);
390
391 /* we take the tlbie lock and hold it. Some hardware will
392 * deadlock if we try to tlbie from two processors at once.
393 */
394 spin_lock(&native_tlbie_lock);
395
396 slots = pteg_count * HPTES_PER_GROUP;
397
398 for (slot = 0; slot < slots; slot++, hptep++) {
399 /*
400 * we could lock the pte here, but we are the only cpu
401 * running, right? and for crash dump, we probably
402 * don't want to wait for a maybe bad cpu.
403 */
David Gibson96e28442005-07-13 01:11:42 -0700404 hpte_v = hptep->v;
R Sharadaf4c82d52005-06-25 14:58:08 -0700405
David Gibson96e28442005-07-13 01:11:42 -0700406 if (hpte_v & HPTE_V_VALID) {
407 hptep->v = 0;
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100408 tlbie(slot2va(hpte_v, slot), MMU_PAGE_4K, 0);
R Sharadaf4c82d52005-06-25 14:58:08 -0700409 }
410 }
411
412 spin_unlock(&native_tlbie_lock);
413 local_irq_restore(flags);
414}
415
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100416/*
417 * Batched hash table flush, we batch the tlbie's to avoid taking/releasing
418 * the lock all the time
419 */
Benjamin Herrenschmidt61b1a942005-09-20 13:52:50 +1000420static void native_flush_hash_range(unsigned long number, int local)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100422 unsigned long va, hash, index, hidx, shift, slot;
David Gibson96e28442005-07-13 01:11:42 -0700423 hpte_t *hptep;
424 unsigned long hpte_v;
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100425 unsigned long want_v;
426 unsigned long flags;
427 real_pte_t pte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 struct ppc64_tlb_batch *batch = &__get_cpu_var(ppc64_tlb_batch);
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100429 unsigned long psize = batch->psize;
430 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 local_irq_save(flags);
433
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 for (i = 0; i < number; i++) {
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100435 va = batch->vaddr[i];
436 pte = batch->pte[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100438 pte_iterate_hashed_subpages(pte, psize, va, index, shift) {
439 hash = hpt_hash(va, shift);
440 hidx = __rpte_to_hidx(pte, index);
441 if (hidx & _PTEIDX_SECONDARY)
442 hash = ~hash;
443 slot = (hash & htab_hash_mask) * HPTES_PER_GROUP;
444 slot += hidx & _PTEIDX_GROUP_IX;
445 hptep = htab_address + slot;
446 want_v = hpte_encode_v(va, psize);
447 native_lock_hpte(hptep);
448 hpte_v = hptep->v;
449 if (!HPTE_V_COMPARE(hpte_v, want_v) ||
450 !(hpte_v & HPTE_V_VALID))
451 native_unlock_hpte(hptep);
452 else
453 hptep->v = 0;
454 } pte_iterate_hashed_end();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 }
456
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100457 if (cpu_has_feature(CPU_FTR_TLBIEL) &&
458 mmu_psize_defs[psize].tlbiel && local) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 asm volatile("ptesync":::"memory");
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100460 for (i = 0; i < number; i++) {
461 va = batch->vaddr[i];
462 pte = batch->pte[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100464 pte_iterate_hashed_subpages(pte, psize, va, index,
465 shift) {
466 __tlbiel(va, psize);
467 } pte_iterate_hashed_end();
468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 asm volatile("ptesync":::"memory");
470 } else {
471 int lock_tlbie = !cpu_has_feature(CPU_FTR_LOCKLESS_TLBIE);
472
473 if (lock_tlbie)
474 spin_lock(&native_tlbie_lock);
475
476 asm volatile("ptesync":::"memory");
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100477 for (i = 0; i < number; i++) {
478 va = batch->vaddr[i];
479 pte = batch->pte[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100481 pte_iterate_hashed_subpages(pte, psize, va, index,
482 shift) {
483 __tlbie(va, psize);
484 } pte_iterate_hashed_end();
485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 asm volatile("eieio; tlbsync; ptesync":::"memory");
487
488 if (lock_tlbie)
489 spin_unlock(&native_tlbie_lock);
490 }
491
492 local_irq_restore(flags);
493}
494
495#ifdef CONFIG_PPC_PSERIES
496/* Disable TLB batching on nighthawk */
497static inline int tlb_batching_enabled(void)
498{
499 struct device_node *root = of_find_node_by_path("/");
500 int enabled = 1;
501
502 if (root) {
503 const char *model = get_property(root, "model", NULL);
504 if (model && !strcmp(model, "IBM,9076-N81"))
505 enabled = 0;
506 of_node_put(root);
507 }
508
509 return enabled;
510}
511#else
512static inline int tlb_batching_enabled(void)
513{
514 return 1;
515}
516#endif
517
518void hpte_init_native(void)
519{
520 ppc_md.hpte_invalidate = native_hpte_invalidate;
521 ppc_md.hpte_updatepp = native_hpte_updatepp;
522 ppc_md.hpte_updateboltedpp = native_hpte_updateboltedpp;
523 ppc_md.hpte_insert = native_hpte_insert;
R Sharadaf4c82d52005-06-25 14:58:08 -0700524 ppc_md.hpte_remove = native_hpte_remove;
525 ppc_md.hpte_clear_all = native_hpte_clear;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (tlb_batching_enabled())
527 ppc_md.flush_hash_range = native_flush_hash_range;
528 htab_finish_init();
529}