Statistics
| Branch: | Revision:

root / hw / spapr_hcall.c @ 9a3a8895

History | View | Annotate | Download (21.6 kB)

1 9fdf0c29 David Gibson
#include "sysemu.h"
2 9fdf0c29 David Gibson
#include "cpu.h"
3 9fdf0c29 David Gibson
#include "qemu-char.h"
4 f43e3525 David Gibson
#include "sysemu.h"
5 f43e3525 David Gibson
#include "qemu-char.h"
6 ed120055 David Gibson
#include "helper_regs.h"
7 9fdf0c29 David Gibson
#include "hw/spapr.h"
8 9fdf0c29 David Gibson
9 f43e3525 David Gibson
#define HPTES_PER_GROUP 8
10 f43e3525 David Gibson
11 f43e3525 David Gibson
#define HPTE_V_SSIZE_SHIFT      62
12 f43e3525 David Gibson
#define HPTE_V_AVPN_SHIFT       7
13 f43e3525 David Gibson
#define HPTE_V_AVPN             0x3fffffffffffff80ULL
14 f43e3525 David Gibson
#define HPTE_V_AVPN_VAL(x)      (((x) & HPTE_V_AVPN) >> HPTE_V_AVPN_SHIFT)
15 f43e3525 David Gibson
#define HPTE_V_COMPARE(x, y)    (!(((x) ^ (y)) & 0xffffffffffffff80UL))
16 f43e3525 David Gibson
#define HPTE_V_BOLTED           0x0000000000000010ULL
17 f43e3525 David Gibson
#define HPTE_V_LOCK             0x0000000000000008ULL
18 f43e3525 David Gibson
#define HPTE_V_LARGE            0x0000000000000004ULL
19 f43e3525 David Gibson
#define HPTE_V_SECONDARY        0x0000000000000002ULL
20 f43e3525 David Gibson
#define HPTE_V_VALID            0x0000000000000001ULL
21 f43e3525 David Gibson
22 f43e3525 David Gibson
#define HPTE_R_PP0              0x8000000000000000ULL
23 f43e3525 David Gibson
#define HPTE_R_TS               0x4000000000000000ULL
24 f43e3525 David Gibson
#define HPTE_R_KEY_HI           0x3000000000000000ULL
25 f43e3525 David Gibson
#define HPTE_R_RPN_SHIFT        12
26 f43e3525 David Gibson
#define HPTE_R_RPN              0x3ffffffffffff000ULL
27 f43e3525 David Gibson
#define HPTE_R_FLAGS            0x00000000000003ffULL
28 f43e3525 David Gibson
#define HPTE_R_PP               0x0000000000000003ULL
29 f43e3525 David Gibson
#define HPTE_R_N                0x0000000000000004ULL
30 f43e3525 David Gibson
#define HPTE_R_G                0x0000000000000008ULL
31 f43e3525 David Gibson
#define HPTE_R_M                0x0000000000000010ULL
32 f43e3525 David Gibson
#define HPTE_R_I                0x0000000000000020ULL
33 f43e3525 David Gibson
#define HPTE_R_W                0x0000000000000040ULL
34 f43e3525 David Gibson
#define HPTE_R_WIMG             0x0000000000000078ULL
35 f43e3525 David Gibson
#define HPTE_R_C                0x0000000000000080ULL
36 f43e3525 David Gibson
#define HPTE_R_R                0x0000000000000100ULL
37 f43e3525 David Gibson
#define HPTE_R_KEY_LO           0x0000000000000e00ULL
38 f43e3525 David Gibson
39 f43e3525 David Gibson
#define HPTE_V_1TB_SEG          0x4000000000000000ULL
40 f43e3525 David Gibson
#define HPTE_V_VRMA_MASK        0x4001ffffff000000ULL
41 f43e3525 David Gibson
42 f43e3525 David Gibson
#define HPTE_V_HVLOCK           0x40ULL
43 f43e3525 David Gibson
44 f43e3525 David Gibson
static inline int lock_hpte(void *hpte, target_ulong bits)
45 f43e3525 David Gibson
{
46 f43e3525 David Gibson
    uint64_t pteh;
47 f43e3525 David Gibson
48 f43e3525 David Gibson
    pteh = ldq_p(hpte);
49 f43e3525 David Gibson
50 f43e3525 David Gibson
    /* We're protected by qemu's global lock here */
51 f43e3525 David Gibson
    if (pteh & bits) {
52 f43e3525 David Gibson
        return 0;
53 f43e3525 David Gibson
    }
54 f43e3525 David Gibson
    stq_p(hpte, pteh | HPTE_V_HVLOCK);
55 f43e3525 David Gibson
    return 1;
56 f43e3525 David Gibson
}
57 f43e3525 David Gibson
58 f43e3525 David Gibson
static target_ulong compute_tlbie_rb(target_ulong v, target_ulong r,
59 f43e3525 David Gibson
                                     target_ulong pte_index)
60 f43e3525 David Gibson
{
61 f43e3525 David Gibson
    target_ulong rb, va_low;
62 f43e3525 David Gibson
63 f43e3525 David Gibson
    rb = (v & ~0x7fULL) << 16; /* AVA field */
64 f43e3525 David Gibson
    va_low = pte_index >> 3;
65 f43e3525 David Gibson
    if (v & HPTE_V_SECONDARY) {
66 f43e3525 David Gibson
        va_low = ~va_low;
67 f43e3525 David Gibson
    }
68 f43e3525 David Gibson
    /* xor vsid from AVA */
69 f43e3525 David Gibson
    if (!(v & HPTE_V_1TB_SEG)) {
70 f43e3525 David Gibson
        va_low ^= v >> 12;
71 f43e3525 David Gibson
    } else {
72 f43e3525 David Gibson
        va_low ^= v >> 24;
73 f43e3525 David Gibson
    }
74 f43e3525 David Gibson
    va_low &= 0x7ff;
75 f43e3525 David Gibson
    if (v & HPTE_V_LARGE) {
76 f43e3525 David Gibson
        rb |= 1;                         /* L field */
77 f43e3525 David Gibson
#if 0 /* Disable that P7 specific bit for now */
78 f43e3525 David Gibson
        if (r & 0xff000) {
79 f43e3525 David Gibson
            /* non-16MB large page, must be 64k */
80 f43e3525 David Gibson
            /* (masks depend on page size) */
81 f43e3525 David Gibson
            rb |= 0x1000;                /* page encoding in LP field */
82 f43e3525 David Gibson
            rb |= (va_low & 0x7f) << 16; /* 7b of VA in AVA/LP field */
83 f43e3525 David Gibson
            rb |= (va_low & 0xfe);       /* AVAL field */
84 f43e3525 David Gibson
        }
85 f43e3525 David Gibson
#endif
86 f43e3525 David Gibson
    } else {
87 f43e3525 David Gibson
        /* 4kB page */
88 f43e3525 David Gibson
        rb |= (va_low & 0x7ff) << 12;   /* remaining 11b of AVA */
89 f43e3525 David Gibson
    }
90 f43e3525 David Gibson
    rb |= (v >> 54) & 0x300;            /* B field */
91 f43e3525 David Gibson
    return rb;
92 f43e3525 David Gibson
}
93 f43e3525 David Gibson
94 e2684c0b Andreas Färber
static target_ulong h_enter(CPUPPCState *env, sPAPREnvironment *spapr,
95 f43e3525 David Gibson
                            target_ulong opcode, target_ulong *args)
96 f43e3525 David Gibson
{
97 f43e3525 David Gibson
    target_ulong flags = args[0];
98 f43e3525 David Gibson
    target_ulong pte_index = args[1];
99 f43e3525 David Gibson
    target_ulong pteh = args[2];
100 f43e3525 David Gibson
    target_ulong ptel = args[3];
101 f73a2575 David Gibson
    target_ulong page_shift = 12;
102 f73a2575 David Gibson
    target_ulong raddr;
103 1235a9cf David Gibson
    target_ulong i;
104 f43e3525 David Gibson
    uint8_t *hpte;
105 f43e3525 David Gibson
106 f43e3525 David Gibson
    /* only handle 4k and 16M pages for now */
107 f43e3525 David Gibson
    if (pteh & HPTE_V_LARGE) {
108 f43e3525 David Gibson
#if 0 /* We don't support 64k pages yet */
109 f43e3525 David Gibson
        if ((ptel & 0xf000) == 0x1000) {
110 f43e3525 David Gibson
            /* 64k page */
111 f43e3525 David Gibson
        } else
112 f43e3525 David Gibson
#endif
113 f43e3525 David Gibson
        if ((ptel & 0xff000) == 0) {
114 f43e3525 David Gibson
            /* 16M page */
115 f73a2575 David Gibson
            page_shift = 24;
116 f43e3525 David Gibson
            /* lowest AVA bit must be 0 for 16M pages */
117 f43e3525 David Gibson
            if (pteh & 0x80) {
118 f43e3525 David Gibson
                return H_PARAMETER;
119 f43e3525 David Gibson
            }
120 f43e3525 David Gibson
        } else {
121 f43e3525 David Gibson
            return H_PARAMETER;
122 f43e3525 David Gibson
        }
123 f43e3525 David Gibson
    }
124 f43e3525 David Gibson
125 f73a2575 David Gibson
    raddr = (ptel & HPTE_R_RPN) & ~((1ULL << page_shift) - 1);
126 f43e3525 David Gibson
127 f73a2575 David Gibson
    if (raddr < spapr->ram_limit) {
128 f73a2575 David Gibson
        /* Regular RAM - should have WIMG=0010 */
129 f73a2575 David Gibson
        if ((ptel & HPTE_R_WIMG) != HPTE_R_M) {
130 f73a2575 David Gibson
            return H_PARAMETER;
131 f73a2575 David Gibson
        }
132 f73a2575 David Gibson
    } else {
133 f73a2575 David Gibson
        /* Looks like an IO address */
134 f73a2575 David Gibson
        /* FIXME: What WIMG combinations could be sensible for IO?
135 f73a2575 David Gibson
         * For now we allow WIMG=010x, but are there others? */
136 f73a2575 David Gibson
        /* FIXME: Should we check against registered IO addresses? */
137 f73a2575 David Gibson
        if ((ptel & (HPTE_R_W | HPTE_R_I | HPTE_R_M)) != HPTE_R_I) {
138 f73a2575 David Gibson
            return H_PARAMETER;
139 f73a2575 David Gibson
        }
140 f43e3525 David Gibson
    }
141 f73a2575 David Gibson
142 f43e3525 David Gibson
    pteh &= ~0x60ULL;
143 f43e3525 David Gibson
144 f43e3525 David Gibson
    if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
145 f43e3525 David Gibson
        return H_PARAMETER;
146 f43e3525 David Gibson
    }
147 f43e3525 David Gibson
    if (likely((flags & H_EXACT) == 0)) {
148 f43e3525 David Gibson
        pte_index &= ~7ULL;
149 f43e3525 David Gibson
        hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
150 f43e3525 David Gibson
        for (i = 0; ; ++i) {
151 f43e3525 David Gibson
            if (i == 8) {
152 f43e3525 David Gibson
                return H_PTEG_FULL;
153 f43e3525 David Gibson
            }
154 f43e3525 David Gibson
            if (((ldq_p(hpte) & HPTE_V_VALID) == 0) &&
155 f43e3525 David Gibson
                lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID)) {
156 f43e3525 David Gibson
                break;
157 f43e3525 David Gibson
            }
158 f43e3525 David Gibson
            hpte += HASH_PTE_SIZE_64;
159 f43e3525 David Gibson
        }
160 f43e3525 David Gibson
    } else {
161 f43e3525 David Gibson
        i = 0;
162 f43e3525 David Gibson
        hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
163 f43e3525 David Gibson
        if (!lock_hpte(hpte, HPTE_V_HVLOCK | HPTE_V_VALID)) {
164 f43e3525 David Gibson
            return H_PTEG_FULL;
165 f43e3525 David Gibson
        }
166 f43e3525 David Gibson
    }
167 f43e3525 David Gibson
    stq_p(hpte + (HASH_PTE_SIZE_64/2), ptel);
168 f43e3525 David Gibson
    /* eieio();  FIXME: need some sort of barrier for smp? */
169 f43e3525 David Gibson
    stq_p(hpte, pteh);
170 f43e3525 David Gibson
171 f43e3525 David Gibson
    assert(!(ldq_p(hpte) & HPTE_V_HVLOCK));
172 f43e3525 David Gibson
    args[0] = pte_index + i;
173 f43e3525 David Gibson
    return H_SUCCESS;
174 f43e3525 David Gibson
}
175 f43e3525 David Gibson
176 a3d0abae David Gibson
enum {
177 a3d0abae David Gibson
    REMOVE_SUCCESS = 0,
178 a3d0abae David Gibson
    REMOVE_NOT_FOUND = 1,
179 a3d0abae David Gibson
    REMOVE_PARM = 2,
180 a3d0abae David Gibson
    REMOVE_HW = 3,
181 a3d0abae David Gibson
};
182 a3d0abae David Gibson
183 e2684c0b Andreas Färber
static target_ulong remove_hpte(CPUPPCState *env, target_ulong ptex,
184 a3d0abae David Gibson
                                target_ulong avpn,
185 a3d0abae David Gibson
                                target_ulong flags,
186 a3d0abae David Gibson
                                target_ulong *vp, target_ulong *rp)
187 f43e3525 David Gibson
{
188 f43e3525 David Gibson
    uint8_t *hpte;
189 f43e3525 David Gibson
    target_ulong v, r, rb;
190 f43e3525 David Gibson
191 a3d0abae David Gibson
    if ((ptex * HASH_PTE_SIZE_64) & ~env->htab_mask) {
192 a3d0abae David Gibson
        return REMOVE_PARM;
193 f43e3525 David Gibson
    }
194 f43e3525 David Gibson
195 a3d0abae David Gibson
    hpte = env->external_htab + (ptex * HASH_PTE_SIZE_64);
196 f43e3525 David Gibson
    while (!lock_hpte(hpte, HPTE_V_HVLOCK)) {
197 f43e3525 David Gibson
        /* We have no real concurrency in qemu soft-emulation, so we
198 f43e3525 David Gibson
         * will never actually have a contested lock */
199 f43e3525 David Gibson
        assert(0);
200 f43e3525 David Gibson
    }
201 f43e3525 David Gibson
202 f43e3525 David Gibson
    v = ldq_p(hpte);
203 f43e3525 David Gibson
    r = ldq_p(hpte + (HASH_PTE_SIZE_64/2));
204 f43e3525 David Gibson
205 f43e3525 David Gibson
    if ((v & HPTE_V_VALID) == 0 ||
206 f43e3525 David Gibson
        ((flags & H_AVPN) && (v & ~0x7fULL) != avpn) ||
207 f43e3525 David Gibson
        ((flags & H_ANDCOND) && (v & avpn) != 0)) {
208 f43e3525 David Gibson
        stq_p(hpte, v & ~HPTE_V_HVLOCK);
209 f43e3525 David Gibson
        assert(!(ldq_p(hpte) & HPTE_V_HVLOCK));
210 a3d0abae David Gibson
        return REMOVE_NOT_FOUND;
211 f43e3525 David Gibson
    }
212 a3d0abae David Gibson
    *vp = v & ~HPTE_V_HVLOCK;
213 a3d0abae David Gibson
    *rp = r;
214 f43e3525 David Gibson
    stq_p(hpte, 0);
215 a3d0abae David Gibson
    rb = compute_tlbie_rb(v, r, ptex);
216 f43e3525 David Gibson
    ppc_tlb_invalidate_one(env, rb);
217 f43e3525 David Gibson
    assert(!(ldq_p(hpte) & HPTE_V_HVLOCK));
218 a3d0abae David Gibson
    return REMOVE_SUCCESS;
219 a3d0abae David Gibson
}
220 a3d0abae David Gibson
221 e2684c0b Andreas Färber
static target_ulong h_remove(CPUPPCState *env, sPAPREnvironment *spapr,
222 a3d0abae David Gibson
                             target_ulong opcode, target_ulong *args)
223 a3d0abae David Gibson
{
224 a3d0abae David Gibson
    target_ulong flags = args[0];
225 a3d0abae David Gibson
    target_ulong pte_index = args[1];
226 a3d0abae David Gibson
    target_ulong avpn = args[2];
227 a3d0abae David Gibson
    int ret;
228 a3d0abae David Gibson
229 a3d0abae David Gibson
    ret = remove_hpte(env, pte_index, avpn, flags,
230 a3d0abae David Gibson
                      &args[0], &args[1]);
231 a3d0abae David Gibson
232 a3d0abae David Gibson
    switch (ret) {
233 a3d0abae David Gibson
    case REMOVE_SUCCESS:
234 a3d0abae David Gibson
        return H_SUCCESS;
235 a3d0abae David Gibson
236 a3d0abae David Gibson
    case REMOVE_NOT_FOUND:
237 a3d0abae David Gibson
        return H_NOT_FOUND;
238 a3d0abae David Gibson
239 a3d0abae David Gibson
    case REMOVE_PARM:
240 a3d0abae David Gibson
        return H_PARAMETER;
241 a3d0abae David Gibson
242 a3d0abae David Gibson
    case REMOVE_HW:
243 a3d0abae David Gibson
        return H_HARDWARE;
244 a3d0abae David Gibson
    }
245 a3d0abae David Gibson
246 a3d0abae David Gibson
    assert(0);
247 a3d0abae David Gibson
}
248 a3d0abae David Gibson
249 a3d0abae David Gibson
#define H_BULK_REMOVE_TYPE             0xc000000000000000ULL
250 a3d0abae David Gibson
#define   H_BULK_REMOVE_REQUEST        0x4000000000000000ULL
251 a3d0abae David Gibson
#define   H_BULK_REMOVE_RESPONSE       0x8000000000000000ULL
252 a3d0abae David Gibson
#define   H_BULK_REMOVE_END            0xc000000000000000ULL
253 a3d0abae David Gibson
#define H_BULK_REMOVE_CODE             0x3000000000000000ULL
254 a3d0abae David Gibson
#define   H_BULK_REMOVE_SUCCESS        0x0000000000000000ULL
255 a3d0abae David Gibson
#define   H_BULK_REMOVE_NOT_FOUND      0x1000000000000000ULL
256 a3d0abae David Gibson
#define   H_BULK_REMOVE_PARM           0x2000000000000000ULL
257 a3d0abae David Gibson
#define   H_BULK_REMOVE_HW             0x3000000000000000ULL
258 a3d0abae David Gibson
#define H_BULK_REMOVE_RC               0x0c00000000000000ULL
259 a3d0abae David Gibson
#define H_BULK_REMOVE_FLAGS            0x0300000000000000ULL
260 a3d0abae David Gibson
#define   H_BULK_REMOVE_ABSOLUTE       0x0000000000000000ULL
261 a3d0abae David Gibson
#define   H_BULK_REMOVE_ANDCOND        0x0100000000000000ULL
262 a3d0abae David Gibson
#define   H_BULK_REMOVE_AVPN           0x0200000000000000ULL
263 a3d0abae David Gibson
#define H_BULK_REMOVE_PTEX             0x00ffffffffffffffULL
264 a3d0abae David Gibson
265 a3d0abae David Gibson
#define H_BULK_REMOVE_MAX_BATCH        4
266 a3d0abae David Gibson
267 e2684c0b Andreas Färber
static target_ulong h_bulk_remove(CPUPPCState *env, sPAPREnvironment *spapr,
268 a3d0abae David Gibson
                                  target_ulong opcode, target_ulong *args)
269 a3d0abae David Gibson
{
270 a3d0abae David Gibson
    int i;
271 a3d0abae David Gibson
272 a3d0abae David Gibson
    for (i = 0; i < H_BULK_REMOVE_MAX_BATCH; i++) {
273 a3d0abae David Gibson
        target_ulong *tsh = &args[i*2];
274 a3d0abae David Gibson
        target_ulong tsl = args[i*2 + 1];
275 a3d0abae David Gibson
        target_ulong v, r, ret;
276 a3d0abae David Gibson
277 a3d0abae David Gibson
        if ((*tsh & H_BULK_REMOVE_TYPE) == H_BULK_REMOVE_END) {
278 a3d0abae David Gibson
            break;
279 a3d0abae David Gibson
        } else if ((*tsh & H_BULK_REMOVE_TYPE) != H_BULK_REMOVE_REQUEST) {
280 a3d0abae David Gibson
            return H_PARAMETER;
281 a3d0abae David Gibson
        }
282 a3d0abae David Gibson
283 a3d0abae David Gibson
        *tsh &= H_BULK_REMOVE_PTEX | H_BULK_REMOVE_FLAGS;
284 a3d0abae David Gibson
        *tsh |= H_BULK_REMOVE_RESPONSE;
285 a3d0abae David Gibson
286 a3d0abae David Gibson
        if ((*tsh & H_BULK_REMOVE_ANDCOND) && (*tsh & H_BULK_REMOVE_AVPN)) {
287 a3d0abae David Gibson
            *tsh |= H_BULK_REMOVE_PARM;
288 a3d0abae David Gibson
            return H_PARAMETER;
289 a3d0abae David Gibson
        }
290 a3d0abae David Gibson
291 a3d0abae David Gibson
        ret = remove_hpte(env, *tsh & H_BULK_REMOVE_PTEX, tsl,
292 a3d0abae David Gibson
                          (*tsh & H_BULK_REMOVE_FLAGS) >> 26,
293 a3d0abae David Gibson
                          &v, &r);
294 a3d0abae David Gibson
295 a3d0abae David Gibson
        *tsh |= ret << 60;
296 a3d0abae David Gibson
297 a3d0abae David Gibson
        switch (ret) {
298 a3d0abae David Gibson
        case REMOVE_SUCCESS:
299 a3d0abae David Gibson
            *tsh |= (r & (HPTE_R_C | HPTE_R_R)) << 43;
300 a3d0abae David Gibson
            break;
301 a3d0abae David Gibson
302 a3d0abae David Gibson
        case REMOVE_PARM:
303 a3d0abae David Gibson
            return H_PARAMETER;
304 a3d0abae David Gibson
305 a3d0abae David Gibson
        case REMOVE_HW:
306 a3d0abae David Gibson
            return H_HARDWARE;
307 a3d0abae David Gibson
        }
308 a3d0abae David Gibson
    }
309 a3d0abae David Gibson
310 f43e3525 David Gibson
    return H_SUCCESS;
311 f43e3525 David Gibson
}
312 f43e3525 David Gibson
313 e2684c0b Andreas Färber
static target_ulong h_protect(CPUPPCState *env, sPAPREnvironment *spapr,
314 f43e3525 David Gibson
                              target_ulong opcode, target_ulong *args)
315 f43e3525 David Gibson
{
316 f43e3525 David Gibson
    target_ulong flags = args[0];
317 f43e3525 David Gibson
    target_ulong pte_index = args[1];
318 f43e3525 David Gibson
    target_ulong avpn = args[2];
319 f43e3525 David Gibson
    uint8_t *hpte;
320 f43e3525 David Gibson
    target_ulong v, r, rb;
321 f43e3525 David Gibson
322 f43e3525 David Gibson
    if ((pte_index * HASH_PTE_SIZE_64) & ~env->htab_mask) {
323 f43e3525 David Gibson
        return H_PARAMETER;
324 f43e3525 David Gibson
    }
325 f43e3525 David Gibson
326 f43e3525 David Gibson
    hpte = env->external_htab + (pte_index * HASH_PTE_SIZE_64);
327 f43e3525 David Gibson
    while (!lock_hpte(hpte, HPTE_V_HVLOCK)) {
328 f43e3525 David Gibson
        /* We have no real concurrency in qemu soft-emulation, so we
329 f43e3525 David Gibson
         * will never actually have a contested lock */
330 f43e3525 David Gibson
        assert(0);
331 f43e3525 David Gibson
    }
332 f43e3525 David Gibson
333 f43e3525 David Gibson
    v = ldq_p(hpte);
334 f43e3525 David Gibson
    r = ldq_p(hpte + (HASH_PTE_SIZE_64/2));
335 f43e3525 David Gibson
336 f43e3525 David Gibson
    if ((v & HPTE_V_VALID) == 0 ||
337 f43e3525 David Gibson
        ((flags & H_AVPN) && (v & ~0x7fULL) != avpn)) {
338 f43e3525 David Gibson
        stq_p(hpte, v & ~HPTE_V_HVLOCK);
339 f43e3525 David Gibson
        assert(!(ldq_p(hpte) & HPTE_V_HVLOCK));
340 f43e3525 David Gibson
        return H_NOT_FOUND;
341 f43e3525 David Gibson
    }
342 f43e3525 David Gibson
343 f43e3525 David Gibson
    r &= ~(HPTE_R_PP0 | HPTE_R_PP | HPTE_R_N |
344 f43e3525 David Gibson
           HPTE_R_KEY_HI | HPTE_R_KEY_LO);
345 f43e3525 David Gibson
    r |= (flags << 55) & HPTE_R_PP0;
346 f43e3525 David Gibson
    r |= (flags << 48) & HPTE_R_KEY_HI;
347 f43e3525 David Gibson
    r |= flags & (HPTE_R_PP | HPTE_R_N | HPTE_R_KEY_LO);
348 f43e3525 David Gibson
    rb = compute_tlbie_rb(v, r, pte_index);
349 f43e3525 David Gibson
    stq_p(hpte, v & ~HPTE_V_VALID);
350 f43e3525 David Gibson
    ppc_tlb_invalidate_one(env, rb);
351 f43e3525 David Gibson
    stq_p(hpte + (HASH_PTE_SIZE_64/2), r);
352 f43e3525 David Gibson
    /* Don't need a memory barrier, due to qemu's global lock */
353 f43e3525 David Gibson
    stq_p(hpte, v & ~HPTE_V_HVLOCK);
354 f43e3525 David Gibson
    assert(!(ldq_p(hpte) & HPTE_V_HVLOCK));
355 f43e3525 David Gibson
    return H_SUCCESS;
356 f43e3525 David Gibson
}
357 f43e3525 David Gibson
358 e2684c0b Andreas Färber
static target_ulong h_set_dabr(CPUPPCState *env, sPAPREnvironment *spapr,
359 821303f5 David Gibson
                               target_ulong opcode, target_ulong *args)
360 821303f5 David Gibson
{
361 821303f5 David Gibson
    /* FIXME: actually implement this */
362 821303f5 David Gibson
    return H_HARDWARE;
363 821303f5 David Gibson
}
364 821303f5 David Gibson
365 ed120055 David Gibson
#define FLAGS_REGISTER_VPA         0x0000200000000000ULL
366 ed120055 David Gibson
#define FLAGS_REGISTER_DTL         0x0000400000000000ULL
367 ed120055 David Gibson
#define FLAGS_REGISTER_SLBSHADOW   0x0000600000000000ULL
368 ed120055 David Gibson
#define FLAGS_DEREGISTER_VPA       0x0000a00000000000ULL
369 ed120055 David Gibson
#define FLAGS_DEREGISTER_DTL       0x0000c00000000000ULL
370 ed120055 David Gibson
#define FLAGS_DEREGISTER_SLBSHADOW 0x0000e00000000000ULL
371 ed120055 David Gibson
372 ed120055 David Gibson
#define VPA_MIN_SIZE           640
373 ed120055 David Gibson
#define VPA_SIZE_OFFSET        0x4
374 ed120055 David Gibson
#define VPA_SHARED_PROC_OFFSET 0x9
375 ed120055 David Gibson
#define VPA_SHARED_PROC_VAL    0x2
376 ed120055 David Gibson
377 e2684c0b Andreas Färber
static target_ulong register_vpa(CPUPPCState *env, target_ulong vpa)
378 ed120055 David Gibson
{
379 ed120055 David Gibson
    uint16_t size;
380 ed120055 David Gibson
    uint8_t tmp;
381 ed120055 David Gibson
382 ed120055 David Gibson
    if (vpa == 0) {
383 ed120055 David Gibson
        hcall_dprintf("Can't cope with registering a VPA at logical 0\n");
384 ed120055 David Gibson
        return H_HARDWARE;
385 ed120055 David Gibson
    }
386 ed120055 David Gibson
387 ed120055 David Gibson
    if (vpa % env->dcache_line_size) {
388 ed120055 David Gibson
        return H_PARAMETER;
389 ed120055 David Gibson
    }
390 ed120055 David Gibson
    /* FIXME: bounds check the address */
391 ed120055 David Gibson
392 06c46bba Alexander Graf
    size = lduw_be_phys(vpa + 0x4);
393 ed120055 David Gibson
394 ed120055 David Gibson
    if (size < VPA_MIN_SIZE) {
395 ed120055 David Gibson
        return H_PARAMETER;
396 ed120055 David Gibson
    }
397 ed120055 David Gibson
398 ed120055 David Gibson
    /* VPA is not allowed to cross a page boundary */
399 ed120055 David Gibson
    if ((vpa / 4096) != ((vpa + size - 1) / 4096)) {
400 ed120055 David Gibson
        return H_PARAMETER;
401 ed120055 David Gibson
    }
402 ed120055 David Gibson
403 ed120055 David Gibson
    env->vpa = vpa;
404 ed120055 David Gibson
405 ed120055 David Gibson
    tmp = ldub_phys(env->vpa + VPA_SHARED_PROC_OFFSET);
406 ed120055 David Gibson
    tmp |= VPA_SHARED_PROC_VAL;
407 ed120055 David Gibson
    stb_phys(env->vpa + VPA_SHARED_PROC_OFFSET, tmp);
408 ed120055 David Gibson
409 ed120055 David Gibson
    return H_SUCCESS;
410 ed120055 David Gibson
}
411 ed120055 David Gibson
412 e2684c0b Andreas Färber
static target_ulong deregister_vpa(CPUPPCState *env, target_ulong vpa)
413 ed120055 David Gibson
{
414 ed120055 David Gibson
    if (env->slb_shadow) {
415 ed120055 David Gibson
        return H_RESOURCE;
416 ed120055 David Gibson
    }
417 ed120055 David Gibson
418 ed120055 David Gibson
    if (env->dispatch_trace_log) {
419 ed120055 David Gibson
        return H_RESOURCE;
420 ed120055 David Gibson
    }
421 ed120055 David Gibson
422 ed120055 David Gibson
    env->vpa = 0;
423 ed120055 David Gibson
    return H_SUCCESS;
424 ed120055 David Gibson
}
425 ed120055 David Gibson
426 e2684c0b Andreas Färber
static target_ulong register_slb_shadow(CPUPPCState *env, target_ulong addr)
427 ed120055 David Gibson
{
428 ed120055 David Gibson
    uint32_t size;
429 ed120055 David Gibson
430 ed120055 David Gibson
    if (addr == 0) {
431 ed120055 David Gibson
        hcall_dprintf("Can't cope with SLB shadow at logical 0\n");
432 ed120055 David Gibson
        return H_HARDWARE;
433 ed120055 David Gibson
    }
434 ed120055 David Gibson
435 06c46bba Alexander Graf
    size = ldl_be_phys(addr + 0x4);
436 ed120055 David Gibson
    if (size < 0x8) {
437 ed120055 David Gibson
        return H_PARAMETER;
438 ed120055 David Gibson
    }
439 ed120055 David Gibson
440 ed120055 David Gibson
    if ((addr / 4096) != ((addr + size - 1) / 4096)) {
441 ed120055 David Gibson
        return H_PARAMETER;
442 ed120055 David Gibson
    }
443 ed120055 David Gibson
444 ed120055 David Gibson
    if (!env->vpa) {
445 ed120055 David Gibson
        return H_RESOURCE;
446 ed120055 David Gibson
    }
447 ed120055 David Gibson
448 ed120055 David Gibson
    env->slb_shadow = addr;
449 ed120055 David Gibson
450 ed120055 David Gibson
    return H_SUCCESS;
451 ed120055 David Gibson
}
452 ed120055 David Gibson
453 e2684c0b Andreas Färber
static target_ulong deregister_slb_shadow(CPUPPCState *env, target_ulong addr)
454 ed120055 David Gibson
{
455 ed120055 David Gibson
    env->slb_shadow = 0;
456 ed120055 David Gibson
    return H_SUCCESS;
457 ed120055 David Gibson
}
458 ed120055 David Gibson
459 e2684c0b Andreas Färber
static target_ulong register_dtl(CPUPPCState *env, target_ulong addr)
460 ed120055 David Gibson
{
461 ed120055 David Gibson
    uint32_t size;
462 ed120055 David Gibson
463 ed120055 David Gibson
    if (addr == 0) {
464 ed120055 David Gibson
        hcall_dprintf("Can't cope with DTL at logical 0\n");
465 ed120055 David Gibson
        return H_HARDWARE;
466 ed120055 David Gibson
    }
467 ed120055 David Gibson
468 06c46bba Alexander Graf
    size = ldl_be_phys(addr + 0x4);
469 ed120055 David Gibson
470 ed120055 David Gibson
    if (size < 48) {
471 ed120055 David Gibson
        return H_PARAMETER;
472 ed120055 David Gibson
    }
473 ed120055 David Gibson
474 ed120055 David Gibson
    if (!env->vpa) {
475 ed120055 David Gibson
        return H_RESOURCE;
476 ed120055 David Gibson
    }
477 ed120055 David Gibson
478 ed120055 David Gibson
    env->dispatch_trace_log = addr;
479 ed120055 David Gibson
    env->dtl_size = size;
480 ed120055 David Gibson
481 ed120055 David Gibson
    return H_SUCCESS;
482 ed120055 David Gibson
}
483 ed120055 David Gibson
484 73f7821b Peter Portante
static target_ulong deregister_dtl(CPUPPCState *env, target_ulong addr)
485 ed120055 David Gibson
{
486 ed120055 David Gibson
    env->dispatch_trace_log = 0;
487 ed120055 David Gibson
    env->dtl_size = 0;
488 ed120055 David Gibson
489 ed120055 David Gibson
    return H_SUCCESS;
490 ed120055 David Gibson
}
491 ed120055 David Gibson
492 e2684c0b Andreas Färber
static target_ulong h_register_vpa(CPUPPCState *env, sPAPREnvironment *spapr,
493 ed120055 David Gibson
                                   target_ulong opcode, target_ulong *args)
494 ed120055 David Gibson
{
495 ed120055 David Gibson
    target_ulong flags = args[0];
496 ed120055 David Gibson
    target_ulong procno = args[1];
497 ed120055 David Gibson
    target_ulong vpa = args[2];
498 ed120055 David Gibson
    target_ulong ret = H_PARAMETER;
499 e2684c0b Andreas Färber
    CPUPPCState *tenv;
500 ed120055 David Gibson
501 ed120055 David Gibson
    for (tenv = first_cpu; tenv; tenv = tenv->next_cpu) {
502 ed120055 David Gibson
        if (tenv->cpu_index == procno) {
503 ed120055 David Gibson
            break;
504 ed120055 David Gibson
        }
505 ed120055 David Gibson
    }
506 ed120055 David Gibson
507 ed120055 David Gibson
    if (!tenv) {
508 ed120055 David Gibson
        return H_PARAMETER;
509 ed120055 David Gibson
    }
510 ed120055 David Gibson
511 ed120055 David Gibson
    switch (flags) {
512 ed120055 David Gibson
    case FLAGS_REGISTER_VPA:
513 ed120055 David Gibson
        ret = register_vpa(tenv, vpa);
514 ed120055 David Gibson
        break;
515 ed120055 David Gibson
516 ed120055 David Gibson
    case FLAGS_DEREGISTER_VPA:
517 ed120055 David Gibson
        ret = deregister_vpa(tenv, vpa);
518 ed120055 David Gibson
        break;
519 ed120055 David Gibson
520 ed120055 David Gibson
    case FLAGS_REGISTER_SLBSHADOW:
521 ed120055 David Gibson
        ret = register_slb_shadow(tenv, vpa);
522 ed120055 David Gibson
        break;
523 ed120055 David Gibson
524 ed120055 David Gibson
    case FLAGS_DEREGISTER_SLBSHADOW:
525 ed120055 David Gibson
        ret = deregister_slb_shadow(tenv, vpa);
526 ed120055 David Gibson
        break;
527 ed120055 David Gibson
528 ed120055 David Gibson
    case FLAGS_REGISTER_DTL:
529 ed120055 David Gibson
        ret = register_dtl(tenv, vpa);
530 ed120055 David Gibson
        break;
531 ed120055 David Gibson
532 ed120055 David Gibson
    case FLAGS_DEREGISTER_DTL:
533 ed120055 David Gibson
        ret = deregister_dtl(tenv, vpa);
534 ed120055 David Gibson
        break;
535 ed120055 David Gibson
    }
536 ed120055 David Gibson
537 ed120055 David Gibson
    return ret;
538 ed120055 David Gibson
}
539 ed120055 David Gibson
540 e2684c0b Andreas Färber
static target_ulong h_cede(CPUPPCState *env, sPAPREnvironment *spapr,
541 ed120055 David Gibson
                           target_ulong opcode, target_ulong *args)
542 ed120055 David Gibson
{
543 ed120055 David Gibson
    env->msr |= (1ULL << MSR_EE);
544 ed120055 David Gibson
    hreg_compute_hflags(env);
545 ed120055 David Gibson
    if (!cpu_has_work(env)) {
546 ed120055 David Gibson
        env->halted = 1;
547 ed120055 David Gibson
    }
548 ed120055 David Gibson
    return H_SUCCESS;
549 ed120055 David Gibson
}
550 ed120055 David Gibson
551 e2684c0b Andreas Färber
static target_ulong h_rtas(CPUPPCState *env, sPAPREnvironment *spapr,
552 39ac8455 David Gibson
                           target_ulong opcode, target_ulong *args)
553 39ac8455 David Gibson
{
554 39ac8455 David Gibson
    target_ulong rtas_r3 = args[0];
555 06c46bba Alexander Graf
    uint32_t token = ldl_be_phys(rtas_r3);
556 06c46bba Alexander Graf
    uint32_t nargs = ldl_be_phys(rtas_r3 + 4);
557 06c46bba Alexander Graf
    uint32_t nret = ldl_be_phys(rtas_r3 + 8);
558 39ac8455 David Gibson
559 39ac8455 David Gibson
    return spapr_rtas_call(spapr, token, nargs, rtas_r3 + 12,
560 39ac8455 David Gibson
                           nret, rtas_r3 + 12 + 4*nargs);
561 39ac8455 David Gibson
}
562 39ac8455 David Gibson
563 e2684c0b Andreas Färber
static target_ulong h_logical_load(CPUPPCState *env, sPAPREnvironment *spapr,
564 827200a2 David Gibson
                                   target_ulong opcode, target_ulong *args)
565 827200a2 David Gibson
{
566 827200a2 David Gibson
    target_ulong size = args[0];
567 827200a2 David Gibson
    target_ulong addr = args[1];
568 827200a2 David Gibson
569 827200a2 David Gibson
    switch (size) {
570 827200a2 David Gibson
    case 1:
571 827200a2 David Gibson
        args[0] = ldub_phys(addr);
572 827200a2 David Gibson
        return H_SUCCESS;
573 827200a2 David Gibson
    case 2:
574 827200a2 David Gibson
        args[0] = lduw_phys(addr);
575 827200a2 David Gibson
        return H_SUCCESS;
576 827200a2 David Gibson
    case 4:
577 827200a2 David Gibson
        args[0] = ldl_phys(addr);
578 827200a2 David Gibson
        return H_SUCCESS;
579 827200a2 David Gibson
    case 8:
580 827200a2 David Gibson
        args[0] = ldq_phys(addr);
581 827200a2 David Gibson
        return H_SUCCESS;
582 827200a2 David Gibson
    }
583 827200a2 David Gibson
    return H_PARAMETER;
584 827200a2 David Gibson
}
585 827200a2 David Gibson
586 e2684c0b Andreas Färber
static target_ulong h_logical_store(CPUPPCState *env, sPAPREnvironment *spapr,
587 827200a2 David Gibson
                                    target_ulong opcode, target_ulong *args)
588 827200a2 David Gibson
{
589 827200a2 David Gibson
    target_ulong size = args[0];
590 827200a2 David Gibson
    target_ulong addr = args[1];
591 827200a2 David Gibson
    target_ulong val  = args[2];
592 827200a2 David Gibson
593 827200a2 David Gibson
    switch (size) {
594 827200a2 David Gibson
    case 1:
595 827200a2 David Gibson
        stb_phys(addr, val);
596 827200a2 David Gibson
        return H_SUCCESS;
597 827200a2 David Gibson
    case 2:
598 827200a2 David Gibson
        stw_phys(addr, val);
599 827200a2 David Gibson
        return H_SUCCESS;
600 827200a2 David Gibson
    case 4:
601 827200a2 David Gibson
        stl_phys(addr, val);
602 827200a2 David Gibson
        return H_SUCCESS;
603 827200a2 David Gibson
    case 8:
604 827200a2 David Gibson
        stq_phys(addr, val);
605 827200a2 David Gibson
        return H_SUCCESS;
606 827200a2 David Gibson
    }
607 827200a2 David Gibson
    return H_PARAMETER;
608 827200a2 David Gibson
}
609 827200a2 David Gibson
610 c73e3771 Benjamin Herrenschmidt
static target_ulong h_logical_memop(CPUPPCState *env, sPAPREnvironment *spapr,
611 c73e3771 Benjamin Herrenschmidt
                                    target_ulong opcode, target_ulong *args)
612 c73e3771 Benjamin Herrenschmidt
{
613 c73e3771 Benjamin Herrenschmidt
    target_ulong dst   = args[0]; /* Destination address */
614 c73e3771 Benjamin Herrenschmidt
    target_ulong src   = args[1]; /* Source address */
615 c73e3771 Benjamin Herrenschmidt
    target_ulong esize = args[2]; /* Element size (0=1,1=2,2=4,3=8) */
616 c73e3771 Benjamin Herrenschmidt
    target_ulong count = args[3]; /* Element count */
617 c73e3771 Benjamin Herrenschmidt
    target_ulong op    = args[4]; /* 0 = copy, 1 = invert */
618 c73e3771 Benjamin Herrenschmidt
    uint64_t tmp;
619 c73e3771 Benjamin Herrenschmidt
    unsigned int mask = (1 << esize) - 1;
620 c73e3771 Benjamin Herrenschmidt
    int step = 1 << esize;
621 c73e3771 Benjamin Herrenschmidt
622 c73e3771 Benjamin Herrenschmidt
    if (count > 0x80000000) {
623 c73e3771 Benjamin Herrenschmidt
        return H_PARAMETER;
624 c73e3771 Benjamin Herrenschmidt
    }
625 c73e3771 Benjamin Herrenschmidt
626 c73e3771 Benjamin Herrenschmidt
    if ((dst & mask) || (src & mask) || (op > 1)) {
627 c73e3771 Benjamin Herrenschmidt
        return H_PARAMETER;
628 c73e3771 Benjamin Herrenschmidt
    }
629 c73e3771 Benjamin Herrenschmidt
630 c73e3771 Benjamin Herrenschmidt
    if (dst >= src && dst < (src + (count << esize))) {
631 c73e3771 Benjamin Herrenschmidt
            dst = dst + ((count - 1) << esize);
632 c73e3771 Benjamin Herrenschmidt
            src = src + ((count - 1) << esize);
633 c73e3771 Benjamin Herrenschmidt
            step = -step;
634 c73e3771 Benjamin Herrenschmidt
    }
635 c73e3771 Benjamin Herrenschmidt
636 c73e3771 Benjamin Herrenschmidt
    while (count--) {
637 c73e3771 Benjamin Herrenschmidt
        switch (esize) {
638 c73e3771 Benjamin Herrenschmidt
        case 0:
639 c73e3771 Benjamin Herrenschmidt
            tmp = ldub_phys(src);
640 c73e3771 Benjamin Herrenschmidt
            break;
641 c73e3771 Benjamin Herrenschmidt
        case 1:
642 c73e3771 Benjamin Herrenschmidt
            tmp = lduw_phys(src);
643 c73e3771 Benjamin Herrenschmidt
            break;
644 c73e3771 Benjamin Herrenschmidt
        case 2:
645 c73e3771 Benjamin Herrenschmidt
            tmp = ldl_phys(src);
646 c73e3771 Benjamin Herrenschmidt
            break;
647 c73e3771 Benjamin Herrenschmidt
        case 3:
648 c73e3771 Benjamin Herrenschmidt
            tmp = ldq_phys(src);
649 c73e3771 Benjamin Herrenschmidt
            break;
650 c73e3771 Benjamin Herrenschmidt
        default:
651 c73e3771 Benjamin Herrenschmidt
            return H_PARAMETER;
652 c73e3771 Benjamin Herrenschmidt
        }
653 c73e3771 Benjamin Herrenschmidt
        if (op == 1) {
654 c73e3771 Benjamin Herrenschmidt
            tmp = ~tmp;
655 c73e3771 Benjamin Herrenschmidt
        }
656 c73e3771 Benjamin Herrenschmidt
        switch (esize) {
657 c73e3771 Benjamin Herrenschmidt
        case 0:
658 c73e3771 Benjamin Herrenschmidt
            stb_phys(dst, tmp);
659 c73e3771 Benjamin Herrenschmidt
            break;
660 c73e3771 Benjamin Herrenschmidt
        case 1:
661 c73e3771 Benjamin Herrenschmidt
            stw_phys(dst, tmp);
662 c73e3771 Benjamin Herrenschmidt
            break;
663 c73e3771 Benjamin Herrenschmidt
        case 2:
664 c73e3771 Benjamin Herrenschmidt
            stl_phys(dst, tmp);
665 c73e3771 Benjamin Herrenschmidt
            break;
666 c73e3771 Benjamin Herrenschmidt
        case 3:
667 c73e3771 Benjamin Herrenschmidt
            stq_phys(dst, tmp);
668 c73e3771 Benjamin Herrenschmidt
            break;
669 c73e3771 Benjamin Herrenschmidt
        }
670 c73e3771 Benjamin Herrenschmidt
        dst = dst + step;
671 c73e3771 Benjamin Herrenschmidt
        src = src + step;
672 c73e3771 Benjamin Herrenschmidt
    }
673 c73e3771 Benjamin Herrenschmidt
674 c73e3771 Benjamin Herrenschmidt
    return H_SUCCESS;
675 c73e3771 Benjamin Herrenschmidt
}
676 c73e3771 Benjamin Herrenschmidt
677 e2684c0b Andreas Färber
static target_ulong h_logical_icbi(CPUPPCState *env, sPAPREnvironment *spapr,
678 827200a2 David Gibson
                                   target_ulong opcode, target_ulong *args)
679 827200a2 David Gibson
{
680 827200a2 David Gibson
    /* Nothing to do on emulation, KVM will trap this in the kernel */
681 827200a2 David Gibson
    return H_SUCCESS;
682 827200a2 David Gibson
}
683 827200a2 David Gibson
684 e2684c0b Andreas Färber
static target_ulong h_logical_dcbf(CPUPPCState *env, sPAPREnvironment *spapr,
685 827200a2 David Gibson
                                   target_ulong opcode, target_ulong *args)
686 827200a2 David Gibson
{
687 827200a2 David Gibson
    /* Nothing to do on emulation, KVM will trap this in the kernel */
688 827200a2 David Gibson
    return H_SUCCESS;
689 827200a2 David Gibson
}
690 827200a2 David Gibson
691 7d7ba3fe David Gibson
static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1];
692 7d7ba3fe David Gibson
static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - KVMPPC_HCALL_BASE + 1];
693 9fdf0c29 David Gibson
694 9fdf0c29 David Gibson
void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn)
695 9fdf0c29 David Gibson
{
696 39ac8455 David Gibson
    spapr_hcall_fn *slot;
697 39ac8455 David Gibson
698 39ac8455 David Gibson
    if (opcode <= MAX_HCALL_OPCODE) {
699 39ac8455 David Gibson
        assert((opcode & 0x3) == 0);
700 9fdf0c29 David Gibson
701 39ac8455 David Gibson
        slot = &papr_hypercall_table[opcode / 4];
702 39ac8455 David Gibson
    } else {
703 39ac8455 David Gibson
        assert((opcode >= KVMPPC_HCALL_BASE) && (opcode <= KVMPPC_HCALL_MAX));
704 9fdf0c29 David Gibson
705 9fdf0c29 David Gibson
706 39ac8455 David Gibson
        slot = &kvmppc_hypercall_table[opcode - KVMPPC_HCALL_BASE];
707 39ac8455 David Gibson
    }
708 9fdf0c29 David Gibson
709 39ac8455 David Gibson
    assert(!(*slot) || (fn == *slot));
710 39ac8455 David Gibson
    *slot = fn;
711 9fdf0c29 David Gibson
}
712 9fdf0c29 David Gibson
713 e2684c0b Andreas Färber
target_ulong spapr_hypercall(CPUPPCState *env, target_ulong opcode,
714 9fdf0c29 David Gibson
                             target_ulong *args)
715 9fdf0c29 David Gibson
{
716 9fdf0c29 David Gibson
    if (msr_pr) {
717 9fdf0c29 David Gibson
        hcall_dprintf("Hypercall made with MSR[PR]=1\n");
718 9fdf0c29 David Gibson
        return H_PRIVILEGE;
719 9fdf0c29 David Gibson
    }
720 9fdf0c29 David Gibson
721 9fdf0c29 David Gibson
    if ((opcode <= MAX_HCALL_OPCODE)
722 9fdf0c29 David Gibson
        && ((opcode & 0x3) == 0)) {
723 39ac8455 David Gibson
        spapr_hcall_fn fn = papr_hypercall_table[opcode / 4];
724 39ac8455 David Gibson
725 39ac8455 David Gibson
        if (fn) {
726 39ac8455 David Gibson
            return fn(env, spapr, opcode, args);
727 39ac8455 David Gibson
        }
728 39ac8455 David Gibson
    } else if ((opcode >= KVMPPC_HCALL_BASE) &&
729 39ac8455 David Gibson
               (opcode <= KVMPPC_HCALL_MAX)) {
730 39ac8455 David Gibson
        spapr_hcall_fn fn = kvmppc_hypercall_table[opcode - KVMPPC_HCALL_BASE];
731 9fdf0c29 David Gibson
732 9fdf0c29 David Gibson
        if (fn) {
733 9fdf0c29 David Gibson
            return fn(env, spapr, opcode, args);
734 9fdf0c29 David Gibson
        }
735 9fdf0c29 David Gibson
    }
736 9fdf0c29 David Gibson
737 9fdf0c29 David Gibson
    hcall_dprintf("Unimplemented hcall 0x" TARGET_FMT_lx "\n", opcode);
738 9fdf0c29 David Gibson
    return H_FUNCTION;
739 9fdf0c29 David Gibson
}
740 f43e3525 David Gibson
741 83f7d43a Andreas Färber
static void hypercall_register_types(void)
742 f43e3525 David Gibson
{
743 f43e3525 David Gibson
    /* hcall-pft */
744 f43e3525 David Gibson
    spapr_register_hypercall(H_ENTER, h_enter);
745 f43e3525 David Gibson
    spapr_register_hypercall(H_REMOVE, h_remove);
746 f43e3525 David Gibson
    spapr_register_hypercall(H_PROTECT, h_protect);
747 39ac8455 David Gibson
748 a3d0abae David Gibson
    /* hcall-bulk */
749 a3d0abae David Gibson
    spapr_register_hypercall(H_BULK_REMOVE, h_bulk_remove);
750 a3d0abae David Gibson
751 821303f5 David Gibson
    /* hcall-dabr */
752 821303f5 David Gibson
    spapr_register_hypercall(H_SET_DABR, h_set_dabr);
753 821303f5 David Gibson
754 ed120055 David Gibson
    /* hcall-splpar */
755 ed120055 David Gibson
    spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa);
756 ed120055 David Gibson
    spapr_register_hypercall(H_CEDE, h_cede);
757 ed120055 David Gibson
758 827200a2 David Gibson
    /* "debugger" hcalls (also used by SLOF). Note: We do -not- differenciate
759 827200a2 David Gibson
     * here between the "CI" and the "CACHE" variants, they will use whatever
760 827200a2 David Gibson
     * mapping attributes qemu is using. When using KVM, the kernel will
761 827200a2 David Gibson
     * enforce the attributes more strongly
762 827200a2 David Gibson
     */
763 827200a2 David Gibson
    spapr_register_hypercall(H_LOGICAL_CI_LOAD, h_logical_load);
764 827200a2 David Gibson
    spapr_register_hypercall(H_LOGICAL_CI_STORE, h_logical_store);
765 827200a2 David Gibson
    spapr_register_hypercall(H_LOGICAL_CACHE_LOAD, h_logical_load);
766 827200a2 David Gibson
    spapr_register_hypercall(H_LOGICAL_CACHE_STORE, h_logical_store);
767 827200a2 David Gibson
    spapr_register_hypercall(H_LOGICAL_ICBI, h_logical_icbi);
768 827200a2 David Gibson
    spapr_register_hypercall(H_LOGICAL_DCBF, h_logical_dcbf);
769 c73e3771 Benjamin Herrenschmidt
    spapr_register_hypercall(KVMPPC_H_LOGICAL_MEMOP, h_logical_memop);
770 827200a2 David Gibson
771 39ac8455 David Gibson
    /* qemu/KVM-PPC specific hcalls */
772 39ac8455 David Gibson
    spapr_register_hypercall(KVMPPC_H_RTAS, h_rtas);
773 f43e3525 David Gibson
}
774 83f7d43a Andreas Färber
775 83f7d43a Andreas Färber
type_init(hypercall_register_types)