4 * Add KVM PowerPC specific calls for qemu.
6 * Copyright 2007 IBM Corporation.
8 * Jerone Young <jyoung5@us.ibm.com>
9 * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
11 * This work is licensed under the GNU GPL licence version 2 or later.
16 #include "config-host.h"
22 #include "helper_regs.h"
27 #include <sys/utsname.h>
29 extern kvm_context_t kvm_context
;
31 void cpu_reset(CPUState
*env
)
37 int kvm_arch_qemu_create_context(void)
42 void kvm_arch_load_regs(CPUState
*env
)
47 rc
= kvm_get_regs(kvm_context
, env
->cpu_index
, ®s
);
49 perror("kvm_get_regs FAILED");
51 /* cr is untouched in qemu and not existant in CPUState fr ppr */
52 /* hflags is a morphed to MSR on ppc, no need to sync that down to kvm */
58 regs
.xer
= ppc_load_xer(env
);
61 regs
.srr0
= env
->spr
[SPR_SRR0
];
62 regs
.srr1
= env
->spr
[SPR_SRR1
];
64 regs
.sprg0
= env
->spr
[SPR_SPRG0
];
65 regs
.sprg1
= env
->spr
[SPR_SPRG1
];
66 regs
.sprg2
= env
->spr
[SPR_SPRG2
];
67 regs
.sprg3
= env
->spr
[SPR_SPRG3
];
68 regs
.sprg4
= env
->spr
[SPR_SPRG4
];
69 regs
.sprg5
= env
->spr
[SPR_SPRG5
];
70 regs
.sprg6
= env
->spr
[SPR_SPRG6
];
71 regs
.sprg7
= env
->spr
[SPR_SPRG7
];
73 for (i
= 0;i
< 32; i
++){
74 regs
.gpr
[i
] = env
->gpr
[i
];
75 regs
.fpr
[i
] = env
->fpr
[i
];
78 rc
= kvm_set_regs(kvm_context
, env
->cpu_index
, ®s
);
80 perror("kvm_set_regs FAILED");
84 void kvm_arch_save_regs(CPUState
*env
)
89 rc
= kvm_get_regs(kvm_context
, env
->cpu_index
, ®s
);
91 perror("kvm_get_regs FAILED");
95 ppc_store_xer(env
,regs
.xer
);
97 /* calculate hflags based on the current msr using the ppc qemu helper */
98 hreg_compute_hflags(env
);
102 env
->spr
[SPR_SRR0
] = regs
.srr0
;
103 env
->spr
[SPR_SRR1
] = regs
.srr1
;
105 env
->spr
[SPR_SPRG0
] = regs
.sprg0
;
106 env
->spr
[SPR_SPRG1
] = regs
.sprg1
;
107 env
->spr
[SPR_SPRG2
] = regs
.sprg2
;
108 env
->spr
[SPR_SPRG3
] = regs
.sprg3
;
109 env
->spr
[SPR_SPRG4
] = regs
.sprg4
;
110 env
->spr
[SPR_SPRG5
] = regs
.sprg5
;
111 env
->spr
[SPR_SPRG6
] = regs
.sprg6
;
112 env
->spr
[SPR_SPRG7
] = regs
.sprg7
;
114 for (i
= 0;i
< 32; i
++){
115 env
->gpr
[i
] = regs
.gpr
[i
];
116 env
->fpr
[i
] = regs
.fpr
[i
];
121 int kvm_arch_qemu_init_env(CPUState
*cenv
)
126 int kvm_arch_halt(void *opaque
, int vcpu
)
128 CPUState
*env
= cpu_single_env
;
130 if (!(env
->interrupt_request
& CPU_INTERRUPT_HARD
)
134 env
->exception_index
= EXCP_HLT
;
139 void kvm_arch_pre_kvm_run(void *opaque
, int vcpu
)
144 void kvm_arch_post_kvm_run(void *opaque
, int vcpu
)
146 CPUState
*env
= qemu_kvm_cpu_env(vcpu
);
147 cpu_single_env
= env
;
148 env
->ready_for_interrupt_injection
= \
149 kvm_is_ready_for_interrupt_injection(kvm_context
, vcpu
);
152 int kvm_arch_has_work(CPUState
*env
)
154 if ((env
->interrupt_request
& (CPU_INTERRUPT_HARD
| CPU_INTERRUPT_EXIT
)) &&
160 int kvm_arch_try_push_interrupts(void *opaque
)
162 CPUState
*env
= cpu_single_env
;
166 if (env
->ready_for_interrupt_injection
&&
167 (env
->interrupt_request
& CPU_INTERRUPT_HARD
))
169 env
->interrupt_request
&= ~CPU_INTERRUPT_HARD
;
171 /* For now KVM disregards the 'irq' argument. However, in the
172 * future KVM could cache it in-kernel to avoid a heavyweight exit
173 * when reading the UIC.
177 r
= kvm_inject_irq(kvm_context
, env
->cpu_index
, irq
);
179 printf("cpu %d fail inject %x\n", env
->cpu_index
, irq
);
182 return (env
->interrupt_request
& CPU_INTERRUPT_HARD
) != 0;
185 void kvm_arch_update_regs_for_sipi(CPUState
*env
)
187 printf("%s: no kvm-powerpc multi processor support yet!\n", __func__
);
190 /* map dcr access to existing qemu dcr emulation */
191 int handle_powerpc_dcr_read(int vcpu
, uint32_t dcrn
, uint32_t *data
)
193 CPUState
*env
= cpu_single_env
;
194 ppc_dcr_read(env
->dcr_env
, dcrn
, data
);
195 return 0; /* XXX ignore failed DCR ops */
198 int handle_powerpc_dcr_write(int vcpu
, uint32_t dcrn
, uint32_t data
)
200 CPUState
*env
= cpu_single_env
;
201 ppc_dcr_write(env
->dcr_env
, dcrn
, data
);
202 return 0; /* XXX ignore failed DCR ops */