2014-10-24 15:19:13 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 - Linaro
|
|
|
|
* Author: Rob Herring <rob.herring@linaro.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 08:23:50 +03:00
|
|
|
|
2015-12-07 19:23:44 +03:00
|
|
|
#include "qemu/osdep.h"
|
2016-06-22 20:11:19 +03:00
|
|
|
#include "cpu.h"
|
|
|
|
#include "exec/helper-proto.h"
|
|
|
|
#include "kvm-consts.h"
|
Include qemu/main-loop.h less
In my "build everything" tree, changing qemu/main-loop.h triggers a
recompile of some 5600 out of 6600 objects (not counting tests and
objects that don't depend on qemu/osdep.h). It includes block/aio.h,
which in turn includes qemu/event_notifier.h, qemu/notify.h,
qemu/processor.h, qemu/qsp.h, qemu/queue.h, qemu/thread-posix.h,
qemu/thread.h, qemu/timer.h, and a few more.
Include qemu/main-loop.h only where it's needed. Touching it now
recompiles only some 1700 objects. For block/aio.h and
qemu/event_notifier.h, these numbers drop from 5600 to 2800. For the
others, they shrink only slightly.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20190812052359.30071-21-armbru@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-08-12 08:23:50 +03:00
|
|
|
#include "qemu/main-loop.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2014-10-24 15:19:13 +04:00
|
|
|
#include "internals.h"
|
2016-05-12 15:22:28 +03:00
|
|
|
#include "arm-powerctl.h"
|
2014-10-24 15:19:13 +04:00
|
|
|
|
|
|
|
bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
|
|
|
|
{
|
2022-02-07 19:54:30 +03:00
|
|
|
/*
|
|
|
|
* Return true if the exception type matches the configured PSCI conduit.
|
|
|
|
* This is called before the SMC/HVC instruction is executed, to decide
|
|
|
|
* whether we should treat it as a PSCI call or with the architecturally
|
2014-10-24 15:19:13 +04:00
|
|
|
* defined behaviour for an SMC or HVC (which might be UNDEF or trap
|
|
|
|
* to EL2 or to EL3).
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (excp_type) {
|
|
|
|
case EXCP_HVC:
|
|
|
|
if (cpu->psci_conduit != QEMU_PSCI_CONDUIT_HVC) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXCP_SMC:
|
|
|
|
if (cpu->psci_conduit != QEMU_PSCI_CONDUIT_SMC) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-02-07 19:54:30 +03:00
|
|
|
return true;
|
2014-10-24 15:19:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void arm_handle_psci_call(ARMCPU *cpu)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This function partially implements the logic for dispatching Power State
|
2022-02-13 06:57:53 +03:00
|
|
|
* Coordination Interface (PSCI) calls (as described in ARM DEN 0022D.b),
|
2014-10-24 15:19:13 +04:00
|
|
|
* to the extent required for bringing up and taking down secondary cores,
|
|
|
|
* and for handling reset and poweroff requests.
|
|
|
|
* Additional information about the calling convention used is available in
|
|
|
|
* the document 'SMC Calling Convention' (ARM DEN 0028)
|
|
|
|
*/
|
|
|
|
CPUARMState *env = &cpu->env;
|
|
|
|
uint64_t param[4];
|
|
|
|
uint64_t context_id, mpidr;
|
|
|
|
target_ulong entry;
|
|
|
|
int32_t ret = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
/*
|
|
|
|
* All PSCI functions take explicit 32-bit or native int sized
|
|
|
|
* arguments so we can simply zero-extend all arguments regardless
|
|
|
|
* of which exact function we are about to call.
|
|
|
|
*/
|
|
|
|
param[i] = is_a64(env) ? env->xregs[i] : env->regs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((param[0] & QEMU_PSCI_0_2_64BIT) && !is_a64(env)) {
|
2022-02-13 06:57:53 +03:00
|
|
|
ret = QEMU_PSCI_RET_NOT_SUPPORTED;
|
2014-10-24 15:19:13 +04:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (param[0]) {
|
|
|
|
CPUState *target_cpu_state;
|
|
|
|
ARMCPU *target_cpu;
|
|
|
|
|
|
|
|
case QEMU_PSCI_0_2_FN_PSCI_VERSION:
|
2022-02-13 06:57:53 +03:00
|
|
|
ret = QEMU_PSCI_VERSION_1_1;
|
2014-10-24 15:19:13 +04:00
|
|
|
break;
|
|
|
|
case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE:
|
|
|
|
ret = QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED; /* No trusted OS */
|
|
|
|
break;
|
|
|
|
case QEMU_PSCI_0_2_FN_AFFINITY_INFO:
|
|
|
|
case QEMU_PSCI_0_2_FN64_AFFINITY_INFO:
|
|
|
|
mpidr = param[1];
|
|
|
|
|
|
|
|
switch (param[2]) {
|
|
|
|
case 0:
|
2016-05-12 15:22:28 +03:00
|
|
|
target_cpu_state = arm_get_cpu_by_id(mpidr);
|
2014-10-24 15:19:13 +04:00
|
|
|
if (!target_cpu_state) {
|
|
|
|
ret = QEMU_PSCI_RET_INVALID_PARAMS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
target_cpu = ARM_CPU(target_cpu_state);
|
2017-02-23 21:29:23 +03:00
|
|
|
|
|
|
|
g_assert(qemu_mutex_iothread_locked());
|
|
|
|
ret = target_cpu->power_state;
|
2014-10-24 15:19:13 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Everything above affinity level 0 is always on. */
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QEMU_PSCI_0_2_FN_SYSTEM_RESET:
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2014-10-24 15:19:13 +04:00
|
|
|
/* QEMU reset and shutdown are async requests, but PSCI
|
|
|
|
* mandates that we never return from the reset/shutdown
|
|
|
|
* call, so power the CPU off now so it doesn't execute
|
|
|
|
* anything further.
|
|
|
|
*/
|
|
|
|
goto cpu_off;
|
|
|
|
case QEMU_PSCI_0_2_FN_SYSTEM_OFF:
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
|
2014-10-24 15:19:13 +04:00
|
|
|
goto cpu_off;
|
|
|
|
case QEMU_PSCI_0_1_FN_CPU_ON:
|
|
|
|
case QEMU_PSCI_0_2_FN_CPU_ON:
|
|
|
|
case QEMU_PSCI_0_2_FN64_CPU_ON:
|
2017-01-20 14:15:10 +03:00
|
|
|
{
|
|
|
|
/* The PSCI spec mandates that newly brought up CPUs start
|
|
|
|
* in the highest exception level which exists and is enabled
|
|
|
|
* on the calling CPU. Since the QEMU PSCI implementation is
|
|
|
|
* acting as a "fake EL3" or "fake EL2" firmware, this for us
|
|
|
|
* means that we want to start at the highest NS exception level
|
|
|
|
* that we are providing to the guest.
|
|
|
|
* The execution mode should be that which is currently in use
|
|
|
|
* by the same exception level on the calling CPU.
|
|
|
|
* The CPU should be started with the context_id value
|
|
|
|
* in x0 (if AArch64) or r0 (if AArch32).
|
|
|
|
*/
|
|
|
|
int target_el = arm_feature(env, ARM_FEATURE_EL2) ? 2 : 1;
|
|
|
|
bool target_aarch64 = arm_el_is_aa64(env, target_el);
|
|
|
|
|
2014-10-24 15:19:13 +04:00
|
|
|
mpidr = param[1];
|
|
|
|
entry = param[2];
|
|
|
|
context_id = param[3];
|
2017-01-20 14:15:10 +03:00
|
|
|
ret = arm_set_cpu_on(mpidr, entry, context_id,
|
|
|
|
target_el, target_aarch64);
|
2014-10-24 15:19:13 +04:00
|
|
|
break;
|
2017-01-20 14:15:10 +03:00
|
|
|
}
|
2014-10-24 15:19:13 +04:00
|
|
|
case QEMU_PSCI_0_1_FN_CPU_OFF:
|
|
|
|
case QEMU_PSCI_0_2_FN_CPU_OFF:
|
|
|
|
goto cpu_off;
|
|
|
|
case QEMU_PSCI_0_1_FN_CPU_SUSPEND:
|
|
|
|
case QEMU_PSCI_0_2_FN_CPU_SUSPEND:
|
|
|
|
case QEMU_PSCI_0_2_FN64_CPU_SUSPEND:
|
|
|
|
/* Affinity levels are not supported in QEMU */
|
|
|
|
if (param[1] & 0xfffe0000) {
|
|
|
|
ret = QEMU_PSCI_RET_INVALID_PARAMS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Powerdown is not supported, we always go into WFI */
|
|
|
|
if (is_a64(env)) {
|
|
|
|
env->xregs[0] = 0;
|
|
|
|
} else {
|
|
|
|
env->regs[0] = 0;
|
|
|
|
}
|
2017-10-31 14:50:50 +03:00
|
|
|
helper_wfi(env, 4);
|
2014-10-24 15:19:13 +04:00
|
|
|
break;
|
2022-02-13 06:57:53 +03:00
|
|
|
case QEMU_PSCI_1_0_FN_PSCI_FEATURES:
|
|
|
|
switch (param[1]) {
|
|
|
|
case QEMU_PSCI_0_2_FN_PSCI_VERSION:
|
|
|
|
case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE:
|
|
|
|
case QEMU_PSCI_0_2_FN_AFFINITY_INFO:
|
|
|
|
case QEMU_PSCI_0_2_FN64_AFFINITY_INFO:
|
|
|
|
case QEMU_PSCI_0_2_FN_SYSTEM_RESET:
|
|
|
|
case QEMU_PSCI_0_2_FN_SYSTEM_OFF:
|
|
|
|
case QEMU_PSCI_0_1_FN_CPU_ON:
|
|
|
|
case QEMU_PSCI_0_2_FN_CPU_ON:
|
|
|
|
case QEMU_PSCI_0_2_FN64_CPU_ON:
|
|
|
|
case QEMU_PSCI_0_1_FN_CPU_OFF:
|
|
|
|
case QEMU_PSCI_0_2_FN_CPU_OFF:
|
|
|
|
case QEMU_PSCI_0_1_FN_CPU_SUSPEND:
|
|
|
|
case QEMU_PSCI_0_2_FN_CPU_SUSPEND:
|
|
|
|
case QEMU_PSCI_0_2_FN64_CPU_SUSPEND:
|
|
|
|
case QEMU_PSCI_1_0_FN_PSCI_FEATURES:
|
|
|
|
if (!(param[1] & QEMU_PSCI_0_2_64BIT) || is_a64(env)) {
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fallthrough */
|
|
|
|
case QEMU_PSCI_0_1_FN_MIGRATE:
|
|
|
|
case QEMU_PSCI_0_2_FN_MIGRATE:
|
|
|
|
default:
|
|
|
|
ret = QEMU_PSCI_RET_NOT_SUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2014-10-24 15:19:13 +04:00
|
|
|
case QEMU_PSCI_0_1_FN_MIGRATE:
|
|
|
|
case QEMU_PSCI_0_2_FN_MIGRATE:
|
2022-02-07 19:54:30 +03:00
|
|
|
default:
|
2014-10-24 15:19:13 +04:00
|
|
|
ret = QEMU_PSCI_RET_NOT_SUPPORTED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (is_a64(env)) {
|
|
|
|
env->xregs[0] = ret;
|
|
|
|
} else {
|
|
|
|
env->regs[0] = ret;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
cpu_off:
|
2016-05-12 15:22:28 +03:00
|
|
|
ret = arm_set_cpu_off(cpu->mp_affinity);
|
2014-10-24 15:19:13 +04:00
|
|
|
/* notreached */
|
2016-05-12 15:22:28 +03:00
|
|
|
/* sanity check in case something failed */
|
|
|
|
assert(ret == QEMU_ARM_POWERCTL_RET_SUCCESS);
|
2014-10-24 15:19:13 +04:00
|
|
|
}
|