1 #include "qemu/osdep.h"
2 #include "sysemu/sysemu.h"
4 #include "helper_regs.h"
5 #include "hw/ppc/spapr.h"
6 #include "mmu-hash64.h"
7 #include "cpu-models.h"
18 static void do_spr_sync(void *arg
)
20 struct SPRSyncState
*s
= arg
;
21 PowerPCCPU
*cpu
= POWERPC_CPU(s
->cs
);
22 CPUPPCState
*env
= &cpu
->env
;
24 cpu_synchronize_state(s
->cs
);
25 env
->spr
[s
->spr
] &= ~s
->mask
;
26 env
->spr
[s
->spr
] |= s
->value
;
29 static void set_spr(CPUState
*cs
, int spr
, target_ulong value
,
32 struct SPRSyncState s
= {
38 run_on_cpu(cs
, do_spr_sync
, &s
);
41 static bool has_spr(PowerPCCPU
*cpu
, int spr
)
43 /* We can test whether the SPR is defined by checking for a valid name */
44 return cpu
->env
.spr_cb
[spr
].name
!= NULL
;
47 static inline bool valid_pte_index(CPUPPCState
*env
, target_ulong pte_index
)
50 * hash value/pteg group index is normalized by htab_mask
52 if (((pte_index
& ~7ULL) / HPTES_PER_GROUP
) & ~env
->htab_mask
) {
58 static bool is_ram_address(sPAPRMachineState
*spapr
, hwaddr addr
)
60 MachineState
*machine
= MACHINE(spapr
);
61 MemoryHotplugState
*hpms
= &spapr
->hotplug_memory
;
63 if (addr
< machine
->ram_size
) {
66 if ((addr
>= hpms
->base
)
67 && ((addr
- hpms
->base
) < memory_region_size(&hpms
->mr
))) {
74 static target_ulong
h_enter(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
75 target_ulong opcode
, target_ulong
*args
)
77 CPUPPCState
*env
= &cpu
->env
;
78 target_ulong flags
= args
[0];
79 target_ulong pte_index
= args
[1];
80 target_ulong pteh
= args
[2];
81 target_ulong ptel
= args
[3];
82 unsigned apshift
, spshift
;
87 apshift
= ppc_hash64_hpte_page_shift_noslb(cpu
, pteh
, ptel
, &spshift
);
89 /* Bad page size encoding */
93 raddr
= (ptel
& HPTE64_R_RPN
) & ~((1ULL << apshift
) - 1);
95 if (is_ram_address(spapr
, raddr
)) {
96 /* Regular RAM - should have WIMG=0010 */
97 if ((ptel
& HPTE64_R_WIMG
) != HPTE64_R_M
) {
101 /* Looks like an IO address */
102 /* FIXME: What WIMG combinations could be sensible for IO?
103 * For now we allow WIMG=010x, but are there others? */
104 /* FIXME: Should we check against registered IO addresses? */
105 if ((ptel
& (HPTE64_R_W
| HPTE64_R_I
| HPTE64_R_M
)) != HPTE64_R_I
) {
112 if (!valid_pte_index(env
, pte_index
)) {
117 if (likely((flags
& H_EXACT
) == 0)) {
119 token
= ppc_hash64_start_access(cpu
, pte_index
);
120 for (; index
< 8; index
++) {
121 if (!(ppc_hash64_load_hpte0(cpu
, token
, index
) & HPTE64_V_VALID
)) {
125 ppc_hash64_stop_access(token
);
130 token
= ppc_hash64_start_access(cpu
, pte_index
);
131 if (ppc_hash64_load_hpte0(cpu
, token
, 0) & HPTE64_V_VALID
) {
132 ppc_hash64_stop_access(token
);
135 ppc_hash64_stop_access(token
);
138 ppc_hash64_store_hpte(cpu
, pte_index
+ index
,
139 pteh
| HPTE64_V_HPTE_DIRTY
, ptel
);
141 args
[0] = pte_index
+ index
;
147 REMOVE_NOT_FOUND
= 1,
152 static RemoveResult
remove_hpte(PowerPCCPU
*cpu
, target_ulong ptex
,
155 target_ulong
*vp
, target_ulong
*rp
)
157 CPUPPCState
*env
= &cpu
->env
;
161 if (!valid_pte_index(env
, ptex
)) {
165 token
= ppc_hash64_start_access(cpu
, ptex
);
166 v
= ppc_hash64_load_hpte0(cpu
, token
, 0);
167 r
= ppc_hash64_load_hpte1(cpu
, token
, 0);
168 ppc_hash64_stop_access(token
);
170 if ((v
& HPTE64_V_VALID
) == 0 ||
171 ((flags
& H_AVPN
) && (v
& ~0x7fULL
) != avpn
) ||
172 ((flags
& H_ANDCOND
) && (v
& avpn
) != 0)) {
173 return REMOVE_NOT_FOUND
;
177 ppc_hash64_store_hpte(cpu
, ptex
, HPTE64_V_HPTE_DIRTY
, 0);
178 ppc_hash64_tlb_flush_hpte(cpu
, ptex
, v
, r
);
179 return REMOVE_SUCCESS
;
182 static target_ulong
h_remove(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
183 target_ulong opcode
, target_ulong
*args
)
185 target_ulong flags
= args
[0];
186 target_ulong pte_index
= args
[1];
187 target_ulong avpn
= args
[2];
190 ret
= remove_hpte(cpu
, pte_index
, avpn
, flags
,
197 case REMOVE_NOT_FOUND
:
207 g_assert_not_reached();
210 #define H_BULK_REMOVE_TYPE 0xc000000000000000ULL
211 #define H_BULK_REMOVE_REQUEST 0x4000000000000000ULL
212 #define H_BULK_REMOVE_RESPONSE 0x8000000000000000ULL
213 #define H_BULK_REMOVE_END 0xc000000000000000ULL
214 #define H_BULK_REMOVE_CODE 0x3000000000000000ULL
215 #define H_BULK_REMOVE_SUCCESS 0x0000000000000000ULL
216 #define H_BULK_REMOVE_NOT_FOUND 0x1000000000000000ULL
217 #define H_BULK_REMOVE_PARM 0x2000000000000000ULL
218 #define H_BULK_REMOVE_HW 0x3000000000000000ULL
219 #define H_BULK_REMOVE_RC 0x0c00000000000000ULL
220 #define H_BULK_REMOVE_FLAGS 0x0300000000000000ULL
221 #define H_BULK_REMOVE_ABSOLUTE 0x0000000000000000ULL
222 #define H_BULK_REMOVE_ANDCOND 0x0100000000000000ULL
223 #define H_BULK_REMOVE_AVPN 0x0200000000000000ULL
224 #define H_BULK_REMOVE_PTEX 0x00ffffffffffffffULL
226 #define H_BULK_REMOVE_MAX_BATCH 4
228 static target_ulong
h_bulk_remove(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
229 target_ulong opcode
, target_ulong
*args
)
233 for (i
= 0; i
< H_BULK_REMOVE_MAX_BATCH
; i
++) {
234 target_ulong
*tsh
= &args
[i
*2];
235 target_ulong tsl
= args
[i
*2 + 1];
236 target_ulong v
, r
, ret
;
238 if ((*tsh
& H_BULK_REMOVE_TYPE
) == H_BULK_REMOVE_END
) {
240 } else if ((*tsh
& H_BULK_REMOVE_TYPE
) != H_BULK_REMOVE_REQUEST
) {
244 *tsh
&= H_BULK_REMOVE_PTEX
| H_BULK_REMOVE_FLAGS
;
245 *tsh
|= H_BULK_REMOVE_RESPONSE
;
247 if ((*tsh
& H_BULK_REMOVE_ANDCOND
) && (*tsh
& H_BULK_REMOVE_AVPN
)) {
248 *tsh
|= H_BULK_REMOVE_PARM
;
252 ret
= remove_hpte(cpu
, *tsh
& H_BULK_REMOVE_PTEX
, tsl
,
253 (*tsh
& H_BULK_REMOVE_FLAGS
) >> 26,
260 *tsh
|= (r
& (HPTE64_R_C
| HPTE64_R_R
)) << 43;
274 static target_ulong
h_protect(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
275 target_ulong opcode
, target_ulong
*args
)
277 CPUPPCState
*env
= &cpu
->env
;
278 target_ulong flags
= args
[0];
279 target_ulong pte_index
= args
[1];
280 target_ulong avpn
= args
[2];
284 if (!valid_pte_index(env
, pte_index
)) {
288 token
= ppc_hash64_start_access(cpu
, pte_index
);
289 v
= ppc_hash64_load_hpte0(cpu
, token
, 0);
290 r
= ppc_hash64_load_hpte1(cpu
, token
, 0);
291 ppc_hash64_stop_access(token
);
293 if ((v
& HPTE64_V_VALID
) == 0 ||
294 ((flags
& H_AVPN
) && (v
& ~0x7fULL
) != avpn
)) {
298 r
&= ~(HPTE64_R_PP0
| HPTE64_R_PP
| HPTE64_R_N
|
299 HPTE64_R_KEY_HI
| HPTE64_R_KEY_LO
);
300 r
|= (flags
<< 55) & HPTE64_R_PP0
;
301 r
|= (flags
<< 48) & HPTE64_R_KEY_HI
;
302 r
|= flags
& (HPTE64_R_PP
| HPTE64_R_N
| HPTE64_R_KEY_LO
);
303 ppc_hash64_store_hpte(cpu
, pte_index
,
304 (v
& ~HPTE64_V_VALID
) | HPTE64_V_HPTE_DIRTY
, 0);
305 ppc_hash64_tlb_flush_hpte(cpu
, pte_index
, v
, r
);
306 /* Don't need a memory barrier, due to qemu's global lock */
307 ppc_hash64_store_hpte(cpu
, pte_index
, v
| HPTE64_V_HPTE_DIRTY
, r
);
311 static target_ulong
h_read(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
312 target_ulong opcode
, target_ulong
*args
)
314 CPUPPCState
*env
= &cpu
->env
;
315 target_ulong flags
= args
[0];
316 target_ulong pte_index
= args
[1];
318 int i
, ridx
, n_entries
= 1;
320 if (!valid_pte_index(env
, pte_index
)) {
324 if (flags
& H_READ_4
) {
325 /* Clear the two low order bits */
326 pte_index
&= ~(3ULL);
330 hpte
= env
->external_htab
+ (pte_index
* HASH_PTE_SIZE_64
);
332 for (i
= 0, ridx
= 0; i
< n_entries
; i
++) {
333 args
[ridx
++] = ldq_p(hpte
);
334 args
[ridx
++] = ldq_p(hpte
+ (HASH_PTE_SIZE_64
/2));
335 hpte
+= HASH_PTE_SIZE_64
;
341 static target_ulong
h_set_sprg0(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
342 target_ulong opcode
, target_ulong
*args
)
344 cpu_synchronize_state(CPU(cpu
));
345 cpu
->env
.spr
[SPR_SPRG0
] = args
[0];
350 static target_ulong
h_set_dabr(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
351 target_ulong opcode
, target_ulong
*args
)
353 if (!has_spr(cpu
, SPR_DABR
)) {
354 return H_HARDWARE
; /* DABR register not available */
356 cpu_synchronize_state(CPU(cpu
));
358 if (has_spr(cpu
, SPR_DABRX
)) {
359 cpu
->env
.spr
[SPR_DABRX
] = 0x3; /* Use Problem and Privileged state */
360 } else if (!(args
[0] & 0x4)) { /* Breakpoint Translation set? */
361 return H_RESERVED_DABR
;
364 cpu
->env
.spr
[SPR_DABR
] = args
[0];
368 static target_ulong
h_set_xdabr(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
369 target_ulong opcode
, target_ulong
*args
)
371 target_ulong dabrx
= args
[1];
373 if (!has_spr(cpu
, SPR_DABR
) || !has_spr(cpu
, SPR_DABRX
)) {
377 if ((dabrx
& ~0xfULL
) != 0 || (dabrx
& H_DABRX_HYPERVISOR
) != 0
378 || (dabrx
& (H_DABRX_KERNEL
| H_DABRX_USER
)) == 0) {
382 cpu_synchronize_state(CPU(cpu
));
383 cpu
->env
.spr
[SPR_DABRX
] = dabrx
;
384 cpu
->env
.spr
[SPR_DABR
] = args
[0];
389 static target_ulong
h_page_init(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
390 target_ulong opcode
, target_ulong
*args
)
392 target_ulong flags
= args
[0];
393 hwaddr dst
= args
[1];
394 hwaddr src
= args
[2];
395 hwaddr len
= TARGET_PAGE_SIZE
;
396 uint8_t *pdst
, *psrc
;
397 target_long ret
= H_SUCCESS
;
399 if (flags
& ~(H_ICACHE_SYNCHRONIZE
| H_ICACHE_INVALIDATE
400 | H_COPY_PAGE
| H_ZERO_PAGE
)) {
401 qemu_log_mask(LOG_UNIMP
, "h_page_init: Bad flags (" TARGET_FMT_lx
"\n",
406 /* Map-in destination */
407 if (!is_ram_address(spapr
, dst
) || (dst
& ~TARGET_PAGE_MASK
) != 0) {
410 pdst
= cpu_physical_memory_map(dst
, &len
, 1);
411 if (!pdst
|| len
!= TARGET_PAGE_SIZE
) {
415 if (flags
& H_COPY_PAGE
) {
416 /* Map-in source, copy to destination, and unmap source again */
417 if (!is_ram_address(spapr
, src
) || (src
& ~TARGET_PAGE_MASK
) != 0) {
421 psrc
= cpu_physical_memory_map(src
, &len
, 0);
422 if (!psrc
|| len
!= TARGET_PAGE_SIZE
) {
426 memcpy(pdst
, psrc
, len
);
427 cpu_physical_memory_unmap(psrc
, len
, 0, len
);
428 } else if (flags
& H_ZERO_PAGE
) {
429 memset(pdst
, 0, len
); /* Just clear the destination page */
432 if (kvm_enabled() && (flags
& H_ICACHE_SYNCHRONIZE
) != 0) {
433 kvmppc_dcbst_range(cpu
, pdst
, len
);
435 if (flags
& (H_ICACHE_SYNCHRONIZE
| H_ICACHE_INVALIDATE
)) {
437 kvmppc_icbi_range(cpu
, pdst
, len
);
444 cpu_physical_memory_unmap(pdst
, TARGET_PAGE_SIZE
, 1, len
);
448 #define FLAGS_REGISTER_VPA 0x0000200000000000ULL
449 #define FLAGS_REGISTER_DTL 0x0000400000000000ULL
450 #define FLAGS_REGISTER_SLBSHADOW 0x0000600000000000ULL
451 #define FLAGS_DEREGISTER_VPA 0x0000a00000000000ULL
452 #define FLAGS_DEREGISTER_DTL 0x0000c00000000000ULL
453 #define FLAGS_DEREGISTER_SLBSHADOW 0x0000e00000000000ULL
455 #define VPA_MIN_SIZE 640
456 #define VPA_SIZE_OFFSET 0x4
457 #define VPA_SHARED_PROC_OFFSET 0x9
458 #define VPA_SHARED_PROC_VAL 0x2
460 static target_ulong
register_vpa(CPUPPCState
*env
, target_ulong vpa
)
462 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
467 hcall_dprintf("Can't cope with registering a VPA at logical 0\n");
471 if (vpa
% env
->dcache_line_size
) {
474 /* FIXME: bounds check the address */
476 size
= lduw_be_phys(cs
->as
, vpa
+ 0x4);
478 if (size
< VPA_MIN_SIZE
) {
482 /* VPA is not allowed to cross a page boundary */
483 if ((vpa
/ 4096) != ((vpa
+ size
- 1) / 4096)) {
489 tmp
= ldub_phys(cs
->as
, env
->vpa_addr
+ VPA_SHARED_PROC_OFFSET
);
490 tmp
|= VPA_SHARED_PROC_VAL
;
491 stb_phys(cs
->as
, env
->vpa_addr
+ VPA_SHARED_PROC_OFFSET
, tmp
);
496 static target_ulong
deregister_vpa(CPUPPCState
*env
, target_ulong vpa
)
498 if (env
->slb_shadow_addr
) {
510 static target_ulong
register_slb_shadow(CPUPPCState
*env
, target_ulong addr
)
512 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
516 hcall_dprintf("Can't cope with SLB shadow at logical 0\n");
520 size
= ldl_be_phys(cs
->as
, addr
+ 0x4);
525 if ((addr
/ 4096) != ((addr
+ size
- 1) / 4096)) {
529 if (!env
->vpa_addr
) {
533 env
->slb_shadow_addr
= addr
;
534 env
->slb_shadow_size
= size
;
539 static target_ulong
deregister_slb_shadow(CPUPPCState
*env
, target_ulong addr
)
541 env
->slb_shadow_addr
= 0;
542 env
->slb_shadow_size
= 0;
546 static target_ulong
register_dtl(CPUPPCState
*env
, target_ulong addr
)
548 CPUState
*cs
= CPU(ppc_env_get_cpu(env
));
552 hcall_dprintf("Can't cope with DTL at logical 0\n");
556 size
= ldl_be_phys(cs
->as
, addr
+ 0x4);
562 if (!env
->vpa_addr
) {
566 env
->dtl_addr
= addr
;
567 env
->dtl_size
= size
;
572 static target_ulong
deregister_dtl(CPUPPCState
*env
, target_ulong addr
)
580 static target_ulong
h_register_vpa(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
581 target_ulong opcode
, target_ulong
*args
)
583 target_ulong flags
= args
[0];
584 target_ulong procno
= args
[1];
585 target_ulong vpa
= args
[2];
586 target_ulong ret
= H_PARAMETER
;
590 tcpu
= ppc_get_vcpu_by_dt_id(procno
);
597 case FLAGS_REGISTER_VPA
:
598 ret
= register_vpa(tenv
, vpa
);
601 case FLAGS_DEREGISTER_VPA
:
602 ret
= deregister_vpa(tenv
, vpa
);
605 case FLAGS_REGISTER_SLBSHADOW
:
606 ret
= register_slb_shadow(tenv
, vpa
);
609 case FLAGS_DEREGISTER_SLBSHADOW
:
610 ret
= deregister_slb_shadow(tenv
, vpa
);
613 case FLAGS_REGISTER_DTL
:
614 ret
= register_dtl(tenv
, vpa
);
617 case FLAGS_DEREGISTER_DTL
:
618 ret
= deregister_dtl(tenv
, vpa
);
625 static target_ulong
h_cede(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
626 target_ulong opcode
, target_ulong
*args
)
628 CPUPPCState
*env
= &cpu
->env
;
629 CPUState
*cs
= CPU(cpu
);
631 env
->msr
|= (1ULL << MSR_EE
);
632 hreg_compute_hflags(env
);
633 if (!cpu_has_work(cs
)) {
635 cs
->exception_index
= EXCP_HLT
;
636 cs
->exit_request
= 1;
641 static target_ulong
h_rtas(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
642 target_ulong opcode
, target_ulong
*args
)
644 target_ulong rtas_r3
= args
[0];
645 uint32_t token
= rtas_ld(rtas_r3
, 0);
646 uint32_t nargs
= rtas_ld(rtas_r3
, 1);
647 uint32_t nret
= rtas_ld(rtas_r3
, 2);
649 return spapr_rtas_call(cpu
, spapr
, token
, nargs
, rtas_r3
+ 12,
650 nret
, rtas_r3
+ 12 + 4*nargs
);
653 static target_ulong
h_logical_load(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
654 target_ulong opcode
, target_ulong
*args
)
656 CPUState
*cs
= CPU(cpu
);
657 target_ulong size
= args
[0];
658 target_ulong addr
= args
[1];
662 args
[0] = ldub_phys(cs
->as
, addr
);
665 args
[0] = lduw_phys(cs
->as
, addr
);
668 args
[0] = ldl_phys(cs
->as
, addr
);
671 args
[0] = ldq_phys(cs
->as
, addr
);
677 static target_ulong
h_logical_store(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
678 target_ulong opcode
, target_ulong
*args
)
680 CPUState
*cs
= CPU(cpu
);
682 target_ulong size
= args
[0];
683 target_ulong addr
= args
[1];
684 target_ulong val
= args
[2];
688 stb_phys(cs
->as
, addr
, val
);
691 stw_phys(cs
->as
, addr
, val
);
694 stl_phys(cs
->as
, addr
, val
);
697 stq_phys(cs
->as
, addr
, val
);
703 static target_ulong
h_logical_memop(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
704 target_ulong opcode
, target_ulong
*args
)
706 CPUState
*cs
= CPU(cpu
);
708 target_ulong dst
= args
[0]; /* Destination address */
709 target_ulong src
= args
[1]; /* Source address */
710 target_ulong esize
= args
[2]; /* Element size (0=1,1=2,2=4,3=8) */
711 target_ulong count
= args
[3]; /* Element count */
712 target_ulong op
= args
[4]; /* 0 = copy, 1 = invert */
714 unsigned int mask
= (1 << esize
) - 1;
715 int step
= 1 << esize
;
717 if (count
> 0x80000000) {
721 if ((dst
& mask
) || (src
& mask
) || (op
> 1)) {
725 if (dst
>= src
&& dst
< (src
+ (count
<< esize
))) {
726 dst
= dst
+ ((count
- 1) << esize
);
727 src
= src
+ ((count
- 1) << esize
);
734 tmp
= ldub_phys(cs
->as
, src
);
737 tmp
= lduw_phys(cs
->as
, src
);
740 tmp
= ldl_phys(cs
->as
, src
);
743 tmp
= ldq_phys(cs
->as
, src
);
753 stb_phys(cs
->as
, dst
, tmp
);
756 stw_phys(cs
->as
, dst
, tmp
);
759 stl_phys(cs
->as
, dst
, tmp
);
762 stq_phys(cs
->as
, dst
, tmp
);
772 static target_ulong
h_logical_icbi(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
773 target_ulong opcode
, target_ulong
*args
)
775 /* Nothing to do on emulation, KVM will trap this in the kernel */
779 static target_ulong
h_logical_dcbf(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
780 target_ulong opcode
, target_ulong
*args
)
782 /* Nothing to do on emulation, KVM will trap this in the kernel */
786 static target_ulong
h_set_mode_resource_le(PowerPCCPU
*cpu
,
801 case H_SET_MODE_ENDIAN_BIG
:
803 set_spr(cs
, SPR_LPCR
, 0, LPCR_ILE
);
805 spapr_pci_switch_vga(true);
808 case H_SET_MODE_ENDIAN_LITTLE
:
810 set_spr(cs
, SPR_LPCR
, LPCR_ILE
, LPCR_ILE
);
812 spapr_pci_switch_vga(false);
816 return H_UNSUPPORTED_FLAG
;
819 static target_ulong
h_set_mode_resource_addr_trans_mode(PowerPCCPU
*cpu
,
825 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
828 if (!(pcc
->insns_flags2
& PPC2_ISA207S
)) {
839 case H_SET_MODE_ADDR_TRANS_NONE
:
842 case H_SET_MODE_ADDR_TRANS_0001_8000
:
845 case H_SET_MODE_ADDR_TRANS_C000_0000_0000_4000
:
846 prefix
= 0xC000000000004000ULL
;
849 return H_UNSUPPORTED_FLAG
;
853 CPUPPCState
*env
= &POWERPC_CPU(cpu
)->env
;
855 set_spr(cs
, SPR_LPCR
, mflags
<< LPCR_AIL_SHIFT
, LPCR_AIL
);
856 env
->excp_prefix
= prefix
;
862 static target_ulong
h_set_mode(PowerPCCPU
*cpu
, sPAPRMachineState
*spapr
,
863 target_ulong opcode
, target_ulong
*args
)
865 target_ulong resource
= args
[1];
866 target_ulong ret
= H_P2
;
869 case H_SET_MODE_RESOURCE_LE
:
870 ret
= h_set_mode_resource_le(cpu
, args
[0], args
[2], args
[3]);
872 case H_SET_MODE_RESOURCE_ADDR_TRANS_MODE
:
873 ret
= h_set_mode_resource_addr_trans_mode(cpu
, args
[0],
882 * Return the offset to the requested option vector @vector in the
883 * option vector table @table.
885 static target_ulong
cas_get_option_vector(int vector
, target_ulong table
)
888 char nr_vectors
, nr_entries
;
894 nr_vectors
= (ldl_phys(&address_space_memory
, table
) >> 24) + 1;
895 if (!vector
|| vector
> nr_vectors
) {
898 table
++; /* skip nr option vectors */
900 for (i
= 0; i
< vector
- 1; i
++) {
901 nr_entries
= ldl_phys(&address_space_memory
, table
) >> 24;
902 table
+= nr_entries
+ 2;
909 uint32_t cpu_version
;
913 static void do_set_compat(void *arg
)
915 SetCompatState
*s
= arg
;
917 cpu_synchronize_state(CPU(s
->cpu
));
918 ppc_set_compat(s
->cpu
, s
->cpu_version
, &s
->err
);
921 #define get_compat_level(cpuver) ( \
922 ((cpuver) == CPU_POWERPC_LOGICAL_2_05) ? 2050 : \
923 ((cpuver) == CPU_POWERPC_LOGICAL_2_06) ? 2060 : \
924 ((cpuver) == CPU_POWERPC_LOGICAL_2_06_PLUS) ? 2061 : \
925 ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0)
927 #define OV5_DRCONF_MEMORY 0x20
929 static target_ulong
h_client_architecture_support(PowerPCCPU
*cpu_
,
930 sPAPRMachineState
*spapr
,
934 target_ulong list
= ppc64_phys_to_real(args
[0]);
935 target_ulong ov_table
, ov5
;
936 PowerPCCPUClass
*pcc_
= POWERPC_CPU_GET_CLASS(cpu_
);
938 bool cpu_match
= false, cpu_update
= true, memory_update
= false;
939 unsigned old_cpu_version
= cpu_
->cpu_version
;
940 unsigned compat_lvl
= 0, cpu_version
= 0;
941 unsigned max_lvl
= get_compat_level(cpu_
->max_compat
);
946 for (counter
= 0; counter
< 512; ++counter
) {
947 uint32_t pvr
, pvr_mask
;
949 pvr_mask
= ldl_be_phys(&address_space_memory
, list
);
951 pvr
= ldl_be_phys(&address_space_memory
, list
);
954 trace_spapr_cas_pvr_try(pvr
);
956 ((cpu_
->env
.spr
[SPR_PVR
] & pvr_mask
) == (pvr
& pvr_mask
))) {
959 } else if (pvr
== cpu_
->cpu_version
) {
961 cpu_version
= cpu_
->cpu_version
;
962 } else if (!cpu_match
) {
963 /* If it is a logical PVR, try to determine the highest level */
964 unsigned lvl
= get_compat_level(pvr
);
966 bool is205
= (pcc_
->pcr_mask
& PCR_COMPAT_2_05
) &&
967 (lvl
== get_compat_level(CPU_POWERPC_LOGICAL_2_05
));
968 bool is206
= (pcc_
->pcr_mask
& PCR_COMPAT_2_06
) &&
969 ((lvl
== get_compat_level(CPU_POWERPC_LOGICAL_2_06
)) ||
970 (lvl
== get_compat_level(CPU_POWERPC_LOGICAL_2_06_PLUS
)));
972 if (is205
|| is206
) {
974 /* User did not set the level, choose the highest */
975 if (compat_lvl
<= lvl
) {
979 } else if (max_lvl
>= lvl
) {
980 /* User chose the level, don't set higher than this */
987 /* Terminator record */
988 if (~pvr_mask
& pvr
) {
993 /* Parsing finished */
994 trace_spapr_cas_pvr(cpu_
->cpu_version
, cpu_match
,
995 cpu_version
, pcc_
->pcr_mask
);
998 if (old_cpu_version
!= cpu_version
) {
1000 SetCompatState s
= {
1001 .cpu
= POWERPC_CPU(cs
),
1002 .cpu_version
= cpu_version
,
1006 run_on_cpu(cs
, do_set_compat
, &s
);
1009 error_report_err(s
.err
);
1019 /* For the future use: here @ov_table points to the first option vector */
1022 ov5
= cas_get_option_vector(5, ov_table
);
1027 /* @list now points to OV 5 */
1028 ov5_byte2
= ldub_phys(&address_space_memory
, ov5
+ 2);
1029 if (ov5_byte2
& OV5_DRCONF_MEMORY
) {
1030 memory_update
= true;
1033 if (spapr_h_cas_compose_response(spapr
, args
[1], args
[2],
1034 cpu_update
, memory_update
)) {
1035 qemu_system_reset_request();
1041 static spapr_hcall_fn papr_hypercall_table
[(MAX_HCALL_OPCODE
/ 4) + 1];
1042 static spapr_hcall_fn kvmppc_hypercall_table
[KVMPPC_HCALL_MAX
- KVMPPC_HCALL_BASE
+ 1];
1044 void spapr_register_hypercall(target_ulong opcode
, spapr_hcall_fn fn
)
1046 spapr_hcall_fn
*slot
;
1048 if (opcode
<= MAX_HCALL_OPCODE
) {
1049 assert((opcode
& 0x3) == 0);
1051 slot
= &papr_hypercall_table
[opcode
/ 4];
1053 assert((opcode
>= KVMPPC_HCALL_BASE
) && (opcode
<= KVMPPC_HCALL_MAX
));
1055 slot
= &kvmppc_hypercall_table
[opcode
- KVMPPC_HCALL_BASE
];
1062 target_ulong
spapr_hypercall(PowerPCCPU
*cpu
, target_ulong opcode
,
1065 sPAPRMachineState
*spapr
= SPAPR_MACHINE(qdev_get_machine());
1067 if ((opcode
<= MAX_HCALL_OPCODE
)
1068 && ((opcode
& 0x3) == 0)) {
1069 spapr_hcall_fn fn
= papr_hypercall_table
[opcode
/ 4];
1072 return fn(cpu
, spapr
, opcode
, args
);
1074 } else if ((opcode
>= KVMPPC_HCALL_BASE
) &&
1075 (opcode
<= KVMPPC_HCALL_MAX
)) {
1076 spapr_hcall_fn fn
= kvmppc_hypercall_table
[opcode
- KVMPPC_HCALL_BASE
];
1079 return fn(cpu
, spapr
, opcode
, args
);
1083 qemu_log_mask(LOG_UNIMP
, "Unimplemented SPAPR hcall 0x" TARGET_FMT_lx
"\n",
1088 static void hypercall_register_types(void)
1091 spapr_register_hypercall(H_ENTER
, h_enter
);
1092 spapr_register_hypercall(H_REMOVE
, h_remove
);
1093 spapr_register_hypercall(H_PROTECT
, h_protect
);
1094 spapr_register_hypercall(H_READ
, h_read
);
1097 spapr_register_hypercall(H_BULK_REMOVE
, h_bulk_remove
);
1100 spapr_register_hypercall(H_REGISTER_VPA
, h_register_vpa
);
1101 spapr_register_hypercall(H_CEDE
, h_cede
);
1103 /* processor register resource access h-calls */
1104 spapr_register_hypercall(H_SET_SPRG0
, h_set_sprg0
);
1105 spapr_register_hypercall(H_SET_DABR
, h_set_dabr
);
1106 spapr_register_hypercall(H_SET_XDABR
, h_set_xdabr
);
1107 spapr_register_hypercall(H_PAGE_INIT
, h_page_init
);
1108 spapr_register_hypercall(H_SET_MODE
, h_set_mode
);
1110 /* "debugger" hcalls (also used by SLOF). Note: We do -not- differenciate
1111 * here between the "CI" and the "CACHE" variants, they will use whatever
1112 * mapping attributes qemu is using. When using KVM, the kernel will
1113 * enforce the attributes more strongly
1115 spapr_register_hypercall(H_LOGICAL_CI_LOAD
, h_logical_load
);
1116 spapr_register_hypercall(H_LOGICAL_CI_STORE
, h_logical_store
);
1117 spapr_register_hypercall(H_LOGICAL_CACHE_LOAD
, h_logical_load
);
1118 spapr_register_hypercall(H_LOGICAL_CACHE_STORE
, h_logical_store
);
1119 spapr_register_hypercall(H_LOGICAL_ICBI
, h_logical_icbi
);
1120 spapr_register_hypercall(H_LOGICAL_DCBF
, h_logical_dcbf
);
1121 spapr_register_hypercall(KVMPPC_H_LOGICAL_MEMOP
, h_logical_memop
);
1123 /* qemu/KVM-PPC specific hcalls */
1124 spapr_register_hypercall(KVMPPC_H_RTAS
, h_rtas
);
1126 /* ibm,client-architecture-support support */
1127 spapr_register_hypercall(KVMPPC_H_CAS
, h_client_architecture_support
);
1130 type_init(hypercall_register_types
)