From patchwork Wed Jul 14 07:24:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12376189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EB84C07E9A for ; Wed, 14 Jul 2021 07:26:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id EB29B61358 for ; Wed, 14 Jul 2021 07:26:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB29B61358 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ZHj-0005pC-V1 for qemu-devel@archiver.kernel.org; Wed, 14 Jul 2021 03:26:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZG9-000485-8o; Wed, 14 Jul 2021 03:24:45 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:58273) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZG7-0007Ds-GJ; Wed, 14 Jul 2021 03:24:45 -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=1626247485; x=1657783485; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gmMBtGIjVwB2suosvF2nd4pSPHvP9RnihxqAwIoab2c=; b=OujZt4jATRi55IfskFfPxONQ5oR4gBIvqNVEvU0c2/v+tIO3SP5ZkhtT oexap3fdHa6n6DOwNSjx8HTbL6y8s+eYhUlqI8EfUa1PCGnOETQm7It1s CoNYEuSlQWSsmdwx1m0CN5x4OL50zff5EFBO1XM5lGOlYJ10326jFfSfj BSCR7JXxw1sA2gDujfVCz1kw7vOFRMhgGp2AmP9bfrnccgJJ2qfQH/ufq m4DZrm1YHUOxVC4FgM5RM1lUujS8ABqgL3DHoD4AExwh9FXiiEW6PmDTX 3u+MfvOsym3opUz18gbptyROw6JkVWTtDX6Dps3yhb6B0y1HtRThWvXaC A==; IronPort-SDR: MrbZRiYCFBxMS+fNJqkvvTK2JOFrs6SNBVvbsU/qFEUbgLGrSRUiE5PLbELZF6E6xBbCZRb0rQ kZS7lsvd0IJF05AcB2xRmtmy0UsJNjfWW0nRyLfD3idPNBc4xXfkIn0aA4phAf7TxvjSv1GweH //hvE7wmT7xzQ2K4iE/VMUJApdipu9OzC4/AOKTyrnlzK1MoRJjAMWOiwm1MrNGH0aBXaBb5Mn OF7pYfkqIcNuzum8PqUA72wdywWiuhjtT2+KL9LwN6FoukrcRRLSU22sWdHxsa2qXnRDcgltf+ VZ0= X-IronPort-AV: E=Sophos;i="5.84,238,1620662400"; d="scan'208";a="278349785" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Jul 2021 15:24:42 +0800 IronPort-SDR: 63PEp4FKUBkrpFmcfVwvDMyCAHI5PjQcKPYBygtKNvqYbpVx6E2mJqyT0ZzjxI0A0KGzievOKI YlMQYoGBtW0nv5K5YWFFe6KkmZ91GoXhkFHt3fdT3oY9el/7CdEPbbdOwaJ5aQKALpganu9oif tRLHrmkI8cuFq1H5HZODe3vpNhk/W5hpxHUvqjovCrBGUS1BdHLLwGyQ+nO89o1MzjhUSdmj3x bGfNiHxqQZL/LBD+sMwflnRTXVyj2+P3nA0EjXf+D9dez73UNg/xPYvCHtTyv/rfj6WbuxA52b 1Vxh+6+kWho7A+LjoKpryXhG Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 00:02:45 -0700 IronPort-SDR: SqrlCQPxhehDn/nZXmOI8/3r5dTV3uOAKOxkvbJT/Xne4lqPRxP/HqD1l8GO6ZOC7tLk2iUcJQ JD7H0/+lr1NVqJ++D7PHnfDYn+Ec700xeb6kFfWkViw/8hGg4yWFGNjYM4i0sHpcZcW2f4/aJm Le74ePaas33PQiFg3zBXt9i503Btzx14l4EuIKfHmTA1CGJfb1Q+otbLs2npZCutOQaw5vr9wx H42AZKc2zeborqqz01yKJCmX7nqcxl8pa+s+xmWiRc76+Ln3qLbfk/ajoZUQgQ+yHlDmFF/g/v 5vA= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.112]) by uls-op-cesaip01.wdc.com with ESMTP; 14 Jul 2021 00:24:38 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 1/5] target/riscv: Expose interrupt pending bits as GPIO lines Date: Wed, 14 Jul 2021 17:24:34 +1000 Message-Id: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=8220343f1=alistair.francis@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-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: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Wed Jul 14 07:24:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12376191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBB5AC07E9A for ; Wed, 14 Jul 2021 07:26:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7D40661358 for ; Wed, 14 Jul 2021 07:26:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7D40661358 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ZI3-0006UU-JF for qemu-devel@archiver.kernel.org; Wed, 14 Jul 2021 03:26:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39900) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGI-0004PJ-Qe; Wed, 14 Jul 2021 03:24:54 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:37162) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGG-0007LD-Gi; Wed, 14 Jul 2021 03:24:54 -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=1626247492; x=1657783492; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VjHj56vum6MlPtczkLtNzIuDgo2GZwTmgWkz10TT0cQ=; b=QpEFq5XuEmJ1ujcTE8J94GNCBQiHcNx+jpw/+32Vx0FrarY7UiZJMjZz cNHH4OyOS4PAdILtDLwnRfkaR6xL7I9PBKDqnNCzNlX1w2WO5D5VU6B+a Tt4O7aFvwcEvqFeTHMKMP4puIZ9xDPYOLzFFoEIWwGH6uby5oyKk1xLKf Yo6MD0y3MCUL88bd9pMMqVWv9CmDw0gQW2Csuc538ydzCCaoyX7zaWG4c fMmEDKrEgKBCxItvncxVgvPyJbofAQpsEMV+tBryY1VIUVrJSyLLd3zNT ac433N1+4sWVZzaDHux/kan8sGJvBA+ap5FU5xjxHPWcEukRHzE8NtI2N w==; IronPort-SDR: 2Tssb2Fy8R671PaBSBDG4HXIye25w7v138Rh6tnzI+16WOd/lWXwUThAsx+7E/2W6foHypN7PA VE/xilWfSq/aA0X/2KhEheUYv8/STCIZrt7pFAUmMKBY9XDepWQMaXKW4lNdwSjbG9aqKFxB6w xu8qLrRaRFIXAXkCR5ObvOKhIpK00N63FDjA0lSKDXt+igplxyvv3izugLuWfVvN60O9wQrZ/S 2v64wbktaaqMTPahF8XlOhMCRlD68qjYYlMeP47Qa0et1BIDoJCDRr0PrBRyHt/zIWR8Aybsoi LVU= X-IronPort-AV: E=Sophos;i="5.84,238,1620662400"; d="scan'208";a="286068373" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Jul 2021 15:24:50 +0800 IronPort-SDR: By4zLhbsPHXP+BdvXbVi4AD98KaWhYBFmQD8s6JvIsJ7LMYyQkiQUhbPQD7hCf+K8xVFFJCp1J 7VMIlOtJN4tmznfQwAGmx9Dsma8ogO6Hj4eepDx0EuQnF3E39DlP5ngZiHtaFzCF6AWob5gr1b wbV1QFotmpwEwTPr/NVQZl1VypFi/mt4ibutFmn3mEill3Qds7OJTlWWQtTAkEs6z0PlGtO2/o rJIeaX8ZUs9+VnPaCVLDZ2zNCOpG5SwECylq/+7VG2RWbbd4XfnZaxH7sxy3nDrVE7/IWtoBek o1/P2iJbdLltqLdmb9FXZyqX 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; 14 Jul 2021 00:02:54 -0700 IronPort-SDR: CmiR/4B7tWVU9vVoyLWAHkbHwxnnmVxeKx/rhM2KfYZDqNAS/cNKPSG5YOih4ypBHwrn5y/wZz Ybgk8dqhbNsbnIeqEXa8p4qJCzI3n/CpNMrKBNkcVZNVvc8sydoOQA7jBI7MhUM7gIJXzeY69T Z/ygLqTks+qdxoDs4UjT9ZwSI2DLhjTKaMxCvVOZnXPcXQPKq9aTfPv4VxcJceH6wkyb7YiQTg qbQisLtHLuZuOGcWptb+imuXo5DDLhGVGPDMDbafSnUH+UEo+FR0+GvQAB4SvnqJ10pnk3h1f1 mcc= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.112]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Jul 2021 00:24:46 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 2/5] hw/intc: sifive_clint: Use RISC-V CPU GPIO lines Date: Wed, 14 Jul 2021 17:24:44 +1000 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> References: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=8220343f1=alistair.francis@wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) 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-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: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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..8a460fdf00 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_named(dev, NULL, i, + qdev_get_gpio_in(DEVICE(rvcpu), IRQ_M_TIMER)); + qdev_connect_gpio_out_named(dev, NULL, 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 Wed Jul 14 07:24:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12376197 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC5CDC07E9A for ; Wed, 14 Jul 2021 07:29:24 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 60D2E61279 for ; Wed, 14 Jul 2021 07:29:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60D2E61279 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ZKd-0002Ff-HD for qemu-devel@archiver.kernel.org; Wed, 14 Jul 2021 03:29:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGR-0004lo-Ui; Wed, 14 Jul 2021 03:25:03 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:17853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGQ-0007Sz-2r; Wed, 14 Jul 2021 03:25:03 -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=1626247501; x=1657783501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sPgmD1iNk+4mYxbFxG6vLhOE/fB/e/hVYChjwyzM0mI=; b=Wc71Tun2BTxEBdWHnA3Lk0NzobMUq7wR+hHoO/i8g6OcLIG7jiqsLPOC vUTm48xqGV9DtzZClHqpxyJnOol07GZVfmMuOn8oG8i6yMnn55XiUAdaI k0PfV2UfQrqd5wwzcdqa/fgiq+WaXeD02PHjeiIQbk8uu/OpmIwl6I/rx PoXhMezqwoHiPe4fWEzin0CAGn+y6hdy3pNtmXuaaY9lBn4gCnp/sXf3u /5w9c8EZ5B7nW7yTIqc2BOGVpqgYJxbI/QSYMby7+OZ8NW/j+kpJpyZ8k BDMVWgy4dkvASKavW80KKm2iIPGSRyg2VxFMaX2pzxzWKPO3qwYvxOfJo g==; IronPort-SDR: CkJHCVWMDxLSxEvatw5yE2C+ueiwsjEgxpWpGYLqbmNBdK+1dxDE2pPvkZyobGtrkaAr/pWPDi Y4/S3g8SzWWvcvJsyk13TBGgMk9SB6AvmPI3gp9fVTTgePxASXCn76FitfmObLzoioRZccM24T GM+WIcL3Ozf9KqFqsA+bWZ/y3vozEKH3PPhA2X8UrUsAbfUBaVpSz1s7QXHNxeXcdQt7HzA0o7 JNzoBEzEVuehSnASjJrki3/1ZDfuepGUPpttJCuEuf8D8MjTcLtgrxnL0cVaY3L4bDh7Efe76j Y/Q= X-IronPort-AV: E=Sophos;i="5.84,238,1620662400"; d="scan'208";a="174533784" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 14 Jul 2021 15:24:58 +0800 IronPort-SDR: YyF4VFO5wSV+pX5ItpUbWhNF9bjsr3kHQfdIDUUThyKlYO1NYFZasFRVExJuhixCfC/PwQ1/+6 heorWWiB8XyO5jM2OYl4UMelW7h4zZd0v2IFyF6kOycsB+8ryEnZ7RlobEGrGcJxtiH4k0oC/o PUUTHmZbvY5QizbmHjd4t4Xf2PY7TrbGBwz8xgmIRC1zJJZgvIJDlPuzkSzC26iJewbJH6DJfa iOJl8ZTHsAsbAopgwxfHY7O89l4ANZEnFt7KQTPrPIRovbsy0hLhEt5NIJAr7YRsvhwqbqwf0V M8wH1LeqmdcfDb6crDjq6MVZ Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 00:01:42 -0700 IronPort-SDR: SW1PtH5lmUuY2/chUUc2rYur3Zhlshizynl7U4jtAlnuu1uvxv7s3LR/VwZLlVmsnyEit0C6Bp u+n8dSD9yeTMHJo5zAdQFXxuTt5vyhjlrFL6NYZssd8gQBlvavo90U9AD3ztbj7dvE0BIJC+dB wMUzwzityH4Krqw4pTYNNBBtayy6pHDBuq4An16PBYMtMDjhcnOL5QYkX2lRhLmiXYxtB25Ng8 vqSVR9CZoLuzFOajLQWTkppFlZIwjjBZb9JiJ06O4ucXqoCG3kCtM4896NG3/O267nvdjsF0N/ XIU= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.112]) by uls-op-cesaip01.wdc.com with ESMTP; 14 Jul 2021 00:24:55 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 3/5] hw/intc: ibex_plic: Convert the PLIC to use RISC-V CPU GPIO lines Date: Wed, 14 Jul 2021 17:24:53 +1000 Message-Id: <569c788eabb3729d561635f17a03fc21d4effc8b.1626247467.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> References: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=8220343f1=alistair.francis@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=ham autolearn_force=no X-Spam_action: no action 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: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 c5a7e3bacb..88a0200972 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -116,6 +116,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); @@ -142,6 +143,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_named(DEVICE(&s->plic), NULL, 0, + 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 Wed Jul 14 07:25: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: 12376199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 919B1C07E9A for ; Wed, 14 Jul 2021 07:31:30 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 363576128B for ; Wed, 14 Jul 2021 07:31:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 363576128B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ZMf-0005Jt-E4 for qemu-devel@archiver.kernel.org; Wed, 14 Jul 2021 03:31:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGZ-0004yH-WA; Wed, 14 Jul 2021 03:25:14 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:58315) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGX-0007Y4-Ou; Wed, 14 Jul 2021 03:25:11 -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=1626247518; x=1657783518; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UthoiwzbLQtBUVh9bXNXc+4p1ASTcTxTmBlt/hjknT8=; b=YAZ33gZdBlVCtFYb5Yn3SAxZXDRGowFrDxelE/UP9Kubdz9M7iCiXvhC yIw6jx/eiUxrwbL0T5ehv486vU9YaFH/LrN9XZT7xzZ5ZVH8NiRsF5O5W ttyRAiRt2xjM77D/PocOOJ2UIEa4m63tLS1d3couD/a8f8KPTzQR8AAKd SQzyAzJy48EQ3A5F2JYhOug8Wc3VbOgKCLjIOOvrq8soQ1ni+WmjqEjjO nVJvRCmKDJZG+2jn4IPaLnySwQRNOFIQAAmoKnMp9cIbCA4ATv3Ne2jvG yYS+MfrqE5Ik0cRr1RfxjiHfmGdfmTJi11ukRHcFwmDZ8Gtd5SrMCz/c8 A==; IronPort-SDR: A0CIsQuwr9ZCXsxQBO55SffbD6XSQiAosKc/ikIUBoSjKBBnNC1X6EodTx4R3ty1Iw4vjmcHgu txwg+6YommBD3Sn7jzCvPsKTsK2SXdJBIWt5T+6fdflFZXtqmM36mclkQ8fXIOW89lHMwmiUwO 2PFeNi3dm390Kfyrg73vkEL/yQania/MaCMUZG97TlH2yU3VZcLlC3IFNO9PElHKYAvwXk5NHr mKLjIgqc7dE9SDijBOtYo2T6krPy53M/6SmQPN1nd8VnTUgff5lLxLUKWXqBdEIh5BsmOLrHDJ Yyw= X-IronPort-AV: E=Sophos;i="5.84,238,1620662400"; d="scan'208";a="278349828" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 14 Jul 2021 15:25:16 +0800 IronPort-SDR: iprGFcreH4H/BMhQZRv2JJsZDNB2idI1C2DMkQMYiKaDeZReZ//zIW5GgeHQN/Sjuh4uYmzc0m aa8IS3WCFmUvThtPLH8XmgIDCsG3frmwrkNPP8PFGAoy4EhwioMnFwttlBIQbWjdYVlMle6cbB L98Or8ii2qTDQSTwxv30Of371lnQBBdI6W5jvGEwByXOZ3WhhFMfn/5NjTME9WFDd+A0suQw9Y 8ogGgOmhRjHClKPb/lSRFy5eXm/J0sPKI0bCQJjPyfk45D+bV7ZXdBR9M4ElcmloaT/2IUJAyY TmkkU3Y+4UN6kL937CwhWwTB 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; 14 Jul 2021 00:03:12 -0700 IronPort-SDR: Zr0F2Qbl7WNa+MKXcpHij7oiDnQAo1M8YEmBGuMy9eqY9E7ek2AG8qDS/MUtzdWKQbLmLNCwde qLV42dkfyKu9+YPYAAAKuFdwXJ3aFZspx3nz97ZZ4vhL2pWlfvtnaMYc5d96v3r8gML6BC/LGH BLk6I5sjEl553QoEu/oDb4D1455g8i+jufMRsxoAQE9wVvqRp94CaANZ7d8aF8gXfsjRMPwMP3 jWogErxzPolSePYt7XnxZg4ReGbDqgSMEhq4AzDUBqtp6BjLTvIf6saGiYxbLgMjPOGcgBss4b bYA= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.112]) by uls-op-cesaip02.wdc.com with ESMTP; 14 Jul 2021 00:25:04 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 4/5] hw/intc: sifive_plic: Convert the PLIC to use RISC-V CPU GPIO lines Date: Wed, 14 Jul 2021 17:25:02 +1000 Message-Id: <389a6f1d9b73c6a8ee7c2e62c8324ee0dc135302.1626247467.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> References: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=8220343f1=alistair.francis@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-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: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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..da1dc64c6d 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 *s_external_irqs; + qemu_irq *m_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..7a795f0a61 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_named(dev, NULL, i, + qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT)); + qdev_connect_gpio_out_named(dev, NULL, 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 ddc658c8d6..03bff21527 100644 --- a/hw/riscv/sifive_e.c +++ b/hw/riscv/sifive_e.c @@ -198,7 +198,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 273c86418c..6d1f9464c2 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -829,7 +829,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 4a3cd2599a..4db40bacae 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -619,7 +619,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 Wed Jul 14 07:25:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12376195 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8E56C07E9A for ; Wed, 14 Jul 2021 07:28:59 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6B9D161279 for ; Wed, 14 Jul 2021 07:28:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B9D161279 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3ZKE-0001pO-Cn for qemu-devel@archiver.kernel.org; Wed, 14 Jul 2021 03:28:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGi-00054o-Vo; Wed, 14 Jul 2021 03:25:21 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:61797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3ZGg-0007eb-Sk; Wed, 14 Jul 2021 03:25:20 -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=1626247517; x=1657783517; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aK5q1LfWMp0Zj3X51JFq8pt1YpO/bfu94V3Z/HHoSvI=; b=G9/SoyboF7MvvF5rPbjzhOrgoJz+q7ADwgzkzpGKKpqVza9fvm9xGnM4 3I5jDfxkopZqTd5BVVv2SoBMWXDsxebiCCTA7jfoiUUbt9PaOHi1hQSMN vV55POg7so73Rpl5kvhpgVFj0P6456wKy38RBi10ljebYnANaO+vvGdmO 3GEctxy2uPDFTClGaxUgqY+dFd6UkDzGpB5+pFr2ITTaEd3pV5UbF1LDk 2uHoKNaT1F80kkPnAXs8eX1PJfO33GMRgN7CO3jixCNboJEkRZ2Nn3kCy EIUOziFMKwRtVL6C/y1ACwwTbObuNRZxHqy/ijVKSur/waoRr/VeRwNTq w==; IronPort-SDR: KP/SBNPBVtHld5ySvdXn1BuslhBUJ+LOXOPUMU3RgLRfLcHp1vYOjzTJOwVRqddFpzFqI3AI3n eYYKU7eRRmiL9CZr+lLcFEVKy+lscKY1rwOsw6JGBcn9u2HdKYuLe2kwwM6LkHOvBFUHiDqNC4 PPDRZjIZE3rI292gpniTb9i6lGQMb95GyOmdlpiaoclhYWfSzmbj8YYQur7djgcmyClj+t5k2Y dBvsKK+vG3255BDd0efC7X1klToAOjEL05nWj5RF5ffOvJRa6LGZuL3MnqInMTh2yV6dXu6K4H F6s= X-IronPort-AV: E=Sophos;i="5.84,238,1620662400"; d="scan'208";a="179344528" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 14 Jul 2021 15:25:15 +0800 IronPort-SDR: /m2P4vKkH6K81q7QRVeHJV5qWbdyy4ml3UmYMfgXDnb9UM/LrPiyUex23NS+LHARcJj62PkagW mmR3Kx0krc7NG+Y4W+FbUAJ4YkutkUDVCQ9gQttNFxeXh/H2heNodGulEAPXtx5NVQ549KuhkL azM/AamOTK/1lb0PqjD5xPYRJLUIJzplrFmrVVMW5Qyevnp6Lx1XsDxnCRE9ywujhRy15BKEBV XnXbBJnsM7Sze/5wWwEXxd3Hwh1zbxIlDe6ffQTGPbM6EqZe/s2d/NLhPIfcj14PanQcClG4V2 30iAFMUrsvKQQaCStBx23biB Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2021 00:01:59 -0700 IronPort-SDR: 7jT0YsNB27Vu9jALH7fWStT7SujC0L7pjqr3+Fx5yHPj/5mlK6um4xRfvC9L2IMqPeOeJMYCaF jhL2qOftSdj6Y2QDPZiQwNAbkvd92cm+2J4ycjYfWzH3iR85F/ZyxRmY1Bbf4VUOOB1pW2r7so GfJULDht792Sc0WWklXJtJdsOKkqCRlEDXXuicYqHEysG7V7FRkDM7MceH46RpQ8WlTyAkdeLH +rJeKl3FshAbtA/FHhSBDkyk5V5s+W8jhpW3OweVybq/zn88QkrJRdy7aep1vhETYjarG+5Tn9 WKY= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.112]) by uls-op-cesaip01.wdc.com with ESMTP; 14 Jul 2021 00:25:13 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 5/5] hw/intc: ibex_timer: Convert the timer to use RISC-V CPU GPIO lines Date: Wed, 14 Jul 2021 17:25:11 +1000 Message-Id: <78eb66f16d6096a60479759e2c1deb524c39757e.1626247467.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> References: <5ebc64a6885af5cc3812beb71621cb7615556a1e.1626247467.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=8220343f1=alistair.francis@wdc.com; helo=esa3.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-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: , Cc: alistair.francis@wdc.com, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 88a0200972..fb0750c16f 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -176,6 +176,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_named(DEVICE(&s->timer), NULL, 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); }