From patchwork Mon Aug 30 05:34:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1522242 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=LjnSNo9+; dkim=pass (2048-bit key; unprotected) header.d=opensource.wdc.com header.i=@opensource.wdc.com header.a=rsa-sha256 header.s=dkim header.b=gcdkcSpd; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gys3S0xJwz9s1l for ; Mon, 30 Aug 2021 23:43:32 +1000 (AEST) Received: from localhost ([::1]:57710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKhZR-00077n-Pk for incoming@patchwork.ozlabs.org; Mon, 30 Aug 2021 09:43:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZx7-0007Ch-I2 for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:25 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:27142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZx4-0007mD-Mh for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1630301722; x=1661837722; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=nSm9A1goegV837KL+0Rg+vRf1hfDkOy/ABxNwnYYvqg=; b=LjnSNo9+Nkl5cWeUBFF492BN/aXJCLd6IbZUG/SBgOrIpKkmj06eWe15 ucDZjG+vpUEQt64/8hrKG3JVwyfnws5XsVmiItDwwOCadPhni9NFaYwXQ W4ZUCbkF5UzoV/MDLx9J4lnRND4hWhi84uFqNr6SdVSbCtIHaE8FMfFeE fBJYzDqhvB82gXQXKqB+FH93ckVCd3lVFJNip7Tk//dsN8vj72rjR5T4f BZ8JSY4vbvb96u8EodH6or5BsESY20sO1U9kQ90DGCV9dhpXNOY8yQpgK MUY906AFqBkRk+kONaIJhYMW1afk6ADfhlJz4Wnr+xU3CkWZqpZrmM5qY Q==; X-IronPort-AV: E=Sophos;i="5.84,362,1620662400"; d="scan'208";a="290336835" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 30 Aug 2021 13:34:32 +0800 IronPort-SDR: HApnMEEEFJZA19eeWcW+6K42cDkUlAel99m11O/5/IOJMCNSW25kx8H0kQ2gVRQ/UV2jywUddH NsFLPFvmNi9adXUHSYcWxyldTPMpp9tMxqQcLJXh/K9adPq0rSx0Qzl6Xl7/F/En1ep3S+mWXB UPEEKaFMjqV4hAf9K1Wjomglev/VM3JmPm7r9xpkjXqmwb81hDr2SB9i9OKNI7YiTOMdWz79Gn /OtOtkKEEPfB15xWmPeupJ27tcO91XFl45VjmUMfvCEVEdivV3VThc/MKqd9w3qTA2spqLQuEQ QR/TMu5vYqBaTgP8bH7HJPqy Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:09:40 -0700 IronPort-SDR: jX345GwtBtw6wc0oc6EaRv8qE9QoM9gstG5BagoUyHLNJ9E0DQ0EzqBFIQxW5sJD7hYAGMnMYg gy5TjRk4mnBzIBNEo/wBRtMuv1B/ayTHA2tO3y/aKSQevZwE3ChmhUZIatWOgBZ5rl6RvXD0AV tQgELEYFTH3HfyCWF5WGykfmHWfVQm+uU6wTRNbGzz0uXTewODYeLIBd5RxTBGbpu4z4Gl+mXi 5Ke2yoSi0R8H8DckutClV8bZcnIaHy12Ii830xzaYdqBOIb8TseRUqGLg3FQfLF19priLOWgm7 3Y4= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:34:32 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4GyfCD20vxz1RvlY for ; Sun, 29 Aug 2021 22:34:32 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :mime-version:x-mailer:message-id:date:subject:to:from; s=dkim; t=1630301671; x=1632893672; bh=nSm9A1goegV837KL+0Rg+vRf1hfDkOy/ ABxNwnYYvqg=; b=gcdkcSpd8ysYF/I57jleF1QJ6wu0ZuDp/Ma9VOg3PsSRJTwZ Mp4jcPcfKW7DLodmDaTWa237HFSBUK+tEzrkYhZ/SFvkyDh+Y2ySpZrP27kRCRRw 1bOmDAMIsuDUN/A8CShjKQfU+VsbNW5ZsCNjtc67UmYjZQbbhihZU769I9TIkcxM 3xheU1p4xrUpF1+ADCAeHdkl893F2u0TdNgQjU0Pktfgawy5MR896S6Y2MkgOMpn kQx1A6j6iXDTuDqTWCS89wllt1J7s2ZiVAZpoRhnR/H5sMojc0Buw7CZWAlO5gqS HT8Rf9/nUA3awIbrYqlm2QrkCK3f5kQrlu7FmA== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tFu-XSQs7Mqi for ; Sun, 29 Aug 2021 22:34:31 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.165.14]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4GyfC71M6yz1Rvl9; Sun, 29 Aug 2021 22:34:26 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: bmeng.cn@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [PATCH v3 1/5] target/riscv: Expose interrupt pending bits as GPIO lines Date: Mon, 30 Aug 2021 15:34:20 +1000 Message-Id: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=8697c1236=alistair.francis@opensource.wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Aug 2021 09:40:47 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Expose the 12 interrupt pending bits in MIP as GPIO lines. Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Bin Meng Tested-by: Bin Meng --- target/riscv/cpu.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 991a6bb760..86321baf9f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -565,11 +565,41 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) mcc->parent_realize(dev, errp); } +#ifndef CONFIG_USER_ONLY +static void riscv_cpu_set_irq(void *opaque, int irq, int level) +{ + RISCVCPU *cpu = RISCV_CPU(opaque); + + switch (irq) { + case IRQ_U_SOFT: + case IRQ_S_SOFT: + case IRQ_VS_SOFT: + case IRQ_M_SOFT: + case IRQ_U_TIMER: + case IRQ_S_TIMER: + case IRQ_VS_TIMER: + case IRQ_M_TIMER: + case IRQ_U_EXT: + case IRQ_S_EXT: + case IRQ_VS_EXT: + case IRQ_M_EXT: + riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level)); + break; + default: + g_assert_not_reached(); + } +} +#endif /* CONFIG_USER_ONLY */ + static void riscv_cpu_init(Object *obj) { RISCVCPU *cpu = RISCV_CPU(obj); cpu_set_cpustate_pointers(cpu); + +#ifndef CONFIG_USER_ONLY + qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq, 12); +#endif /* CONFIG_USER_ONLY */ } static Property riscv_cpu_properties[] = { From patchwork Mon Aug 30 05:34:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1522244 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=awPqbtuX; dkim=pass (2048-bit key; unprotected) header.d=opensource.wdc.com header.i=@opensource.wdc.com header.a=rsa-sha256 header.s=dkim header.b=bHsefsgr; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gys7415Wtz9s1l for ; Mon, 30 Aug 2021 23:46:38 +1000 (AEST) Received: from localhost ([::1]:36582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKhcR-0003Xk-E0 for incoming@patchwork.ozlabs.org; Mon, 30 Aug 2021 09:46:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40646) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZx9-0007Cu-SN for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:27 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:27142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZx7-0007mD-Pi for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1630301725; x=1661837725; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DbvJuxxtAb/ojEOuQffJ+/3nh+9Kr5gmKMWIROe04To=; b=awPqbtuXuAq7dF4fVrrLVsDkEckcGrXeuwyS7VhhaZScGc6/TT6xQyX8 EGdpDXBvHiAxOWjZYAkI9V0jU2nurXuqSMz/DXHXKr3+MP7yescvZmI2n r/k3mKqYjeEQto6hLi+lZrP3Ikzp5jsjhBV4053hjzsUkeVvvByn7/VrD gdaBoRP9206GF2DwZTXXUj6/VbcMZ5GUJ60qp6NpL3s1dBVajXBMYTpWx bzSc21yEypsIDmCd3RMykLmQw6f00f77FpkqXWCm2PFNCLeRDKrG+fMR3 wDU452lVDJCoBjRRBZigdUuREMDrXgtTVHFMma3KXseHEbKOOpGSRZXzU w==; X-IronPort-AV: E=Sophos;i="5.84,362,1620662400"; d="scan'208";a="290336878" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 30 Aug 2021 13:34:48 +0800 IronPort-SDR: u1kf1eql/+CVT1UPo2dIO4Vw6Uy35uXh412eUoWXVGA+d3gQtnC3j0QiXgo26HV/5qzdVTHf9P Du5QaNM+nkkhuFfQioy0unlIadEWWgT52bEXhuyCPcRQT83azGGiJ4vL8LFkir31FCqc3ZB4rj sxq+J9xOftQbbnMfpTjMy3LdnqzcwqHURBZnfaz+wQ8c8wbSGbWHNsXAy0fJX9iIKxBhIlzGTS 88x/4mtv9oUxky2mmWSypXGfz6hfFKknTaAuOgzuMyhmNAe3Jj+IvuEnXSYUIUAf0+TIvLNVMb ydC74+8a1HKbIDuGZtokO9hV Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:09:56 -0700 IronPort-SDR: fVZGZ8QUeGgmghHDmZluC8HRUdQLOmj6UPWF7uLnZi+wqk7biBg3pkUXgECd4qDIEq6RFNnvw4 4tooWjDGvlNsYPsBhFu/q4DARSAxIH6uIwSGQT+AcDOIxFVW/fZl69pd9ms+t0jkIPLDdDxSAO ecGSiib0oAF6yQSYrHtH5D1ls9F8F6wVvt8q66CmDKwrga0cBsJqQoJvj0/JeZrLwnP5jYg8fu Tjxq1Xn/i+fNBD+X/ns0TMdDSMivFh5TWxL/3RlxKjVuQIjZE/FsKjw88Y3NsPGftVM3o/uVoj +Gw= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:34:48 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4GyfCW5QCpz1RvlZ for ; Sun, 29 Aug 2021 22:34:47 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:subject:to :from; s=dkim; t=1630301686; x=1632893687; bh=DbvJuxxtAb/ojEOuQf fJ+/3nh+9Kr5gmKMWIROe04To=; b=bHsefsgr8D8Xot/CEuOqvywd39zvGyK5U8 zO0Rv+B5/PwIVTPpY5i1ErazLmSpT8IhD6kV9q+jUFnbRGP/QIUrOmus5xft+QpV giccUPz9lgQWNxU4MEbqTNSRG2QnFy/ivp3mk2PhdpXRa8RibyLXxVByOpkvDa2O MvG/zcA99U69V/0kMqe8fPxWjfQMp1vsGt7yr5TcCwqNE4NeZb3/wny73MudKwZh 1WX5ENgvRfNaAldx0lDOgZaI8OBFd1u8TxaI3YkMkh9hv5vnxbEewi1t2fnWgroA es5VkAOe2Qy4idBh/qakPsx+NUIC6hyswGjy8GAub7HwqJrgSCUg== X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id qLepc44PdFpP for ; Sun, 29 Aug 2021 22:34:46 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.165.14]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4GyfCR09JMz1Rvl9; Sun, 29 Aug 2021 22:34:42 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: bmeng.cn@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [PATCH v3 2/5] hw/intc: sifive_clint: Use RISC-V CPU GPIO lines Date: Mon, 30 Aug 2021 15:34:36 +1000 Message-Id: <946e1ef5e268b24084c7ddad84c146de62a56736.1630301632.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> References: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=8697c1236=alistair.francis@opensource.wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Aug 2021 09:40:47 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Instead of using riscv_cpu_update_mip() let's instead use the new RISC-V CPU GPIO lines to set the timer and soft MIP bits. Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: LIU Zhiwei --- include/hw/intc/sifive_clint.h | 2 + hw/intc/sifive_clint.c | 68 ++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/include/hw/intc/sifive_clint.h b/include/hw/intc/sifive_clint.h index a30be0f3d6..921b1561dd 100644 --- a/include/hw/intc/sifive_clint.h +++ b/include/hw/intc/sifive_clint.h @@ -40,6 +40,8 @@ typedef struct SiFiveCLINTState { uint32_t time_base; uint32_t aperture_size; uint32_t timebase_freq; + qemu_irq *timer_irqs; + qemu_irq *soft_irqs; } SiFiveCLINTState; DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, diff --git a/hw/intc/sifive_clint.c b/hw/intc/sifive_clint.c index 0f41e5ea1c..b2f83604a6 100644 --- a/hw/intc/sifive_clint.c +++ b/hw/intc/sifive_clint.c @@ -28,6 +28,12 @@ #include "hw/qdev-properties.h" #include "hw/intc/sifive_clint.h" #include "qemu/timer.h" +#include "hw/irq.h" + +typedef struct sifive_clint_callback { + SiFiveCLINTState *s; + int num; +} sifive_clint_callback; static uint64_t cpu_riscv_read_rtc(uint32_t timebase_freq) { @@ -39,7 +45,9 @@ static uint64_t cpu_riscv_read_rtc(uint32_t timebase_freq) * Called when timecmp is written to update the QEMU timer or immediately * trigger timer interrupt if mtimecmp <= current timer value. */ -static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value, +static void sifive_clint_write_timecmp(SiFiveCLINTState *s, RISCVCPU *cpu, + int hartid, + uint64_t value, uint32_t timebase_freq) { uint64_t next; @@ -51,12 +59,12 @@ static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value, if (cpu->env.timecmp <= rtc_r) { /* if we're setting an MTIMECMP value in the "past", immediately raise the timer interrupt */ - riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(1)); + qemu_irq_raise(s->timer_irqs[hartid - s->hartid_base]); return; } /* otherwise, set up the future timer interrupt */ - riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(0)); + qemu_irq_lower(s->timer_irqs[hartid - s->hartid_base]); diff = cpu->env.timecmp - rtc_r; /* back to ns (note args switched in muldiv64) */ next = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + @@ -70,8 +78,9 @@ static void sifive_clint_write_timecmp(RISCVCPU *cpu, uint64_t value, */ static void sifive_clint_timer_cb(void *opaque) { - RISCVCPU *cpu = opaque; - riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(1)); + sifive_clint_callback *state = opaque; + + qemu_irq_raise(state->s->timer_irqs[state->num]); } /* CPU wants to read rtc or timecmp register */ @@ -137,7 +146,7 @@ static void sifive_clint_write(void *opaque, hwaddr addr, uint64_t value, if (!env) { error_report("clint: invalid timecmp hartid: %zu", hartid); } else if ((addr & 0x3) == 0) { - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MSIP, BOOL_TO_MASK(value)); + qemu_set_irq(clint->soft_irqs[hartid - clint->hartid_base], value); } else { error_report("clint: invalid sip write: %08x", (uint32_t)addr); } @@ -153,13 +162,13 @@ static void sifive_clint_write(void *opaque, hwaddr addr, uint64_t value, } else if ((addr & 0x7) == 0) { /* timecmp_lo */ uint64_t timecmp_hi = env->timecmp >> 32; - sifive_clint_write_timecmp(RISCV_CPU(cpu), + sifive_clint_write_timecmp(clint, RISCV_CPU(cpu), hartid, timecmp_hi << 32 | (value & 0xFFFFFFFF), clint->timebase_freq); return; } else if ((addr & 0x7) == 4) { /* timecmp_hi */ uint64_t timecmp_lo = env->timecmp; - sifive_clint_write_timecmp(RISCV_CPU(cpu), + sifive_clint_write_timecmp(clint, RISCV_CPU(cpu), hartid, value << 32 | (timecmp_lo & 0xFFFFFFFF), clint->timebase_freq); } else { error_report("clint: invalid timecmp write: %08x", (uint32_t)addr); @@ -205,6 +214,12 @@ static void sifive_clint_realize(DeviceState *dev, Error **errp) memory_region_init_io(&s->mmio, OBJECT(dev), &sifive_clint_ops, s, TYPE_SIFIVE_CLINT, s->aperture_size); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio); + + s->timer_irqs = g_malloc(sizeof(qemu_irq) * s->num_harts); + qdev_init_gpio_out(dev, s->timer_irqs, s->num_harts); + + s->soft_irqs = g_malloc(sizeof(qemu_irq) * s->num_harts); + qdev_init_gpio_out(dev, s->soft_irqs, s->num_harts); } static void sifive_clint_class_init(ObjectClass *klass, void *data) @@ -228,7 +243,6 @@ static void sifive_clint_register_types(void) type_init(sifive_clint_register_types) - /* * Create CLINT device. */ @@ -238,29 +252,43 @@ DeviceState *sifive_clint_create(hwaddr addr, hwaddr size, bool provide_rdtime) { int i; + + DeviceState *dev = qdev_new(TYPE_SIFIVE_CLINT); + qdev_prop_set_uint32(dev, "hartid-base", hartid_base); + qdev_prop_set_uint32(dev, "num-harts", num_harts); + qdev_prop_set_uint32(dev, "sip-base", sip_base); + qdev_prop_set_uint32(dev, "timecmp-base", timecmp_base); + qdev_prop_set_uint32(dev, "time-base", time_base); + qdev_prop_set_uint32(dev, "aperture-size", size); + qdev_prop_set_uint32(dev, "timebase-freq", timebase_freq); + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + for (i = 0; i < num_harts; i++) { CPUState *cpu = qemu_get_cpu(hartid_base + i); + RISCVCPU *rvcpu = RISCV_CPU(cpu); CPURISCVState *env = cpu ? cpu->env_ptr : NULL; + sifive_clint_callback *cb = g_malloc0(sizeof(sifive_clint_callback)); + if (!env) { + g_free(cb); continue; } if (provide_rdtime) { riscv_cpu_set_rdtime_fn(env, cpu_riscv_read_rtc, timebase_freq); } + + cb->s = SIFIVE_CLINT(dev); + cb->num = i; env->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, - &sifive_clint_timer_cb, cpu); + &sifive_clint_timer_cb, cb); env->timecmp = 0; + + qdev_connect_gpio_out(dev, i, + qdev_get_gpio_in(DEVICE(rvcpu), IRQ_M_TIMER)); + qdev_connect_gpio_out(dev, num_harts + i, + qdev_get_gpio_in(DEVICE(rvcpu), IRQ_M_SOFT)); } - DeviceState *dev = qdev_new(TYPE_SIFIVE_CLINT); - qdev_prop_set_uint32(dev, "hartid-base", hartid_base); - qdev_prop_set_uint32(dev, "num-harts", num_harts); - qdev_prop_set_uint32(dev, "sip-base", sip_base); - qdev_prop_set_uint32(dev, "timecmp-base", timecmp_base); - qdev_prop_set_uint32(dev, "time-base", time_base); - qdev_prop_set_uint32(dev, "aperture-size", size); - qdev_prop_set_uint32(dev, "timebase-freq", timebase_freq); - sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); return dev; } From patchwork Mon Aug 30 05:34:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1522245 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=asj4cw66; dkim=pass (2048-bit key; unprotected) header.d=opensource.wdc.com header.i=@opensource.wdc.com header.a=rsa-sha256 header.s=dkim header.b=Wb8qZSxT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gys9T3sHNz9sRf for ; Mon, 30 Aug 2021 23:48:45 +1000 (AEST) Received: from localhost ([::1]:39890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKheV-0005vf-9f for incoming@patchwork.ozlabs.org; Mon, 30 Aug 2021 09:48:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZxG-0007Gv-5v for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:35 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:27142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZxB-0007mD-Vq for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1630301729; x=1661837729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V1Q1eyaUKg34qe5BkhYmnC+g3xItY5QViYtDFWipPLs=; b=asj4cw66+pMuMzdBklaV51zGh5cs6qU9hK7UePi3gl+h/mBWqhela27F aLDsXLW4dH8PPd6yAmZVsZ0MgZc9w0R6xlLN2hZhYzlGF/+SI329Di4MN QTCtNhgEdREzr9jf8m6dt266YMMNiemyeHcgz60e8ILl+6Fev7paxJTc1 R9NAR3hurlgNRO34810KUKNvnZboeNjd6p/NHifMyVm/s+Ks2ZAYEi3xz xF6fRXJ2W4TkMWI8zUZxYwa7x5n7IE8sU3nYH1RQ0/dnjOgAQ0j5JH2lJ 6pX/rFuQnqjDbO1QA1WifRDW2jZtGGI5NPlpMaFDR/XmzH5RcYBp2BFb2 Q==; X-IronPort-AV: E=Sophos;i="5.84,362,1620662400"; d="scan'208";a="290336898" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Aug 2021 13:35:02 +0800 IronPort-SDR: 7vp3oVP/1M7nuRNtxIyJFmhgnEE90dLEvbvGM5NEguVTUJAc/6U35KRvfhH8yohsA47jBG6jWC kVnM/eokjkcv3NxXN2muPt4YzbxJj887sb9iccNfe4R/AcWMtKpmgher1xBu2g7NOAyNAkt8wz gTfvUcrZMS1Is5h2OszHsXm7Vxp1Kr0k6/n79iQBoMt5CIDT3523wKNCKzYIFHOhovuDrw1a/+ l//5Qfy73rGr/evAKx4izxHUWD7zibcYEyK73HY4/J/aK//2npiMDAwweRGbRwEcMdRtCb/pf+ PJSO/pBHdBDU1N8vIL18jPC5 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:11:51 -0700 IronPort-SDR: 4Y4sc/1o6IWncCGabwNLc/T6ZEYkEG1ROtYOgWtQ6ZkCs0p9TXnNp+h0xK93VysJ7gQ5hwTqfn 2wBGDgTGu8Ci/8w3mf8U+vFgoBooZppohh2FUnp9rPaaORYvCp5IdeL104HIOSnj+yXU4jx7oe ZM3rZUvXyB3fzlJk4kD3ClUoEKSGHfam21EIPsxgjck7JsjWKGaZz/w4emKEHxm1YpMdrEsyvt wnWaylbYIVMIPNyk5K+ckT5TPX78FPiP+074XVm0OvGVegGNhNcqeLd9/8d+bqSKlB0MsMboqN SVU= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:35:00 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4GyfCm0ZbWz1RvlV for ; Sun, 29 Aug 2021 22:35:00 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :mime-version:references:in-reply-to:x-mailer:message-id:date :subject:to:from; s=dkim; t=1630301699; x=1632893700; bh=V1Q1eya UKg34qe5BkhYmnC+g3xItY5QViYtDFWipPLs=; b=Wb8qZSxTqqB1hKounZp8A/j VfMEd5R6dF2Ie4OeS7O1hxHS9cxIyn24HiMXFKJLWD14rk996XLF2sgwFYXNpBBv 1M4MxlpEcSe1zULJlriyCAzv+K+D1BaiGr+1LOWnUjR9L5d6zjfOUSrzBhy3JBLP 4Qh2u1YRe56EaGCsWoRESmZ8C9yx3zDuiBbjxOE04ZYMc9FY/ZARQVlR8sg0/E5T 5cK2kKjLC2glcoPco09H84dLSdnpL53nV/M7YfZP2Wmh8FGtAaD+IjHaGZmMIHUN ey78fG7E304vy9Hgb2U4sgi7HcUzb1NTN/9hHPPBO1QM9xObqqrHNs2xeIz9D9Q= = X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xOMBODlhghfT for ; Sun, 29 Aug 2021 22:34:59 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.165.14]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4GyfCg3FPRz1Rvl9; Sun, 29 Aug 2021 22:34:54 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: bmeng.cn@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [PATCH v3 3/5] hw/intc: ibex_plic: Convert the PLIC to use RISC-V CPU GPIO lines Date: Mon, 30 Aug 2021 15:34:49 +1000 Message-Id: <0a76946981852f5bd15f0c37ab35b253371027a8.1630301632.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> References: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=8697c1236=alistair.francis@opensource.wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Aug 2021 09:40:47 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Instead of using riscv_cpu_update_mip() let's instead use the new RISC-V CPU GPIO lines to set the external MIP bits. Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- include/hw/intc/ibex_plic.h | 2 ++ hw/intc/ibex_plic.c | 17 ++++++----------- hw/riscv/opentitan.c | 8 ++++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/hw/intc/ibex_plic.h b/include/hw/intc/ibex_plic.h index 7fc495db99..d596436e06 100644 --- a/include/hw/intc/ibex_plic.h +++ b/include/hw/intc/ibex_plic.h @@ -60,6 +60,8 @@ struct IbexPlicState { uint32_t threshold_base; uint32_t claim_base; + + qemu_irq *external_irqs; }; #endif /* HW_IBEX_PLIC_H */ diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c index edf76e4f61..ff430356f8 100644 --- a/hw/intc/ibex_plic.c +++ b/hw/intc/ibex_plic.c @@ -27,6 +27,7 @@ #include "target/riscv/cpu_bits.h" #include "target/riscv/cpu.h" #include "hw/intc/ibex_plic.h" +#include "hw/irq.h" static bool addr_between(uint32_t addr, uint32_t base, uint32_t num) { @@ -92,19 +93,10 @@ static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context) static void ibex_plic_update(IbexPlicState *s) { - CPUState *cpu; - int level, i; + int i; for (i = 0; i < s->num_cpus; i++) { - cpu = qemu_get_cpu(i); - - if (!cpu) { - continue; - } - - level = ibex_plic_irqs_pending(s, 0); - - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(level)); + qemu_set_irq(s->external_irqs[i], ibex_plic_irqs_pending(s, 0)); } } @@ -268,6 +260,9 @@ static void ibex_plic_realize(DeviceState *dev, Error **errp) qdev_init_gpio_in(dev, ibex_plic_irq_request, s->num_sources); + s->external_irqs = g_malloc(sizeof(qemu_irq) * s->num_cpus); + qdev_init_gpio_out(dev, s->external_irqs, s->num_cpus); + /* * We can't allow the supervisor to control SEIP as this would allow the * supervisor to clear a pending external interrupt which will result in diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index 36a41c8b5b..048aced0ec 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -118,6 +118,7 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) MachineState *ms = MACHINE(qdev_get_machine()); LowRISCIbexSoCState *s = RISCV_IBEX_SOC(dev_soc); MemoryRegion *sys_mem = get_system_memory(); + int i; object_property_set_str(OBJECT(&s->cpus), "cpu-type", ms->cpu_type, &error_abort); @@ -149,6 +150,13 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) } sysbus_mmio_map(SYS_BUS_DEVICE(&s->plic), 0, memmap[IBEX_DEV_PLIC].base); + for (i = 0; i < ms->smp.cpus; i++) { + CPUState *cpu = qemu_get_cpu(i); + + qdev_connect_gpio_out(DEVICE(&s->plic), i, + qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT)); + } + /* UART */ qdev_prop_set_chr(DEVICE(&(s->uart)), "chardev", serial_hd(0)); if (!sysbus_realize(SYS_BUS_DEVICE(&s->uart), errp)) { From patchwork Mon Aug 30 05:35:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1522240 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=NXwUeDoE; dkim=pass (2048-bit key; unprotected) header.d=opensource.wdc.com header.i=@opensource.wdc.com header.a=rsa-sha256 header.s=dkim header.b=nN+7SQeo; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gys170jQSz9sWS for ; Mon, 30 Aug 2021 23:41:31 +1000 (AEST) Received: from localhost ([::1]:51888 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKhXU-00033R-RR for incoming@patchwork.ozlabs.org; Mon, 30 Aug 2021 09:41:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZxg-0007Rr-Ua for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:36:01 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:59126) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZxe-0008ME-Mx for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:36:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1630301758; x=1661837758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GGWiDACSH03nm/CKhcs0uPyEIjeFOoJwborFbGxLIYQ=; b=NXwUeDoE+qLHkuPNEpxl87OoN3T2s4ko0KvJMmkDeKeMh4JTVZM44Pqd wW8GWE7meH0dd/J7MUfgOOP4jICAVZ/W5nSkLI7NSAm79RWzfWMuiWXr3 ZpCKbWR/EMcWms88caVLeBJnaKYiv9vQ9tHbtqt0JItjafRYoZmRvgcl/ +bqiYgXwKPEHKrSQh0RMKDOU/K5YYRZzE5oBMTPDibjnH1vdpv4fQVg0F oY/d24A9vy9aDIjOBZZ5JE+BULWM7L61B252YyocFaMboCjhhsMHXHiMs 93CCdgf+J8RvmFREPRwuz8Y43dgeyaXuGS5z/FBxeYXduk2Kgy6tDiIww g==; X-IronPort-AV: E=Sophos;i="5.84,362,1620662400"; d="scan'208";a="282524621" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 Aug 2021 13:35:13 +0800 IronPort-SDR: KZWhGFzHUdjBeT93Pf0ofWY1Ppa3j14DfdigWODu0W0pvzu6V8xtpPgNfwz6LuUvtZqq75Sqlv t/i9Esl/VikkC6fr1teYtnzzi5BwdVdpsnJ0emEZCQvr7bv5B/8USamAutyEDi2ob8np0LI9KQ rs+9sQcWLNGOLcjskPzfV+QOPkC/AVInGujpyjRqcO9/aI97gn09IBBnX0Zev2jahZlsO6Rghw hj1gVzfWplYRwZcYVDz9zNTjLqPRZtOpZPbGQoJ+kiDI7F/xxJ/cZh5qEm7LhnWApuSG8vk2UX DErJH/xqpMLuKeQJpOE64NQD Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:12:04 -0700 IronPort-SDR: SLe/sdF7W0PDoDT1z20mVRyMH5bIukguUKisz8L2UrllLfSNls98Gc9BHDobS5TcVAAq78833p Sms7Eb+al63mohDK2XU4z/hEPNsMfpNo+MgGamGrWhq0ZaMKLD8KmEzGhwVc5Ki92maZG8QTuE Izf9x1iuhfVS+NMu85eZJRyY/5+896/Pjzf/1uKzRoFGs4CHsv/MUdwMPB8qd5y6koPxoCQ1mF azLx/D3nMBO2hLYyhZGHWxS03cj++TesbT1q+xHP3cZdh3nIdr0dj/iozPS8I4tntOgFyK34XI 0eM= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:35:13 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4GyfD139N8z1RvlT for ; Sun, 29 Aug 2021 22:35:13 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :mime-version:references:in-reply-to:x-mailer:message-id:date :subject:to:from; s=dkim; t=1630301712; x=1632893713; bh=GGWiDAC SH03nm/CKhcs0uPyEIjeFOoJwborFbGxLIYQ=; b=nN+7SQeoo/mNh3R0rjHaDgA j4kPoy1JpeAFpQykag9uNQXtqoKXp7rTEI1sFD9la52826fJRPJvzkZthURNtEiq LmMENaebzAqm71VQ4z5i+Laao3hD4HUufBMQMPnxmhWp+6jbgHp6g6AUdRCSNTHX hUuH3CXIuXB6fyQQjPlGDMbjRhq5emOkWD1kmI/CX1+zo5IGEV9i7rP4bb+aRb2T EgjD8gprbMdXup2/b3FeK4vgLCSV/IK/LeDCOxvd740kvx4eDwkpIQANOz9nn1O9 kRcO45B13frwJMlCKg61hTQN0p1YZCsL48sj+7EuumjqWKPKD915SEttTTu+jWg= = X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cGvLNrdnaHN2 for ; Sun, 29 Aug 2021 22:35:12 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.165.14]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4GyfCw6CL5z1Rvl9; Sun, 29 Aug 2021 22:35:08 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: bmeng.cn@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [PATCH v3 4/5] hw/intc: sifive_plic: Convert the PLIC to use RISC-V CPU GPIO lines Date: Mon, 30 Aug 2021 15:35:02 +1000 Message-Id: <0364190bfa935058a845c0fa1ecf650328840ad5.1630301632.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> References: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=8697c1236=alistair.francis@opensource.wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Aug 2021 09:40:47 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Instead of using riscv_cpu_update_mip() let's instead use the new RISC-V CPU GPIO lines to set the external MIP bits. Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Reviewed-by: Bin Meng Tested-by: Bin Meng --- include/hw/intc/sifive_plic.h | 4 ++++ hw/intc/sifive_plic.c | 30 +++++++++++++++++++++++------- hw/riscv/microchip_pfsoc.c | 2 +- hw/riscv/shakti_c.c | 3 ++- hw/riscv/sifive_e.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/riscv/virt.c | 2 +- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/include/hw/intc/sifive_plic.h b/include/hw/intc/sifive_plic.h index 1e451a270c..134cf39a96 100644 --- a/include/hw/intc/sifive_plic.h +++ b/include/hw/intc/sifive_plic.h @@ -72,9 +72,13 @@ struct SiFivePLICState { uint32_t context_base; uint32_t context_stride; uint32_t aperture_size; + + qemu_irq *m_external_irqs; + qemu_irq *s_external_irqs; }; DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, + uint32_t num_harts, uint32_t hartid_base, uint32_t num_sources, uint32_t num_priorities, uint32_t priority_base, uint32_t pending_base, uint32_t enable_base, diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c index 78903beb06..9ba36dc0b3 100644 --- a/hw/intc/sifive_plic.c +++ b/hw/intc/sifive_plic.c @@ -29,6 +29,7 @@ #include "hw/intc/sifive_plic.h" #include "target/riscv/cpu.h" #include "migration/vmstate.h" +#include "hw/irq.h" #define RISCV_DEBUG_PLIC 0 @@ -139,18 +140,14 @@ static void sifive_plic_update(SiFivePLICState *plic) for (addrid = 0; addrid < plic->num_addrs; addrid++) { uint32_t hartid = plic->addr_config[addrid].hartid; PLICMode mode = plic->addr_config[addrid].mode; - CPUState *cpu = qemu_get_cpu(hartid); - CPURISCVState *env = cpu ? cpu->env_ptr : NULL; - if (!env) { - continue; - } int level = sifive_plic_irqs_pending(plic, addrid); + switch (mode) { case PLICMode_M: - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(level)); + qemu_set_irq(plic->m_external_irqs[hartid - plic->hartid_base], level); break; case PLICMode_S: - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_SEIP, BOOL_TO_MASK(level)); + qemu_set_irq(plic->s_external_irqs[hartid - plic->hartid_base], level); break; default: break; @@ -456,6 +453,12 @@ static void sifive_plic_realize(DeviceState *dev, Error **errp) sysbus_init_mmio(SYS_BUS_DEVICE(dev), &plic->mmio); qdev_init_gpio_in(dev, sifive_plic_irq_request, plic->num_sources); + plic->s_external_irqs = g_malloc(sizeof(qemu_irq) * plic->num_harts); + qdev_init_gpio_out(dev, plic->s_external_irqs, plic->num_harts); + + plic->m_external_irqs = g_malloc(sizeof(qemu_irq) * plic->num_harts); + qdev_init_gpio_out(dev, plic->m_external_irqs, plic->num_harts); + /* We can't allow the supervisor to control SEIP as this would allow the * supervisor to clear a pending external interrupt which will result in * lost a interrupt in the case a PLIC is attached. The SEIP bit must be @@ -520,6 +523,7 @@ type_init(sifive_plic_register_types) * Create PLIC device. */ DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, + uint32_t num_harts, uint32_t hartid_base, uint32_t num_sources, uint32_t num_priorities, uint32_t priority_base, uint32_t pending_base, uint32_t enable_base, @@ -527,6 +531,8 @@ DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, uint32_t context_stride, uint32_t aperture_size) { DeviceState *dev = qdev_new(TYPE_SIFIVE_PLIC); + int i; + assert(enable_stride == (enable_stride & -enable_stride)); assert(context_stride == (context_stride & -context_stride)); qdev_prop_set_string(dev, "hart-config", hart_config); @@ -542,5 +548,15 @@ DeviceState *sifive_plic_create(hwaddr addr, char *hart_config, qdev_prop_set_uint32(dev, "aperture-size", aperture_size); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + + for (i = 0; i < num_harts; i++) { + CPUState *cpu = qemu_get_cpu(hartid_base + i); + + qdev_connect_gpio_out(dev, i, + qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT)); + qdev_connect_gpio_out(dev, num_harts + i, + qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT)); + } + return dev; } diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c index eb8e79e0a1..eef55f69fd 100644 --- a/hw/riscv/microchip_pfsoc.c +++ b/hw/riscv/microchip_pfsoc.c @@ -274,7 +274,7 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) /* PLIC */ s->plic = sifive_plic_create(memmap[MICROCHIP_PFSOC_PLIC].base, - plic_hart_config, 0, + plic_hart_config, ms->smp.cpus, 0, MICROCHIP_PFSOC_PLIC_NUM_SOURCES, MICROCHIP_PFSOC_PLIC_NUM_PRIORITIES, MICROCHIP_PFSOC_PLIC_PRIORITY_BASE, diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c index 18f70fadaa..09d4e1433e 100644 --- a/hw/riscv/shakti_c.c +++ b/hw/riscv/shakti_c.c @@ -106,13 +106,14 @@ type_init(shakti_c_machine_type_info_register) static void shakti_c_soc_state_realize(DeviceState *dev, Error **errp) { + MachineState *ms = MACHINE(qdev_get_machine()); ShaktiCSoCState *sss = RISCV_SHAKTI_SOC(dev); MemoryRegion *system_memory = get_system_memory(); sysbus_realize(SYS_BUS_DEVICE(&sss->cpus), &error_abort); sss->plic = sifive_plic_create(shakti_c_memmap[SHAKTI_C_PLIC].base, - (char *)SHAKTI_C_PLIC_HART_CONFIG, 0, + (char *)SHAKTI_C_PLIC_HART_CONFIG, ms->smp.cpus, 0, SHAKTI_C_PLIC_NUM_SOURCES, SHAKTI_C_PLIC_NUM_PRIORITIES, SHAKTI_C_PLIC_PRIORITY_BASE, diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c index 5b7b245e1f..04265c5640 100644 --- a/hw/riscv/sifive_e.c +++ b/hw/riscv/sifive_e.c @@ -197,7 +197,7 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp) /* MMIO */ s->plic = sifive_plic_create(memmap[SIFIVE_E_DEV_PLIC].base, - (char *)SIFIVE_E_PLIC_HART_CONFIG, 0, + (char *)SIFIVE_E_PLIC_HART_CONFIG, ms->smp.cpus, 0, SIFIVE_E_PLIC_NUM_SOURCES, SIFIVE_E_PLIC_NUM_PRIORITIES, SIFIVE_E_PLIC_PRIORITY_BASE, diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index 6cc1a62b0f..6766edc1d0 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -832,7 +832,7 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) /* MMIO */ s->plic = sifive_plic_create(memmap[SIFIVE_U_DEV_PLIC].base, - plic_hart_config, 0, + plic_hart_config, ms->smp.cpus, 0, SIFIVE_U_PLIC_NUM_SOURCES, SIFIVE_U_PLIC_NUM_PRIORITIES, SIFIVE_U_PLIC_PRIORITY_BASE, diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 0e55411045..1ecaa0d9b7 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -618,7 +618,7 @@ static void virt_machine_init(MachineState *machine) /* Per-socket PLIC */ s->plic[i] = sifive_plic_create( memmap[VIRT_PLIC].base + i * memmap[VIRT_PLIC].size, - plic_hart_config, base_hartid, + plic_hart_config, hart_count, base_hartid, VIRT_PLIC_NUM_SOURCES, VIRT_PLIC_NUM_PRIORITIES, VIRT_PLIC_PRIORITY_BASE, From patchwork Mon Aug 30 05:35:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 1522241 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=B1omPWuv; dkim=pass (2048-bit key; unprotected) header.d=opensource.wdc.com header.i=@opensource.wdc.com header.a=rsa-sha256 header.s=dkim header.b=CqgYusS8; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gys191Ddnz9s1l for ; Mon, 30 Aug 2021 23:41:33 +1000 (AEST) Received: from localhost ([::1]:51866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mKhXW-00032Z-Vv for incoming@patchwork.ozlabs.org; Mon, 30 Aug 2021 09:41:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZxD-0007G2-VL for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:33 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:42408) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKZxB-0007uV-OP for qemu-devel@nongnu.org; Mon, 30 Aug 2021 01:35:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1630301729; x=1661837729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ElyS80uppEByNcflPyUirCPKW1PNonQqY0PEvynn4tc=; b=B1omPWuv3RUynMhKyVJ/euiWGImlnBxwoGMy17mpV7eQN//XfGbJfgFK R1HTHbLCDOqIMQckYAvKLUeG0B8kv3gMHpY8GBTkNSA7hTRMpL+BSMBlg K7+DJUAaByM7AUmD6k/3am1gGRIIvhqusUVfNj4RgShCQPi3wk6vD2XJD fbacCk53m1bw2nSYQuUh8nNIn4SQoYgylDDJHnhlrMwkFrC8NHnlW57hh /QbcT//IHrQCcF7hpPfCQ00LTXK4/3fdp6nF7O4f1sw2yFDi/vMxq7Gp1 QchGHNxu/rWAUlp/GvqSRGlJEWR9PcUOX653QWFZj906VdqkdB6LQ/IP2 Q==; X-IronPort-AV: E=Sophos;i="5.84,362,1620662400"; d="scan'208";a="178738780" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 30 Aug 2021 13:35:25 +0800 IronPort-SDR: wluNeJ3ZPiHYz2AUVhF1U3EMS5DobNHzMnYGARc8ymj5qm1jFppQvQZ8cAxIxEN5SDkx2+a/bw EVjhv9i/03xZU6oJWAF+9k3FkJbo7aEMfuvXt2VKaps3+JarETZ6JrTCx6hg8MutP5SrIsJ4XF zQpVIGuJDdJWmF6qpZwhxgoDHCbw/Xn8EFuoDuC0/AXSuJJkB8jBI/CNsQS6i1+LtyuHODPcwK La4nahLLhPdIdLm5S2Jbu/GOwqAohxo0EJqCgkaKicBTZFVWBTm5L/rBU7p5125DJFkMrn92Xs YH9IB/4UGIIzru8Il8fr3lxx Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:10:34 -0700 IronPort-SDR: HObKYObfFgd9c/EGH1xrdsbklAwB2TsHzb4oVNYTH5gnvKR2QITO6O30s9m06W1nVRh/+/Hh47 /0Gf0JxACbFEyt32VHuCOe91Ekbg2Ztm1rUng68qjJ+fcwfXVE57RVHWQpOIQkM7mJmVcotK+T JllJCtk4Y0bl4tONuyruFmYjL7BQr9A7kOvaFELxkYWvv4D9AODxF7vcWF2IW9MFCl4cqD5PLQ cMiA1kBvkKwfR2sV3S4KT8CfbuxzrD6WnE+j2c9JiS+H5MpRCfV1upf/N+BGS/WPhv4q8KehGy 3Wo= WDCIronportException: Internal Received: from usg-ed-osssrv.wdc.com ([10.3.10.180]) by uls-op-cesaip02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Aug 2021 22:35:26 -0700 Received: from usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTP id 4GyfDF57X6z1RvlX for ; Sun, 29 Aug 2021 22:35:25 -0700 (PDT) Authentication-Results: usg-ed-osssrv.wdc.com (amavisd-new); dkim=pass reason="pass (just generated, assumed good)" header.d=opensource.wdc.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= opensource.wdc.com; h=content-transfer-encoding:content-type :mime-version:references:in-reply-to:x-mailer:message-id:date :subject:to:from; s=dkim; t=1630301725; x=1632893726; bh=ElyS80u ppEByNcflPyUirCPKW1PNonQqY0PEvynn4tc=; b=CqgYusS8NBz/9jLE2c+viZh CKUuwi416ciqy+nvPXvgFWxNZ/1lOzLfTIrU/tseE4SDU6mpdHRRs61VqNBbJL0+ FTRj5OILMjBVB8QsUMRaYKAevfBOnV+M95Ojl89UpBpxPIQ5UUnML7rKtxK5GGj4 YvtpK1g7kk8PkBzsZjW8MygG8pRQXq202/1JmgqV2faA3IeTCTYGdEdwNeAD4fXu 2paU+66YRg/Be8vaMVOgWNXewupQ5reLAg15RKkL0s/7dJljEjSyoUtivMiouik1 sX5sBuwafaSlroRalKLeiQW1AaG+STR/ErelYIOX9pyDB88I1dyKnFkGYHBtEsA= = X-Virus-Scanned: amavisd-new at usg-ed-osssrv.wdc.com Received: from usg-ed-osssrv.wdc.com ([127.0.0.1]) by usg-ed-osssrv.wdc.com (usg-ed-osssrv.wdc.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id hHIPf9VIw6nh for ; Sun, 29 Aug 2021 22:35:25 -0700 (PDT) Received: from toolbox.alistair23.me (unknown [10.225.165.14]) by usg-ed-osssrv.wdc.com (Postfix) with ESMTPSA id 4GyfD86TSHz1Rvl9; Sun, 29 Aug 2021 22:35:20 -0700 (PDT) From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: bmeng.cn@gmail.com, palmer@dabbelt.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [PATCH v3 5/5] hw/intc: ibex_timer: Convert the timer to use RISC-V CPU GPIO lines Date: Mon, 30 Aug 2021 15:35:15 +1000 Message-Id: <84d5b1d5783d2e79eee69a2f7ac480cc0c070db3.1630301632.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> References: <069d6162f0bc2f4a4f5a44e73f6442b11c703c53.1630301632.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=8697c1236=alistair.francis@opensource.wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 30 Aug 2021 09:40:47 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Alistair Francis Instead of using riscv_cpu_update_mip() let's instead use the new RISC-V CPU GPIO lines to set the timer MIP bits. Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- include/hw/timer/ibex_timer.h | 2 ++ hw/riscv/opentitan.c | 3 +++ hw/timer/ibex_timer.c | 17 ++++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/hw/timer/ibex_timer.h b/include/hw/timer/ibex_timer.h index 6a43537003..b6f69b38ee 100644 --- a/include/hw/timer/ibex_timer.h +++ b/include/hw/timer/ibex_timer.h @@ -48,5 +48,7 @@ struct IbexTimerState { uint32_t timebase_freq; qemu_irq irq; + + qemu_irq m_timer_irq; }; #endif /* HW_IBEX_TIMER_H */ diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index 048aced0ec..f7cfcf1c3a 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -183,6 +183,9 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer), 0, qdev_get_gpio_in(DEVICE(&s->plic), IBEX_TIMER_TIMEREXPIRED0_0)); + qdev_connect_gpio_out(DEVICE(&s->timer), 0, + qdev_get_gpio_in(DEVICE(qemu_get_cpu(0)), + IRQ_M_TIMER)); create_unimplemented_device("riscv.lowrisc.ibex.gpio", memmap[IBEX_DEV_GPIO].base, memmap[IBEX_DEV_GPIO].size); diff --git a/hw/timer/ibex_timer.c b/hw/timer/ibex_timer.c index 5befb53506..66e1f8e48c 100644 --- a/hw/timer/ibex_timer.c +++ b/hw/timer/ibex_timer.c @@ -77,7 +77,7 @@ static void ibex_timer_update_irqs(IbexTimerState *s) /* * If the mtimecmp was in the past raise the interrupt now. */ - riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(1)); + qemu_irq_raise(s->m_timer_irq); if (s->timer_intr_enable & R_INTR_ENABLE_IE_0_MASK) { s->timer_intr_state |= R_INTR_STATE_IS_0_MASK; qemu_set_irq(s->irq, true); @@ -86,7 +86,7 @@ static void ibex_timer_update_irqs(IbexTimerState *s) } /* Setup a timer to trigger the interrupt in the future */ - riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(0)); + qemu_irq_lower(s->m_timer_irq); qemu_set_irq(s->irq, false); diff = cpu->env.timecmp - now; @@ -106,10 +106,8 @@ static void ibex_timer_update_irqs(IbexTimerState *s) static void ibex_timer_cb(void *opaque) { IbexTimerState *s = opaque; - CPUState *cs = qemu_get_cpu(0); - RISCVCPU *cpu = RISCV_CPU(cs); - riscv_cpu_update_mip(cpu, MIP_MTIP, BOOL_TO_MASK(1)); + qemu_irq_raise(s->m_timer_irq); if (s->timer_intr_enable & R_INTR_ENABLE_IE_0_MASK) { s->timer_intr_state |= R_INTR_STATE_IS_0_MASK; qemu_set_irq(s->irq, true); @@ -280,12 +278,21 @@ static void ibex_timer_init(Object *obj) sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); } +static void ibex_timer_realize(DeviceState *dev, Error **errp) +{ + IbexTimerState *s = IBEX_TIMER(dev); + + qdev_init_gpio_out(dev, &s->m_timer_irq, 1); +} + + static void ibex_timer_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); dc->reset = ibex_timer_reset; dc->vmsd = &vmstate_ibex_timer; + dc->realize = ibex_timer_realize; device_class_set_props(dc, ibex_timer_properties); }