From patchwork Fri Jul 9 03:30:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12366579 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.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,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 6487CC07E99 for ; Fri, 9 Jul 2021 03:32:41 +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 B95A061439 for ; Fri, 9 Jul 2021 03:32:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B95A061439 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]:56854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1hFn-0000Ie-GF for qemu-devel@archiver.kernel.org; Thu, 08 Jul 2021 23:32:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEK-0006HQ-ET; Thu, 08 Jul 2021 23:31:08 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:23409) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEE-0006R9-02; Thu, 08 Jul 2021 23:31:08 -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=1625801461; x=1657337461; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=FGftd06KQUZ7tDQ5OGzIJ1X9u0u0bQAockp3XcvLTxU=; b=gkfQhiFZXLXL49BLAwz6cQvvj5l3DEZP1a8mLWfKDpIkpgbxVKVL+gpi 1LSQeCMvN1Oe0lDbNITf+D3cNvBGZyL36WfUoOYWo3cKfViF0P7bzs4wS U9lsd31J8+N/nOYiwbfBr8MTeeR1nHtpijjPVuILencMtpaoOceAnFb+3 06FWOcF9l7z8iIYKyxck+d2FpoLZ66PGWhdJfGLAdegJJ45eqeUR47xtD 9voBgxDbZZ+SE10emNVpa5BdWCPIaR5pk8JM1ivTno+mMm6IDW4so8sc7 EEI+CNLs4cd3t5yMeVERycvKS8FO1Du9Wi6tlb8qRj62/s5x0ThO4bAwt g==; IronPort-SDR: /W2okUXLjoRwCiyaLlB591g9cJ4sePw48O/qCThKGv44xAUiSYn+ZfQxAQvhzTl8747Ew3pcat fH6emdp4waqk8sLs7637j8ig7KFz620h5XM/qhEW/CSLnw8+lNEhA31my9pOhidbmUjeyXfZ/G hlUIeofQdSQamRkZcXhUMPgenIg1lTcVGHO4hSgdkzTLIiRmP02wufqA819e2KHSIC1O2lBX5v tvuK+9FgRwYgcPtvgjDIQmoFNbWbxL1SDVhX/2eztb9pnWdlVKhXE4Z+v0MAQC2DWCHfIhUtpV Ang= X-IronPort-AV: E=Sophos;i="5.84,225,1620662400"; d="scan'208";a="285648619" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Jul 2021 11:30:55 +0800 IronPort-SDR: oVPcahEAOFREzQ3uaxnhm09R2DnRKVwAa70FRfsluCl0nJ46EKdiTN2SnMy9uoacYxP+zkQyft cptLvBLPtCJzPbTmt57IRYbkNYoiTWjKEjCdymMvvqyYnXXT7B/G7ZEice44NYI5QjAeOD/QCX VDupBAPyC5eLapOoo+mxGyd2oC0dIo2Wydi/qX3JJMFdWwvlLAOEFc3oyqHTJEsQtX8+XYWPZL SExYNHRdeXUfKXqyzIAW3Vn9G1/G98aOI74c3DRX1sqYYm/ayKPrYbiAtYjb47rHM911RjA9k1 t6JrsajjBKHFvaUb1QjtM+JH 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; 08 Jul 2021 20:07:53 -0700 IronPort-SDR: O6zxN4L7z/gW8LFnjvYIoqgvYDnoTZ9cjepdq8DtkCS4B42lP3oW08/9JFN8PJHVskDkcPH/iZ NdlgE1M6Fq55yZL8onJP8MG9sPbMubJfXRno7PC96WK0vM4aNQsYdhBM3xSslUo9X2nWpw++nx i0kStOtWLy5Oi3wdFrfh9qe4/b8IHI6ibkSALYiLPHdSfDWNGyQbybV1ZOmYc4aVzn4Jny0QMS vxM78mYvX5D6f1jyO5CWc5Ln06diwRNC2A3966YsWzTv6RGagbRW1Qy2Cn1HQH7SXeYCUnBTe3 bCE= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.107]) by uls-op-cesaip01.wdc.com with ESMTP; 08 Jul 2021 20:30:51 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v1 1/5] target/riscv: Expose interrupt pending bits as GPIO lines Date: Fri, 9 Jul 2021 13:30:48 +1000 Message-Id: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.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=81790befc=alistair.francis@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-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 --- 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 Fri Jul 9 03:30:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12366581 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=-14.0 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, 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 E9624C07E99 for ; Fri, 9 Jul 2021 03:32:48 +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 889C36142B for ; Fri, 9 Jul 2021 03:32:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 889C36142B 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]:57082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1hFv-0000SO-LD for qemu-devel@archiver.kernel.org; Thu, 08 Jul 2021 23:32:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEP-0006Yg-2k; Thu, 08 Jul 2021 23:31:13 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:57105) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEJ-0006UJ-4Y; Thu, 08 Jul 2021 23:31:12 -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=1625801470; x=1657337470; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/Gw9STos6NBwpuzBXsW+NGiKKxmORegyUdoxl6UtuGM=; b=oXtJsw5NHYky4tpsZdAfimVmjvPo81h6usYyZnCv50kFPgzmeGPtbnSF 6Mx3TZuFAq++l+9hj0h4FKcjfD/ZXtsdFXhglGXuKhZALXh+/zHT+RYzW MBWQQWbdTyk/rllZozWDN/XnxvyKhsxDnvGElijdgqShQaheMoU+evw6q Ob3pXTlmwYqbjmsmmZ6va4xRe2F9ea0Q8o5pT11XLSw9zWyInjdpWNrXn t8tEwIWJEyIhGYCeYZbQKexsn8sI1jjvyvCY0CmXDls1FUFtyBBxBfvud rplAPuQZU8dKOVcdk3y5AhySv0QZYBy512ij313aAQjloD/XXiNMXhIi6 A==; IronPort-SDR: mDcTQxHF40eXpOwM1BM2oipQgTlF0K1GakG/vcR2WomdcNZzD7h3zyHc2Iv+mdGEAl+SwvYL6p kEl2Otd/DzARBxumdI0OXweDqpfNjqedya53DupzvZpantmHGwPMbMWoamiphzWFC2n8zu624N /Ezdwkd0nZuEZlFKq4HdJXCSMvGUs1S1bDNLE50rpe5ITL2x99EX+0EWOmp2dt9EMy5NVvYqRe beKj5MDvwB/PgOEU8WrKYq4ZcYJjR8DqxerLwU/TEJga69L8x5FCQHoBOuf4mVY9Z64zK6lafj 6zs= X-IronPort-AV: E=Sophos;i="5.84,225,1620662400"; d="scan'208";a="277931119" 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; 09 Jul 2021 11:31:07 +0800 IronPort-SDR: 3adyX6TQx2BmJkknMrN0ssmhtMAE5TZnBYxNQ7TyspXlHfHsxiWlNYYUg1s//H7jCHC3xXIVBb WbPJwlIjLiOxbxW+vGx0ULuzo6B7glVkQNEoNyAC9RYRtTkofQ8M08crsuROSb8juIxzP49gZj ksxktRyeW8pINY/viXSfRP2cXtnuyVSIHyaWebfP69nA/pS55MbKnEBmgFCmVB3q6GB6jBI2za lXWrMqaxC/s2joc9c0BcSZMKYNnWZXjiEVs79gPL+o3HBIOAAW8rUgSMiT5AWO6Idb4JWVOnnC lNye8kKsG6J+nGvmYkOy5eG/ 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; 08 Jul 2021 20:08:03 -0700 IronPort-SDR: Eix23Zdt+n5gt6kQTRc6+KREs8Lw4RS5LSk+nEwrOOq+HoJQgvG7A2rlVur5gXK8hMO+K1vImX ruS5Di85gRlBYEtuudXp16mrBx1OKGbWR5LBrMVArtOyiceZ7XNA5JOJ9aWepwfovOJuiPaSos pTqi6ZVK+Aud9JwluXK8uqdnYWD/kKidi/3gYTlPqJvXErHohDDcJcq5VLsaOZnJnxi9eXktW5 gOvZalaYfvvVVWgTSO8Ni0pARcGgZwqJ0AP9/XqGhW2KAoYRnxKLDJTDsDbIH1G/IRE7rGHSnS YVA= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.107]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jul 2021 20:31:01 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v1 2/5] hw/intc: sifive_clint: Use RISC-V CPU GPIO lines Date: Fri, 9 Jul 2021 13:30:59 +1000 Message-Id: <3a9be7f66702c6fb18ab09ad9db0fdd50b1a7df6.1625801410.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> References: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=81790befc=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 timer and soft MIP bits. Signed-off-by: Alistair Francis --- include/hw/intc/sifive_clint.h | 2 + hw/intc/sifive_clint.c | 72 ++++++++++++++++++++++++---------- 2 files changed, 54 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..c635a47507 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]); 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]); 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,11 @@ 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)); + if (value) { + qemu_irq_raise(clint->soft_irqs[hartid]); + } else { + qemu_irq_lower(clint->soft_irqs[hartid]); + } } else { error_report("clint: invalid sip write: %08x", (uint32_t)addr); } @@ -153,13 +166,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 +218,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 +247,6 @@ static void sifive_clint_register_types(void) type_init(sifive_clint_register_types) - /* * Create CLINT device. */ @@ -238,29 +256,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 Fri Jul 9 03:31:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12366585 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.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,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 0DEE9C07E99 for ; Fri, 9 Jul 2021 03:34:14 +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 9AB2D6142B for ; Fri, 9 Jul 2021 03:34:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9AB2D6142B 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]:33984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1hHI-0003pH-JO for qemu-devel@archiver.kernel.org; Thu, 08 Jul 2021 23:34:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEU-0006z3-Rs; Thu, 08 Jul 2021 23:31:18 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:30630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hES-0006YC-Jr; Thu, 08 Jul 2021 23:31:18 -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=1625801476; x=1657337476; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6c/KZWs3N+qXZkARwm1MYqVBGr2JMpddi+z+do71ivk=; b=JXpAP0tYLxpmT4d4toZcfDVsszRWBw8b97gB+H2MW6sE+l3Kft51RBv6 0OlgFL/amTKWuQoTNCDSix6RTD1cKJa7iPrOsd58mocmIlxG320TjXdNg eHi2v7759zANgJJrGGHaNM1Yi4GHdrsh5kiigk5AZ5Cb1oBISwVyVGw/w lGBLX7xRaOmN+5wvUOqgZszldIDMBfOzTUgn7VPplHmktOM/TsQWKEOrN 0JMy9tjq78qhDObOtQLpNmOQLslbFmxiYcKpuHc4ZvK5SuNdvy2vMH5ei IVed7san3AkUAFmlPBrpK8K43iMVcmHcHgz4xddN6wk/ZHf41dZjzVssm w==; IronPort-SDR: BTowxxGPGUiO395tujgXYEehguwKPwCHWHABBfBmEEu7I5tzr98N3zJy3C2u7MrKv9cgQ62zuc uxts308YO1+XJ03jSCuPeoxVgORXEL3q5b2C0f7vrmDlo4UHF4+93wyrBL/KHvjLqdFwa9VAeQ qsQ9q9TABtkUR3kzbO4JaEc71tfJRREWxHb2FI5x9kRV304RHFTrwDEt98BHglWNtAoWxTOKyb qwzs3y/QX/wOREoXFYmSYa7LCyQOrchqnvKkNM7YE2y752yEk3pnB6eCOfM0+AIOIcQZpl7UuZ PLM= X-IronPort-AV: E=Sophos;i="5.84,225,1620662400"; d="scan'208";a="173363596" 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; 09 Jul 2021 11:31:14 +0800 IronPort-SDR: Ig2ScRhWhkONe3C35jk6p6tNc0KWwal/3PvFYtclwMem/OnUY9NBhMnHigReMjAO+G12D1t3c6 rJdptd/ur5XNQiUpSh7iiYqu+AGi38A/5PVoKhVntbzOlGXhPYybjZkVTKQ9LJPPKGv/H3n6BQ S02QEZ4PFgIUCBY8zNwmO7XBPiSY7P7az7iecLtmqH6awKl21MP9YffX+/6GQSwiqfRxTcTyc1 jgZy+QLoqvCXsPPBmbtS1Ofk2gvE6KKwg8r4hWngyRdR/xCPNvm7fPDHFuV7BmKw3L3uJKz0tW Eyo6awOwjP7WmxkEoj9d4+BZ 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; 08 Jul 2021 20:08:12 -0700 IronPort-SDR: HclBgfyK5GsIzKpNNK7bLceN9AI9xMU3X/T6jpmnbGv4hRodmWi+b8U8s07ZOF7GZjaxtwI2sL 2mRZh0vyYRrPgOSHVzb0IR7MWjC/teLFQSLLlUtopdaHhQTSQl00N/ioNxihoSsTOmcJTAKJrU 2r8Q//EFFlVmN7byrjYmQDi6YGF2Va84/EeTreNDJGOtR5OhRij7w5chrN0aeoY7sdsT38Hs7B qt+BwK5ggWt8HmdWbzUQvzg/BRKfBQ3NISgbs1/tP4frb0QD1K7RbzxNG6O86yE2EoAmci0E9q nLw= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.107]) by uls-op-cesaip01.wdc.com with ESMTP; 08 Jul 2021 20:31:10 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v1 3/5] hw/intc: ibex_plic: Convert the PLIC to use RISC-V CPU GPIO lines Date: Fri, 9 Jul 2021 13:31:08 +1000 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> References: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=81790befc=alistair.francis@wdc.com; helo=esa4.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 | 19 +++++++++---------- hw/riscv/opentitan.c | 8 ++++++++ 3 files changed, 19 insertions(+), 10 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..ae40f10ca1 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,14 @@ 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; + if (ibex_plic_irqs_pending(s, 0)) { + qemu_irq_raise(s->external_irqs[i]); + } else { + qemu_irq_lower(s->external_irqs[i]); } - - level = ibex_plic_irqs_pending(s, 0); - - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(level)); } } @@ -268,6 +264,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 Fri Jul 9 03:31:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12366587 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.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,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 56FF9C07E99 for ; Fri, 9 Jul 2021 03:35:46 +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 DCD5B61442 for ; Fri, 9 Jul 2021 03:35:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCD5B61442 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]:36148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1hIn-0005I8-38 for qemu-devel@archiver.kernel.org; Thu, 08 Jul 2021 23:35:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEi-0007Xf-LW; Thu, 08 Jul 2021 23:31:32 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:20351) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEc-0006bj-Um; Thu, 08 Jul 2021 23:31: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=1625801485; x=1657337485; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RhlKZ9j17LJcDAtKf/vTdfdaiQmZvsjUSYrAvS4f5+8=; b=CN+n8DvbTwdcaqwv3aQDz5r0zkJRC8cXh7ijWeUjPIMgA0FDE5vBmMzy YxZIXijYDmKdDLQKFQLevbVtLwv6ntxVKUrrQNAxlPvqnUUIBC4dINbwr YeM5Qit1Rr9rbDJdd8mCa8+QisnT0vZcM2keA8+nPx6lht8KdVkqEJ4qn khDh2umGdPitglYFfXZ0Wnno/uorSiDDSW7anC9MKfRHJ96alZN137L3P VyjpqG01zRH4u17gO2gvZ6kCB1ov1NYC9X4f3DkyijYCXOT2jWitxYBAw ZRy6YPQMETgW3JSaf2aeoGCtnLsrY+Gvt98RY+bYVYgvKIENCZLyVN/LX A==; IronPort-SDR: WLjTO7mDXFdNjHHPsk5RPurRJYwoJ464RqelqOt/L6dR4QUxVefVyTPTUeaZ/4bC1NQvSlv9kI zXufrceRpjUfj9g8hq0MQ0Kq3OpWHhmLaLkbi7Ot0R1HDbKyZQRI4kzuk9kFUh5ZEQ2M34hDdS XS3kHYZcOsuHI+QciRFW0yoUF9x8fh+uXqd4/3t/uom1+Y9DpGXoP+6Qpstw5pqO3IWsxhf/mR seHtCp11KpgCFNNBE8jneJ0NLbQgHqAC5vOxQiCVYlGxUvw/lQ0UBL1BDRBZhYa+bF98iOXusB rLc= X-IronPort-AV: E=Sophos;i="5.84,225,1620662400"; d="scan'208";a="174125082" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 09 Jul 2021 11:31:23 +0800 IronPort-SDR: aEYzump55EN1AmA4Q0R7iaT1He3+okTVkb5B8Z87XJ2Ey6zVBqIQoDWM2+uDQ65ApwzX1H38xG 6/764AePNM3v6bV6B2I+NbZ07tvsJhrTS53rBKSHQDfA8DGN+5Seef23XkyEHcVw/Iz/9SOAqW n4I+e22Bdomxip5P1GIR7Bd/CW01cUYXnMcOe2auUPXBcmA2hFKBtZ2zuEByA2NCN0fdMh6w5H feCxMX5f2TQTSnjkl36g/vmVB0wxlVQPHYe5yUdYbVhyeHofZZhLHbSs8PuWkoDPtU81dEi6Ha 2qc2TLO2xBFjVEyrHccGUWRB 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; 08 Jul 2021 20:08:22 -0700 IronPort-SDR: HI5rmOPOV62dd2/HvF3gMpRrvqhr7z9gHyhtd0lbukNLP/UnGSL949iOLBHE6KQh5NRsaeBSNt NeemUceOthilCTgKskU/ma68X0jslr5x6JRWEKpgAtiLtj47Zh1zSXxFrLCekvciPqeL/4yrmy ajmw2oB7JvMIOHYBzzihAZzFTKtW10zxQMgsDQOY4+ffUnVAAwmWzuu2C0PeIfJC53EBFFZQTD q57yW0Ws4rDZmLR1OaCkbxJinN1QIDGJLLq83KEbEsqwIuiMxQtmMFArpSKfL9iRZjJQbTHdm/ YRw= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.107]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jul 2021 20:31:19 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v1 4/5] hw/intc: sifive_plic: Convert the PLIC to use RISC-V CPU GPIO lines Date: Fri, 9 Jul 2021 13:31:17 +1000 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> References: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=81790befc=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/sifive_plic.h | 4 ++++ hw/intc/sifive_plic.c | 38 ++++++++++++++++++++++++++++------- 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 | 3 ++- 7 files changed, 42 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..dc17b55408 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,22 @@ 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)); + if (level) { + qemu_irq_raise(plic->m_external_irqs[hartid]); + } else { + qemu_irq_lower(plic->m_external_irqs[hartid]); + } break; case PLICMode_S: - riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_SEIP, BOOL_TO_MASK(level)); + if (level) { + qemu_irq_raise(plic->s_external_irqs[hartid]); + } else { + qemu_irq_lower(plic->s_external_irqs[hartid]); + } break; default: break; @@ -456,6 +461,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 +531,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 +539,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 +556,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..8bbafae429 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -548,6 +548,7 @@ static void virt_machine_init(MachineState *machine) MemoryRegion *system_memory = get_system_memory(); MemoryRegion *main_mem = g_new(MemoryRegion, 1); MemoryRegion *mask_rom = g_new(MemoryRegion, 1); + MachineState *ms = MACHINE(qdev_get_machine()); char *plic_hart_config, *soc_name; size_t plic_hart_config_len; target_ulong start_addr = memmap[VIRT_DRAM].base; @@ -619,7 +620,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, ms->smp.cpus, base_hartid, VIRT_PLIC_NUM_SOURCES, VIRT_PLIC_NUM_PRIORITIES, VIRT_PLIC_PRIORITY_BASE, From patchwork Fri Jul 9 03:31:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 12366583 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.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,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 2C252C07E99 for ; Fri, 9 Jul 2021 03:33:05 +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 B1DE16142B for ; Fri, 9 Jul 2021 03:33:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1DE16142B 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]:58412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1hGB-0001KM-Ry for qemu-devel@archiver.kernel.org; Thu, 08 Jul 2021 23:33:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEn-0007i3-BQ; Thu, 08 Jul 2021 23:31:37 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:47209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1hEl-0006ec-FG; Thu, 08 Jul 2021 23:31:37 -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=1625801494; x=1657337494; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MXIILtZslEpEVdMOElaZ83rBmD2Q9028dbZaS7jZb9Y=; b=GQifXc+3u6STj8Neie2X808YrW9XKRRsDkYWiv+Hnf+RwTY9eyKPD7Df h3TJ9Kjgz+VP0rIQrrGnBuV0qthctVDGXkTd/HSxJa+3dzoonYjAeAaKQ 3tpvmVACgeou1+CDV5U/wlthav3r9C66+zFEAWJxSGGFrpTt0SDxh4XMb Bhn7hXygFUNj7znnbPsQnuUCPF0QvQ39KibDG1yXNTUKdePsZMcthLAmC t9UustVa5aTGJGbfDML74nTSmGbN+kgNCuxdl1rUJIdUcqlLItyHrScyX AHBd9YCEHp/QgvziyfvgztBPFhBdBxVwUmeD85/ze1grGSeQ1vg5+wdy2 A==; IronPort-SDR: x+Hy3P1EbkUzjZz73DQXkgXXgYf0sird2fVjVTGCP1fD5fBKZeCQLCWyx/itL6S57XdC1/TgYc A14ccGi6JKVdVU5yGvanxmUIE2EeskbdjdFg8lKP+2dnKWDKZ3h8qxuJ83QATn8SI8xXqV3r3N zUO11tCNBAFmuVA88zKQkeqcBY6NOUUoauTuo3qjhCJizIH4Kiohn/3IuTB6Y39cMjpu2vT37W TJIglPng/AdbS82wtoL7Mt6GYUVCevSulhRV5o6mWHzPknYvQ7AzRNiLwmBboMqaqcEl//oZfc 3VE= X-IronPort-AV: E=Sophos;i="5.84,225,1620662400"; d="scan'208";a="178927543" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 09 Jul 2021 11:31:31 +0800 IronPort-SDR: hhPFpluprrTcPcNpGvhWDjKmbnVjAMHo8mxRihDAeU/UE/ag4gq1caTriaYR9HjVa5u19Oo9qW VIsV9m2D0ZTJ3z3M0C4QUw+JRvNMxZjh82n8oFm47iG92Hlwk4sPM+tMajVh5odPxdr6hbkiFH fJtJfy1WoI0sMuvNtuHWme1aBEj8hzVAUIp/AzEfA+zvTdCLILseTQfyblql1XdwI1x465lMon GuNTlNFfLc/r4IQiqsbmJdI72b9VvSCmL9nfzFX5m57Kt2/4f9gqzjyMvKcYgypm8s3Eu3G87+ yBNrmmXP8qLDuhGsP1LKAeJR 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; 08 Jul 2021 20:09:45 -0700 IronPort-SDR: 6EN3tfQIvuASYNyBe3pJs7mxinuKB8xJHAGZaCC0DfPDvVWGCrw1lZwdvR3LSLwrorWxSSWJsF uGNwhz9j3mZBuH40vRsV3G0jT6ZGhQKpvOsSMUsOsyqZnuX8ZMDqubvxpS3tYQMkB1TFhdOpej YhNtTmxbao8Terox73/gDB47C2/jlblerFUaCHp/JMA/VC7KWF9Nr9HmLMoQOdM/6ypWeXmvxj LX1hs+6MxalHPFLQUy9YBLPVXPJK1iU8efNlKvG4ZQKC9zlrslYL9mGhdxXUUYBdcfNIRr4xGY g7g= WDCIronportException: Internal Received: from unknown (HELO toolbox.wdc.com) ([10.225.165.107]) by uls-op-cesaip02.wdc.com with ESMTP; 08 Jul 2021 20:31:28 -0700 From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v1 5/5] hw/intc: ibex_timer: Convert the timer to use RISC-V CPU GPIO lines Date: Fri, 9 Jul 2021 13:31:26 +1000 Message-Id: <85c77d5c22719a8a93561f5fbe4d0bc0d63b6266.1625801410.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> References: <37f8680b1ae39de82f9594d8e7a0d9596de9be8b.1625801410.git.alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=81790befc=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..b52642316d 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_irqs; }; #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..13d6df5c86 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_irqs); 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_irqs); 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_irqs); 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_irqs, 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); }