From patchwork Thu Feb 28 11:08:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 159325 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp502560jad; Thu, 28 Feb 2019 03:12:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IYUD+A3KuAb1KaNQNT1dm5uHGMc9ypSDHnmHWA8o9vPfEEIXwz+bqFswvQ/ksiOsOEQdIKl X-Received: by 2002:a0d:d9d6:: with SMTP id b205mr4840782ywe.85.1551352320659; Thu, 28 Feb 2019 03:12:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551352320; cv=none; d=google.com; s=arc-20160816; b=h4oOi0r0cxfEa1E9L/QcDlflrOck3Xw2kuveKIukka5PSz6jl/t/NMmLS2CsfeK2hd mCF5oH10fD1WOB+TN1h4+pZfrT5pCkmXJbsX81IpQ3I8WMlInl+DEy5mcM6a/92HE3C5 xrKolaoQdPD1UHP2PnXRffCDmlyd1EIpYv9DjfgUpcUF/dlyjqdq9ofH1tD++yCrOSJm lZcxNpdYZ4v3ocHaxzCKZdseyW9SyklfwnrUtcriHWA9K3SQD85gCpShX9seYzbzrSib hitEFxdD7e8MXwHByJNUJzciAle/YeNGDXMiGm1lbdExyGWSKtn0ryDlr6oIsCtO17iu ax2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=P6Xnni7stc/AZcmPiLqWW2UaWJXecr6jRBamFkErdOQ=; b=pGLHbKaWajrqzorW0Zn/3ZSJ08Z+my0jlULYuL6WPFgjsvQTiJ/tGYk/CWTQ8QyveX OCuGZgfwydVkqRFWpIaxv8aVuWtNeYm1ffwlJ8OzXE4C/4OwaaR7XW2qcOsBbEKrY7ga Dert3KgPjkHCtD1KUn4LBtiwyJXbrEmjY756jJluvcZs31hK02jzYkHJMtMKWZNVFaW+ NCZHF0Ac1l8dbO7+fuURiiUEGuqlRm6FREWC8XfUm/oanGj16PCsSQc5znpnZlcp5yfk 3Cd8yKzzIxsAxFALrBdmnjQZbQgptpsVwmABKqKDYBzRMWfUCe4bwdaEJcEXzu5fOXo1 mYBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cd2IQRa4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h185si6938423ybh.43.2019.02.28.03.12.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 03:12:00 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=cd2IQRa4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:36186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzJbc-0002Tj-2u for patch@linaro.org; Thu, 28 Feb 2019 06:12:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzJYo-0001Eu-8l for qemu-devel@nongnu.org; Thu, 28 Feb 2019 06:09:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzJYn-0003cl-2G for qemu-devel@nongnu.org; Thu, 28 Feb 2019 06:09:06 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:46732) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzJYm-0003Os-PY for qemu-devel@nongnu.org; Thu, 28 Feb 2019 06:09:04 -0500 Received: by mail-wr1-x431.google.com with SMTP id i16so21421168wrs.13 for ; Thu, 28 Feb 2019 03:08:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=P6Xnni7stc/AZcmPiLqWW2UaWJXecr6jRBamFkErdOQ=; b=cd2IQRa46iMTtheK6ZQu7yjO+oUBnXUdRT4QhAMoS5JbI4kpw3gOlFXocdB5aDJiW+ CG8oAXlYjPCegyl16UfUsQQyANgUi1WTDTUsqDCBiPiWqJXYoplrBF2wgTBld7RgSmXD xC7o9S5Jki8F6eSQ9g7OEQ2RX4CHd4GstWeddunL1iStV6ooYJw4klxqCTdovU9q0s1M i9xGxlouaQ+S+Fd4J2f334ZlKs5tG/xbYkfakhoA79NIXFaeeZ/H6p2ScQKvkEdc9p6h aVibD93Hveao+G0lbFCpBUEXIh7mYmXko/wwqB6NQWK3sSvdwaaxziTmObZFj/GpZtCI M/Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P6Xnni7stc/AZcmPiLqWW2UaWJXecr6jRBamFkErdOQ=; b=aBDP8Ss3sAlzieGnOGu4d7DcjLHFge6iZ/ZnibxLijlWYJJBwWB6hOtwQ359+VbBdC bT2YOvRyFFGlMgxuhRq6A/S4/BXCcaWiZXyIpZXXjpZd3n4LZK1eb+JXtirmVyLNAVVb AfvUYvVXI0rqdpUS3ump//Wxddpo4Xnz9QStxQm0NVTwSjysPXp5ZOEQNgRRW9gp+A0K MWjbYayllTcDPRX+8D4PF3U1Iq2ZZEZGjG/0osgUvrv7b/v+hefepMbOjFSJSSkjgdiS PYrKUN1o/+giZJvRU15Og6dk8kvk6oX2kPndjsgQwNVP3n8HtIlIa2uJqPk4RcetDdYl veEA== X-Gm-Message-State: APjAAAVZzL9woJNdLti/5gkzbi4CVxIPiS5ynPbJjBa7x3Tm36ow5Otr xgnUSiZBg9j45w9vueaM2VLSWl/gUBE= X-Received: by 2002:adf:fc12:: with SMTP id i18mr5778834wrr.201.1551352136545; Thu, 28 Feb 2019 03:08:56 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id c17sm13153241wrs.17.2019.02.28.03.08.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Feb 2019 03:08:55 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 28 Feb 2019 11:08:23 +0000 Message-Id: <20190228110835.16159-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190228110835.16159-1-peter.maydell@linaro.org> References: <20190228110835.16159-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 Subject: [Qemu-devel] [PULL 04/16] target/arm/arm-powerctl: Add new arm_set_cpu_on_and_reset() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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" Currently the Arm arm-powerctl.h APIs allow: * arm_set_cpu_on(), which powers on a CPU and sets its initial PC and other startup state * arm_reset_cpu(), which resets a CPU which is already on (and fails if the CPU is powered off) but there is no way to say "power on a CPU as if it had just come out of reset and don't do anything else to it". Add a new function arm_set_cpu_on_and_reset(), which does this. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20190219125808.25174-5-peter.maydell@linaro.org --- target/arm/arm-powerctl.h | 16 +++++++++++ target/arm/arm-powerctl.c | 56 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) -- 2.20.1 diff --git a/target/arm/arm-powerctl.h b/target/arm/arm-powerctl.h index 04353923c06..37c8a04f0a9 100644 --- a/target/arm/arm-powerctl.h +++ b/target/arm/arm-powerctl.h @@ -74,4 +74,20 @@ int arm_set_cpu_off(uint64_t cpuid); */ int arm_reset_cpu(uint64_t cpuid); +/* + * arm_set_cpu_on_and_reset: + * @cpuid: the id of the CPU we want to star + * + * Start the cpu designated by @cpuid and put it through its normal + * CPU reset process. The CPU will start in the way it is architected + * to start after a power-on reset. + * + * Returns: QEMU_ARM_POWERCTL_RET_SUCCESS on success. + * QEMU_ARM_POWERCTL_INVALID_PARAM if there is no CPU with that ID. + * QEMU_ARM_POWERCTL_ALREADY_ON if the CPU is already on. + * QEMU_ARM_POWERCTL_ON_PENDING if the CPU is already partway through + * powering on. + */ +int arm_set_cpu_on_and_reset(uint64_t cpuid); + #endif diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c index f9de5164e55..f77a950db67 100644 --- a/target/arm/arm-powerctl.c +++ b/target/arm/arm-powerctl.c @@ -228,6 +228,62 @@ int arm_set_cpu_on(uint64_t cpuid, uint64_t entry, uint64_t context_id, return QEMU_ARM_POWERCTL_RET_SUCCESS; } +static void arm_set_cpu_on_and_reset_async_work(CPUState *target_cpu_state, + run_on_cpu_data data) +{ + ARMCPU *target_cpu = ARM_CPU(target_cpu_state); + + /* Initialize the cpu we are turning on */ + cpu_reset(target_cpu_state); + target_cpu_state->halted = 0; + + /* Finally set the power status */ + assert(qemu_mutex_iothread_locked()); + target_cpu->power_state = PSCI_ON; +} + +int arm_set_cpu_on_and_reset(uint64_t cpuid) +{ + CPUState *target_cpu_state; + ARMCPU *target_cpu; + + assert(qemu_mutex_iothread_locked()); + + /* Retrieve the cpu we are powering up */ + target_cpu_state = arm_get_cpu_by_id(cpuid); + if (!target_cpu_state) { + /* The cpu was not found */ + return QEMU_ARM_POWERCTL_INVALID_PARAM; + } + + target_cpu = ARM_CPU(target_cpu_state); + if (target_cpu->power_state == PSCI_ON) { + qemu_log_mask(LOG_GUEST_ERROR, + "[ARM]%s: CPU %" PRId64 " is already on\n", + __func__, cpuid); + return QEMU_ARM_POWERCTL_ALREADY_ON; + } + + /* + * If another CPU has powered the target on we are in the state + * ON_PENDING and additional attempts to power on the CPU should + * fail (see 6.6 Implementation CPU_ON/CPU_OFF races in the PSCI + * spec) + */ + if (target_cpu->power_state == PSCI_ON_PENDING) { + qemu_log_mask(LOG_GUEST_ERROR, + "[ARM]%s: CPU %" PRId64 " is already powering on\n", + __func__, cpuid); + return QEMU_ARM_POWERCTL_ON_PENDING; + } + + async_run_on_cpu(target_cpu_state, arm_set_cpu_on_and_reset_async_work, + RUN_ON_CPU_NULL); + + /* We are good to go */ + return QEMU_ARM_POWERCTL_RET_SUCCESS; +} + static void arm_set_cpu_off_async_work(CPUState *target_cpu_state, run_on_cpu_data data) {