Lines Matching full:vcpu

34 static unsigned long kvm_psci_vcpu_suspend(struct kvm_vcpu *vcpu)  in kvm_psci_vcpu_suspend()  argument
37 * NOTE: For simplicity, we make VCPU suspend emulation to be in kvm_psci_vcpu_suspend()
49 kvm_vcpu_wfi(vcpu); in kvm_psci_vcpu_suspend()
54 static inline bool kvm_psci_valid_affinity(struct kvm_vcpu *vcpu, in kvm_psci_valid_affinity() argument
64 struct kvm_vcpu *vcpu = NULL; in kvm_psci_vcpu_on() local
72 vcpu = kvm_mpidr_to_vcpu(kvm, cpu_id); in kvm_psci_vcpu_on()
78 if (!vcpu) in kvm_psci_vcpu_on()
81 spin_lock(&vcpu->arch.mp_state_lock); in kvm_psci_vcpu_on()
82 if (!kvm_arm_vcpu_stopped(vcpu)) { in kvm_psci_vcpu_on()
91 reset_state = &vcpu->arch.reset_state; in kvm_psci_vcpu_on()
105 kvm_make_request(KVM_REQ_VCPU_RESET, vcpu); in kvm_psci_vcpu_on()
113 WRITE_ONCE(vcpu->arch.mp_state.mp_state, KVM_MP_STATE_RUNNABLE); in kvm_psci_vcpu_on()
114 kvm_vcpu_wake_up(vcpu); in kvm_psci_vcpu_on()
117 spin_unlock(&vcpu->arch.mp_state_lock); in kvm_psci_vcpu_on()
121 static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu) in kvm_psci_vcpu_affinity_info() argument
128 struct kvm *kvm = vcpu->kvm; in kvm_psci_vcpu_affinity_info()
131 target_affinity = smccc_get_arg1(vcpu); in kvm_psci_vcpu_affinity_info()
132 lowest_affinity_level = smccc_get_arg2(vcpu); in kvm_psci_vcpu_affinity_info()
134 if (!kvm_psci_valid_affinity(vcpu, target_affinity)) in kvm_psci_vcpu_affinity_info()
146 * If one or more VCPU matching target affinity are running in kvm_psci_vcpu_affinity_info()
164 static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type, u64 flags) in kvm_prepare_system_event() argument
178 kvm_for_each_vcpu(i, tmp, vcpu->kvm) { in kvm_prepare_system_event()
183 kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP); in kvm_prepare_system_event()
185 memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); in kvm_prepare_system_event()
186 vcpu->run->system_event.type = type; in kvm_prepare_system_event()
187 vcpu->run->system_event.ndata = 1; in kvm_prepare_system_event()
188 vcpu->run->system_event.data[0] = flags; in kvm_prepare_system_event()
189 vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; in kvm_prepare_system_event()
192 static void kvm_psci_system_off(struct kvm_vcpu *vcpu) in kvm_psci_system_off() argument
194 kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_SHUTDOWN, 0); in kvm_psci_system_off()
197 static void kvm_psci_system_off2(struct kvm_vcpu *vcpu) in kvm_psci_system_off2() argument
199 kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_SHUTDOWN, in kvm_psci_system_off2()
203 static void kvm_psci_system_reset(struct kvm_vcpu *vcpu) in kvm_psci_system_reset() argument
205 kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_RESET, 0); in kvm_psci_system_reset()
208 static void kvm_psci_system_reset2(struct kvm_vcpu *vcpu) in kvm_psci_system_reset2() argument
210 kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_RESET, in kvm_psci_system_reset2()
214 static void kvm_psci_system_suspend(struct kvm_vcpu *vcpu) in kvm_psci_system_suspend() argument
216 struct kvm_run *run = vcpu->run; in kvm_psci_system_suspend()
218 memset(&run->system_event, 0, sizeof(vcpu->run->system_event)); in kvm_psci_system_suspend()
223 static void kvm_psci_narrow_to_32bit(struct kvm_vcpu *vcpu) in kvm_psci_narrow_to_32bit() argument
232 vcpu_set_reg(vcpu, i, lower_32_bits(vcpu_get_reg(vcpu, i))); in kvm_psci_narrow_to_32bit()
235 static unsigned long kvm_psci_check_allowed_function(struct kvm_vcpu *vcpu, u32 fn) in kvm_psci_check_allowed_function() argument
240 if ((fn & PSCI_0_2_64BIT) && vcpu_mode_is_32bit(vcpu)) in kvm_psci_check_allowed_function()
246 static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) in kvm_psci_0_2_call() argument
248 u32 psci_fn = smccc_get_function(vcpu); in kvm_psci_0_2_call()
262 val = kvm_psci_vcpu_suspend(vcpu); in kvm_psci_0_2_call()
265 kvm_arm_vcpu_power_off(vcpu); in kvm_psci_0_2_call()
269 kvm_psci_narrow_to_32bit(vcpu); in kvm_psci_0_2_call()
272 val = kvm_psci_vcpu_on(vcpu); in kvm_psci_0_2_call()
275 kvm_psci_narrow_to_32bit(vcpu); in kvm_psci_0_2_call()
278 val = kvm_psci_vcpu_affinity_info(vcpu); in kvm_psci_0_2_call()
289 kvm_psci_system_off(vcpu); in kvm_psci_0_2_call()
291 * We shouldn't be going back to guest VCPU after in kvm_psci_0_2_call()
295 * guest VCPU after SYSTEM_OFF request then guest in kvm_psci_0_2_call()
296 * VCPU should see internal failure from PSCI return in kvm_psci_0_2_call()
304 kvm_psci_system_reset(vcpu); in kvm_psci_0_2_call()
317 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_0_2_call()
321 static int kvm_psci_1_x_call(struct kvm_vcpu *vcpu, u32 minor) in kvm_psci_1_x_call() argument
324 u32 psci_fn = smccc_get_function(vcpu); in kvm_psci_1_x_call()
325 struct kvm *kvm = vcpu->kvm; in kvm_psci_1_x_call()
334 arg = smccc_get_arg1(vcpu); in kvm_psci_1_x_call()
335 val = kvm_psci_check_allowed_function(vcpu, arg); in kvm_psci_1_x_call()
375 kvm_psci_narrow_to_32bit(vcpu); in kvm_psci_1_x_call()
379 * Return directly to userspace without changing the vCPU's in kvm_psci_1_x_call()
384 kvm_psci_system_suspend(vcpu); in kvm_psci_1_x_call()
389 kvm_psci_narrow_to_32bit(vcpu); in kvm_psci_1_x_call()
393 arg = smccc_get_arg1(vcpu); in kvm_psci_1_x_call()
397 kvm_psci_system_reset2(vcpu); in kvm_psci_1_x_call()
398 vcpu_set_reg(vcpu, 0, PSCI_RET_INTERNAL_FAILURE); in kvm_psci_1_x_call()
407 kvm_psci_narrow_to_32bit(vcpu); in kvm_psci_1_x_call()
413 arg = smccc_get_arg1(vcpu); in kvm_psci_1_x_call()
419 smccc_get_arg2(vcpu) != 0) { in kvm_psci_1_x_call()
423 kvm_psci_system_off2(vcpu); in kvm_psci_1_x_call()
428 * the vCPU. in kvm_psci_1_x_call()
434 return kvm_psci_0_2_call(vcpu); in kvm_psci_1_x_call()
437 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_1_x_call()
441 static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) in kvm_psci_0_1_call() argument
443 u32 psci_fn = smccc_get_function(vcpu); in kvm_psci_0_1_call()
448 kvm_arm_vcpu_power_off(vcpu); in kvm_psci_0_1_call()
452 val = kvm_psci_vcpu_on(vcpu); in kvm_psci_0_1_call()
459 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_0_1_call()
465 * @vcpu: Pointer to the VCPU struct
477 int kvm_psci_call(struct kvm_vcpu *vcpu) in kvm_psci_call() argument
479 u32 psci_fn = smccc_get_function(vcpu); in kvm_psci_call()
480 int version = kvm_psci_version(vcpu); in kvm_psci_call()
483 val = kvm_psci_check_allowed_function(vcpu, psci_fn); in kvm_psci_call()
485 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_call()
491 return kvm_psci_1_x_call(vcpu, 3); in kvm_psci_call()
493 return kvm_psci_1_x_call(vcpu, 2); in kvm_psci_call()
495 return kvm_psci_1_x_call(vcpu, 1); in kvm_psci_call()
497 return kvm_psci_1_x_call(vcpu, 0); in kvm_psci_call()
499 return kvm_psci_0_2_call(vcpu); in kvm_psci_call()
501 return kvm_psci_0_1_call(vcpu); in kvm_psci_call()
504 smccc_set_retval(vcpu, SMCCC_RET_NOT_SUPPORTED, 0, 0, 0); in kvm_psci_call()