From patchwork Mon May 5 16:00:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 29654 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F2F432055D for ; Mon, 5 May 2014 16:02:18 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id pa12sf9969230veb.7 for ; Mon, 05 May 2014 09:02:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=EmFkRsk8dVuUZNOHLn1HT4FrHYIoKID+PM0pJiMZxfg=; b=S1XgGtt57wJ5qM/p7St2Z+AFJjCPEb4GVTVRvrJwkZW2OdvoW3IjU0wjMGeQwgrL9w WHu23Tg03jGpFmjvRMlBsmKhP1sRU+LppgN0ZyFse1DvdFmGFbAwUhCaV+lnUxE3hxr5 J4AcHp+M5RXZ0dzG3s6hGhiMDjhmJ2wiqdPZaj/4gxoX8H6LfUl761Qxbv3LB6xLPt9Q wdCFmpWVJaVLhMCxmKsL8AW8mHKKVpa3fZ6u0eUxCNN33hGInHqCYBsSR6oJyalOC0mV h7RVJowOX62gb76kbo2cFysgqSafejxf+NyjrXiL5nj/PAfJ0YMyWfM06KQRe2At1Kol hn4g== X-Gm-Message-State: ALoCoQku5kE/7r+X1jMfrBJUYoqcoAfrrXo47g4GXjGW46HvzRNJnvo2mZ+15yXgJ+OvFODDnyB1 X-Received: by 10.236.39.175 with SMTP id d35mr14302924yhb.12.1399305738691; Mon, 05 May 2014 09:02:18 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.23.106 with SMTP id 97ls2538990qgo.34.gmail; Mon, 05 May 2014 09:02:18 -0700 (PDT) X-Received: by 10.220.44.20 with SMTP id y20mr832511vce.60.1399305738476; Mon, 05 May 2014 09:02:18 -0700 (PDT) Received: from mail-ve0-x234.google.com (mail-ve0-x234.google.com [2607:f8b0:400c:c01::234]) by mx.google.com with ESMTPS id p8si1686818vef.176.2014.05.05.09.02.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 May 2014 09:02:18 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=2607:f8b0:400c:c01::234; Received: by mail-ve0-f180.google.com with SMTP id db12so5538390veb.11 for ; Mon, 05 May 2014 09:02:18 -0700 (PDT) X-Received: by 10.52.227.138 with SMTP id sa10mr11751678vdc.25.1399305738391; Mon, 05 May 2014 09:02:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp151738vcb; Mon, 5 May 2014 09:02:18 -0700 (PDT) X-Received: by 10.140.18.173 with SMTP id 42mr42384545qgf.94.1399305737937; Mon, 05 May 2014 09:02:17 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g10si1314461qge.117.2014.05.05.09.02.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 05 May 2014 09:02:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:58231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhLLN-00009n-IO for patch@linaro.org; Mon, 05 May 2014 12:02:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhLJv-0006tQ-P2 for qemu-devel@nongnu.org; Mon, 05 May 2014 12:00:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhLJq-0000tL-EE for qemu-devel@nongnu.org; Mon, 05 May 2014 12:00:47 -0400 Received: from mail-ob0-x22e.google.com ([2607:f8b0:4003:c01::22e]:35750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhLJp-0000qa-PD for qemu-devel@nongnu.org; Mon, 05 May 2014 12:00:41 -0400 Received: by mail-ob0-f174.google.com with SMTP id uz6so1837900obc.5 for ; Mon, 05 May 2014 09:00:41 -0700 (PDT) X-Received: by 10.60.50.197 with SMTP id e5mr34389671oeo.39.1399305641024; Mon, 05 May 2014 09:00:41 -0700 (PDT) Received: from localhost.localdomain (72-48-77-163.dyn.grandenetworks.net. [72.48.77.163]) by mx.google.com with ESMTPSA id dw5sm20133189obb.0.2014.05.05.09.00.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 May 2014 09:00:40 -0700 (PDT) From: Rob Herring To: Peter Maydell Date: Mon, 5 May 2014 11:00:21 -0500 Message-Id: <1399305623-22016-6-git-send-email-robherring2@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1399305623-22016-1-git-send-email-robherring2@gmail.com> References: <1399305623-22016-1-git-send-email-robherring2@gmail.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c01::22e Cc: Rob Herring , qemu-devel@nongnu.org, Christoffer Dall Subject: [Qemu-devel] [PATCH 5/7] target-arm: add emulation of PSCI calls for system emulation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Original-Sender: robherring2@gmail.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=fail header.i=@gmail.com; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Rob Herring Add support for handling PSCI calls in system emulation. Both version 0.1 and 0.2 of the PSCI spec are supported. Platforms can enable support by setting "psci-method" QOM property on the cpus to SMC or HVC emulation and having PSCI binding in their dtb. Signed-off-by: Rob Herring --- target-arm/Makefile.objs | 1 + target-arm/cpu-qom.h | 6 ++ target-arm/cpu.c | 1 + target-arm/helper.c | 16 ++--- target-arm/kvm-consts.h | 6 ++ target-arm/psci.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 target-arm/psci.c diff --git a/target-arm/Makefile.objs b/target-arm/Makefile.objs index dcd167e..deda9f4 100644 --- a/target-arm/Makefile.objs +++ b/target-arm/Makefile.objs @@ -7,5 +7,6 @@ obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o obj-y += translate.o op_helper.o helper.o cpu.o obj-y += neon_helper.o iwmmxt_helper.o obj-y += gdbstub.o +obj-y += psci.o obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o obj-y += crypto_helper.o diff --git a/target-arm/cpu-qom.h b/target-arm/cpu-qom.h index 88aaf6a..2905525 100644 --- a/target-arm/cpu-qom.h +++ b/target-arm/cpu-qom.h @@ -98,6 +98,11 @@ typedef struct ARMCPU { bool start_powered_off; bool powered_off; + /* PSCI emulation state + * 0 - disabled, 1 - smc, 2 - hvc + */ + uint32_t psci_method; + /* [QEMU_]KVM_ARM_TARGET_* constant for this CPU, or * QEMU_KVM_ARM_TARGET_NONE if the kernel doesn't support this CPU type. */ @@ -185,6 +190,7 @@ extern const struct VMStateDescription vmstate_arm_cpu; void register_cp_regs_for_features(ARMCPU *cpu); void init_cpreg_list(ARMCPU *cpu); +bool arm_handle_psci(CPUState *cs); bool arm_cpu_do_hvc(CPUState *cs); bool arm_cpu_do_smc(CPUState *cs); diff --git a/target-arm/cpu.c b/target-arm/cpu.c index 2d18a20..eb21a52 100644 --- a/target-arm/cpu.c +++ b/target-arm/cpu.c @@ -1009,6 +1009,7 @@ static const ARMCPUInfo arm_cpus[] = { static Property arm_cpu_properties[] = { DEFINE_PROP_BOOL("start-powered-off", ARMCPU, start_powered_off, false), + DEFINE_PROP_UINT32("psci-method", ARMCPU, psci_method, 0), DEFINE_PROP_UINT32("midr", ARMCPU, midr, 0), DEFINE_PROP_END_OF_LIST() }; diff --git a/target-arm/helper.c b/target-arm/helper.c index b5b4a17..637c46a 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3255,23 +3255,23 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) bool arm_cpu_do_hvc(CPUState *cs) { - bool ret; + ARMCPU *cpu = ARM_CPU(cs); - ret = arm_handle_psci(cs); - if (ret) { - return ret; + if (cpu->psci_method == QEMU_PSCI_METHOD_HVC) { + return arm_handle_psci(cs); } + return false; } bool arm_cpu_do_smc(CPUState *cs) { - bool ret; + ARMCPU *cpu = ARM_CPU(cs); - ret = arm_handle_psci(cs); - if (ret) { - return ret; + if (cpu->psci_method == QEMU_PSCI_METHOD_SMC) { + return arm_handle_psci(cs); } + return false; } diff --git a/target-arm/kvm-consts.h b/target-arm/kvm-consts.h index 5cf93ab..d0a89c7 100644 --- a/target-arm/kvm-consts.h +++ b/target-arm/kvm-consts.h @@ -91,6 +91,12 @@ MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE, PSCI_0_2_FN64_MIGRATE) MISMATCH_CHECK(QEMU_PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU, \ PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU) +enum { + QEMU_PSCI_METHOD_DISABLED = 0, + QEMU_PSCI_METHOD_SMC = 1, + QEMU_PSCI_METHOD_HVC = 2, +}; + /* Note that KVM uses overlapping values for AArch32 and AArch64 * target CPU numbers. AArch32 targets: */ diff --git a/target-arm/psci.c b/target-arm/psci.c new file mode 100644 index 0000000..5c66236 --- /dev/null +++ b/target-arm/psci.c @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2014 - Linaro + * Author: Rob Herring + * + * 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 . + */ +#include +#include +#include +#include +#include + +#if !defined(CONFIG_USER_ONLY) + +bool arm_handle_psci(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(cs); + 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++) { + param[i] = is_a64(env) ? env->xregs[i] : env->regs[i]; + } + + if ((param[0] & PSCI_0_2_64BIT) && !is_a64(env)) { + ret = PSCI_RET_INVALID_PARAMS; + goto err; + } + + switch (param[0]) { + case PSCI_0_2_FN_PSCI_VERSION: + ret = PSCI_VERSION_MAJOR(0) | PSCI_VERSION_MINOR(2); + break; + case PSCI_0_2_FN_MIGRATE_INFO_TYPE: + ret = PSCI_0_2_TOS_MP; /* No trusted OS */ + break; + case PSCI_0_2_FN_AFFINITY_INFO: + case PSCI_0_2_FN64_AFFINITY_INFO: + mpidr = param[1]; + + switch (param[2]) { + case 0: + cs = qemu_get_cpu(mpidr & 0xff); + if (!cs) { + ret = PSCI_RET_INVALID_PARAMS; + break; + } + cpu = ARM_CPU(cs); + ret = cpu->powered_off ? 1 : 0; + break; + default: + /* Everything above affinity level 0 is always on. */ + ret = 0; + } + break; + case PSCI_0_2_FN_SYSTEM_RESET: + qemu_system_reset_request(); + break; + case PSCI_0_2_FN_SYSTEM_OFF: + qemu_system_powerdown_request(); + break; + case QEMU_PSCI_FN_CPU_ON: + case PSCI_0_2_FN_CPU_ON: + case PSCI_0_2_FN64_CPU_ON: + mpidr = param[1]; + entry = param[2]; + context_id = param[3]; + + /* change to the cpu we are powering up */ + cs = qemu_get_cpu(mpidr & 0xff); + if (!cs) { + ret = PSCI_RET_INVALID_PARAMS; + break; + } + cpu = ARM_CPU(cs); + + if (!cpu->powered_off) { + ret = PSCI_RET_ALREADY_ON; + break; + } + + /* Initialize the cpu we are turning on */ + cpu_reset(cs); + arm_cpu_set_pc(cs, entry); + cpu->powered_off = false; + cs->interrupt_request |= CPU_INTERRUPT_EXITTB; + + /* Set the context_id in r0/x0 */ + if (is_a64(env)) { + cpu->env.xregs[0] = context_id; + } else { + cpu->env.regs[0] = context_id; + } + + ret = 0; + break; + case QEMU_PSCI_FN_CPU_OFF: + case PSCI_0_2_FN_CPU_OFF: + cpu->powered_off = true; + cs->exit_request = 1; + cs->halted = 1; + + /* CPU_OFF should never return, but if it does return an error */ + ret = PSCI_RET_DENIED; + break; + case QEMU_PSCI_FN_CPU_SUSPEND: + case PSCI_0_2_FN_CPU_SUSPEND: + case PSCI_0_2_FN64_CPU_SUSPEND: + /* Affinity levels are not supported in QEMU */ + if (param[1] & 0xfffe0000) { + ret = PSCI_RET_INVALID_PARAMS; + break; + } + /* Powerdown is not supported, we always go into WFI */ + cs->halted = 1; + cs->exit_request = 1; + + /* Return success when we wakeup */ + ret = 0; + break; + case QEMU_PSCI_FN_MIGRATE: + case PSCI_0_2_FN_MIGRATE: + ret = PSCI_RET_NOT_SUPPORTED; + break; + default: + return false; + } + +err: + if (is_a64(env)) { + env->xregs[0] = ret; + } else { + env->regs[0] = ret; + } + return true; +} +#endif