Statistics
| Branch: | Revision:

root / hw / spapr_hcall.c @ 0ed8b6f6

History | View | Annotate | Download (21.7 kB)

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