From patchwork Tue Sep 24 15:21:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heyi Guo X-Patchwork-Id: 11159089 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0877014ED for ; Tue, 24 Sep 2019 15:24:42 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA339214DA for ; Tue, 24 Sep 2019 15:24:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HGrmv5PP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA339214DA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NTXcvceS0kxtDDP9Ub+KTsPtF0Rb0rzj/igVRJLcJgY=; b=HGrmv5PPzPEzfN EidUt1Q9jF80QdOZKsx2nX9IskOzA3+MPUYmbintGKWQZuKBnv8VEufyvAGlhHkSeuLQHnLdx5SUF 7GXfKrrOCjNT7GHUb2hB8Upq8j9WUwW/j5YD/81HNRxZUqN/qgzsaf18uzVUgjBGShsnXU4BffVWk hlVw5HJWe1hW0QY5coQ+WWY6JMs8XNjiLUqZvaF6u5ACZmM4Vci6qtQ+BduTGYC3/gvjiCdJ3Kkcd ReC/Fl8bU36QjdLSjmOGxsjjltpwX0/Z2rXiqKtoaNYzxbEn9i7Uky8wzpkXFE1GRb4fRf42X+dB3 bbZ+4UpwcjnfuuCMLLAA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCmgC-00040J-L3; Tue, 24 Sep 2019 15:24:40 +0000 Received: from szxga07-in.huawei.com ([45.249.212.35] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.92.2 #3 (Red Hat Linux)) id 1iCmf3-00035h-Nt for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2019 15:23:31 +0000 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 5EA36BE9A1306E7B3A53; Tue, 24 Sep 2019 23:23:27 +0800 (CST) Received: from linux-Bxxcye.huawei.com (10.175.104.222) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.439.0; Tue, 24 Sep 2019 23:23:17 +0800 From: Heyi Guo To: , , , Subject: [RFC PATCH 05/12] arm/sdei: add support to trigger event by GIC interrupt ID Date: Tue, 24 Sep 2019 23:21:44 +0800 Message-ID: <1569338511-3572-6-git-send-email-guoheyi@huawei.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1569338511-3572-1-git-send-email-guoheyi@huawei.com> References: <1569338511-3572-1-git-send-email-guoheyi@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.222] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190924_082330_136642_1DA6E721 X-CRM114-Status: GOOD ( 11.38 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.35 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Peter Maydell , Marc Zyngier , James Morse , Heyi Guo , wanghaibin.wang@huawei.com, Dave Martin Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add an external interface to trigger an SDEI event bound to an interrupt by providing GIC interrupt ID. Signed-off-by: Heyi Guo Cc: Peter Maydell Cc: Dave Martin Cc: Marc Zyngier Cc: Mark Rutland Cc: James Morse --- target/arm/sdei.c | 38 ++++++++++++++++++++++++++++++++++++++ target/arm/sdei.h | 7 +++++++ 2 files changed, 45 insertions(+) diff --git a/target/arm/sdei.c b/target/arm/sdei.c index f9a1208..088ed76 100644 --- a/target/arm/sdei.c +++ b/target/arm/sdei.c @@ -453,6 +453,29 @@ static int64_t sdei_version(QemuSDEState *s, CPUState *cs, struct kvm_run *run) (0ULL << SDEI_VERSION_MINOR_SHIFT); } +static bool inject_event(QemuSDEState *s, CPUState *cs, + int32_t event, int irq) +{ + QemuSDE *sde; + + if (event < 0) { + return false; + } + sde = get_sde_no_check(s, event, cs); + if (sde->event_id == SDEI_INVALID_EVENT_ID) { + put_sde(sde, cs); + return false; + } + if (irq > 0 && sde->prop->interrupt != irq) { + /* Someone unbinds the interrupt! */ + put_sde(sde, cs); + return false; + } + sde->pending = true; + dispatch_single(s, sde, cs); + return true; +} + static int64_t unregister_single_sde(QemuSDEState *s, int32_t event, CPUState *cs, bool force) { @@ -1033,6 +1056,21 @@ void sdei_handle_request(CPUState *cs, struct kvm_run *run) } } +bool trigger_sdei_by_irq(int cpu, int irq) +{ + QemuSDEState *s = sde_state; + + if (!s || irq >= ARRAY_SIZE(s->irq_map)) { + return false; + } + + if (s->irq_map[irq] == SDEI_INVALID_EVENT_ID) { + return false; + } + + return inject_event(s, arm_get_cpu_by_id(cpu), s->irq_map[irq], irq); +} + static void qemu_shared_sde_init(QemuSDEState *s) { int i; diff --git a/target/arm/sdei.h b/target/arm/sdei.h index a69a0e4..a61e788 100644 --- a/target/arm/sdei.h +++ b/target/arm/sdei.h @@ -31,4 +31,11 @@ void sdei_handle_request(CPUState *cs, struct kvm_run *run); +/* + * Trigger an SDEI event bound to an interrupt. + * Return true if event has been triggered successfully. + * Return false if event has not been triggered for some reason. + */ +bool trigger_sdei_by_irq(int cpu, int irq); + #endif