2 * iSeries hashtable management.
3 * Derived from pSeries_htab.c
5 * SMP scalability work:
6 * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
13 #include <asm/machdep.h>
14 #include <asm/pgtable.h>
16 #include <asm/mmu_context.h>
17 #include <asm/iSeries/HvCallHpt.h>
18 #include <asm/abs_addr.h>
21 #include <linux/spinlock.h>
22 #include <linux/bitops.h>
23 #include <linux/threads.h>
24 #include <linux/smp.h>
26 #include <asm/tlbflush.h>
28 #include <asm/cputable.h>
31 static long iSeries_hpte_insert(unsigned long hpte_group, unsigned long va,
32 unsigned long prpn, int secondary,
33 unsigned long hpteflags, int bolted, int large)
39 * The hypervisor tries both primary and secondary.
40 * If we are being called to insert in the secondary,
41 * it means we have already tried both primary and secondary,
42 * so we return failure immediately.
47 slot = HvCallHpt_findValid(&lhpte, va >> PAGE_SHIFT);
49 panic("select_hpte_slot found entry already valid\n");
51 if (slot == -1) /* No available entry found in either group */
54 if (slot < 0) { /* MSB set means secondary group */
56 slot &= 0x7fffffffffffffff;
60 lhpte.dw1.dw1.rpn = physRpn_to_absRpn(prpn);
61 lhpte.dw1.flags.flags = hpteflags;
64 lhpte.dw0.dw0.avpn = va >> 23;
65 lhpte.dw0.dw0.h = secondary;
66 lhpte.dw0.dw0.bolted = bolted;
69 /* Now fill in the actual HPTE */
70 HvCallHpt_addValidate(slot, secondary, &lhpte);
72 return (secondary << 3) | (slot & 7);
75 static unsigned long iSeries_hpte_getword0(unsigned long slot)
80 HvCallHpt_get(&hpte, slot);
81 dword0 = hpte.dw0.dword0;
86 static long iSeries_hpte_remove(unsigned long hpte_group)
88 unsigned long slot_offset;
92 /* Pick a random slot to start at */
93 slot_offset = mftb() & 0x7;
95 for (i = 0; i < HPTES_PER_GROUP; i++) {
97 iSeries_hpte_getword0(hpte_group + slot_offset);
99 if (!lhpte.dw0.dw0.bolted) {
100 HvCallHpt_invalidateSetSwBitsGet(hpte_group +
113 * The HyperVisor expects the "flags" argument in this form:
114 * bits 0..59 : reserved
116 * bits 61..63 : PP2,PP1,PP0
118 static long iSeries_hpte_updatepp(unsigned long slot, unsigned long newpp,
119 unsigned long va, int large, int local)
122 unsigned long avpn = va >> 23;
124 HvCallHpt_get(&hpte, slot);
125 if ((hpte.dw0.dw0.avpn == avpn) && (hpte.dw0.dw0.v)) {
126 HvCallHpt_setPp(slot, (newpp & 0x3) | ((newpp & 0x4) << 1));
133 * Functions used to find the PTE for a particular virtual address.
134 * Only used during boot when bolting pages.
136 * Input : vpn : virtual page number
137 * Output: PTE index within the page table of the entry
140 static long iSeries_hpte_find(unsigned long vpn)
146 * The HvCallHpt_findValid interface is as follows:
147 * 0xffffffffffffffff : No entry found.
148 * 0x00000000xxxxxxxx : Entry found in primary group, slot x
149 * 0x80000000xxxxxxxx : Entry found in secondary group, slot x
151 slot = HvCallHpt_findValid(&hpte, vpn);
152 if (hpte.dw0.dw0.v) {
154 slot &= 0x7fffffffffffffff;
163 * Update the page protection bits. Intended to be used to create
164 * guard pages for kernel data structures on pages which are bolted
165 * in the HPT. Assumes pages being operated on will not be stolen.
166 * Does not work on large pages.
168 * No need to lock here because we should be the only user.
170 static void iSeries_hpte_updateboltedpp(unsigned long newpp, unsigned long ea)
172 unsigned long vsid,va,vpn;
175 vsid = get_kernel_vsid(ea);
176 va = (vsid << 28) | (ea & 0x0fffffff);
177 vpn = va >> PAGE_SHIFT;
178 slot = iSeries_hpte_find(vpn);
180 panic("updateboltedpp: Could not find page to bolt\n");
181 HvCallHpt_setPp(slot, newpp);
184 static void iSeries_hpte_invalidate(unsigned long slot, unsigned long va,
185 int large, int local)
188 unsigned long avpn = va >> 23;
190 lhpte.dw0.dword0 = iSeries_hpte_getword0(slot);
192 if ((lhpte.dw0.dw0.avpn == avpn) && lhpte.dw0.dw0.v)
193 HvCallHpt_invalidateSetSwBitsGet(slot, 0, 0);
196 void hpte_init_iSeries(void)
198 ppc_md.hpte_invalidate = iSeries_hpte_invalidate;
199 ppc_md.hpte_updatepp = iSeries_hpte_updatepp;
200 ppc_md.hpte_updateboltedpp = iSeries_hpte_updateboltedpp;
201 ppc_md.hpte_insert = iSeries_hpte_insert;
202 ppc_md.hpte_remove = iSeries_hpte_remove;