Lines Matching +full:psci +full:- +full:0
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2012 - ARM Ltd
7 #include <linux/arm-smccc.h>
24 #define AFFINITY_MASK(level) ~((0x1UL << ((level) * MPIDR_LEVEL_BITS)) - 1)
31 return 0; in psci_affinity_mask()
38 * same-as WFI (Wait-for-interrupt) emulation. in kvm_psci_vcpu_suspend()
42 * in section 5.4.1 of PSCI v0.2 specification (ARM DEN 0022A). in kvm_psci_vcpu_suspend()
44 * Further, we also treat power-down request to be same as in kvm_psci_vcpu_suspend()
45 * stand-by request as-per section 5.4.2 clause 3 of PSCI v0.2 in kvm_psci_vcpu_suspend()
63 struct kvm *kvm = source_vcpu->kvm; in kvm_psci_vcpu_on()
86 reset_state = &vcpu->arch.reset_state; in kvm_psci_vcpu_on()
88 reset_state->pc = smccc_get_arg2(source_vcpu); in kvm_psci_vcpu_on()
91 reset_state->be = kvm_vcpu_is_be(source_vcpu); in kvm_psci_vcpu_on()
94 * NOTE: We always update r0 (or x0) because for PSCI v0.1 in kvm_psci_vcpu_on()
97 reset_state->r0 = smccc_get_arg3(source_vcpu); in kvm_psci_vcpu_on()
99 WRITE_ONCE(reset_state->reset, true); in kvm_psci_vcpu_on()
108 vcpu->arch.mp_state.mp_state = KVM_MP_STATE_RUNNABLE; in kvm_psci_vcpu_on()
116 int matching_cpus = 0; in kvm_psci_vcpu_affinity_info()
121 struct kvm *kvm = vcpu->kvm; in kvm_psci_vcpu_affinity_info()
165 * actual request is made. Since we are implementing PSCI and a in kvm_prepare_system_event()
166 * caller of PSCI reboot and shutdown expects that the system shuts in kvm_prepare_system_event()
169 * re-initialized. in kvm_prepare_system_event()
171 kvm_for_each_vcpu(i, tmp, vcpu->kvm) in kvm_prepare_system_event()
172 tmp->arch.mp_state.mp_state = KVM_MP_STATE_STOPPED; in kvm_prepare_system_event()
173 kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP); in kvm_prepare_system_event()
175 memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); in kvm_prepare_system_event()
176 vcpu->run->system_event.type = type; in kvm_prepare_system_event()
177 vcpu->run->system_event.ndata = 1; in kvm_prepare_system_event()
178 vcpu->run->system_event.data[0] = flags; in kvm_prepare_system_event()
179 vcpu->run->exit_reason = KVM_EXIT_SYSTEM_EVENT; in kvm_prepare_system_event()
184 kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_SHUTDOWN, 0); in kvm_psci_system_off()
189 kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_RESET, 0); in kvm_psci_system_reset()
200 struct kvm_run *run = vcpu->run; in kvm_psci_system_suspend()
202 memset(&run->system_event, 0, sizeof(vcpu->run->system_event)); in kvm_psci_system_suspend()
203 run->system_event.type = KVM_SYSTEM_EVENT_SUSPEND; in kvm_psci_system_suspend()
204 run->exit_reason = KVM_EXIT_SYSTEM_EVENT; in kvm_psci_system_suspend()
222 * Prevent 32 bit guests from calling 64 bit PSCI functions. in kvm_psci_check_allowed_function()
227 return 0; in kvm_psci_check_allowed_function()
232 struct kvm *kvm = vcpu->kvm; in kvm_psci_0_2_call()
240 * Bits[31:16] = Major Version = 0 in kvm_psci_0_2_call()
241 * Bits[15:0] = Minor Version = 2 in kvm_psci_0_2_call()
257 mutex_lock(&kvm->lock); in kvm_psci_0_2_call()
259 mutex_unlock(&kvm->lock); in kvm_psci_0_2_call()
283 * VCPU should see internal failure from PSCI return in kvm_psci_0_2_call()
285 * PSCI return value INTERNAL_FAILURE. in kvm_psci_0_2_call()
288 ret = 0; in kvm_psci_0_2_call()
294 * with PSCI return value INTERNAL_FAILURE. in kvm_psci_0_2_call()
297 ret = 0; in kvm_psci_0_2_call()
304 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_0_2_call()
312 struct kvm *kvm = vcpu->kvm; in kvm_psci_1_x_call()
318 val = minor == 0 ? KVM_ARM_PSCI_1_0 : KVM_ARM_PSCI_1_1; in kvm_psci_1_x_call()
342 val = 0; in kvm_psci_1_x_call()
346 if (test_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags)) in kvm_psci_1_x_call()
347 val = 0; in kvm_psci_1_x_call()
352 val = 0; in kvm_psci_1_x_call()
365 if (test_bit(KVM_ARCH_FLAG_SYSTEM_SUSPEND_ENABLED, &kvm->arch.flags)) { in kvm_psci_1_x_call()
367 return 0; in kvm_psci_1_x_call()
380 vcpu_set_reg(vcpu, 0, PSCI_RET_INTERNAL_FAILURE); in kvm_psci_1_x_call()
381 return 0; in kvm_psci_1_x_call()
392 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_1_x_call()
398 struct kvm *kvm = vcpu->kvm; in kvm_psci_0_1_call()
408 mutex_lock(&kvm->lock); in kvm_psci_0_1_call()
410 mutex_unlock(&kvm->lock); in kvm_psci_0_1_call()
417 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_0_1_call()
422 * kvm_psci_call - handle PSCI call if r0 value is in range
425 * Handle PSCI calls from guests through traps from HVC instructions.
429 * This function returns: > 0 (success), 0 (success but exit to user
430 * space), and < 0 (errors)
433 * -EINVAL: Unrecognized PSCI function
442 smccc_set_retval(vcpu, val, 0, 0, 0); in kvm_psci_call()
450 return kvm_psci_1_x_call(vcpu, 0); in kvm_psci_call()
456 return -EINVAL; in kvm_psci_call()