Lines Matching +full:cs +full:- +full:1

1 /* SPDX-License-Identifier: GPL-2.0-or-later */
14 #include "qemu/error-report.h"
15 #include "qemu/main-loop.h"
21 #include "exec/address-spaces.h"
27 #include "cpu-csr.h"
37 static int kvm_get_stealtime(CPUState *cs) in kvm_get_stealtime() argument
39 CPULoongArchState *env = cpu_env(cs); in kvm_get_stealtime()
44 .addr = (uint64_t)&env->stealtime.guest_addr, in kvm_get_stealtime()
47 err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); in kvm_get_stealtime()
52 err = kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, attr); in kvm_get_stealtime()
61 static int kvm_set_stealtime(CPUState *cs) in kvm_set_stealtime() argument
63 CPULoongArchState *env = cpu_env(cs); in kvm_set_stealtime()
68 .addr = (uint64_t)&env->stealtime.guest_addr, in kvm_set_stealtime()
71 err = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, attr); in kvm_set_stealtime()
76 err = kvm_vcpu_ioctl(cs, KVM_SET_DEVICE_ATTR, attr); in kvm_set_stealtime()
79 strerror(errno), env->stealtime.guest_addr); in kvm_set_stealtime()
86 static int kvm_loongarch_get_regs_core(CPUState *cs) in kvm_loongarch_get_regs_core() argument
91 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_get_regs_core()
94 ret = kvm_vcpu_ioctl(cs, KVM_GET_REGS, &regs); in kvm_loongarch_get_regs_core()
100 env->gpr[0] = 0; in kvm_loongarch_get_regs_core()
101 for (i = 1; i < 32; i++) { in kvm_loongarch_get_regs_core()
102 env->gpr[i] = regs.gpr[i]; in kvm_loongarch_get_regs_core()
105 env->pc = regs.pc; in kvm_loongarch_get_regs_core()
109 static int kvm_loongarch_put_regs_core(CPUState *cs) in kvm_loongarch_put_regs_core() argument
114 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_put_regs_core()
118 regs.gpr[i] = env->gpr[i]; in kvm_loongarch_put_regs_core()
121 regs.pc = env->pc; in kvm_loongarch_put_regs_core()
122 ret = kvm_vcpu_ioctl(cs, KVM_SET_REGS, &regs); in kvm_loongarch_put_regs_core()
130 static int kvm_loongarch_get_csr(CPUState *cs) in kvm_loongarch_get_csr() argument
133 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_get_csr()
135 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CRMD), in kvm_loongarch_get_csr()
136 &env->CSR_CRMD); in kvm_loongarch_get_csr()
138 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRMD), in kvm_loongarch_get_csr()
139 &env->CSR_PRMD); in kvm_loongarch_get_csr()
141 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EUEN), in kvm_loongarch_get_csr()
142 &env->CSR_EUEN); in kvm_loongarch_get_csr()
144 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_MISC), in kvm_loongarch_get_csr()
145 &env->CSR_MISC); in kvm_loongarch_get_csr()
147 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ECFG), in kvm_loongarch_get_csr()
148 &env->CSR_ECFG); in kvm_loongarch_get_csr()
150 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ESTAT), in kvm_loongarch_get_csr()
151 &env->CSR_ESTAT); in kvm_loongarch_get_csr()
153 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ERA), in kvm_loongarch_get_csr()
154 &env->CSR_ERA); in kvm_loongarch_get_csr()
156 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADV), in kvm_loongarch_get_csr()
157 &env->CSR_BADV); in kvm_loongarch_get_csr()
159 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADI), in kvm_loongarch_get_csr()
160 &env->CSR_BADI); in kvm_loongarch_get_csr()
162 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EENTRY), in kvm_loongarch_get_csr()
163 &env->CSR_EENTRY); in kvm_loongarch_get_csr()
165 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBIDX), in kvm_loongarch_get_csr()
166 &env->CSR_TLBIDX); in kvm_loongarch_get_csr()
168 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBEHI), in kvm_loongarch_get_csr()
169 &env->CSR_TLBEHI); in kvm_loongarch_get_csr()
171 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO0), in kvm_loongarch_get_csr()
172 &env->CSR_TLBELO0); in kvm_loongarch_get_csr()
174 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO1), in kvm_loongarch_get_csr()
175 &env->CSR_TLBELO1); in kvm_loongarch_get_csr()
177 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ASID), in kvm_loongarch_get_csr()
178 &env->CSR_ASID); in kvm_loongarch_get_csr()
180 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDL), in kvm_loongarch_get_csr()
181 &env->CSR_PGDL); in kvm_loongarch_get_csr()
183 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDH), in kvm_loongarch_get_csr()
184 &env->CSR_PGDH); in kvm_loongarch_get_csr()
186 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGD), in kvm_loongarch_get_csr()
187 &env->CSR_PGD); in kvm_loongarch_get_csr()
189 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCL), in kvm_loongarch_get_csr()
190 &env->CSR_PWCL); in kvm_loongarch_get_csr()
192 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCH), in kvm_loongarch_get_csr()
193 &env->CSR_PWCH); in kvm_loongarch_get_csr()
195 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_STLBPS), in kvm_loongarch_get_csr()
196 &env->CSR_STLBPS); in kvm_loongarch_get_csr()
198 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_RVACFG), in kvm_loongarch_get_csr()
199 &env->CSR_RVACFG); in kvm_loongarch_get_csr()
201 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID), in kvm_loongarch_get_csr()
202 &env->CSR_CPUID); in kvm_loongarch_get_csr()
204 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG1), in kvm_loongarch_get_csr()
205 &env->CSR_PRCFG1); in kvm_loongarch_get_csr()
207 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG2), in kvm_loongarch_get_csr()
208 &env->CSR_PRCFG2); in kvm_loongarch_get_csr()
210 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG3), in kvm_loongarch_get_csr()
211 &env->CSR_PRCFG3); in kvm_loongarch_get_csr()
213 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(0)), in kvm_loongarch_get_csr()
214 &env->CSR_SAVE[0]); in kvm_loongarch_get_csr()
216 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(1)), in kvm_loongarch_get_csr()
217 &env->CSR_SAVE[1]); in kvm_loongarch_get_csr()
219 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(2)), in kvm_loongarch_get_csr()
220 &env->CSR_SAVE[2]); in kvm_loongarch_get_csr()
222 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(3)), in kvm_loongarch_get_csr()
223 &env->CSR_SAVE[3]); in kvm_loongarch_get_csr()
225 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(4)), in kvm_loongarch_get_csr()
226 &env->CSR_SAVE[4]); in kvm_loongarch_get_csr()
228 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(5)), in kvm_loongarch_get_csr()
229 &env->CSR_SAVE[5]); in kvm_loongarch_get_csr()
231 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(6)), in kvm_loongarch_get_csr()
232 &env->CSR_SAVE[6]); in kvm_loongarch_get_csr()
234 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(7)), in kvm_loongarch_get_csr()
235 &env->CSR_SAVE[7]); in kvm_loongarch_get_csr()
237 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TID), in kvm_loongarch_get_csr()
238 &env->CSR_TID); in kvm_loongarch_get_csr()
240 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CNTC), in kvm_loongarch_get_csr()
241 &env->CSR_CNTC); in kvm_loongarch_get_csr()
243 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TICLR), in kvm_loongarch_get_csr()
244 &env->CSR_TICLR); in kvm_loongarch_get_csr()
246 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_LLBCTL), in kvm_loongarch_get_csr()
247 &env->CSR_LLBCTL); in kvm_loongarch_get_csr()
249 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL1), in kvm_loongarch_get_csr()
250 &env->CSR_IMPCTL1); in kvm_loongarch_get_csr()
252 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL2), in kvm_loongarch_get_csr()
253 &env->CSR_IMPCTL2); in kvm_loongarch_get_csr()
255 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRENTRY), in kvm_loongarch_get_csr()
256 &env->CSR_TLBRENTRY); in kvm_loongarch_get_csr()
258 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRBADV), in kvm_loongarch_get_csr()
259 &env->CSR_TLBRBADV); in kvm_loongarch_get_csr()
261 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRERA), in kvm_loongarch_get_csr()
262 &env->CSR_TLBRERA); in kvm_loongarch_get_csr()
264 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRSAVE), in kvm_loongarch_get_csr()
265 &env->CSR_TLBRSAVE); in kvm_loongarch_get_csr()
267 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO0), in kvm_loongarch_get_csr()
268 &env->CSR_TLBRELO0); in kvm_loongarch_get_csr()
270 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO1), in kvm_loongarch_get_csr()
271 &env->CSR_TLBRELO1); in kvm_loongarch_get_csr()
273 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBREHI), in kvm_loongarch_get_csr()
274 &env->CSR_TLBREHI); in kvm_loongarch_get_csr()
276 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRPRMD), in kvm_loongarch_get_csr()
277 &env->CSR_TLBRPRMD); in kvm_loongarch_get_csr()
279 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(0)), in kvm_loongarch_get_csr()
280 &env->CSR_DMW[0]); in kvm_loongarch_get_csr()
282 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(1)), in kvm_loongarch_get_csr()
283 &env->CSR_DMW[1]); in kvm_loongarch_get_csr()
285 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(2)), in kvm_loongarch_get_csr()
286 &env->CSR_DMW[2]); in kvm_loongarch_get_csr()
288 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(3)), in kvm_loongarch_get_csr()
289 &env->CSR_DMW[3]); in kvm_loongarch_get_csr()
291 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TVAL), in kvm_loongarch_get_csr()
292 &env->CSR_TVAL); in kvm_loongarch_get_csr()
294 ret |= kvm_get_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TCFG), in kvm_loongarch_get_csr()
295 &env->CSR_TCFG); in kvm_loongarch_get_csr()
300 static int kvm_loongarch_put_csr(CPUState *cs, int level) in kvm_loongarch_put_csr() argument
303 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_put_csr()
305 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CRMD), in kvm_loongarch_put_csr()
306 &env->CSR_CRMD); in kvm_loongarch_put_csr()
308 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRMD), in kvm_loongarch_put_csr()
309 &env->CSR_PRMD); in kvm_loongarch_put_csr()
311 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EUEN), in kvm_loongarch_put_csr()
312 &env->CSR_EUEN); in kvm_loongarch_put_csr()
314 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_MISC), in kvm_loongarch_put_csr()
315 &env->CSR_MISC); in kvm_loongarch_put_csr()
317 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ECFG), in kvm_loongarch_put_csr()
318 &env->CSR_ECFG); in kvm_loongarch_put_csr()
320 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ESTAT), in kvm_loongarch_put_csr()
321 &env->CSR_ESTAT); in kvm_loongarch_put_csr()
323 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ERA), in kvm_loongarch_put_csr()
324 &env->CSR_ERA); in kvm_loongarch_put_csr()
326 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADV), in kvm_loongarch_put_csr()
327 &env->CSR_BADV); in kvm_loongarch_put_csr()
329 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_BADI), in kvm_loongarch_put_csr()
330 &env->CSR_BADI); in kvm_loongarch_put_csr()
332 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_EENTRY), in kvm_loongarch_put_csr()
333 &env->CSR_EENTRY); in kvm_loongarch_put_csr()
335 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBIDX), in kvm_loongarch_put_csr()
336 &env->CSR_TLBIDX); in kvm_loongarch_put_csr()
338 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBEHI), in kvm_loongarch_put_csr()
339 &env->CSR_TLBEHI); in kvm_loongarch_put_csr()
341 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO0), in kvm_loongarch_put_csr()
342 &env->CSR_TLBELO0); in kvm_loongarch_put_csr()
344 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBELO1), in kvm_loongarch_put_csr()
345 &env->CSR_TLBELO1); in kvm_loongarch_put_csr()
347 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_ASID), in kvm_loongarch_put_csr()
348 &env->CSR_ASID); in kvm_loongarch_put_csr()
350 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDL), in kvm_loongarch_put_csr()
351 &env->CSR_PGDL); in kvm_loongarch_put_csr()
353 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGDH), in kvm_loongarch_put_csr()
354 &env->CSR_PGDH); in kvm_loongarch_put_csr()
356 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PGD), in kvm_loongarch_put_csr()
357 &env->CSR_PGD); in kvm_loongarch_put_csr()
359 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCL), in kvm_loongarch_put_csr()
360 &env->CSR_PWCL); in kvm_loongarch_put_csr()
362 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PWCH), in kvm_loongarch_put_csr()
363 &env->CSR_PWCH); in kvm_loongarch_put_csr()
365 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_STLBPS), in kvm_loongarch_put_csr()
366 &env->CSR_STLBPS); in kvm_loongarch_put_csr()
368 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_RVACFG), in kvm_loongarch_put_csr()
369 &env->CSR_RVACFG); in kvm_loongarch_put_csr()
373 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CPUID), in kvm_loongarch_put_csr()
374 &env->CSR_CPUID); in kvm_loongarch_put_csr()
377 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG1), in kvm_loongarch_put_csr()
378 &env->CSR_PRCFG1); in kvm_loongarch_put_csr()
380 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG2), in kvm_loongarch_put_csr()
381 &env->CSR_PRCFG2); in kvm_loongarch_put_csr()
383 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_PRCFG3), in kvm_loongarch_put_csr()
384 &env->CSR_PRCFG3); in kvm_loongarch_put_csr()
386 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(0)), in kvm_loongarch_put_csr()
387 &env->CSR_SAVE[0]); in kvm_loongarch_put_csr()
389 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(1)), in kvm_loongarch_put_csr()
390 &env->CSR_SAVE[1]); in kvm_loongarch_put_csr()
392 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(2)), in kvm_loongarch_put_csr()
393 &env->CSR_SAVE[2]); in kvm_loongarch_put_csr()
395 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(3)), in kvm_loongarch_put_csr()
396 &env->CSR_SAVE[3]); in kvm_loongarch_put_csr()
398 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(4)), in kvm_loongarch_put_csr()
399 &env->CSR_SAVE[4]); in kvm_loongarch_put_csr()
401 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(5)), in kvm_loongarch_put_csr()
402 &env->CSR_SAVE[5]); in kvm_loongarch_put_csr()
404 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(6)), in kvm_loongarch_put_csr()
405 &env->CSR_SAVE[6]); in kvm_loongarch_put_csr()
407 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_SAVE(7)), in kvm_loongarch_put_csr()
408 &env->CSR_SAVE[7]); in kvm_loongarch_put_csr()
410 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TID), in kvm_loongarch_put_csr()
411 &env->CSR_TID); in kvm_loongarch_put_csr()
413 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_CNTC), in kvm_loongarch_put_csr()
414 &env->CSR_CNTC); in kvm_loongarch_put_csr()
416 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TICLR), in kvm_loongarch_put_csr()
417 &env->CSR_TICLR); in kvm_loongarch_put_csr()
419 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_LLBCTL), in kvm_loongarch_put_csr()
420 &env->CSR_LLBCTL); in kvm_loongarch_put_csr()
422 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL1), in kvm_loongarch_put_csr()
423 &env->CSR_IMPCTL1); in kvm_loongarch_put_csr()
425 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_IMPCTL2), in kvm_loongarch_put_csr()
426 &env->CSR_IMPCTL2); in kvm_loongarch_put_csr()
428 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRENTRY), in kvm_loongarch_put_csr()
429 &env->CSR_TLBRENTRY); in kvm_loongarch_put_csr()
431 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRBADV), in kvm_loongarch_put_csr()
432 &env->CSR_TLBRBADV); in kvm_loongarch_put_csr()
434 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRERA), in kvm_loongarch_put_csr()
435 &env->CSR_TLBRERA); in kvm_loongarch_put_csr()
437 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRSAVE), in kvm_loongarch_put_csr()
438 &env->CSR_TLBRSAVE); in kvm_loongarch_put_csr()
440 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO0), in kvm_loongarch_put_csr()
441 &env->CSR_TLBRELO0); in kvm_loongarch_put_csr()
443 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRELO1), in kvm_loongarch_put_csr()
444 &env->CSR_TLBRELO1); in kvm_loongarch_put_csr()
446 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBREHI), in kvm_loongarch_put_csr()
447 &env->CSR_TLBREHI); in kvm_loongarch_put_csr()
449 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TLBRPRMD), in kvm_loongarch_put_csr()
450 &env->CSR_TLBRPRMD); in kvm_loongarch_put_csr()
452 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(0)), in kvm_loongarch_put_csr()
453 &env->CSR_DMW[0]); in kvm_loongarch_put_csr()
455 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(1)), in kvm_loongarch_put_csr()
456 &env->CSR_DMW[1]); in kvm_loongarch_put_csr()
458 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(2)), in kvm_loongarch_put_csr()
459 &env->CSR_DMW[2]); in kvm_loongarch_put_csr()
461 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_DMW(3)), in kvm_loongarch_put_csr()
462 &env->CSR_DMW[3]); in kvm_loongarch_put_csr()
467 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TVAL), in kvm_loongarch_put_csr()
468 &env->CSR_TVAL); in kvm_loongarch_put_csr()
470 ret |= kvm_set_one_reg(cs, KVM_IOC_CSRID(LOONGARCH_CSR_TCFG), in kvm_loongarch_put_csr()
471 &env->CSR_TCFG); in kvm_loongarch_put_csr()
475 static int kvm_loongarch_get_regs_fp(CPUState *cs) in kvm_loongarch_get_regs_fp() argument
479 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_get_regs_fp()
481 ret = kvm_vcpu_ioctl(cs, KVM_GET_FPU, &fpu); in kvm_loongarch_get_regs_fp()
487 env->fcsr0 = fpu.fcsr; in kvm_loongarch_get_regs_fp()
489 env->fpr[i].vreg.UD[0] = fpu.fpr[i].val64[0]; in kvm_loongarch_get_regs_fp()
490 env->fpr[i].vreg.UD[1] = fpu.fpr[i].val64[1]; in kvm_loongarch_get_regs_fp()
491 env->fpr[i].vreg.UD[2] = fpu.fpr[i].val64[2]; in kvm_loongarch_get_regs_fp()
492 env->fpr[i].vreg.UD[3] = fpu.fpr[i].val64[3]; in kvm_loongarch_get_regs_fp()
495 env->cf[i] = fpu.fcc & 0xFF; in kvm_loongarch_get_regs_fp()
502 static int kvm_loongarch_put_regs_fp(CPUState *cs) in kvm_loongarch_put_regs_fp() argument
506 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_put_regs_fp()
508 fpu.fcsr = env->fcsr0; in kvm_loongarch_put_regs_fp()
511 fpu.fpr[i].val64[0] = env->fpr[i].vreg.UD[0]; in kvm_loongarch_put_regs_fp()
512 fpu.fpr[i].val64[1] = env->fpr[i].vreg.UD[1]; in kvm_loongarch_put_regs_fp()
513 fpu.fpr[i].val64[2] = env->fpr[i].vreg.UD[2]; in kvm_loongarch_put_regs_fp()
514 fpu.fpr[i].val64[3] = env->fpr[i].vreg.UD[3]; in kvm_loongarch_put_regs_fp()
518 fpu.fcc |= env->cf[i] << (8 * i); in kvm_loongarch_put_regs_fp()
521 ret = kvm_vcpu_ioctl(cs, KVM_SET_FPU, &fpu); in kvm_loongarch_put_regs_fp()
529 static int kvm_loongarch_put_lbt(CPUState *cs) in kvm_loongarch_put_lbt() argument
531 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_put_lbt()
536 if (FIELD_EX32(env->cpucfg[2], CPUCFG2, LBT_ALL) != 7) { in kvm_loongarch_put_lbt()
540 /* set six LBT registers including scr0-scr3, eflags, ftop */ in kvm_loongarch_put_lbt()
541 ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR0, &env->lbt.scr0); in kvm_loongarch_put_lbt()
542 ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR1, &env->lbt.scr1); in kvm_loongarch_put_lbt()
543 ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR2, &env->lbt.scr2); in kvm_loongarch_put_lbt()
544 ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR3, &env->lbt.scr3); in kvm_loongarch_put_lbt()
546 * Be cautious, KVM_REG_LOONGARCH_LBT_FTOP is defined as 64-bit however in kvm_loongarch_put_lbt()
547 * lbt.ftop is 32-bit; the same with KVM_REG_LOONGARCH_LBT_EFLAGS register in kvm_loongarch_put_lbt()
549 val = env->lbt.eflags; in kvm_loongarch_put_lbt()
550 ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_EFLAGS, &val); in kvm_loongarch_put_lbt()
551 val = env->lbt.ftop; in kvm_loongarch_put_lbt()
552 ret |= kvm_set_one_reg(cs, KVM_REG_LOONGARCH_LBT_FTOP, &val); in kvm_loongarch_put_lbt()
557 static int kvm_loongarch_get_lbt(CPUState *cs) in kvm_loongarch_get_lbt() argument
559 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_get_lbt()
564 if (FIELD_EX32(env->cpucfg[2], CPUCFG2, LBT_ALL) != 7) { in kvm_loongarch_get_lbt()
568 /* get six LBT registers including scr0-scr3, eflags, ftop */ in kvm_loongarch_get_lbt()
569 ret = kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR0, &env->lbt.scr0); in kvm_loongarch_get_lbt()
570 ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR1, &env->lbt.scr1); in kvm_loongarch_get_lbt()
571 ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR2, &env->lbt.scr2); in kvm_loongarch_get_lbt()
572 ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_SCR3, &env->lbt.scr3); in kvm_loongarch_get_lbt()
573 ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_EFLAGS, &val); in kvm_loongarch_get_lbt()
574 env->lbt.eflags = (uint32_t)val; in kvm_loongarch_get_lbt()
575 ret |= kvm_get_one_reg(cs, KVM_REG_LOONGARCH_LBT_FTOP, &val); in kvm_loongarch_get_lbt()
576 env->lbt.ftop = (uint32_t)val; in kvm_loongarch_get_lbt()
581 void kvm_arch_reset_vcpu(CPUState *cs) in kvm_arch_reset_vcpu() argument
583 CPULoongArchState *env = cpu_env(cs); in kvm_arch_reset_vcpu()
585 env->mp_state = KVM_MP_STATE_RUNNABLE; in kvm_arch_reset_vcpu()
586 kvm_set_one_reg(cs, KVM_REG_LOONGARCH_VCPU_RESET, 0); in kvm_arch_reset_vcpu()
589 static int kvm_loongarch_get_mpstate(CPUState *cs) in kvm_loongarch_get_mpstate() argument
593 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_get_mpstate()
596 ret = kvm_vcpu_ioctl(cs, KVM_GET_MP_STATE, &mp_state); in kvm_loongarch_get_mpstate()
601 env->mp_state = mp_state.mp_state; in kvm_loongarch_get_mpstate()
607 static int kvm_loongarch_put_mpstate(CPUState *cs) in kvm_loongarch_put_mpstate() argument
611 .mp_state = cpu_env(cs)->mp_state in kvm_loongarch_put_mpstate()
615 ret = kvm_vcpu_ioctl(cs, KVM_SET_MP_STATE, &mp_state); in kvm_loongarch_put_mpstate()
624 static int kvm_loongarch_get_cpucfg(CPUState *cs) in kvm_loongarch_get_cpucfg() argument
628 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_get_cpucfg()
631 ret = kvm_get_one_reg(cs, KVM_IOC_CPUCFG(i), &val); in kvm_loongarch_get_cpucfg()
635 env->cpucfg[i] = (uint32_t)val; in kvm_loongarch_get_cpucfg()
640 static int kvm_check_cpucfg2(CPUState *cs) in kvm_check_cpucfg2() argument
649 CPULoongArchState *env = cpu_env(cs); in kvm_check_cpucfg2()
651 ret = kvm_vcpu_ioctl(cs, KVM_HAS_DEVICE_ATTR, &attr); in kvm_check_cpucfg2()
654 kvm_vcpu_ioctl(cs, KVM_GET_DEVICE_ATTR, &attr); in kvm_check_cpucfg2()
655 env->cpucfg[2] &= val; in kvm_check_cpucfg2()
657 if (FIELD_EX32(env->cpucfg[2], CPUCFG2, FP)) { in kvm_check_cpucfg2()
658 /* The FP minimal version is 1. */ in kvm_check_cpucfg2()
659 env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, FP_VER, 1); in kvm_check_cpucfg2()
662 if (FIELD_EX32(env->cpucfg[2], CPUCFG2, LLFTP)) { in kvm_check_cpucfg2()
663 /* The LLFTP minimal version is 1. */ in kvm_check_cpucfg2()
664 env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LLFTP_VER, 1); in kvm_check_cpucfg2()
671 static int kvm_loongarch_put_cpucfg(CPUState *cs) in kvm_loongarch_put_cpucfg() argument
674 CPULoongArchState *env = cpu_env(cs); in kvm_loongarch_put_cpucfg()
679 ret = kvm_check_cpucfg2(cs); in kvm_loongarch_put_cpucfg()
684 val = env->cpucfg[i]; in kvm_loongarch_put_cpucfg()
685 ret = kvm_set_one_reg(cs, KVM_IOC_CPUCFG(i), &val); in kvm_loongarch_put_cpucfg()
693 int kvm_arch_get_registers(CPUState *cs, Error **errp) in kvm_arch_get_registers() argument
697 ret = kvm_loongarch_get_regs_core(cs); in kvm_arch_get_registers()
702 ret = kvm_loongarch_get_cpucfg(cs); in kvm_arch_get_registers()
707 ret = kvm_loongarch_get_csr(cs); in kvm_arch_get_registers()
712 ret = kvm_loongarch_get_regs_fp(cs); in kvm_arch_get_registers()
717 ret = kvm_loongarch_get_lbt(cs); in kvm_arch_get_registers()
722 ret = kvm_get_stealtime(cs); in kvm_arch_get_registers()
727 ret = kvm_loongarch_get_mpstate(cs); in kvm_arch_get_registers()
731 int kvm_arch_put_registers(CPUState *cs, int level, Error **errp) in kvm_arch_put_registers() argument
735 ret = kvm_loongarch_put_regs_core(cs); in kvm_arch_put_registers()
740 ret = kvm_loongarch_put_cpucfg(cs); in kvm_arch_put_registers()
745 ret = kvm_loongarch_put_csr(cs, level); in kvm_arch_put_registers()
750 ret = kvm_loongarch_put_regs_fp(cs); in kvm_arch_put_registers()
755 ret = kvm_loongarch_put_lbt(cs); in kvm_arch_put_registers()
765 ret = kvm_set_stealtime(cs); in kvm_arch_put_registers()
771 ret = kvm_loongarch_put_mpstate(cs); in kvm_arch_put_registers()
779 CPUState *cs = opaque; in kvm_loongarch_vm_stage_change() local
780 LoongArchCPU *cpu = LOONGARCH_CPU(cs); in kvm_loongarch_vm_stage_change()
783 ret = kvm_set_one_reg(cs, KVM_REG_LOONGARCH_COUNTER, in kvm_loongarch_vm_stage_change()
784 &cpu->kvm_state_counter); in kvm_loongarch_vm_stage_change()
789 ret = kvm_get_one_reg(cs, KVM_REG_LOONGARCH_COUNTER, in kvm_loongarch_vm_stage_change()
790 &cpu->kvm_state_counter); in kvm_loongarch_vm_stage_change()
797 static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature) in kvm_feature_supported() argument
832 static int kvm_cpu_check_lbt(CPUState *cs, Error **errp) in kvm_cpu_check_lbt() argument
834 CPULoongArchState *env = cpu_env(cs); in kvm_cpu_check_lbt()
835 LoongArchCPU *cpu = LOONGARCH_CPU(cs); in kvm_cpu_check_lbt()
838 kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_LBT); in kvm_cpu_check_lbt()
839 if (cpu->lbt == ON_OFF_AUTO_ON) { in kvm_cpu_check_lbt()
841 env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LBT_ALL, 7); in kvm_cpu_check_lbt()
844 return -ENOTSUP; in kvm_cpu_check_lbt()
846 } else if ((cpu->lbt == ON_OFF_AUTO_AUTO) && kvm_supported) { in kvm_cpu_check_lbt()
847 env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, LBT_ALL, 7); in kvm_cpu_check_lbt()
853 static int kvm_cpu_check_pmu(CPUState *cs, Error **errp) in kvm_cpu_check_pmu() argument
855 LoongArchCPU *cpu = LOONGARCH_CPU(cs); in kvm_cpu_check_pmu()
856 CPULoongArchState *env = cpu_env(cs); in kvm_cpu_check_pmu()
859 kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_PMU); in kvm_cpu_check_pmu()
860 if (cpu->pmu == ON_OFF_AUTO_ON) { in kvm_cpu_check_pmu()
863 return -ENOTSUP; in kvm_cpu_check_pmu()
865 } else if (cpu->pmu != ON_OFF_AUTO_AUTO) { in kvm_cpu_check_pmu()
871 env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, PMP, 1); in kvm_cpu_check_pmu()
872 env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, PMNUM, 3); in kvm_cpu_check_pmu()
873 env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, PMBITS, 63); in kvm_cpu_check_pmu()
874 env->cpucfg[6] = FIELD_DP32(env->cpucfg[6], CPUCFG6, UPM, 1); in kvm_cpu_check_pmu()
879 int kvm_arch_init_vcpu(CPUState *cs) in kvm_arch_init_vcpu() argument
886 qemu_add_vm_change_state_handler(kvm_loongarch_vm_stage_change, cs); in kvm_arch_init_vcpu()
888 if (!kvm_get_one_reg(cs, KVM_REG_LOONGARCH_DEBUG_INST, &val)) { in kvm_arch_init_vcpu()
892 ret = kvm_cpu_check_lbt(cs, &local_err); in kvm_arch_init_vcpu()
897 ret = kvm_cpu_check_pmu(cs, &local_err); in kvm_arch_init_vcpu()
905 int kvm_arch_destroy_vcpu(CPUState *cs) in kvm_arch_destroy_vcpu() argument
910 unsigned long kvm_arch_vcpu_id(CPUState *cs) in kvm_arch_vcpu_id() argument
912 return cs->cpu_index; in kvm_arch_vcpu_id()
957 void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run) in kvm_arch_pre_run() argument
961 MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) in kvm_arch_post_run() argument
966 int kvm_arch_process_async_events(CPUState *cs) in kvm_arch_process_async_events() argument
968 return cs->halted; in kvm_arch_process_async_events()
971 bool kvm_arch_stop_on_emulation_error(CPUState *cs) in kvm_arch_stop_on_emulation_error() argument
979 dbg->control |= KVM_GUESTDBG_ENABLE | KVM_GUESTDBG_USE_SW_BP; in kvm_arch_update_guest_debug()
983 int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) in kvm_arch_insert_sw_breakpoint() argument
985 if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 4, 0) || in kvm_arch_insert_sw_breakpoint()
986 cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&brk_insn, 4, 1)) { in kvm_arch_insert_sw_breakpoint()
988 return -EINVAL; in kvm_arch_insert_sw_breakpoint()
993 int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) in kvm_arch_remove_sw_breakpoint() argument
997 if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&brk, 4, 0) || in kvm_arch_remove_sw_breakpoint()
999 cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)&bp->saved_insn, 4, 1)) { in kvm_arch_remove_sw_breakpoint()
1001 return -EINVAL; in kvm_arch_remove_sw_breakpoint()
1008 return -ENOSYS; in kvm_arch_insert_hw_breakpoint()
1013 return -ENOSYS; in kvm_arch_remove_hw_breakpoint()
1020 static bool kvm_loongarch_handle_debug(CPUState *cs, struct kvm_run *run) in kvm_loongarch_handle_debug() argument
1022 LoongArchCPU *cpu = LOONGARCH_CPU(cs); in kvm_loongarch_handle_debug()
1023 CPULoongArchState *env = &cpu->env; in kvm_loongarch_handle_debug()
1025 kvm_cpu_synchronize_state(cs); in kvm_loongarch_handle_debug()
1026 if (cs->singlestep_enabled) { in kvm_loongarch_handle_debug()
1030 if (kvm_find_sw_breakpoint(cs, env->pc)) { in kvm_loongarch_handle_debug()
1037 int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) in kvm_arch_handle_exit() argument
1040 CPULoongArchState *env = cpu_env(cs); in kvm_arch_handle_exit()
1043 attrs.requester_id = env_cpu(env)->cpu_index; in kvm_arch_handle_exit()
1045 trace_kvm_arch_handle_exit(run->exit_reason); in kvm_arch_handle_exit()
1046 switch (run->exit_reason) { in kvm_arch_handle_exit()
1048 address_space_rw(env->address_space_iocsr, in kvm_arch_handle_exit()
1049 run->iocsr_io.phys_addr, in kvm_arch_handle_exit()
1051 run->iocsr_io.data, in kvm_arch_handle_exit()
1052 run->iocsr_io.len, in kvm_arch_handle_exit()
1053 run->iocsr_io.is_write); in kvm_arch_handle_exit()
1057 if (kvm_loongarch_handle_debug(cs, run)) { in kvm_arch_handle_exit()
1063 ret = -1; in kvm_arch_handle_exit()
1064 warn_report("KVM: unknown exit reason %d", run->exit_reason); in kvm_arch_handle_exit()
1073 CPUState *cs = CPU(cpu); in kvm_loongarch_set_interrupt() local
1078 intr.irq = -irq; in kvm_loongarch_set_interrupt()
1082 return kvm_vcpu_ioctl(cs, KVM_INTERRUPT, &intr); in kvm_loongarch_set_interrupt()