From patchwork Fri May 14 14:32:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12257969 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_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 B7E53C433ED for ; Fri, 14 May 2021 14:34:31 +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 1B02D6144A for ; Fri, 14 May 2021 14:34:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B02D6144A 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]:34706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhYta-0002N3-86 for qemu-devel@archiver.kernel.org; Fri, 14 May 2021 10:34:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsO-0008RE-6e; Fri, 14 May 2021 10:33:16 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:34521) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsL-00072v-Iv; Fri, 14 May 2021 10:33:15 -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=1621002793; x=1652538793; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=EniPEKMnEr8oXFZtbFUyesWVl1DQUYNFYayrY+U27pM=; b=D6DNpv/Y/90ALpPT2PwSGp9k/ZaZ9Xf/CafHN6E1ti22iPZRYT/L45fI 9cu1i6g5jkiAxc5rcxQbQ4eWtUAqkpdcWmuocGM8SyH9SYDY+bG3lJak+ IIsmUMJq0ci+L6eBDlOKmElfMoEpYVi5CKRZXsHyhD+NDNGGMXAEDcr41 +L5oQQcWi7dyj+AkVC/Gp80Vdxa/eJYsn75pYRAG/1IB8YtMUevSCMg2p h/bberCxj1Wi1C6bsHPUpVGuT6u1wsunH0fMTOLsgRO7hjK0kC+3cVR/h zxsHxQ/8OLOrLurIhPwWbrsJH4ZfiC/FSrXDMLKcsrSWUK0RPkdyDXV0V A==; IronPort-SDR: PJqdt4yl0BUzED8y7AzQDcJTEjVfHWHEMyKZhflCivhAEn+1KIbK8Ieda55r19OEONZbxu0biy NHD6RllSJbOpyJ+9qu2e3ZFRTgWmIcPgwNbDWZv76deGZSMY6Vo3ClY0b7f17550CMPhQCnQH+ mp6SpeJqe+3cRjfIsCe2p5J5CTwxN6y6PsAA2FTHKRrT7TTdWrJEQiQgeNW0I2bNO8T37VrqtZ 8lPrzbs1mO+TE3Sjg+6Lc59K6NJ8i1se4TLcVFrpVhHS5OJxsuMprJI9Ev5aRTZQS7Eq13NzKC u3c= X-IronPort-AV: E=Sophos;i="5.82,300,1613404800"; d="scan'208";a="167526766" Received: from mail-sn1anam02lp2049.outbound.protection.outlook.com (HELO NAM02-SN1-obe.outbound.protection.outlook.com) ([104.47.57.49]) by ob1.hgst.iphmx.com with ESMTP; 14 May 2021 22:33:11 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CuqQmqWqaJHqHuW+K9E9nCbiqe8ZTtjNeE9NsBvoaufRo8uaAzCcblveYkGFz2xdGRicFQp166Z98L/7+W8kwuquTMxtrxzeeP2wu8FcwaeCeWmofmyKUOGece9cfOwGvhPguSRcVI5kUGHTcZ0bsmoqz/QHziXm7taxsEW/x6a3SJwQ2g9L58niymGnz0NYhZgNzOvpomFWU/9+f1hbAm+bXcMrWdsenWnSf9Q0J+QaM2PrOmCzQRU5NB+B/JnRuBcOvZhxiLH/8PZW7r15VCNlhmnX0BQdY5vVhHbn4SbqKpJEa+XnzXabT/2hEUhbkWvqCuZGWOr2wnBuOTJL2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lwZthBkobJRmJuntBPYbhZ/+s8+qDL6hwilBEn8mzVk=; b=fv657VFBAMw00mhNkf7foEdkfcs18vjYkCtYube0L/kugeoou5gbysj4MiyY5x5qSTWJorBHlitSCfREhOEnGveZMCd1Rw/7UyZ2Ki90tMxPtk/6X5yb28inkBA68ldYszHQYr7P3S9++/9XASVb12FZa+mcVnSyxzkEXrk3ZEiQ2Vhd6c6KGSUMlGbDe2zDWoNNbUndpIvfpYdFx1Xdo58doZ+dHAdhqDcOjYJ2wHhgIh7WjzY8+vOKNILSV1uIkhYJhTWpM4B23nGBTc3zCWgvSjs0BHwkPPx4osUZNC75wrWZOfwodI3TFBFYW8EJi38x/kLjKOcIB//gk1BFrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lwZthBkobJRmJuntBPYbhZ/+s8+qDL6hwilBEn8mzVk=; b=oYL+6Ekqn1Wd8oWr8XofwlBjHj3hKgW6ibfvNdpa7//XY69bm46NQ2MWGk++6SyBHnzqQwNavi9kEJ2BUoOhJs5f31oYhLlgxRzc7nEP/rN+s8oEhqW3CWn3NnMY2MqsjTa8NgeIR9tmXT2/Pdv47BGQY5arfoLw3DfXNqYEOjo= Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7810.namprd04.prod.outlook.com (2603:10b6:5:358::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Fri, 14 May 2021 14:33:10 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.028; Fri, 14 May 2021 14:33:10 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH 1/4] target/riscv: Add defines for AIA local interrupt CSRs Date: Fri, 14 May 2021 20:02:39 +0530 Message-Id: <20210514143242.377645-2-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210514143242.377645-1-anup.patel@wdc.com> References: <20210514143242.377645-1-anup.patel@wdc.com> X-Originating-IP: [122.179.90.73] X-ClientProxiedBy: MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.90.73) by MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 14 May 2021 14:33:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c4378f4-5b6c-4823-522b-08d916e5329a X-MS-TrafficTypeDiagnostic: CO6PR04MB7810: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:298; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mGr1xqU3UTlJyvfvoN+1ov1IriS38njOmpLdUH4i7lGD5+xdkzSo25U/g0VL6xS9WGQzuMjo20bndqfm95aw9/jBLyyrTmj/26rc6WKmRpgTUwlA6AFpG1nv1lERIXHBfHICG7JS7m+6vUTnEUTnu8QR8n54xacyMkb7slC+Cc9yUZHWr3c9mi8e2QSqoUjYtH32hWop9ygLd7Xs0yUmlQ47ti4VCrLABiuDV6YzHLBzO5qeZU9m+8CHXh0wW8ImN5D7hVy6Oyp4Kb3CBmZ1YtwMW/WouIGamLKkgUjIlDfs+XrqVqHn1G6ZMfzW9OkEHSNrvztGZtBZGid1SfpKMtpwKUbXWuE4VsFSWVBiCKyZjTbG8gdF6kOMfrI9T1EeBB5jQgU6YcrEkwGrzyqXreNUSNlV1gU9ELx7/S4YMcHyg7gmW/Iaep3UzR5rQ8RDgxCbVKLv8Z+wJqSCprSkubTVUj1ibVHxyu2H3W0o4ZLRXCnpmVDX9+qEi9cdjV/i+OmfkKmWBtSO7fTuPbJAIOKeH8Nm/DgaUyK+3ZB3hMtl3j9qZxALILk+NUFVlsxdrWDwMQXogJX4ophNHBZriHLMNUiPp7apwJ13B5WwZ5Oxj0MPZS/CPWnur0cObVXlQnMDlJiRsSa0+AhcBuhhH6ybkOqB5UAWNBVbcoHCzcI= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39840400004)(396003)(346002)(136003)(376002)(366004)(52116002)(7696005)(1076003)(26005)(5660300002)(38350700002)(83380400001)(86362001)(66556008)(478600001)(36756003)(8886007)(66476007)(66946007)(6666004)(54906003)(16526019)(110136005)(186003)(316002)(8676002)(38100700002)(55016002)(8936002)(956004)(2906002)(2616005)(4326008)(44832011); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Fqn47mcLdvizBaS4aLENkWxand/+/YNl4OsWct7L2UEbJTAHWtCWX0PAzyOnETmbVCAvMVPfkUYLQITug41p3z0YVIFttBGsWg9Yu4LYT6yy4Zdw7dyzJ8kcAMIino9Yj2XDJyZ0BmR2YC8V47NfbkQX4fQ0fReM34jS+Tiruev0EtiXL/Dc2lvKWwEl8dfwkGQaxSZwpiCANUgjSg7D9Q/c20Q+/3jUS1FN4ZvFgbfnQR7KgreVlSp5M6kbOXI9q8KnsXDJe9jItfO2xjvYeNC38Dqd+96Zcvs6/BuF1LG1rFlXJtvqnCDZZbmEmGdrWWvvhfcBTlY7BaWdw4BxH4ooIARYpwlOOeojfe76mr2dQZ1r/V3yMYMyNGXzEW20Qm3wwgjNcE0GcQPi5sGRkemE62ak0fwVaACb2I7cDgT4HUt53fqTIuUUjvi+H+LXwl5G6inLmpraviojJTzjRYPSi5BExJ7uatTrN1EekiJMIXnjSeYkbRXuVELLYqPn6/6aur7EaYSVJ77Kdjb8h1rXzFvGujvqJkctVmONoXNYxXHDdtkznzZeuCy/ydrmWIwOCKOXQzmoydx6rvCteyz7TBegSZIhsK9OjtD+v8SrTqfJSQMSzzNhWPkfbDjhLYGRssRsugJDa6BIhAbP4XLdC7Wlv+XMslN9Xr2Y+0iK01JiCB3revKNB9hZbngx0pw3Nu1D7ZLEfXltIVz6MsT174qPo9yBSQ6NGMtaYbykjcp2DY+o/KibRaa+akLEm3q4E3COkIRqtTGlQlT2C0BZ17rC76n+6pwOKVg1Eptp9AypG5J22OAHZ3Rw9PW4jExt/B8+SJWkCYrwYHTbup3ACWicmM8PJAKNTUJ+9hDH22LWSz1t2kK04VqubphzaU4LWTvBOy00RFqjUj8dYvtsYmBNpgParm1olOe1ewScAzLke7oNZ57tQKjwJdV/3avgNHto5uto3LUH8K4M3AsDgHCNhBCcuMCfnEIeDTX0xdEV+2axcCorBqW+WghroeZt+f/gc/urvnqhoqrEBpvjUB2th4CskaLa3k5GXeagBnDAYjo73O1wEZdcD+jQSbGa2suyWPxbOR33m6rvVnPWFaIhKgAwp2WJVC7Ixy3zcGRWlj/7/FtrwnxWj+gcbCgGeeYhvw7/cTunxAQS6LeLcm0S8TjxUcdhAzk3Is1pYRl8N0KZ1h//Qqa5AxaKSW7795sPntNhgadTuGOT/C8+3WclaXSX3eqeg3qt1KoVKKujARSWuZ2gSPDZf3DWSSxWxLd8Ywgw4BRDP4nkNyCZcdl8mFG6bLLmYsrdxOeL3AEQzavg7ELB+cwiZmg0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c4378f4-5b6c-4823-522b-08d916e5329a X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2021 14:33:10.5526 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AZXPB5PeK7VWtvgYP0YD/O/OgZ02FNpfOp8R8OqDxGyGKMiz5TTGYdsZyM56Dx1o40/kEK9G9qb5+KRSU7vzHA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7810 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=761afde0a=Anup.Patel@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, MSGID_FROM_MTA_HEADER=0.001, 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: Atish Patra , Anup Patel , qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Anup Patel Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The RISC-V AIA specification extends RISC-V local interrupts and introduces new CSRs. This patch adds defines for the new AIA local interrupt CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu_bits.h | 128 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index caf4599207..d23242655e 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -169,6 +169,31 @@ /* Legacy Machine Trap Handling (priv v1.9.1) */ #define CSR_MBADADDR 0x343 +/* Machine-Level Window to Indirectly Accessed Registers (AIA) */ +#define CSR_MISELECT 0x350 +#define CSR_MIREG 0x351 + +/* Machine-Level Interrupts (AIA) */ +#define CSR_MTOPI 0xfb0 + +/* Machine-Level IMSIC Interface (AIA) */ +#define CSR_MSETEIPNUM 0x358 +#define CSR_MCLREIPNUM 0x359 +#define CSR_MSETEIENUM 0x35a +#define CSR_MCLREIENUM 0x35b +#define CSR_MCLAIMEI 0xfa8 + +/* Virtual Interrupts for Supervisor Level (AIA) */ +#define CSR_MVIEN 0x308 +#define CSR_MVIP 0x309 + +/* Machine-Level High-Half CSRs (AIA) */ +#define CSR_MIDELEGH 0x313 +#define CSR_MIEH 0x314 +#define CSR_MVIENH 0x318 +#define CSR_MVIPH 0x319 +#define CSR_MIPH 0x354 + /* Supervisor Trap Setup */ #define CSR_SSTATUS 0x100 #define CSR_SEDELEG 0x102 @@ -191,6 +216,24 @@ #define CSR_SPTBR 0x180 #define CSR_SATP 0x180 +/* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */ +#define CSR_SISELECT 0x150 +#define CSR_SIREG 0x151 + +/* Supervisor-Level Interrupts (AIA) */ +#define CSR_STOPI 0xdb0 + +/* Supervisor-Level IMSIC Interface (AIA) */ +#define CSR_SSETEIPNUM 0x158 +#define CSR_SCLREIPNUM 0x159 +#define CSR_SSETEIENUM 0x15a +#define CSR_SCLREIENUM 0x15b +#define CSR_SCLAIMEI 0xda8 + +/* Supervisor-Level High-Half CSRs (AIA) */ +#define CSR_SIEH 0x114 +#define CSR_SIPH 0x154 + /* Hpervisor CSRs */ #define CSR_HSTATUS 0x600 #define CSR_HEDELEG 0x602 @@ -232,6 +275,34 @@ #define CSR_MTINST 0x34a #define CSR_MTVAL2 0x34b +/* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ +#define CSR_HVIEN 0x608 +#define CSR_HVICONTROL 0x609 +#define CSR_HVIPRIO1 0x646 +#define CSR_HVIPRIO2 0x647 + +/* VS-Level Window to Indirectly Accessed Registers (H-extension with AIA) */ +#define CSR_VSISELECT 0x250 +#define CSR_VSIREG 0x251 + +/* VS-Level Interrupts (H-extension with AIA) */ +#define CSR_VSTOPI 0xeb0 + +/* VS-Level IMSIC Interface (H-extension with AIA) */ +#define CSR_VSSETEIPNUM 0x258 +#define CSR_VSCLREIPNUM 0x259 +#define CSR_VSSETEIENUM 0x25a +#define CSR_VSCLREIENUM 0x25b + +/* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ +#define CSR_HIDELEGH 0x613 +#define CSR_HVIENH 0x618 +#define CSR_HVIPH 0x655 +#define CSR_HVIPRIO1H 0x656 +#define CSR_HVIPRIO2H 0x657 +#define CSR_VSIEH 0x214 +#define CSR_VSIPH 0x254 + /* Physical Memory Protection */ #define CSR_PMPCFG0 0x3a0 #define CSR_PMPCFG1 0x3a1 @@ -436,6 +507,7 @@ #define HSTATUS_SPVP 0x00000100 #define HSTATUS_HU 0x00000200 #define HSTATUS_VGEIN 0x0003F000 +#define HSTATUS_VGEIN_SHIFT 12 #define HSTATUS_VTVM 0x00100000 #define HSTATUS_VTSR 0x00400000 #define HSTATUS_VSXL 0x300000000 @@ -565,6 +637,7 @@ #define IRQ_S_EXT 9 #define IRQ_VS_EXT 10 #define IRQ_M_EXT 11 +#define IRQ_S_GEXT 12 /* mip masks */ #define MIP_USIP (1 << IRQ_U_SOFT) @@ -592,4 +665,59 @@ #define MIE_UTIE (1 << IRQ_U_TIMER) #define MIE_SSIE (1 << IRQ_S_SOFT) #define MIE_USIE (1 << IRQ_U_SOFT) + +/* MISELECT, SISELECT, and VSISELECT bits (AIA) */ +#define ISELECT_IPRIO0 0x30 +#define ISELECT_IPRIO15 0x3f +#define ISELECT_IMSIC_EIDELIVERY 0x70 +#define ISELECT_IMSIC_EITHRESHOLD 0x72 +#define ISELECT_IMSIC_TOPEI 0x76 +#define ISELECT_IMSIC_EIP0 0x80 +#define ISELECT_IMSIC_EIP63 0xbf +#define ISELECT_IMSIC_EIE0 0xc0 +#define ISELECT_IMSIC_EIE63 0xff +#define ISELECT_IMSIC_FIRST ISELECT_IMSIC_EIDELIVERY +#define ISELECT_IMSIC_LAST ISELECT_IMSIC_EIE63 + +/* IMSIC bits (AIA) */ +#define IMSIC_TOPEI_IID_SHIFT 16 +#define IMSIC_TOPEI_IID_MASK 0x7ff +#define IMSIC_TOPEI_IPIRO_MASK 0x7ff +#define IMSIC_EIPx_BITS 32 +#define IMSIC_EIEx_BITS 32 + +/* MTOPI and STOPI bits (AIA) */ +#define TOPI_IID_SHIFT 16 +#define TOPI_IID_MASK 0xfff +#define TOPI_IPRIO_MASK 0xff + +/* Interrupt priority bits (AIA) */ +#define IPRIO_IRQ_BITS 8 +#define IPRIO_MMAXIPRIO 255 +#define IPRIO_DEFAULT_MMAXIPRIO 15 +#define IPRIO_DEFAULT_VS (IPRIO_DEFAULT_MMAXIPRIO - 4) +#define IPRIO_DEFAULT_SGEXT (IPRIO_DEFAULT_MMAXIPRIO - 5) +#define IPRIO_DEFAULT_S (IPRIO_DEFAULT_MMAXIPRIO - 6) +#define IPRIO_DEFAULT_M (IPRIO_DEFAULT_MMAXIPRIO - 7) +#define IPRIO_DEFAULT_U(_i) (((_i) >> 4) & 0x3) +#define IPRIO_DEFAULT_L(_i) ((_i) & 0xf) +#define IPRIO_DEFAULT_16_23(_i) \ + (IPRIO_DEFAULT_MMAXIPRIO - (IPRIO_DEFAULT_L(_i) >> 1)) +#define IPRIO_DEFAULT_24_31(_i) \ + (IPRIO_DEFAULT_MMAXIPRIO - (4 + (IPRIO_DEFAULT_L(_i) >> 1))) +#define IPRIO_DEFAULT_32_47(_i) \ + (IPRIO_DEFAULT_MMAXIPRIO - (IPRIO_DEFAULT_L(_i) >> 2)) +#define IPRIO_DEFAULT_48_63(_i) \ + (IPRIO_DEFAULT_MMAXIPRIO - (8 + (IPRIO_DEFAULT_L(_i) >> 2))) + +/* HVICONTROL bits (AIA) */ +#define HVICONTROL_VTI 0x40000000 +#define HVICONTROL_IID_MASK 0xfff +#define HVICONTROL_IID_SHIFT 16 +#define HVICONTROL_IPRIO_MASK 0xff +#define HVICONTROL_VALID_MASK \ + (HVICONTROL_VTI | \ + (HVICONTROL_IID_MASK << HVICONTROL_IID_SHIFT) | \ + HVICONTROL_IPRIO_MASK) + #endif From patchwork Fri May 14 14:32:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12257975 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_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 7F9EBC433ED for ; Fri, 14 May 2021 14:36:20 +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 0DB226144A for ; Fri, 14 May 2021 14:36:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DB226144A 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]:40992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhYvL-0006dq-6R for qemu-devel@archiver.kernel.org; Fri, 14 May 2021 10:36:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsR-0000Dz-Td; Fri, 14 May 2021 10:33:19 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:4336) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsP-00075s-TP; Fri, 14 May 2021 10:33:19 -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=1621002798; x=1652538798; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=mSKQX2scjYO0kQ/NLv/Uc3/4MigoS/+nvPTLETUzKGc=; b=pud0HS514FSH3SueTjZkGJvdHnePyni8GUXmS4ZxoFSas2KDRt468PIM jsmOVowbqm9saAOZhEG+x3KVuStPcVkpjtHS7xergVNYyzcBA9wfYQeKl 36vMT9fwXrQ7ULwFSu5dC3NUTfLZOuJwWwSqrjLKokIdLQp3S7hB2sZu6 crpFP5stDFF+EbxIf5oRUUUVSkJE5XVcKFrl+PsbHEaaQH2PzscYxuudp 5ABRumOzv2eu6XXk5LmRti9PcVSp2zU/nZMc1ENY0B6jfv+YG/yPSsiRe m6PgL6DhtcZRrn4eK6TL1/6ttEBf2v37crZ4NkXxKW+wBM6awhmZAdDeN g==; IronPort-SDR: NHw4RFKhRJULIzpi/4dp2+f5063kncWBuRLJcXmEfYOKdDrX0PKmIohq3J4fVcBgWBILgefkem rhfgtIS9A49T0h34PLD0xB8IWuCjZfTa7GDl/L4KGKLO6+Uf/BzOuLYvFSBoCVXZBIfWI5ZXIa IRb8i1rp/RBcUNQt8MbDw83ovJgSUmpCdDmxC/mczSdK3vJg+c/oYTyNrtTyH2/e7BdKryr+Es QjVwuf2eha0QV5CfXbtfv7p/Qb14d2Ea1JEB2vlxDVI/abiVIoJqC+GlH2f+K7Nxx6B0Kj0Ca2 KNE= X-IronPort-AV: E=Sophos;i="5.82,300,1613404800"; d="scan'208";a="168759605" Received: from mail-bn7nam10lp2103.outbound.protection.outlook.com (HELO NAM10-BN7-obe.outbound.protection.outlook.com) ([104.47.70.103]) by ob1.hgst.iphmx.com with ESMTP; 14 May 2021 22:33:15 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MiOOebElWmajJ204aNtSX8poDpmXyyn8NDz3PGCo5u1gihia2/5QElEaycoZb1R92HZIXMFikOvJ4Hn9AMzlDahON5H68fIfBXvkpnJ6iKa2rUStkPhD4sHAiOYlTfW6kKrt9SZ2d6iXD4l/NbRb08tiSLSegVx35a0HzPluuCHYwE4W2RWEvqfWkvk4ziMTNJNqcs1sl5wUC+L3Y/lsJpDZpjUzgfK7O0tfbC7w25qLyK7S3IGvOm+NgCLjtPMIYv0lJMigo7OLnI2ZpaT6d/MaPSbqe397zFLlEw4Q24jP6Han5A4WMCgk8BT3+h51KK3rh5xq7Sl4KgG6F50mJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BO7apSkh5on2A7azci+D46uso+TY/gcTHDdMRls6lOg=; b=kfZaFpbe3KxZpdky0jbc1FxVTKk5nClgrkiU1jEk7DyJZEmwvv6tYHOmLSQpI4Q+qZglOSmvuJ7miepgHlh/SIQrymJw/JB4zLzUiiodHiuLFMGPUl0+PUoHIyB6k/QGoQrCe8MZsoDwBGrpBnrNluRQjD/rnzE9mCMOrIKs7sfP1lUFlpr/rnXCUnEHke+2qR+kzA+v8jmZuUSS4gt2DRg2BurxXHdSMfWwVO51T0DEYjkTBa0JXoEJIAweKzPW3NaXbQ4QuKX0hYMj+UN3awGom+gzJlJNWwdvqgXd4/haojPKDgscgNgm6ImhIULgKXmwOQc5u4efVblqK8z+kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BO7apSkh5on2A7azci+D46uso+TY/gcTHDdMRls6lOg=; b=DuUF7XUyCdZ4HI58x3+QY4At675cOJZLiY9w7HlMCpsTi9y4IFgpBMblp3cqhV6Izk4jLJeNGDuYd26SWKXVhqwDdM9E+rrfUbEgJQCztW9LFvQ8qWFOogZfW3jYkThTD7jd8KvPCjnLw/6oX2jIO/zi+PSbg5bzKyFhmFIuqPg= Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7810.namprd04.prod.outlook.com (2603:10b6:5:358::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Fri, 14 May 2021 14:33:14 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.028; Fri, 14 May 2021 14:33:14 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH 2/4] target/riscv: Add CPU feature for AIA CSRs Date: Fri, 14 May 2021 20:02:40 +0530 Message-Id: <20210514143242.377645-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210514143242.377645-1-anup.patel@wdc.com> References: <20210514143242.377645-1-anup.patel@wdc.com> X-Originating-IP: [122.179.90.73] X-ClientProxiedBy: MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.90.73) by MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 14 May 2021 14:33:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9708a108-c452-4033-4f97-08d916e534db X-MS-TrafficTypeDiagnostic: CO6PR04MB7810: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:2803; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vh36Kx2n8oorANjCkIXpPcu/6omp05N23S3HK7RZrxlflP1yBp6oSTKhPcV7hKV4Guti5SNdtpdixR9MmbLT7/ah57JcN0Hz0qErn6MBXs8tIJbefM/cCqhY2gGH7hDx9Lgscn+wOSgmCzW+8UzT8ss8KR8jVQuHhUvUCKHvIQc6YHD2VBXzy+hG8bnWpOtCpsXe8jDpWjwxpd7Zf6drVFeYbt/NWUamJj+OqxJyAEOmcTU/oyV9PLgeBJyHkYC1AQwNwFI+KY2EjoBlo1O1y7tNPOP7bkuSmBw3rw6CI52Yw/dFZbQSbGhaW5NR4c2qNP4n0NF/9j4Gbvbe0VXhRGqmbJ1v/gZhCGL+wpXVdatTSkvhjS7TUJYZi5KJtBCEGr+YLIBrfjBvdIUFNN+abCxCgPPjcg3LOD1+tfp1rC2P0My3LqCHHm+AYsU7WsiBFW6tHiLIvJgkc2LhFp3OLDpQ/QWgIuFHojoIAmka/98unSkFgfiUUngaVlt8/05vp0xeHjlpnWT/r3i6XPkCMNLMUupBJBDaV24VfbFTKlXFrUmdPkYjpNPdg2DDSHpe35HlQxvq9w2/zmo822Gf6Lad7oj3GkeEMdjlVXIo3S6rMUSuv64pvWqc+L4BRvngJH3Fs5ZsMBOzKxDFaIMVdA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39840400004)(396003)(346002)(136003)(376002)(366004)(52116002)(7696005)(1076003)(26005)(5660300002)(38350700002)(83380400001)(86362001)(66556008)(478600001)(36756003)(8886007)(66476007)(66946007)(6666004)(54906003)(16526019)(110136005)(186003)(316002)(8676002)(38100700002)(55016002)(8936002)(956004)(2906002)(2616005)(4326008)(44832011); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: GmPT+W2xeEOLitGtWg/iLjpjNcnKBMVBZqhFTV65h0ZAM0AWBaL2IxQ0OkFlS4L9T1zlcY3RStaFE8iWOiDULHDVekGlQohc/6C15tU+PrSfAxlMC5+5Cn7FoXElPiZ/pF2+Cdwhpnwr/j7AUbT25zmVXmSZL6q48fSKJZbuUG9PDRA6fmCI6Y2WuQcuJwOtufIDPx2gRjyL7acpXk+wZkcqBjuIPhExNAOAr2Sl/exwHI742kE6ZU4ldR43L64KAAM0qoD++YYBtqDb/Nll5SZ/5L7y+uO0eTBnSLE/nX+mNWwM379S2CDMmSXB3YzBbRigSWqpBUVpAFKa82VswYlwn6nUOFjDqxQTu01zj6ewUbmpa6yb5Ii45tR50KjX4qWFz3Cg+gwI2n6DBTu/IYLs+FTjQTjiR4neCGuB5dmkmlF5KuPDhsvpp09vmP+AAjqseM3U5ey1KQT2KSOeUqOnW/ZaRhLUFWFe/zzJ2FeXM4Cv3Ufo1Zd9KVPldbx15R2J+Yc0skeyrKsYkaDtjU1meHgDyYLjYm6ntjOmGPTXkZwuNfRkJ5jU5femDqqCTjHf6Rv4IIqB8ZL9M7nGWomUqoKgdbatYNiHUEbnwCQGG91OtcMM4q6FGpbuQT/a/6eP5BgsWjuhJX5M2B663KFyFXmbfLGe/OhdMsWCEQeXl/A3NbLm09/jNkkZiFKnhzA0vZusn0lHIetbd+PoKJt6ucfNvLlWZX5JiDO15VaOShWoMYzl4pPiidnCO79fjeYz8appgQQSLrxelDGMICEgLbD98Hc5t7cOvXE7oYI3Krm9fB2Ileilh9rQeIEASWWapQitfLANNIGTbrD+8OwWLOYWoFk7MUz4mM9cZYe6PDgaHpWTHBRjHkI3RS5K++euKAeWNMcBSNadMvgKg9RDYaUuPqiLII4PgB/A3yGu82g72MvO4PFHRSmIszrYXvS7GB8SElIyConVEVaKGGvwj3r2XmtdAs7LiY891hAb0sZm9yymqjZ/aE0U6/sPCKU25ZVSGq90Ryx0mdOovzsHr39QlI9ulOUfop889Z288o748bsB6dbL/KzlulcpNtEWJSskpQ0miaKLYZGrjmZbqTP3p3vRB3lT8hBIQdb5TzW9M2VJwCJ07uAOSvGt7cPA/mTPbtSZbgBlT5pEJQRKfniZurAaAJw74RmieH/MCNkFCnEXZzJtY+VozPqJ7nlUAJs+3/1L/1ZMutO+6aH07xy8Yz0VmQPyr+WEWE3ObjVHSErPsXkuVlqgmhxTbvQ2AiviW3aACBrPJIAxdGrGf/kLkkvSAMkPnRX+uUgwXZvZSpplmEMey/Y7wJXA X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9708a108-c452-4033-4f97-08d916e534db X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2021 14:33:14.1179 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3tlcItBSdeHDbqHRVWIMCBlgHQV53tc4OnpgqwiSlAiSiEYuQbnOytv32DHowzmHRbF1MdCloRSMM90apkLLig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7810 Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=761afde0a=Anup.Patel@wdc.com; helo=esa6.hgst.iphmx.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, 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: Atish Patra , Anup Patel , qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Anup Patel Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We add experimental CPU feature to enable AIA CSRs. This experimental feature can be enabled by setting "x-aia=true" for CPU in the QEMU command-line parameters. Signed-off-by: Anup Patel --- target/riscv/cpu.c | 5 +++++ target/riscv/cpu.h | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7d6ed80f6b..f3702111ae 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -414,6 +414,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) set_feature(env, RISCV_FEATURE_PMP); } + if (cpu->cfg.aia) { + set_feature(env, RISCV_FEATURE_AIA); + } + set_resetvec(env, cpu->cfg.resetvec); /* If only XLEN is set for misa, then set misa from properties */ @@ -554,6 +558,7 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), + DEFINE_PROP_BOOL("x-aia", RISCVCPU, cfg.aia, false), DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC), DEFINE_PROP_END_OF_LIST(), }; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0a33d387ba..f00c60c840 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -80,7 +80,8 @@ enum { RISCV_FEATURE_MMU, RISCV_FEATURE_PMP, - RISCV_FEATURE_MISA + RISCV_FEATURE_MISA, + RISCV_FEATURE_AIA }; #define PRIV_VERSION_1_10_0 0x00011000 @@ -303,6 +304,7 @@ struct RISCVCPU { uint16_t elen; bool mmu; bool pmp; + bool aia; uint64_t resetvec; } cfg; }; From patchwork Fri May 14 14:32:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12257971 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_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 EE3D6C433B4 for ; Fri, 14 May 2021 14:35:23 +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 5108F6144A for ; Fri, 14 May 2021 14:35:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5108F6144A 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]:37520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhYuQ-0004Ep-C5 for qemu-devel@archiver.kernel.org; Fri, 14 May 2021 10:35:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsZ-0000gO-9Q; Fri, 14 May 2021 10:33:27 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:34531) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsU-00078Y-97; Fri, 14 May 2021 10:33:26 -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=1621002802; x=1652538802; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=GZeFP0jcMeypNdrTJrmH3kYY/RUR2K6Swu7nMPolMqQ=; b=SMi4CuH86Z4Z8k4s55uj9BDniB/K5oSx/Szs5k+D09Km+pAShNSkX+sm RPs4MQWCTy2wekXtimOyY39CsfIUhXYmfbeL7AYwGukgCkZzDQmVw1bov lHLOIMiM6dPsuPXwyKRD3Qhks7IXVxhY11XNJpEFc8EbCJP/NxqnHGR3U TdHWUdlDLNC8hupU8rprIy76M5VKgE+U/1s2QV823IIirDRLATAYPFVgx Duu/Dz/ztSPy+VH9qAFxRbRNdQWLeuCeYpPVGNpIezhzPnMMkSCyxaho8 XeaEuikLGTMVdgvXoOnCxezdxL+vNV2kJATdtg1BxkRclPv9fS3mIhNOg A==; IronPort-SDR: WV03M9TuVhUV/lb9RE6+usIzWAfgscCKbgVpbBxQXW1euEYQO4aXCH68NHX5hUAgUXAn1pfHKp ac4mu+G5Gl3YlqASuY5tEK1uj9pIXWDVOCJxyKwh6uzBBa1A92yBbSH++bamstcF4HP5hmgM2S h9QJ8MloR77JNli7hF0McJxN4SU51rMWLrlOMqcF396CmLBl/2vv2UcNo6FSpt5OJKvNYJ/LI8 B4weFyyczvcJnEjF1TD2Iqir/cmiCrtSDUQtZYveZb0btFtXVJA8wi+2X7j3ZD6y6MCW7uoY6K v48= X-IronPort-AV: E=Sophos;i="5.82,300,1613404800"; d="scan'208";a="167526807" Received: from mail-sn1anam02lp2046.outbound.protection.outlook.com (HELO NAM02-SN1-obe.outbound.protection.outlook.com) ([104.47.57.46]) by ob1.hgst.iphmx.com with ESMTP; 14 May 2021 22:33:19 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kc8FWEEiUmBYji8ISlLsgMjrMm/2UzGdXd5LybbxZLGSGDeP98lWzD9xaSU1b7KVYxm52nPmtC/TspoDC/a6DDFsja1WTAbrlwkwdlhOKtiC9oMp1VeywkmL4n7wslI4IvrR0sH86vc03BtSMd3Y/MmptOM1VMJXwN60GieOqtuYOlZWgSrr7YTPcB1FjuNEHu1dPiypOJGkcN1icCPym0pYqJgGRJbnjghiR9fLYeZ5KmEQfIawanWMa2CpTCJhZWjifTHC7E5XZD4jv6AUAR9/OE3PCFxs+QwJl24jIVZHr16a05tRgEkSb+Vexv/VQwJKtkdHM3Z+sU7ZyLtZNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PXLfpp7HnkV8q3AncSMjFHbvZ1QNzRsnyXIUpz9ibdc=; b=YpGo9YMTAv7ep/naF32H06EpsKgDUvJJj8oOu9oQy2Fv0998c/ukctzKWftRiBCyj+57GTQkaTUeGmx8qHiYg+ftz/SWtdEoMDJt+ijOvI+Xx9vJMxveJBeZJcb+pcbKGTZ/jcHIw+kdYReSblJ5V3qBnZzt7dV1GCLlLAzqTEt2TUmGr66jSsibu2bEOHv0RJbmX4SjKePeHincnB3pPyy6Ne21InOCy9wPtZ667GfHfFu25wZjLz10kgIlGllKt0FgAMiGODIMqZBP0RCT91SGxDqWufIOp//2/G3yZNFp3BowYOjrL/nuqV7Pd1vxWBY5S5Dpru8a9uvS1psorA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PXLfpp7HnkV8q3AncSMjFHbvZ1QNzRsnyXIUpz9ibdc=; b=sL8qI9FnR1RA8o+H9/yZF7WLWthiewvWSiF69pPbp/UA1RR5Gii6lRfqYEAqub5R1v5UuTVkRX/gxUNNQgIIpAS0KJPWoPz4j9vHGinHtv/ehKP7I7DzdNfeC3TN2SR9NucaQjzsSUFTaYTCaUTsmrke4o19vMZUayuJduOH9ms= Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7810.namprd04.prod.outlook.com (2603:10b6:5:358::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Fri, 14 May 2021 14:33:18 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.028; Fri, 14 May 2021 14:33:18 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH 3/4] target/riscv: Implement AIA local interrupt CSRs Date: Fri, 14 May 2021 20:02:41 +0530 Message-Id: <20210514143242.377645-4-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210514143242.377645-1-anup.patel@wdc.com> References: <20210514143242.377645-1-anup.patel@wdc.com> X-Originating-IP: [122.179.90.73] X-ClientProxiedBy: MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.90.73) by MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 14 May 2021 14:33:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7109d883-05fc-4675-9e90-08d916e5372d X-MS-TrafficTypeDiagnostic: CO6PR04MB7810: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:525; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UB/hcNc3IZScbwn8P14T2yFOJuKLn4h4PTO9Y3PBlaEWdEdwRJ0SAO7LuHTHpdxDN0Azm+785WLsBeNosD1a+QuU3RGwBP4f4bofBs1p87/hOubBuH+wkSYTOADQ03CusbNdcamHjYSZvGMapcK9jK2Gwfz45SbIangNhPSCxu7NLSFalS7vTc3y/KsnyWolC/6LFivqsqYG4RZF78OyXb0DZuLfAp1m+XYUd3rgs63rB2CZDD96aDc2MVWiwlI4ECfudlax6HXv8Hx1nmCbLsa/KeY95fOQLHcMqcL5Bug/RmuSwK/A0u4Ac7LqO0SMECMpcbsGcz91jgXiNMx3bHRJw9HMxVjo+UHgtllSLvSb91nAzA2X+4sv/SFKjB5tb2TDp/1E9gsNSmqhe8n+Gt7Y2V5lFykyqd4E+zBckaVOQ5HvE1aXQ4WZSpBubx5qRCoFmz22rQcjPXGCHDBSujVtK1hUNlSP/Q4HFMhIuH29FAX/T9GJ5dQRrkrcjUDZ88aNPYNc7sb8b3HRoX+EjIf4AkFvmhwODgQ+RDxhycxjqmvQZYMl5q1x918qXOJR4U/cfQwwYUutvcCHYsQhh7AgD2bk4TmuMiU5I3v/fMm+XDmPZ7CmzKuNOQiEF/Y7250OmnUeHCoIuTCuIamCx2ENEDCGgugPrG1KHimb0P4= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39840400004)(396003)(346002)(136003)(376002)(366004)(52116002)(7696005)(1076003)(26005)(30864003)(5660300002)(38350700002)(83380400001)(86362001)(66556008)(478600001)(36756003)(8886007)(66476007)(66946007)(6666004)(54906003)(16526019)(110136005)(186003)(316002)(8676002)(38100700002)(55016002)(8936002)(956004)(2906002)(2616005)(4326008)(44832011)(559001)(579004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?ZsayFwJ0Y+RVajg8Sunf1CfSrctbSX?= =?utf-8?q?hPCqDDbfatoVVSvMSLV1WDLhph54NovZ4mRcMgnJZu4XKJBpfBTbQP2Ipgf7/wTqz?= =?utf-8?q?Vrp2hteoeFBUbQpDGPq29ClvoMZX/T8PnoKckSU7gcw+e9nfPiY1hkC9yRun1aAdB?= =?utf-8?q?3FfEVUkmRmHiBRzojkUkTQfruyWJlEzckTchYc0lf/tl6CwSOcQVAJdIdYW5ZoYcN?= =?utf-8?q?UrOhWiJ0e8Ap74nMETK+jmByrOu3Y0auJXl26H5sbDBP45ZxoOfFPRiTbqjSjOPME?= =?utf-8?q?uDynzo8qqoQcU+LJ9/MbU8PeLLV7kYrFLgvTsKJe7z/wzz6d1lqI1bjLhfsFL/kYt?= =?utf-8?q?lN9yp4RH8SxkHuD2gqrDskxfuwBe2glHasQ/n1lHcHaRVkkNkHEX2qlasYQ8RIvJu?= =?utf-8?q?V5R6Ax4Kg0qwJIRA4xDd9npxh2h9P/a0dwqVaR18zzQyS9h6IFofWbEabYNYlZpn6?= =?utf-8?q?u2YGaz6mLitUM/Y0pyc2DqehWZcu0yd7sllU7k9E2LcmFmwTCpMEGPMVEXBF5wI7z?= =?utf-8?q?Ojet/CkwCBMKebteZT2ya4pnK7drhMrtH9iEWseuDks/hxuObFqQ5v8VSEBNqVFyO?= =?utf-8?q?hOXTW7rh4aoJSUqhmzw3ziXBkT+76PA3lSJ6FdZIzF2w30ZGLR58CvqfVXmt4s9wm?= =?utf-8?q?WQZifJjmnD4/a0UK8THN0oE84OtefRvcButZjhpM9OUqDBwnA5hFO4D8jGuP+gugN?= =?utf-8?q?9bA3uuIUNBHJ+PHf8feTHaFq+289FKh4On2wPNCEkHl6NRkiaPIYd84rLN+0K1UHU?= =?utf-8?q?IOxTaq0bjkjSvGG2RyB5NOpACR9ufksB7BvwthJyTdPUtyMdK5BlCr5vCsLzYyYC/?= =?utf-8?q?EcbI9LbDSriOoNsDcLYDPLJDbXMjvZIfzFCquT1xwWh5FbSuAXTkP974Uivf8gQve?= =?utf-8?q?a6CBaR5whBEPzm1mlo8Pma4cWNYRDMpPN4nJKF2S7fh9oVq7eiKGTyXASNrvysrJY?= =?utf-8?q?SofVX2/ow835FYm8n0FcZaNKeVC285xmV4gZDJ187MYV094HvvMo4CKEryIQqPRjU?= =?utf-8?q?R/7YsthIHL1rPN2nDSa7c7mGxCUNDUAkE6Yr3NysP+6LYbQzpLejNPI4D4Gh2Wcn9?= =?utf-8?q?LA/EBJOjQmLi+GYfkax5C5fL6vA8SU15IGLFZ3cYFf0+hkEqxbr/4l2kz8dTp5Eyf?= =?utf-8?q?xAdOiEyvAQKSDbUJr4Qrq0rVKdRZG4u0K2Icg7r7n7qVY+t0iTEsmh4AMThRdl9cu?= =?utf-8?q?QE4ca7MsrHgxmMb2Opv1ew62FCLnIOab5XlyGOwRjI8xCWUhBEyZCy29Covs4PgRX?= =?utf-8?q?gkySWvFJYxFwFk?= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7109d883-05fc-4675-9e90-08d916e5372d X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2021 14:33:18.2925 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: aKjeUeyiMlgo2JhHQgr3lDFlJEET+CG3r0AoqOPkYfTmA+AeG2aZnW0/eh6oyj2W19KV0mtXODgteGzsdVSxKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7810 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=761afde0a=Anup.Patel@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, MSGID_FROM_MTA_HEADER=0.001, 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: Atish Patra , Anup Patel , qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Anup Patel Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We implement various AIA local interrupt CSRs for M-mode, HS-mode, and VS-mode. Signed-off-by: Anup Patel --- target/riscv/cpu.c | 27 +- target/riscv/cpu.h | 52 +- target/riscv/cpu_helper.c | 245 ++++++++- target/riscv/csr.c | 1059 +++++++++++++++++++++++++++++++++++-- target/riscv/machine.c | 26 +- 5 files changed, 1309 insertions(+), 100 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f3702111ae..795162834b 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -256,11 +256,11 @@ static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "vsstatus ", (target_ulong)env->vsstatus); } - qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mip ", env->mip); - qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mie ", env->mie); - qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "mideleg ", env->mideleg); + qemu_fprintf(f, " %s %016" PRIx64 "\n", "mip ", env->mip); + qemu_fprintf(f, " %s %016" PRIx64 "\n", "mie ", env->mie); + qemu_fprintf(f, " %s %016" PRIx64 "\n", "mideleg ", env->mideleg); if (riscv_has_ext(env, RVH)) { - qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "hideleg ", env->hideleg); + qemu_fprintf(f, " %s %016" PRIx64 "\n", "hideleg ", env->hideleg); } qemu_fprintf(f, " %s " TARGET_FMT_lx "\n", "medeleg ", env->medeleg); if (riscv_has_ext(env, RVH)) { @@ -345,6 +345,8 @@ void restore_state_to_opc(CPURISCVState *env, TranslationBlock *tb, static void riscv_cpu_reset(DeviceState *dev) { + uint8_t iprio; + int i, irq, rdzero; CPUState *cs = CPU(dev); RISCVCPU *cpu = RISCV_CPU(cs); RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); @@ -357,6 +359,23 @@ static void riscv_cpu_reset(DeviceState *dev) env->mcause = 0; env->pc = env->resetvec; env->two_stage_lookup = false; + + /* Initialized default priorities of local interrupts. */ + for (i = 0; i < ARRAY_SIZE(env->miprio); i++) { + iprio = riscv_cpu_default_priority(i); + env->miprio[i] = iprio; + env->siprio[i] = iprio; + env->hviprio[i] = IPRIO_DEFAULT_MMAXIPRIO; + } + i = 0; + while (!riscv_cpu_hviprio_index2irq(i, &irq, &rdzero)) { + if (rdzero) { + env->hviprio[irq] = 0; + } else { + env->hviprio[irq] = env->miprio[irq]; + } + i++; + } #endif cs->exception_index = EXCP_NONE; env->load_res = -1; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f00c60c840..780d3f9058 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -157,12 +157,12 @@ struct CPURISCVState { */ uint64_t mstatus; - target_ulong mip; + uint64_t mip; - uint32_t miclaim; + uint64_t miclaim; - target_ulong mie; - target_ulong mideleg; + uint64_t mie; + uint64_t mideleg; target_ulong sptbr; /* until: priv-1.9.1 */ target_ulong satp; /* since: priv-1.10.0 */ @@ -179,16 +179,27 @@ struct CPURISCVState { target_ulong mcause; target_ulong mtval; /* since: priv-1.10.0 */ + /* AIA CSRs */ + target_ulong miselect; + target_ulong siselect; + + uint8_t miprio[64]; + uint8_t siprio[64]; + /* Hypervisor CSRs */ target_ulong hstatus; target_ulong hedeleg; - target_ulong hideleg; + uint64_t hideleg; target_ulong hcounteren; target_ulong htval; target_ulong htinst; target_ulong hgatp; uint64_t htimedelta; + /* AIA HS-mode CSRs */ + uint8_t hviprio[64]; + target_ulong hvicontrol; + /* Virtual CSRs */ /* * For RV32 this is 32-bit vsstatus and 32-bit vsstatush. @@ -202,6 +213,9 @@ struct CPURISCVState { target_ulong vstval; target_ulong vsatp; + /* AIA VS-mode CSRs */ + target_ulong vsiselect; + target_ulong mtval2; target_ulong mtinst; @@ -236,6 +250,18 @@ struct CPURISCVState { uint64_t (*rdtime_fn)(uint32_t); uint32_t rdtime_fn_arg; + /* machine specific AIA IMSIC read-modify-write callback */ +#define IMSIC_MAKE_REG(__isel, __priv, __virt, __vgein) \ + ((((__vgein) & 0x3f) << 24) | (((__virt) & 0x1) << 20) | \ + (((__priv) & 0x3) << 16) | (__isel & 0xffff)) +#define IMSIC_REG_ISEL(__reg) ((__reg) & 0xffff) +#define IMSIC_REG_PRIV(__reg) (((__reg) >> 16) & 0x3) +#define IMSIC_REG_VIRT(__reg) (((__reg) >> 20) & 0x1) +#define IMSIC_REG_VGEIN(__reg) (((__reg) >> 24) & 0x3f) + int (*imsic_rmw_fn)(void *arg, target_ulong reg, target_ulong *val, + target_ulong new_val, target_ulong write_mask); + void *imsic_rmw_fn_arg; + /* True if in debugger mode. */ bool debugger; #endif @@ -335,6 +361,11 @@ int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, int cpuid, void *opaque); int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); +int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero); +uint8_t riscv_cpu_default_priority(int irq); +int riscv_cpu_mirq_pending(CPURISCVState *env); +int riscv_cpu_sirq_pending(CPURISCVState *env); +int riscv_cpu_vsirq_pending(CPURISCVState *env); bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request); bool riscv_cpu_fp_enabled(CPURISCVState *env); bool riscv_cpu_virt_enabled(CPURISCVState *env); @@ -364,9 +395,16 @@ void riscv_cpu_list(void); #ifndef CONFIG_USER_ONLY void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env); -int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts); -uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value); +int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts); +uint64_t riscv_cpu_update_mip(RISCVCPU *cpu, uint64_t mask, uint64_t value); #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */ +void riscv_cpu_set_imsic_rmw_fn(CPURISCVState *env, + int (*rmw_fn)(void *arg, + target_ulong reg, + target_ulong *val, + target_ulong new_val, + target_ulong write_mask), + void *rmw_fn_arg); void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), uint32_t arg); #endif diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 21c54ef561..5b06b4f995 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -36,44 +36,219 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) } #ifndef CONFIG_USER_ONLY -static int riscv_cpu_local_irq_pending(CPURISCVState *env) + +/* + * The HS-mode is allowed to configure priority only for the + * following VS-mode local interrupts: + * + * 0 (Reserved interrupt, reads as zero) + * 1 Supervisor software interrupt + * 4 (Reserved interrupt, reads as zero) + * 5 Supervisor timer interrupt + * 8 (Reserved interrupt, reads as zero) + * 13 (Reserved interrupt) + * 14 " + * 15 " + * 16 " + * 18 Debug/trace interrupt + * 20 (Reserved interrupt) + * 22 ” + * 24 ” + * 26 ” + * 28 " + * 30 (Reserved for standard reporting of bus or system errors) + */ + +static int hviprio_index2irq[] = + { 0, 1, 4, 5, 8, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30 }; +static int hviprio_index2rdzero[] = + { 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero) { - target_ulong irqs; + if (index < 0 || ARRAY_SIZE(hviprio_index2irq) <= index) { + return -EINVAL; + } - target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE); - target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE); - target_ulong hs_mstatus_sie = get_field(env->mstatus_hs, MSTATUS_SIE); + if (out_irq) { + *out_irq = hviprio_index2irq[index]; + } + + if (out_rdzero) { + *out_rdzero = hviprio_index2rdzero[index]; + } - target_ulong pending = env->mip & env->mie & - ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); - target_ulong vspending = (env->mip & env->mie & - (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)); + return 0; +} - target_ulong mie = env->priv < PRV_M || - (env->priv == PRV_M && mstatus_mie); - target_ulong sie = env->priv < PRV_S || - (env->priv == PRV_S && mstatus_sie); - target_ulong hs_sie = env->priv < PRV_S || - (env->priv == PRV_S && hs_mstatus_sie); +uint8_t riscv_cpu_default_priority(int irq) +{ + int u, l; + uint8_t iprio = IPRIO_MMAXIPRIO; - if (riscv_cpu_virt_enabled(env)) { - target_ulong pending_hs_irq = pending & -hs_sie; + if (irq < 0 || irq > 63) { + return iprio; + } - if (pending_hs_irq) { - riscv_cpu_set_force_hs_excep(env, FORCE_HS_EXCEP); - return ctz64(pending_hs_irq); + /* + * Default priorities of local interrupts are defined in the + * RISC-V Advanced Interrupt Architecture specification. + * + * ---------------------------------------------------------------- + * Default | + * Priority | Major Interrupt Numbers + * ---------------------------------------------------------------- + * Highest | 63 (3f), 62 (3e), 31 (1f), 30 (1e), 61 (3d), 60 (3c), + * | 59 (3b), 58 (3a), 29 (1d), 28 (1c), 57 (39), 56 (38), + * | 55 (37), 54 (36), 27 (1b), 26 (1a), 53 (35), 52 (34), + * | 51 (33), 50 (32), 25 (19), 24 (18), 49 (31), 48 (30) + * | + * | 11 (0b), 3 (03), 7 (07) + * | 9 (09), 1 (01), 5 (05) + * | 12 (0c) + * | 10 (0a), 2 (02), 6 (06) + * | + * | 47 (2f), 46 (2e), 23 (17), 22 (16), 45 (2d), 44 (2c), + * | 43 (2b), 42 (2a), 21 (15), 20 (14), 41 (29), 40 (28), + * | 39 (27), 38 (26), 19 (13), 18 (12), 37 (25), 36 (24), + * Lowest | 35 (23), 34 (22), 17 (11), 16 (10), 33 (21), 32 (20) + * ---------------------------------------------------------------- + */ + + u = IPRIO_DEFAULT_U(irq); + l = IPRIO_DEFAULT_L(irq); + if (u == 0) { + if (irq == IRQ_VS_EXT || irq == IRQ_VS_TIMER || + irq == IRQ_VS_SOFT) { + iprio = IPRIO_DEFAULT_VS; + } else if (irq == IRQ_S_GEXT) { + iprio = IPRIO_DEFAULT_SGEXT; + } else if (irq == IRQ_S_EXT || irq == IRQ_S_TIMER || + irq == IRQ_S_SOFT) { + iprio = IPRIO_DEFAULT_S; + } else if (irq == IRQ_M_EXT || irq == IRQ_M_TIMER || + irq == IRQ_M_SOFT) { + iprio = IPRIO_DEFAULT_M; + } else { + iprio = IPRIO_DEFAULT_VS; } + } else if (u == 1) { + if (l < 8) { + iprio = IPRIO_DEFAULT_16_23(irq); + } else { + iprio = IPRIO_DEFAULT_24_31(irq); + } + } else if (u == 2) { + iprio = IPRIO_DEFAULT_32_47(irq); + } else if (u == 3) { + iprio = IPRIO_DEFAULT_48_63(irq); + } + + return iprio; +} + +static int riscv_cpu_pending_to_irq(CPURISCVState *env, + uint64_t pending, uint8_t *iprio) +{ + int irq, best_irq = EXCP_NONE; + unsigned int prio, best_prio = UINT_MAX; - pending = vspending; + if (!pending) { + return EXCP_NONE; } - irqs = (pending & ~env->mideleg & -mie) | (pending & env->mideleg & -sie); + irq = ctz64(pending); + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return irq; + } - if (irqs) { - return ctz64(irqs); /* since non-zero */ + pending = pending >> irq; + while (pending) { + prio = iprio[irq]; + if (!prio) { + prio = (riscv_cpu_default_priority(irq) < IPRIO_DEFAULT_M) ? + 1 : IPRIO_MMAXIPRIO; + } + if ((pending & 0x1) && (prio < best_prio)) { + best_irq = irq; + best_prio = prio; + } + irq++; + pending = pending >> 1; + } + + return best_irq; +} + +int riscv_cpu_mirq_pending(CPURISCVState *env) +{ + uint64_t irqs = env->mip & env->mie & ~env->mideleg & + ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + + return riscv_cpu_pending_to_irq(env, irqs, env->miprio); +} + +int riscv_cpu_sirq_pending(CPURISCVState *env) +{ + uint64_t irqs = env->mip & env->mie & env->mideleg & + ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + + return riscv_cpu_pending_to_irq(env, irqs, env->siprio); +} + +int riscv_cpu_vsirq_pending(CPURISCVState *env) +{ + uint64_t irqs = env->mip & env->mie & env->mideleg & + (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + + return riscv_cpu_pending_to_irq(env, irqs >> 1, env->hviprio); +} + +static int riscv_cpu_local_irq_pending(CPURISCVState *env) +{ + int virq; + uint64_t irqs, mie, sie, vsie; + uint64_t pending, vspending; + + /* Determine interrupt enable state of all privilege modes */ + if (riscv_cpu_virt_enabled(env)) { + mie = 1; + sie = 1; + vsie = (env->priv < PRV_S) || + (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_SIE)); } else { - return EXCP_NONE; /* indicates no pending interrupt */ + mie = (env->priv < PRV_M) || + (env->priv == PRV_M && get_field(env->mstatus, MSTATUS_MIE)); + sie = (env->priv < PRV_S) || + (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_SIE)); + vsie = 0; + } + + /* Check M-mode interrupts */ + pending = env->mip & env->mie & + ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + irqs = pending & ~env->mideleg & -mie; + if (irqs) { + return riscv_cpu_pending_to_irq(env, irqs, env->miprio); + } + + /* Check HS-mode interrupts */ + irqs = pending & env->mideleg & -sie; + if (irqs) { + return riscv_cpu_pending_to_irq(env, irqs, env->siprio); + } + + /* Check VS-mode interrupts */ + vspending = env->mip & env->mie & + (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + irqs = vspending & env->hideleg & -vsie; + if (irqs) { + virq = riscv_cpu_pending_to_irq(env, irqs >> 1, env->hviprio); + return (virq <= 0) ? virq : virq + 1; } + + /* Indicates no pending interrupt */ + return EXCP_NONE; } #endif @@ -213,7 +388,7 @@ bool riscv_cpu_two_stage_lookup(int mmu_idx) return mmu_idx & TB_FLAGS_PRIV_HYP_ACCESS_MASK; } -int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts) +int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts) { CPURISCVState *env = &cpu->env; if (env->miclaim & interrupts) { @@ -224,11 +399,11 @@ int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint32_t interrupts) } } -uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) +uint64_t riscv_cpu_update_mip(RISCVCPU *cpu, uint64_t mask, uint64_t value) { CPURISCVState *env = &cpu->env; CPUState *cs = CPU(cpu); - uint32_t old = env->mip; + uint64_t old = env->mip; bool locked = false; if (!qemu_mutex_iothread_locked()) { @@ -251,6 +426,18 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) return old; } +void riscv_cpu_set_imsic_rmw_fn(CPURISCVState *env, + int (*rmw_fn)(void *arg, + target_ulong reg, + target_ulong *val, + target_ulong new_val, + target_ulong write_mask), + void *rmw_fn_arg) +{ + env->imsic_rmw_fn = rmw_fn; + env->imsic_rmw_fn_arg = rmw_fn_arg; +} + void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), uint32_t arg) { @@ -904,7 +1091,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) */ bool async = !!(cs->exception_index & RISCV_EXCP_INT_FLAG); target_ulong cause = cs->exception_index & RISCV_EXCP_INT_MASK; - target_ulong deleg = async ? env->mideleg : env->medeleg; + uint64_t deleg = async ? env->mideleg : env->medeleg; bool write_tval = false; target_ulong tval = 0; target_ulong htval = 0; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d2585395bf..3c016d7452 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -153,11 +153,56 @@ static int any32(CPURISCVState *env, int csrno) } +static int aia_any(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return -RISCV_EXCP_ILLEGAL_INST; + } + + return any(env, csrno); +} + +static int aia_any32(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return -RISCV_EXCP_ILLEGAL_INST; + } + + return any32(env, csrno); +} + static int smode(CPURISCVState *env, int csrno) { return -!riscv_has_ext(env, RVS); } +static int smode32(CPURISCVState *env, int csrno) +{ + if (!riscv_cpu_is_32bit(env)) { + return -RISCV_EXCP_ILLEGAL_INST; + } + + return smode(env, csrno); +} + +static int aia_smode(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return -RISCV_EXCP_ILLEGAL_INST; + } + + return smode(env, csrno); +} + +static int aia_smode32(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return -RISCV_EXCP_ILLEGAL_INST; + } + + return smode32(env, csrno); +} + static int hmode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS) && @@ -177,11 +222,28 @@ static int hmode(CPURISCVState *env, int csrno) static int hmode32(CPURISCVState *env, int csrno) { if (!riscv_cpu_is_32bit(env)) { - return 0; + return -RISCV_EXCP_ILLEGAL_INST; + } + + return hmode(env, csrno); +} + +static int aia_hmode(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return -RISCV_EXCP_ILLEGAL_INST; } return hmode(env, csrno); +} +static int aia_hmode32(CPURISCVState *env, int csrno) +{ + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return -RISCV_EXCP_ILLEGAL_INST; + } + + return hmode32(env, csrno); } static int pmp(CPURISCVState *env, int csrno) @@ -388,14 +450,16 @@ static int read_timeh(CPURISCVState *env, int csrno, target_ulong *val) /* Machine constants */ -#define M_MODE_INTERRUPTS (MIP_MSIP | MIP_MTIP | MIP_MEIP) -#define S_MODE_INTERRUPTS (MIP_SSIP | MIP_STIP | MIP_SEIP) -#define VS_MODE_INTERRUPTS (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP) +#define M_MODE_INTERRUPTS ((uint64_t)(MIP_MSIP | MIP_MTIP | MIP_MEIP)) +#define S_MODE_INTERRUPTS ((uint64_t)(MIP_SSIP | MIP_STIP | MIP_SEIP)) +#define VS_MODE_INTERRUPTS ((uint64_t)(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)) + +#define TLOWBITS64 ((uint64_t)((target_ulong)-1)) -static const target_ulong delegable_ints = S_MODE_INTERRUPTS | - VS_MODE_INTERRUPTS; -static const target_ulong all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | - VS_MODE_INTERRUPTS; +static const uint64_t delegable_ints = S_MODE_INTERRUPTS | + VS_MODE_INTERRUPTS; +static const uint64_t all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | + VS_MODE_INTERRUPTS; static const target_ulong delegable_excps = (1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | @@ -419,10 +483,10 @@ static const target_ulong delegable_excps = static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD; -static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; -static const target_ulong hip_writable_mask = MIP_VSSIP; -static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; -static const target_ulong vsip_writable_mask = MIP_VSSIP; +static const uint64_t sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; +static const uint64_t hip_writable_mask = MIP_VSSIP; +static const uint64_t hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; +static const uint64_t vsip_writable_mask = MIP_VSSIP; static const char valid_vm_1_10_32[16] = { [VM_1_10_MBARE] = 1, @@ -596,7 +660,437 @@ static int read_mideleg(CPURISCVState *env, int csrno, target_ulong *val) static int write_mideleg(CPURISCVState *env, int csrno, target_ulong val) { - env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints); + uint64_t mask = delegable_ints & TLOWBITS64; + + env->mideleg = (env->mideleg & ~mask) | (val & mask); + if (riscv_has_ext(env, RVH)) { + env->mideleg |= VS_MODE_INTERRUPTS; + } + return 0; +} + +static int aia_xlate_vs_csrno(CPURISCVState *env, int csrno) +{ + if (!riscv_cpu_virt_enabled(env)) { + return csrno; + } + + switch (csrno) { + case CSR_SISELECT: + return CSR_VSISELECT; + case CSR_SIREG: + return CSR_VSIREG; + case CSR_STOPI: + return CSR_VSTOPI; + case CSR_SSETEIPNUM: + return CSR_VSSETEIPNUM; + case CSR_SCLREIPNUM: + return CSR_VSCLREIPNUM; + case CSR_SSETEIENUM: + return CSR_VSSETEIENUM; + case CSR_SCLREIENUM: + return CSR_VSCLREIENUM; + default: + return csrno; + }; +} + +static int rmw_xiselect(CPURISCVState *env, int csrno, target_ulong *val, + target_ulong new_val, target_ulong write_mask) +{ + target_ulong *iselect; + + switch (csrno) { + case CSR_MISELECT: + iselect = &env->miselect; + break; + case CSR_SISELECT: + iselect = riscv_cpu_virt_enabled(env) ? + &env->vsiselect : &env->siselect; + break; + case CSR_VSISELECT: + iselect = &env->vsiselect; + break; + default: + return -RISCV_EXCP_ILLEGAL_INST; + }; + + if (val) { + *val = *iselect; + } + + if (write_mask) { + *iselect = (*iselect & ~write_mask) | (new_val & write_mask); + } + + return 0; +} + +static int rmw_iprio(target_ulong iselect, uint8_t *iprio, + target_ulong *val, target_ulong new_val, + target_ulong write_mask) +{ + int i, firq, nirqs; + target_ulong old_val; + + if (iselect < ISELECT_IPRIO0 || ISELECT_IPRIO15 < iselect) { + return -EINVAL; + } +#if TARGET_LONG_BITS == 64 + if (iselect & 0x1) { + return -EINVAL; + } +#endif + + nirqs = 4 * (TARGET_LONG_BITS / 32); + firq = ((iselect - ISELECT_IPRIO0) / (TARGET_LONG_BITS / 32)) * (nirqs); + + old_val = 0; + for (i = 0; i < nirqs; i++) { + old_val |= ((target_ulong)iprio[firq + i]) << (IPRIO_IRQ_BITS * i); + } + + if (val) { + *val = old_val; + } + + if (write_mask) { + new_val = (old_val & ~write_mask) | (new_val & write_mask); + for (i = 0; i < nirqs; i++) { + iprio[firq + i] = (new_val >> (IPRIO_IRQ_BITS * i)) & 0xff; + } + } + + return 0; +} + +static int rmw_xireg(CPURISCVState *env, int csrno, target_ulong *val, + target_ulong new_val, target_ulong write_mask) +{ + bool virt; + uint8_t *iprio; + int ret = -EINVAL; + target_ulong priv, isel, vgein; + + /* Translate CSR number for VS-mode */ + csrno = aia_xlate_vs_csrno(env, csrno); + + /* Decode register details from CSR number */ + virt = false; + switch (csrno) { + case CSR_MIREG: + iprio = env->miprio; + isel = env->miselect; + priv = PRV_M; + break; + case CSR_SIREG: + iprio = env->siprio; + isel = env->siselect; + priv = PRV_S; + break; + case CSR_VSIREG: + iprio = env->hviprio; + isel = env->vsiselect; + priv = PRV_S; + virt = true; + break; + default: + goto done; + }; + + /* Find the selected guest interrupt file */ + vgein = (virt) ? (env->hstatus & HSTATUS_VGEIN) >> HSTATUS_VGEIN_SHIFT : 0; + + if (ISELECT_IPRIO0 <= isel && isel <= ISELECT_IPRIO15) { + /* Local interrupt priority registers not available for VS-mode */ + if (!virt) { + ret = rmw_iprio(isel, iprio, val, new_val, write_mask); + } + } else if (ISELECT_IMSIC_FIRST <= isel && isel <= ISELECT_IMSIC_LAST) { + /* IMSIC registers only available when machine implements it. */ + if (env->imsic_rmw_fn) { + /* Selected guest interrupt file should not be zero */ + if (virt && !vgein) { + goto done; + } + /* Call machine specific IMSIC register emulation */ + ret = env->imsic_rmw_fn(env->imsic_rmw_fn_arg, + IMSIC_MAKE_REG(isel, priv, virt, vgein), + val, new_val, write_mask); + } + } + +done: + if (ret) { + return (riscv_cpu_virt_enabled(env) && virt) ? + -RISCV_EXCP_VIRT_INSTRUCTION_FAULT : -RISCV_EXCP_ILLEGAL_INST; + } + return 0; +} + +static int read_mtopi(CPURISCVState *env, int csrno, target_ulong *val) +{ + int irq; + + irq = riscv_cpu_mirq_pending(env); + if (irq <= 0 || irq > 63) { + *val = 0; + } else { + *val = (irq & TOPI_IID_MASK) << TOPI_IID_SHIFT; + *val |= env->miprio[irq]; + } + + return 0; +} + +static int read_xsetclreinum(CPURISCVState *env, int csrno, target_ulong *val) +{ + bool virt; + int ret = -EINVAL; + target_ulong vgein; + + /* Translate CSR number for VS-mode */ + csrno = aia_xlate_vs_csrno(env, csrno); + + /* Decode register details from CSR number */ + virt = false; + switch (csrno) { + case CSR_MSETEIPNUM: + case CSR_MCLREIPNUM: + case CSR_MSETEIENUM: + case CSR_MCLREIENUM: + case CSR_SSETEIPNUM: + case CSR_SCLREIPNUM: + case CSR_SSETEIENUM: + case CSR_SCLREIENUM: + break; + case CSR_VSSETEIPNUM: + case CSR_VSCLREIPNUM: + case CSR_VSSETEIENUM: + case CSR_VSCLREIENUM: + virt = true; + break; + default: + goto done; + }; + + /* IMSIC CSRs only available when machine implements IMSIC. */ + if (!env->imsic_rmw_fn) { + goto done; + } + + /* Find the selected guest interrupt file */ + vgein = (virt) ? (env->hstatus & HSTATUS_VGEIN) >> HSTATUS_VGEIN_SHIFT : 0; + + /* Selected guest interrupt file should not be zero */ + if (virt && !vgein) { + goto done; + } + + /* Set/Clear CSRs always read zero */ + ret = 0; + if (val) { + *val = 0; + } + +done: + if (ret) { + return (riscv_cpu_virt_enabled(env) && virt) ? + -RISCV_EXCP_VIRT_INSTRUCTION_FAULT : -RISCV_EXCP_ILLEGAL_INST; + } + return 0; +} + +static int write_xsetclreinum(CPURISCVState *env, int csrno, target_ulong val) +{ + int ret = -EINVAL; + bool set, pend, virt; + target_ulong priv, isel, vgein; + target_ulong new_val, write_mask; + + /* Translate CSR number for VS-mode */ + csrno = aia_xlate_vs_csrno(env, csrno); + + /* Decode register details from CSR number */ + virt = set = pend = false; + switch (csrno) { + case CSR_MSETEIPNUM: + priv = PRV_M; + set = true; + break; + case CSR_MCLREIPNUM: + priv = PRV_M; + pend = true; + break; + case CSR_MSETEIENUM: + priv = PRV_M; + set = true; + break; + case CSR_MCLREIENUM: + priv = PRV_M; + break; + case CSR_SSETEIPNUM: + priv = PRV_S; + set = true; + pend = true; + break; + case CSR_SCLREIPNUM: + priv = PRV_S; + pend = true; + break; + case CSR_SSETEIENUM: + priv = PRV_S; + set = true; + break; + case CSR_SCLREIENUM: + priv = PRV_S; + break; + case CSR_VSSETEIPNUM: + priv = PRV_S; + virt = true; + set = true; + pend = true; + break; + case CSR_VSCLREIPNUM: + priv = PRV_S; + virt = true; + pend = true; + break; + case CSR_VSSETEIENUM: + priv = PRV_S; + virt = true; + set = true; + break; + case CSR_VSCLREIENUM: + priv = PRV_S; + virt = true; + break; + default: + goto done; + }; + + /* IMSIC CSRs only available when machine implements IMSIC. */ + if (!env->imsic_rmw_fn) { + goto done; + } + + /* Find target interrupt pending/enable register */ + if (pend) { + isel = ISELECT_IMSIC_EIP0; + } else { + isel = ISELECT_IMSIC_EIE0; + } + isel += val / IMSIC_EIPx_BITS; + + /* Find the interrupt bit to be set/clear */ + write_mask = 1 << (val % IMSIC_EIPx_BITS); + new_val = (set) ? write_mask : 0; + + /* Find the selected guest interrupt file */ + vgein = (virt) ? (env->hstatus & HSTATUS_VGEIN) >> HSTATUS_VGEIN_SHIFT : 0; + + /* Selected guest interrupt file should not be zero */ + if (virt && !vgein) { + goto done; + } + + /* Call machine specific IMSIC register emulation */ + ret = env->imsic_rmw_fn(env->imsic_rmw_fn_arg, + IMSIC_MAKE_REG(isel, priv, virt, vgein), + NULL, new_val, write_mask); + +done: + if (ret) { + return (riscv_cpu_virt_enabled(env) && virt) ? + -RISCV_EXCP_VIRT_INSTRUCTION_FAULT : -RISCV_EXCP_ILLEGAL_INST; + } + return 0; +} + +static int read_xclaimei(CPURISCVState *env, int csrno, target_ulong *val) +{ + bool virt; + int ret = -EINVAL; + target_ulong priv, isel, vgein; + target_ulong topei, write_mask; + + /* Decode register details from CSR number */ + virt = false; + switch (csrno) { + case CSR_MCLAIMEI: + priv = PRV_M; + break; + case CSR_SCLAIMEI: + priv = PRV_S; + virt = riscv_cpu_virt_enabled(env); + break; + default: + goto done; + }; + + /* IMSIC CSRs only available when machine implements IMSIC. */ + if (!env->imsic_rmw_fn) { + goto done; + } + + /* Find the selected guest interrupt file */ + vgein = (virt) ? (env->hstatus & HSTATUS_VGEIN) >> HSTATUS_VGEIN_SHIFT : 0; + + /* Selected guest interrupt file should not be zero */ + if (virt && !vgein) { + goto done; + } + + /* Call machine specific IMSIC register emulation for reading TOPEI */ + ret = env->imsic_rmw_fn(env->imsic_rmw_fn_arg, + IMSIC_MAKE_REG(ISELECT_IMSIC_TOPEI, priv, virt, vgein), + &topei, -1, 0); + if (ret) { + goto done; + } + + /* If no interrupt pending then we are done */ + if (!topei) { + goto done; + } + + /* Find target interrupt pending register */ + isel = ISELECT_IMSIC_EIP0; + isel += ((topei >> TOPI_IID_SHIFT) / IMSIC_EIPx_BITS); + + /* Find the interrupt bit to be cleared */ + write_mask = 1 << ((topei >> TOPI_IID_SHIFT) % IMSIC_EIPx_BITS); + + /* Call machine specific IMSIC register emulation to clear pending bit */ + ret = env->imsic_rmw_fn(env->imsic_rmw_fn_arg, + IMSIC_MAKE_REG(isel, priv, virt, vgein), + NULL, 0, write_mask); + + /* Update return value */ + if (val) { + *val = topei; + } + +done: + if (ret) { + return (riscv_cpu_virt_enabled(env) && virt) ? + -RISCV_EXCP_VIRT_INSTRUCTION_FAULT : -RISCV_EXCP_ILLEGAL_INST; + } + return 0; +} + +static int read_midelegh(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val = (env->mideleg >> 32); + return 0; +} + +static int write_midelegh(CPURISCVState *env, int csrno, target_ulong val) +{ + uint64_t mask = delegable_ints & ~TLOWBITS64; + uint64_t newval = ((uint64_t)val) << 32; + + env->mideleg = (env->mideleg & ~mask) | (newval & mask); if (riscv_has_ext(env, RVH)) { env->mideleg |= VS_MODE_INTERRUPTS; } @@ -611,7 +1105,24 @@ static int read_mie(CPURISCVState *env, int csrno, target_ulong *val) static int write_mie(CPURISCVState *env, int csrno, target_ulong val) { - env->mie = (env->mie & ~all_ints) | (val & all_ints); + uint64_t mask = all_ints & TLOWBITS64; + + env->mie = (env->mie & ~mask) | (val & mask); + return 0; +} + +static int read_mieh(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val = (env->mie >> 32); + return 0; +} + +static int write_mieh(CPURISCVState *env, int csrno, target_ulong val) +{ + uint64_t mask = all_ints & ~TLOWBITS64; + uint64_t newval = ((uint64_t)val) << 32; + + env->mie = (env->mie & ~mask) | (newval & mask); return 0; } @@ -718,8 +1229,9 @@ static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, { RISCVCPU *cpu = env_archcpu(env); /* Allow software control of delegable interrupts not claimed by hardware */ - target_ulong mask = write_mask & delegable_ints & ~env->miclaim; - uint32_t old_mip; + uint64_t mask = ((uint64_t)write_mask) & delegable_ints & + ~env->miclaim & TLOWBITS64; + uint64_t old_mip; if (mask) { old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask)); @@ -734,6 +1246,29 @@ static int rmw_mip(CPURISCVState *env, int csrno, target_ulong *ret_value, return 0; } +static int rmw_miph(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask) +{ + RISCVCPU *cpu = env_archcpu(env); + /* Allow software control of delegable interrupts not claimed by hardware */ + uint64_t mask = ((uint64_t)write_mask << 32) & delegable_ints & + ~env->miclaim & ~TLOWBITS64; + uint64_t new_value64 = (uint64_t)new_value << 32; + uint64_t old_mip; + + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value64 & mask)); + } else { + old_mip = env->mip; + } + + if (ret_value) { + *ret_value = old_mip >> 32; + } + + return 0; +} + /* Supervisor Trap Setup */ static int read_sstatus(CPURISCVState *env, int csrno, target_ulong *val) { @@ -751,39 +1286,103 @@ static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val) static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) { + uint64_t mask = VS_MODE_INTERRUPTS & env->hideleg & TLOWBITS64; + /* Shift the VS bits to their S bit location in vsie */ - *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; + *val = (env->mie & mask) >> 1; + return 0; +} + +static int read_vsieh(CPURISCVState *env, int csrno, target_ulong *val) +{ + uint64_t mask = VS_MODE_INTERRUPTS & env->hideleg & ~TLOWBITS64; + + /* Shift the VS bits to their S bit location in vsieh */ + *val = (env->mie & mask) >> (32 + 1); return 0; } static int read_sie(CPURISCVState *env, int csrno, target_ulong *val) { if (riscv_cpu_virt_enabled(env)) { - read_vsie(env, CSR_VSIE, val); - } else { - *val = env->mie & env->mideleg; + if (env->hvicontrol & HVICONTROL_VTI) { + return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + return read_vsie(env, CSR_VSIE, val); } + + *val = env->mie & env->mideleg; return 0; } static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) { + uint64_t mask = VS_MODE_INTERRUPTS & env->hideleg & + all_ints & TLOWBITS64; + /* Shift the S bits to their VS bit location in mie */ - target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | - ((val << 1) & env->hideleg & VS_MODE_INTERRUPTS); - return write_mie(env, CSR_MIE, newval); + env->mie = (env->mie & ~mask) | ((val << 1) & mask); + + return 0; +} + +static int write_vsieh(CPURISCVState *env, int csrno, target_ulong val) +{ + uint64_t mask = VS_MODE_INTERRUPTS & env->hideleg & + all_ints & ~TLOWBITS64; + uint64_t newval = (uint64_t)val << 32; + + /* Shift the S bits to their VS bit location in mie */ + env->mie = (env->mie & ~mask) | ((newval << 1) & mask); + + return 0; } static int write_sie(CPURISCVState *env, int csrno, target_ulong val) { + uint64_t mask; + if (riscv_cpu_virt_enabled(env)) { - write_vsie(env, CSR_VSIE, val); - } else { - target_ulong newval = (env->mie & ~S_MODE_INTERRUPTS) | - (val & S_MODE_INTERRUPTS); - write_mie(env, CSR_MIE, newval); + if (env->hvicontrol & HVICONTROL_VTI) { + return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + return write_vsie(env, CSR_VSIE, val); + } + + mask = S_MODE_INTERRUPTS & env->mideleg & all_ints & TLOWBITS64; + env->mie = (env->mie & ~mask) | ((uint64_t)val & mask); + + return 0; +} + +static int read_sieh(CPURISCVState *env, int csrno, target_ulong *val) +{ + if (riscv_cpu_virt_enabled(env)) { + if (env->hvicontrol & HVICONTROL_VTI) { + return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + return read_vsieh(env, CSR_VSIEH, val); + } + + *val = ((env->mie & env->mideleg) >> 32); + return 0; +} + +static int write_sieh(CPURISCVState *env, int csrno, target_ulong val) +{ + uint64_t mask, newval; + + if (riscv_cpu_virt_enabled(env)) { + if (env->hvicontrol & HVICONTROL_VTI) { + return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + return write_vsieh(env, CSR_VSIEH, val); } + mask = S_MODE_INTERRUPTS & env->mideleg & all_ints & ~TLOWBITS64; + newval = (uint64_t)val << 32; + + env->mie = (env->mie & ~mask) | (newval & mask); return 0; } @@ -868,29 +1467,110 @@ static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val) static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, target_ulong new_value, target_ulong write_mask) { - /* Shift the S bits to their VS bit location in mip */ - int ret = rmw_mip(env, 0, ret_value, new_value << 1, - (write_mask << 1) & vsip_writable_mask & env->hideleg); - *ret_value &= VS_MODE_INTERRUPTS; - /* Shift the VS bits to their S bit location in vsip */ - *ret_value >>= 1; - return ret; + RISCVCPU *cpu = env_archcpu(env); + /* Allow software control of delegable interrupts not claimed by hardware */ + uint64_t mask = ((uint64_t)write_mask << 1) & delegable_ints & + vsip_writable_mask & env->hideleg & + ~env->miclaim & TLOWBITS64; + uint64_t old_mip; + + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask)); + } else { + old_mip = env->mip; + } + + if (ret_value) { + *ret_value = old_mip & VS_MODE_INTERRUPTS; + } + + return 0; +} + +static int rmw_vsiph(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask) +{ + RISCVCPU *cpu = env_archcpu(env); + /* Allow software control of delegable interrupts not claimed by hardware */ + uint64_t mask = ((uint64_t)write_mask << (32 + 1)) & delegable_ints & + vsip_writable_mask & env->hideleg & + ~env->miclaim & ~TLOWBITS64; + uint64_t new_value64 = (uint64_t)new_value << 32; + uint64_t old_mip; + + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value64 & mask)); + } else { + old_mip = env->mip; + } + + if (ret_value) { + *ret_value = (old_mip & VS_MODE_INTERRUPTS) >> 32; + } + + return 0; } static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, target_ulong new_value, target_ulong write_mask) { - int ret; + RISCVCPU *cpu = env_archcpu(env); + uint64_t mask, old_mip; if (riscv_cpu_virt_enabled(env)) { - ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask); + if (env->hvicontrol & HVICONTROL_VTI) { + return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + return rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask); + } + + /* Allow software control of delegable interrupts not claimed by hardware */ + mask = ((uint64_t)write_mask) & delegable_ints & + env->mideleg & sip_writable_mask & + ~env->miclaim & TLOWBITS64; + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask)); } else { - ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value, - write_mask & env->mideleg & sip_writable_mask); + old_mip = env->mip; } - *ret_value &= env->mideleg; - return ret; + if (ret_value) { + *ret_value = old_mip; + } + + return 0; +} + +static int rmw_siph(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask) +{ + RISCVCPU *cpu = env_archcpu(env); + uint64_t mask, new_value64; + uint64_t old_mip; + + if (riscv_cpu_virt_enabled(env)) { + if (env->hvicontrol & HVICONTROL_VTI) { + return -RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } + return rmw_vsiph(env, CSR_VSIPH, ret_value, new_value, write_mask); + } + + /* Allow software control of delegable interrupts not claimed by hardware */ + mask = ((uint64_t)write_mask << 32) & delegable_ints & + env->mideleg & sip_writable_mask & + ~env->miclaim & ~TLOWBITS64; + new_value64 = (uint64_t)new_value << 32; + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value64 & mask)); + } else { + old_mip = env->mip; + } + + if (ret_value) { + *ret_value = (old_mip & env->mideleg) >> 32; + } + + return 0; } /* Supervisor Protection and Translation */ @@ -930,6 +1610,51 @@ static int write_satp(CPURISCVState *env, int csrno, target_ulong val) return 0; } +static int read_vstopi(CPURISCVState *env, int csrno, target_ulong *val) +{ + int irq, hiid; + uint8_t hiprio, iprio; + + irq = riscv_cpu_vsirq_pending(env); + if (irq <= 0 || irq > 63) { + *val = 0; + } else { + *val = (irq & TOPI_IID_MASK) << TOPI_IID_SHIFT; + iprio = env->hviprio[irq]; + /* TODO: This needs to improve in specification */ + if (!(env->hstatus & HSTATUS_VGEIN)) { + hiid = (env->hvicontrol & HVICONTROL_IID_MASK) >> + HVICONTROL_IID_SHIFT; + hiprio = env->hvicontrol & HVICONTROL_IPRIO_MASK; + if (irq == hiid && hiprio) { + iprio = hiprio; + } + } + *val |= iprio; + } + + return 0; +} + +static int read_stopi(CPURISCVState *env, int csrno, target_ulong *val) +{ + int irq; + + if (riscv_cpu_virt_enabled(env)) { + return read_vstopi(env, CSR_VSTOPI, val); + } + + irq = riscv_cpu_sirq_pending(env); + if (irq <= 0 || irq > 63) { + *val = 0; + } else { + *val = (irq & TOPI_IID_MASK) << TOPI_IID_SHIFT; + *val |= env->siprio[irq]; + } + + return 0; +} + /* Hypervisor Extensions */ static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) { @@ -979,26 +1704,90 @@ static int write_hideleg(CPURISCVState *env, int csrno, target_ulong val) return 0; } +static int read_hidelegh(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val = env->hideleg >> 32; + return 0; +} + +static int write_hidelegh(CPURISCVState *env, int csrno, target_ulong val) +{ + uint64_t mask = ~TLOWBITS64; + uint64_t newval = ((uint64_t)val) << 32; + + env->hideleg = (env->hideleg & ~mask) | (newval & mask); + + return 0; +} + static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, target_ulong new_value, target_ulong write_mask) { - int ret = rmw_mip(env, 0, ret_value, new_value, - write_mask & hvip_writable_mask); + RISCVCPU *cpu = env_archcpu(env); + /* Allow software control of delegable interrupts not claimed by hardware */ + uint64_t mask = ((uint64_t)write_mask) & delegable_ints & + hvip_writable_mask & + ~env->miclaim & TLOWBITS64; + uint64_t old_mip; + + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask)); + } else { + old_mip = env->mip; + } - *ret_value &= hvip_writable_mask; + if (ret_value) { + *ret_value = old_mip & hvip_writable_mask; + } - return ret; + return 0; +} + +static int rmw_hviph(CPURISCVState *env, int csrno, target_ulong *ret_value, + target_ulong new_value, target_ulong write_mask) +{ + RISCVCPU *cpu = env_archcpu(env); + /* Allow software control of delegable interrupts not claimed by hardware */ + uint64_t mask = ((uint64_t)write_mask << 32) & delegable_ints & + hvip_writable_mask & + ~env->miclaim & ~TLOWBITS64; + uint64_t new_value64 = (uint64_t)new_value << 32; + uint64_t old_mip; + + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value64 & mask)); + } else { + old_mip = env->mip; + } + + if (ret_value) { + *ret_value = (old_mip & hvip_writable_mask) >> 32; + } + + return 0; } static int rmw_hip(CPURISCVState *env, int csrno, target_ulong *ret_value, target_ulong new_value, target_ulong write_mask) { - int ret = rmw_mip(env, 0, ret_value, new_value, - write_mask & hip_writable_mask); + RISCVCPU *cpu = env_archcpu(env); + /* Allow software control of delegable interrupts not claimed by hardware */ + uint64_t mask = ((uint64_t)write_mask) & delegable_ints & + hip_writable_mask & + ~env->miclaim & TLOWBITS64; + uint64_t old_mip; - *ret_value &= hip_writable_mask; + if (mask) { + old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask)); + } else { + old_mip = env->mip; + } - return ret; + if (ret_value) { + *ret_value = old_mip & hip_writable_mask; + } + + return 0; } static int read_hie(CPURISCVState *env, int csrno, target_ulong *val) @@ -1009,8 +1798,9 @@ static int read_hie(CPURISCVState *env, int csrno, target_ulong *val) static int write_hie(CPURISCVState *env, int csrno, target_ulong val) { - target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | (val & VS_MODE_INTERRUPTS); - return write_mie(env, CSR_MIE, newval); + uint64_t mask = VS_MODE_INTERRUPTS & all_ints & TLOWBITS64; + env->mie = (env->mie & ~mask) | ((uint64_t)val & mask); + return 0; } static int read_hcounteren(CPURISCVState *env, int csrno, target_ulong *val) @@ -1128,6 +1918,110 @@ static int write_htimedeltah(CPURISCVState *env, int csrno, target_ulong val) return 0; } +static int read_hvicontrol(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val = env->hvicontrol; + return 0; +} + +static int write_hvicontrol(CPURISCVState *env, int csrno, target_ulong val) +{ + env->hvicontrol = val & HVICONTROL_VALID_MASK; + return 0; +} + +static int read_hvipriox(CPURISCVState *env, int first_index, + uint8_t *iprio, target_ulong *val) +{ + int i, irq, rdzero, num_irqs = 4 * (TARGET_LONG_BITS / 32); + + /* First index has to be multiple of numbe of irqs per register */ + if (first_index % num_irqs) { + return (riscv_cpu_virt_enabled(env)) ? + -RISCV_EXCP_VIRT_INSTRUCTION_FAULT : -RISCV_EXCP_ILLEGAL_INST; + } + + /* Fill-up return value */ + *val = 0; + for (i = 0; i < num_irqs; i++) { + if (riscv_cpu_hviprio_index2irq(first_index + i, &irq, &rdzero)) { + continue; + } + if (rdzero) { + continue; + } + *val |= ((target_ulong)iprio[irq]) << (i * 8); + } + + return 0; +} + +static int write_hvipriox(CPURISCVState *env, int first_index, + uint8_t *iprio, target_ulong val) +{ + int i, irq, rdzero, num_irqs = 4 * (TARGET_LONG_BITS / 32); + + /* First index has to be multiple of numbe of irqs per register */ + if (first_index % num_irqs) { + return (riscv_cpu_virt_enabled(env)) ? + -RISCV_EXCP_VIRT_INSTRUCTION_FAULT : -RISCV_EXCP_ILLEGAL_INST; + } + + /* Fill-up priority arrary */ + for (i = 0; i < num_irqs; i++) { + if (riscv_cpu_hviprio_index2irq(first_index + i, &irq, &rdzero)) { + continue; + } + if (rdzero) { + iprio[irq] = 0; + } else { + iprio[irq] = (val >> (i * 8)) & 0xff; + } + } + + return 0; +} + +static int read_hviprio1(CPURISCVState *env, int csrno, target_ulong *val) +{ + return read_hvipriox(env, 0, env->hviprio, val); +} + +static int write_hviprio1(CPURISCVState *env, int csrno, target_ulong val) +{ + return write_hvipriox(env, 0, env->hviprio, val); +} + +static int read_hviprio1h(CPURISCVState *env, int csrno, target_ulong *val) +{ + return read_hvipriox(env, 4, env->hviprio, val); +} + +static int write_hviprio1h(CPURISCVState *env, int csrno, target_ulong val) +{ + return write_hvipriox(env, 4, env->hviprio, val); +} + +static int read_hviprio2(CPURISCVState *env, int csrno, target_ulong *val) +{ + return read_hvipriox(env, 8, env->hviprio, val); +} + +static int write_hviprio2(CPURISCVState *env, int csrno, target_ulong val) +{ + return write_hvipriox(env, 8, env->hviprio, val); +} + +static int read_hviprio2h(CPURISCVState *env, int csrno, target_ulong *val) +{ + return read_hvipriox(env, 12, env->hviprio, val); +} + +static int write_hviprio2h(CPURISCVState *env, int csrno, target_ulong val) +{ + return write_hvipriox(env, 12, env->hviprio, val); +} + /* Virtual CSR Registers */ static int read_vsstatus(CPURISCVState *env, int csrno, target_ulong *val) { @@ -1428,6 +2322,25 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MBADADDR] = { "mbadaddr", any, read_mbadaddr, write_mbadaddr }, [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, + /* Machine-Level Window to Indirectly Accessed Registers (AIA) */ + [CSR_MISELECT] = { "miselect", aia_any, NULL, NULL, rmw_xiselect }, + [CSR_MIREG] = { "mireg", aia_any, NULL, NULL, rmw_xireg }, + + /* Machine-Level Interrupts (AIA) */ + [CSR_MTOPI] = { "mtopi", aia_any, read_mtopi }, + + /* Machine-Level IMSIC Interface (AIA) */ + [CSR_MSETEIPNUM] = { "mseteipnum", aia_any, read_xsetclreinum, write_xsetclreinum }, + [CSR_MCLREIPNUM] = { "mclreipnum", aia_any, read_xsetclreinum, write_xsetclreinum }, + [CSR_MSETEIENUM] = { "mseteienum", aia_any, read_xsetclreinum, write_xsetclreinum }, + [CSR_MCLREIENUM] = { "mclreienum", aia_any, read_xsetclreinum, write_xsetclreinum }, + [CSR_MCLAIMEI] = { "mclaimei", aia_any, read_xclaimei }, + + /* Machine-Level High-Half CSRs (AIA) */ + [CSR_MIDELEGH] = { "midelegh", aia_any32, read_midelegh, write_midelegh }, + [CSR_MIEH] = { "mieh", aia_any32, read_mieh, write_mieh }, + [CSR_MIPH] = { "miph", aia_any32, NULL, NULL, rmw_miph }, + /* Supervisor Trap Setup */ [CSR_SSTATUS] = { "sstatus", smode, read_sstatus, write_sstatus }, [CSR_SIE] = { "sie", smode, read_sie, write_sie }, @@ -1444,6 +2357,24 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Supervisor Protection and Translation */ [CSR_SATP] = { "satp", smode, read_satp, write_satp }, + /* Supervisor-Level Window to Indirectly Accessed Registers (AIA) */ + [CSR_SISELECT] = { "siselect", aia_smode, NULL, NULL, rmw_xiselect }, + [CSR_SIREG] = { "sireg", aia_smode, NULL, NULL, rmw_xireg }, + + /* Supervisor-Level Interrupts (AIA) */ + [CSR_STOPI] = { "stopi", aia_smode, read_stopi }, + + /* Supervisor-Level IMSIC Interface (AIA) */ + [CSR_SSETEIPNUM] = { "sseteipnum", aia_smode, read_xsetclreinum, write_xsetclreinum }, + [CSR_SCLREIPNUM] = { "sclreipnum", aia_smode, read_xsetclreinum, write_xsetclreinum }, + [CSR_SSETEIENUM] = { "sseteienum", aia_smode, read_xsetclreinum, write_xsetclreinum }, + [CSR_SCLREIENUM] = { "sclreienum", aia_smode, read_xsetclreinum, write_xsetclreinum }, + [CSR_SCLAIMEI] = { "sclaimei", aia_smode, read_xclaimei }, + + /* Supervisor-Level High-Half CSRs (AIA) */ + [CSR_SIEH] = { "sieh", aia_smode32, read_sieh, write_sieh }, + [CSR_SIPH] = { "siph", aia_smode32, NULL, NULL, rmw_siph }, + [CSR_HSTATUS] = { "hstatus", hmode, read_hstatus, write_hstatus }, [CSR_HEDELEG] = { "hedeleg", hmode, read_hedeleg, write_hedeleg }, [CSR_HIDELEG] = { "hideleg", hmode, read_hideleg, write_hideleg }, @@ -1472,6 +2403,32 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL2] = { "mtval2", hmode, read_mtval2, write_mtval2 }, [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst }, + /* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ + [CSR_HVICONTROL] = { "hvicontrol", aia_hmode, read_hvicontrol, write_hvicontrol }, + [CSR_HVIPRIO1] = { "hviprio1", aia_hmode, read_hviprio1, write_hviprio1 }, + [CSR_HVIPRIO2] = { "hviprio2", aia_hmode, read_hviprio2, write_hviprio2 }, + + /* VS-Level Window to Indirectly Accessed Registers (H-extension with AIA) */ + [CSR_VSISELECT] = { "vsiselect", aia_hmode, NULL, NULL, rmw_xiselect }, + [CSR_VSIREG] = { "vsireg", aia_hmode, NULL, NULL, rmw_xireg }, + + /* VS-Level Interrupts (H-extension with AIA) */ + [CSR_VSTOPI] = { "vstopi", aia_hmode, read_vstopi }, + + /* VS-Level IMSIC Interface (H-extension with AIA) */ + [CSR_VSSETEIPNUM] = { "vsseteipnum", aia_hmode, read_xsetclreinum, write_xsetclreinum }, + [CSR_VSCLREIPNUM] = { "vsclreipnum", aia_hmode, read_xsetclreinum, write_xsetclreinum }, + [CSR_VSSETEIENUM] = { "vsseteienum", aia_hmode, read_xsetclreinum, write_xsetclreinum }, + [CSR_VSCLREIENUM] = { "vsclreienum", aia_hmode, read_xsetclreinum, write_xsetclreinum }, + + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ + [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, read_hidelegh, write_hidelegh }, + [CSR_HVIPH] = { "hviph", aia_hmode32, NULL, NULL, rmw_hviph }, + [CSR_HVIPRIO1H] = { "hviprio1h", aia_hmode32, read_hviprio1h, write_hviprio1h }, + [CSR_HVIPRIO2H] = { "hviprio2h", aia_hmode32, read_hviprio2h, write_hviprio2h }, + [CSR_VSIEH] = { "vsieh", aia_hmode32, read_vsieh, write_vsieh }, + [CSR_VSIPH] = { "vsiep", aia_hmode32, NULL, NULL, rmw_vsiph }, + /* Physical Memory Protection */ [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 44d4015bd6..f7fa48c240 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -102,19 +102,22 @@ static const VMStateDescription vmstate_vector = { static const VMStateDescription vmstate_hyper = { .name = "cpu/hyper", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .needed = hyper_needed, .fields = (VMStateField[]) { VMSTATE_UINTTL(env.hstatus, RISCVCPU), VMSTATE_UINTTL(env.hedeleg, RISCVCPU), - VMSTATE_UINTTL(env.hideleg, RISCVCPU), + VMSTATE_UINT64(env.hideleg, RISCVCPU), VMSTATE_UINTTL(env.hcounteren, RISCVCPU), VMSTATE_UINTTL(env.htval, RISCVCPU), VMSTATE_UINTTL(env.htinst, RISCVCPU), VMSTATE_UINTTL(env.hgatp, RISCVCPU), VMSTATE_UINT64(env.htimedelta, RISCVCPU), + VMSTATE_UINT8_ARRAY(env.hviprio, RISCVCPU, 64), + VMSTATE_UINTTL(env.hvicontrol, RISCVCPU), + VMSTATE_UINT64(env.vsstatus, RISCVCPU), VMSTATE_UINTTL(env.vstvec, RISCVCPU), VMSTATE_UINTTL(env.vsscratch, RISCVCPU), @@ -122,6 +125,7 @@ static const VMStateDescription vmstate_hyper = { VMSTATE_UINTTL(env.vscause, RISCVCPU), VMSTATE_UINTTL(env.vstval, RISCVCPU), VMSTATE_UINTTL(env.vsatp, RISCVCPU), + VMSTATE_UINTTL(env.vsiselect, RISCVCPU), VMSTATE_UINTTL(env.mtval2, RISCVCPU), VMSTATE_UINTTL(env.mtinst, RISCVCPU), @@ -140,11 +144,13 @@ static const VMStateDescription vmstate_hyper = { const VMStateDescription vmstate_riscv_cpu = { .name = "cpu", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .fields = (VMStateField[]) { VMSTATE_UINTTL_ARRAY(env.gpr, RISCVCPU, 32), VMSTATE_UINT64_ARRAY(env.fpr, RISCVCPU, 32), + VMSTATE_UINT8_ARRAY(env.miprio, RISCVCPU, 64), + VMSTATE_UINT8_ARRAY(env.siprio, RISCVCPU, 64), VMSTATE_UINTTL(env.pc, RISCVCPU), VMSTATE_UINTTL(env.load_res, RISCVCPU), VMSTATE_UINTTL(env.load_val, RISCVCPU), @@ -161,10 +167,10 @@ const VMStateDescription vmstate_riscv_cpu = { VMSTATE_UINTTL(env.resetvec, RISCVCPU), VMSTATE_UINTTL(env.mhartid, RISCVCPU), VMSTATE_UINT64(env.mstatus, RISCVCPU), - VMSTATE_UINTTL(env.mip, RISCVCPU), - VMSTATE_UINT32(env.miclaim, RISCVCPU), - VMSTATE_UINTTL(env.mie, RISCVCPU), - VMSTATE_UINTTL(env.mideleg, RISCVCPU), + VMSTATE_UINT64(env.mip, RISCVCPU), + VMSTATE_UINT64(env.miclaim, RISCVCPU), + VMSTATE_UINT64(env.mie, RISCVCPU), + VMSTATE_UINT64(env.mideleg, RISCVCPU), VMSTATE_UINTTL(env.sptbr, RISCVCPU), VMSTATE_UINTTL(env.satp, RISCVCPU), VMSTATE_UINTTL(env.sbadaddr, RISCVCPU), @@ -177,6 +183,8 @@ const VMStateDescription vmstate_riscv_cpu = { VMSTATE_UINTTL(env.mepc, RISCVCPU), VMSTATE_UINTTL(env.mcause, RISCVCPU), VMSTATE_UINTTL(env.mtval, RISCVCPU), + VMSTATE_UINTTL(env.miselect, RISCVCPU), + VMSTATE_UINTTL(env.siselect, RISCVCPU), VMSTATE_UINTTL(env.scounteren, RISCVCPU), VMSTATE_UINTTL(env.mcounteren, RISCVCPU), VMSTATE_UINTTL(env.sscratch, RISCVCPU), From patchwork Fri May 14 14:32:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12257977 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_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 B25AAC433B4 for ; Fri, 14 May 2021 14:37: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 1CD0D613BE for ; Fri, 14 May 2021 14:37:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CD0D613BE 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]:46582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lhYwj-0001ux-5U for qemu-devel@archiver.kernel.org; Fri, 14 May 2021 10:37:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsZ-0000gr-Cb; Fri, 14 May 2021 10:33:27 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:34538) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lhYsW-0007A7-BA; Fri, 14 May 2021 10:33:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1621002804; x=1652538804; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=El6ly+FwAkzsS1bqEH2tsGfO1DY40r9BUXYYlBuYq10=; b=eLiJi+QfZNYUBCGwvF9fWQNVJVeGwWzNKV1eru6wHtFxycscsNskq+AM Ygsrq07SLbNtWKmTCMebUDrpt2yhckxRU0oNVXjIHLyMhQYUsMtXjZVel 2/wp04j46+EYYaz2xwNQoEMoBzb5LEJwBzdiCTLWCqbnksUh6IGFHpQ8F rXO9W3QJ0A55suGMT85AoZFndNoX0PKhI4N3qg4AN8x5XjyVWN/YaIIXV 4AjkRv9M2jDjAWuJnICf5syv4jHLlNLjnCk2vk0EvcbzKjqwaBVaYVXEr kq4HlFc1j+VL1uloadWSgb70tuORbo9ypIlQmf5FF8LXd3wnwbBSBhTTB A==; IronPort-SDR: R5BZtBBZsxf7yjcdKbF42BbY7UZTt6ePaQEOsrQBWFEAMm6FzorzLgHeSSQNV1z9gqCl5Brykz fSfYUhjGGHNHshJlyLaMK14/l6R7rh4TkVHpdyDks6n+r2z73cUt8VN97LeAxijId0qjGm1SrB nqGhk3CJ2+4tAh1TX+t54iXLK8WPjmAzSB3IUJZEKTMBEOaHU1K62z3QTQrmvsWYb+KrGYQR1D Lx27pr+zcfptlrj6lYYAkIZik68fWmftChpaXqTBiZ3emwxs/UbW3skvly1uHNliOjNAv0TOnX nVQ= X-IronPort-AV: E=Sophos;i="5.82,300,1613404800"; d="scan'208";a="167526819" Received: from mail-sn1anam02lp2045.outbound.protection.outlook.com (HELO NAM02-SN1-obe.outbound.protection.outlook.com) ([104.47.57.45]) by ob1.hgst.iphmx.com with ESMTP; 14 May 2021 22:33:22 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cHQgNelukpMVQS8GKz8ffpYL0PYAzVaRt3S8NrkypViyLZXxtKNL/fISD27PCATBtTxTlVToOWJXi+qcmYLsIO1lgt9rNRUObt5WLbH6uYF9lqwaTXpAB/vT3RjrHwBECgScceKNw/mZVt9oSoOKmbCcVmCLx+HNAWoj7E/+Wnt6XFhKsQKxGkxSsilvBLpdEoIP8E7dxVhTRk0kpx9tY4GvsZwqMV7AwiWg9fa9FuGKjtq/FmLW0VzypvNloLvFOnRqJCH1KGAgtWiBqTbSecXPi9m9OLQAy4PYAlZAbW21K+/h9cJ4HbnnQT8vemIfAlRU2ujVoW5TwTdJ8nPCyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kFa1J7YVbYgSHSjZAWRK077pK2y5y52q/pY9BQUNF8E=; b=fyAE27JcNpIQ2upSM8WtGc2hY5LzNLIvpKawjhtSx1rWzEowxlyfhGL4cl1D+n/mlbAmmrtF0y9D9cZ/dzAeZC6OaUbXBXpWSHScSdLxpKEXjuOthl+qNsoNaPS4dvnaMPUT8HRnr2bqW+gpTFWZRGssTy2wJOOVjVVd+u3z6LCUaNlk92bB0Y/rDJ6WU8fITjUVHbaOhQtIdsRjgWqTC/NbHxpYS2fZdEasynatZk97kPKdI/1Ddptdk32S+y3fVVXU8T6/vLzdXzcPZqNlizDC5Ps0MvKAwQK4wYx/2i07WdFycYrFtTVUyuFR4ZMwc8WnEqKTtiH9IfDPMI4zoQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kFa1J7YVbYgSHSjZAWRK077pK2y5y52q/pY9BQUNF8E=; b=Ft1Q92C9R7+vwkVpGSnelx56OQmij2Qwnv8xBRIxDLq9sQVwlsA7i9+CbQe2f1CeMMl2dhtD2U2AxW0SN1AGlfD5ln0A1IZsNR/Y4vKs1u3Qn+WdfudHleea2KmWIS6lTC+mIvziHUC+oa0BzcGW04Vxjj5nE/9GLPTVLWdUDmE= Authentication-Results: linaro.org; dkim=none (message not signed) header.d=none;linaro.org; dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7810.namprd04.prod.outlook.com (2603:10b6:5:358::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Fri, 14 May 2021 14:33:21 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::88a0:bf18:b01d:1a50%4]) with mapi id 15.20.4129.028; Fri, 14 May 2021 14:33:21 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH 4/4] hw/riscv: virt: Use AIA INTC compatible string when available Date: Fri, 14 May 2021 20:02:42 +0530 Message-Id: <20210514143242.377645-5-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210514143242.377645-1-anup.patel@wdc.com> References: <20210514143242.377645-1-anup.patel@wdc.com> X-Originating-IP: [122.179.90.73] X-ClientProxiedBy: MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from wdc.com (122.179.90.73) by MAXPR0101CA0046.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:d::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Fri, 14 May 2021 14:33:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e9a1868-6fa6-4da9-2534-08d916e53932 X-MS-TrafficTypeDiagnostic: CO6PR04MB7810: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:454; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: avM9kOsZhIUpS+GELvruxvEJczojPkCFG76zVM+SnONE4ApwXr6QPMpZkeH3HSLtuogkpyRYvMZRyH2GTFkjsHScG1WkmXd4iYE9ik+ZhOcjS2U8+5hsAk0C90Cil+4cvOwiI5qqKi+W7+JwLHKfnJ0MN+CC8/s/jtpvp8ZWScSq1vR5XAg1we5kb4+Psk4xxUXtL7ykqpj4x5oSY4vsFZvti/z1MXgVjMdwqWDQl4dT+PP9boj/G2nbw0GwukxKTM5OxEqcrsH4yNImWPee0MsC2OUoVk+V40RQojj9jjd1FM4sRQZnlp+0Lf6EsO2VLou2DQLjyOMiiR0RGhXhIztzOkLv47urreNt+tr/O+hc3HDtOCfPVW51PXmHNQa2BGWQj9235p/kakQmQBAmf7shRkUEn87L3DC8Nlpqq+OtR492XNmI07hBU3KF1/cmk10lHFbUwgJbiT2xRijnrXuJzGMd1w3T84q/tkKeZf53KSflVBxJR8vArsPqazwmYbKWqOj9CHXXCAm+HI702ClMARSLMpDsS6WlFvfOhQvbjRZBzdpO2lwXanobFr2LIHQEuECgLTNSnZ5wpzDQIblpPXNrtvGAG7lmv7geze6puO4GaUE4gPVaVOCW6snlweYJ6MT7BtY9NX5Zr2m4xVQ15rxoiHShOAX0p31b0YU= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39840400004)(396003)(346002)(136003)(376002)(366004)(52116002)(7696005)(1076003)(26005)(5660300002)(38350700002)(83380400001)(86362001)(66556008)(478600001)(36756003)(8886007)(66476007)(66946007)(6666004)(54906003)(16526019)(110136005)(186003)(316002)(8676002)(38100700002)(55016002)(8936002)(956004)(2906002)(2616005)(4326008)(44832011); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: e97xaYqEvOTwRzYPSZz4dqZepn3DmVr6U/kLr0xBxnr137yTH8eMruhUe3uNCrTSEg11vCdPHzdvdg+VlU7Y8bBI5BkO2HkHl9nRlHYqQ1f6InCm4s+KueZfuSBPu9Q47P4CNspPMj5XMJN0xAVCpkEoHFuxIyw0DtHiH6J1izcaeJK5t76w4Y7MKaXcGH7CPgdkRo/TJONCbTMy7jPxib2mp8utExt86JZ6SImVFN6AOEzA05vQJi5BJzgrTh+wxRB7ppUzr7ErfjvuySq0Z9NAHUJ37Optuc2iUl+u5ocntSDyz6pL3ZleRXNPQYsZ5DPgBEgi1G5M0xxjMD3ZQmSW4k+R1pEZld4425D8LKN3jXs1z4RvBIROQCAmVhUBZFUKTAarzgMXETbwOIJuQW76rGcPxF2e/50cy+s782c4LkwUlH8svJvW3NckM4YqUZtwq3hP3+ItkEaJNKvIdwmecv0DNVUx6ZMzKV1hIYQZTZ0jjzJFVU1aGSJu4SpUvssPDoYegQVp8VuAa9L8tZgY0rw/ytSWe6oEQtcpVnIOPiwO1MPsmCgjJQf8+zhb42Co1d+utjCkBV5JRZLgkxCD/spuwnEo234oCTNcshqar2+G9wms7Qhi4kA138sOPAcgWDNW2DIWTVE9hM81pTBBw7GhSjdcuDjrjzGr2G9wkhWIiPjyL53St2Q2/kNovSaw7XH8cueFBbKKmFikKj5UNfOc2JzieK0J53OoJcwoTw8AMydCRqKTuih6K0id2TdPZml9E8M4+ty4uYSmPRZq9TxoPtzWjKnab0y0uCugJw4atKlNMc4qKATpeGuYDxGTovPNxqLBo+hjxFsGrXiFTGQf41IwGwfgJTZGNoNBoFiRfocDDIxOGmkqBGwJq9N+NcGZlRRZ/NMmRJoRSVeTaSO7I/o5/KuIOg/UYax3ueEgMFyJitdrXxL3D5dX3Lr2MWsfF+8vfUxdJ8VEqP+OwKhi4M9qZGEnWhEHDhW6UWI1zcjmV+6uE52aN1iM8ZaSEVGXkb0Ps1H3uUam/GHJRPXVIL3AnA0jaDluPAbvrv60EM0v5o0lXUo47zyRygltP1s4TOspAeiafGhnpmuiTewO6Fn6cFNQCSFTIA3LG/faR1PunWxIoD2yKVs/r9ySjwmE91ME7ntLy+sftr7W2CS0KJ2ymdRgYaUXSOtkPe0DKsZetWDVxqymeHTO3W3v/HrMsXGwTrV6wFY20oqPHEXb/+2eNbLOPwcL/j5psXc0o27FWu9EvmvOp8dkoINiPA4PE0WA5EJdMBiBiX1AHfs/ew637+aBmGdH9hc4T/3I2cTOJQyX6MlIzexx X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e9a1868-6fa6-4da9-2534-08d916e53932 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 May 2021 14:33:21.4307 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QfiFxP31HO1odz3GCVfQTs2vAydFHwchjCjyVNgHYaWFTkFRZV0aLBPsaAH6qBvdh4SVDfzAc7vJIH76BSvIEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7810 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=761afde0a=Anup.Patel@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, MSGID_FROM_MTA_HEADER=0.001, 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: Atish Patra , Anup Patel , qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Anup Patel Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We should use the AIA INTC compatible string in the CPU INTC DT nodes when the CPUs support AIA feature. This will allow Linux INTC driver to use AIA local interrupt CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index c0dc69ff33..981a3a06d5 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -262,8 +262,15 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, qemu_fdt_add_subnode(fdt, intc_name); intc_phandle = phandle++; qemu_fdt_setprop_cell(fdt, intc_name, "phandle", intc_phandle); - qemu_fdt_setprop_string(fdt, intc_name, "compatible", - "riscv,cpu-intc"); + if (riscv_feature(&s->soc[socket].harts[cpu].env, + RISCV_FEATURE_AIA)) { + const char intcomp[] = "riscv,cpu-intc-aia\0riscv,cpu-intc"; + qemu_fdt_setprop(fdt, name, "compatible", + intcomp, sizeof(intcomp)); + } else { + qemu_fdt_setprop_string(fdt, intc_name, "compatible", + "riscv,cpu-intc"); + } qemu_fdt_setprop(fdt, intc_name, "interrupt-controller", NULL, 0); qemu_fdt_setprop_cell(fdt, intc_name, "#interrupt-cells", 1);