From patchwork Mon Dec 5 05:50:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 9460315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 609AA6071F for ; Mon, 5 Dec 2016 05:51:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FB3B24B5B for ; Mon, 5 Dec 2016 05:51:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42AAF26212; Mon, 5 Dec 2016 05:51:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B211824B5B for ; Mon, 5 Dec 2016 05:51:04 +0000 (UTC) Received: from localhost ([::1]:37037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDmB4-0006sl-AV for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Dec 2016 00:51:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cDmAh-0006sV-Id for qemu-devel@nongnu.org; Mon, 05 Dec 2016 00:50:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cDmAd-0007np-FI for qemu-devel@nongnu.org; Mon, 05 Dec 2016 00:50:39 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:36206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cDmAd-0007nl-4N; Mon, 05 Dec 2016 00:50:35 -0500 Received: by mail-pf0-x243.google.com with SMTP id c4so16464610pfb.3; Sun, 04 Dec 2016 21:50:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=rSd181VQ7Ei3wzGXWjkKRp+KrsdnQ6JPTjTzCnoyPW4=; b=F5AZjGmzfgnZbLm55aPMKTPM2JtsIR3aP7uzC7KrHvIrDMj8DNpFhxGLytVCAqYbLs 3dNWdQ9GwRjSqQcIL1CdfjYhjyq39ku4WoD1VEHV304sMk4uTTmNFe7rkI+x4QCmnBbe 3AO1TuBvs3GmQS3Bcl3IEC1PPsIGPGannKfNWHVDfV1vvVDNtcUqcfyWJMjXQAacm9z7 Y1/EA+bfdmQ9m0cX7xkPfXuq9rqC/MnxhoXlze1N5DbF8nBsfvB5IsXQg+HjwexYwQXb ilMW1+ithzS2yyqky8b95NXGPmKoYyEuFEAVMwtpaB0yEuV0EZ+rIgIiA79Hwkpgc2Y6 DJ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rSd181VQ7Ei3wzGXWjkKRp+KrsdnQ6JPTjTzCnoyPW4=; b=LZa63V3QjgRiZRMzxh5w9A5GCrM6ynZ2xEtfavfOsFcfRe1XWInpImMA4f3zXSoxzM 4LzGExe5KPvcjrEsEhQNN+y+DSC9tv3iKT0m3b3BszJRHeymUPqYnKOyatz3dFsfkdqu 2B5F4esxfjSXdekzQ97n7feXmP3+eeoDEC1UUkseEoa9ev5WChDT7d6Ij9z/YGV4PFE9 epfeIJfd+SbCb/37c+rzbq2+QFQ3b5nQKPrzgCmdPwr+yFQ1wqTDu+BizTdyj5yTKTU6 EXB+J5Zzz9qVV7bDoXT0HsR0dcSeHKdG8e/XUQWbMoeEQ0jOjzwB1x41WxTxgHxRuvLV za+Q== X-Gm-Message-State: AKaTC016+2hfodGYUvJY9sOME/2IJVEkzIoFSkSe/NqABQBKPyX3XWOI7S3wz4+BRBIi2Q== X-Received: by 10.99.37.195 with SMTP id l186mr98499759pgl.91.1480917034021; Sun, 04 Dec 2016 21:50:34 -0800 (PST) Received: from roar.au.ibm.com (27-33-21-189.tpgi.com.au. [27.33.21.189]) by smtp.gmail.com with ESMTPSA id m19sm23861444pfi.24.2016.12.04.21.50.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Dec 2016 21:50:33 -0800 (PST) From: Nicholas Piggin To: David Gibson , qemu-devel@nongnu.org, qemu-ppc@nongnu.org Date: Mon, 5 Dec 2016 16:50:21 +1100 Message-Id: <20161205055021.4985-1-npiggin@gmail.com> X-Mailer: git-send-email 2.10.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::243 Subject: [Qemu-devel] [PATCH ppc-for-2.9] ppc/spapr: implement H_SIGNAL_SYS_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: , Cc: Thomas Huth , Greg Kurz , Nicholas Piggin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The H_SIGNAL_SYS_RESET hcall allows a guest CPU to raise a system reset exception on CPUs within the same guest -- all CPUs, all-but-self, or a specific CPU (including self). This has not made its way to a PAPR release yet, but we have an hcall number assigned. H_SIGNAL_SYS_RESET = 0x380 Syntax: hcall(uint64 H_SIGNAL_SYS_RESET, int64 target); Generate a system reset NMI on the threads indicated by target. Values for target: -1 = target all online threads including the caller -2 = target all online threads except for the caller All other negative values: reserved Positive values: The thread to be targeted, obtained from the value of the "ibm,ppc-interrupt-server#s" property of the CPU in the OF device tree. Semantics: - Invalid target: return H_Parameter. - Otherwise: Generate a system reset NMI on target thread(s), return H_Success. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr.c | 4 ++-- hw/ppc/spapr_hcall.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 5 ++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 684d1d4..b693ab5 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2265,7 +2265,7 @@ static void spapr_machine_finalizefn(Object *obj) g_free(spapr->kvm_type); } -static void ppc_cpu_do_nmi_on_cpu(CPUState *cs, run_on_cpu_data arg) +void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg) { cpu_synchronize_state(cs); ppc_cpu_do_system_reset(cs); @@ -2276,7 +2276,7 @@ static void spapr_nmi(NMIState *n, int cpu_index, Error **errp) CPUState *cs; CPU_FOREACH(cs) { - async_run_on_cpu(cs, ppc_cpu_do_nmi_on_cpu, RUN_ON_CPU_NULL); + async_run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL); } } diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 35499ae..fd9f1d4 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -881,6 +881,46 @@ static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPRMachineState *spapr, return ret; } +#define H_SIGNAL_SYS_RESET_ALL -1 +#define H_SIGNAL_SYS_RESET_ALLBUTSELF -2 + +static target_ulong h_signal_sys_reset(PowerPCCPU *cpu, + sPAPRMachineState *spapr, + target_ulong opcode, target_ulong *args) +{ + target_long target = args[0]; + CPUState *cs; + + if (target < 0) { + /* Broadcast */ + if (target < H_SIGNAL_SYS_RESET_ALLBUTSELF) { + return H_PARAMETER; + } + + CPU_FOREACH(cs) { + PowerPCCPU *c = POWERPC_CPU(cs); + + if (target == H_SIGNAL_SYS_RESET_ALLBUTSELF) { + if (c == cpu) { + continue; + } + } + run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL); + } + return H_SUCCESS; + + } else { + /* Unicast */ + CPU_FOREACH(cs) { + if (cpu->cpu_dt_id == target) { + run_on_cpu(cs, spapr_do_system_reset_on_cpu, RUN_ON_CPU_NULL); + return H_SUCCESS; + } + } + return H_PARAMETER; + } +} + typedef struct { uint32_t compat_pvr; Error *err; @@ -1097,6 +1137,7 @@ static void hypercall_register_types(void) /* hcall-splpar */ spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa); spapr_register_hypercall(H_CEDE, h_cede); + spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset); /* processor register resource access h-calls */ spapr_register_hypercall(H_SET_SPRG0, h_set_sprg0); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 04d2821..a2d8964 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -347,7 +347,8 @@ struct sPAPRMachineState { #define H_XIRR_X 0x2FC #define H_RANDOM 0x300 #define H_SET_MODE 0x31C -#define MAX_HCALL_OPCODE H_SET_MODE +#define H_SIGNAL_SYS_RESET 0x380 +#define MAX_HCALL_OPCODE H_SIGNAL_SYS_RESET /* The hcalls above are standardized in PAPR and implemented by pHyp * as well. @@ -660,4 +661,6 @@ int spapr_rng_populate_dt(void *fdt); #define SPAPR_LMB_FLAGS_DRC_INVALID 0x00000020 #define SPAPR_LMB_FLAGS_RESERVED 0x00000080 +void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg); + #endif /* HW_SPAPR_H */