From patchwork Tue Oct 26 06:42:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7D02C433EF for ; Tue, 26 Oct 2021 07:39:04 +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 428EF610A0 for ; Tue, 26 Oct 2021 07:39:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 428EF610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:42988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfH31-0003m0-ET for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:39:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGAw-00034i-5f; Tue, 26 Oct 2021 02:43:12 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:17119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGAr-0008LU-0S; Tue, 26 Oct 2021 02:43:07 -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=1635230584; x=1666766584; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=LZY9aIog688ACRn9v1sFVo0EZJ0feFHY9C5xQBrGttQ=; b=lApmzs7oj4xfl1EjHdROth9JLYNqHhUfVkmKJcyZdR3Jo38y8Yss07n/ iVmmzqr6rtKERIqeQ8CiMfFq64gfTnCmUJrHLEPEBuoPKVY01MendWlEt Z5Nk+tAkan9vfRi6ZrsrrVZ09aOvg9uuYXF0Yxmzpx/tVFHOwdwWhUm1o ZHXORSM8ZC3eSLWeoBK3tY+byRpr44tmYuv2mpItIj/1RZnl5TwYOW928 iuzLOEZfNuKsmIJ/bN1iCwZXfOEsGAvp41Ey2uC2iWwQi5bQVbScrTwkn rSoxJXAGxIb9HLHjRXwZrOwPnKsANKpHve817cK4fuymuNKXN4jTUzjjA w==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="188620387" Received: from mail-dm6nam08lp2041.outbound.protection.outlook.com (HELO NAM04-DM6-obe.outbound.protection.outlook.com) ([104.47.73.41]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:42:58 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QtmDj3RTPwjpXWLqmGxeZIb2Jb0yHJ3GNWpWn1kAkdWDkldg+FPqUTp6djb1EfIYM+1LP7CCWjnzA2uClBh8eQeY7gxBjV1XlYh16jevgAuxBfeepovVMjLw0+by4exFw0cPBhSvc2x+VU2B5lEPkjyCT7v2PNpKRWuBqg1BjHzxJk5MfQEUFiPOaC0xzMiU9/e252/cNEniVDSl/hsaFzCzd/PF8OBGBwwHWxAjrw7DlCSffz9DeigIaLMmNJe6fGJJRwaSuYpGO9+xWt4O/xiEyYUBEgHWb9keb6SVimFwfWGSutZX+EZZaqPlDDRCqVHk5+LXm+OXdI6fsJDg6A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pasaDxUrDGGL+adGOjziWJyX9WXrc8eQxAiAYer2fwo=; b=Qx104ld+5n+BWP4/d7pZOCwtgh05+9PXmpDLIakSrkyfs6gM3pZZFnulb3ga3vaxph55fOU0nIIMfyct4591gFjDZ93Z1HJEteTzX0gI77r++ae2LbWl958LWxYHaA3V6K3xFV8yM6IjvzZsR7vUvxI62JzexPEU0cZa/yugbAVnrwQzLET82QjEB31y/Zgovo5tlBW05Uv5D+pJ/Jydlv6+vPpisiJhwmNEpv6/w5AOJkqUfUVuqofGsvIUMB3y646TtubrtmyoTW4XFR3RKYA29lxgTscCYuinXZf3QUM4IlrMPYYJr7GmNzWrdZmjetF3dtO0KRzgpPE6SvAJig== 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=pasaDxUrDGGL+adGOjziWJyX9WXrc8eQxAiAYer2fwo=; b=PskkuEz9/nA3DkNNi8Edkp6wT9sLL2Q0eY81i9Kvd0K1kf64HQvQW09R3NrauTyNiUBxnuXLP9gqohVaD0sbkJFPbwmJnMLgMpT6CvLB0bCA60UAn9V64XyxtLMcvLw87ez4EdoBokU8Ys7gZmQ9kMasw9169/qzXP4QGWsObfY= 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 CO6PR04MB8394.namprd04.prod.outlook.com (2603:10b6:303:141::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Tue, 26 Oct 2021 06:42:58 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:42:58 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 01/22] target/riscv: Fix trap cause for RV32 HS-mode CSR access from RV64 HS-mode Date: Tue, 26 Oct 2021 12:12:06 +0530 Message-Id: <20211026064227.2014502-2-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:42:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14d4566e-d5ce-4e37-8eb4-08d9984bd8a5 X-MS-TrafficTypeDiagnostic: CO6PR04MB8394: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:519; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iRNMuPsB0xzNrTsNoiaDzyhWC+X7AIDC8bY6R8PfuSZxHsIsYRRUwn7vzDh0MIDPHHSk79HSr4ily1zLP+9+/2phsCHrTMWbyaZ1gidHgcD0gQQVcQV+vEHU+AFDHAl+F7/FOYO0aIU7hn3572iBlRtBScMjcFsx9jDaRVKZkwUWlCbGObDnf2szepUrCNA4oVOR9ek7TLKfIqIHzRUUxMGDjfjvJth/Ux0DLE2mefWyZwy9rSjfnWt35FuzrW/qF9SCzSS+T3wo+1x4Uh3l+AI8+R9jpqvDZfH4FUoqxLeTkt97XP3nN/k6f5FBwOLikwjYhdX6vh/p+vy3BY3Gx3+GQ9i9+BftFdyhlusqcQ3bwKjCzAvXsXltnvoQ1W36w+11CNh0Qge+g5d7WnbLDTnlYzwK5VDjs4kBFL25Xuyn6KHRGa3ASM7ycuKS1Nn5XRNzlKsbsXobYSOf2i05+6Jp3IeBBUBvA5ujE/8wK7fiZU6k9lxise/fSR6+EfxAOU1bGwBdZLsrLOJ7mNz0Kb3LaL6rWW3zvFijLa3rrq/CE0zeiRsc6kq7mO/153wj5sCkRi9aHB6tBJexYz9/6Rb0Z+KbHf4X4AH9hE9NE3sfCBx7B3AYg70gyb8sWYmfAlWFoWIrIhgVOTBehB3jjn22EWJravbY8St57TXiroqSvBELrV26h7WyCFDQEp8+NjChrV+ZTq4yJpfggVbRxQ== 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)(366004)(2616005)(956004)(83380400001)(8886007)(508600001)(6666004)(8936002)(44832011)(82960400001)(8676002)(5660300002)(55016002)(186003)(26005)(36756003)(1076003)(38350700002)(66556008)(38100700002)(66476007)(66946007)(316002)(52116002)(7696005)(4326008)(86362001)(54906003)(4744005)(2906002)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KaD6ZrPMFjsgTLyRpOozE5BKGKrs+ooVwMfLplNvDYyKOTksWOSoej7vc1oHuaRWXvQQnPzXdKyGLWDPL5JhZRCKG07B4PX6RWhmFAMdCD8mBfWDzqs/mdrtkH98dr2hlSBPJjp2pTiMVocxYuHdaIfLUbbGulS2WzSOoww3fnoPXStjre8BbbtNcFCIZY+fbvqDYodz7FaIzIACmiKdplXKrwoC1CkK5C7Wo7Cb9URD6WoYVvh/vzTWJdUFVita6XHYFAsLUarh/lobh0bT9NKIPxm0zL5zO2pcs3o/ZroWiRIa7NVbTjg80aWC8zjnZrAD4C/MTLWBxcB4J73tB0MOOp+ZQYinTz+flLAR2FRpTVbfGAtkXQFmLYIrOpcIiRa8jJl1BWfbNqfHfpGLVM1KDsgt/WSmOlZmtDe2yl6WligwWxgTOSovsEdCSapQFY7t10VEXRR7/gzb1gEvnIqx602UI5r/BXCFjoXNQKkXmxeEsU9zvvFP9nwmI9Pp8524R+0v73k9BB7xlq+Uzpeo1plle0VGUzBSUZCa9tbSDPsA0gsHwG3IzbsqHrSL0fA7OGKjmHn2WFdO9FSRRCzDIlzkNc0pod5xFyea13Pd2OP73iSjb5u/qG4iUQMGnYxxBtrkyiqsW+CVWD7WHEGYYmXYYMtmFWNy3g2yF7BYwN7pHNcLinnRYFGcvJb24MFobgIceGf7u7BmeotxlnrulOZ7dK08yK5hJDxvcaC1acimZv2FvGVLTD31uJNulJ7xglqsy3mAY6r1z6ecnbkVNeOZUaYgHkBPQ8EA+BMq/RdrkvuxNRrXrXVdDvB2GrvpRROqaYQIYpPLzHfjOOpRtACt1eLGwlbpmbNxM+JYduSqPffTz4gMEtyUm52r22IkakpPAID6oHh+h1TOug3io00QwSZxoI1GHiA5GYEW9QGBbWfKGg6/rDM4df/XpNOdvZDSg4YmYmmgEl21NU90DEUEUAVm0FZZJo4iqqoryQpAI33ggxOYvBuMN+iNwpSKTRSFrwdgKZ/g2JkXbw7RtywkeQt/LRSWptX0dIVft/+yOPxYzJyM7zA6uJ9Llpz5Rmf00mTgQuv24Fos60BblmWsoiB/2Fx2+Ly5XElBe8DJSHv535wnVjZHdfd2Yv+mnXluq4l5P6agPHHwi86VPfAjpE634TGRG1fWy6cjyTYM7NcSIfQWVKB7clFa15gZNOhDXfwFkjaVa3lerxGVvhyHLc/zO3Q45HTYBfkG0a3xefTxD/SAqpIlguI/2ErjR789ZONn9QK0mgrJ1KhsW+J3U/qeLIIWw3AAW+y87j3kmNDz/ocA1mXdBANN5hewuJ6Ce2yhNlv8Q6j4+cKKxX3pIuWbcTUvy8/XzvqeKQ1rQ0aFMCjoOVD6EYdcTjKdoAgePzJRvyHB3fnXtMrC0ICuC+uL3c5DHaRgxn3VuAj26WJfLNVDR4g057gUfT9eoa5rr3O6cRjeze6IYt78UykVizI0L8giEqqpMXG+BQRC+d+nbajVl50wIQcl8L42EpRNaHoqv5flwZjpx6zsTrQD4HZxgRwKCJ/M/NJ7ihye7ITZdItNSGEkoYeZC/XcCYAgrPyyGRBJf+En7QPKh7OVaavAWlmnskFH7xc= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14d4566e-d5ce-4e37-8eb4-08d9984bd8a5 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:42:57.8176 (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: RPB4UrTEuAnEyVAnNE9gDN47t8y59ksyvwzjc8JRlVGUJ+rSuBUvimv9vnpX7JwiWXJqiflb0Lp7+WZaQu79rg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8394 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa3.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We should be returning illegal instruction trap when RV64 HS-mode tries to access RV32 HS-mode CSR. Fixes: d6f20dacea51 ("target/riscv: Fix 32-bit HS mode access permissions") Signed-off-by: Anup Patel Reviewed-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 69e4d65fcd..9dfc9b5eba 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -181,7 +181,7 @@ static RISCVException hmode(CPURISCVState *env, int csrno) static RISCVException hmode32(CPURISCVState *env, int csrno) { if (riscv_cpu_mxl(env) != MXL_RV32) { - if (riscv_cpu_virt_enabled(env)) { + if (!riscv_cpu_virt_enabled(env)) { return RISCV_EXCP_ILLEGAL_INST; } else { return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; From patchwork Tue Oct 26 06:42:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584045 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF570C433EF for ; Tue, 26 Oct 2021 07:36:53 +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 1C403610A0 for ; Tue, 26 Oct 2021 07:36:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1C403610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfH0u-0001Wz-29 for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:36:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB7-00038G-4J; Tue, 26 Oct 2021 02:43:21 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:17119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGAw-0008LU-6z; Tue, 26 Oct 2021 02:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1635230589; x=1666766589; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=XMbfyezYLlZZPqOTSDDPiQxcWawUqBfVM4lykBwoyOc=; b=Cq9adOrbYUdBDSYi9ZtN8UQLhHKOkg+w68J1j72yijEClwBBHil4KEcB yqRPBoN7Zd++Y3gjRq2820LZRfbmwPc3RRomPSbuT9HQWFaRLoYcDOVFr 08Ijc+G8Bw04pEnMnY0/xJ2qwnyGBJihMn9Q82Q/k6vT9MQwq2ELlV8ia AcP2xEQxo3/vjc6Ibt1y3VJeFT7EL1f9dt5tWidXhzg0lF2M5fwJ29EG+ 4KXweDqxTH83vXctPYLvDAGGMI+QFBvehVPl/E/oSUS3jfSiDNkBeL7o7 ipi+BcxbPfse8z+wPJcOsLq24qDbm/YaCvqvUJBAT3mRRG1FTWtb2P9Qy Q==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="188620392" Received: from mail-dm6nam08lp2043.outbound.protection.outlook.com (HELO NAM04-DM6-obe.outbound.protection.outlook.com) ([104.47.73.43]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:02 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ECgvgsVbal2dLpTE+KeLBa8xfkwMeOV9vqvySdOLHR9uIhcQgnRnJIBzdureRnZUbqmeT1xzEtc+i77obr/Qjowq40g6h4So4BzSORX59O9Yp9szWYFSlSnviccExAbktxs+QEdveUy1HXD9qg4UFv1cdsQTCiUaKJsw/ZKYO4vLhcMR2D84Rm87y2gfhc8ias3/CUeGoNLU1mfa5eCR235PxLd9RasObuxiqQK+iDrETUt+kIyMsFCMEVhSR4zNYfyp8EN22SLuqnBd3FUjCyTjKfbITlLcqPFL1FFCzW0lLR51Dk5Qq9MUWd12byjZpo4ZDHS/YDVAYkPTjTnJhw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=W87Jq2+WmqYQ9cdmWWINQjKkFz3m0utqsjzhxrkRCyY=; b=cbqYa0bBBYao1oAI7jbe13FyD+3mVFnYy5CvVZBRrEgiLuN/laaXYyAWNm7HqXCg2+l1fqJHFnq8V4xrvs7xYzVDfB7wtVzWVz5ABm7pzgGx4bJWo3tbD2Z+Bs/Arn926cgPmFePq588eu0+qgtvM76x5GlUo+VI2ASPc3Rs9XmEqvbcb538p7E5cN+NrhG8EkLjEFnukviD0z/QmlOW5Du9C2aQy4Xc7xiV6r5Gm0mMwfAZD9VKQvc9aV68dJpZOLgVs4EIIXRXvVOrk0qvWzuGqY/VvpjzeDBaHVt7jSyNmPzvO1P9t93w2bPJjy/NGna7+ml017ANBYx1qSnAcg== 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=W87Jq2+WmqYQ9cdmWWINQjKkFz3m0utqsjzhxrkRCyY=; b=XbmzjfUyBYrpbLHIAyUSjxz5rcuQz8fjR2G2L6IRPy2ipExbjLAR3asu9Q1rTaHPG0E747jZ9PxlZFlHo8kQ0DApDdSFZx8bUHnYS/a7ZQv77pLZzAaIcXYQjWXM1rzBStWDP7T84W9dSK6YYZ+owfPF6PYwtutl063OzJM403c= 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 CO6PR04MB8394.namprd04.prod.outlook.com (2603:10b6:303:141::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Tue, 26 Oct 2021 06:43:01 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:01 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 02/22] target/riscv: Implement SGEIP bit in hip and hie CSRs Date: Tue, 26 Oct 2021 12:12:07 +0530 Message-Id: <20211026064227.2014502-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:42:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 196be9dd-81bf-4117-d695-08d9984bdad5 X-MS-TrafficTypeDiagnostic: CO6PR04MB8394: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:173; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: t152lgfsQ6IGcKo1OmggN20KqyFxmDgY20EHQJGHdegR3vB4KLVJSnjgoqznb4R5spOpSYMkVZNAy5hG1O17ByeEL/7h0SS0AtY6QQ/r6NVYiu+20Nrub8fWQ4UWCiJYElrSkrLRxe6r1kEvdwaV3Q6j/7jBpJ0gZv0uUfrhnh+swOf41ouEyk3+gHubL8fwPdgiFoqCcJlqpi8F6IEMKqp+eJ/s8hIX+KmGirKOPMHUYpdAWXNMAqZfugy2kgAe5zUfRlLep4zN1Lad0y0QDCbrq2Ki+r2sal/QbkmmMyi6s7oeyseggeJOj2O7xSkC/mF6zBtFdFJEXbFBNVFopo32CHrt5/w8Sqe8CKCGKTHEJMAnDVHt0QXl63aSju6Satl0t46+XOuwCvl64JL//c1DPvf5ToNEKCxTX7fUIkhAKvMhDOo4pTKe4p4Zvs2n1uGrtI4Ofql2x0pqXHif6FyX6mbomEKYKRMwK5+jMOe80/G302X5yQg1m6hC/QZNzYtdszKABQoJ3+ahaYJxzZ7H4ROnOikJnmMm4UCTpTYzjUbyXpuFW+cp/I2s1k8RMQAIlQaapkXupwESu8lxViS7jPmK3cBGec81+ID1b47NMksjyIL/dp+txTl5bRDA3Me+65DKx4E+fMqC3DWQe9/D0I0y3nsr0QS8+jJRzanQqJzfuOeWneq+7RrvJh1BlRpWXQa7zzCvfoLThobCqA== 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)(366004)(2616005)(956004)(83380400001)(8886007)(508600001)(6666004)(8936002)(44832011)(82960400001)(8676002)(5660300002)(55016002)(186003)(26005)(36756003)(1076003)(38350700002)(66556008)(38100700002)(66476007)(66946007)(316002)(52116002)(7696005)(4326008)(86362001)(54906003)(2906002)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cCiH0mkGOgY8qUeNHguzgtbfFcefGayqI4ayjZIPuBUb6D9R6RYoFHfHiKfXjIOQcerqJAfCPua53kRuqWpv9nomo71ZJsmA3YiPNH0zYek5a6Oawv1ZHttcvv6T0K7UGtrIAhwl/w3+7tHwIBQihKd1XTV6SIzaS6j9N+dJVsEDH3aMj8CxHtwt0lIUJIkOW3lDoIEUArgy9aUfBQDn9l7g/JuuLwIj0y8CkhdvliuPx79wkiNuaZDgunVKXhCqCZctIJ0tiWYDXdS/1jotACWDXO1xNVbhVTNfmXosZ8yI7OJFY5/BuDsICGWxX/xg0lOVj90UYoMly7wsqTx3SZxIYcPjmbGveFBgK7XciyIwfAX6xkjgNq/SL6HAJfsoVgwdyLOyq5NHxR137H43SMmMDuEmzOSGT5hC/DT/Z9gqBXHxDRjsWoiG+r0z9P1xM0OhZeaHrzippnhFapaD7Vn20qc7HMwzGZDmQ3LjYlY3jVOWjAeMTdyq8GkkbveyZyATaUrCIc6IprDDnRQ3ChZXK/OCrZ4L0UsTXehy1/Dsy6fk3DsILu1ba1b82EiHKxWg9XP7t4RPqSbZ3BngBzKoflCBC0oz1+8m9Rlok2ml+qpq0QiTOJS70YknR+7RVBbD41nbdwpx4TMdDyooJRK6/4+0epRaoqA8s/SOGvJwvfxRfvJHU3JewaEaU+RAtH41wiYA/kn+Ks+Cca/s2fhWiNCfzNZMPXfG/KO1kZHm+QpwDQ2IteaH+jGNy5+95HfOK0vMdrVrgAN1ehHKFXJFlIAwIkleXC/VhC8vKwhvOqUNCv+PtLXQhG6W6y+2wxN6hNAaNqwRD0zsk7jy02XUmKOA4RShVSVREGljZRFy+csEANQTlHsaPTy+41X3TPwGUlxlCFGjjVl6fsTe0wgny9NbvEzPiZm1B5kh+3K8RcbuvbZJSZfiHD+c5YnuJ64pvFr02xoOiOOr6HeOtIN4vXAaAY3KjVONShzV6RGZuUUDG2sW2UJsKCApuQzl9qRSsbsljeITEFB0u/Nf5jN+CBtZsko+o4pSFiolHrslIwjGAtlSkbklVVu4OjCpu+kS2lZewwKIGJx262d14QRImyE1q8yt3TvLDzsAg+jNiB4sovGa2ikKgJHSHI4gj/YrE22tp66k0YOMFJ5WDCMf6L9Q9G5N2xkrfTAj4IshuTy9+h+v2qhzPCYg49TMhS79o+HwATG/jeOTXTggM+OeNI1gJbMzdKoe7YPDU0+zRkEOYtKZWms6m60rhPK/xOZ4LeFWAPAeuKgCP4+TAes+JctysttNXT8IWNSB679h/LNpeXfDF3X2GnAi5q9G7VlBad1OOQTp2S4FJg1yahtX9W1rhE07Hk1/kCDYS9z/gynK8UVUDcmCS2JpK5UrTtIWjrsf1g0oAkHI9xL8oWQGfc1SgvEhOJ5FpTMNsrkAarSnu7AN7A/EptTJgHmOK7T3dPA23arzxeELUe0oXHCjOrgjiaLEIVgA5V2Wkr906M5QHEvNnpzGar+/zXnPPMotoYy0BU2aPYMTeGK2Mpw4b8O2NrfUIxFGDW3+pYcXEHoC9EkBkvCRr5dD34onLOuxnCPF6ye2LeM75v8Gggk1JqK36xD+WpVPdvzbnU8= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 196be9dd-81bf-4117-d695-08d9984bdad5 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:01.2894 (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: Kx+pDYb8e/Qg3zl+6kIlDu1b9XakSqrYxMl5Zcy99koFHw79lkhAHOPz7wSs72nCLvqWtrV3vlD6qN9wY0GzrQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8394 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa3.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" A hypervsior can optionally take guest external interrupts using SGEIP bit of hip and hie CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 3 ++- target/riscv/cpu_bits.h | 3 +++ target/riscv/csr.c | 18 +++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 788fa0b11c..0460a3972b 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -365,6 +365,7 @@ static void riscv_cpu_reset(DeviceState *dev) env->mstatus = set_field(env->mstatus, MSTATUS64_UXL, env->misa_mxl); } env->mcause = 0; + env->miclaim = MIP_SGEIP; env->pc = env->resetvec; env->two_stage_lookup = false; #endif @@ -598,7 +599,7 @@ static void riscv_cpu_init(Object *obj) cpu_set_cpustate_pointers(cpu); #ifndef CONFIG_USER_ONLY - qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq, 12); + qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq, IRQ_LOCAL_MAX); #endif /* CONFIG_USER_ONLY */ } diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index cffcd3a5df..8a5a4cde95 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -498,6 +498,8 @@ typedef enum RISCVException { #define IRQ_S_EXT 9 #define IRQ_VS_EXT 10 #define IRQ_M_EXT 11 +#define IRQ_S_GEXT 12 +#define IRQ_LOCAL_MAX 13 /* mip masks */ #define MIP_USIP (1 << IRQ_U_SOFT) @@ -512,6 +514,7 @@ typedef enum RISCVException { #define MIP_SEIP (1 << IRQ_S_EXT) #define MIP_VSEIP (1 << IRQ_VS_EXT) #define MIP_MEIP (1 << IRQ_M_EXT) +#define MIP_SGEIP (1 << IRQ_S_GEXT) /* sip masks */ #define SIP_SSIP MIP_SSIP diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 9dfc9b5eba..9a0a0c0679 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -408,12 +408,13 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno, #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 HS_MODE_INTERRUPTS (MIP_SGEIP | VS_MODE_INTERRUPTS) static const target_ulong delegable_ints = S_MODE_INTERRUPTS | VS_MODE_INTERRUPTS; static const target_ulong vs_delegable_ints = VS_MODE_INTERRUPTS; static const target_ulong all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | - VS_MODE_INTERRUPTS; + HS_MODE_INTERRUPTS; #define DELEGABLE_EXCPS ((1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | \ (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | \ (1ULL << (RISCV_EXCP_ILLEGAL_INST)) | \ @@ -673,7 +674,7 @@ static RISCVException write_mideleg(CPURISCVState *env, int csrno, { env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints); if (riscv_has_ext(env, RVH)) { - env->mideleg |= VS_MODE_INTERRUPTS; + env->mideleg |= HS_MODE_INTERRUPTS; } return RISCV_EXCP_NONE; } @@ -689,6 +690,9 @@ static RISCVException write_mie(CPURISCVState *env, int csrno, target_ulong val) { env->mie = (env->mie & ~all_ints) | (val & all_ints); + if (!riscv_has_ext(env, RVH)) { + env->mie &= ~MIP_SGEIP; + } return RISCV_EXCP_NONE; } @@ -984,7 +988,7 @@ static RISCVException rmw_sip(CPURISCVState *env, int csrno, } if (ret_value) { - *ret_value &= env->mideleg; + *ret_value &= env->mideleg & S_MODE_INTERRUPTS; } return ret; } @@ -1102,7 +1106,7 @@ static RISCVException rmw_hvip(CPURISCVState *env, int csrno, write_mask & hvip_writable_mask); if (ret_value) { - *ret_value &= hvip_writable_mask; + *ret_value &= VS_MODE_INTERRUPTS; } return ret; } @@ -1115,7 +1119,7 @@ static RISCVException rmw_hip(CPURISCVState *env, int csrno, write_mask & hip_writable_mask); if (ret_value) { - *ret_value &= hip_writable_mask; + *ret_value &= HS_MODE_INTERRUPTS; } return ret; } @@ -1123,14 +1127,14 @@ static RISCVException rmw_hip(CPURISCVState *env, int csrno, static RISCVException read_hie(CPURISCVState *env, int csrno, target_ulong *val) { - *val = env->mie & VS_MODE_INTERRUPTS; + *val = env->mie & HS_MODE_INTERRUPTS; return RISCV_EXCP_NONE; } static RISCVException write_hie(CPURISCVState *env, int csrno, target_ulong val) { - target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | (val & VS_MODE_INTERRUPTS); + target_ulong newval = (env->mie & ~HS_MODE_INTERRUPTS) | (val & HS_MODE_INTERRUPTS); return write_mie(env, CSR_MIE, newval); } From patchwork Tue Oct 26 06:42:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584037 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A504CC433EF for ; Tue, 26 Oct 2021 07:32:02 +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 271D4610C7 for ; Tue, 26 Oct 2021 07:32:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 271D4610C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:60484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfGwD-0004mQ-5D for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:32:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB6-00038C-3m; Tue, 26 Oct 2021 02:43:21 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:17124) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGAw-000075-76; Tue, 26 Oct 2021 02:43: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=1635230589; x=1666766589; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=cCSVrMFQZK0YBYECnnhAPfLUnCnHNqNNUJ+jWklO1VM=; b=LSvAUrbBBZ6UkHDkfkvZR8X89mU2G81dgxq8mjL3tYDNBtvKtn9h2qUa 3oE0+eNw1Mt4n3kz7nW514eoqYLq70+9NnDDrYcg49xn23qVvLqPiuWsi +HE/i6KVuoDmLGtp21R9I9nbH8YjOHEe0Ev1q8XiCwI3wnc8+vKTzZWjW G1g2LDYZNbnHbPOAqJ8YE4M+BoK/El2DXj2oLBonJaWCJO7TnU6LqqrxE 4zNiMVyt8zClsFpCzM1iaryEM28IlssVBPQknPBZgjNMKbafCAhi8XAwo UcqqKT9r5AupPlJPJRMSbJVEQ/77PH4pSREVfdHfrsmOa8f6QXsEFbus5 g==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="188620394" Received: from mail-dm6nam08lp2040.outbound.protection.outlook.com (HELO NAM04-DM6-obe.outbound.protection.outlook.com) ([104.47.73.40]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:05 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gF7jD+i39TroE1pb1tCRGvjeeV5TY2mpoEzTyTBxXQEnUvAOoJZxDqeb6mprDGtr6/zI2DgBB/nBIhqxHe8kesguETLhod2LdckYruxtRNtKFVE2u3JtsDeeWR7ERpK6TfzOHV9Q4EmOxWtBCL7KZ4EPa2VOknZZ7itoZf0XLcUgdDb9kVY9czisuLt1G6CVsKGtPUiIQ0KGACkhCLcdDMi3itdet3lq87hoqHlAIb8D637QAJg5HbNQI5UfFWrV6veodL2bmzoFunUjaD0Y9eAqBupDL/JgUBCVeXEnlxJHgSorX6fwBUOJwHkiCiIGU6Eo3cIArnvpc7lb1McvdA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZlRWqy2KFGv4IYynZao2oNqPMPDr2xUqua+m+KlFHS4=; b=Vpt+eBlR8qB16tUcSEKqyMEBISKCrPGnEAXRwGewUhWrzpSZOaZAnnp5LC2MCsMEEYSGX5J1L/PjGgpXkr/URuEbdlhhn5UuN2RdR+yJXiPPpdrrWcd9Im+c23TsiKPdcEwzK0GzbhQmK4kydzdHIInvGCMKWgouSXeok2VtSrAv7KaRJ5ir36X8xTptiZorbkqhznpn03EZx/1z/FLex4L1MLdUS1/lTEiKti9tqgsFwz80A3aBGM3+wSgZY6zK3ES2BlcD9XbeBPXRSIFjUYn7pxO7NuLTrU/fh4f1J3igSrnFBmCWRXxeeef1i0xlseYO0MPvbMh5xTN9GTSpOw== 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=ZlRWqy2KFGv4IYynZao2oNqPMPDr2xUqua+m+KlFHS4=; b=Uj3BxQSrRDoZ2j+X/zCiORErG0vLXkXoTBlcuI1A22yXG4MANqelPTPvxnfhr59R/oqvvOmW7pKOx3YlZdGY2pCVGNVkom3aykuF0nEVwH0Mlie8mmZ27P8MlR1vJ+A4fvj8LkjwVrfAUOWuMUwd8xc4wVQFpB1LUlF7NQOxCE0= 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 CO6PR04MB8394.namprd04.prod.outlook.com (2603:10b6:303:141::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Tue, 26 Oct 2021 06:43:04 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:04 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 03/22] target/riscv: Implement hgeie and hgeip CSRs Date: Tue, 26 Oct 2021 12:12:08 +0530 Message-Id: <20211026064227.2014502-4-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ed0cc16a-e04f-4ab1-ef01-08d9984bdccb X-MS-TrafficTypeDiagnostic: CO6PR04MB8394: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u6kvlVRqy/7uScAZukUSkdlqfD8MPgwFLaRx2Na74gX5/EElXNd9dywZ9RNalg0CkpJ7SRVfO3bB06BjT2pWjMOcG73je0x6iQZe+8qerUDstN0FGFnfDpXUogKueQ8TcM2Rk3heymixFLhYXPdY/orrDYwNTy+XkqqqaVN2Cg0n+UqBzFRIbpBOceKjSULwg86mmRSUB0GikpSQ5HJS9aR46Jq0SmEONd1BivrUedlbQDqtfReyf0s2/rwOpM/YeX4P13Q/dvZG1gh7wE2ct+Jbv6wpRz2g6tMdZIb+84cP2kl1O2m1MKInZ39ME1csh1Lkcl3jlpcgq05RPFn2CDSY0r6cjJGmbYyNWG012kj1dWwWme87EfpOfageTzgrrf7t+pfuyLHpf3NtrRti5vgN4HHpbkvkn+mrTPILmUjp1A9Sihmb5QRH/nyktIiSBwlC4ZEC4rpO5RC8q7dci9NnSvqVAZkneAX6DbNg1gW4UlQRMDmQsAhVWqajBKWEKmchVgVQCn4rDYqySSu0HcjSqhKUfrNcIvCxTQumHpNUqaKbI8XTisgICYv3Kva2K0HllFD6amacarwLRIYkYrODpU5fUS3WNRrcNB7+K7MpiijBKaIX/8BS0rUmgjw/CHEeVrN7okg1BrTQO5PEgXPTCkBdDI6qx/jTTY8VGKVV8eJeEqcNYUGo2Zybd+aUoUHT6/xCJgm0+MTL7Govrw== 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)(366004)(2616005)(956004)(83380400001)(8886007)(508600001)(8936002)(44832011)(82960400001)(8676002)(5660300002)(55016002)(186003)(26005)(36756003)(1076003)(38350700002)(66556008)(38100700002)(66476007)(66946007)(316002)(52116002)(7696005)(4326008)(86362001)(54906003)(2906002)(30864003)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XQBVUfHVRuhdQwLMrmuffmFxfqlh4PaIJuCWE+p6qP2dr6pXKVo1isV/e+Ty5l5NiMa3wiIpULnYj+AFq2K5bkipf3Jm7lT029TiQRMFrVCZDXw0eBtQCZeElOz2EuWD019sCI22rP1Jpwj06QEQrBuuDRurGnjLLQ62k4k+xp1hlXZobrIITFr8fxWyPI3SzXX8pYOZg82subOwDn3J6QLHV5XH4YG1zctNL7u76edlfEPHSZ2NP5sBmzjDTuZZRHKkXrxd5Anq5g4P7yXtz1ncXpH9ZbVl24wSYoWfzGPHkhuOc1XkIorqiMiNrTpJZxPm2scNiZLv3oazqCbsypheeZaNCJKv98omAsNJBU+pvjBS//VBcPeq+Hrz9o+TecI99J4LiytSUmzrRbQYlq7rfXil95Gj9/pglurabhUMpUgMpbs5mAd7AQ1uXv+EFUX1XPoHdOr+Vw4GsIH6BA5xOD0vam90J1EIXaT6bpuICsgKxxIiw9m/C2/wFGQuWw2cppjVq/ZoLuJrcQT2aAcl+RccKXP0kISteUu0amKqgTv2peOWGU5PTbIQOb+r1PVc56FtqQgEp0mIKg2BhqTEJoMUNpyj0XEFc2wJuFSv4WwXu0oOgZlGwsxC9/yie4QHlKfI8Ndi3ut/Q3Lz1vs2UPbJgPwqMSG0TeQcOY0QMUEmRbQs9m3biPEssuiIgDisxTTExJg15XwU9fORwRh2wYTi4sweJenVEYx88dkfTtWKm9HGKUYba5aWJhnbHh3jcJi3RICVVEGH8hn+MH+uqdgVrC3lkwrl3CAPsCe80MZjKgSrsvlHk7EcaDt/tYnj1ZYPIYzaN8YnmuGTwmgschZCBtvqmAyA1+L+c730gjq667daM7oMQV8/RtpnDBFSYErfjab78rtjsxm9d+njIdaVTiyvMC9VeDJonPKqhQLm2JX+gipSML7M+xp6DTgzT8DkK9M+mcsE+br5JYH+NDjW+qpOK6ojg206B6VOa5y1mB+GmQPQZuR/S7sPv33h7nkpAS4Z8TgLE12sl5Xki36Y4CkMNLL+n+jPC3qhbyGb/WqkrUpcYOsbSWsVktEKVODEn3kkgnzBmIlnDhsA5nORqsijxh7Vty4xst064Bt9kyzh0d7hf3tlZyG2+LhH3vYCOeP+P9HrKPZssLHtXZRBsSPGKJa0nmCe0zDIYozcP6i3s7LuuX9eDM26mlji1ikAR+7InjmW3sTABDhrl7QV8yLeJJBEvWBUGgYpCv0WvyrI+MKemGmwOcRs8G5eyVDutD4QrcQloxXpmgZGl2jA9/TshboaEb2TFS/5fxCCoBxgwsmjOTZ3DfLVTD9ZmajNkCcLXxzLsTQqxTMLWp7ZhIq6VJXrBjB9itEYbbfErR7jkc7dPH63r1za9TDc1Dxb6kXwZBJ7fQvm7wHfJMO2TO0PjlIMIUjtdfIBembAOaJfaV7YZYEZm/eITl9Haluozidx1J7fbVtgc9PQtuSd2jz3b3/Lfeya7frU98O1j6GxJN8n6OXzrs0uCVWButJfmxrTx9qC3qRf8Rd+8+wqmYeBNpCxcFue+HkSXkyqxw1M0hWKWMa4pizcl6dG84/XfitkYvcRBLgUcJT3rDkeAr8slCX17c0hf6E= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed0cc16a-e04f-4ab1-ef01-08d9984bdccb X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:04.4883 (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: XNSXFXUKv7/RRg7BqeZUNCN+EdrP20IsEcIv8EkJELknJEUPRNQbgDtbm9ENvgqcF9IvQCKr84uHw5//xr3YVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8394 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa3.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The hgeie and hgeip CSRs are required for emulating an external interrupt controller capable of injecting virtual external interrupt to Guest/VM running at VS-level. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 61 ++++++++++++++++++++++++++++----------- target/riscv/cpu.h | 5 ++++ target/riscv/cpu_bits.h | 1 + target/riscv/cpu_helper.c | 36 +++++++++++++++++++++-- target/riscv/csr.c | 43 ++++++++++++++++++--------- target/riscv/machine.c | 6 ++-- 6 files changed, 117 insertions(+), 35 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 0460a3972b..8042c4ebcf 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -570,23 +570,49 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) static void riscv_cpu_set_irq(void *opaque, int irq, int level) { RISCVCPU *cpu = RISCV_CPU(opaque); + CPURISCVState *env = &cpu->env; - switch (irq) { - case IRQ_U_SOFT: - case IRQ_S_SOFT: - case IRQ_VS_SOFT: - case IRQ_M_SOFT: - case IRQ_U_TIMER: - case IRQ_S_TIMER: - case IRQ_VS_TIMER: - case IRQ_M_TIMER: - case IRQ_U_EXT: - case IRQ_S_EXT: - case IRQ_VS_EXT: - case IRQ_M_EXT: - riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level)); - break; - default: + if (irq < IRQ_LOCAL_MAX) { + switch (irq) { + case IRQ_U_SOFT: + case IRQ_S_SOFT: + case IRQ_VS_SOFT: + case IRQ_M_SOFT: + case IRQ_U_TIMER: + case IRQ_S_TIMER: + case IRQ_VS_TIMER: + case IRQ_M_TIMER: + case IRQ_U_EXT: + case IRQ_S_EXT: + case IRQ_VS_EXT: + case IRQ_M_EXT: + riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level)); + break; + default: + g_assert_not_reached(); + } + } else if (irq < (IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX)) { + /* Require H-extension for handling guest local interrupts */ + if (!riscv_has_ext(env, RVH)) { + g_assert_not_reached(); + } + + /* Compute bit position in HGEIP CSR */ + irq = irq - IRQ_LOCAL_MAX + 1; + if (env->geilen < irq) { + g_assert_not_reached(); + } + + /* Update HGEIP CSR */ + env->hgeip &= ~((target_ulong)1 << irq); + if (level) { + env->hgeip |= (target_ulong)1 << irq; + } + + /* Update mip.SGEIP bit */ + riscv_cpu_update_mip(cpu, MIP_SGEIP, + BOOL_TO_MASK(!!(env->hgeie & env->hgeip))); + } else { g_assert_not_reached(); } } @@ -599,7 +625,8 @@ static void riscv_cpu_init(Object *obj) cpu_set_cpustate_pointers(cpu); #ifndef CONFIG_USER_ONLY - qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq, IRQ_LOCAL_MAX); + qdev_init_gpio_in(DEVICE(cpu), riscv_cpu_set_irq, + IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX); #endif /* CONFIG_USER_ONLY */ } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index a33dc30be8..bbf469f079 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -148,6 +148,7 @@ struct CPURISCVState { target_ulong priv; /* This contains QEMU specific information about the virt state. */ target_ulong virt; + target_ulong geilen; target_ulong resetvec; target_ulong mhartid; @@ -185,6 +186,8 @@ struct CPURISCVState { target_ulong htval; target_ulong htinst; target_ulong hgatp; + target_ulong hgeie; + target_ulong hgeip; uint64_t htimedelta; /* Virtual CSRs */ @@ -337,6 +340,8 @@ int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, 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); bool riscv_cpu_fp_enabled(CPURISCVState *env); +target_ulong riscv_cpu_get_geilen(CPURISCVState *env); +void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen); bool riscv_cpu_virt_enabled(CPURISCVState *env); void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable); bool riscv_cpu_force_hs_excep_enabled(CPURISCVState *env); diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 8a5a4cde95..335e0193a9 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -500,6 +500,7 @@ typedef enum RISCVException { #define IRQ_M_EXT 11 #define IRQ_S_GEXT 12 #define IRQ_LOCAL_MAX 13 +#define IRQ_LOCAL_GUEST_MAX (TARGET_LONG_BITS - 1) /* mip masks */ #define MIP_USIP (1 << IRQ_U_SOFT) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 0d1132f39d..bb7ac9890b 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -125,7 +125,10 @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env) target_ulong pending = env->mip & env->mie & ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); - target_ulong vspending = (env->mip & env->mie & + target_ulong vsgemask = + (target_ulong)1 << get_field(env->hstatus, HSTATUS_VGEIN); + target_ulong vsgein = (env->hgeip & vsgemask) ? MIP_VSEIP : 0; + target_ulong vspending = ((env->mip | vsgein) & env->mie & (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)); target_ulong mie = env->priv < PRV_M || @@ -241,6 +244,28 @@ void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env) } } +target_ulong riscv_cpu_get_geilen(CPURISCVState *env) +{ + if (!riscv_has_ext(env, RVH)) { + return 0; + } + + return env->geilen; +} + +void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen) +{ + if (!riscv_has_ext(env, RVH)) { + return; + } + + if (geilen > (TARGET_LONG_BITS - 1)) { + return; + } + + env->geilen = geilen; +} + bool riscv_cpu_virt_enabled(CPURISCVState *env) { if (!riscv_has_ext(env, RVH)) { @@ -302,9 +327,14 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) { CPURISCVState *env = &cpu->env; CPUState *cs = CPU(cpu); - uint32_t old = env->mip; + uint32_t gein, vsgein = 0, old = env->mip; bool locked = false; + if (riscv_cpu_virt_enabled(env)) { + gein = get_field(env->hstatus, HSTATUS_VGEIN); + vsgein = (env->hgeip & (1ULL << gein)) ? MIP_VSEIP : 0; + } + if (!qemu_mutex_iothread_locked()) { locked = true; qemu_mutex_lock_iothread(); @@ -312,7 +342,7 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value) env->mip = (env->mip & ~mask) | (value & mask); - if (env->mip) { + if (env->mip | vsgein) { cpu_interrupt(cs, CPU_INTERRUPT_HARD); } else { cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 9a0a0c0679..7ff285282b 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -793,7 +793,7 @@ static RISCVException rmw_mip(CPURISCVState *env, int csrno, 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; + uint32_t gin, old_mip; if (mask) { old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask)); @@ -801,6 +801,11 @@ static RISCVException rmw_mip(CPURISCVState *env, int csrno, old_mip = env->mip; } + if (csrno != CSR_HVIP) { + gin = get_field(env->hstatus, HSTATUS_VGEIN); + old_mip |= (env->hgeip & ((target_ulong)1 << gin)) ? MIP_VSEIP : 0; + } + if (ret_value) { *ret_value = old_mip; } @@ -963,7 +968,7 @@ static RISCVException rmw_vsip(CPURISCVState *env, int csrno, 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, + int ret = rmw_mip(env, csrno, ret_value, new_value << 1, (write_mask << 1) & vsip_writable_mask & env->hideleg); if (ret_value) { @@ -983,7 +988,7 @@ static RISCVException rmw_sip(CPURISCVState *env, int csrno, if (riscv_cpu_virt_enabled(env)) { ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask); } else { - ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value, + ret = rmw_mip(env, csrno, ret_value, new_value, write_mask & env->mideleg & sip_writable_mask); } @@ -1102,7 +1107,7 @@ static RISCVException 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, + int ret = rmw_mip(env, csrno, ret_value, new_value, write_mask & hvip_writable_mask); if (ret_value) { @@ -1115,7 +1120,7 @@ static RISCVException 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, + int ret = rmw_mip(env, csrno, ret_value, new_value, write_mask & hip_writable_mask); if (ret_value) { @@ -1152,15 +1157,27 @@ static RISCVException write_hcounteren(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } -static RISCVException write_hgeie(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException read_hgeie(CPURISCVState *env, int csrno, + target_ulong *val) { if (val) { - qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); + *val = env->hgeie; } return RISCV_EXCP_NONE; } +static RISCVException write_hgeie(CPURISCVState *env, int csrno, + target_ulong val) +{ + /* Only GEILEN:1 bits implemented and BIT0 is never implemented */ + val &= ((((target_ulong)1) << env->geilen) - 1) << 1; + env->hgeie = val; + /* Update mip.SGEIP bit */ + riscv_cpu_update_mip(env_archcpu(env), MIP_SGEIP, + BOOL_TO_MASK(!!(env->hgeie & env->hgeip))); + return RISCV_EXCP_NONE; +} + static RISCVException read_htval(CPURISCVState *env, int csrno, target_ulong *val) { @@ -1188,11 +1205,11 @@ static RISCVException write_htinst(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } -static RISCVException write_hgeip(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException read_hgeip(CPURISCVState *env, int csrno, + target_ulong *val) { if (val) { - qemu_log_mask(LOG_UNIMP, "No support for a non-zero GEILEN."); + *val = env->hgeip; } return RISCV_EXCP_NONE; } @@ -1619,10 +1636,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_HIP] = { "hip", hmode, NULL, NULL, rmw_hip }, [CSR_HIE] = { "hie", hmode, read_hie, write_hie }, [CSR_HCOUNTEREN] = { "hcounteren", hmode, read_hcounteren, write_hcounteren }, - [CSR_HGEIE] = { "hgeie", hmode, read_zero, write_hgeie }, + [CSR_HGEIE] = { "hgeie", hmode, read_hgeie, write_hgeie }, [CSR_HTVAL] = { "htval", hmode, read_htval, write_htval }, [CSR_HTINST] = { "htinst", hmode, read_htinst, write_htinst }, - [CSR_HGEIP] = { "hgeip", hmode, read_zero, write_hgeip }, + [CSR_HGEIP] = { "hgeip", hmode, read_hgeip, NULL }, [CSR_HGATP] = { "hgatp", hmode, read_hgatp, write_hgatp }, [CSR_HTIMEDELTA] = { "htimedelta", hmode, read_htimedelta, write_htimedelta }, [CSR_HTIMEDELTAH] = { "htimedeltah", hmode32, read_htimedeltah, write_htimedeltah }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index f64b2a96c1..fe99ec7304 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -102,8 +102,8 @@ 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), @@ -113,6 +113,8 @@ static const VMStateDescription vmstate_hyper = { VMSTATE_UINTTL(env.htval, RISCVCPU), VMSTATE_UINTTL(env.htinst, RISCVCPU), VMSTATE_UINTTL(env.hgatp, RISCVCPU), + VMSTATE_UINTTL(env.hgeie, RISCVCPU), + VMSTATE_UINTTL(env.hgeip, RISCVCPU), VMSTATE_UINT64(env.htimedelta, RISCVCPU), VMSTATE_UINT64(env.vsstatus, RISCVCPU), From patchwork Tue Oct 26 06:42:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584051 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46D77C433EF for ; Tue, 26 Oct 2021 07:43:38 +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 CE68A60D07 for ; Tue, 26 Oct 2021 07:43:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CE68A60D07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:50316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfH7Q-0000Lj-Ty for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:43:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53008) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB5-00037r-0V; Tue, 26 Oct 2021 02:43:19 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:17108) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGAw-0008KZ-Cx; Tue, 26 Oct 2021 02:43:17 -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=1635230589; x=1666766589; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=z3qIOXYfVWykrEEtE+DZx9v+O2iQ78PhkBTRuSZjnU8=; b=hQB9bYLYTtwVHNs5mZ1iGc36yZcbfXJBlqHI41bF8O4nstwTj7E12YaO LAP4DCo7NPPiAfS9ToaSN430+1Yznh6rf23cjQWHHmbSniQXRRFY0W7Q+ D9BJ7dmSq4uVCjkkJOPvp5FL4duFDDv6MRUuf/RcoEBO6fY+ibdWxSrod nUBK+a2CFVkUSFkcuUXJ9HLsdp/l6HmdsPIsQq5BbWwHGlPav252T4N2n mK2bWwfoIaAKW0DKoa3oQ2sp10WDIBEQMLafdasMZNaQX/MhmYHGruHlj ocqkn9/OLUMqY0d6v8+JAO4skc6qji9AQ8NatTgI9v6Z+31MUiiAv3PE8 A==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="188620397" Received: from mail-dm6nam08lp2043.outbound.protection.outlook.com (HELO NAM04-DM6-obe.outbound.protection.outlook.com) ([104.47.73.43]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:08 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M4L+PLQQXWU8PZYCGo9DsSU+npEapysINuxjjAAX0DuhIDKKTM2LME1zFMWg4nEB/+Pg6fVowTkP/LDZC7GGBNRSzmYRpFbRzd55EHd+xBUgXtLFxZyRyOpaIYF9uZe+Yk3OetDIsyq0SkR5FcZZj4LU7ZVV7o5/Tf8620XPb4mlKkw9Owgn867zAuqKEF2a+IpsHzvE3aqQV4sErJKkUbGPpLp65eJZAiwvd8QXSy5Fy/ok5YdjraXWkhqRFzSNKEhz0igN0nM5Rzct1mBqEY6I7XBwzE5i+KRwbAVpaX06878B90a3WeRhRIBcjQ6qv6rPMbOizoFz/viMa8nXJA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dL1YDusRsyUzrz9kwwbmLXyN21mUnwX+DADOnb91Df4=; b=OZx9q3p6thOvjLtkZ0faiclyo7lXHRgKik4U/00/QgPLEIjd1XWF742CA2nwYHl33DSPKBZieQqWv0ToErT4CzUxW/ISrBNwX9DrMR9+426hDJ8I0jWMdrwdEkDkVUUgd844g9rnWcMTl698BSVpCrEOgdJzm8VyXo3aA1H2BXt2Os/DMtW08NY+1h4rxGAl9Ud03x+hjKhnxmY/Ni4yp6iyp7mNGHAn8RrMM5Leqf8f8c9PNvQbNGCn3SYOsqqplGnPoh8g6UIEtXyzCvaDw37EpLtEltJ245w96h0XMUT4Id/xzAgELeKw3054Vl5TWGhO+qF6OwTYRqXUxdjJaQ== 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=dL1YDusRsyUzrz9kwwbmLXyN21mUnwX+DADOnb91Df4=; b=jyJmDV6xdw35S7txvd5IGiwrGxhqPUhA9sJnjXI23j0MYebEca3k1MzSO2aw+UTag2vLvbFLaJJry1raUY2HrYtMx4deLXMj3gJeL2o2mdeoveGYigMHBLNZEnW7/9KIKwqa1ipzA7jeo3Y2qp5NYmRuVMZvdoEz8kjWzx8XHz8= 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 CO6PR04MB8394.namprd04.prod.outlook.com (2603:10b6:303:141::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Tue, 26 Oct 2021 06:43:07 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:07 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 04/22] target/riscv: Improve delivery of guest external interrupts Date: Tue, 26 Oct 2021 12:12:09 +0530 Message-Id: <20211026064227.2014502-5-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 257f4ff9-494c-42e0-d864-08d9984bde93 X-MS-TrafficTypeDiagnostic: CO6PR04MB8394: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /bmiSBX9nihlgR4Ob3lcS7Qya0qz8Daztb55snRMMxaVlgehQU94XJeEu2wULhXSguRK8tyO9olRZNVBPqeat3PR/+XKfZsEP7mQHeoT0kNk26LgRm4MKsWVwMufBcfUJy98k/rxCA0P/ftewMmKB4axEop0IolFtWHbFlZbFjG9BbFA1GZJdmxDIO5cwrKR99sLbYYN4cddxqV9BZNT8b5bM6nXfoFWLd/VzsKlTy3eFL4RWV99YBBT0xHjGYvcCjnxo6sGH1O7LVLTuklApLiTL4XlXSaIGjOqlRhO0lKxot5f3v6xEw3iiJxgkbFoHzVV9uEtXP6NRbaS8u9E9wDOpPJTd/NuLZz4xqJX5CaJwuGfBeYZgI2f+wSDw2o/whW3cnC8yRHvIMcyA2Bmm5ZJNiIBTFHE/ldr8H7hIL8RIW7/3xVTnj1gtuQ3yU3jrhiuKe5brlShHn1s9dHDexqH/RJO6Do+GGWFnJt5QGnWV8O6ic57qkNAxUKVnYTkJrvLxkW9Z3XO1lOJFkSo41jYLCS8a3Lqq/8TdrT0Y/hyv0QK9MRshuXsAw12djQdp/2ynm7VuFqOFmMlvTvcdRSBLrI/TRNdXJMfXWn1N7sZeU0zjYDGQBgrUQR4pxyjQQNOtiTolDdEcERaf+CmaMwkPahKN3fCQKU1ghjTWGsuLSthwObfy3/7hADbLrDIevzdNNQg/xCQvR/Q4VV26Q== 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)(366004)(2616005)(956004)(83380400001)(8886007)(508600001)(8936002)(44832011)(82960400001)(8676002)(5660300002)(55016002)(186003)(26005)(36756003)(1076003)(38350700002)(66556008)(38100700002)(66476007)(66946007)(316002)(52116002)(7696005)(4326008)(86362001)(54906003)(2906002)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GS4GjMVjKViE50/l2y5CdHEsxUdgk3RnIeP8GaadQbbMmcRIMR1lqdUYaJ+TQkr3/3UErCXSTo1y9rEZisvo2M+gTthpG2/+5+nvWQDD0Wo0LIexV9Ol21n2kh74zxHqkUwz9G4YsB+u0IZ+8fIKCQAEpMoLSZoTh+lxlssfemzXmK8QMU+0FjPWySLgpAFL3HWCek69I4+s5vn+CFxGakIknLqATu+DZaOj8l1GXRYiJrKfBOKsD7ab2Zf85A6O3Nzf0MwlbUs9iOAXCJsx7JTIldVHZShfAILszeBybToURl3yR3g8HgFhybBwzPumaYEq1cyBcn4CSmltURupO5Dbq02XqN59YhEj1BAxzb7r5yIgsjlXATlkAzLaN22juTJN9xs1/SpBDVkZXA2UJajy7t5EJ5j9yYG4UCTeMtoq8F3P3YuauKEcaxVCuwBkpUDeyVTzEhGzawIwBhmFBqRh3Xqc9yZeufv5fUzZZSp8eHkGSFhXizsdFjtDnmf5A0dGpjZ4H9hu7A/Fdt6MWYOxu4scjO9xy8JTL1Ndxr3UI4HVF4RDRs1S+YeRAC4CMSSu/SUiX5rPmjbL+67lW9LHwkkynbBI+7SZZWZoAbWnSHbcVfXrTsXLXvRG6hbkXTrUgxMnfPwNnGaQKspVKtmiOMXr1nkDWu8DimHpHO0n9KvBhFn7bi/f/WpvyMPf4znq6ZOmoZZ1l5qPys+jLC0b47CgcngM0ZgRUASJ1CtcyMYHCZVqQ7+gKO4K2+4E206vDEInnZTD+8whbx/L56bZiMyAO5l2KEsffST9zZYr3z6vAIcF/hu0RrtPEFGaHd3+Kng2N3Jz6K0G3XuTOKGpT5sPXfVCrhhlA3Sl3OptlHeC5WUD1HGIYO/cY2Sp9rKV6d0pDoRVwOb8W0seRroiqPcyBJqi9+lKPp94Pt+C6/RuDCQ7lTcLg6tVp7sRog2IN/tr25u/+2jYQ/CQ2I1ZikQfz9FnyoJcvBcHnK7U0dQoLKHP+Da1nyTrJ/xvoJ3uWftonDjMWpW+HrtF8LWQv6m4v9ErHe6gDQjCQD4i5x48ujjVOmSqRTRocB8Zp3ubX6Pprf+C7tZ/ewMexyC/DMFvDsyzn2V0RRDeuuaU7/HAlkALwsUchmmvlDly/lczv8SeDVitsphKwFCsGW4M1nNY3SMj+Kb5RHYkZWxl7dsaG78awBeFB7xTotZPOxJmJcAmatEfMtPtwgASf2J+yPeQDykSgdeVp+txxTNgfmVBuZ/hMuWm3RGBwjl2Q8P7+ib9V2ARgM9rXjWSIpoRFCzspzHpC0G96FHpBIrxsxhZttbqAME43ec20DYi20SwJfwYQY69ITsNPwUBV/w3ahVkRQt0IPBycHcIvyFUNV8YP79eFUl3X9HyOHI8t3/649265zX9bjGeZVnju2czqhjM7pLy2/2XpW8Ume4DHfkt7jIywqbNvelQmnzkNoD8qX6h11z9QD8ABncejE+bifRu1XS06aL5sZSR61y3yKZNNhsCc+rxJXUFJAvOwEqza9Q8d3wtcFCduaPU1jN0DM7UKUUZd6JzS2mHtrM0wC/e2F1XTuDGvreM+JVK95ENh7BDgS8wR6uevrfludAa0o3PUvHh3nmtBsVZYY4= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 257f4ff9-494c-42e0-d864-08d9984bde93 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:07.4811 (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: vUYuBJH+JLVF7Wq2xXUJUC64OyMiOAMd9XNZjisikW2ueNGuEZ8a7I9K4ICEnvy/pqgLeWDMC+KK8z+Hu5J44w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8394 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa3.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The guest external interrupts from an interrupt controller are delivered only when the Guest/VM is running (i.e. V=1). This means any guest external interrupt which is triggered while the Guest/VM is not running (i.e. V=0) will be missed on QEMU resulting in Guest with sluggish response to serial console input and other I/O events. To solve this, we check and inject interrupt after setting V=1. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu_helper.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index bb7ac9890b..04df3792a8 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -287,6 +287,19 @@ void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable) } env->virt = set_field(env->virt, VIRT_ONOFF, enable); + + if (enable) { + /* + * The guest external interrupts from an interrupt controller are + * delivered only when the Guest/VM is running (i.e. V=1). This means + * any guest external interrupt which is triggered while the Guest/VM + * is not running (i.e. V=0) will be missed on QEMU resulting in guest + * with sluggish response to serial console input and other I/O events. + * + * To solve this, we check and inject interrupt after setting V=1. + */ + riscv_cpu_update_mip(env_archcpu(env), 0, 0); + } } bool riscv_cpu_force_hs_excep_enabled(CPURISCVState *env) From patchwork Tue Oct 26 06:42:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584031 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 699B9C433F5 for ; Tue, 26 Oct 2021 07:26:50 +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 0741760FC2 for ; Tue, 26 Oct 2021 07:26:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0741760FC2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:52878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfGrB-00080p-50 for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:26:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB6-00038D-C5; Tue, 26 Oct 2021 02:43:21 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB3-0000fV-C0; Tue, 26 Oct 2021 02:43:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1635230597; x=1666766597; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=F4pbNsiSyjXt/w3RGLt2kpfldLdxI9pJ+NPektJMfPQ=; b=a6NjxA3U0w35K79y9As9Y6GfYpHjOK1i/GQ83Y83SwRZoYfMLK390bde 718dWbAVnDAE9DSbWHWORG/pm1uie0NhrdWgYPj74HswR7FzzndAYCeKi 3xpUEJt2iYxeEWQtAjuABDsrcSw2PBKbg3jTKdU6RjlF7T1gSCgOT52e7 4BtQFxlgZ7WSDUt1mUO013beplh1UZw1Lfextm+kDVmfgGfK9CxZ30Dka 3ARC0QNjx/RqRweQHJ05dra2HBocTAHQIoGrDKH1Bzua7AZvg6yRczlqc NTaH2a0a8jWG0l/Vo4fS18Ygdad5V7cqgA4sM5hEmbpxOOA1WmYWbg0vf Q==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854745" Received: from mail-mw2nam12lp2049.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.49]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:13 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WZG0qxCs59jshkMfYc5UXESi07zahCIRHpGm+/HPAaVpVPPmHHXdiO2RJnQAqt7+P0oFka2ZgT8dZNRaTLa3DoQdnyN/8BVhyYP16RkILGfFn+2/UQtONfSm3hk9CBp2l62/k5mHAg4FPJiU/olGgi0+Nbko5Ggcl7yMBGsOxYwtU4HdtHM+jHVeWSmy16m+h7HAs96lygxSnp+Vls08PDqRCew1PtsQHjSscYB+HLBuL3IxbDjbasE+S5HMfgMoqpT3XuxaO+DqE7btVeeskMzOqcYVCrYnkb3G5GVIr1wdcxIn61yWXXDUQbBEz1RtMgpFZGXwyuUX2IAxywOilA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2ZRw8yn4wv6nwmvRB4TZv4OYoG8c4FtHXTYiLykfc1Q=; b=P4PfQo6BgUL5dsyxd7lyi+ous9vsiLJBz757oPpG8rtxBouZg5frxKcMpPp06q2JobUDxBX6U3d7AoWfAFrwq+U9IXODWvI02LRPPwHfII4zfXFOC7tBBtM+gDdgSdHr9iDgMKhfrYuRzx6VdeMj/DlavuV4z78msAJfegAJiRHphmCAMVOJexMH10Q/FYRxR+RgvPIFDZPkwdS88YkR2PzfQfLC59KBfvkGs+bMvM0N4WZSQ5MtyL142+dpZTz2JZNI1YRx4L/CbEwr9zvyFpfPv5Sn+ChaL62BZNtB0gRQ91nC+LKrZ4V+Rj3j472n/7KQoj1BxjlW0DIW2IkNbw== 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=2ZRw8yn4wv6nwmvRB4TZv4OYoG8c4FtHXTYiLykfc1Q=; b=imZamo6o8lRC8Q/1CBx5m8K8NPplV6Q/rfmVwf1WcecT0wst9MfxD7tOx4MZqmcffMl4pvtSNRYfx6jsrXYgthvl6qT6FR/7hOLf5d+pnIYx9KKDC03WVggkphmZJHS66aaMc8A9OtQYk7m/PAZZSvzLWvCu0oZMFeQtsIOcl2M= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:10 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:10 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 05/22] target/riscv: Allow setting CPU feature from machine/device emulation Date: Tue, 26 Oct 2021 12:12:10 +0530 Message-Id: <20211026064227.2014502-6-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4bf7f52-c4e8-4475-78bf-08d9984be084 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NWRkA3yP6lEWcq0evpPY7he7DflfxjQxZLI9vUCObGicTqvF+STbHb0DJ6DpRmPeWGn4AQ9NlI+LvMzHVajj+zaAOn/CpUc99FphEzPgISF+cO3YY3M0T6alAiUQYVP4oe3N/w/3zNcq4GjCBPWMLOjVYI9r8SCY15zxbOvyD3zQpWjwHPVRo1ya93Yjq9cOHb1ga4Vs11FqyvziQ7CkS/GyVvejNqkAjArx0JCg2WWbDaSwKJeqSwy5OFC8F+H3I1JSxfEcHNaXoJu4UNPAN1IHNRovza5Kjc7peWqjO6NqdIBS54s4vETCuaDtu/lyjITZ2yQhS7Xy839VWo/qCKgHm7bp6XDC3lCQ9EnZTPcZN7wqs4jESDlxPwRdBjsDnpB0v2l/bdrBLmz9B1pfJEDA35/f21eFq6D03dxDkoOIIFfYCbP1t9/OVF+XtaLUQpMIwHD1mz5dxh0eskWCaUxoy9Lmb8jb4D7+ef6xe3entyKflDWLno5uaOD04OnQEEmAqE9Xkn1N9sp2VNUdM1ltzxcB6dG3AboBtXEG+M1k39A9vPsQI6tA5Q7JQGZyjPmjwQ9FCwZKmSsiEoZG59KQaG3P4PAKuiRxEvrCMDTAGq0Lo1DMrfdWb3XuV+HodED1BiSKcm+WOGT7W2gLynnBHMo8qC6ByBwNBg9HGT7vNJeCu1NF3Ccvi3WIs2LZPX/ILAhX10NEvJZ8MUWoGw== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OYVmoWbldiusoO+/AVsoRPFTWWOZFWnhw9+g3PtcR3yhR6x/Zj5CjPR4agZR/c3CDp98UsS+RvlolDTttSe2snTGZYp/CtyTFg6uZ5lWc5yrWCarqJQIf2u1uF3RhpW/z7qSCe8Ki07X8a+z7fe6LnI/4PdKnuffJ1hpe63sdIGfP+vH16faPpGpke64YJXvnoiVe9bD1R822uaPsMXhZ5GxDmN9BxzzNH63wfHPW6weAcZ6hfkO9VyvxY2mvB5HiHSchqBealtwUmnvzOwUbrE6+6Ju/L0gZx5lsTdCCcWAdh3zdV/K09LXw4K5JfPgwQPtqpsVvMRI3Cd7H9SP79CcvhhttkF7e9KahwP4HarofC7wKtKtU8TqR6Oee5e9DuRM6uUka9CyGeibQEQ/wez3thQE79ahclaUdO03aYo/UL68Ymo8ZProTFTeYI1u7+0Cgq2Zfrni6yaGYADG71Jgc3YtfgQ0drpQhaS+ZhbgBc0cDRaBlBAxkSifxWzOPzGjO/qrcTFUNG9+tEdTjS8i386jyo4EFTn9zx/ShovURfHI6o3eaDEXHYm8zXoCc8z9LnWWer4c2nfgrVteBdK5JBqQFvWcJCzTr8wHRGLnBQQsl75Do1DXqSiIzk37J5ysJzRWvrtsWviZvw/W4PZ6Nn6kRI7r6JahHC1MlX5TAxZ9QQBC3IpgkeSRycs3V8v6UdrGPbKbZXbwUKljqdXUHARb1Y0UKa0D6HGNFnYw2jpGikNLtIkmjiH6nKGf54+4fEn8o1c1WNC9x5HLHN2mgNKIldsBBWk0kQDQ45uKuYhKq5YkGL5WxefBGE/+ztsUBRqovevlzHT95wlItIAHEj+SUY3nOHOUMotGIYwVkMGFfmTv2io6S/cY+dxP9OwGPHxYPXFx4gIo7k0DdowhXySwB908YgOSzwMOVU+uAPU1Wc/yIWva8SE7Bv2xO1LPN2JDs8pLve1PYXkiwZ4YPu87pYLx/7TTvwxK2R7SV+mDN+yP02pks3fGEdQZkXscxsgjysr+9Ml+LdeoBsY1V2j3vpyiUk+XK8+tQG3ihfDX+cRn64dDilGJcxBjHmvYPXQkc5pswJj+6Ur8RrnVVXEDUoT5KWHs1T3u7QjNdN3W4/DeEb4YXez5Vv0X/+zQfwrUKjIE6m+ZD+4N2/3J86I8SE1+IOsvAlhEaVeJiCRukyzr85oBh72gJ9PjCc8yNnGUTrQEupgHNAPHOIJ45wVfMJ7gqqoPz9/a4pBydMCVtBK/+9kG794dME2prlRA2iExW1Q+jYbbBow+720KpqL+LHbsiqwnQAfKHm4UPprxK1xQK+oOP2Vl/azIrJJ0fl4r4pU0WP1OyG7lSnyCpD0pLEN+jhpXGukEQUiK5Ri1qCeHDMeKEIAed/2/jM1O9aQcXe/GA8QswOb6LCfIrPTxKvCqrnpZTHpu756OOqaIU0VvP5AGZr5oVuHQuK37v4KmGs8G8Vfr+sfr4tXvefDGkNHd3FZm7kX+12D4dBRUUpPN+K43DAkPQJ3o1+F1gBoz/NOBMBaD5LJ66Dvc0BmBiJRBfqsx+yjQcLZuSyuapinjwhfMZYUGMV3RdsvJoy6xpg4lPRuRSkquxFweWBcVIfL/vgUSD5oPDsk= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: d4bf7f52-c4e8-4475-78bf-08d9984be084 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:10.7428 (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: sdiTxUaEDXVTpwEAL7dXTUcFZGmT/deZuc0RPY8A7Z6A83YSn5U/EGAGbbYOrPIznGma+4GPgp84vqVoKRoAAg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The machine or device emulation should be able to force set certain CPU features because: 1) We can have certain CPU features which are in-general optional but implemented by RISC-V CPUs on the machine. 2) We can have devices which require a certain CPU feature. For example, AIA IMSIC devices expect AIA CSRs implemented by RISC-V CPUs. Signed-off-by: Anup Patel Reviewed-by: Bin Meng Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 11 +++-------- target/riscv/cpu.h | 5 +++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 8042c4ebcf..69d6b5eb36 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -124,11 +124,6 @@ static void set_vext_version(CPURISCVState *env, int vext_ver) env->vext_ver = vext_ver; } -static void set_feature(CPURISCVState *env, int feature) -{ - env->features |= (1ULL << feature); -} - static void set_resetvec(CPURISCVState *env, target_ulong resetvec) { #ifndef CONFIG_USER_ONLY @@ -425,18 +420,18 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } if (cpu->cfg.mmu) { - set_feature(env, RISCV_FEATURE_MMU); + riscv_set_feature(env, RISCV_FEATURE_MMU); } if (cpu->cfg.pmp) { - set_feature(env, RISCV_FEATURE_PMP); + riscv_set_feature(env, RISCV_FEATURE_PMP); /* * Enhanced PMP should only be available * on harts with PMP support */ if (cpu->cfg.epmp) { - set_feature(env, RISCV_FEATURE_EPMP); + riscv_set_feature(env, RISCV_FEATURE_EPMP); } } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index bbf469f079..cc035a8897 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -326,6 +326,11 @@ static inline bool riscv_feature(CPURISCVState *env, int feature) return env->features & (1ULL << feature); } +static inline void riscv_set_feature(CPURISCVState *env, int feature) +{ + env->features |= (1ULL << feature); +} + #include "cpu_user.h" extern const char * const riscv_int_regnames[]; From patchwork Tue Oct 26 06:42:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 307B4C433F5 for ; Tue, 26 Oct 2021 07:58:51 +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 B826160EFE for ; Tue, 26 Oct 2021 07:58:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B826160EFE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:49140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHM9-0001zl-Td for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:58:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB5-00038B-Ux; Tue, 26 Oct 2021 02:43:20 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53140) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB3-0000h8-C1; Tue, 26 Oct 2021 02:43: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=1635230597; x=1666766597; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Nx9wCl2PjPZzfxgMbTLUztdO8ypGA2pn2dH8yP9taUo=; b=VOg0Z/77NMvvWj/LHvbsM7//mQwEPFSHUPQBD73VQAM6KXU1E2OdztLW n2gDzma6tvEYfBRLVmieZiHFfqHwKFWZJrL2erhyfp4sOmImqzCJzCYTo I49njPteaxSGP01U648KE8n1G6re/IW35LW9W4eGeFtfp5O7bLtkorvWc 4exy8Jgz4CpnfMRYfjJvAqlu0PNGLNu9J4HudgEaKqPqWIz2THlNBGrv1 Swmyej94uBwjcKS5T9POqh3eUa5d1+Vi+Al/PHW37JNJEx3v9KQRvhWzg CgQqIEw0tA2kroVTIQVcYTTV3t/RFxrEo3IZUmwOea7GT2StzBd0GBFbm A==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854749" Received: from mail-mw2nam12lp2045.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.45]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:14 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Og1Rnbt3oK0DnMX60UfWyd3YtF8aQJrwjL+BjA8q96zN+P0T4dtWBIulbbFotKrATO6/2ej50QCeAiaHzesfZM3gefXf5GeuT7qCIrqo6csg+l4SKzVoePbCHrsmyN9UlG2BCd+3wgLxQw+TyAzdfkEwWhe8zGGPQ6bJ6DE1KZjgzb4KByh7BKMRlqH58CnIyyxruLofUpq4bOFvN9VUCbV6IRBvQqd7fqeJZa+fMKmFQbrVVFfFGt9UuJmZamTmUbaiY3LrPwbZtPhjz2rJQy3jAF76YiGB8ZjJn5tIfzlzVh68x6a9KTqR3bDivRHKam+dMY63pSPmSBs1OG99cA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=To9GxHvfKRpL30vajheq0UdXgtqFpVnZyox+gEMsUAg=; b=U9KXZq5zcFXD7wIF66uZZK/ChGohdriQUUSflLgjmpGq6MUbaEonQufyf4VE7DjJOXt53/O8jsvmITT6gESnhSlwyhZ2inu0R06Y1exOKEPtx3buJdFIIuCG75iQLYfA/0p1Aw630rjuixypB9ckQnAPi64gAy/HUYI5smbhfNxZil9LurVdnPT40m7mkuQYyZ1663CcJ1YiNWl0ZfcuYawkJlI3TXufTq0cJ/MlO4t3qIaDljGszuWBRb2NAKC0k7mOa8FI22uelKQbEFvuYlmILSKVmaAMfpJi/T1SMusoRF0xGVsFHpSRpHsZeDhA4BVBlbqXd3JO5H85dvWywA== 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=To9GxHvfKRpL30vajheq0UdXgtqFpVnZyox+gEMsUAg=; b=VMw+Zk8B7mbkR8R9kpdQUexOFPR4gr+y/HKFjt/8c4J3+s+7cd3O8t55983x76ABcijA9nzTsGXwY1lHfPwSK4wWk1+Mi0tYO9+cNeZyVz15bBsz4wXo1qjfOxr9q4sJsFoyNevUZTLRl9VSlo674kdyONSzG//NZ6Rcw0uZbxg= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:14 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:14 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 06/22] target/riscv: Add AIA cpu feature Date: Tue, 26 Oct 2021 12:12:11 +0530 Message-Id: <20211026064227.2014502-7-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b3f02a6-b41c-409d-01f4-08d9984be26a X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ta1EjPMkneWLGQUf4Aa+rObNjCumf80KZZ1FL7lEollzawCDH+uwhf541NyWK5be2ZdsXoaQ8PiICIeu3bh7dJ+zKoiPLKrGIHAQujSU8TSmTAjjpoEPO/WaROEiqTSm2embUVCcrzQmxGmQVmi9DrglA89O26F1hkz/2NBaIf6FZcvUtVIiQnFU782TU6XCw4YyxqOoK20N5VC3p6MSbEGGl+c/kgIFbLXF3jjYWfsM3xG+PHzDrhjM1PunHj2aJ5Xf8JSyRGcEGlHF5Ko0H4t1lIYGdGssKyf8crrjynmT9tZX6u1Uk9Isrs64GuLEvXWIWkV+BLK29hK99OCgXUE++qDO1Oap0ftZW5drNGukG+FOWvS2MOf3nVO1M4S3OYn4xKMuY5xB7gnclxk6H+CXmbfbxH1kI0mKLUoVLJaEaHjo48idBa53gGxD45QuxycCF2oSzTl51R2SpsYPqv1KAEJajWXtwVaw9NY+onb728bMsFvrEiutQJWj1ljYu3WpyEinaB4Aikj3PLDn8bd9aKP7Rl1JPogZ70haePBwhfMAp5Bqe6EdnehlE3nHDYq+otC41a+dEMbUpD0uA8lb5XslzgbP+kQUeDqQ6NOURavoZakr/1nJhODKhWbrjSVhJlcLmTYEP0lQsCuzkQKeqp+a62IyueYTT8D26mD/4LpclmC+5ATJvrg1xKKb 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(4744005)(66946007)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G9GZb6A6QVa5AHl748qr5OTJ94Iw9WK7Aq4k7uwuekkH7v+D884qtMhHG/n7iXWoic5bEHD8xB/6Ej1HiCoVhq/hG4AKIU9D5CsIP+UHhUBwTwm6U4HZ/ClQpbaTZUGQgXCmsPgGISBqfXM891pW3UV6VbLpUwNrpcTJtpBtDw4HqYYUb5HDu5gDY6vbfDtNMqOCBV6BP6IrXMs0tn6MDAzZ/DgEgNJ+mLIrT2MqJMbKNAfR00XxK8XJapEBMYeXpp8zcHIej6GTnyRnuFw/DYvaYwAh8FYKzZmSQCIvHGZMZsPGqSL+rpsuswA1q7uEFeZVvDBnmhbCAXzRfDOZo5t7XZrre+Jcv6iEYC7w2hbeYQJxfbsmRXYxpSIOHjubdTsTjNzI1Xd4DyNBizXrEOGPYVq5LVWjuVvonrgfGG5JTx1ejYwky1LVVJV0b0O1jTFH83mg7gKJg0gBDzyiO2pjI+ywM0ynFnFsCLN1Hj//llUkF2rl/cAu7G9+AdfQSo3MAL9aBiRt15exzuuoejOXt/CXZtSv4nnFc0NYH6T8qg40dONMEGjJNjyLgiSqnE4ZvkYbvYsqkhu3FTgmCrzJWpUnxi9nMWAzq5s+MZlzo0Xl+Yf9uAnesOpz38tsG1O+voIQrP+zkPxgxkvZN5oKncczkJ6fumNoSzaHRDiUQnefqhTUChjiKcgNkSlL4UQgFFjc09euzx3RKvwmXFKnMFJieHgpM7PP4t3qiyt/ggWVm3nuIa0vHlPq+ms24+o3cRgQ6RkM1yioTS0fEAdO9rUbLkTBJYxjtluRY1r8QZY2jkf1qH2vIsydnp6ivYWWVEdfqQw1a7ozT65KaMQwSw2RZt5KRErtjZRb6mmV43Wh2YhumS2tNr4L+nE6/W1pKD4qgLBlqfwWG1NroMB4dmv3xnKQxIdZKhwVdiLp+ilGo2b0hNMjvCNKX0fCkLXdvmfu3U0SKS768EIy4C7T8VgROj3NbxGsRbkkYTJ10W5bdiUBPZpOYDY7aWU2i+jNyA+Zq/wG7Muvh/cPFd/pA2jKBkBiq+RrEmgtm+6pbAhzSCFz3eEt0dF9EI88fROGsW7ceNjTwJSmLUxXWFzF8yxbTwvrl0CVyo1HBy8v+TO0MK+d77Sm2lE6RV7oNzeVP6PtsraFX7sWtBrdAg/73DCXc273Kx9wMOxSTK2GhARE8ZBWYTzV1VtTq7my0Z7j6RnopS3BX1zTg2dHxVvh8ZJ4PHETYes23s9RrlyMIT2xVZAERxln+8n7tvuA3AjvXFKZaVcF+aR6FRb48RXXXS5xkBhQl/brjymIh9z6PBP9nMBbn7S9cFviTpqmxxW8Uwsi3/9e4w40d6oA+SGkVB36zhq5WFbBDQERtr2cb1rjREq9IL1eBY6t2o4lLsVrXa3Y9//sA0FOhmK5QK8xeMf9By+xspwh6mIS5K2/WZgqMHHaqNnHJ/q/BaLD3Mx8ZcPjmYAnxsu7k9aVmA04gSlR0dDi1cKN59k3evGvfwTH/9rcKby5DpMKH5LwU/B2jLTIlhSDl3nh2jHSLUQ+I+gye+qGIdP7AyFskCKSxVA3w9/2P4b+9g2MPB57HmQxUNZTjCMSnmgHwPKA1NoFuCG8Daaf4ttZIJ00HEU= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b3f02a6-b41c-409d-01f4-08d9984be26a X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:14.2673 (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: UD/DZ1ppLixenj0GAFFoPNeVtyy4H90zZ8Xcy1FP9YkMEE6DK896jQ2mjtXq6/YK66muQ0qpKTMHZ3/sNRDS/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We define a CPU feature for AIA CSR support in RISC-V CPUs which can be set by machine/device emulation. The RISC-V CSR emulation will also check this feature for emulating AIA CSRs. Signed-off-by: Anup Patel Reviewed-by: Bin Meng Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index cc035a8897..7182fadd21 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -74,7 +74,8 @@ enum { RISCV_FEATURE_MMU, RISCV_FEATURE_PMP, RISCV_FEATURE_EPMP, - RISCV_FEATURE_MISA + RISCV_FEATURE_MISA, + RISCV_FEATURE_AIA }; #define PRIV_VERSION_1_10_0 0x00011000 From patchwork Tue Oct 26 06:42:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12583929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7C12C433EF for ; Tue, 26 Oct 2021 07:06: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 2A76560F92 for ; Tue, 26 Oct 2021 07:06:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2A76560F92 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:55130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfGXO-0006ob-94 for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:06:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB8-0003A7-Ec; Tue, 26 Oct 2021 02:43:22 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB6-0000sH-5x; Tue, 26 Oct 2021 02:43:22 -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=1635230599; x=1666766599; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=VFsPm/Le0NmunV+Z0t7675HUmm8YKZpuqWcYIU4WpSg=; b=RlHGXxXa+OPio+wa4UlfA5qrkr51uVsQleIMJ0bv2fOn33L2rt14VHm3 oW62OqMNPRu5ZJ7eTS5tu7hB3/+R4lEo2hDoY6R/REbP+GqWNCAYGqBGJ ALTZiBBFdqWljSFS/O4oXCTXb0jl1NntvVoEP7LBHFszbSungrp+unH2m YVQEaLjF9vvK8lnL9D5Tp+Xw60rRNpkLgAGYt1FB9o6eBVLhpWAbXFvlJ l0GhlZx6sSYHBSwNuVPZfjk/a9U7KoAHGDKWlZD4Wv5rD+lmogkLgoerq 0cbu8rwlJizl8HWs2y4DpXcrthci7PHtOhTF/ClWxZ4/61GaQOYo+kTdT g==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854756" Received: from mail-mw2nam12lp2047.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.47]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:17 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YPCh0tNje0EuO6P4vT5YlU3jQI3gWm8jSiaL2WaECjq6PQH+iFXnF6gBfp/T32GxlNGYjjmdaiRrPYjrrd92njpxnAjgF8QEM9CgS8fpgHSnENeigafMlwNikOGi63QFBVAb/h4W8krqwNpOC7L6CKMcI5q9pYCPcP0RUpwzPxcjvyNc2dHvYXOSKajV+h9tGC9zUdpSAjBZ/QQ5yNvnjP2r6lCjZhwa8XGOTNeMT09adWToitrjNuRR+8Zf2zqIt8nY6sM2X3/IQFzClP1mVuGjuABBPrGe1rKdWU4NahKbQhAE5pEt0yiMnUYC85ov5bC46EFQIjCrZXkutK0N4w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9rdkORUTMcNAMPkdUgbqfjrm5/Q9/FUfd14WFnTfzFI=; b=KLAEehVdBj9q4SIxFsIEv9U/Rt6CpQsHKB4gJ+W2jfGCQT7OAAxN5KdSgA3IdsEHugr6i+y1rFh+DBdUbe/zWQ7o0N59/Gm8L01lrOkl4UQ+m5/wkWH757CRHmZkyHaGoARpVldphMgv2+Y5HD99i/2j5IB0p6SyDsSX1zct1aCEIXxyjzIxprZAEKlwMN+HreyYHAj7eb57N9hNWPE4BWvvGLGTjTD87hySv8bQG8I8rF7V8SOqFf4Tr7dY1HJNURFUvLQi609QBeRc5K2PaeS41P66/UgPlFRKLvK2b/QZdd6oiQwsAggsyAySzSwTDfnOcGp/vLMljPsa1KX4/g== 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=9rdkORUTMcNAMPkdUgbqfjrm5/Q9/FUfd14WFnTfzFI=; b=mqY780v6KFdKc6ojxtiM9QeVnf1jmo8y8MsePJ5HTegQh1FfSZJpRQIe1C3x7UQckJe2ijmZ/w/PI7+uZwRh739rCbcXTRJ/HVEDhUMQ8oY7BVRWienc6sIv+/znoYsjnvKBo1QndoVDOXsRHzvSj8/LgQAz6ENgyUq+wLHV3XU= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:17 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:17 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 07/22] target/riscv: Add defines for AIA CSRs Date: Tue, 26 Oct 2021 12:12:12 +0530 Message-Id: <20211026064227.2014502-8-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9cdf0515-edd7-4b44-71fd-08d9984be463 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:298; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FVSoKjbqlNgO9XSuhzsxs41AxrK28PXYWwwBjxw0nmc/NxqXTM8w1gtNY72M2UgRuXtM1DCWZYs2NcrmwTT3qudmj4afN1+CufAFEHAEAYXU5GKFbVFjIgsufV208VvAmEDnU3T0/KdUHGlvepbX6dVmRkKgzB3pYqAn9psWUu1BG2jY98lhbV0I+68ItJoBXcwr5f0YD0dxTRh7GELa2STChE4dk2yd5sI5G/s/7ONWKx1i8hfSum1VA2hqQxRXkbwPkHtyb/2Eo1zf4lHCPcT1gaqRS0JH6+GgBzzvTy5P41lnG2UJogfaVsyDt/5xB23DAQtAqQZnyAVOtkes1AMElHyAmSsuPpdVxGpNSnQiDOrFJgMzzPKx36byGgaXKhuACU/VHOpsHyJxIkbeoLkGnjAwWaV/F5843WTqwFi28dgdMhZ35wnazAXYzChfXSm1i7HSGmZjugzAsgmn/pipALIocYnXE65hSExLQDwTEdBCuXhk6GexLnBLx5h/gYqe0s74P8FykKnguiqcDRiTkoCGgUGRuonC62glPw68RKm55PRdYt2Lg+OBphkyyZWzFqW+Y87I23HeaDUoZogKUSZKNa0U8M7YooGEGYJXlwd9w6/9CDLhn42EbzU7aO7yVNA9KYwq0n0hzBuAvDMMeFCqgSMePiSc1Xpqc/KMrJTz7E9ofRH9yvxrcx/0bXcdiYmCA5tKCOm7ZI5hmQ== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(66946007)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xGIko9RJdojklQ6h7BKLMZ/Mp1aCF8BMvm7ATG7z2Bbn63tavSQx8Q0Em5QrBp+kCxWczgeSTcx/QQUznznOORDGlyuFErAxknOPoR14I2nQhamzs4d37pr/jDDTE5ZD1pg9ufpxXXDcBI5mPIfJQC/r+tzX2Bxgtq6ARfHUUg7c36h/bGALc+XL2fpd4gOimU4P4U8HDibuHpJQ+2F1f8lDstdMUWJ6WT9QfU2rMlMOvJKlLi7xfu190VPta+DNm1SQYrIb7ezO0lpkRF2wXJEbwh8gAC0agT2amDb/tGj/5tg3aTsV3gjxVF/6JKwxlS3UdoBmB7FgHcZ11PP+e78MF6Hl51Pn6CxxEHWpZub3A3DjW1n4EihcES2ju+gASCYP0s2e4Jr0o5VZ0oMg7QbNtnpHwgHlw2AurYE2AvNp5w/3DfHpXZ5aG2RB8x8oPd4NC2+j8eek9p81eCyBghEmRiJCQBCfYXv+4+bHFqkvyf34askpnItzFNO9jqTFM3wd6m02bw1ZkAP4ouQFBoB+xKtAuK5Hpei0nC3LxNWDwwCzZTVycx21UE3shM0q8XjD2SzM5ZHpOLtDhnlYRvF5Dd85JTjWH7/sVFDRlytCYhTyuHF17Z9kP4wXA/yrF+C3F8pvPksL50NZa3R5j/lz6iKd1/731iuPllU6mkX0ru3Xhtj8KU+E3Y02FS9958vyKaUZWtRYnM216myRaybFGUuqJVZxRzmFhd5Z3hIBRftMpGpnpOe/iqMsBHrEMe5PuC8DmMUPQX4eYuNeYj2gpRG6vAn5FU6z1QQzMNUj8uEfP9VH8tSNXu3VERNzvqcFvLSR0B6B50u9c6rBwyI80Xp2YFWdS76SBfzhDtcHRXqtSHC6j67/rFELauL673jsi74jAX+z6bssMYcMoQBoNKW7Nxgjjo/GBO7ahNcrDdzSAm8KLlQ0WaH/M8KrbgcdCFJ6falNn+grPqShQbxxo4fPj1Ye3Ae507EIuYw6HS5P6i0vwCfCBlF8mr9vRRVB7oNFHloz88LEj92G4KQKaiDTX452x3u4dwpAi534BQqbgfrlOVWX/aUnwo+HXWJC6R5UtbHZvUu5Le9C7Ts+7MjTnjxAltrEnK2JLPM6/32CqfF32TxWlLVhWT+7UrYyYFUXXIZ5x25nYFJvxD/meTt9o4b35Nix0LpClcJ9ICTbo6EH+8Uxq70thChfytUkHQdEd5o3A4pQePgkNbcaQF1EaGzNTgvmpuPWyRFNLwCdeQUorwGfdxtzr4b2n75g/uA+LAjPXKL7U0NtA8Cx4KcHidQjYeRI2/sjjX2cbMvNRizJ0yI4SeWzdfTQQ6MOTChEHt925tYM+q7Nt/h5nlkCdq9v56VNWA7lushpygoEwb/hku/ZDP6MRpkiUENa1A3L0Eq4afdJUZZwJX2ZO2TdvuRYriDqAQ8wnYKs+fivmXTSASTD+NLCAtSqng67uyWj9mi3BWJaSwQuDxBiEif9L6rHOSehIu3kwoRt8Eb1hTN20jNr2Qe/zFCGMqBtsUoPjkiRlsTQasQBl1CuitXDtO9sb1Lw5UXTMVxDNly+BCZlKionzBNxjQrXWuhHvJFdUyoFzg9ansXR/EpqByPCNkhHeI683/RT9OI= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9cdf0515-edd7-4b44-71fd-08d9984be463 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:17.2472 (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: j04xR7zn3da1geJx621UYtbzIuVMDCkIa7YBew67l7KwuE3VpoW7ojlX1/U8vO6fmPQtp9z6eO6/Sfuiu3yX5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng 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 CSRs. Signed-off-by: Anup Patel --- 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 335e0193a9..0a79784d99 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -160,6 +160,31 @@ #define CSR_MTVAL 0x343 #define CSR_MIP 0x344 +/* 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_MTOPEI 0x35c + +/* 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 @@ -179,6 +204,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_STOPEI 0x15c + +/* Supervisor-Level High-Half CSRs (AIA) */ +#define CSR_SIEH 0x114 +#define CSR_SIPH 0x154 + /* Hpervisor CSRs */ #define CSR_HSTATUS 0x600 #define CSR_HEDELEG 0x602 @@ -209,6 +252,35 @@ #define CSR_MTINST 0x34a #define CSR_MTVAL2 0x34b +/* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ +#define CSR_HVIEN 0x608 +#define CSR_HVICTL 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 +#define CSR_VSTOPEI 0x25c + +/* 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 + /* Enhanced Physical Memory Protection (ePMP) */ #define CSR_MSECCFG 0x747 #define CSR_MSECCFGH 0x757 @@ -529,4 +601,60 @@ typedef enum RISCVException { #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_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 +#define ISELECT_MASK 0x1ff + +/* Dummy [M|S|VS]ISELECT value for emulating [M|S|VS]TOPEI CSRs */ +#define ISELECT_IMSIC_TOPEI (ISELECT_MASK + 1) + +/* IMSIC bits (AIA) */ +#define IMSIC_TOPEI_IID_SHIFT 16 +#define IMSIC_TOPEI_IID_MASK 0x7ff +#define IMSIC_TOPEI_IPRIO_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))) + +/* HVICTL bits (AIA) */ +#define HVICTL_VTI 0x40000000 +#define HVICTL_IID 0x0fff0000 +#define HVICTL_IPRIOM 0x00000100 +#define HVICTL_IPRIO 0x000000ff +#define HVICTL_VALID_MASK \ + (HVICTL_VTI | HVICTL_IID | HVICTL_IPRIOM | HVICTL_IPRIO) + #endif From patchwork Tue Oct 26 06:42:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D9D5C433F5 for ; Tue, 26 Oct 2021 08:03:18 +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 7C23960F22 for ; Tue, 26 Oct 2021 08:03:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7C23960F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:57380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHQS-0007ev-EL for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 04:03:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBC-0003Ew-GO; Tue, 26 Oct 2021 02:43:28 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGB9-0000sH-2x; Tue, 26 Oct 2021 02:43: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=1635230602; x=1666766602; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=NGwNLy3VtsuvzQvknfNkvFHGtfZZZZlsEz+En4k0Ids=; b=gBz5BaFx7tLi4cyl6z+Jew/2ytpa3kSPD4/0ikYplaPvN7hv52TUYx30 Vh59A4mGXCp68S8oA8x1uZjlYGTeqxGOHJiUb7HC3ghfPyug4FZjOM/Fz Z5HLbHyyct8dJuyO81Ny1sauaEtOSqZ86vtEc0NmEF7Wv0FQWr/RCyNqP +rL9pc2INSQq7sv3oqNakFtAxJbfy1TWlcC+pv4xl5I1OCC1TADBE0iLP PHmqLX3T7ACriyNayA6bNj7RzOOXBnEgbihR7F7EFMAYmXQsxp3cudmYC et7uLy7x914W9A4EO+xytWTpcMQAxzS15R8hbWsekAB4gq0+D/Z28Rg3B A==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854757" Received: from mail-mw2nam12lp2045.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.45]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:20 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=la9cOHenet+UNKRlo6ViCFnCcFcrTNnmrjqTt/2oPC92aA+Qca3VBjwgy53rWhOaseeaXfoKZh74GR8e62sdl9RmKoZeWmeFRQ5Z+ugBMnj47jDhNUspvgiHPqSvIx9Eg+wlz9ckkUxCbqr7KlikUKakNsMROiuFVria7wa/Bh64gZrD0CFRBFt7tKTs58+aiDIai0NKmm1bRXVMpF9VpdVnqlUZIvmKz/9gyPCnrkm+dl/VTgUeCRAdUE7iJ4GTJghS3KYHK/KJ9w06cl7puxdD2x8fDrEuAyRFqO3J6p0A7At1CTRLoFlWqLU1hAYtIJr4ooaaFbvJvSKbgbm3gg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5IoA+eQN/FbuJHLOtN90iE/uH/FjhhGxlNydRO6Cqc4=; b=df8sBRgutHK2rUb4Hzg5mpRXtElRrmr9O94OuGx3LMXD6M+hcohiM8vjFc4eIqu8P4tWDJ2Lu1Id/u6WIS3lgDVgVTlYLZ09X1ADwQrFKY9gsw/iyI7QS5bLxoNu4zIRMCG4c71aCEfmiZHXEUVVSFcYdkSLvC7nn6I7yQp3Xt4gekuShMHWg2P1vax/yxUI4O8HHvf6LfWXGyxFBSa09u20x//vZ+USCGm+PJ6O+WCVKNLFQ06aK8IL7PNqyekNfW6Vz/onYoprabHqK4/HN2oPPYN4Q8mgU35bu+T/uNVJv9KIXCZF29SE0n+2dGtT77vi8o+Zq0rkvIMnHSMx8Q== 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=5IoA+eQN/FbuJHLOtN90iE/uH/FjhhGxlNydRO6Cqc4=; b=YDYjXzxq5oK8Y3n1HgfpwSSiFVPIF5s9hklAcQtgH853E/PmU2xvNcbl/NRoIO2CMmQthHOgaEq+ek5zabSVgFXrzuzWPPaahlHH9basxSEqpdYfrpm3eabuQvIXyowMmW7+RhJB+/HbH459PDMIPVWICfGRqo3nO+jdUPuxZik= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:20 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:20 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 08/22] target/riscv: Allow AIA device emulation to set ireg rmw callback Date: Tue, 26 Oct 2021 12:12:13 +0530 Message-Id: <20211026064227.2014502-9-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5ef5c09b-1d1c-49b4-f3f7-08d9984be632 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QdPjszVMWLAyvY1W4VRD5X0I2ILlUcAJBf0cL50JC5527zGBkc4Eez5JXdj6mE5kCKz3bUVGnLSbAxnWRynQyUzF6m/ctwVD31SoEAlQypKmFdqhVsXNKwIYTONzmWYuDpImGP0VGfXG8EHg/Y5kYYHB+0nN7PVWM7fhbOObYNaZ33gIVuk5R/eA9f2iUeq1yUQOI3AR3Tzv4llOOBRLCRY5JKkRXxHS2FgKohtHovATrg1uQ/+4hw2CJuwam1BrA1JLOCITsTa8uBqvjzwrhwWWjM4nIc5JS/9lk2GcmXORK+ijLYvesTtZeITDmAlOJh/7rcjS0e9l7KZgxXzsdzgkOlLl63c0GY3iWOdflbHHrHD8k+Gt6e3IFLrGInfF34fSA7a0GDqa8RzDyGZSF1xW5p2Bp7B6J5O5lSSbgjHzn4nPeN82ayPgtCS6ZDXolEeZKfXb21Gl7SWmlLrlty1JeURoQUX2xYBZWQcWlxGdMe5pAYiVMtnIL3Mfmt+F1ow1W6QzNxg4fur4a+5uMKJURLXAqCTlRSe60CC1v/VEBnK1WjVxh17nWBNOjWdx2j/xLIjmQHyFftMl2jys/oktvakLQv91uCvFSk8JWzVXwCFtzp/LQMK2tCRJc0igrZ7C4gBfw55Zcub5v+sChJt+mwqrF+m6bjT8qAh/F9IdrUXBTFkLCizQQs3DsrV7FLerPYEQrdH6wbIkV4/BYw== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: t7OJuXTxSOC5ItA2iuOi6eB8W/DRnr4cH7D2TWO87FZeawau89d3ObuhNRTWZ5OTL6OYZZXGT95I42PmfUSqD+HNpI9enQVM3Jl0Ed5T2ufxQXOdG1kFZgLZRCMxYdrl6BPm+THVccKcVl4w5kZ0SBTn1aoynGbYf7Z8c+Lx46h6mI1G0g5Zo0AlKr+XB2DDP4G/xr9lF1SGjIhbROVEVvvlmGhnLYISo97E+His5Rl8/uEavapRRPpS5JgdGwooJcmLlUFexUEJ6sIJg6zATun9yTZAdDTNx4FVOVw0Z95yRIDDbSOgusgdsLGQjjheHRt9eabcr8zq/zuwdj52aSTFZ0y8q3RiA28E3cMM1RFxttIl7mERGzVHIM8aEKWMo1UPk8HDYCFR/X0eOILnE4rIjkCsPNahcUn0wISJUDnHDJ0tEC4koARlz5P6Hh68UErgqnu4NcPaL2JxM+Zj0KE5eioxxlGzW+BBgr0iVupTkBxfE1qFgBj0VgOBhfgC1VgQH2i3Zg4i4p0L4tKShmxxIoB4xNxq3JsT9ZR3z+HiJ2+og1bcYxWLe+m/3rfRNyikcJuPsUgycl9v9aLc3sxNXBSJ+sikKlu5eoSv1fZ395ve9G38P0b5YMX3YhOtov43yQHsQLtgF0zmtBja17oI1IE+Mn3wBGom4fOUI+Wq85p8DjzobERIqMznYaF1pFwwbYSBqJWqzjBSHdW3L6ViiLNYB+TtyxMlty3pyEoBqXw8crfcjUig0spfrDDuzslRtvQitBGYtlsgM+q7hBSxEE0XkceDeHUnm8oR3s1eQxdEFJx4f9yRM6TVDvZe8hxZObatu6ZYlnqNnCeDQZc4O+jfMKr10QBPTqqZeVRnbndEY/lL4jXno4/uoWVLQTDKohcT9PB+AEUCJEjVs3fq08lq3FeZZR5/RmfGvRPjwDT4TrJowMl7+PbkiGL6Ie5qWjn4We+5O92KZPO+E87ewTZu8ophj3Z2oXdLEGb/dQjg2VadlzAjrRcYIz1vZqaW39uF4Fud2PPV1TjHxeMJeQJiaDhh+iepBUkrzlMJVYFckPCgQTYWvk12pT2Tvv5hzV+ZVwO+wkaR6BDf/IzgU1RIpfmBRq6NbTNov8L58E0JsLauusK0HwFFyXsvlLrwADviGRztmM2z4Birq44cEtBH2P+2w/l2BkC7258ciciCBw21UpJAZBCWEtXL7NqdAuADDeag8isfm1l387+vftoFk7JQVTgYWIND/Yxff6IBAsGujDmnVfKO0+tWR4RwZdbjpAsSpcuUxnpm1AWgo3dErk4ex1z0Wc2yzVU96qtPa3MUjl4LNAIW1yx+jUcfbNGzRguP4LQeq1HjhQ8XiAudlryM4EP8+Jgd9v2/0Lvzdf6NrYVoMEImSCcuDi+uskP2YTfLTnF5msRsnhpMdJOKpnr/uq7cPQspxZirx4Qk2F6BPDyrh/dkeUSzSupi+sU27zsCEqVR9KbvjsgdSOQ8ZVx7hw2F0kSljYhAy8YQPJvDHut0RaYLGIcCoLL21J6n1nJ/YDqYjEcFtaZcZrePC2hXk0gP3rzHCZLBLc7T4v1DS1/tDFTy8NaqLrD/jgAnmWQpdifEgrJ6WiqsEAfopwujxAh8H9S2b1Y= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ef5c09b-1d1c-49b4-f3f7-08d9984be632 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:20.2600 (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: O2YiHFCD3LU797vFaNsjqvyFJ78gJzkY5AxaIsADi8AUUEIWmk+By26Pcuvm4QRBSK+r1mPMmunhU/G9KyNQsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA device emulation (such as AIA IMSIC) should be able to set (or provide) AIA ireg read-modify-write callback for each privilege level of a RISC-V HART. Signed-off-by: Anup Patel --- target/riscv/cpu.h | 19 +++++++++++++++++++ target/riscv/cpu_helper.c | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7182fadd21..ef4298dc69 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -239,6 +239,18 @@ struct CPURISCVState { uint64_t (*rdtime_fn)(uint32_t); uint32_t rdtime_fn_arg; + /* machine specific AIA ireg read-modify-write callback */ +#define AIA_MAKE_IREG(__isel, __priv, __virt, __vgein) \ + ((((__vgein) & 0x3f) << 24) | (((__virt) & 0x1) << 20) | \ + (((__priv) & 0x3) << 16) | (__isel & 0xffff)) +#define AIA_IREG_ISEL(__ireg) ((__ireg) & 0xffff) +#define AIA_IREG_PRIV(__ireg) (((__ireg) >> 16) & 0x3) +#define AIA_IREG_VIRT(__ireg) (((__ireg) >> 20) & 0x1) +#define AIA_IREG_VGEIN(__ireg) (((__ireg) >> 24) & 0x3f) + int (*aia_ireg_rmw_fn[4])(void *arg, target_ulong reg, + target_ulong *val, target_ulong new_val, target_ulong write_mask); + void *aia_ireg_rmw_fn_arg[4]; + /* True if in debugger mode. */ bool debugger; #endif @@ -380,6 +392,13 @@ uint32_t riscv_cpu_update_mip(RISCVCPU *cpu, uint32_t mask, uint32_t value); #define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */ void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), uint32_t arg); +void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env, uint32_t priv, + int (*rmw_fn)(void *arg, + target_ulong reg, + target_ulong *val, + target_ulong new_val, + target_ulong write_mask), + void *rmw_fn_arg); #endif void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 04df3792a8..d70def1da8 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -375,6 +375,20 @@ void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), env->rdtime_fn_arg = arg; } +void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env, uint32_t priv, + int (*rmw_fn)(void *arg, + target_ulong reg, + target_ulong *val, + target_ulong new_val, + target_ulong write_mask), + void *rmw_fn_arg) +{ + if (priv <= PRV_M) { + env->aia_ireg_rmw_fn[priv] = rmw_fn; + env->aia_ireg_rmw_fn_arg[priv] = rmw_fn_arg; + } +} + void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) { if (newpriv > PRV_M) { From patchwork Tue Oct 26 06:42:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4A62C433EF for ; Tue, 26 Oct 2021 07:50:43 +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 376936109E for ; Tue, 26 Oct 2021 07:50:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 376936109E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:59814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHEI-0006rZ-60 for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:50:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBK-0003Lh-OR; Tue, 26 Oct 2021 02:43:34 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBC-00014K-0e; Tue, 26 Oct 2021 02:43:34 -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=1635230605; x=1666766605; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=hOBcfWOZyMxNSEnsrYeNAdCfPEAYfe/PEWI99yI9jf4=; b=HuUxkCWGx3y40TrTI8fdzqNmVfBLXJTUPt8O2DXro3FOW8ZEcDRNZRiC SU5RZzE91nH/Vw+g30/vVt0zBQpwtVAr9H/jGk+6wSlnWfFCgy7W6DNBd BfXTCzkOmibjh1ayl7OpAJR7E8JKeOIVV5996XJ2jXd9F0SH72EnEPUIw 61cR7p7+9vCRJgrrIp7nzvbW4G3viI0eqScQrBUgjM0WGDnMoTQ+O0onF YzqTFlX8AMJK18yJ6BleeU/dJtij1FB9cMetka9n7ulm5VbGz+/6iuSJu k7kygu2rLe+h7w167iCedCk/9OJybh69+uKfnB6ujyNxGe78tVXa0DGG5 Q==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854759" Received: from mail-mw2nam12lp2045.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.45]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:24 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aII0Ze3G0XJWcAeD9kBWwhSmBDpAImyGTKsJewhjxZCIQuCmJRG8zwAPmMtdcWyJYGjsPueCYcCu/+Gqf+v8k/9wkxVbjQ4+HlIf8H6jh2B6mW9UDuYM4uDdkfVDfBNxuDnradxxPoBUFEZB1cZ1eVmB4bEJDNJAw4c8EHQLQVEKbZyy128f5TM93QDNZWEeRJpFK62x9RjyvqfY5Wjyr9JPGX5vShEXNAvED2jLSLT0VQ4XsQ7/WxI7qCtd5rz9I2J2CLl+k8JTaAKMXjlF+p3l9Ub2AC6jXckg29y5xf5TTGx8oGo9JL7VUbdUpmG2/RjaKvqwZweor96nqk3WkA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J7mpUD20rxUSkfLTal+eQ9Ny345KnghaauwRlhj2gsg=; b=DnJIPReuwYZ6LbKaKmC6PlRoDcHobUmzYSHP5KwK4ZKgc41kGLmiugSvDhpV5ScOUvPwTFmVh/DD+PPDpqun3gnhTEyV75YKXYHcuiNT86zdHVrnWUi6aa06+AwD2U+atN5PU22PT8J0F1r9Ql4QBKQciBlNhAvUgvPA5U6WK9GkQNSE+KyOTlX6rKN5tZCF6gY8T3O+wb9Orh7m6mM3ThPc0XsSvM/FgPLlxt8jj33LQLniMvqeaQC/icvXCSCnTSAiBfC+ofZ+0nIN4xox+R6PJQ6ZLFh15x+nTksuDHafseKlUB1W4u5z3uJvciKN59MrVxRZgiEEkzZ0vmKnrw== 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=J7mpUD20rxUSkfLTal+eQ9Ny345KnghaauwRlhj2gsg=; b=hEg1YkL5nTRHcywvucmJ6NgMrqp3yw0T2+WHq4R2+uLKozj0uhz/2K5AqQR4QrJnwwT4Mt05bbo9mShFX/Iq0SSOOxu4ImGs7+Zzbm/lIw1C+wCuj3ezPRhiZHLY+t6bN1MQc7ZzcS4/OfQ4c9fITMSDR21mu9FAPjMGpryX51A= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:23 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:23 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 09/22] target/riscv: Implement AIA local interrupt priorities Date: Tue, 26 Oct 2021 12:12:14 +0530 Message-Id: <20211026064227.2014502-10-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5574036c-39d4-4bb1-7c5c-08d9984be800 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:1227; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hiTVPPOR9clXv7dGIzoF7wxC52QTe/oWage0cQXIEVLN4fU3nVxkmPXFaZtSEDJCqlQFOFevPxR6q4t+AaZsfWkbKgxpDj1CDvTXcmSU9pK5OcAaQOz8SUPfX7AdzpyOeP7AaGvrHRolsMsa8ySSPymvj+7v4slNUp8n5KPx1njdJtiRnXtTmXrqckcmCzyCcN/JQt2mKgEkufREnRVI2CVVy9NT3e2xZnezUGWdl+34UNUGgpeF71ieWzEL4ikhGo20EP8Rc41r/0MPQAG1IADszvoGEPJevPsuZ04wGkSOjmtGq2uRpDqoouJzifrUtLQY3UhGcDc3/k+g9BtiJMly9coWzBxigvvbyqBxK3Bj67o4i4d2RLsaQD2gtEiqZ8FP/zJ5VOs2mU8fnIujZXkYXZEepfX6MafrSOVbxja8UDgy43p9+beNAWuSq5tsnsIewXZH1S+/OZxu/zHohwqmxp84p9S7bT5rcderVZY9oHAYFB+iSOHzrf87FFejwvEu4yjuia/k8/pMORasBbu4qCkhgF9tGgPWoe/+cfcA0iZw2Ah3bzhKacpCR/aXAujSIR6V+mDdEpXklks8q5qkd3d9bGM/bPWEYcl26ueW1hHzBWyKhmHZGVs8Ud2Q1KmPXcXZOuVZDS5WFnvbNZsxAwvEIRRmjj4bLfcoPgkWgCX93tVejtWplVzTf/2oihevii8YIlWuCdktSN78aA== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(30864003)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r+ymPlYu9sNBF1I7ba6WR5sM/DEnlLwKfXZbFU0g0HUkI5T2YC2TOYlCJhuivfhqYybiMN7ajfsa0i5VfHc3napxT7/YxMrpm8Jc35aOMNY7ZGcl0xuLLs0ZbWCAy+uqO6o3YxZP0ilO/ZfgCCULhmWqyvVVYXa6sY9RDLx6vrLcaEU15ENF53o1emSQaUk9YAscrrpt/xBrcClfWwNCt/0KROIKDo5NmIQ8M0LwukyioWtDdduv9Ar6tsrsIK0JllPDzl3/D/QVRz1mp/pLeypj22v5kXUVX8lSIxyXbR7fZrmMBtMb0unJsHjRgHuBBEUHmi3vv6SMC1oECe/L/l2VGeckrhyjZ4+waZznvS03hyqTJGVsbHS6Z4NF0kUrSaEMR8FNOC29WwY3vrDAjTmIdtaW7Jg24RvABmM6jvDoaon9Pt9W8+7DLqKcQybUQ84cPaqJ1CMNlts0RnVCcAnnEGa/AiOHLzybJeF1dJtlcR+8KpUtZUphQ+AAEDlNAN7VbT/L8VwtslQo5guNHUtElSFpgqU/bMxAy6UlKCFWbAhe8O3Ob9rib+qk9LV11cBJzkU5qiWwMLMEjY/fVA8hYZSuB789LY83X7mrlY6OBNRp2O/4UNUWy6HJZZFoPEA8USTv7LMgO/YpRfygC3B3T7fU9m4qPRFasqDQSAfz1j5yu7r40GYC2resjDYAXCo9Dryo57S4BA4yMcUKjlEdsSyaKXam7lzswdxck/Id6FYGONQW54dLLpaUqaOUvtXbLczqqVhYCZik7Wo1XpJ//OY1U9dG+e1yx5g+oitj39RBH3iYg9WVa2YagW3x89zPyOq7V+PMZ/TQT7JM+VrubR1CIIRruC4Aum58DQaVEHxEH7Vg0sQcikjxgVBAsAWl/N8+zWgEK899M+POCJWd6gC8a6bwXkovMmJKA+0CWejRaps56z7sx/l7Lnr4saVrvOjnj700t2DDgXSCAqI9pqs7CufOoVUVrSnrfy8nckl9mekisCEvRBmVEOUS4ri6n0Os1pNTcDb9gbuxrLDL/ehpRLR6SNoMy87yabVW/LD1PYQY5Kcyxuyd1iRfxyDrmRAWLbim2fYekj25cblznkKSNImByNMhhTOdTUiaYzBf6/foPaqYM33Zu7iufDc6pjRjhPqM7dbFis9OWmI9PIc1YfQ1PN8co/RiOUzpe8MbzQV0+84szdi3n5TVJxlNazr7U6QWN7j9lGGdjcV8F2q+lpITCXPpQvPng/0J2F7nOOYYm81mmNbxm/Ce/Lre04JiKcjLsIhss9l2/wBBkNKJqyTx53YnE4ocxGfhpZtG+X0A1tLjJEwql1uSnqQgzPg9U4bAEXB5nyinZBpaiGG9ZymvjvX5yXmrUkRyAdCMXiRlxg4rH58MIkEj2CAldo6Tqun/RXrqqZpO3JjIw4IYtMXxr5Suca/3kj86G+Ac1XtKUv1K6CAMpragC8G1rjCRZUzKL35KqPeI4BgAoRRPTHZIQALOtjr4Hlm6a4Cjx+gWVHAFeQ6+HJiwGHy2FKdB6sFFMNrKtAm3PFhcBwdxZSSdzDGdD1x55v2YlaEV8Fg/BsfkHSydSDGlgUFiHaG2H+rdFAdKQ++q060F85BUNfylqm4yQ4LPSqg= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5574036c-39d4-4bb1-7c5c-08d9984be800 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:23.5604 (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: xhsD6tPFS53n9YmUfdIF05yr2ZTxx6CVjgcCujW+gZOkiX9YThLQ4k9qm/4h2xJHTCo+HaOr/Uk8edRvK0cC7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA spec defines programmable 8-bit priority for each local interrupt at M-level, S-level and VS-level so we extend local interrupt processing to consider AIA interrupt priorities. The AIA CSRs which help software configure local interrupt priorities will be added by subsequent patches. Signed-off-by: Anup Patel --- target/riscv/cpu.c | 19 +++ target/riscv/cpu.h | 12 ++ target/riscv/cpu_helper.c | 241 +++++++++++++++++++++++++++++++++----- target/riscv/machine.c | 3 + 4 files changed, 245 insertions(+), 30 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 69d6b5eb36..0006989c39 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -341,6 +341,10 @@ void restore_state_to_opc(CPURISCVState *env, TranslationBlock *tb, static void riscv_cpu_reset(DeviceState *dev) { +#ifndef CONFIG_USER_ONLY + uint8_t iprio; + int i, irq, rdzero; +#endif CPUState *cs = CPU(dev); RISCVCPU *cpu = RISCV_CPU(cs); RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); @@ -363,6 +367,21 @@ static void riscv_cpu_reset(DeviceState *dev) env->miclaim = MIP_SGEIP; 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] = (i == IRQ_M_EXT) ? 0 : iprio; + env->siprio[i] = (i == IRQ_S_EXT) ? 0 : iprio; + env->hviprio[i] = 0; + } + i = 0; + while (!riscv_cpu_hviprio_index2irq(i, &irq, &rdzero)) { + if (!rdzero) { + env->hviprio[irq] = env->miprio[irq]; + } + i++; + } #endif cs->exception_index = RISCV_EXCP_NONE; env->load_res = -1; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ef4298dc69..c47e57efc8 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -179,6 +179,10 @@ struct CPURISCVState { target_ulong mcause; target_ulong mtval; /* since: priv-1.10.0 */ + /* Machine and Supervisor interrupt priorities */ + uint8_t miprio[64]; + uint8_t siprio[64]; + /* Hypervisor CSRs */ target_ulong hstatus; target_ulong hedeleg; @@ -191,6 +195,9 @@ struct CPURISCVState { target_ulong hgeip; uint64_t htimedelta; + /* Hypervisor controlled virtual interrupt priorities */ + uint8_t hviprio[64]; + /* Virtual CSRs */ /* * For RV32 this is 32-bit vsstatus and 32-bit vsstatush. @@ -357,6 +364,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_fp_enabled(CPURISCVState *env); target_ulong riscv_cpu_get_geilen(CPURISCVState *env); void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index d70def1da8..73ebce1efd 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -115,47 +115,228 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, } #ifndef CONFIG_USER_ONLY + +/* + * 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) +{ + if (index < 0 || ARRAY_SIZE(hviprio_index2irq) <= index) { + return -EINVAL; + } + + if (out_irq) { + *out_irq = hviprio_index2irq[index]; + } + + if (out_rdzero) { + *out_rdzero = hviprio_index2rdzero[index]; + } + + return 0; +} + +uint8_t riscv_cpu_default_priority(int irq) +{ + int u, l; + uint8_t iprio = IPRIO_MMAXIPRIO; + + if (irq < 0 || irq > 63) { + return iprio; + } + + /* + * 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 = RISCV_EXCP_NONE; + unsigned int prio, best_prio = UINT_MAX; + + if (!pending) { + return RISCV_EXCP_NONE; + } + + irq = ctz64(pending); + if (!riscv_feature(env, RISCV_FEATURE_AIA)) { + return irq; + } + + 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; +} + +static uint64_t riscv_cpu_all_pending(CPURISCVState *env) +{ + uint32_t gein = get_field(env->hstatus, HSTATUS_VGEIN); + uint64_t vsgein = (env->hgeip & (1ULL << gein)) ? MIP_VSEIP : 0; + + return (env->mip | vsgein) & env->mie; +} + +int riscv_cpu_mirq_pending(CPURISCVState *env) +{ + uint64_t irqs = riscv_cpu_all_pending(env) & ~env->mideleg & + ~(MIP_SGEIP | 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 = riscv_cpu_all_pending(env) & 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 = riscv_cpu_all_pending(env) & 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) { - target_ulong irqs; - - 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); - - target_ulong pending = env->mip & env->mie & - ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); - target_ulong vsgemask = - (target_ulong)1 << get_field(env->hstatus, HSTATUS_VGEIN); - target_ulong vsgein = (env->hgeip & vsgemask) ? MIP_VSEIP : 0; - target_ulong vspending = ((env->mip | vsgein) & env->mie & - (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP)); - - 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); + int virq; + uint64_t irqs, pending, mie, sie, vsie; + /* Determine interrupt enable state of all privilege modes */ if (riscv_cpu_virt_enabled(env)) { - target_ulong pending_hs_irq = pending & -hs_sie; + mie = 1; + sie = 1; + vsie = (env->priv < PRV_S) || + (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_SIE)); + } else { + 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; + } - if (pending_hs_irq) { - riscv_cpu_set_force_hs_excep(env, FORCE_HS_EXCEP); - return ctz64(pending_hs_irq); - } + /* Determine all pending interrupts */ + pending = riscv_cpu_all_pending(env); - pending = vspending; + /* Check M-mode interrupts */ + irqs = pending & ~env->mideleg & -mie & + ~(MIP_SGEIP | MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + if (irqs) { + return riscv_cpu_pending_to_irq(env, irqs, env->miprio); } - irqs = (pending & ~env->mideleg & -mie) | (pending & env->mideleg & -sie); + /* Check HS-mode interrupts */ + irqs = pending & env->mideleg & -sie & + ~(MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); + if (irqs) { + return riscv_cpu_pending_to_irq(env, irqs, env->siprio); + } + /* Check VS-mode interrupts */ + irqs = pending & env->hideleg & -vsie & + (MIP_VSSIP | MIP_VSTIP | MIP_VSEIP); if (irqs) { - return ctz64(irqs); /* since non-zero */ - } else { - return RISCV_EXCP_NONE; /* indicates no pending interrupt */ + virq = riscv_cpu_pending_to_irq(env, irqs >> 1, env->hviprio); + return (virq <= 0) ? virq : virq + 1; } + + /* Indicate no pending interrupt */ + return RISCV_EXCP_NONE; } bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request) diff --git a/target/riscv/machine.c b/target/riscv/machine.c index fe99ec7304..a7102220b6 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -116,6 +116,7 @@ static const VMStateDescription vmstate_hyper = { VMSTATE_UINTTL(env.hgeie, RISCVCPU), VMSTATE_UINTTL(env.hgeip, RISCVCPU), VMSTATE_UINT64(env.htimedelta, RISCVCPU), + VMSTATE_UINT8_ARRAY(env.hviprio, RISCVCPU, 64), VMSTATE_UINT64(env.vsstatus, RISCVCPU), VMSTATE_UINTTL(env.vstvec, RISCVCPU), @@ -147,6 +148,8 @@ const VMStateDescription vmstate_riscv_cpu = { .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), From patchwork Tue Oct 26 06:42:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12583931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CB0CC433EF for ; Tue, 26 Oct 2021 07:11:36 +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 DACF461040 for ; Tue, 26 Oct 2021 07:11:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DACF461040 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:60282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfGcQ-0001yi-TB for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:11:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBM-0003OQ-U1; Tue, 26 Oct 2021 02:43:36 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53150) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBH-0000sH-A3; Tue, 26 Oct 2021 02:43:36 -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=1635230610; x=1666766610; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=rKP8ERSSBeopz63Qg33Ie7Q4IWAK6FD4XKl/43KmKp4=; b=Jz900EDU7nWoJIf6bXmispU9ETKeFi1HieeNMDCmPEn6ink3lefs+T2b bW8UHakLinVl0DE89i6m/X1WsfGolxjcGJcx3eG6IrMe4DF7dJZJpOg4a Gy28u/s/wFVaDMpcaGQqPbt9XaWZWuGjGXV+nV+cQsss7ovckVlQDgHn/ Df4TRnfPZL2tLZ2f2uQ7VuR/SPCSiI750PjVu0d39x+OczfKqdW9TbmWu AVpqbqUbJbcFa+lFcEsRoSo3wN9u3j2RFccAZyOA2ES4ic+7ypA1ZJn7Y xEQfZbkaSK8yXSNkHayyIvdCPutoNrsMGOh3HDc/iPyy36OUzw+PyBxHy Q==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854762" Received: from mail-mw2nam12lp2047.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.47]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:27 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I9IjvFARYTQ0m8ZHHVLmMwPZ+C3TzUdS6QJP1z5tdQJnje6zMMwUYEsfgtrNAI6rW8aDzBRdhmTPu8tj6ynWkmPAPMp/kPTPJZJR8kQMfWlUfRWGrS/fFJx70H/a3yB7mrFsynGZMOivV5E5BTbuzuYC62lO8xdb/ZXmXRHwcE9vOG1nbPJ9peun70yGdpQkBHN0xD3Oze9dK265iW4yiMNV6G2l1Sthr7g75LI96hDEMlTMknX0U8VVtQUpyJVPQCZDthhGM1s2MYrxYgB1EzKWNstgtGlsOMTE1PypvdcM79QkDbkbdQ9mrOFajbRgeNgWQmnGln0QpsDG3HnRXg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=34+3LCWzxEVgk0mpKaOex72lodu5H+aIGa7Bx1Am4EE=; b=frjIdtauY2d6WyZ7HWumCGBqVZicrdEov7QU/wbWnuMwbaUn3axxTulBj98DRuOpMo8Tkd624CEJyP9qxy3kxzQHLQGiL/bWXEe3w7pbDd4IHh/IMK1yMi10f++YEPI49pPkKYlbi72Al+eEgv+mNza1bYzAPDAvfn/0EXYFZYiDoWs3Y1TXp6jt818hOZMDjkE93sPznXRWlkbr9CJhn4Suzj/tOsnAUcuF8k2ZcWE6GwW6wQZaABUPzm7GP8gDfDDTlq4gVDf+9wxqQxIAjLhgctO27A8v/eQ4AUVfDVqkY/x6wo24SnpL0ZTWAXTS4Uxl/OXiv0zDHxHTx4AB9A== 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=34+3LCWzxEVgk0mpKaOex72lodu5H+aIGa7Bx1Am4EE=; b=L41hJhQ1mmZxMxZBeFcsMt/QOxloMC9vrAQpknsWmyn7lYVztY2ZWm5I4xSdlBqm9SMTps6qacS7hIuBaUpdFcDlCZHzFTltw5nr+1EnvYs5LfZbnzZFBlv510Drn9PsizXdo+l4v9+VuukmIA2IKiS9VPMGzV27dTMHMrGDmTo= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:27 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:27 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 10/22] target/riscv: Implement AIA CSRs for 64 local interrupts on RV32 Date: Tue, 26 Oct 2021 12:12:15 +0530 Message-Id: <20211026064227.2014502-11-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6a04e620-0e6f-4e58-9836-08d9984be9fb X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r4fWT8cAyc4Uw2U0ZdsVNE1O56MisyevQHbmNhpsZmhzAyOC5VmQpjSXC2AHh9K4DjfjuK8PMlKHKLfqKdGuSk7dJLv7lI5YNkoL3n+kHwEn/UwdQC8Aq56q+sTHGycY02otb+Oo1YkSFNiKrm0czt4xUPj70wAY7wRQImaPhbK4JpUuMoU3LZ6ktzfDZw90O9RM5ITsNu0d2Wthdav5vCBdbhs2w6ZNAovQwnvmd15IqKJBKl0NZT67/172jLX/q/WWVaowIcM6iYZqVgVtsxYe+7JKVE4X0wt2p+A6X8HeDVR75cF+F7BXNK6sBAD/hjsN28My/7dQW5k1yBLND0fuqo2p0zKq7D6N+b4115meBXmYh8PGEJ7bp51w74fe5d82ssrjaHPeFrbK1TNmmLIbR7HjAYsWh89cwM32Jj1ssObAdmTmxPsM5NWP5a0GpmBhttNXsxrc0xJxu+HjOCeAvbFmHBE/H7C+IYq5tna3UWtYW3w40uKftpI+2dcMrKM2eCK61g36ZRdjfYetlm0J3b5ofNNRAvKEhfKbrfTQmKH/69a8GDRVWAT9q+ufcyeU3TL8bfHW7mWCj5lAdOQFNazb2u/7RCgb1WePFmSHlL1yHxWJgyiP3y0YwZlOnlGFTqAyIPI8R52U3Bl6bZRDPovFy1kP8oHnhpC4Sh0nG5Hn0XJw2HJvyjW0Pnqg8FZcXJWMCGNaEigkNAiUIQ== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(30864003)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MwV/MB/bGQfb9WI+lGEvBOW5SrlbUJW5yP+pIQzyK+hJ+QvoNNmTTfTo+DLH9YzEDohLsVALn2LwnKgRXcwhXO3YdIUT53r2qYUfwyqEO8uWxxehOof4vwQnAhJU03pDZKBBAvu7qW2OkhT4KcuoP1aBRr5hAackgWUAgNiGQcB4LFGIXWlLT8EhBYX9tpXfMSZ4O1oM6emCeYdqU4M5Bj4vY2Zcz7TnK7H81Q0RRDaEKuA1XMT3xGouyP/4IKNLRNajA0rAUFjPKVZOziZ+ZWsN9M9ORBA5mdxvWNko5L8hJOdM3vKfJngLep26dhbaMQ7Kj8mTJiOuizKVFMVhdT50fwSaMlVOUrdZP7D8TiW7cdY7Z/9I4YFN+CjIdd619A2P91n2VRK7xbFuk4EKXOxJX7fcHAEzaPlm/dLgtA/4OIq7ylMnKRNUJz8dbOWDCCbTVv5J8evgls3tV6wFVSf1sYDDnUWysq0DYHlzDFFB7bpyhM2KqYgjwNnfTbZ+pUhHshUJG3qOwAOnvKbreaspxPP8d/aeH2uvAnNmRfW41R5ER7Cf+UCzGOXAbdQsyATY6RrMc2lM+kC6RvpF9DLTy+l97Fja+CPhTZ6GvGFQe2k3hDn6coWvg9T2DT7ITid6mKZMpzfSOTvpue6kM5/XBKNgsw4h20r7WiLNlUDvtBwGvEnUfQVgDf0vmdKkbekJIRAZtE9YGIRu39YCwDQd+HI68IxrdoYD45j13VrXmakd1D6Fz0+TwMa+MaCPfAJ6q1mY3t9BSw0yap5lHheC9BAiW3dy1f4MNRlyKsrvm6a8j5ESE7vrTkaBV35a6mGHAZc3L1zECA00cT7U6cTixAuv4tnV78RS4sZ6Ii5as1Nn3ytXV+ILQKEJfVPC2ZfKNk3QzA6DW2N/vOei7zhXdsT/qZI008XPC7GFcx54nBT+GDsjOfHtpILRSLPltk8lZDIdq4w7yosNEVAJgPU2Lic5vyFuAYXXuoDAq/YfrTxnOM6qYUHqPwRnm7040j44OgpQJ9G6zr0ygLQrmXMZ3MRTYJmq7Ezx58Dv2T1lfK5CG6bgFJ09vbb6kTw779cJdOViQfjMS7citJs5+wi1AnTolu15WeEB0s7piIFK72cvAp03UKgfhaZsGDW+sLV1ZZPUTHSjgakI54DOZq0j5QS7XwhJARBQO/FmDnkhNhSkO2f2ccggEH7ppI9QnUdX/r5fQeiMvtpv8juP0UMVndjmyfGI8DXWHBK9d4N2xjwMXDa/6NTBXpsBKeHFDTIQey+OnfI8OIMWpP2JVRBmtNw4ZJQqfutn1fj7R5NxqMf7icBEsz4G0dFbibvrxU+wNwVD61dO70TKHN+2QXdL1OALHeqZr8ORaIIGV98YufRHtWJECOeBqE5V3xWmD83DURHFQ9nWRTPanb+pF3T1p2WVfegoG4zZU5aGEQT6lhf1d448g7xK7FEi4bwjxD2QJXFHmD4BAVmzEcFcpIBlTfgrl+eE4Aqa8LOWxlvY0jc7LaMNlvox3hsxSPN7+osZJu2qp4T2vPZXErIC54VsP+kUzI2Ebe64rs49vFQBLt/ciB74i101ZpdI8IOH5FjaU5Q6pfVZkhiD9rbHyw+J0mbuNh9M+vAcfL5p02M= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a04e620-0e6f-4e58-9836-08d9984be9fb X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:26.9495 (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: 7RVyXpqdGaJWuFbg4S47cIjp3HaoBCyfE0KpS4CdXcXI+Z554C9F9d/0jQ4GZq7STZvklUxpWoPRsIHsaTEcSA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification adds new CSRs for RV32 so that RISC-V hart can support 64 local interrupts on both RV32 and RV64. Signed-off-by: Anup Patel --- target/riscv/cpu.h | 14 +- target/riscv/cpu_helper.c | 10 +- target/riscv/csr.c | 560 +++++++++++++++++++++++++++++++------- target/riscv/machine.c | 10 +- 4 files changed, 474 insertions(+), 120 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index c47e57efc8..718a95e864 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -159,12 +159,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 satp; /* since: priv-1.10.0 */ target_ulong stval; @@ -186,7 +186,7 @@ struct CPURISCVState { /* Hypervisor CSRs */ target_ulong hstatus; target_ulong hedeleg; - target_ulong hideleg; + uint64_t hideleg; target_ulong hcounteren; target_ulong htval; target_ulong htinst; @@ -399,8 +399,8 @@ void riscv_cpu_list(void); #ifndef CONFIG_USER_ONLY bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request); 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_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(uint32_t), uint32_t arg); diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 73ebce1efd..416b11f85c 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -506,7 +506,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) { @@ -517,11 +517,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 gein, vsgein = 0, old = env->mip; + uint64_t gein, vsgein = 0, old = env->mip; bool locked = false; if (riscv_cpu_virt_enabled(env)) { @@ -1244,7 +1244,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; @@ -1311,7 +1311,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) cause < TARGET_LONG_BITS && ((deleg >> cause) & 1)) { /* handle the trap in S-mode */ if (riscv_has_ext(env, RVH)) { - target_ulong hdeleg = async ? env->hideleg : env->hedeleg; + uint64_t hdeleg = async ? env->hideleg : env->hedeleg; if (env->two_stage_lookup && write_tval) { /* diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 7ff285282b..3a7d89ac34 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -153,6 +153,15 @@ static RISCVException any32(CPURISCVState *env, int 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 RISCVException smode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS)) { @@ -162,6 +171,24 @@ static RISCVException smode(CPURISCVState *env, int csrno) return RISCV_EXCP_ILLEGAL_INST; } +static int smode32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) != MXL_RV32) { + 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 RISCVException hmode(CPURISCVState *env, int csrno) { if (riscv_has_ext(env, RVS) && @@ -192,6 +219,15 @@ static RISCVException hmode32(CPURISCVState *env, int 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 RISCVException pmp(CPURISCVState *env, int csrno) { if (riscv_feature(env, RISCV_FEATURE_PMP)) { @@ -405,15 +441,15 @@ static RISCVException read_timeh(CPURISCVState *env, int csrno, /* 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 HS_MODE_INTERRUPTS (MIP_SGEIP | VS_MODE_INTERRUPTS) +#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 HS_MODE_INTERRUPTS ((uint64_t)(MIP_SGEIP | VS_MODE_INTERRUPTS)) -static const target_ulong delegable_ints = S_MODE_INTERRUPTS | +static const uint64_t delegable_ints = S_MODE_INTERRUPTS | VS_MODE_INTERRUPTS; -static const target_ulong vs_delegable_ints = VS_MODE_INTERRUPTS; -static const target_ulong all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | +static const uint64_t vs_delegable_ints = VS_MODE_INTERRUPTS; +static const uint64_t all_ints = M_MODE_INTERRUPTS | S_MODE_INTERRUPTS | HS_MODE_INTERRUPTS; #define DELEGABLE_EXCPS ((1ULL << (RISCV_EXCP_INST_ADDR_MIS)) | \ (1ULL << (RISCV_EXCP_INST_ACCESS_FAULT)) | \ @@ -662,40 +698,107 @@ static RISCVException write_medeleg(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } -static RISCVException read_mideleg(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_mideleg64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { - *val = env->mideleg; - return RISCV_EXCP_NONE; -} + uint64_t mask = wr_mask & delegable_ints; + + if (ret_val) { + *ret_val = env->mideleg; + } + + env->mideleg = (env->mideleg & ~mask) | (new_val & mask); -static RISCVException write_mideleg(CPURISCVState *env, int csrno, - target_ulong val) -{ - env->mideleg = (env->mideleg & ~delegable_ints) | (val & delegable_ints); if (riscv_has_ext(env, RVH)) { env->mideleg |= HS_MODE_INTERRUPTS; } + return RISCV_EXCP_NONE; } -static RISCVException read_mie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_mideleg(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - *val = env->mie; - return RISCV_EXCP_NONE; + uint64_t rval; + RISCVException ret; + + ret = rmw_mideleg64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; + } + + return ret; } -static RISCVException write_mie(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException rmw_midelegh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, + target_ulong wr_mask) { - env->mie = (env->mie & ~all_ints) | (val & all_ints); + uint64_t rval; + RISCVException ret; + + ret = rmw_mideleg64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + + return ret; +} + +static RISCVException rmw_mie64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + uint64_t mask = wr_mask & all_ints; + + if (ret_val) { + *ret_val = env->mie; + } + + env->mie = (env->mie & ~mask) | (new_val & mask); + if (!riscv_has_ext(env, RVH)) { - env->mie &= ~MIP_SGEIP; + env->mie &= ~((uint64_t)MIP_SGEIP); } + return RISCV_EXCP_NONE; } +static RISCVException rmw_mie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_mie64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; + } + + return ret; +} + +static RISCVException rmw_mieh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_mie64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + + return ret; +} + static RISCVException read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) { @@ -786,17 +889,17 @@ static RISCVException write_mtval(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } -static RISCVException rmw_mip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +static RISCVException rmw_mip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { 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 gin, old_mip; + uint64_t old_mip, mask = wr_mask & delegable_ints & ~env->miclaim; + uint32_t gin; if (mask) { - old_mip = riscv_cpu_update_mip(cpu, mask, (new_value & mask)); + old_mip = riscv_cpu_update_mip(cpu, mask, (new_val & mask)); } else { old_mip = env->mip; } @@ -806,13 +909,44 @@ static RISCVException rmw_mip(CPURISCVState *env, int csrno, old_mip |= (env->hgeip & ((target_ulong)1 << gin)) ? MIP_VSEIP : 0; } - if (ret_value) { - *ret_value = old_mip; + if (ret_val) { + *ret_val = old_mip; } return RISCV_EXCP_NONE; } +static RISCVException rmw_mip(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_mip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; + } + + return ret; +} + +static RISCVException rmw_miph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_mip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + + return ret; +} + /* Supervisor Trap Setup */ static RISCVException read_sstatus(CPURISCVState *env, int csrno, target_ulong *val) @@ -832,45 +966,112 @@ static RISCVException write_sstatus(CPURISCVState *env, int csrno, return write_mstatus(env, CSR_MSTATUS, newval); } -static RISCVException read_vsie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_vsie64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { - /* Shift the VS bits to their S bit location in vsie */ - *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; - return RISCV_EXCP_NONE; + RISCVException ret; + uint64_t rval, vsbits, mask = env->hideleg & VS_MODE_INTERRUPTS; + + /* Bring VS-level bits to correct position */ + vsbits = new_val & (VS_MODE_INTERRUPTS >> 1); + new_val &= ~(VS_MODE_INTERRUPTS >> 1); + new_val |= vsbits << 1; + vsbits = wr_mask & (VS_MODE_INTERRUPTS >> 1); + wr_mask &= ~(VS_MODE_INTERRUPTS >> 1); + wr_mask |= vsbits << 1; + + ret = rmw_mie64(env, csrno, &rval, new_val, wr_mask & mask); + if (ret_val) { + rval &= mask; + vsbits = rval & VS_MODE_INTERRUPTS; + rval &= ~VS_MODE_INTERRUPTS; + *ret_val = rval | (vsbits >> 1); + } + + return ret; } -static RISCVException read_sie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_vsie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - if (riscv_cpu_virt_enabled(env)) { - read_vsie(env, CSR_VSIE, val); - } else { - *val = env->mie & env->mideleg; + uint64_t rval; + RISCVException ret; + + ret = rmw_vsie64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; } - return RISCV_EXCP_NONE; + + return ret; } -static RISCVException write_vsie(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException rmw_vsieh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - /* 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); + uint64_t rval; + RISCVException ret; + + ret = rmw_vsie64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + + return ret; } -static int write_sie(CPURISCVState *env, int csrno, target_ulong val) +static RISCVException rmw_sie64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { + RISCVException ret; + uint64_t mask = env->mideleg & S_MODE_INTERRUPTS; + if (riscv_cpu_virt_enabled(env)) { - write_vsie(env, CSR_VSIE, val); + ret = rmw_vsie64(env, CSR_VSIE, ret_val, new_val, wr_mask); } else { - target_ulong newval = (env->mie & ~S_MODE_INTERRUPTS) | - (val & S_MODE_INTERRUPTS); - write_mie(env, CSR_MIE, newval); + ret = rmw_mie64(env, csrno, ret_val, new_val, wr_mask & mask); } - return RISCV_EXCP_NONE; + if (ret_val) { + *ret_val &= mask; + } + + return ret; +} + +static RISCVException rmw_sie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_sie64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; + } + + return ret; +} + +static RISCVException rmw_sieh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_sie64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + + return ret; } static RISCVException read_stvec(CPURISCVState *env, int csrno, @@ -963,38 +1164,111 @@ static RISCVException write_stval(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +static RISCVException rmw_vsip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + RISCVException ret; + uint64_t rval, vsbits, mask = env->hideleg & vsip_writable_mask; + + /* Bring VS-level bits to correct position */ + vsbits = new_val & (VS_MODE_INTERRUPTS >> 1); + new_val &= ~(VS_MODE_INTERRUPTS >> 1); + new_val |= vsbits << 1; + vsbits = wr_mask & (VS_MODE_INTERRUPTS >> 1); + wr_mask &= ~(VS_MODE_INTERRUPTS >> 1); + wr_mask |= vsbits << 1; + + ret = rmw_mip64(env, csrno, &rval, new_val, wr_mask & mask); + if (ret_val) { + rval &= mask; + vsbits = rval & VS_MODE_INTERRUPTS; + rval &= ~VS_MODE_INTERRUPTS; + *ret_val = rval | (vsbits >> 1); + } + + return ret; +} + static RISCVException rmw_vsip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - /* Shift the S bits to their VS bit location in mip */ - int ret = rmw_mip(env, csrno, ret_value, new_value << 1, - (write_mask << 1) & vsip_writable_mask & env->hideleg); + uint64_t rval; + RISCVException ret; - if (ret_value) { - *ret_value &= VS_MODE_INTERRUPTS; - /* Shift the VS bits to their S bit location in vsip */ - *ret_value >>= 1; + ret = rmw_vsip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; } + return ret; } -static RISCVException rmw_sip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) +static RISCVException rmw_vsiph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - int ret; + uint64_t rval; + RISCVException ret; + + ret = rmw_vsip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + + return ret; +} + +static RISCVException rmw_sip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + RISCVException ret; + uint64_t mask = env->mideleg & sip_writable_mask; if (riscv_cpu_virt_enabled(env)) { - ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask); + ret = rmw_vsip64(env, CSR_VSIE, ret_val, new_val, wr_mask); } else { - ret = rmw_mip(env, csrno, ret_value, new_value, - write_mask & env->mideleg & sip_writable_mask); + ret = rmw_mip64(env, csrno, ret_val, new_val, wr_mask & mask); } - if (ret_value) { - *ret_value &= env->mideleg & S_MODE_INTERRUPTS; + if (ret_val) { + *ret_val &= env->mideleg & S_MODE_INTERRUPTS; + } + + return ret; +} + +static RISCVException rmw_sip(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_sip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; } + + return ret; +} + +static RISCVException rmw_siph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_sip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + return ret; } @@ -1089,30 +1363,94 @@ static RISCVException write_hedeleg(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } -static RISCVException read_hideleg(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_hideleg64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) { - *val = env->hideleg; + uint64_t mask = wr_mask & vs_delegable_ints; + + if (ret_val) { + *ret_val = env->hideleg & vs_delegable_ints; + } + + env->hideleg = (env->hideleg & ~mask) | (new_val & mask); return RISCV_EXCP_NONE; } -static RISCVException write_hideleg(CPURISCVState *env, int csrno, - target_ulong val) +static RISCVException rmw_hideleg(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - env->hideleg = val & vs_delegable_ints; - return RISCV_EXCP_NONE; + uint64_t rval; + RISCVException ret; + + ret = rmw_hideleg64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; + } + + return ret; +} + +static RISCVException rmw_hidelegh(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_hideleg64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; + } + + return ret; +} + +static RISCVException rmw_hvip64(CPURISCVState *env, int csrno, + uint64_t *ret_val, + uint64_t new_val, uint64_t wr_mask) +{ + RISCVException ret; + + ret = rmw_mip64(env, csrno, ret_val, new_val, + wr_mask & hvip_writable_mask); + if (ret_val) { + *ret_val &= VS_MODE_INTERRUPTS; + } + + return ret; } static RISCVException rmw_hvip(CPURISCVState *env, int csrno, - target_ulong *ret_value, - target_ulong new_value, target_ulong write_mask) + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - int ret = rmw_mip(env, csrno, ret_value, new_value, - write_mask & hvip_writable_mask); + uint64_t rval; + RISCVException ret; - if (ret_value) { - *ret_value &= VS_MODE_INTERRUPTS; + ret = rmw_hvip64(env, csrno, &rval, new_val, wr_mask); + if (ret_val) { + *ret_val = rval; + } + + return ret; +} + +static RISCVException rmw_hviph(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) +{ + uint64_t rval; + RISCVException ret; + + ret = rmw_hvip64(env, csrno, &rval, + ((uint64_t)new_val) << 32, ((uint64_t)wr_mask) << 32); + if (ret_val) { + *ret_val = rval >> 32; } + return ret; } @@ -1129,18 +1467,19 @@ static RISCVException rmw_hip(CPURISCVState *env, int csrno, return ret; } -static RISCVException read_hie(CPURISCVState *env, int csrno, - target_ulong *val) +static RISCVException rmw_hie(CPURISCVState *env, int csrno, + target_ulong *ret_val, + target_ulong new_val, target_ulong wr_mask) { - *val = env->mie & HS_MODE_INTERRUPTS; - return RISCV_EXCP_NONE; -} + uint64_t rval; + RISCVException ret; -static RISCVException write_hie(CPURISCVState *env, int csrno, - target_ulong val) -{ - target_ulong newval = (env->mie & ~HS_MODE_INTERRUPTS) | (val & HS_MODE_INTERRUPTS); - return write_mie(env, CSR_MIE, newval); + ret = rmw_mie64(env, csrno, &rval, new_val, wr_mask & HS_MODE_INTERRUPTS); + if (ret_val) { + *ret_val = rval & HS_MODE_INTERRUPTS; + } + + return ret; } static RISCVException read_hcounteren(CPURISCVState *env, int csrno, @@ -1598,9 +1937,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus }, [CSR_MISA] = { "misa", any, read_misa, write_misa }, - [CSR_MIDELEG] = { "mideleg", any, read_mideleg, write_mideleg }, + [CSR_MIDELEG] = { "mideleg", any, NULL, NULL, rmw_mideleg }, [CSR_MEDELEG] = { "medeleg", any, read_medeleg, write_medeleg }, - [CSR_MIE] = { "mie", any, read_mie, write_mie }, + [CSR_MIE] = { "mie", any, NULL, NULL, rmw_mie }, [CSR_MTVEC] = { "mtvec", any, read_mtvec, write_mtvec }, [CSR_MCOUNTEREN] = { "mcounteren", any, read_mcounteren, write_mcounteren }, @@ -1613,9 +1952,14 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, + /* Machine-Level High-Half CSRs (AIA) */ + [CSR_MIDELEGH] = { "midelegh", aia_any32, NULL, NULL, rmw_midelegh }, + [CSR_MIEH] = { "mieh", aia_any32, NULL, NULL, rmw_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 }, + [CSR_SIE] = { "sie", smode, NULL, NULL, rmw_sie }, [CSR_STVEC] = { "stvec", smode, read_stvec, write_stvec }, [CSR_SCOUNTEREN] = { "scounteren", smode, read_scounteren, write_scounteren }, @@ -1629,12 +1973,16 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Supervisor Protection and Translation */ [CSR_SATP] = { "satp", smode, read_satp, write_satp }, + /* Supervisor-Level High-Half CSRs (AIA) */ + [CSR_SIEH] = { "sieh", aia_smode32, NULL, NULL, rmw_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 }, + [CSR_HIDELEG] = { "hideleg", hmode, NULL, NULL, rmw_hideleg }, [CSR_HVIP] = { "hvip", hmode, NULL, NULL, rmw_hvip }, [CSR_HIP] = { "hip", hmode, NULL, NULL, rmw_hip }, - [CSR_HIE] = { "hie", hmode, read_hie, write_hie }, + [CSR_HIE] = { "hie", hmode, NULL, NULL, rmw_hie }, [CSR_HCOUNTEREN] = { "hcounteren", hmode, read_hcounteren, write_hcounteren }, [CSR_HGEIE] = { "hgeie", hmode, read_hgeie, write_hgeie }, [CSR_HTVAL] = { "htval", hmode, read_htval, write_htval }, @@ -1646,7 +1994,7 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_VSSTATUS] = { "vsstatus", hmode, read_vsstatus, write_vsstatus }, [CSR_VSIP] = { "vsip", hmode, NULL, NULL, rmw_vsip }, - [CSR_VSIE] = { "vsie", hmode, read_vsie, write_vsie }, + [CSR_VSIE] = { "vsie", hmode, NULL, NULL, rmw_vsie }, [CSR_VSTVEC] = { "vstvec", hmode, read_vstvec, write_vstvec }, [CSR_VSSCRATCH] = { "vsscratch", hmode, read_vsscratch, write_vsscratch }, [CSR_VSEPC] = { "vsepc", hmode, read_vsepc, write_vsepc }, @@ -1657,6 +2005,12 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL2] = { "mtval2", hmode, read_mtval2, write_mtval2 }, [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst }, + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ + [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh }, + [CSR_HVIPH] = { "hviph", aia_hmode32, NULL, NULL, rmw_hviph }, + [CSR_VSIEH] = { "vsieh", aia_hmode32, NULL, NULL, rmw_vsieh }, + [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, + /* Physical Memory Protection */ [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg }, [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index a7102220b6..7356d70be6 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -108,7 +108,7 @@ static const VMStateDescription vmstate_hyper = { .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), @@ -168,10 +168,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.satp, RISCVCPU), VMSTATE_UINTTL(env.stval, RISCVCPU), VMSTATE_UINTTL(env.medeleg, RISCVCPU), From patchwork Tue Oct 26 06:42:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0EA0C433EF for ; Tue, 26 Oct 2021 07:42:56 +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 E2DDF60D07 for ; Tue, 26 Oct 2021 07:42:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E2DDF60D07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:48528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfH6k-0007Zn-JU for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:42:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53142) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBM-0003OR-UU; Tue, 26 Oct 2021 02:43:36 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBK-0001ly-KN; Tue, 26 Oct 2021 02:43:36 -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=1635230614; x=1666766614; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=CtHtkLXiLMCVmNIUwSdHSamCeIOuJ4YxOeC1MZGTmd0=; b=IbEoIojng2mpayaEzNUaEAZFV4WR7riBqFwWGGKj9PF8Lx+irb6saVKs NTCB+W+BIBBkQU3mAZ1Yj2gorAnIOV3VYbSHoKqvJkcNy5LoJ0vRqlV7g Blcr5qcEOKlvlPsSvYLCQBkX9RMwSc2+ZG97HkNO8+sfJxo0OKe3amgVG tHW6gGLVo8Ubju7M2/hjkMhdYSqhsQJOLpjOi4cg3FccFAoH9cxXVAkJS 1mWSmlgZRJ9odWlVbiy4T/bnSRSeV5JOf8qC19B8BKz8zdI+6Q6MHpvSY DbAfSVdbuNqV/p6UPj7aJNp+D4Yl5zogz+AlBucIFBZlxu0VT6ocK84ku g==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854765" Received: from mail-mw2nam12lp2040.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.40]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:30 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DgzvLSHUWH3gqYxE2nsqba3LXO1Nu5DqD4JXx47kAJupRR09vs5XVKlDyPuBi5QTBrxkTRhvIv65RZR11JbcFm9qUtNrpgkv0tf7/7KEqCT19TOEk9SH/yivSkFZ1ocx/zxWL1NzRGRgMJuYL5XiJ4P66/UrThHuTAskck3GGu9G1sDpvYzksCTSRs+T5KkroOZaw2H+z66PI14hXMxREibrS8Y6tqJVv0ewHU38Zvkx2YCB9CDF5oIUUkfceBbyCjObWtAz0f9g0YoWuUtMNRxl2rLmMa40n1TYDDgV7vj+f+ppw9R8FOQQq4//oT/8drbr7m7TDeZJzSGIjoRE7g== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1/Hi4UdfODeNucs5WPgXOslYNww+VY+KApy6XktK8FM=; b=BY4V21NhjKsFpcxhJolRgluRmalfpNloeRV17hBf32kbPhxR4hQoqlaQWOsA/xjWSp/m+BbK+dfAG3HQhkXM3i337Yp2pd77SOjpVM6ZRVzhF5LFa9vVTnsBcrs7Jk11ZwpH8uJvgAHCQnEx9p9ayOtPHwjq8C3vgiedqULtGX7BXjqlksZWSCR/NmJb0utG4MTfq6DBSYxyZF5E5LhY6EVRNDlSQPNDyOGD6JloP4K/Wl91PdmenLY0PCh60RgrTVPrjngkoOWetwpPzBMclGdnrR+qEXT0nb3YWUi0UB/pged3Ikd750/dXVnnPgvSh8kejqU8Q8vp1ViyQtE5bA== 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=1/Hi4UdfODeNucs5WPgXOslYNww+VY+KApy6XktK8FM=; b=VU31y7cMZ5ETZZBbkMch6IvO1taMSaP0Lw5YhwDYzF9aSPuHAD0ydq7S02k2TxrGqf6Oh/6J8sEwYhwKL6PfmDoKNbLle0t1mGz9rP/k02fPlSQhS14AfeasoM0cVbEoDR9c3gLA+kksgsBG8j0a02aehYCT8WgbohWq93zN+iY= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:30 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:30 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 11/22] target/riscv: Implement AIA hvictl and hviprioX CSRs Date: Tue, 26 Oct 2021 12:12:16 +0530 Message-Id: <20211026064227.2014502-12-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f89a7037-f293-4074-fed9-08d9984bebfd X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xtHsVM58LLw9lP/4JTwdVNwUka548KgfBIdIyy+Nwr30femFiBK2Qi5L+LJsChzACin2BqKktm/lFl1YawhG0JuzLIVV+4BHYFN4TiE2h1fH0+MT2HQIUsSez7Gn6WeD3+Y7pItdvWb6fBp/aHkBxnC3AD1zNyIyiBaSIbsdplFE5xyYJVth49Gt40nnNtUcIlsSfNGAoejAeGLBQ2GVrwaFjEmrJ+W7JoJNR60DBrE8e1C89zzCMurBg/rVYOFzFNvoAgP0dw9JN7jIrTPWXIivlzv2l9N/NGA+UwBK4MUTYGQJmmFdovIa3swQ5LAX9FWBYrH6FdIi3M2g2kpOr/6UHt1L41/u81iC99qzO5baym1cG1Ibz2aFlCl5sMjvM46Cy8IjgKpQrP+JvT3dyO68wlTTfTr/1+ZKxc8f1r3qpKM9IL0+U6LIxwH1dClFhBkJwH0R+t5iyCLIsztWjg9/w5wk/oAZzv0CkFOr2E++ltBEz15rzxYzWYLhWtfqv4OyrsHa/q4aTo1xgoJjTnzqIqincB4y7ILkjaoHj5Cxeki7/Kgx04QwnBA/IzUBf+2D72AJArQqzbBAZ5BNhwELr25Gb30u+gsvpb4hPo9P3ZaO6a7qLV+LXkkYsIUWdWKa1hcoxYtZPi0Pum58zQt4/Uj3FQJDIXq1vf4JMBPNjojv38FG349SeRDNA8cJ 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: du6hDde0Iw8vyj7xzSPQ+ilEuUPkAXQcsiGVrhkO3L+EiQjVza9B4TV9ijoiDjXi1clOGLcahtW8vnnRwg2WQk9RnzmMnrPQ/MU7v7PwPltt+9Vyw4KxwcmzOeYL62cTrwPiVlKEriLwfdyHstNFpUf2qUmKstWQ2wh50i3rM5fhGPF0gX/UUcEsZvFTp1J0e8pRe4JeLZYdHzUJsiR9GHfpkZ51AwdtASiYQ1bmTUn3/4Z8d8YU2b7dKvfigAnROPUdxPJgeCoxBjjp4pKulwf3gyYGAl5gKtg4ixw3FgF790/T7M3b6CFxi4X3Px2cLUdGeoDVzm3iEe6kpDn+FC2nHhV+Xymrhs+hKMkWgSmEv0l7YzwQJOo9Jc0dzZMhk4OtG66hqsHoXMutot5T1ipSgZSdud0xfAR9CxDStpZ/zsE3Q2tr8uPdhagGlETdRBJ6i8H63rUuasKLs6iFeB1oT4zoH6Jeg166iGEG2iUinGnwHG2RmQ1VkETNAe2XlM8++G4f3zkcmCh8pnhZ1pn6obkGmlSlHOLfKULh25nuOuHy4TSjaezE46Qs1xvh2eCQg1AWRSfv+YQHzbVO0/M6TReV/N5HiGCbA8ChHbMsO/OEKGybRD0FzlkHs8ar1Ll3pQqLRLlvo4fUzHpwcGe1a4/T787yh8wr8YIq1cOUa+Affd1FA/t7VL3bI31rj18X0Xstt5ST28hSFceIPDaxIaorb9UCqJrtUo1ZS9nh5EGMrrCHmR/QxopkVQFAo2Tn9VJryIefEbMPETZRYZIWjUt4jXRxtORvfNxX3RmzzhyolRHNcQmJS1wGcQ/W/cFDt7e1EW0vB+61RaUDSe6ol/SPwcjx+O/2ShvffgDIQI24dEC90v+gFGeqQj1VFaiqYIDYx1eZzUPLQCgU2VYM15v+K4TLG3Ft7qRJIZdAANgw8EJehTCzY9WaRXTRZkrte+qHGRF8YGH2S2+6fF4T3dwd3KoFveqDRs4kp53P/YfwU+Ehbsv9OdcZuh2I+kbiMx4HgVDIIgccrhUdBtsG3Qg7sTIjoCANL3tmwp3tPOJoNjceePKRPCyXWYXd6KR/mq9DAJzdjhURge8tcXmlxeRTEHKD2w2lkQBVORZwON5oz6uPJFThkRnrpqMzCyOa8DYrHRQMjrFbPrhhTpMYLb8jItLTjtOkm/cYocUILZULozm3iRkd6VBnPB4xWt9tniV3C+eA+JtRDTDrCP37K+WQDFYOQu8Dd6ggdtgea6tn13KdmRXR9yvzZbCGl1Uld/8c9bxB/yvvNUlta2s5V8DwUPf/7y3bM/WZkP/L/jz9MwCERic4W0O24A/rnAJKtebJLN9E59fjbhGMGrTxBS515FiasqMPfxaDfO2AAUEqUBaHpZEK/Rrz2V5K6aFU7BDncdQNPkdvPKzIHZtpt3AN6wIb1qpl2kOTIfzuHqC/+56W5Eqen7l+iMl6i2JzT4jujJPt6jyEw3144LI/AlznmuQM+ME5YZNHIrg4Zg7RHSuOGAwapnl59nRnpIKP4dmb0nbDEKO26F6W87a0r1NljCax7x5OYVna/2VkTtaFSa1NJP0efvzAqmUQBM6sbTX038bRv1CWkUs3ajy+YqYUljacaK4xPcI+X7Q= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: f89a7037-f293-4074-fed9-08d9984bebfd X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:30.1206 (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: yEIAJ8FDjZMoRytR3ID9ABN4iRjjl/52FukGbIEvdYPoQdHYfabQp9clPboW3VRQ/PBZi6Oub5arl+/hf1LbsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA hvictl and hviprioX CSRs allow hypervisor to control interrupts visible at VS-level. This patch implements AIA hvictl and hviprioX CSRs. Signed-off-by: Anup Patel --- target/riscv/cpu.h | 1 + target/riscv/csr.c | 126 +++++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 2 + 3 files changed, 129 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 718a95e864..21d9c536ef 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -196,6 +196,7 @@ struct CPURISCVState { uint64_t htimedelta; /* Hypervisor controlled virtual interrupt priorities */ + target_ulong hvictl; uint8_t hviprio[64]; /* Virtual CSRs */ diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 3a7d89ac34..46d0cabbde 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -219,6 +219,15 @@ static RISCVException hmode32(CPURISCVState *env, int 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)) { @@ -1031,6 +1040,9 @@ static RISCVException rmw_sie64(CPURISCVState *env, int csrno, uint64_t mask = env->mideleg & S_MODE_INTERRUPTS; if (riscv_cpu_virt_enabled(env)) { + if (env->hvictl & HVICTL_VTI) { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } ret = rmw_vsie64(env, CSR_VSIE, ret_val, new_val, wr_mask); } else { ret = rmw_mie64(env, csrno, ret_val, new_val, wr_mask & mask); @@ -1229,6 +1241,9 @@ static RISCVException rmw_sip64(CPURISCVState *env, int csrno, uint64_t mask = env->mideleg & sip_writable_mask; if (riscv_cpu_virt_enabled(env)) { + if (env->hvictl & HVICTL_VTI) { + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; + } ret = rmw_vsip64(env, CSR_VSIE, ret_val, new_val, wr_mask); } else { ret = rmw_mip64(env, csrno, ret_val, new_val, wr_mask & mask); @@ -1615,6 +1630,110 @@ static RISCVException write_htimedeltah(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +static int read_hvictl(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val = env->hvictl; + return RISCV_EXCP_NONE; +} + +static int write_hvictl(CPURISCVState *env, int csrno, target_ulong val) +{ + env->hvictl = val & HVICTL_VALID_MASK; + return RISCV_EXCP_NONE; +} + +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 RISCV_EXCP_NONE; +} + +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 RISCV_EXCP_NONE; +} + +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 RISCVException read_vsstatus(CPURISCVState *env, int csrno, target_ulong *val) @@ -2005,9 +2124,16 @@ 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_HVICTL] = { "hvictl", aia_hmode, read_hvictl, write_hvictl }, + [CSR_HVIPRIO1] = { "hviprio1", aia_hmode, read_hviprio1, write_hviprio1 }, + [CSR_HVIPRIO2] = { "hviprio2", aia_hmode, read_hviprio2, write_hviprio2 }, + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_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, NULL, NULL, rmw_vsieh }, [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 7356d70be6..bc20960260 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -116,6 +116,8 @@ static const VMStateDescription vmstate_hyper = { VMSTATE_UINTTL(env.hgeie, RISCVCPU), VMSTATE_UINTTL(env.hgeip, RISCVCPU), VMSTATE_UINT64(env.htimedelta, RISCVCPU), + + VMSTATE_UINTTL(env.hvictl, RISCVCPU), VMSTATE_UINT8_ARRAY(env.hviprio, RISCVCPU, 64), VMSTATE_UINT64(env.vsstatus, RISCVCPU), From patchwork Tue Oct 26 06:42:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F13CC433F5 for ; Tue, 26 Oct 2021 07:48:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9B6CD60F22 for ; Tue, 26 Oct 2021 07:48:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9B6CD60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHBj-0004Kz-Nj for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:48:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBR-0003Qr-Be; Tue, 26 Oct 2021 02:43:41 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBL-00014K-Cr; Tue, 26 Oct 2021 02:43:41 -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=1635230615; x=1666766615; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=xQ+uoogFLR4BdpvIx+FQYy5pY3pNfH/hNMFmtvUv1i4=; b=NFWqCTX1cOhAtlWQ86/tJ8o1QYafoHxQGkrlQbKxmjviGfJFo1kXL/NL 4EgnkaBoKFlCy+6jSTvzr4jsbiVFlEp6HdRbcKAyjIvjxVXuPkLbWzWZ8 ldryyBROOQ3dT04qsZcoUgtH5C+TBWPgNThccbS4DXXSuRazkWDh//P9v c9QsFY838x+ldY7vhf753jVHK6Rj0ncHuEBiIs0ZqzmUKldugep4Ocx1b 4mcNgc8PuTssu12jPKnEZ5LlJSCA4mYX19SglrVU3cDX5j7a2RmbmQ+vu fjD5PbRSfrO70klflcofU9uOeCMw60Cgcz+KYQ6fPGqCTFCuTvev0sOyl Q==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854768" Received: from mail-mw2nam12lp2048.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.48]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:33 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WOy4isa2fZ6kJUKIKKU7okQCQ/JnBBOlCvqStwkuqaDPq9ClF3gmDNmnBAx1ogjBrJzHK0XwoepkjAz4ThCIB1993och8I5PRqIaaHDlclRIY0A65NtWt/Dzuvo8QJpDuyuyCnhPnsNDwtZH64A1ioeiWJp0HrflsK33taAcVUZsEbFiqGB0ftWurEg+eXt+qpwJOkbJ+rg4kT5Maa3CPQ4/BBuTXOH1W7s5q+ABrSTquMOZW8qwUoQirBq6iqE+5xX6zQOGLq7IvtBpKdfB3yd7B1o1gUamLUZoMht+Xh++8KdwklOCkEbtacrTEJSLs56Z9Y0AgpR6erk/yH1jcw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LlHAPG0OuTGyaL39JRZZDmoqnAC97fPSA6n7pThq9R4=; b=CgpMoy0VfYXPm0778u/7FTKxlF98llesoiEkLM6lxzpBKvzrnPIaO1H66sVG7Q6HjAl5t3SCM3aP77Lm1ut+L2V43NV3yruRcQpKXdTw0fxPS4dhwhtV2B4gA4bfDJSGCeWpC6jZguDXrjKmw9hO+0wyszTvZZUnfaSWeOzDhUPpXMpHJ3RmmZZLE0z105yhg98HBT0pzNoyBLLumObvpi/a1MRRGSTFNVC7PnY1kWGhLAg/90RAiacL57RB8rOVHtc3jZjEhcpGOl8EvGGj/90HZ2Iyp/tKULnzpkSZBvXsuEJGi8T9dhUJaS+YIvNgCBVWtP4W+IQoQP8tnF/WJA== 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=LlHAPG0OuTGyaL39JRZZDmoqnAC97fPSA6n7pThq9R4=; b=dVrEfgissWyDj0HM6Uqq+XuDT1VRIqTmy2cI1dsbBrv849ZPEIYxuaLzYS8ADl3leCc3rdYCV0PM7KXqzBFrb29/uo4ZGldGA4vgKH+prHO1c1iGxSq4iCquf/tMyFPjSmtCx4p3EhRaNU/cFez6+7Shgj2/iX7S+cXbaYBPBEY= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:33 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:33 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 12/22] target/riscv: Implement AIA interrupt filtering CSRs Date: Tue, 26 Oct 2021 12:12:17 +0530 Message-Id: <20211026064227.2014502-13-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 99495c71-a509-4015-ec14-08d9984bedd6 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rWPKlGc6nrtZvz/5Sd8f9empCY1FS8VEnb9N873ookSutUXx9X8W6B05zT4uSIOGVuyuakBJ0UIWmDYHWlFrW2XTJX2QMKvoeij9ZZaLZCm+BW6itMoSVkny1JtvahML2wEn+1fqVKwT7b3uLMX+0UttHPV2qSEXB1ZG1AGYhC3ZSYsybTR6Mz0MhCghjSfl7A9vX8JwredD3UMbsCk2PXxeGnD/1S83M2qUJ8lM9UJi7M+lywYQzdU5dJj93xfsZcU1HgXdZFqxKytJu4+i+VWZiOFT9hCDbTy/0Xd2EhcIQ6ZAGtTG0+4BOo9eJm6IrkVmhZy+mHzRMwNjwRtF/bF8hR3THmORjTsv2J2wR7wUZ5tsI6NnazVT1xsx8tJv3ATcEQ/us3UCfLL1L4kkwF11ScMbrNHzG74gv6nQPBG1QRwbPvAR+YBcPKFS4i6nFhugyYUN+lqiqAQ2T/1TAs6YxZGiZxNyUDf28Sn1XDtFifAQVrMO6FmzvoSuF89veJ4WSlpFyCtOa0mHoVJYAGEQd5rAuaO+Ic4Om3YUQqaD7d8yQfdTajYlmADKnAcL53VmAztH9+H+y0sR8cUPROZ8b9eJq2UJdJMp9fhaUBL31CFe2hYAMyjoVnI0dRXbnVMcNftOu+sD5Q/BmATD6mcWZR5Fnx+CFz77m6xKWGZcrVSY1NTYZ6+KR8rELvTwkqP6Gk1WxG/LUVvFq3+TGA== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z0+w4+vq9kfY2yTTOC09qWwFzkLEN92P52g8sSTu5kYIpW+jjppQ7Nge7KeSbfOl9MuCeGd+dzjCbRuq02nhyAVk4yoGYPYovU2XfImhiy/iRPwSlnep0om8lCTgaUANTmXhLrXPgVj5N97ZTdrNleHgzL2tyonIoJCElURnt4wKkbVstVSl/T3ggCVp/kISAQJk4OvwrfAdYjcMIHnOOUMlvOY5n7VjEaNJ8MF4hQ50SjO9cPyGoVid63pCSeJ1qxXGx4QKFlDjTyu51oVaGwqGhCHRpOofagblTGbAZ6EiE+TAmZfZ56hOFTLMB3GQH0FsGKDPjYSfdnWiRHHAvrsV8LXpK+5klLbKTvgybsxA/XaEHKoVKQc6qzaA3UJIpAk4YEfPGNe2rEe/0bH7mknCZB2aFzL7IqqVT8oWEF1WhEm1M84bTFa8Yh3eQ36n0c5gRVFuqU+xzyYWIc+1tX2Icz91aeJrETbAjbdzv4ZZoeDbPhq/P2rBye94sHGqtHBhapbPn+XhLNAXisaSFZY6ciAUlCxMIAkATzNosPpCo3c1G0ObBWcpRMiudhpgncVQkLXC8lGB63XFq+RViNoxmPjh7MCadLvvT/sKXROCd9HZGR8JHnhDLZhw33U+7DCZql0ckywt35Pe5sR+xriEz3FhRsfAUQNVJEntWr/XIIjF7bF2xSDaN421a56pxEqq3JskoEXWcBVJIX/do/bPoht1w4ZK6sC2U1sp0QPDFhM7mJtG1lxgIg51FHJ8njfV0MOMLrThbe7Hc0RPRUK2egNzdeEpuoZp+gY/Fk1B9AaxYn2g1HhpZNtuaNiL64gbrDTZVF204hrhzox4hiJxWisOmfrvOprFSTe8dlMC3Hwe8xDe3KkVHCnTjHccxxHsH7kUHgiGONiPPFTI4jJt86N/3onz3sLDCGsVsQJMjdStkd+mvc8jXy0feiMmaTGe4zBCzcfPZ0PaT4Rx9v5DTpDwiOG/zlc7FCuz+nIhYUjUkOqKp26yAauTZIXpsTaYRR0z+sS/pPXkgH7r78frGZgdM+bNQSdO/NeVWbwqKRTwUk05HP/4znUhItx1wFgslX+Ul/qKTayrpGKliod2gk+Ol8KRu1Ra+B3ZNb7mHfoDSOfESU7I5knLE4bY8oY8c2cAkQhxbZncn0Q2pLVei2Pzo2kRUXROqMB+1fpSgBkoXAi/xtM99l/7A/pO1fzamwUgmp3mgE/EPCe9SgNOEzKwCyrgbw6Pf3ZwdIW5BBAVhlgU5/VK/cPoyL8BZVqmyVrVkiSOOmnnne/dOtmA4CeGMyPcPbRhY/WGMCtAXqvE0fayQ5yYQ9j390/fQj7A/GS/JAP7yDBmoRgCTEheo726x+iFr82twruKnz93Tldii91oBtvCvQ/R+gtf2KIfsUHh7G6Ty3osaPNYaiGqInChfVg/S0BvpJMMV+OyAGIYS8CIcfNoItGOgCt57n4WmeqzWqk2zJe9OxPWOW0XaRh/1JLJwAiYZVKXjS93XYe+Y2iY8GZ+zdApgDk/YJi7Ec7yDANSSwij9y6mufXuuE0RYEZsUszk20hOiF++82artLUE21hUtVJFYa0buI4xashIeSiZ1RJ6icWgWrTYBm1uHdO20S6s24n/bn8= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99495c71-a509-4015-ec14-08d9984bedd6 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:33.0915 (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: tkhU32zIOGU9p9XPPT/RonutfujuHd+8PHTqvykDPcaUW4EFyLSSHhXQmSvuidk8uGu1Lt2KPHbSLnrW7S5xzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specificaiton adds interrupt filtering support for M-mode and HS-mode. Using AIA interrupt filtering M-mode and H-mode can take local interrupt 13 or above and selectively inject same local interrupt to lower privilege modes. At the moment, we don't have any local interrupts above 12 so we add dummy implementation (i.e. read zero and ignore write) of AIA interrupt filtering CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/csr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 46d0cabbde..43ae444774 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -153,6 +153,15 @@ static RISCVException 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)) { @@ -515,6 +524,12 @@ static RISCVException read_zero(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +static RISCVException write_ignore(CPURISCVState *env, int csrno, + target_ulong val) +{ + return RISCV_EXCP_NONE; +} + static RISCVException read_mhartid(CPURISCVState *env, int csrno, target_ulong *val) { @@ -2071,9 +2086,15 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, + /* Virtual Interrupts for Supervisor Level (AIA) */ + [CSR_MVIEN] = { "mvien", aia_any, read_zero, write_ignore }, + [CSR_MVIP] = { "mvip", aia_any, read_zero, write_ignore }, + /* Machine-Level High-Half CSRs (AIA) */ [CSR_MIDELEGH] = { "midelegh", aia_any32, NULL, NULL, rmw_midelegh }, [CSR_MIEH] = { "mieh", aia_any32, NULL, NULL, rmw_mieh }, + [CSR_MVIENH] = { "mvienh", aia_any32, read_zero, write_ignore }, + [CSR_MVIPH] = { "mviph", aia_any32, read_zero, write_ignore }, [CSR_MIPH] = { "miph", aia_any32, NULL, NULL, rmw_miph }, /* Supervisor Trap Setup */ @@ -2125,12 +2146,14 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst }, /* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ + [CSR_HVIEN] = { "hvien", aia_hmode, read_zero, write_ignore }, [CSR_HVICTL] = { "hvictl", aia_hmode, read_hvictl, write_hvictl }, [CSR_HVIPRIO1] = { "hviprio1", aia_hmode, read_hviprio1, write_hviprio1 }, [CSR_HVIPRIO2] = { "hviprio2", aia_hmode, read_hviprio2, write_hviprio2 }, /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh }, + [CSR_HVIENH] = { "hvienh", aia_hmode32, read_zero, write_ignore }, [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 }, From patchwork Tue Oct 26 06:42:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AC53C433F5 for ; Tue, 26 Oct 2021 07:56:52 +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 584FE60F22 for ; Tue, 26 Oct 2021 07:56:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 584FE60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:43038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHKC-0006JA-N6 for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:56:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBU-0003VS-B0; Tue, 26 Oct 2021 02:43:44 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBS-0002ER-09; Tue, 26 Oct 2021 02:43:44 -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=1635230621; x=1666766621; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=8hCfvF6U3YpAM0d9MZNIIUkZmdVvqrgow2wJTWop+lo=; b=fG4rAppx5vA2BVE1/KnLT9QHP+oqyPuPhzdIMBSovZrzfqqhsn2Remxn eg6Btd7E3OHqZSwpqC6rkgZDZktf06DsMgrOjIPZpvjcG7Exg44f0EZsp M3xytAyOhNLThukXgNiDjWXnqdQUmlPes5/UY9oavqpTFNiaJuSdydxZc X1AUXSywEcozgaeqE0IS/Zm49swjwr4Difp399Jm7wkVqW9TfXupMn7LN 2+05hKA6HRw3Z7fIuGwaMx6epk8NkHfDkYNszfm0RAojbTP9Cl7T+9zsB ISgWHP+0hBOZ7Eu1rcGiffopm4+4ZjyX5hrv6NNog08ZtBThiHyfdFRvl Q==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854770" Received: from mail-mw2nam12lp2047.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.47]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:36 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TM9uhPUvcOtwuIxzSC0+GhfXhIOdvCpl/+Ur1hWIhtnUwXSmgfB0M3CQDmktJPYlKdu9TxpC2XwV/oOCYABfPZcS2CWUf1y7g4WYOyZcN7brDHCJxKFQpOhTNVsCI23eEak95GWGqbAGX0lnuuuDyr3ZQhAP2fJaQ+hFITzvDyJ1dLMcGPdQNFd3KrrOKKFchvbmVvfDgoMf/m/67+96OIyVMzGgaJd+f2lasxB2dE2Zrg9vKZTBXz+/+Z7nTphl10J/r98vx7GfrK3jkpJucVi8SqRpybGVPrngrWx47jSUcxv2b+o/KvhTSYsY+GhPOBMy7PxHeM17gjGBXentag== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JdW/996re6102wzlutMgaIwMLUHwY2GHwdAMZDfEEK4=; b=bS8//iJozkbJJ7o/+Ow0HzanxobN9vEo+Z/GEDESp8Y7UPgHypeOU83Q4FyykNwwuNPzqhXIRZuP1zOc9xdHiP6usHk4duU02KP5PPHg5UEUmTv7nRby/XeZu26VgW75wgTQ5ibZnxtHzcGD4YBCDao0lea2QMfwUWscqvP6TicMlS0arCxnc0/lLhfU67+bxj2i5e/SU6AzPd5hj0Lfvrp1RXo+J8HC8Jk3m6RYjsehaTjPWQk3/riu9ZaZFOmJzB3b8zfR8oXtOMyA2nrnFGbSDaP7rzLNN1MPW3F3I2e6AjPWJGBIQCmbNL3WeckaGezMaWlXFOkVDs2XbwNY8A== 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=JdW/996re6102wzlutMgaIwMLUHwY2GHwdAMZDfEEK4=; b=PVKXO8AkU3J8cxYQopbmcSbIHsvTPccTVtpK6c99KYkXQlddrVPw9AMV+rDonjdL1ZAhThmTovU2jCT910aTX/2hA8TNqATMnKxBKHEymZhMRMufUfiw8W3f7ZfV0C3xjt/ksgCwfBWKbdua4LHSriCfDiL0hVXMnNBcg06WRPU= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:36 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:36 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 13/22] target/riscv: Implement AIA mtopi, stopi, and vstopi CSRs Date: Tue, 26 Oct 2021 12:12:18 +0530 Message-Id: <20211026064227.2014502-14-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41803108-f3ae-4267-19de-08d9984befa8 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:250; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NW6JwKUObiuoiLyckxnNXiye7haRxXIPuzGmrvlma4Ce6Wtk4E/ZDXe1KFtnIVsaEbWygJh4I3ffuXTD+BsomxioerRBcOn6lzUkCz4SEbISykdJq7wZBd6231DMneOIga+JBc52M7Z4jotd8Nnied7BADNO+RQu231PDXe/cl+jbcgGx+YJrmdsXo0mHUo3YKeu4D8UCpC3Irp/dubXCwPVHoWkTWdyHMWo+ym5ax1Ajh/LXvyZaEiGRb8/DArDsTERMAan50QN3KEpnnxGrzH+jRzEB5O3zPmb7sSeq6J4hD1LICHZOWlmFomgXY7eVP/AO0KBsfEXqs3acsgCcfEanS3yu8ayQ1kZYDWssFrd3bFDMuXVZXqx0rqhtVvXW5t2Qg5v+1lvnfa/rTGVmKNgDI0lmlP0sZkfq7AMJZZy/VuW+/lLl1sF3M3GaMdT8KTNgEg6wgFTrXitGqI0xTlMeXlhbvT9N67bZzzgW00spHTwmlOnaYggYQafIkvFGL7S2u538A6jCw/tPj+GtKfutWUg2YYc0pS8cX/JxT99OLG+y0PKFt1GRUQUa2jk8epUTOxoVuwHYF7cqzbECHqfpb0CUN4CnkJ8evjc1xnaelKaRPmoDpvyU9dY8NQW2NRFOZ3IbRWbMvzUs5BtOLYxiz103tDxjOkoDcNROvu1CUOmmwEfyVCVX3lfqjRHr7Pvvk+4fzr67pWiYhj/zw== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EihTosm53RyQvhTmrf37a5VfL/gRWp3VO7guew9tna01wj9CXlw9DBRmBoS0b0PDHJnNV8mNYdUFchZOD9GKTY6cruKisC85P9J8UhWsawx/O3ZWjTiX3Y/pZt95nGCBCEu/Ny7IoMNVHmw9yLikNXsYVpRjB7MniCIUSR/LFJX/Hz0JgPxV4g5InFzfNo42E92cANsOX27lDzqXshvzkJdPqTJ9PnjmPnyA7ISG/FfTqX3Xhgyfm9/Vjt0pdKFe8IyYM3fzmRuha1WJDHY096sqP5QE/9dkx4jCVv5XQxisgj90sHHc97YXVJ0w9mA/UB53vep4VDsJqe0hmaoeifVc7s+xEspZMZauGYkViuM5rIzQEdkLch0DOE/yptSLBNKS1rAEsan/yBu0hXWc3TJhedbgd1qz/bviIYECOACHKW9pRS1bcuavBN8haZe44AqVUi31d8ZNMyMMFzUrpE8tV30oau/ju62PfT5xQ5MkNisZDA6z2x6U9F1/ZAPLUXkHWCQ8AXOYDly5M8pJJociJjNexRR/a8Bd97HkkRLGPId19UTebFDLdFY/uQGQXg6QUJjvl2cRTqDgRdemhwm4+QqOeke9z18D4UffJ88j+OstXF4NxhMkeJH29y7FdKgZkPnLcqo7a1wA3L0j4rIOUtGoVDm8bNkNE3hkDwBvmzNRo6djtSzywAu2GNliu8X/ZRt+G3cV245h1xHokj6nKpPC6WrYFZb4pStRWx9ofdCpNgYQ/4ihkGMJCNYODO0sjnSLwIgUlsFdDxGgflQOznuFIkMpk2VVA+zDTy4q3mXHXraLRTSCQsF3igqmBU5hN4Fp9x9u8h0ZwG/cGM4DHJUlrRbBA8j/lxY4dby9qxblWcS/fcsi7lcHRz+n/cK3BBaxOGFXnEh8k/nZqQ5TJsakZK1uXsK9o9XRImnVqQxIXQpERdXDQ304KXj+G+NlcJGWzw1oNfEax8OdHbAwkExH1e/gOhpjXh+gY1KlE+n2nkV/ee/FNigOwtI/teB57oxPJiCPUIzkswMT4gHmS81tKcOgw1YojfFKXu4zaXNbEHsqv6qy4/XYoQQUwj9uGt8MRIkX+bMrr6iQN15CnQaJvXhV881hT6gHzAVOARVlDiA8V1wuGfYsJz40aLYJcC2YYwsWdouyRv6Hnjhqu6lY6SWOiWof4DTS0Ct/8BwxWdW55f77M2YDCHxU/WSzNWUQfJ1hatZnYqM5pVSm8qwI3n97Jhh7DteUFC/L0o8zzRrbfEPsoFrCSXqJH7hTLAnEvSVGJyo7XBijabx78AP73nyDXlrlgai1XdoK4+YPphilS6xXIwhR9KDGUCHyS7DX0F34bwJlhbGkp2pOvRkIFRRkgfnAlaRO10r/WL/mq6k4SGR6Pq8zi94O7gZZsmfnxj0Dr2fkCjjfXd7NE2nHUTMq6DQUesfUQE/QET3ZIe58VdvmmF70o5CCtqTtR+I/19RzVbuseuVXsHfTncA8tDe7KqcnWjs/e6JpPzzrZnAtpd1IyMzjihEhsn2sB7WUGcdhr8sfl5oDeuns50VyH+K9l9ZllLYLxYDTPUzOMM1+m6oJKc+NAVHDc2HDVbzj5GP7xmGQLdxyDAg4vz4LREF91Xi11bt9PyU= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41803108-f3ae-4267-19de-08d9984befa8 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:36.1182 (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: Fb5SSq6fbGwzYNbLWmQAScSxemnFRflTvD44YbmOGGHi8RYYq1u9OW0mR5bAyIQhShSBdjGFfU9HF3mY1TKJoA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification introduces new [m|s|vs]topi CSRs for reporting pending local IRQ number and associated IRQ priority. Signed-off-by: Anup Patel --- target/riscv/csr.c | 154 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 43ae444774..69e857d1e5 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -189,6 +189,15 @@ static int smode32(CPURISCVState *env, int csrno) 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)) { @@ -823,6 +832,28 @@ static RISCVException rmw_mieh(CPURISCVState *env, int csrno, return ret; } +static int read_mtopi(CPURISCVState *env, int csrno, target_ulong *val) +{ + int irq; + uint8_t iprio; + + irq = riscv_cpu_mirq_pending(env); + if (irq <= 0 || irq > 63) { + *val = 0; + } else { + iprio = env->miprio[irq]; + if (!iprio) { + if (riscv_cpu_default_priority(irq) > IPRIO_DEFAULT_M) { + iprio = IPRIO_MMAXIPRIO; + } + } + *val = (irq & TOPI_IID_MASK) << TOPI_IID_SHIFT; + *val |= iprio; + } + + return RISCV_EXCP_NONE; +} + static RISCVException read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) { @@ -1352,6 +1383,120 @@ static RISCVException write_satp(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +static int read_vstopi(CPURISCVState *env, int csrno, target_ulong *val) +{ + int irq, ret; + target_ulong topei; + uint64_t vseip, vsgein; + uint32_t iid, iprio, hviid, hviprio, gein; +#define VSTOPI_NUM_SRCS 5 + uint32_t s, scount = 0, siid[VSTOPI_NUM_SRCS], siprio[VSTOPI_NUM_SRCS]; + + gein = get_field(env->hstatus, HSTATUS_VGEIN); + hviid = get_field(env->hvictl, HVICTL_IID); + hviprio = get_field(env->hvictl, HVICTL_IPRIO); + + if (gein) { + vsgein = (env->hgeip & (1ULL << gein)) ? MIP_VSEIP : 0; + vseip = env->mie & (env->mip | vsgein) & MIP_VSEIP; + if (gein <= env->geilen && vseip) { + siid[scount] = IRQ_S_EXT; + siprio[scount] = IPRIO_MMAXIPRIO + 1; + if (env->aia_ireg_rmw_fn[PRV_S]) { + /* + * Call machine specific IMSIC register emulation for + * reading TOPEI. + */ + ret = env->aia_ireg_rmw_fn[PRV_S]( + env->aia_ireg_rmw_fn_arg[PRV_S], + AIA_MAKE_IREG(ISELECT_IMSIC_TOPEI, PRV_S, true, gein), + &topei, 0, 0); + if (!ret && topei) { + siprio[scount] = topei & IMSIC_TOPEI_IPRIO_MASK; + } + } + scount++; + } + } else { + if (hviid == IRQ_S_EXT && hviprio) { + siid[scount] = IRQ_S_EXT; + siprio[scount] = hviprio; + scount++; + } + } + + if (env->hvictl & HVICTL_VTI) { + if (hviid != IRQ_S_EXT) { + siid[scount] = hviid; + siprio[scount] = hviprio; + scount++; + } + } else { + irq = riscv_cpu_vsirq_pending(env); + if (irq != IRQ_S_EXT && 0 < irq && irq <= 63) { + siid[scount] = irq; + siprio[scount] = env->hviprio[irq]; + scount++; + } + } + + iid = 0; + iprio = UINT_MAX; + for (s = 0; s < scount; s++) { + if (siprio[s] < iprio) { + iid = siid[s]; + iprio = siprio[s]; + } + } + + if (iid) { + if (env->hvictl & HVICTL_IPRIOM) { + if (iprio > IPRIO_MMAXIPRIO) { + iprio = IPRIO_MMAXIPRIO; + } + if (!iprio) { + if (riscv_cpu_default_priority(iid) > IPRIO_DEFAULT_S) { + iprio = IPRIO_MMAXIPRIO; + } + } + } else { + iprio = 1; + } + } else { + iprio = 0; + } + + *val = (iid & TOPI_IID_MASK) << TOPI_IID_SHIFT; + *val |= iprio; + return RISCV_EXCP_NONE; +} + +static int read_stopi(CPURISCVState *env, int csrno, target_ulong *val) +{ + int irq; + uint8_t iprio; + + 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 { + iprio = env->siprio[irq]; + if (!iprio) { + if (riscv_cpu_default_priority(irq) > IPRIO_DEFAULT_S) { + iprio = IPRIO_MMAXIPRIO; + } + } + *val = (irq & TOPI_IID_MASK) << TOPI_IID_SHIFT; + *val |= iprio; + } + + return RISCV_EXCP_NONE; +} + /* Hypervisor Extensions */ static RISCVException read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) @@ -2086,6 +2231,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, [CSR_MIP] = { "mip", any, NULL, NULL, rmw_mip }, + /* Machine-Level Interrupts (AIA) */ + [CSR_MTOPI] = { "mtopi", aia_any, read_mtopi }, + /* Virtual Interrupts for Supervisor Level (AIA) */ [CSR_MVIEN] = { "mvien", aia_any, read_zero, write_ignore }, [CSR_MVIP] = { "mvip", aia_any, read_zero, write_ignore }, @@ -2113,6 +2261,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Supervisor Protection and Translation */ [CSR_SATP] = { "satp", smode, read_satp, write_satp }, + /* Supervisor-Level Interrupts (AIA) */ + [CSR_STOPI] = { "stopi", aia_smode, read_stopi }, + /* Supervisor-Level High-Half CSRs (AIA) */ [CSR_SIEH] = { "sieh", aia_smode32, NULL, NULL, rmw_sieh }, [CSR_SIPH] = { "siph", aia_smode32, NULL, NULL, rmw_siph }, @@ -2151,6 +2302,9 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_HVIPRIO1] = { "hviprio1", aia_hmode, read_hviprio1, write_hviprio1 }, [CSR_HVIPRIO2] = { "hviprio2", aia_hmode, read_hviprio2, write_hviprio2 }, + /* VS-Level Interrupts (H-extension with AIA) */ + [CSR_VSTOPI] = { "vstopi", aia_hmode, read_vstopi }, + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh }, [CSR_HVIENH] = { "hvienh", aia_hmode32, read_zero, write_ignore }, From patchwork Tue Oct 26 06:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584127 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B977C433EF for ; Tue, 26 Oct 2021 08:08:26 +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 0E87B610A0 for ; Tue, 26 Oct 2021 08:08:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0E87B610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:37256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHVR-0004tu-7R for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 04:08:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBU-0003V2-4I; Tue, 26 Oct 2021 02:43:44 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53156) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBS-00014K-0g; Tue, 26 Oct 2021 02:43:43 -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=1635230621; x=1666766621; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=/m+pb6B4KK3IKZzdxau0a214vI4jr9MbdzhsMRb843U=; b=XK6mOlOH+9f5Qv0BLkT9Tdemg+XHQwz2/TFs49PWLsVP5uZfEtlO7Oj+ P8xMrbUzRV8jxeKQzj/tBPeHYMDPecB/vCv0TLP9zWeteA0rjRxpgCNFk SicGceRyEE4aHys5DoNvqk+wx2EAQ4moAi3zZZapRBqetH1/A2g6Hl7bO N+Cxi0JkicefW/CALHza/DpRtojJdVB/uQzmOjZ3ggkc0ufhY5ddFhZBh 8e+r5KFcb5+mxCAZA3ZOD2CCQ6fEMylg8IMoS13SuCxmSv2LTmD4bodLy KS2VMGsu4QRGVwiQlBs3X8VX7Ie1LuANZxfjHTgSyIAtdMbiK05YXaDXu w==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854774" Received: from mail-mw2nam12lp2046.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.46]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:40 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aTdwq/qm7VmTyL45IgXp2GuXeeoHHcQbgczDvdLNXPMPvt1qFJYTTGzOE1KJB2rPbV2HPsNIX1xGxdJbGiS3AaFP7TGBsU8ffT1/Qm83IOsqWOKqnmZBixUbKrsKLEhMF6TIOt4HooYPh7+hu2sS84u+MiEEi/o93vfnSxmW9iqM3BHOnxWkxXGfRmSHXI6ezn4y33b3hrHDcHJE5OdCPRdpGM4mi96PRFkzENzpPDngDvUG9oqpApa3PhtgsfCgMi+5rFjHFCuWxWppDDICAXylJoUjonbf/S7puB3+sjGr5ldq/MfviMQlhQRUkuudO9AXy00NluxR0icW+zUC3A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=20CN8QSGjuuUSn794mTU1Wold6bVUdDJ1zZ/1OXqtCU=; b=mMOuHGMOn++SiA1cP7ziF8l4FD1HFtPDvlQckB7tVkTLumzanAVmUX0evF0pOQgzc/8SQg9BHSjGsLRYfDEuQd9nEWOv3YOWe+yeMRJcv/0lQ1g0pdlb/sTvmT0Ut8DBCyAqaEejDleY67QRaemO5Rk7rkb1TvIPc/eV0HeDt1zeUpdxV2clJUfBl++Vw50KoWF33C1Z3tashqyUTNOve18yWyYVsOp8jr8JYZ3eD8asLxiPeOxykWtuqBHb91SI3A04Db49RH5MAvKIYnVYY6o31Gz7KxHD/kD6x5vco3WHR2A/GH1tg04EVMFiCG01U3c+LfpTDK90lE7uKxihRw== 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=20CN8QSGjuuUSn794mTU1Wold6bVUdDJ1zZ/1OXqtCU=; b=fVLDd68VOrO1AUrsm4uRUSX2qAkDhwmD3+UFyBasFqSVHMQLt8uiPhy1nON6vOv4or4xDMgIXAHG+H4JWYmshV977xWuPMhWpmlFqYE71Lm8SLJ3p7181Z73l3gw/NgeubWEZQYIELGHdfUTxYuRNIqi+n7nPPO6sOBY31sBVf0= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:39 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:39 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 14/22] target/riscv: Implement AIA xiselect and xireg CSRs Date: Tue, 26 Oct 2021 12:12:19 +0530 Message-Id: <20211026064227.2014502-15-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e6fc313a-d1d7-4e3d-e2cb-08d9984bf16d X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:1122; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sU4vaIo63ms/CUxwpB1cYt6xumwS+Pdiqs4roIx5mwMHfAOLvinpSNLjMATc+sMlLhpQS0duznuf/0+VAlmRnIVWHqimwFQFFUpWXZ4jY6Nm5hIPTPzhmg32N+t00fvLU5Usm64WBQ62sQjRb5nxEWQ2fESQE1//5sMnPFNWfDmn39LrehG2f9biUGEFaD7vYYv0Vk5WsjrleSyzCCxNxGWeqlfeS3X/lfqSv1+XEKAHu9WWvj3IXHrU0ZzGREj3MuGBg4KUYWe0OV9hcojDUqizBh/Vb5Jl5yFI677HLVkD8W1A82Ywc8+SqgxPa5o5r+Pu22BtKNShaPZV/npNnyFEjud/wFTrw5SDF6ozKPOrFPKerPCGkZw8EyKJ2uqAD8zma8aMlGipfmUmlPB487db+l8O7nGdEbsaWnGN2Mkx0HbSvteLzr//iqemJ/0af/FBenltZ1fe+/w6f2ZCidY+F1CrzY+SKA9MhbwYSG2leTfASYy7hbYLMdZyydueBicgMA18KsD8Ku/ZYxpFTkovufOMsOQ5kDjsPh9DhodVp73BtEFjHFDT1M3onbmstchVUKncKcKdJypSnkKqbNCqM9LRSCu8QGKUKHiTZZhhxIfU4lWAhLvSWQErZoPbHSxaNomEEFUR5Se7q5wYH78BrYcdJJt9ma4xeHQqtI2AFE7C3gXUtb3bVlyI49lF 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: m5aMcan7qjCA1zS2nhYFxS2d65YV9ERAmsdjDfHZmL6o1OlNU0bHPun4RBwP0NxmDaJetZiIQ4VfYc9/5a3+OceprFb1I1VPxLvleCIjfkQ1cH1+ZwB8mySUXRhQ+j/UMkMVbrVn5lqNN07IiH1TObHINJCrsOw4AhJI496YjUn1osMN88CTbI+uGqcYgQsbbuIIQyq62hI3MyHU5N859Q4oxK+etXUe+SyDYTkkHYLgBVddvIOBxeKrYu0PgIPyB025Lc6uKvFU3iXMiJkN3B/q7hlJ2szvxihXrQjZFbucN1WNjrHV9O9HUrdBKFquD8i+ltWvx1e17ZEbsGGT9JAn9LRpCdamkbruxwoELzoGqDtrQE23jh5yEArC0rZ3lrlrklELKSYyYzCxj8gSjaEmfmhd4Lz50hnXMq57/pLual3lrexHISrhH5Qh0UI4i9QrNknrg/dJcdD1IcOXW3qKw/4pHART2vJbS/q3ZCO0ra2Jf9EzHB+tmt28E1Ae7TL3ZmRaMiVx36s04UQEukWH5v8xJIJTWe8Wf4ygkTzl+dbuVXZ5wad32RRseZByxnfSwWE9QYUFrbBepVdgRP4dDoqoCYPzA08ETp9++V/5n5qzXDBpmTD4mhNanAh84WgukOEkCfzRQb5/Q1dgDWFw42+f+r6U/v/eqx3+rWqLnU2OB1HJ8Xf5dhLNHDOdnQuAXZPmH28Xn3+1WB1zmElr24ouHFB2z8aWFrol5JjShWRh0zRsNvSrQQRZ1018/rCKKfuXJNr8fHm1sRZSFebtOCIfuMEGHxSsRuYYWu3x5iGo5tO0OAfU49z7Di56FM97gz3rV7AOAbDevQEgz1ctoXB6CsGKRgP4enKBCNa97FrkVfx2yzeTB8RgmsCVrw8BPCbEnx9YSFd/haoIAHNh8E29uEpr8OgeU+EZO17MZ/5LWYjWm33srUsLzwb3udqCNCHpYVJ89/XiFs3TUwA3UwLLDfiWRhbSig9rBfkkbM3JMh4iM+juLISZka4DzbY3FdmHrL9X/8aCk9AUdAgC02BtRuOGBU+ikSE1OaAVU9kddwqyygkgA51YbN3T+W4TBA6KUjmjGmvmCmDGznhMmmWmFQt5NFsuDBjUflvp6WD0JB1+iVh7CkdzJUPfjp+kYlAUh0q5NDbP9iuSEY761oY1DiJH3czfw1fE8Qe8U6ZU0QFeXmWsnpXfqdAeZ5Ae+rA7F4dWfY0QkZkduoykAjVOej1KOLLijjgMFcjwon0kYHwC7tm5JlxYnjxkppkmwM7nMQmRMp2PzgHyLqSCYCJ8LVz6Z/QwZh3ZCUC9v3QwU0W/Mwdq9brGvebpiAmp/AraYrOPV6gzLuyINTciLggvBsyQJzn5RtHOCBl9zBfg2BF0LPEnbqJ1dj1TItTNLKW5UHG0hF+NXbeUR3oxCsv20tAvujI0JJh1ZJUi4UEKaOdlPQXJjn7derGbeXgFuFfRf5fYgq3/hucGzX5BId1kkXA9E0S9/m2mvWHO67Ur/b1cIXNNd4tQ/08pU5DXks2vEv/Zaw8d9ndZtqxmnqJGztyPIRVKAQ4guHGiSbodr4M7Pm1U98uqvxURfIVVambUFCO630+tzgMOA5tTW1KFx/nfmWtKiKQllXQ= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6fc313a-d1d7-4e3d-e2cb-08d9984bf16d X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:39.3430 (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: wuWVgA3Zn3fLAePwa++bEmYQvJ6cVHT42VPs+C7/ENWbatCLgGKLVqi5lZjRpPJ6oDOaerp6tKOTp0AX5eABQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification defines [m|s|vs]iselect and [m|s|vs]ireg CSRs which allow indirect access to interrupt priority arrays and per-HART IMSIC registers. This patch implements AIA xiselect and xireg CSRs. Signed-off-by: Anup Patel --- target/riscv/cpu.h | 7 ++ target/riscv/csr.c | 174 +++++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 3 + 3 files changed, 184 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 21d9c536ef..bf688eb1ea 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -183,6 +183,10 @@ struct CPURISCVState { uint8_t miprio[64]; uint8_t siprio[64]; + /* AIA CSRs */ + target_ulong miselect; + target_ulong siselect; + /* Hypervisor CSRs */ target_ulong hstatus; target_ulong hedeleg; @@ -212,6 +216,9 @@ struct CPURISCVState { target_ulong vstval; target_ulong vsatp; + /* AIA VS-mode CSRs */ + target_ulong vsiselect; + target_ulong mtval2; target_ulong mtinst; diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 69e857d1e5..e72220fd0f 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -854,6 +854,168 @@ static int read_mtopi(CPURISCVState *env, int csrno, target_ulong *val) return RISCV_EXCP_NONE; } +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; + default: + return csrno; + }; +} + +static int rmw_xiselect(CPURISCVState *env, int csrno, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + target_ulong *iselect; + + /* Translate CSR number for VS-mode */ + csrno = aia_xlate_vs_csrno(env, csrno); + + /* Find the iselect CSR based on CSR number */ + switch (csrno) { + case CSR_MISELECT: + iselect = &env->miselect; + break; + case CSR_SISELECT: + iselect = &env->siselect; + break; + case CSR_VSISELECT: + iselect = &env->vsiselect; + break; + default: + return RISCV_EXCP_ILLEGAL_INST; + }; + + if (val) { + *val = *iselect; + } + + wr_mask &= ISELECT_MASK; + if (wr_mask) { + *iselect = (*iselect & ~wr_mask) | (new_val & wr_mask); + } + + return RISCV_EXCP_NONE; +} + +static int rmw_iprio(target_ulong iselect, uint8_t *iprio, + target_ulong *val, target_ulong new_val, + target_ulong wr_mask, int ext_irq_no) +{ + 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 (wr_mask) { + new_val = (old_val & ~wr_mask) | (new_val & wr_mask); + for (i = 0; i < nirqs; i++) { + /* + * M-level and S-level external IRQ priority always read-only + * zero. This means default priority order is always preferred + * for M-level and S-level external IRQs. + */ + if ((firq + i) == ext_irq_no) { + continue; + } + 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 wr_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) ? get_field(env->hstatus, HSTATUS_VGEIN) : 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, wr_mask, + (priv == PRV_M) ? IRQ_M_EXT : IRQ_S_EXT); + } + } else if (ISELECT_IMSIC_FIRST <= isel && isel <= ISELECT_IMSIC_LAST) { + /* IMSIC registers only available when machine implements it. */ + if (env->aia_ireg_rmw_fn[priv]) { + /* Selected guest interrupt file should not be zero */ + if (virt && (!vgein || env->geilen < vgein)) { + goto done; + } + /* Call machine specific IMSIC register emulation */ + ret = env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[priv], + AIA_MAKE_IREG(isel, priv, virt, vgein), + val, new_val, wr_mask); + } + } + +done: + if (ret) { + return (riscv_cpu_virt_enabled(env) && virt) ? + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; + } + return RISCV_EXCP_NONE; +} + static RISCVException read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) { @@ -2231,6 +2393,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MTVAL] = { "mtval", any, read_mtval, write_mtval }, [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 }, @@ -2261,6 +2427,10 @@ 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 }, @@ -2302,6 +2472,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [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 }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index bc20960260..821e05d934 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -127,6 +127,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), @@ -184,6 +185,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 Tue Oct 26 06:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50498C433F5 for ; Tue, 26 Oct 2021 07:18:12 +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 B6E8860E8C for ; Tue, 26 Oct 2021 07:18:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B6E8860E8C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfGio-0007Vd-T0 for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:18:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53216) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBf-0003Yn-QO; Tue, 26 Oct 2021 02:43:56 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:53775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBZ-0002eZ-2Y; Tue, 26 Oct 2021 02:43:55 -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=1635230628; x=1666766628; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=YalgbHXxM2191ElR0bM+PDks8VpaQ7psxsle5UZzVnc=; b=OCrCAbtzjrzYSGp5B81bCWmFdNR1CnSa4MmbnlyyjVMh6Fv1wEzZ0f7S s0q/gk8Xyy5pK/u7mbktx0Ujf6jNCRSwjRXEvp4GHeGSItCNTIWYWTlY6 zzpO0lnCxnlL6i662vd/Cz5dxBKke0r2H61B7dLC4M6uIuSzqA0egFg1s WY962f0U/Z0atEzQt6Rwnn7+VM0DduMMhjNvZTA0ME5EIpuLj866ZJN2h yXF2/oxcwzVhXLrniLWBIPXHdtZ7U7kTC4U+Bk01ycjUKWNcVVrmP2t1c D23ONkyJz8f+AcOea/MmAXOCLNPn2GFtmD7yTHj/Y+IQubVsLOmIzg1ES Q==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="287722103" Received: from mail-mw2nam12lp2043.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.43]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:43 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OHR4I2Z4/B43mfI31Lvmaau2//yliWo4cN9oI6Oeo47aX7gBiZHF5f0nPrBp68dcITyv8NxUX85spxUlgUw7NT0v6WaLcVfIXTC01VrwXlGwFfEQ4aeyttx8zfsTeBYIcCZwdCzRHsCIMqoj4JvcMIs18bzc+ALyfV0kEXCI0oqKky+zznMuwszX2Bs+Mi0w1jvkTj8+ScP7dpNx9GwcbvotJCJryuE1Dbtd40Vg8sS5clUK3g0jzbx8dtOT9qd5os1L8yLwwjBGSZV/T1m2il98lZNELD6ssNzCoCxz6F11szj0adCEilU7S8M5XqH9biBJdhfIhoKQNmbC2lMI8w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OaPYwARyIYVOGxfft2tJEZ9ddwVOXkB243Qumr4i1vY=; b=gN3bCgOZipKtFkWQhNZXxlstwVoGqDQwhsyZWQLfPXTUbSLOV70iW8N+qrCBZ3pjx9ZLnVD2dLRZNALkk9Iczk4YlavpyUlEROIvVbjQfWSnI//fgwbE94nG5mwuQQ2rsCKmOh0On1cBRvKOCYUOei5OlmZ2pIVskxexb1xmS0CsF5LZq76YPGdeaL44wFzIsUanVWQNkMQxfDVmjNkvswO8fByl3ZjY9WsE3CHctgWJwtKehhAwZBfQelkX/XXLMoUc4IotDHe787lJd6NoMZdAcamtVZXbLQ6wqqYI0jcSqp8OLQZZQdI19my6euc1zSBfIiyCSSDVTk/Nx9mBCQ== 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=OaPYwARyIYVOGxfft2tJEZ9ddwVOXkB243Qumr4i1vY=; b=nupiu+CjsAo4nlikeyFXhaqXkf+c3YODSit0tSn5QJLrUieLEN/zUcHd3+inBgWAlrqTFwzFbL34Oqp0HnU60/XD/xN59IVRkfcFoVCNP9smHZEDqXaaGCjORU+1cEAidH2Y39iBF27JPwXAOpllcwxYsLNrRwVS5t2j/rXGnO0= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:42 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:42 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 15/22] target/riscv: Implement AIA IMSIC interface CSRs Date: Tue, 26 Oct 2021 12:12:20 +0530 Message-Id: <20211026064227.2014502-16-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7d6254f5-1e34-4585-31e4-08d9984bf359 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4lGmBn8WmeY2qlZkw67IfIQxwMe8bq5GWQVHekZe/b4ww0HYpIeY2gQzbTk68nd6ONjOL458h2sfBHUfWAigDSFkEHR0/pmJ4uPHeWFyKcmjV3LKEmN+5dVVX+yMHKf4yVw28ttLLu76/IWm1CA8NpAH3agYH4MmdTehBMfaELlCZXJJR5PrKg1I4xU5S/OFSS1rtUGMxWNnW1cwbbSBISipyghrjwMn6b+ZjTKQf3/d5sEDQpqYq4+D/RCS521P+KXkJ80kYzFDLKPUzGdy3OsIKWc62Au1wRyW+fy4Sc07emfnMqEYTvxapJvxk8KV4HeYHicd56lkWqv2TyMVPyVw/wSyes+uDglvzTgr+dWDYIrRZ7Qazn8aleOahk9you6tBryrGnmJjPtk1Zgt/uQh27ZeLKe2kgU1kIKaRYuYVRozo62Cc0BpJRaxaeivsvSgrJOLwLXGsLgVNFqMQntFUHrenZt7n0dXs4PuvjwW1UHq/yiDhubGFPb3w0KSmox3v5qnT7hhQ4gesHfVhxKsEnXYL5vhLl3gV+JXmQBNucYUSABy92qJJHh+X0qAQMQVspxGnC8TXH71lUILfJvEZecR+BvNNV1+5tj0Mk1Ox5m5znihIgXC/Yh/H/Y2rXG8DPKHPwJaAI+USYKuyD326dACzGAR3Y5zjSDDrF2SWO1LKFIfWtsPDQj/lSyI 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tCz8+RAAMKFggEcdSphlCCoYVHp1b/sEJ70vN3a56VB23gc8inTr7sZbwDqfy6vklabUQP46gvPQBIMmKfwsezVOdEOZGesiSM6uFAkLfVbfySLwAQouqimxI8HQhQB1Vz+OQzOHFruf7um/pymMMAIuCEtkEvAFEZNel33f0/4lYqy4+3GGwAr46P6cKy4II2Zr8fi4Ayl/pyduO95780fH2NOzuyvwq85RUq36jn/YyUpSW/2fnjaFTYDmSF9WXuLX1/z5MG7bUHZZHw1O1wyuFOVEFrHel5rBxpOysMhT35JNJtjlbUtZNgsXxHfEi5djXZdFDjTyfgDLSnWjCdSlZntsY/kWwnUqkJILqHPKqo8H8X5Bf3BpJeQTG4f4FLjVsxNcCVGopyL5ZGX8M9eA65+xfBg2oBDPDT2jGykNDx20Idl2gY+NZj7C4uJdk87RsbJJobzmc5MTbQOYgbUNZl+BPfBXnsvUZ5JBR39gig23ZNxrvAd/R31xp4QHNnFfFan6XrJmU3BtRoC9D7+tkT1dUOaNtS4kwfJIvi+OpflM9u+7U5QSYp3onfAAa3PnXxJdGSVvFQTWCBGTNJMwsywnZBTq+JfkjlRjqRHP88EoJFBDc8CcRrumFaQR7YTJ6AFk7lAJHM0Dfnxdoa5M62HflfLX4v6m5NS0mjoZdvJCOvQTaaAbLWyDYp+WfgoXQnKA0BfwnjZRg+uw6aFqbWP7kfgCbBjSaRuptgXbBf1HvioP70PIB/bHcbIgFX6JgBMZ0BQ/KDEcKpA9lTfRu5KUAq4r2PQo25txzQaI62+xG1xydybz1gohVrz16EYdUGzMa1J/JC4hvOC4N9wxD720AyMICFw64JTOhGIKNtDc15aGQ2OcXMnsNQThUCdp4xP/Z+Q9YrFHsbb7plIr/QW9LWlk+M6E9FFPJXxFPABIQiOxGR+anYRp0kWW99GSx5SO4TknRqSfOkRgjTYZ8pdUIOgyyzYwDvVnmuXGmczjLP5Usweq3QHdYnV1YM0jS43tDdsJ5nJMwWUMwd9GJyZytEfbqV+X1EeuhS4jIiJA9B9CN2cBYfHjJElrenPNbART3x+AlfGIvhf252KnK2ceK94CKohlpMO1gZOAEiPWVtMDg1y1cFSH9QgwO6EPpzSd3WbOAu3c22Pd7Mb+wmMtI1VBA7QxBfv0KWNWbvsBOfsUaM66pO4blsHdeDJL3OpptQdUq4Zr5GZiAy6WuP5rj8qpYFiUhWk3rNANGnmL20czfnUvCa81mDyaRmpur3qyrSQjNaYzm18eBR8dNZO10LuhDQUTpqqRzmxdifU1r5m6xUBKOo+0uAOISvpqGWOeS/0PxyBinWSJAcyLxAOB6jo0YcHRwysWjqtT6EwmdKQy7Y9J+FRFiRNwH/4XiSZMmwFIflwJqGZCRCk/+KFqiAST9uBGi0TcIqnbhgZvpregS8sfuUo5XuPPFs//m8zYSUBIHT3DYS2/ksEnU0lwWMPobUNWohMnhHTKg3mBDemxea8InDQI/cObrwtonSKNJBsiUtR5VR4sbheoFBriKE5SCJOZsgIqOBKADvoEthpBl/KNpd3+NaqxNwkt4pB4wKQi2ElRYQ0k6EHYYdeH7v/4P0RmC4G/VhA= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7d6254f5-1e34-4585-31e4-08d9984bf359 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:42.5012 (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: jD/1QaGGSWSjZ+g3U5cJ1Dtb9eFfaKfjRO2xaAplfxYotnbN14LyS6UYkdfJAszINyh83q+FHsT0URDCGugztQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification defines IMSIC interface CSRs for easy access to the per-HART IMSIC registers without using indirect xiselect and xireg CSRs. This patch implements the AIA IMSIC interface CSRs. Signed-off-by: Anup Patel --- target/riscv/csr.c | 199 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index e72220fd0f..19fe5b76e0 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -865,6 +865,16 @@ static int aia_xlate_vs_csrno(CPURISCVState *env, int csrno) return CSR_VSISELECT; case CSR_SIREG: return CSR_VSIREG; + case CSR_SSETEIPNUM: + return CSR_VSSETEIPNUM; + case CSR_SCLREIPNUM: + return CSR_VSCLREIPNUM; + case CSR_SSETEIENUM: + return CSR_VSSETEIENUM; + case CSR_SCLREIENUM: + return CSR_VSCLREIENUM; + case CSR_STOPEI: + return CSR_VSTOPEI; default: return csrno; }; @@ -1016,6 +1026,174 @@ done: return RISCV_EXCP_NONE; } +static int rmw_xsetclreinum(CPURISCVState *env, int csrno, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + int ret = -EINVAL; + bool set, pend, virt; + target_ulong priv, isel, vgein, nval, wmask; + + /* 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->aia_ireg_rmw_fn[priv]) { + goto done; + } + + /* Find the selected guest interrupt file */ + vgein = (virt) ? get_field(env->hstatus, HSTATUS_VGEIN) : 0; + + /* Selected guest interrupt file should be valid */ + if (virt && (!vgein || env->geilen < vgein)) { + goto done; + } + + /* Set/Clear CSRs always read zero */ + if (val) { + *val = 0; + } + + if (wr_mask) { + /* Get interrupt number */ + new_val &= wr_mask; + + /* Find target interrupt pending/enable register */ + isel = (new_val / TARGET_LONG_BITS); + isel *= (TARGET_LONG_BITS / IMSIC_EIPx_BITS); + isel += (pend) ? ISELECT_IMSIC_EIP0 : ISELECT_IMSIC_EIE0; + + /* Find the interrupt bit to be set/clear */ + wmask = ((target_ulong)1) << (new_val % TARGET_LONG_BITS); + nval = (set) ? wmask : 0; + + /* Call machine specific IMSIC register emulation */ + ret = env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[priv], + AIA_MAKE_IREG(isel, priv, virt, vgein), + NULL, nval, wmask); + } else { + ret = 0; + } + +done: + if (ret) { + return (riscv_cpu_virt_enabled(env) && virt) ? + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; + } + return RISCV_EXCP_NONE; +} + +static int rmw_xtopei(CPURISCVState *env, int csrno, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + bool virt; + int ret = -EINVAL; + target_ulong priv, 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_MTOPEI: + priv = PRV_M; + break; + case CSR_STOPEI: + priv = PRV_S; + break; + case CSR_VSTOPEI: + priv = PRV_S; + virt = true; + break; + default: + goto done; + }; + + /* IMSIC CSRs only available when machine implements IMSIC. */ + if (!env->aia_ireg_rmw_fn[priv]) { + goto done; + } + + /* Find the selected guest interrupt file */ + vgein = (virt) ? get_field(env->hstatus, HSTATUS_VGEIN) : 0; + + /* Selected guest interrupt file should be valid */ + if (virt && (!vgein || env->geilen < vgein)) { + goto done; + } + + /* Call machine specific IMSIC register emulation for TOPEI */ + ret = env->aia_ireg_rmw_fn[priv](env->aia_ireg_rmw_fn_arg[priv], + AIA_MAKE_IREG(ISELECT_IMSIC_TOPEI, priv, virt, vgein), + val, new_val, wr_mask); + +done: + if (ret) { + return (riscv_cpu_virt_enabled(env) && virt) ? + RISCV_EXCP_VIRT_INSTRUCTION_FAULT : RISCV_EXCP_ILLEGAL_INST; + } + return RISCV_EXCP_NONE; +} + static RISCVException read_mtvec(CPURISCVState *env, int csrno, target_ulong *val) { @@ -2400,6 +2578,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Machine-Level Interrupts (AIA) */ [CSR_MTOPI] = { "mtopi", aia_any, read_mtopi }, + /* Machine-Level IMSIC Interface (AIA) */ + [CSR_MSETEIPNUM] = { "mseteipnum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MCLREIPNUM] = { "mclreipnum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MSETEIENUM] = { "mseteienum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MCLREIENUM] = { "mclreienum", aia_any, NULL, NULL, rmw_xsetclreinum }, + [CSR_MTOPEI] = { "mtopei", aia_any, NULL, NULL, rmw_xtopei }, + /* Virtual Interrupts for Supervisor Level (AIA) */ [CSR_MVIEN] = { "mvien", aia_any, read_zero, write_ignore }, [CSR_MVIP] = { "mvip", aia_any, read_zero, write_ignore }, @@ -2434,6 +2619,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* Supervisor-Level Interrupts (AIA) */ [CSR_STOPI] = { "stopi", aia_smode, read_stopi }, + /* Supervisor-Level IMSIC Interface (AIA) */ + [CSR_SSETEIPNUM] = { "sseteipnum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_SCLREIPNUM] = { "sclreipnum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_SSETEIENUM] = { "sseteienum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_SCLREIENUM] = { "sclreienum", aia_smode, NULL, NULL, rmw_xsetclreinum }, + [CSR_STOPEI] = { "stopei", aia_smode, NULL, NULL, rmw_xtopei }, + /* Supervisor-Level High-Half CSRs (AIA) */ [CSR_SIEH] = { "sieh", aia_smode32, NULL, NULL, rmw_sieh }, [CSR_SIPH] = { "siph", aia_smode32, NULL, NULL, rmw_siph }, @@ -2479,6 +2671,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { /* 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, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSCLREIPNUM] = { "vsclreipnum", aia_hmode, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSSETEIENUM] = { "vsseteienum", aia_hmode, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSCLREIENUM] = { "vsclreienum", aia_hmode, NULL, NULL, rmw_xsetclreinum }, + [CSR_VSTOPEI] = { "vstopei", aia_hmode, NULL, NULL, rmw_xtopei }, + /* Hypervisor and VS-Level High-Half CSRs (H-extension with AIA) */ [CSR_HIDELEGH] = { "hidelegh", aia_hmode32, NULL, NULL, rmw_hidelegh }, [CSR_HVIENH] = { "hvienh", aia_hmode32, read_zero, write_ignore }, From patchwork Tue Oct 26 06:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92185C433F5 for ; Tue, 26 Oct 2021 08:00:01 +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 29A7260F22 for ; Tue, 26 Oct 2021 08:00:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 29A7260F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:52364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHNI-00047S-4k for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 04:00:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBh-0003ZD-LD; Tue, 26 Oct 2021 02:43:59 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:53779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBd-0002p3-CD; Tue, 26 Oct 2021 02:43:56 -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=1635230633; x=1666766633; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=EjStFy0Uux4hB3UssCPVRcOfhMK4l65TuN0t3V/k6aw=; b=o8637q5ZpAP16vpxPpslE0Qsi27cHubDUgixge+n29PCplo2xdorPe/t u3xekIdy7IzOIaOR4VSXMhDzGU8mHos5ZZ4eL3cHFR9nfDI+eij4PDdHV dEIFv7c+Ibnf/ysXJ0umXHtpKxyyTQU08lnW2cJatkr7o/PvTQ2YqSi57 OFvHlqw95BNv8gxMWO7CE3TamxNTEgzn/kYHaJFqCFRX6RL7Wy570RK4J H+7CV7Olcfkfsl5Ky3vHmv/RQWgHcl4MsxEpx3ieptvqNSLqRzcN0Kb+D bvc2/ES1/fGh3GUnbHjgP6rSkL+xiKLO6D4bGf/TIcKCGQdIfuQgvSLim A==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="287722105" Received: from mail-mw2nam12lp2046.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.46]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:46 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VuznaVq2IF2hk+jaRT8WLJl7L8ohfIadxdx+M6mDZEXN5dahw/uciHz1xm7cUUXiCX7Fp13Kg6xWP48DwCkjBdHvlFjkEkrGII+AZ1FsYm4VAqiNyoDmgJzYTjhE4UxLmErppljPNGK7VA58+28QYvygw9yKyfgpH/MVelZYmrkNEo+MDGvFsrSQr8B4fvJX/xWdykAZCR3rxHolm4kIxoCg4PxGt5jDOLhnxqtQ/MPOVzQWmXJkYM+U9IqFm0k7pr1s0B2FO1t24GXtZwq4/i+8cjcHOA3eGvkEeSLHFHwRIEouuZHSFip1gS7YqexKbk72PJO+U80Ucb8M+/LCyQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=w2P+Ws87gYa9iglFTyQoBUGbeZ0MQP0XcyniCqROoYw=; b=KTeeXMZMfxQ6amyqeYzvGcM9suJoxqNolkzZYuO4EfiCkcgjWr6wgfcVH46JaZYaKvqUgDiGPjCW2R1CI3+10cGFqjhvUHs1Fqi5DyyrzX22M0lsW+AtUlhQsxZqZwga0iq/84npxL9Q6HMYD34u3j+9Llh7FS7tW/jZufEfVD1wqHWN+78JKk0Yz+LONy+e13G7s79yeXWgKgkUQRIzFo0Dq6GYKNFcODbNbwrZyI5D+gQze/M5WmmKkUx/c1POAWr3UiFFUooXylwoptXtFHHEYybZ6zvbb63rX6q5VabgWhafPKVbWChy2RZT2TlTUlC4yfn4cWDXX94JSF9VNg== 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=w2P+Ws87gYa9iglFTyQoBUGbeZ0MQP0XcyniCqROoYw=; b=AyUVx4ojnK0YF0ThydlMCDkWLxNfrCpaGJBZU0ecVWscKx+0J+oP8BdTR/E/E06sIQXQO7IrIjZ9tmICuXPQzVvyS/+SvTTjbwXz6U9GXBM3VavG9wYFVp0LlV02YsIFwPUjQjb1VGAxumupOz5fD4wvOUOf+uHSdonnUBJrfic= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:46 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:46 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 16/22] hw/riscv: virt: Use AIA INTC compatible string when available Date: Tue, 26 Oct 2021 12:12:21 +0530 Message-Id: <20211026064227.2014502-17-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b1b9f91-a7bc-4695-ccb1-08d9984bf563 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:454; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d4GI0y9Haj3os+PK47pppCvlqa1uITuSwfXV8ljMUrsIP7VZ6KL/QYea29HZ9eEHgB8cdulBVb4ttwZ5nxc2enydEaqM0MvkiYXSDh4NA9QoVsVgItZuF71eQvFSkVm2ujrfb6FDggC73XiN7v8lV+LzByG+1zhMJKG92Dq9g1K+G8UWMgRjbgOBoVDkEkXOtOry4o1eRRxdFBdY7/vbDUs66N0iMuEspKRhGo/uUya+tJot2plQ1Yi7BWjaV7jGwIGCjsGIJM43SqpQPdfLaU9xoM8s6p8D+HJe2AxIhe4t123p84alx0eJYXAtWbyuR1r1mt/cU3QJdPom7sdNtWI17QUt4ZvHGvrT94tJHKRuLnRshBrdM7axZW/xDgfSaQFWkARPOQpSUWKdqULT2QHSjpyR7cEvf/zWVxZW7V+32Sp4R7ZLdAQ5psuvN0UEz0W6nC7Y+BOxj7UaOL39U6908GjlUC0z2b+rzGK5b4G6mjYg4CiDX7TDL1M2iXtGQXQcAG0UIDVXWGVTM+D2pG8azGcBuJHgTLJKtj5mwGUTzF/ubPIRnRCNgo99T8IoOLX/ExMDRbxsKevKF0gGXXi9LiZdrqIR9sPbHkunY+FRb317npU6Jsp9wUCDM3Kgbr9+BiVpvz48NOMCkW4pWki1iy5jWm1QloDZdMuQ3EnWQwY/b+fKaHvNMQEgZpBC 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5RVr9GVLeSiynJa2+/OHpq5n4DIiS9STCFcgYhl37RAIFXkjle8Nh3HnywOfpgQEAfuAQK/4brV3tQ/tTviv2VKWK6cryosnpNN72LPgm87KMhJWxWu6wzzuA3gpygkRybr82SDR5A2GK7YvqEoVz57L0VTFICX+Q+DMlTfHiBO6G0pEqm6HPQ2Iyz2nj6AM9UQYKojwlOyMXFnFr1ZhJcdz/6zoQf6M83GeaxUvQ8nMoP3dG/z8F027SuyvF03Xj9VD5aTRrqY9ZYS63wMGhv2/0UYUhul1JohbgmePAxc3EAGUtlDij0vTy6CNxuTs7naOUmuTwwfDBwZKJMUQz/g8eD1Uj9U+JQPrVa0WsOXUwYfWTncbGuIr1Ys/YwmKuknQ3sjdF0QG4STH/RtfBCjM0qQpDbeO8K3iHno+WM2ZQj+FdGjmejlCj8ffHL2jqtsvAZq06ZJYro3BKgdlefv4LtKRLsZixsibPGU8504HmPoLW9ic4haWx3SBgXnUIyLzEq784m952De/yIjYpFwrnHvSq3N/v07X49CVlsdqGW0rfNAaedVLKThzG58UzDSndMIbz9BQtSrKT5JF9N1Np9W65y+i2x3s2b1Hr192sKdSJw+ZAJurFQwLTINjr35u5hJ6Me9Xbs6Kf9nNWQm3FbTS6+EPtmgpW31g2i31P17gRPzbcoOg+k8LTpcddjFig8jNDkns1j5BRzcJT1axr0BIZuKfiJqDGtGV2ecmKxdpBGEOjQ6SLYHNX9R4UT2QmvqQ+39KdvdfYtEkN9T90CsYTp15pIkHZ07VifzaAkHwmjxqIZbn1oJu1t9x8IBMofsXMgKim57lUmm1qCiH6oeW72FhFZu90HYllcAWWbzQTSHINgFAI+JDt62Tv8vxXqHfVRdK9QuQzRzJC5M3ryNm9GSiqMExF5J6Hg+2cJjhdJPPff5zH95JStuc/PvlD4sbn4z5AJD6LVCE20W1akQkAeAihqmzt5NgHLl6aHj95FxWa2dV8z0drHcfE3awuty5tzlV2PvCy1+wTEnu6SPbR+utA+oN2B4GzORIRPLxBqkhzyroA0h5BczdtXWBfmZB0ZzfC9QN/eNXXGT7LSLEakqjeXkDHXQMPRcqf6j6iqHxTu9TE8C25Zk7BprEtEWQt8cUpfcbND30YjyIwpCo/k79CPF3PrZWyRtIW1Qtwrw/XvxfgRBO+BDp2/WZbaTjJrmluoZqpr83z015qMu7gDl/OSCDFkU7r4APP6Yos8OXQ2afpzkVvTLjFHcjyyRPHvOPipYywCD3A5IQG/1miL6M5YS1yHSI9xo/XZEpzbNtAQnfA6oC7z3OPDTlfRaJ2D6lCTsjsHbfLe7esLODqddlpQX0n+VmBeHft8gdze6XhdUedzlH1uw9X4m4AC0H0zITqPJcF8TRrMskLPcuEF0IEzWZ5Ww3nto6CaL/bN796SczhHi3zw+VjX2rghAP7fio2zrFmWTdrtq6RsPUodjpEwD5TDIyc+rvzk439AY8DWVdY09P1YzGnYEfl/LAEXBkr/TtqpbuH1p1Z+vZ+K0OFCnf1bhRS8kyq+ap2Im+AXgBdMGZhd5fhfkWwIarpzsgUgG/pT0DqiJaoHzXE+OEv037M+nrOko= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b1b9f91-a7bc-4695-ccb1-08d9984bf563 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:45.8733 (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: xyRLxHTGABOv7JOy6qo/H5uVY+vOMnaogm2DUtASJCVPBF+ATvD+anexoi9+Jl+9PPElRIJy0BFZysCa2fD3UA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng 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 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index b3b431c847..83f784bdee 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -211,8 +211,17 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, int socket, qemu_fdt_add_subnode(mc->fdt, intc_name); qemu_fdt_setprop_cell(mc->fdt, intc_name, "phandle", intc_phandles[cpu]); - qemu_fdt_setprop_string(mc->fdt, intc_name, "compatible", - "riscv,cpu-intc"); + if (riscv_feature(&s->soc[socket].harts[cpu].env, + RISCV_FEATURE_AIA)) { + static const char * const compat[2] = { + "riscv,cpu-intc-aia", "riscv,cpu-intc" + }; + qemu_fdt_setprop_string_array(mc->fdt, name, "compatible", + (char **)&compat, ARRAY_SIZE(compat)); + } else { + qemu_fdt_setprop_string(mc->fdt, intc_name, "compatible", + "riscv,cpu-intc"); + } qemu_fdt_setprop(mc->fdt, intc_name, "interrupt-controller", NULL, 0); qemu_fdt_setprop_cell(mc->fdt, intc_name, "#interrupt-cells", 1); From patchwork Tue Oct 26 06:42:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4C0BC433EF for ; Tue, 26 Oct 2021 07:23: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 2F2FA60F70 for ; Tue, 26 Oct 2021 07:23:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2F2FA60F70 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:46666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfGnn-0003lf-9U for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:23:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBh-0003ZE-P9; Tue, 26 Oct 2021 02:43:59 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:53782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBd-0002t7-CZ; Tue, 26 Oct 2021 02:43:57 -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=1635230633; x=1666766633; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=qesbuuEt1k5lDjm2lc3GrA5LxA6lJCG8dTP6OBcwp/Y=; b=OkCySlEx7ttdZic1k3D9XH2zqnBe7tFcgYGEkRlirJmowTUZFKR9S3Bt duxzYnFt/p4SzFXD6dciwP6cWjXCylWWQjuJsHgK3bEGProf1CEiheTS2 aHv6IYV6Fi8Ce4V3ysX8lEtI9H27vVFzo5CPyWeq6LNbOOf1OM9vtl1nb KMiTIwwBerE+Cm6p8lkTQnyGTY5objsxI9dBzzH9lZ+SNKy6SoogRw9jG Bmk5TIPYPtpy5tC5qpL6N5m2Gh6zpM/EdEiUNT3BBoS5m8Nx1x20x36uy mdbO3uegxaGAnQSK3u5kuqNDgcCP/xtewegJWkjviRq741/6U49oMTGs0 A==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="287722108" Received: from mail-mw2nam12lp2049.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.49]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:49 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BDU5Dp/Lr1mnazbasFXoW4Yy2UTKWQ2fT+XXKpmnqCDPHjqEmTz8nJiQJe7KxuCQPJm6tMfvinzr2cus/tnIgNVSLcqW09PYBtJr964mW6oK/Dcd+DJus2U6qS9c55PydrT3FXG/lvSdrHzAncQqEl90DCBbZXzNXigZsPDTJu2t7KDkt/ffZHitliLxyBAJrLLewpgrBw4caA/ZoHRBVTl5rFs4yU0vA33+OqQMWywc7Dw58y7YClQXL+aefTxZHQNiSxG03ElyMJsrTH1nM8EULYcdNR1x13e7NJFFzrZeMyMhe7k11Kl9J9WwQozog5C7HhWNgC/NrP8HlcMUrQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L6+yJR5Zwh4+dvBJqZcHbxy6tL2JticSalZpLVSsgnI=; b=XM+/n8MWOgDa5rv3XpkoreVqfxQLGi+oUxO0jbtaX2LIXzebL1xyT+9R8vIBlOhdEPWeR+xWufvsTcM1fCxgbVeM6Y9f10eUbqw4aXoDzDqUhmnYh16jRR+xGOLFusqg+s8CJz2VuuFt/dMBfh/DBsoCY8w1y104NGIvoQ5HmK/WiK2bKGAmoYxMFA1pNPSSsSIpmYF1IPdSVVeLoZnjLCkbu/xOyTEODuDCh5152hN/UfamgKJAyef8AmNqTCbcTXbT0cdUVd3mBa/NDxicvc4eYA9yjklQedKxlSPum2dywi7tBeCDt1BOMXjd7HdPwU28y1UvxGy6ceF17oouIQ== 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=L6+yJR5Zwh4+dvBJqZcHbxy6tL2JticSalZpLVSsgnI=; b=obJajwubqrJIVDnKkjuVZVrA0V0vFcLKijpJBLA4G3/MVEcOJlgDZ0kcqQQZ0VvP5KcBrk7H7iiKfbEe/3uXcx7fUMPr6y4+y8PGG/GDBIoFtBjqGhhy1CWjzzHG6XTXbTPAn+NGUVdLoQrsapHEvwUXP8L5ldBMF6D/M3RfSO0= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:49 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:49 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 17/22] target/riscv: Allow users to force enable AIA CSRs in HART Date: Tue, 26 Oct 2021 12:12:22 +0530 Message-Id: <20211026064227.2014502-18-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5f255614-ea6f-4ca3-eb84-08d9984bf757 X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:1850; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bKqvam4LbBAlf6vThb8CVV47FV0pdaJSnGWswenibWEbdgA/DflNaLWnBm6uQ+CLPBp/6hba57ToLefyklTA/TvkB2GUeJC+1QW2UZUnrceA96ynP+HuqVeqEvDwphuw2S74dYQUMkR+8A1W/uu87P2r2vYUhZDHn1PGUoDz5Zr+MHy++qWUmuAaZruVUmXEH7hw9AVFZDsONx5tAZTRbexW9OSM/VTJtcjGyuwa3aLuUPJEoAp/m1y6cZp4fRVc28Qi8hgMT9/lEZtp91PUks/fPSmIL71x5ZrwVO5WOI6Svt1ppT7qfBa96pTJfEsh/xrwxGwrWyeGUwkpCFjqmHgSDIEYBASseavRLgHbSIzIoz33AWIqB72FSZ8vxTqPkoMLQjxph+zjCUiEpITIzPB9J5TVacSGLCy20dNj8AgWz67mTgVPeceO4BjQjgn/eYv9J867oJBviunpx72RIlk86Zr2q4ytpxawcdSldYgkR0wY9/60Wk9PBlps0AMUb5pJcMOyHFh+Fc5TA7hoU2HmxXgLxkIeRIiSVKuMt78zRmrYyMFm7fB6tzcD/GNlZnkl1pXhyt7jvG4tUnvbCAp4TYao9vWfcaN98EDMVwHAAtlzlnCk3zZCvYGlXKGkVpMtHDu4CJIV8uc1d4WfImZwN4IFc/dELwXA6j9r3mWNXBNvAt2tJXfWovC1GFYI8f/AhuakR95CtN+Bjrp44Q== 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4eyjONkJqbgK4t+JAlTON6ljzo3kHEK7jgGkb/MsV98H2DVLcfCA8DtuxR09kC8GEiTbVNmVTd2wnkyGFNv6j86GD0rTOksnzhU3htThDRTIDkiXIf7/JqeQV6S4XJtA3XRcCzQLSBJe5OIVtZWIlWRjoqB123M8mQEOxt4+NxLpv2NZyQdTPmk6rOE2TQFA5vtk1IV5loJOUVzJPrXgztRymd2YQbSj+ybsPP3yOj594tE22JjTZIgcTBWqxFb9IiyAKyMCw762MxpzWoye6/akp5c1jazM7eTQHQOR8fUQnUfLjG1uNoJ9G+PMSOjP8ape67uULuv+cK+rD2LECu8dLR5emV0o5OCkFpF4qc3b0dUGp3AaFljB3rNWraQZLm4tG+/zbfs7tbdlsjakEQWPmF9OxP/7qvGIC58HQP8d7swyz3gLKQH/mOSX5OwLLhSLhzKW6kyvhmpjcIYiWB0bH8Gp9wLcNIfMLjOqZ66kBE/HnIedJKfQRimgyc9Ma3Gtql0IYjXNANLcLCv6pGqQ+Hf+mDS+W1a+u8PIBYIwranXCm1fXwyrvRLAa1Oyj1mx4wCW+kOZ9hRH7vAJSiFTD5qjZvvIbPw9YwnHpv7Y71sZfCOyYogE0ulw/mCaQAcw8xYOJ3ghTfjyULtLEHBwLqirn9/FuVP6fX5naroHF3YBjjaCPMYwZ02uSqs11O/YzM8zonTP9NC1Ye2d3V9w/nEDxUAKBFm5KIv7oHvMPyPdooyw5TCzTZBbpAhlwft7lGAbSpNzEJZ02RWtqHg92OcHBoB+AiGg/WFZ0JNj8QB2b422kHifRwEt833zBDbdq0sqsJaKnb3SUoVPf+YukETgxmSA3pgg0vPFWuFjh3kHbZid50hA9LlsZ1X+g9WIRq5pa6THVEe+D5qka3mK0iSKND7A85/WEfNea8mAvJF9rkz4PSGQppjRaZR3ZjQZlwgIQiXPWyUiYgrY1AcrRJusBg9CxerPlqb42rvqdsZmhzjvRB/hQjmAfGXELmwMlCqCZa/s8tCKe0CJ1AoneTJ7m3QR4h8Bc6nj5sr2WAmuCb1mUy+iDBMgoYBl9PcXmFIuodDhxsGv1GcMkJPQyeTfW05ZnffeC0lMtbP7sqC2VR4g6eOM52ei77Qh0u+1jWWgB6hF5xjMEK5ypJtdGPvpMnkowkW5r5RM6Pqe/rvyHXu35RtirjfFgi9cV8bTu7cnX0D07DSqsQB4T8jPHk4o1fbcMgnHmZQueCStweZ1NR7/S6EfLG3Xdzit9nvkUaEr2URWzMucZrlcXRcZwZS1qXlThNpqz8nUdg9RK7p4pGJlsc9r6rOfFqSmikIm/UYDheyBQG8+AR3xaIKLCt+oUflq5jfFnoGR35J9lBDVbm62Lkly4zrrARTwInvD8B3vIscFjfKyvz4w4eb35hID7lIDsDCcKuS1joUzoJM8z8cWP3SUX0IOPnI7BUuAXRQmVQqbSsis7TkfjN/oFAEc9YrCCwsxKvAcYrbz+AZifwvSiXgu6ahgLB9I/fZIXQey5moRqb2fH+fiUwEZbg88GHVtjX6Y8sRLLZu0TrbTQYbLLuD7uV7b3N2Kd6jwvg6wm9lmaKd1EMo/d/EJhFNEXU6gwMrHWvfHe10= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f255614-ea6f-4ca3-eb84-08d9984bf757 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:49.0892 (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: vBie3mpRf3T+qUOsXzhrCg1J1rZ1DAnNqZ00QFEtHW5AsRGpL3nU2n8CcPaSSc6VS+wTTsieNMDjs48p+IplBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We add "x-aia" command-line option for RISC-V HART using which allows users to force enable CPU AIA CSRs without changing the interrupt controller available in RISC-V machine. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 5 +++++ target/riscv/cpu.h | 1 + 2 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 0006989c39..d88a2bd766 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -454,6 +454,10 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } } + if (cpu->cfg.aia) { + riscv_set_feature(env, RISCV_FEATURE_AIA); + } + set_resetvec(env, cpu->cfg.resetvec); /* Validate that MISA_MXL is set properly. */ @@ -676,6 +680,7 @@ static Property riscv_cpu_properties[] = { DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), /* ePMP 0.9.3 */ DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false), + 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 bf688eb1ea..b7a9506544 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -340,6 +340,7 @@ struct RISCVCPU { bool mmu; bool pmp; bool epmp; + bool aia; uint64_t resetvec; } cfg; }; From patchwork Tue Oct 26 06:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15AB6C433EF for ; Tue, 26 Oct 2021 07:54:43 +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 6232F60F22 for ; Tue, 26 Oct 2021 07:54:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6232F60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:38266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHI9-00030P-Df for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:54:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBn-0003cx-Ub; Tue, 26 Oct 2021 02:44:05 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:53201) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBf-0002tM-TS; Tue, 26 Oct 2021 02:44:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1635230635; x=1666766635; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=gOuqDFIv+r+JoUY8NfNizEmuiaC23InLTOFTKwu1Z5I=; b=l1kndouQlskWu3ARTyBvuIFDrbTcPTJ5Ho3/xR/QqXPCbTClfnsVe8VG ViZWc4Xs5blZ9xUV4CmsN9M4pvHpZ+jOiO+LONsGOGllYiF4UfdxwTy4q YYoAZS2zYWhatZvgJLYFjBlgQnzhBypwNgANKl7p+xS7CXCaySVKIxZMM 3Hs6gJLSA9+2C7VYp/+8yvg7AOTbF/RdZwPuLmR3auma7iahM1udsKCow cflP3C2dK3LwewoHywuJuOAXxN/DcVQFN25adiB8pcA9SB6ZQm1nNfaBh vgvtNiKNqRqOo0RfBkYgLmr5T7PuNf95A/iVx0XbKn6FvxhL7Uu91SJET A==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="182854790" Received: from mail-mw2nam12lp2042.outbound.protection.outlook.com (HELO NAM12-MW2-obe.outbound.protection.outlook.com) ([104.47.66.42]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:53 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BjJ14i2ZTrP8v7HIv4AGdYqQWX4D1nRq5T/aZyC2z91dr+mrlQoiU6XwnnH6uautwn/P6O2uLkV5qFTIDCasZrM4HfM0hbmwACci37ZDFj6vTQ30UOwiEHwqTjRgoJrmC6DA0LbJh1Td3RTHbMDIxk2d4zEmKGiJGtnLc5vzV64Bz/Cmn92oSubbcl8FjWpVRfUQud4NtsaNKOtVJCTz0vT2VNnqNGLrQC6efyrKuEkKj7xeO27j8ZUUh5FUa+sS4edYkDZuR39HYc8bjujhoPYD4VufCyoeGmDsesl4obCddP00MaXxYcve1R2MSaM0Tuls2vQIuPQn6CZuwJ51Cg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2C28XhQx7YeXAC7V5RJ7Z3nV30V4CzoGYD4VcOwMwfg=; b=EDLNFPaVDkJu+r04mEa2NgIW4TsqWS/bJ3x3yre3XW3IsmDCjiUM+D5a3gcliWtM3lyR7m784V4DGElUo11/1An24KMGAyBAq2SRH5PPqMxtj4PDDXOcTg7ljQlQW/SCv7fBWZ3fiZxZGC4hXZwWAHzwZJH0/bbMfQZwOf+yIKJe1eu1MnG1Xa174CM6y/2a9RBkFwGCx++Z8g2ZbAtvZG1PhZ4I2VNio/0Sp+3N6VfErauVZS15l9mKi2vC/52XV+KHfyE8a6NQoQVHNjfj41+Jxn+6lq/iRkaR9A/bxa+nRl5+VuSHh0oEtWh3afEnm3ADmnR4sVbt37omo+YuIQ== 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=2C28XhQx7YeXAC7V5RJ7Z3nV30V4CzoGYD4VcOwMwfg=; b=pJlWCQl90HAkrtjKuB210kZyoXIZFbkaj7YS9kLZsBL3FaanirDI/fIiaKAyGrwSCqZr2e+4vWCfa8e68AVfgS1YwY9BWCOghUV6tiMRbNu5i+Ts01f58kcDfcLspsJRVCmI/tww7Ofd6yY8Q3KJav4YiO5yJbPY/W5RUHtwgrI= 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 CO6PR04MB8379.namprd04.prod.outlook.com (2603:10b6:303:142::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.20; Tue, 26 Oct 2021 06:43:52 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:52 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 18/22] hw/intc: Add RISC-V AIA APLIC device emulation Date: Tue, 26 Oct 2021 12:12:23 +0530 Message-Id: <20211026064227.2014502-19-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06213b55-75a9-43ba-0c78-08d9984bf92d X-MS-TrafficTypeDiagnostic: CO6PR04MB8379: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:313; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NwVpiq5VFoJeVcmR+JBJPDTXqfxAkRSJ996WT9JqEey9/Ks5ak7NZrDSCDNn2gQ+6hcOuePPmlUGXNhUQkgPx1oky/0XOlB4xqHzXMk38XoxXQirKuwbfUN8EIn97rmM65CcRbzZg1/k+Pzk07II/VDAwsnMdp1utRcjl/UD8baxQzagEzfkXtG26NEIDMP/ksyI91wU7zlaFAe5d7Wkj6biyVDKy7qRffb9oJqFM2bD65hv5ZCGYvdY76WXIdtY4kuynUQKze+ZtOJc3nifF9D7kIKIgsHoMJZJtJzr4aivq3f74pggzdk290Vif/OBaqXjuZV05JP5nbGGbzdUmFJ91XT4CDDm4y4LCywfu4OtMDDwr4+/0UOfjyXIScgnglNpCbUeqONhJ8MRdT0d+IwAIj79lKWjYnUdY5hMQSsbwayciQAraPsygON9U0vJdb0d3bRu4ElTILmUYYxIkrqEXOg4r/uRtg+UFsm06V9wOf16a7sxCPrD76RfdMhQ2/z2mVvgDe8IM9aulNLtWsJZsfQvJXEvA0aaSfChCRjzhY2pXExpwm61toheMfAU+wNX6S/v5jQBOo5YWYzvXHJN8sCQZNNRMbnyjkM4SOhI/vhPgmBS1sERXPNJH7/t/ml5pbfzkI0SHg9r6lreQj6zUVJmyvXv1wcwLZmEtKH4Yael8Z+kvpPicm9l1Qk9axjv9Ygwp6AFcPsUQP1xxI2lQztrmncTynuM9nxXHqyUwSLgLFeWD9aAEvAgTpbGNdXQNYY7uzL+jv7Q7TZtRmVRAOn/9SRvjRmfn/kDJgo= 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)(366004)(5660300002)(186003)(66476007)(4326008)(110136005)(8886007)(55016002)(2616005)(1076003)(508600001)(7696005)(2906002)(38350700002)(26005)(44832011)(66556008)(86362001)(54906003)(8936002)(83380400001)(30864003)(66946007)(6666004)(36756003)(52116002)(316002)(8676002)(38100700002)(82960400001)(956004)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F18eC0bQ29C4SfP4ACJL4LdDJXRTKOy70wNIq/TXLG2xi725ZGFJlHpIPchH81q5P6Ds6U1+OB5drUpFKvjahvXOQ4/4XV7WUQDP6il/zL01IYmHeCGYoJf9ssLtv3SCzPquwIdxrTJnmgOafztI7wN1FE6yTIU4Rts9UGUV8j6V22tA4eWhZCW3RgUuGja1IO9Ll+/BazkmZt73qsWVRGZ6j8G0udcJ83PpM08hKN2JbPwsA/q8UCcZsV+5VE8zEcegWm2nl4CVJPl/b5VKLJbUDR08KjZgDZzrserruoH+exnI1AO1I3AEkpOylruZ8XKhWrlDJRluj9ZZUMW5E9r9M91aJoqtSkivOcRVVwbJKtLcXyXmNd9FURo5t2xzsm5UY9SB+r2i/59Ib/H9Ri+urAar7EmkE5JuLRlF48gWvX+NFboncEYzZhb+rORCkrKXcnsnvpvDZbYf0dKXiCwy9YpULqXwHdkmtuS9VJDCVleDwkSTlLetFK/rPXE+ZmiPtCm3NFqRHT5isLcnyIq9y9EbcKnst2EbPLTHF1kNeXFjbogxzR+CUundetI6tO06xPMzdUjxmXmDPuWplCKWd1Ltn4ZAwrSaBaWqo7L/PjRlch2KpfiouEPhPFTYy258svYOYpZ5HMOM4FmZ8mR5B6mp2wkzE+4/TTCHs9vththY36uglv0vmFEFiYIsNxgTtFZCmlzFL4C2No2209jiVLINUr7RXwV0hJEr+84FFWeRaPkEtyQtBChHcVha0/VbtPguFU8Xew0TKRBNJp21gL1fiB+VCRHyWeZGDhx1TyX3RMMtznjfqLDtKjRlOUql/SBWD0VgZxgUClIr3mRH2lxfQ7+Y7T2PEFAm/Xu3Ub+ayJzMmwDa1DchM41IQ1XAT/8vK0EzguDBAeW3xSLWObCt01n1cAur3HKbADJc8Wan4rWXS2aFEGdNR4I4druxHMZ7Bn8Yy7C+45FK1PIBLmoBKThciACNwM5BWD5x16LMEK2KcNNz4GwDlRm3UG8cZCfnyFN4LvqOkawBsnid+ordkcsOcvSmAAka6BoPJBFFHJlEXN1xByx5FnvZCdOeVW8LwEI6bdGE4paJI2lm+HVwxtgt1gRnM0k3AMX0V2Oyl73TORPtMzYaA7fynZLTN1Nl7Tzf0JLQ6jHur+kMU6VkEQAGRyplEcZSGdqgRnJPSWRgW5mmNR7PynqjRfwrT177pGhBSc/t1grBHBgeboWB8Npw7hOozsuJj0zbLx0Ga8hOPvgHRn7oR3zNiGtOTA8kcLjr+2d/9oKpFkPhd1SdvMT+h2sXUJr5IvL1JovqstEDtW3BZjExjm8FwW51l6wrvWXmMY2pQXaUIyoxeZlOubt7rReDG3SkJtNuI2f4R2NOqSsBpt6kUfCA7SWiUl3hrCE0G/LBwOedDn3WUFNEc67jF+EbPlhXhOg0TCeyD+P4fMofphOqMZrz8K4PCZDBO4wOBmE6hT8X1ei0QrBG+gnCslvEejTR7P/K/v4Dy7wyFl4d0gM1Br3nsv+8sXPzJP5ax3eofdaBB9AmwBHUHbtismJIrxlpgYq9wgMo6Zy0TIQsWDgT8qng2LgSsdT/hfCE+WWrqXzwk6Ii0wU6g/NgOI+K2QTSpqU= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06213b55-75a9-43ba-0c78-08d9984bf92d X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:52.3280 (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: ijyY1/PGswOMbmNodCVSf6FlZqD9yiqV2AoGN2D2D/VWT+xXbfEwYepSCXTpJsUbvCJKM92ftGwSfbYr+L2EJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8379 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=9269cd5e3=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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for wired interrupts called APLIC (Advanced Platform Level Interrupt Controller). The APLIC is capabable of forwarding wired interupts to RISC-V HARTs directly or as MSIs (Message Signaled Interupts). This patch adds device emulation for RISC-V AIA APLIC. Signed-off-by: Anup Patel --- hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/riscv_aplic.c | 970 ++++++++++++++++++++++++++++++++++ include/hw/intc/riscv_aplic.h | 73 +++ 4 files changed, 1047 insertions(+) create mode 100644 hw/intc/riscv_aplic.c create mode 100644 include/hw/intc/riscv_aplic.h diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index 78aed93c45..1592623233 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -65,6 +65,9 @@ config LOONGSON_LIOINTC config RISCV_ACLINT bool +config RISCV_APLIC + bool + config SIFIVE_PLIC bool diff --git a/hw/intc/meson.build b/hw/intc/meson.build index c89d2ca180..77b068f673 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -47,6 +47,7 @@ specific_ss.add(when: 'CONFIG_S390_FLIC', if_true: files('s390_flic.c')) specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) specific_ss.add(when: 'CONFIG_SH_INTC', if_true: files('sh_intc.c')) specific_ss.add(when: 'CONFIG_RISCV_ACLINT', if_true: files('riscv_aclint.c')) +specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'], diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c new file mode 100644 index 0000000000..f4b8828dac --- /dev/null +++ b/hw/intc/riscv_aplic.c @@ -0,0 +1,970 @@ +/* + * RISC-V APLIC (Advanced Platform Level Interrupt Controller) + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/error-report.h" +#include "qemu/bswap.h" +#include "exec/address-spaces.h" +#include "hw/sysbus.h" +#include "hw/pci/msi.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/intc/riscv_aplic.h" +#include "hw/irq.h" +#include "target/riscv/cpu.h" +#include "sysemu/sysemu.h" +#include "migration/vmstate.h" + +#define APLIC_MAX_IDC (1UL << 14) +#define APLIC_MAX_SOURCE 1024 +#define APLIC_MIN_IPRIO_BITS 1 +#define APLIC_MAX_IPRIO_BITS 8 +#define APLIC_MAX_CHILDREN 1024 + +#define APLIC_DOMAINCFG 0x0000 +#define APLIC_DOMAINCFG_IE (1 << 8) +#define APLIC_DOMAINCFG_DM (1 << 2) +#define APLIC_DOMAINCFG_BE (1 << 0) + +#define APLIC_SOURCECFG_BASE 0x0004 +#define APLIC_SOURCECFG_D (1 << 10) +#define APLIC_SOURCECFG_CHILDIDX_MASK 0x000003ff +#define APLIC_SOURCECFG_SM_MASK 0x00000007 +#define APLIC_SOURCECFG_SM_INACTIVE 0x0 +#define APLIC_SOURCECFG_SM_DETACH 0x1 +#define APLIC_SOURCECFG_SM_EDGE_RISE 0x4 +#define APLIC_SOURCECFG_SM_EDGE_FALL 0x5 +#define APLIC_SOURCECFG_SM_LEVEL_HIGH 0x6 +#define APLIC_SOURCECFG_SM_LEVEL_LOW 0x7 + +#define APLIC_MMSICFGADDR 0x1bc0 +#define APLIC_MMSICFGADDRH 0x1bc4 +#define APLIC_SMSICFGADDR 0x1bc8 +#define APLIC_SMSICFGADDRH 0x1bcc + +#define APLIC_xMSICFGADDRH_L (1UL << 31) +#define APLIC_xMSICFGADDRH_HHXS_MASK 0x1f +#define APLIC_xMSICFGADDRH_HHXS_SHIFT 24 +#define APLIC_xMSICFGADDRH_LHXS_MASK 0x7 +#define APLIC_xMSICFGADDRH_LHXS_SHIFT 20 +#define APLIC_xMSICFGADDRH_HHXW_MASK 0x7 +#define APLIC_xMSICFGADDRH_HHXW_SHIFT 16 +#define APLIC_xMSICFGADDRH_LHXW_MASK 0xf +#define APLIC_xMSICFGADDRH_LHXW_SHIFT 12 +#define APLIC_xMSICFGADDRH_BAPPN_MASK 0xfff + +#define APLIC_xMSICFGADDR_PPN_SHIFT 12 + +#define APLIC_xMSICFGADDR_PPN_HART(__lhxs) \ + ((1UL << (__lhxs)) - 1) + +#define APLIC_xMSICFGADDR_PPN_LHX_MASK(__lhxw) \ + ((1UL << (__lhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_LHX_SHIFT(__lhxs) \ + ((__lhxs)) +#define APLIC_xMSICFGADDR_PPN_LHX(__lhxw, __lhxs) \ + (APLIC_xMSICFGADDR_PPN_LHX_MASK(__lhxw) << \ + APLIC_xMSICFGADDR_PPN_LHX_SHIFT(__lhxs)) + +#define APLIC_xMSICFGADDR_PPN_HHX_MASK(__hhxw) \ + ((1UL << (__hhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_HHX_SHIFT(__hhxs) \ + ((__hhxs) + APLIC_xMSICFGADDR_PPN_SHIFT) +#define APLIC_xMSICFGADDR_PPN_HHX(__hhxw, __hhxs) \ + (APLIC_xMSICFGADDR_PPN_HHX_MASK(__hhxw) << \ + APLIC_xMSICFGADDR_PPN_HHX_SHIFT(__hhxs)) + +#define APLIC_xMSICFGADDRH_VALID_MASK \ + (APLIC_xMSICFGADDRH_L | \ + (APLIC_xMSICFGADDRH_HHXS_MASK << APLIC_xMSICFGADDRH_HHXS_SHIFT) | \ + (APLIC_xMSICFGADDRH_LHXS_MASK << APLIC_xMSICFGADDRH_LHXS_SHIFT) | \ + (APLIC_xMSICFGADDRH_HHXW_MASK << APLIC_xMSICFGADDRH_HHXW_SHIFT) | \ + (APLIC_xMSICFGADDRH_LHXW_MASK << APLIC_xMSICFGADDRH_LHXW_SHIFT) | \ + APLIC_xMSICFGADDRH_BAPPN_MASK) + +#define APLIC_SETIP_BASE 0x1c00 +#define APLIC_SETIPNUM 0x1cdc + +#define APLIC_CLRIP_BASE 0x1d00 +#define APLIC_CLRIPNUM 0x1ddc + +#define APLIC_SETIE_BASE 0x1e00 +#define APLIC_SETIENUM 0x1edc + +#define APLIC_CLRIE_BASE 0x1f00 +#define APLIC_CLRIENUM 0x1fdc + +#define APLIC_SETIPNUM_LE 0x2000 +#define APLIC_SETIPNUM_BE 0x2004 + +#define APLIC_ISTATE_PENDING (1U << 0) +#define APLIC_ISTATE_ENABLED (1U << 1) +#define APLIC_ISTATE_ENPEND (APLIC_ISTATE_ENABLED | \ + APLIC_ISTATE_PENDING) +#define APLIC_ISTATE_INPUT (1U << 8) + +#define APLIC_GENMSI 0x3000 + +#define APLIC_TARGET_BASE 0x3004 +#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_TARGET_HART_IDX_MASK 0x3fff +#define APLIC_TARGET_GUEST_IDX_SHIFT 12 +#define APLIC_TARGET_GUEST_IDX_MASK 0x3f +#define APLIC_TARGET_IPRIO_MASK 0xff +#define APLIC_TARGET_EIID_MASK 0x7ff + +#define APLIC_IDC_BASE 0x4000 +#define APLIC_IDC_SIZE 32 + +#define APLIC_IDC_IDELIVERY 0x00 + +#define APLIC_IDC_IFORCE 0x04 + +#define APLIC_IDC_ITHRESHOLD 0x08 + +#define APLIC_IDC_TOPI 0x18 +#define APLIC_IDC_TOPI_ID_SHIFT 16 +#define APLIC_IDC_TOPI_ID_MASK 0x3ff +#define APLIC_IDC_TOPI_PRIO_MASK 0xff + +#define APLIC_IDC_CLAIMI 0x1c + +static uint32_t riscv_aplic_read_input_word(RISCVAPLICState *aplic, + uint32_t word) +{ + uint32_t i, irq, ret = 0; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + ret |= ((aplic->state[irq] & APLIC_ISTATE_INPUT) ? 1 : 0) << i; + } + + return ret; +} + +static uint32_t riscv_aplic_read_pending_word(RISCVAPLICState *aplic, + uint32_t word) +{ + uint32_t i, irq, ret = 0; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + ret |= ((aplic->state[irq] & APLIC_ISTATE_PENDING) ? 1 : 0) << i; + } + + return ret; +} + +static void riscv_aplic_set_pending_raw(RISCVAPLICState *aplic, + uint32_t irq, bool pending) +{ + if (pending) { + aplic->state[irq] |= APLIC_ISTATE_PENDING; + } else { + aplic->state[irq] &= ~APLIC_ISTATE_PENDING; + } +} + +static void riscv_aplic_set_pending(RISCVAPLICState *aplic, + uint32_t irq, bool pending) +{ + uint32_t sourcecfg, sm; + + if ((irq <= 0) || (aplic->num_irqs <= irq)) { + return; + } + + sourcecfg = aplic->sourcecfg[irq]; + if (sourcecfg & APLIC_SOURCECFG_D) { + return; + } + + sm = sourcecfg & APLIC_SOURCECFG_SM_MASK; + if ((sm == APLIC_SOURCECFG_SM_INACTIVE) || + (!aplic->msimode && ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) || + (sm == APLIC_SOURCECFG_SM_LEVEL_LOW)))) { + return; + } + + riscv_aplic_set_pending_raw(aplic, irq, pending); +} + +static void riscv_aplic_set_pending_word(RISCVAPLICState *aplic, + uint32_t word, uint32_t value, + bool pending) +{ + uint32_t i, irq; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + if (value & (1U << i)) { + riscv_aplic_set_pending(aplic, irq, pending); + } + } +} + +static uint32_t riscv_aplic_read_enabled_word(RISCVAPLICState *aplic, + int word) +{ + uint32_t i, irq, ret = 0; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + ret |= ((aplic->state[irq] & APLIC_ISTATE_ENABLED) ? 1 : 0) << i; + } + + return ret; +} + +static void riscv_aplic_set_enabled_raw(RISCVAPLICState *aplic, + uint32_t irq, bool enabled) +{ + if (enabled) { + aplic->state[irq] |= APLIC_ISTATE_ENABLED; + } else { + aplic->state[irq] &= ~APLIC_ISTATE_ENABLED; + } +} + +static void riscv_aplic_set_enabled(RISCVAPLICState *aplic, + uint32_t irq, bool enabled) +{ + uint32_t sourcecfg, sm; + + if ((irq <= 0) || (aplic->num_irqs <= irq)) { + return; + } + + sourcecfg = aplic->sourcecfg[irq]; + if (sourcecfg & APLIC_SOURCECFG_D) { + return; + } + + sm = sourcecfg & APLIC_SOURCECFG_SM_MASK; + if (sm == APLIC_SOURCECFG_SM_INACTIVE) { + return; + } + + riscv_aplic_set_enabled_raw(aplic, irq, enabled); +} + +static void riscv_aplic_set_enabled_word(RISCVAPLICState *aplic, + uint32_t word, uint32_t value, + bool enabled) +{ + uint32_t i, irq; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + if (value & (1U << i)) { + riscv_aplic_set_enabled(aplic, irq, enabled); + } + } +} + +static void riscv_aplic_msi_send(RISCVAPLICState *aplic, + uint32_t hart_idx, uint32_t guest_idx, + uint32_t eiid) +{ + uint64_t addr; + MemTxResult result; + RISCVAPLICState *aplic_m; + uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; + + aplic_m = aplic; + while (aplic_m && !aplic_m->mmode) { + aplic_m = aplic_m->parent; + } + if (!aplic_m) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: m-level APLIC not found\n", + __func__); + return; + } + + if (aplic->mmode) { + msicfgaddr = aplic_m->mmsicfgaddr; + msicfgaddrH = aplic_m->mmsicfgaddrH; + } else { + msicfgaddr = aplic_m->smsicfgaddr; + msicfgaddrH = aplic_m->smsicfgaddrH; + } + + lhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXS_SHIFT) & + APLIC_xMSICFGADDRH_LHXS_MASK; + lhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXW_SHIFT) & + APLIC_xMSICFGADDRH_LHXW_MASK; + hhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXS_SHIFT) & + APLIC_xMSICFGADDRH_HHXS_MASK; + hhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXW_SHIFT) & + APLIC_xMSICFGADDRH_HHXW_MASK; + + group_idx = hart_idx >> lhxw; + hart_idx &= APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw); + + addr = msicfgaddr; + addr |= ((uint64_t)(msicfgaddrH & APLIC_xMSICFGADDRH_BAPPN_MASK)) << 32; + addr |= ((uint64_t)(group_idx & APLIC_xMSICFGADDR_PPN_HHX_MASK(hhxw))) << + APLIC_xMSICFGADDR_PPN_HHX_SHIFT(hhxs); + addr |= ((uint64_t)(hart_idx & APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw))) << + APLIC_xMSICFGADDR_PPN_LHX_SHIFT(lhxs); + addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); + addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; + + address_space_stl_le(&address_space_memory, addr, + eiid, MEMTXATTRS_UNSPECIFIED, &result); + if (result != MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: MSI write failed for " + "hart_index=%d guest_index=%d eiid=%d\n", + __func__, hart_idx, guest_idx, eiid); + } +} + +static void riscv_aplic_msi_irq_update(RISCVAPLICState *aplic, uint32_t irq) +{ + uint32_t hart_idx, guest_idx, eiid; + + if (!aplic->msimode || (aplic->num_irqs <= irq) || + !(aplic->domaincfg & APLIC_DOMAINCFG_IE)) { + return; + } + + if ((aplic->state[irq] & APLIC_ISTATE_ENPEND) != APLIC_ISTATE_ENPEND) { + return; + } + + riscv_aplic_set_pending_raw(aplic, irq, false); + + hart_idx = aplic->target[irq] >> APLIC_TARGET_HART_IDX_SHIFT; + hart_idx &= APLIC_TARGET_HART_IDX_MASK; + if (aplic->mmode) { + /* M-level APLIC ignores guest_index */ + guest_idx = 0; + } else { + guest_idx = aplic->target[irq] >> APLIC_TARGET_GUEST_IDX_SHIFT; + guest_idx &= APLIC_TARGET_GUEST_IDX_MASK; + } + eiid = aplic->target[irq] & APLIC_TARGET_EIID_MASK; + riscv_aplic_msi_send(aplic, hart_idx, guest_idx, eiid); +} + +static uint32_t riscv_aplic_idc_topi(RISCVAPLICState *aplic, uint32_t idc) +{ + uint32_t best_irq, best_iprio; + uint32_t irq, iprio, ihartidx, ithres; + + if (aplic->num_harts <= idc) { + return 0; + } + + ithres = aplic->ithreshold[idc]; + if (!ithres) { + return 0; + } + + best_irq = best_iprio = UINT32_MAX; + for (irq = 1; irq < aplic->num_irqs; irq++) { + if ((aplic->state[irq] & APLIC_ISTATE_ENPEND) != + APLIC_ISTATE_ENPEND) { + continue; + } + + ihartidx = aplic->target[irq] >> APLIC_TARGET_HART_IDX_SHIFT; + ihartidx &= APLIC_TARGET_HART_IDX_MASK; + if (ihartidx != idc) { + continue; + } + + iprio = aplic->target[irq] & aplic->iprio_mask; + if (iprio >= ithres) { + continue; + } + + if (iprio < best_iprio) { + best_irq = irq; + best_iprio = iprio; + } + } + + if (best_irq < aplic->num_irqs && best_iprio <= aplic->iprio_mask) { + return (best_irq << APLIC_IDC_TOPI_ID_SHIFT) | best_iprio; + } + + return 0; +} + +static void riscv_aplic_idc_update(RISCVAPLICState *aplic, uint32_t idc) +{ + uint32_t topi; + + if (aplic->msimode || aplic->num_harts <= idc) { + return; + } + + topi = riscv_aplic_idc_topi(aplic, idc); + if ((aplic->domaincfg & APLIC_DOMAINCFG_IE) && + aplic->idelivery[idc] && + (aplic->iforce[idc] || topi)) { + qemu_irq_raise(aplic->external_irqs[idc]); + } else { + qemu_irq_lower(aplic->external_irqs[idc]); + } +} + +static uint32_t riscv_aplic_idc_claimi(RISCVAPLICState *aplic, uint32_t idc) +{ + uint32_t irq, state, sm, topi = riscv_aplic_idc_topi(aplic, idc); + + if (!topi) { + aplic->iforce[idc] = 0; + return 0; + } + + irq = (topi >> APLIC_IDC_TOPI_ID_SHIFT) & APLIC_IDC_TOPI_ID_MASK; + sm = aplic->sourcecfg[irq] & APLIC_SOURCECFG_SM_MASK; + state = aplic->state[irq]; + riscv_aplic_set_pending_raw(aplic, irq, false); + if ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) && + (state & APLIC_ISTATE_INPUT)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + } else if ((sm == APLIC_SOURCECFG_SM_LEVEL_LOW) && + !(state & APLIC_ISTATE_INPUT)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + } + riscv_aplic_idc_update(aplic, idc); + + return topi; +} + +static void riscv_aplic_request(void *opaque, int irq, int level) +{ + bool update = false; + RISCVAPLICState *aplic = opaque; + uint32_t sourcecfg, childidx, state, idc; + + assert((0 < irq) && (irq < aplic->num_irqs)); + + sourcecfg = aplic->sourcecfg[irq]; + if (sourcecfg & APLIC_SOURCECFG_D) { + childidx = sourcecfg & APLIC_SOURCECFG_CHILDIDX_MASK; + if (childidx < aplic->num_children) { + riscv_aplic_request(aplic->children[childidx], irq, level); + } + return; + } + + state = aplic->state[irq]; + switch (sourcecfg & APLIC_SOURCECFG_SM_MASK) { + case APLIC_SOURCECFG_SM_EDGE_RISE: + if ((level > 0) && !(state & APLIC_ISTATE_INPUT) && + !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + case APLIC_SOURCECFG_SM_EDGE_FALL: + if ((level <= 0) && (state & APLIC_ISTATE_INPUT) && + !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + case APLIC_SOURCECFG_SM_LEVEL_HIGH: + if ((level > 0) && !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + case APLIC_SOURCECFG_SM_LEVEL_LOW: + if ((level <= 0) && !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + default: + break; + } + + if (level <= 0) { + aplic->state[irq] &= ~APLIC_ISTATE_INPUT; + } else { + aplic->state[irq] |= APLIC_ISTATE_INPUT; + } + + if (update) { + if (aplic->msimode) { + riscv_aplic_msi_irq_update(aplic, irq); + } else { + idc = aplic->target[irq] >> APLIC_TARGET_HART_IDX_SHIFT; + idc &= APLIC_TARGET_HART_IDX_MASK; + riscv_aplic_idc_update(aplic, idc); + } + } +} + +static uint64_t riscv_aplic_read(void *opaque, hwaddr addr, unsigned size) +{ + uint32_t irq, word, idc; + RISCVAPLICState *aplic = opaque; + + /* Reads must be 4 byte words */ + if ((addr & 0x3) != 0) { + goto err; + } + + if (addr == APLIC_DOMAINCFG) { + return aplic->domaincfg | (aplic->msimode ? APLIC_DOMAINCFG_DM : 0); + } else if ((APLIC_SOURCECFG_BASE <= addr) && + (addr < (APLIC_SOURCECFG_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_SOURCECFG_BASE) >> 2) + 1; + return aplic->sourcecfg[irq]; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDR)) { + return aplic->mmsicfgaddr; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDRH)) { + return aplic->mmsicfgaddrH; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDR)) { + /* Registers SMSICFGADDR and SMSICFGADDRH are implemented only if: + * (a) the interrupt domain is at machine level + * (b) the domain???s harts implement supervisor mode + * (c) the domain has one or more child supervisor-level domains + * that support MSI delivery mode (domaincfg.DM is not read- + * only zero in at least one of the supervisor-level child + * domains). + */ + return (aplic->num_children) ? aplic->smsicfgaddr : 0; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDRH)) { + return (aplic->num_children) ? aplic->smsicfgaddrH : 0; + } else if ((APLIC_SETIP_BASE <= addr) && + (addr < (APLIC_SETIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIP_BASE) >> 2; + return riscv_aplic_read_pending_word(aplic, word); + } else if (addr == APLIC_SETIPNUM) { + return 0; + } else if ((APLIC_CLRIP_BASE <= addr) && + (addr < (APLIC_CLRIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_CLRIP_BASE) >> 2; + return riscv_aplic_read_input_word(aplic, word); + } else if (addr == APLIC_CLRIPNUM) { + return 0; + } else if ((APLIC_SETIE_BASE <= addr) && + (addr < (APLIC_SETIE_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIE_BASE) >> 2; + return riscv_aplic_read_enabled_word(aplic, word); + } else if (addr == APLIC_SETIENUM) { + return 0; + } else if ((APLIC_CLRIE_BASE <= addr) && + (addr < (APLIC_CLRIE_BASE + aplic->bitfield_words * 4))) { + return 0; + } else if (addr == APLIC_CLRIENUM) { + return 0; + } else if (addr == APLIC_SETIPNUM_LE) { + return 0; + } else if (addr == APLIC_SETIPNUM_BE) { + return 0; + } else if (addr == APLIC_GENMSI) { + return (aplic->msimode) ? aplic->genmsi : 0; + } else if ((APLIC_TARGET_BASE <= addr) && + (addr < (APLIC_TARGET_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_TARGET_BASE) >> 2) + 1; + return aplic->target[irq]; + } else if (!aplic->msimode && (APLIC_IDC_BASE <= addr) && + (addr < (APLIC_IDC_BASE + aplic->num_harts * APLIC_IDC_SIZE))) { + idc = (addr - APLIC_IDC_BASE) / APLIC_IDC_SIZE; + switch (addr - (APLIC_IDC_BASE + idc * APLIC_IDC_SIZE)) { + case APLIC_IDC_IDELIVERY: + return aplic->idelivery[idc]; + case APLIC_IDC_IFORCE: + return aplic->iforce[idc]; + case APLIC_IDC_ITHRESHOLD: + return aplic->ithreshold[idc]; + case APLIC_IDC_TOPI: + return riscv_aplic_idc_topi(aplic, idc); + case APLIC_IDC_CLAIMI: + return riscv_aplic_idc_claimi(aplic, idc); + default: + goto err; + }; + } + +err: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid register read 0x%" HWADDR_PRIx "\n", + __func__, addr); + return 0; +} + +static void riscv_aplic_write(void *opaque, hwaddr addr, uint64_t value, + unsigned size) +{ + RISCVAPLICState *aplic = opaque; + uint32_t irq, word, idc = UINT32_MAX; + + /* Writes must be 4 byte words */ + if ((addr & 0x3) != 0) { + goto err; + } + + if (addr == APLIC_DOMAINCFG) { + /* Only IE bit writeable at the moment */ + value &= APLIC_DOMAINCFG_IE; + aplic->domaincfg = value; + } else if ((APLIC_SOURCECFG_BASE <= addr) && + (addr < (APLIC_SOURCECFG_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_SOURCECFG_BASE) >> 2) + 1; + if (!aplic->num_children && (value & APLIC_SOURCECFG_D)) { + value = 0; + } + if (value & APLIC_SOURCECFG_D) { + value &= (APLIC_SOURCECFG_D | APLIC_SOURCECFG_CHILDIDX_MASK); + } else { + value &= (APLIC_SOURCECFG_D | APLIC_SOURCECFG_SM_MASK); + } + aplic->sourcecfg[irq] = value; + if ((aplic->sourcecfg[irq] & APLIC_SOURCECFG_D) || + (aplic->sourcecfg[irq] == 0)) { + riscv_aplic_set_pending_raw(aplic, irq, false); + riscv_aplic_set_enabled_raw(aplic, irq, false); + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDR)) { + if (!(aplic->mmsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->mmsicfgaddr = value; + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDRH)) { + if (!(aplic->mmsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->mmsicfgaddrH = value & APLIC_xMSICFGADDRH_VALID_MASK; + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDR)) { + /* Registers SMSICFGADDR and SMSICFGADDRH are implemented only if: + * (a) the interrupt domain is at machine level + * (b) the domain???s harts implement supervisor mode + * (c) the domain has one or more child supervisor-level domains + * that support MSI delivery mode (domaincfg.DM is not read- + * only zero in at least one of the supervisor-level child + * domains). + */ + if (aplic->num_children && + !(aplic->smsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->smsicfgaddr = value; + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDRH)) { + if (aplic->num_children && + !(aplic->smsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->smsicfgaddrH = value & APLIC_xMSICFGADDRH_VALID_MASK; + } + } else if ((APLIC_SETIP_BASE <= addr) && + (addr < (APLIC_SETIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIP_BASE) >> 2; + riscv_aplic_set_pending_word(aplic, word, value, true); + } else if (addr == APLIC_SETIPNUM) { + riscv_aplic_set_pending(aplic, value, true); + } else if ((APLIC_CLRIP_BASE <= addr) && + (addr < (APLIC_CLRIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_CLRIP_BASE) >> 2; + riscv_aplic_set_pending_word(aplic, word, value, false); + } else if (addr == APLIC_CLRIPNUM) { + riscv_aplic_set_pending(aplic, value, false); + } else if ((APLIC_SETIE_BASE <= addr) && + (addr < (APLIC_SETIE_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIE_BASE) >> 2; + riscv_aplic_set_enabled_word(aplic, word, value, true); + } else if (addr == APLIC_SETIENUM) { + riscv_aplic_set_enabled(aplic, value, true); + } else if ((APLIC_CLRIE_BASE <= addr) && + (addr < (APLIC_CLRIE_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_CLRIE_BASE) >> 2; + riscv_aplic_set_enabled_word(aplic, word, value, false); + } else if (addr == APLIC_CLRIENUM) { + riscv_aplic_set_enabled(aplic, value, false); + } else if (addr == APLIC_SETIPNUM_LE) { + riscv_aplic_set_pending(aplic, value, true); + } else if (addr == APLIC_SETIPNUM_BE) { + riscv_aplic_set_pending(aplic, bswap32(value), true); + } else if (addr == APLIC_GENMSI) { + if (aplic->msimode) { + aplic->genmsi = value & ~(APLIC_TARGET_GUEST_IDX_MASK << + APLIC_TARGET_GUEST_IDX_SHIFT); + riscv_aplic_msi_send(aplic, + value >> APLIC_TARGET_HART_IDX_SHIFT, + 0, + value & APLIC_TARGET_EIID_MASK); + } + } else if ((APLIC_TARGET_BASE <= addr) && + (addr < (APLIC_TARGET_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_TARGET_BASE) >> 2) + 1; + if (aplic->msimode) { + aplic->target[irq] = value; + } else { + aplic->target[irq] = (value & ~APLIC_TARGET_IPRIO_MASK) | + (value & aplic->iprio_mask); + } + } else if (!aplic->msimode && (APLIC_IDC_BASE <= addr) && + (addr < (APLIC_IDC_BASE + aplic->num_harts * APLIC_IDC_SIZE))) { + idc = (addr - APLIC_IDC_BASE) / APLIC_IDC_SIZE; + switch (addr - (APLIC_IDC_BASE + idc * APLIC_IDC_SIZE)) { + case APLIC_IDC_IDELIVERY: + aplic->idelivery[idc] = value & 0x1; + break; + case APLIC_IDC_IFORCE: + aplic->iforce[idc] = value & 0x1; + break; + case APLIC_IDC_ITHRESHOLD: + aplic->ithreshold[idc] = value & aplic->iprio_mask; + break; + default: + goto err; + }; + } else { + goto err; + } + + if (aplic->msimode) { + for (irq = 1; irq < aplic->num_irqs; irq++) { + riscv_aplic_msi_irq_update(aplic, irq); + } + } else { + if (idc == UINT32_MAX) { + for (idc = 0; idc < aplic->num_harts; idc++) { + riscv_aplic_idc_update(aplic, idc); + } + } else { + riscv_aplic_idc_update(aplic, idc); + } + } + + return; + +err: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid register write 0x%" HWADDR_PRIx "\n", + __func__, addr); +} + +static const MemoryRegionOps riscv_aplic_ops = { + .read = riscv_aplic_read, + .write = riscv_aplic_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } +}; + +static void riscv_aplic_realize(DeviceState *dev, Error **errp) +{ + uint32_t i; + RISCVAPLICState *aplic = RISCV_APLIC(dev); + + aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; + aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); + aplic->state = g_new(uint32_t, aplic->num_irqs); + aplic->target = g_new0(uint32_t, aplic->num_irqs); + aplic->idelivery = g_new0(uint32_t, aplic->num_harts); + aplic->iforce = g_new0(uint32_t, aplic->num_harts); + aplic->ithreshold = g_new0(uint32_t, aplic->num_harts); + + memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, aplic, + TYPE_RISCV_APLIC, aplic->aperture_size); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); + + /* Only root APLICs have hardware IRQ lines. All non-root APLICs + * have IRQ lines delegated by their parent APLIC. + */ + if (!aplic->parent) { + qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); + } + + /* Create output IRQ lines for non-MSI mode */ + if (!aplic->msimode) { + aplic->external_irqs = g_malloc(sizeof(qemu_irq) * aplic->num_harts); + qdev_init_gpio_out(dev, aplic->external_irqs, aplic->num_harts); + + /* Claim the CPU interrupt to be triggered by this APLIC */ + for (i = 0; i < aplic->num_harts; i++) { + RISCVCPU *cpu = RISCV_CPU(qemu_get_cpu(aplic->hartid_base + i)); + if (riscv_cpu_claim_interrupts(cpu, + (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { + error_report("%s already claimed", + (aplic->mmode) ? "MEIP" : "SEIP"); + exit(1); + } + } + } + + msi_nonbroken = true; +} + +static Property riscv_aplic_properties[] = { + DEFINE_PROP_UINT32("aperture-size", RISCVAPLICState, aperture_size, 0), + DEFINE_PROP_UINT32("hartid-base", RISCVAPLICState, hartid_base, 0), + DEFINE_PROP_UINT32("num-harts", RISCVAPLICState, num_harts, 0), + DEFINE_PROP_UINT32("iprio-mask", RISCVAPLICState, iprio_mask, 0), + DEFINE_PROP_UINT32("num-irqs", RISCVAPLICState, num_irqs, 0), + DEFINE_PROP_BOOL("msimode", RISCVAPLICState, msimode, 0), + DEFINE_PROP_BOOL("mmode", RISCVAPLICState, mmode, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static const VMStateDescription vmstate_riscv_aplic = { + .name = "riscv_aplic", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(domaincfg, RISCVAPLICState), + VMSTATE_UINT32(mmsicfgaddr, RISCVAPLICState), + VMSTATE_UINT32(mmsicfgaddrH, RISCVAPLICState), + VMSTATE_UINT32(smsicfgaddr, RISCVAPLICState), + VMSTATE_UINT32(smsicfgaddrH, RISCVAPLICState), + VMSTATE_UINT32(genmsi, RISCVAPLICState), + VMSTATE_VARRAY_UINT32(sourcecfg, RISCVAPLICState, + num_irqs, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(state, RISCVAPLICState, + num_irqs, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(target, RISCVAPLICState, + num_irqs, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(idelivery, RISCVAPLICState, + num_harts, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(iforce, RISCVAPLICState, + num_harts, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(ithreshold, RISCVAPLICState, + num_harts, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_END_OF_LIST() + } +}; + +static void riscv_aplic_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + device_class_set_props(dc, riscv_aplic_properties); + dc->realize = riscv_aplic_realize; + dc->vmsd = &vmstate_riscv_aplic; +} + +static const TypeInfo riscv_aplic_info = { + .name = TYPE_RISCV_APLIC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(RISCVAPLICState), + .class_init = riscv_aplic_class_init, +}; + +static void riscv_aplic_register_types(void) +{ + type_register_static(&riscv_aplic_info); +} + +type_init(riscv_aplic_register_types) + +/* + * Add a APLIC device to another APLIC device as child for + * interrupt delegation. + */ +void riscv_aplic_add_child(DeviceState *parent, DeviceState *child) +{ + RISCVAPLICState *caplic, *paplic; + + assert(parent && child); + caplic = RISCV_APLIC(child); + paplic = RISCV_APLIC(parent); + + assert(paplic->num_irqs == caplic->num_irqs); + assert(paplic->num_children <= QEMU_APLIC_MAX_CHILDREN); + + caplic->parent = paplic; + paplic->children[paplic->num_children] = caplic; + paplic->num_children++; +} + +/* + * Create APLIC device. + */ +DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, + uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, + uint32_t iprio_bits, bool msimode, bool mmode, DeviceState *parent) +{ + DeviceState *dev = qdev_new(TYPE_RISCV_APLIC); + uint32_t i; + + assert(num_harts < APLIC_MAX_IDC); + assert((APLIC_IDC_BASE + (num_harts * APLIC_IDC_SIZE)) <= size); + assert(num_sources < APLIC_MAX_SOURCE); + assert(APLIC_MIN_IPRIO_BITS <= iprio_bits); + assert(iprio_bits <= APLIC_MAX_IPRIO_BITS); + + qdev_prop_set_uint32(dev, "aperture-size", size); + qdev_prop_set_uint32(dev, "hartid-base", hartid_base); + qdev_prop_set_uint32(dev, "num-harts", num_harts); + qdev_prop_set_uint32(dev, "iprio-mask", ((1U << iprio_bits) - 1)); + qdev_prop_set_uint32(dev, "num-irqs", num_sources + 1); + qdev_prop_set_bit(dev, "msimode", msimode); + qdev_prop_set_bit(dev, "mmode", mmode); + + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + + if (parent) { + riscv_aplic_add_child(parent, dev); + } + + if (!msimode) { + for (i = 0; i < num_harts; i++) { + CPUState *cpu = qemu_get_cpu(hartid_base + i); + + qdev_connect_gpio_out_named(dev, NULL, i, + qdev_get_gpio_in(DEVICE(cpu), + (mmode) ? IRQ_M_EXT : IRQ_S_EXT)); + } + } + + return dev; +} diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h new file mode 100644 index 0000000000..d96d7b38c1 --- /dev/null +++ b/include/hw/intc/riscv_aplic.h @@ -0,0 +1,73 @@ +/* + * RISC-V APLIC (Advanced Platform Level Interrupt Controller) interface + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef HW_RISCV_APLIC_H +#define HW_RISCV_APLIC_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_RISCV_APLIC "riscv.aplic" + +typedef struct RISCVAPLICState RISCVAPLICState; +DECLARE_INSTANCE_CHECKER(RISCVAPLICState, RISCV_APLIC, TYPE_RISCV_APLIC) + +struct RISCVAPLICState { + /*< private >*/ + SysBusDevice parent_obj; + qemu_irq *external_irqs; + + /*< public >*/ + MemoryRegion mmio; + uint32_t bitfield_words; + uint32_t domaincfg; + uint32_t mmsicfgaddr; + uint32_t mmsicfgaddrH; + uint32_t smsicfgaddr; + uint32_t smsicfgaddrH; + uint32_t genmsi; + uint32_t *sourcecfg; + uint32_t *state; + uint32_t *target; + uint32_t *idelivery; + uint32_t *iforce; + uint32_t *ithreshold; + + /* topology */ +#define QEMU_APLIC_MAX_CHILDREN 16 + struct RISCVAPLICState *parent; + struct RISCVAPLICState *children[QEMU_APLIC_MAX_CHILDREN]; + uint16_t num_children; + + /* config */ + uint32_t aperture_size; + uint32_t hartid_base; + uint32_t num_harts; + uint32_t iprio_mask; + uint32_t num_irqs; + bool msimode; + bool mmode; +}; + +void riscv_aplic_add_child(DeviceState *parent, DeviceState *child); + +DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, + uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, + uint32_t iprio_bits, bool msimode, bool mmode, DeviceState *parent); + +#endif From patchwork Tue Oct 26 06:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584123 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22BF3C433EF for ; Tue, 26 Oct 2021 08:05:01 +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 A0E0A60F22 for ; Tue, 26 Oct 2021 08:05:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A0E0A60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:60792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHS7-0001Wl-Fl for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 04:04:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBz-0003ky-Q6; Tue, 26 Oct 2021 02:44:17 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:57183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBo-0002ts-0u; Tue, 26 Oct 2021 02:44: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=1635230643; x=1666766643; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=mFPorsj1ASThHK/4dhs/o5YWaW0/s9Uiub4Mb/k3ZvA=; b=Z1cgClR0wvrh2Nox6euk6NWbXvHqGhXGMw6PZf5Cr0R7rWER8Eyqcp/C cEnwA+CUTLt/ZCeD+sj3Sj1/H0K7nAi/HUGO5/zkaP/qZ1qb93QwF6Ca/ gyer6kV0KFiD4tto4IS6uYzEUZRX4rtAyUyra77XJApf5AZk5Gexk1ZUB htLz01v0AgtzJ58rmvVvG9XaipfTIeycCJ7xTQLuYCKDRv6LS7z1B0Iy7 gvVVPk0IowKnz4euodYkD9qe9HV1PiWxc6kLN0d1/XUlHbUejNE1+eh7I l47JUjEhLnOEowzvCHwDUNo6SmUgLTDTqIkkbTn6xDbXX7/fpLGMoAILm w==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="295585006" Received: from mail-dm6nam11lp2173.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.173]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:43:57 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y59BRLRFUjjvzf8vttubzpH7fbkPRHgKFjPuDrzl7s67C6FwJN1nDF57HupU2sWtYBU1PcouKpi+kxQdjZV0mFVis/rVC8QgJfi21ERRiGFn6QvOJ4saV2PL+VUkRwhFlWgQZSOAN3djf7MK2gb8C3ucSX3MaVcLwi5K+wXMXnyfMMQUlgLt0cFwPLMjbG0+0p8NiSEfHBvAuiDWwxv6TJUaIdsoDD087lWrDaUNbMCRNtsnx+QBy8twEqeI738q8X+qqDlAuRZXHWoaBMi78qgcw77Me3NJb+OjYSEDqC0PAVL951Nyv4rLFZgHfecu1zhULcjFaIP7qXAoWNAKvw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hviGy8ShJe2mssNuhWRdhtEdfdPds2KyZr2esvoqhEA=; b=oO7Vg6h6oyTP1s7eExYHsQkFKX00ge7Ug1sZd4uN3/4J9H6dxZZKrPSViwu/aBPA9Z4Hko8T9ZGdv5jZpZyLacfzXNG8HgYwgze7npUL1X29SGfu7cZc337F+UxiMTECJrrXbbMBFEdTnZs1OOtoSW3d4wKX1pL66lbmcuT3lotyQtp2IXZH75CZ3PUFPD7dQgE0U84hX8VtswWm71ESuHmV9sobWf/ZUKQ6BEH0XTfejhZjFojws4zzeQI6WD1t8qfo8mmW8PUspNflB/Nuylk8VLe5igqLsBqOonnw6fPoUUl64KppnHxt0BoIXT76tD6hvA16/a8wPUWguI7VuQ== 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=hviGy8ShJe2mssNuhWRdhtEdfdPds2KyZr2esvoqhEA=; b=0K65ykTYqzEoe5LnB9JTT4QBpmcfTONh/SkvSS5ww3UQn6VICw3uwYUxaQg4Akz+x7N5muvsv3BeJzR9+DoKQwBl98A8WYGJLs8hTyAkmFifKpXg+uNXo3LpOygwJ6oYEqhxouICr6DupIAPNvu0Q04iB2lA98o9NW9Kh2GozMA= 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 CO6PR04MB7825.namprd04.prod.outlook.com (2603:10b6:303:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Tue, 26 Oct 2021 06:43:55 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:55 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 19/22] hw/riscv: virt: Add optional AIA APLIC support to virt machine Date: Tue, 26 Oct 2021 12:12:24 +0530 Message-Id: <20211026064227.2014502-20-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1bf82d53-6248-4b50-5233-08d9984bfb21 X-MS-TrafficTypeDiagnostic: CO6PR04MB7825: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:163; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6Jg4hFZdvYfPWxDyJq7gvvYjm3/rQDrVMrR4teA14QoCViebgemks8hiDTzwt585m2VCAhKLIAho0EV28DEvDDWqv4+YvHJTAi6gylineWJDeLzeT16RSvI/sWMGM9rUFlddnjm0RootrRv/WZBkWdHIZxJ54n3P/Bc1km+yxhzRTxdNjslaAjV+rxudRzjPCiJA+h/hh6B/HMJodZDOqJt/f2qcxgMeNcgY3DyLFkeUEhuLYuw1mFeFfuMxNrh6+sIF+nbQqj+KjwAMQwNy4BRq/YKJ01sTqJ1v3/sdxvSKooBnRYm7MHHVyEG9jzi/SydEQu9kXzFKLJvhV4vTAehlMxcVf/oLH+r19gN/nK9GMtIkqkf5nOiuLqreo8S9RYd6Wp6LFFDq/rIFX1lNMAD+MIhN/nFhPW9Fdx9Ewlbb19MwRcOzI7QpvNUMZDaao0TBCMxoRw5RVnSb4hnkFoUz9K7oa9xKhoyxoQg2IutnUvxaEIiZYXoqgFHOz7u5sYVWy1fZe7sGqnEwgYm2/uof8WMaaFWC4hafOEigkkVnNsgidMtSwPLWeGY+EUABP54Hx0BcdTw/8brQT25IHbsepGy9w1NJB5zQCyjoVygsW6a5MHHfnZNR6fN/RnokF924XVpxx/Mdd6pPixjZ9tMLR/PKRtxbyPz6so0oiGim361qEvbiqQM3brfm2Iiw 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)(366004)(316002)(2906002)(66476007)(8936002)(66556008)(55016002)(82960400001)(52116002)(5660300002)(508600001)(186003)(66946007)(8676002)(36756003)(54906003)(38350700002)(38100700002)(6666004)(4326008)(30864003)(110136005)(1076003)(86362001)(26005)(2616005)(44832011)(956004)(8886007)(7696005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1E4VJSnXWC57qoKvUTC5MncPX+z+63yvOz20AsNvwQtRqjielpBJ4t0iRYLhV6lH+DkstR8DIpy4L0lyKVsN2d/Tauj9f+ZaYY5OkofN4LePMmvJY0jT5TTzVC1n+wh4KTA+ibJ/lwoqzz4jgGax7nCKnAa2U3QRW70gwEQ/9R6BSzSUAwCqFUVTrh6WmUiYTrxBQGPZu5O0u1U/m1sLOA3/XfmpBbkHbppuudtAKyqvEusfVsNJghVWiNsfb5dyeU/+JTLGwiA9Z9bVsOa55ob4IIwyQ7aQlwwA/t2mm1CyQBtp3iXSftPS44Eto/sIDEQo6jPZFkFDSVSaHRwiKr19rbLyV212Vam68y7nY/ajpotWk9eoMjnrg3u0h2NuMP9daaNkO1p1w5kL7U5/SIuaCvF648dWanmMLaOeFDYwrhIkLd8Sv1jv0+r0FjQqsTouwzlG9hRN1/W0CtZHaWEJX6V9zchu+tNHumNHUH8Veks624+yudPJPJcRv3KvWQ5raGbL2fi9SgEprvSaB5dcpT+nysbpe7co0agZAwLheQ+fGpeZu7h5NOPdWu+6H4JJ8kyOWlBD9EXPl3I1t1+nesXsZ8o9fvXgyxhjitMqaQfj+MBlEeMKzYRhTq+S7cemgx83DiomHUZCWbePIdp4sPb4mE5iIT9MyNJ0Yb4zKlP2iwEHSvxjMzbniKsgB4wVQ9+EN10Z07GijTmfntcY4SNCIrFj0/LmBBavSTEwE8eQhtSDvPKopMOlvxETN79G6URNELTG3c2ggHTkrBUILC/afJRDyJm8xQQ3z1qr66UChHgko3TcNDgzR7ZrKY/zRs4CNaKrf0wDfDZ9RjBcfeJ4l9ZLk1+KjPhmjhYtPUNovIvjqINxh6LBM+t+5c0Oogcss5YfAwa5SZguNI3u99Wc+23CAB/WFv1lkA6Wg160KC15z8UuWjwa8U86ozzzRciXvrJOTkVlWbq21mbV9S6gp8GxMalSTvi94NlAXV617LLi1bHaJjm5LFNg42qFo5w20O+/rul83Tv7W/duDkoQAF+fLPVvT1QUFiRxCTY+b9YtyiPXpCdT06rty9HxxoOMNhyd0nNsBghtPUnY9l0VRULHJNChSOOV3JHBWF0wKE174u8iZqNOeMaLE2tNzqKWTWLDbqb1Lj/8tBWN9WY512VUb50XteV3f9+brEZv8igonxmxd1GWpm/ZVp8vJqWUAqR/SwJbZ90PdDENMwDOmNwmgsPrY4cceTUrT+b/dGCY/JUA29G7U3TSMCJsUfFYpLArzxZ4+hGVsbS8d1elU1030nMwpdmX7ZeMGRcYRAnfCKeSuW3kTb3zrz/GuA1BcoYYsoIG1CqIOnFceF+DLtH0WJNRV66REqA2H6UgWOXI9+N1ja23al8lCeP9zFCDtTjOiRAUuBGm46E8q4FHDbvMILTsD1zaU2wY1riyH6ncUw2P3AMzxbxsLn4Kg4UHbftjAG3TlZ9q41f/Ur3BpKEipSQ3czs+ig5omvhsSO2M88CP2XqR2L1clH9mxHRoEdRJmCsANdQHVPN9EUCg4oWoZcHPodCwgv+66YwV6cUBDrWcuGly+V02XgLcLHUd8qlYfeTCqloOecW4E36gmrFmqoG26/GwnlY= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1bf82d53-6248-4b50-5233-08d9984bfb21 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:55.6344 (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: egndKW1tkADlcgWThc0oE02Ot+zeStnXcTDkKjCc3a5fTk+9lO3rp3981N0RtZXSGG1BcW7tBHoi7263dMtQ0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7825 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We extend virt machine to emulate AIA APLIC devices only when "aia=aplic" parameter is passed along with machine name in QEMU command-line. When "aia=none" or not specified then we fallback to original PLIC device emulation. Signed-off-by: Anup Patel --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 293 ++++++++++++++++++++++++++++++++-------- include/hw/riscv/virt.h | 26 +++- 3 files changed, 260 insertions(+), 60 deletions(-) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index d2d869aaad..c30bb7cb6c 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -42,6 +42,7 @@ config RISCV_VIRT select PFLASH_CFI01 select SERIAL select RISCV_ACLINT + select RISCV_APLIC select SIFIVE_PLIC select SIFIVE_TEST select VIRTIO_MMIO diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 83f784bdee..4e21b485aa 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -33,6 +33,7 @@ #include "hw/riscv/boot.h" #include "hw/riscv/numa.h" #include "hw/intc/riscv_aclint.h" +#include "hw/intc/riscv_aplic.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_test.h" #include "chardev/char.h" @@ -51,6 +52,8 @@ static const MemMapEntry virt_memmap[] = { [VIRT_ACLINT_SSWI] = { 0x2F00000, 0x4000 }, [VIRT_PCIE_PIO] = { 0x3000000, 0x10000 }, [VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) }, + [VIRT_APLIC_M] = { 0xc000000, 0x8000 }, + [VIRT_APLIC_S] = { 0xd000000, 0x8000 }, [VIRT_UART0] = { 0x10000000, 0x100 }, [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, [VIRT_FW_CFG] = { 0x10100000, 0x18 }, @@ -132,12 +135,13 @@ static void virt_flash_map(RISCVVirtState *s, sysmem); } -static void create_pcie_irq_map(void *fdt, char *nodename, - uint32_t plic_phandle) +static void create_pcie_irq_map(RISCVVirtState *s, void *fdt, char *nodename, + uint32_t irqchip_phandle) { int pin, dev; - uint32_t - full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * FDT_INT_MAP_WIDTH] = {}; + uint32_t irq_map_stride = 0; + uint32_t full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * + FDT_MAX_INT_MAP_WIDTH] = {}; uint32_t *irq_map = full_irq_map; /* This code creates a standard swizzle of interrupts such that @@ -155,23 +159,31 @@ static void create_pcie_irq_map(void *fdt, char *nodename, int irq_nr = PCIE_IRQ + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_IRQS); int i = 0; + /* Fill PCI address cells */ irq_map[i] = cpu_to_be32(devfn << 8); - i += FDT_PCI_ADDR_CELLS; - irq_map[i] = cpu_to_be32(pin + 1); + /* Fill PCI Interrupt cells */ + irq_map[i] = cpu_to_be32(pin + 1); i += FDT_PCI_INT_CELLS; - irq_map[i++] = cpu_to_be32(plic_phandle); - i += FDT_PLIC_ADDR_CELLS; - irq_map[i] = cpu_to_be32(irq_nr); - - irq_map += FDT_INT_MAP_WIDTH; + /* Fill interrupt controller phandle and cells */ + irq_map[i++] = cpu_to_be32(irqchip_phandle); + irq_map[i++] = cpu_to_be32(irq_nr); + if (s->aia_type != VIRT_AIA_TYPE_NONE) { + irq_map[i++] = cpu_to_be32(0x4); + } + + if (!irq_map_stride) { + irq_map_stride = i; + } + irq_map += irq_map_stride; } } - qemu_fdt_setprop(fdt, nodename, "interrupt-map", - full_irq_map, sizeof(full_irq_map)); + qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, + GPEX_NUM_IRQS * GPEX_NUM_IRQS * + irq_map_stride * sizeof(uint32_t)); qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", 0x1800, 0, 0, 0x7); @@ -394,8 +406,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s, plic_addr = memmap[VIRT_PLIC].base + (memmap[VIRT_PLIC].size * socket); plic_name = g_strdup_printf("/soc/plic@%lx", plic_addr); qemu_fdt_add_subnode(mc->fdt, plic_name); - qemu_fdt_setprop_cell(mc->fdt, plic_name, - "#address-cells", FDT_PLIC_ADDR_CELLS); qemu_fdt_setprop_cell(mc->fdt, plic_name, "#interrupt-cells", FDT_PLIC_INT_CELLS); qemu_fdt_setprop_string_array(mc->fdt, plic_name, "compatible", @@ -415,6 +425,76 @@ static void create_fdt_socket_plic(RISCVVirtState *s, g_free(plic_cells); } +static void create_fdt_socket_aia(RISCVVirtState *s, + const MemMapEntry *memmap, int socket, + uint32_t *phandle, uint32_t *intc_phandles, + uint32_t *aplic_phandles) +{ + int cpu; + char *aplic_name; + uint32_t *aplic_cells; + unsigned long aplic_addr; + MachineState *mc = MACHINE(s); + uint32_t aplic_m_phandle, aplic_s_phandle; + + aplic_m_phandle = (*phandle)++; + aplic_s_phandle = (*phandle)++; + aplic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2); + + /* M-level APLIC node */ + for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { + aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + aplic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_M_EXT); + } + aplic_addr = memmap[VIRT_APLIC_M].base + + (memmap[VIRT_APLIC_M].size * socket); + aplic_name = g_strdup_printf("/soc/aplic@%lx", aplic_addr); + qemu_fdt_add_subnode(mc->fdt, aplic_name); + qemu_fdt_setprop_string(mc->fdt, aplic_name, "compatible", "riscv,aplic"); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, + "#interrupt-cells", FDT_APLIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", + 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_M].size); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", + VIRT_IRQCHIP_NUM_SOURCES); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,children", + aplic_s_phandle); + qemu_fdt_setprop_cells(mc->fdt, aplic_name, "riscv,delegate", + 0x1, VIRT_IRQCHIP_NUM_SOURCES, aplic_s_phandle); + riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_m_phandle); + g_free(aplic_name); + + /* S-level APLIC node */ + for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { + aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + aplic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT); + } + aplic_addr = memmap[VIRT_APLIC_S].base + + (memmap[VIRT_APLIC_S].size * socket); + aplic_name = g_strdup_printf("/soc/aplic@%lx", aplic_addr); + qemu_fdt_add_subnode(mc->fdt, aplic_name); + qemu_fdt_setprop_string(mc->fdt, aplic_name, "compatible", "riscv,aplic"); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, + "#interrupt-cells", FDT_APLIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", + 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_S].size); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", + VIRT_IRQCHIP_NUM_SOURCES); + riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_s_phandle); + g_free(aplic_name); + + g_free(aplic_cells); + aplic_phandles[socket] = aplic_s_phandle; +} + static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, bool is_32_bit, uint32_t *phandle, uint32_t *irq_mmio_phandle, @@ -451,8 +531,13 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, create_fdt_socket_clint(s, memmap, socket, intc_phandles); } - create_fdt_socket_plic(s, memmap, socket, phandle, - intc_phandles, xplic_phandles); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + create_fdt_socket_plic(s, memmap, socket, phandle, + intc_phandles, xplic_phandles); + } else { + create_fdt_socket_aia(s, memmap, socket, phandle, + intc_phandles, xplic_phandles); + } g_free(intc_phandles); g_free(clust_name); @@ -493,7 +578,13 @@ static void create_fdt_virtio(RISCVVirtState *s, const MemMapEntry *memmap, 0x0, memmap[VIRT_VIRTIO].size); qemu_fdt_setprop_cell(mc->fdt, name, "interrupt-parent", irq_virtio_phandle); - qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", VIRTIO_IRQ + i); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", + VIRTIO_IRQ + i); + } else { + qemu_fdt_setprop_cells(mc->fdt, name, "interrupts", + VIRTIO_IRQ + i, 0x4); + } g_free(name); } } @@ -531,7 +622,7 @@ static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.size); - create_pcie_irq_map(mc->fdt, name, irq_pcie_phandle); + create_pcie_irq_map(s, mc->fdt, name, irq_pcie_phandle); g_free(name); } @@ -590,7 +681,11 @@ static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap, 0x0, memmap[VIRT_UART0].size); qemu_fdt_setprop_cell(mc->fdt, name, "clock-frequency", 3686400); qemu_fdt_setprop_cell(mc->fdt, name, "interrupt-parent", irq_mmio_phandle); - qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", UART0_IRQ); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", UART0_IRQ); + } else { + qemu_fdt_setprop_cells(mc->fdt, name, "interrupts", UART0_IRQ, 0x4); + } qemu_fdt_add_subnode(mc->fdt, "/chosen"); qemu_fdt_setprop_string(mc->fdt, "/chosen", "stdout-path", name); @@ -611,7 +706,11 @@ static void create_fdt_rtc(RISCVVirtState *s, const MemMapEntry *memmap, 0x0, memmap[VIRT_RTC].base, 0x0, memmap[VIRT_RTC].size); qemu_fdt_setprop_cell(mc->fdt, name, "interrupt-parent", irq_mmio_phandle); - qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", RTC_IRQ); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", RTC_IRQ); + } else { + qemu_fdt_setprop_cells(mc->fdt, name, "interrupts", RTC_IRQ, 0x4); + } g_free(name); } @@ -692,7 +791,7 @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, hwaddr high_mmio_base, hwaddr high_mmio_size, hwaddr pio_base, - DeviceState *plic) + DeviceState *irqchip) { DeviceState *dev; MemoryRegion *ecam_alias, *ecam_reg; @@ -726,7 +825,7 @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); for (i = 0; i < GPEX_NUM_IRQS; i++) { - irq = qdev_get_gpio_in(plic, PCIE_IRQ + i); + irq = qdev_get_gpio_in(irqchip, PCIE_IRQ + i); sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); gpex_set_irq_num(GPEX_HOST(dev), i, PCIE_IRQ + i); @@ -775,18 +874,75 @@ static char *plic_hart_config_string(int hart_count) return g_strjoinv(",", (char **)vals); } +static DeviceState *virt_create_plic(const MemMapEntry *memmap, int socket, + int base_hartid, int hart_count) +{ + DeviceState *ret; + char *plic_hart_config; + + /* Per-socket PLIC hart topology configuration string */ + plic_hart_config = plic_hart_config_string(hart_count); + + /* Per-socket PLIC */ + ret = sifive_plic_create( + memmap[VIRT_PLIC].base + socket * memmap[VIRT_PLIC].size, + plic_hart_config, hart_count, base_hartid, + VIRT_IRQCHIP_NUM_SOURCES, + ((1U << VIRT_IRQCHIP_NUM_PRIO_BITS) - 1), + VIRT_PLIC_PRIORITY_BASE, + VIRT_PLIC_PENDING_BASE, + VIRT_PLIC_ENABLE_BASE, + VIRT_PLIC_ENABLE_STRIDE, + VIRT_PLIC_CONTEXT_BASE, + VIRT_PLIC_CONTEXT_STRIDE, + memmap[VIRT_PLIC].size); + + g_free(plic_hart_config); + + return ret; +} + +static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, + const MemMapEntry *memmap, int socket, + int base_hartid, int hart_count) +{ + DeviceState *aplic_m; + + /* Per-socket M-level APLIC */ + aplic_m = riscv_aplic_create( + memmap[VIRT_APLIC_M].base + socket * memmap[VIRT_APLIC_M].size, + memmap[VIRT_APLIC_M].size, + base_hartid, hart_count, + VIRT_IRQCHIP_NUM_SOURCES, + VIRT_IRQCHIP_NUM_PRIO_BITS, + false, true, NULL); + + if (aplic_m) { + /* Per-socket S-level APLIC */ + riscv_aplic_create( + memmap[VIRT_APLIC_S].base + socket * memmap[VIRT_APLIC_S].size, + memmap[VIRT_APLIC_S].size, + base_hartid, hart_count, + VIRT_IRQCHIP_NUM_SOURCES, + VIRT_IRQCHIP_NUM_PRIO_BITS, + false, false, aplic_m); + } + + return aplic_m; +} + static void virt_machine_init(MachineState *machine) { const MemMapEntry *memmap = virt_memmap; RISCVVirtState *s = RISCV_VIRT_MACHINE(machine); MemoryRegion *system_memory = get_system_memory(); MemoryRegion *mask_rom = g_new(MemoryRegion, 1); - char *plic_hart_config, *soc_name; + char *soc_name; target_ulong start_addr = memmap[VIRT_DRAM].base; target_ulong firmware_end_addr, kernel_start_addr; uint32_t fdt_load_addr; uint64_t kernel_entry; - DeviceState *mmio_plic, *virtio_plic, *pcie_plic; + DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; int i, base_hartid, hart_count; /* Check socket count limit */ @@ -797,7 +953,7 @@ static void virt_machine_init(MachineState *machine) } /* Initialize sockets */ - mmio_plic = virtio_plic = pcie_plic = NULL; + mmio_irqchip = virtio_irqchip = pcie_irqchip = NULL; for (i = 0; i < riscv_socket_count(machine); i++) { if (!riscv_socket_check_hartids(machine, i)) { error_report("discontinuous hartids in socket%d", i); @@ -847,36 +1003,27 @@ static void virt_machine_init(MachineState *machine) base_hartid, hart_count, true); } - /* Per-socket PLIC hart topology configuration string */ - plic_hart_config = plic_hart_config_string(hart_count); - - /* Per-socket PLIC */ - s->plic[i] = sifive_plic_create( - memmap[VIRT_PLIC].base + i * memmap[VIRT_PLIC].size, - plic_hart_config, hart_count, base_hartid, - VIRT_PLIC_NUM_SOURCES, - VIRT_PLIC_NUM_PRIORITIES, - VIRT_PLIC_PRIORITY_BASE, - VIRT_PLIC_PENDING_BASE, - VIRT_PLIC_ENABLE_BASE, - VIRT_PLIC_ENABLE_STRIDE, - VIRT_PLIC_CONTEXT_BASE, - VIRT_PLIC_CONTEXT_STRIDE, - memmap[VIRT_PLIC].size); - g_free(plic_hart_config); + /* Per-socket interrupt controller */ + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + s->irqchip[i] = virt_create_plic(memmap, i, + base_hartid, hart_count); + } else { + s->irqchip[i] = virt_create_aia(s->aia_type, memmap, i, + base_hartid, hart_count); + } - /* Try to use different PLIC instance based device type */ + /* Try to use different IRQCHIP instance based device type */ if (i == 0) { - mmio_plic = s->plic[i]; - virtio_plic = s->plic[i]; - pcie_plic = s->plic[i]; + mmio_irqchip = s->irqchip[i]; + virtio_irqchip = s->irqchip[i]; + pcie_irqchip = s->irqchip[i]; } if (i == 1) { - virtio_plic = s->plic[i]; - pcie_plic = s->plic[i]; + virtio_irqchip = s->irqchip[i]; + pcie_irqchip = s->irqchip[i]; } if (i == 2) { - pcie_plic = s->plic[i]; + pcie_irqchip = s->irqchip[i]; } } @@ -975,7 +1122,7 @@ static void virt_machine_init(MachineState *machine) for (i = 0; i < VIRTIO_COUNT; i++) { sysbus_create_simple("virtio-mmio", memmap[VIRT_VIRTIO].base + i * memmap[VIRT_VIRTIO].size, - qdev_get_gpio_in(DEVICE(virtio_plic), VIRTIO_IRQ + i)); + qdev_get_gpio_in(DEVICE(virtio_irqchip), VIRTIO_IRQ + i)); } gpex_pcie_init(system_memory, @@ -986,14 +1133,14 @@ static void virt_machine_init(MachineState *machine) virt_high_pcie_memmap.base, virt_high_pcie_memmap.size, memmap[VIRT_PCIE_PIO].base, - DEVICE(pcie_plic)); + DEVICE(pcie_irqchip)); serial_mm_init(system_memory, memmap[VIRT_UART0].base, - 0, qdev_get_gpio_in(DEVICE(mmio_plic), UART0_IRQ), 399193, + 0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART0_IRQ), 399193, serial_hd(0), DEVICE_LITTLE_ENDIAN); sysbus_create_simple("goldfish_rtc", memmap[VIRT_RTC].base, - qdev_get_gpio_in(DEVICE(mmio_plic), RTC_IRQ)); + qdev_get_gpio_in(DEVICE(mmio_irqchip), RTC_IRQ)); virt_flash_create(s); @@ -1009,6 +1156,37 @@ static void virt_machine_instance_init(Object *obj) { } +static char *virt_get_aia(Object *obj, Error **errp) +{ + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); + const char *val; + + switch (s->aia_type) { + case VIRT_AIA_TYPE_APLIC: + val = "aplic"; + break; + default: + val = "none"; + break; + }; + + return g_strdup(val); +} + +static void virt_set_aia(Object *obj, const char *val, Error **errp) +{ + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); + + if (!strcmp(val, "none")) { + s->aia_type = VIRT_AIA_TYPE_NONE; + } else if (!strcmp(val, "aplic")) { + s->aia_type = VIRT_AIA_TYPE_APLIC; + } else { + error_setg(errp, "Invalid AIA interrupt controller type"); + error_append_hint(errp, "Valid values are none, and aplic.\n"); + } +} + static bool virt_get_aclint(Object *obj, Error **errp) { MachineState *ms = MACHINE(obj); @@ -1047,6 +1225,13 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "aclint", "Set on/off to enable/disable " "emulating ACLINT devices"); + + object_class_property_add_str(oc, "aia", virt_get_aia, + virt_set_aia); + object_class_property_set_description(oc, "aia", + "Set type of AIA interrupt " + "conttoller. Valid values are " + "none, and aplic."); } static const TypeInfo virt_machine_typeinfo = { diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index d9105c1886..a26ef4a295 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -32,18 +32,24 @@ typedef struct RISCVVirtState RISCVVirtState; DECLARE_INSTANCE_CHECKER(RISCVVirtState, RISCV_VIRT_MACHINE, TYPE_RISCV_VIRT_MACHINE) +typedef enum RISCVVirtAIAType { + VIRT_AIA_TYPE_NONE=0, + VIRT_AIA_TYPE_APLIC, +} RISCVVirtAIAType; + struct RISCVVirtState { /*< private >*/ MachineState parent; /*< public >*/ RISCVHartArrayState soc[VIRT_SOCKETS_MAX]; - DeviceState *plic[VIRT_SOCKETS_MAX]; + DeviceState *irqchip[VIRT_SOCKETS_MAX]; PFlashCFI01 *flash[2]; FWCfgState *fw_cfg; int fdt_size; bool have_aclint; + RISCVVirtAIAType aia_type; }; enum { @@ -54,6 +60,8 @@ enum { VIRT_CLINT, VIRT_ACLINT_SSWI, VIRT_PLIC, + VIRT_APLIC_M, + VIRT_APLIC_S, VIRT_UART0, VIRT_VIRTIO, VIRT_FW_CFG, @@ -73,9 +81,10 @@ enum { VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ }; +#define VIRT_IRQCHIP_NUM_SOURCES 127 +#define VIRT_IRQCHIP_NUM_PRIO_BITS 3 + #define VIRT_PLIC_HART_CONFIG "MS" -#define VIRT_PLIC_NUM_SOURCES 127 -#define VIRT_PLIC_NUM_PRIORITIES 7 #define VIRT_PLIC_PRIORITY_BASE 0x04 #define VIRT_PLIC_PENDING_BASE 0x1000 #define VIRT_PLIC_ENABLE_BASE 0x2000 @@ -87,9 +96,14 @@ enum { #define FDT_PCI_ADDR_CELLS 3 #define FDT_PCI_INT_CELLS 1 -#define FDT_PLIC_ADDR_CELLS 0 #define FDT_PLIC_INT_CELLS 1 -#define FDT_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + 1 + \ - FDT_PLIC_ADDR_CELLS + FDT_PLIC_INT_CELLS) +#define FDT_APLIC_INT_CELLS 2 +#define FDT_MAX_INT_CELLS 2 +#define FDT_MAX_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_MAX_INT_CELLS) +#define FDT_PLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_PLIC_INT_CELLS) +#define FDT_APLIC_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ + 1 + FDT_APLIC_INT_CELLS) #endif From patchwork Tue Oct 26 06:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA02EC433EF for ; Tue, 26 Oct 2021 07:58:33 +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 496FA60F22 for ; Tue, 26 Oct 2021 07:58:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 496FA60F22 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:47670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHLr-00010V-64 for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:58:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBr-0003gX-UO; Tue, 26 Oct 2021 02:44:08 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:53782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBo-0002t7-0V; Tue, 26 Oct 2021 02:44:07 -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=1635230643; x=1666766643; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=INNmg/hDvf169nc2ZiqfiMFwT909p8OF0AB4mrgOtxo=; b=VbXygnMqHFMOifgUf1OJU3pEMsRo/tagheU1z3E0Jdysqml5DWBEiQJc DtBGoieoGtn9rM6NC/PKOvnzAHTRnyhLN5HCPyDr2s6Oeyjdgz7zGap0a on7biWfDC0T/wJuAH1HaUrjsXC/rANeNHUOdeueXLL/M3VFi1oV5uBS9e df9lCa/Q1k9GxsKHWRIaMMuO9xzQg4rWwN+TBU5B0L0PSWXXp4AjpES6f lGKxOjfdHiNf+3pp5WdeQX6PXPYHOuovzDoVNC5Bftqj7dT0UiBKcEZdB /DopvcnugLUCMLdfT1FFQJ6xJjJ1MTmCWVQMfpo88wrajQxxSJiADaARd w==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="287722113" Received: from mail-dm6nam11lp2175.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.175]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:44:00 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VzFE+7Va80nilM+faZFrOWfjXRmEj+n3PeBFaYO6IQTEQwZ+KeVFL8aIxv8pD+zdsImS0uuYUqzdOurX9oRpQJ9EmAhwzPB5VhSHin9m7I8RTEXuJNp0nsFHuL7/wiVYf0bWNfNBuLQQ/25aubIkaS3fgySdAVXO+s/VML1kzbG2VfVd6POEsTpHiq6N+yC8XUv961fiwdZEZ4tJOcFJO4fk/RYaiJSpjSpXswEQhbouJCLFOzcKjFsfpGmrQYaSiwFb4f84J+Bm+eFF5a1uq6YQcD76jfp0YysYMrALaFLpaejlvuQb0uSibhGMYX7vyNQtZ2u8LfVLX0r8gkvY1A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZExT2KE+FXyyR+Z/ptYaBm2OEHhmHudUcOL4ornmbEQ=; b=co+4EIGf6VZVZuQDF+DoLJl0Dc+byEgcZ32y8oFsFQ50bo4pTKK/xvtHRSGVQV3TBejqpqwGkac5DFInAppQj1fxj0eHdJco4HyeuZZ17v5vfIw2OUWW7Ynoip1rtfncJcRfOpy08kVg6/v4hgfPxCaWRdr2lQiNsGTTmsSd3lHXVxJu/QbXxXgF9VqXnDrWiqotbRGD/3BJaBpyfi9dnZiUbsZHw1ceOqQZrCkhqCURPMmAIBgKfK4tqIhOL+kDMgecdfd8+tQCxX42ENmpRbXvbfaN7kVI9FXvz7q+G1u3o5b4rIytjwioDp0RinPEguYyAyRJ3XjipabQPcSezg== 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=ZExT2KE+FXyyR+Z/ptYaBm2OEHhmHudUcOL4ornmbEQ=; b=Rz/wYKhR7JX89DFNEHbQ2/3HnOW8fVK/fn+xwSuwse/PHySIVdW3c7FAXCtmD/VSwj6OCMfdsZk/faqzVZciWQ82gXu3I/ONdkiRi/Xb0p79pWQ2poqILd3QaESFRYvVF2PM97d/RfsD4h93H+cdZt6FL2UMm9W/JcVtIsaQTSs= 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 CO6PR04MB7825.namprd04.prod.outlook.com (2603:10b6:303:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Tue, 26 Oct 2021 06:43:58 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:43:58 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 20/22] hw/intc: Add RISC-V AIA IMSIC device emulation Date: Tue, 26 Oct 2021 12:12:25 +0530 Message-Id: <20211026064227.2014502-21-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 70447197-1ace-4389-2338-08d9984bfd15 X-MS-TrafficTypeDiagnostic: CO6PR04MB7825: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:224; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ETrJRWNsyekkTHAa/H1VRB/aL/s/jZpSLh6sjsYLjci2GUJs/fOjou4p9mvwR/y6iHNAmOvC/HKZyokMhx8zojIyf19UsqsSs5FoXgH/XA0vQaDRU/qGyXK0GY1F4Uvi1pzyowM7ddBF+a+f7fzW/RMpyjmcb2YL4VqILBBoKixQwv9qP02rrizqmcio+MPktHkn60GECcOeImAuqVU5xmRqAvZu4sgViaskGu5kF8B5ITwDaYb9TW+zShZQJsAJLIW7aCpK7jFx5FfMWPJVf6pCnrmWXKh+qbBH+MgoPpEP/buuDC+R/Up8tqVrIiiLSwYEwetNYSve/ljm5QTjNS8GBTXHhV/QSnk7uqRM7VzpHe5fyGmukFQLYllcp1/Rs29TYuhOQTn5lUi1A9D8gvJyWhmA5kMk4/5QLWDunlngBQmP25lM696TLYZNucg4IcqXW+3X0l3h299ZRlAUqfXtKXCeTGS5aw87xPtKJjVNFEF1A1aU3cNlKvqv5kuA6ktD4SjIrc3MtvVKMaDj5Pi/vflQIwftcRASNlAHZBhgQj5bEWHc5H+mECLRv/XzMUAmKK84FfSkdxr1xY3O6PnI9+O0YptT1hADJGfy6Nvxva/bcPv5swaxWZJAJwLG8e+ziKkA1PEjwgBBDDqVSx6X0LwSDZBX5Q4Hb433G8NVInch2y2GTfiKGgTLO3Jm6XFsYXVYJQq7aMH3o5K2b1g+q0iBjcqzGZa65nadCKqzJOIpD1I7o4ihlSZvorZdCvkUsFMqbPZPQXSYRxSLU2pGRXkqHHw3kfFHe+biFhw= 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)(366004)(316002)(2906002)(66476007)(8936002)(66556008)(55016002)(82960400001)(52116002)(5660300002)(508600001)(186003)(66946007)(8676002)(36756003)(54906003)(38350700002)(38100700002)(6666004)(4326008)(30864003)(110136005)(1076003)(86362001)(26005)(2616005)(44832011)(956004)(8886007)(7696005)(83380400001)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3oVD1z0X8BFWiJJIdoqVI1wibsfbh13XrxqhHBRsBjY1t8CedaXCrUoGmDjGRkua59ZuYgw4SP76F412z4qMW6AagZuzx4Zr9i1n0j7O9XUe0XDaMOT/uFHMZePD0D5Ek/MCL5XF9ORh7I4frFzChmMEMDxUsm9Q3i+vpBoTPBfHDPy3lRg0Uq660E07oRaeZBA2MqnaVGU50QKTvduh4EafF+LTyWhZN6Mj/uvFeMYEob70hZhY6gbqJrELAUF+rY4TSH0wQJGTS+F5kXRtRLyyZW06Ff+AJzscb2EGlkXBpvyi/T6a1/VJgGKUgguvt+OY0XP6W/VFgf5biW/zZYnJZCNsMZG+RHRM/X2LOyTMigsYNoTmvTE4rQicIs1iVBHdQhZqwAsE51dBMizBg0nPougesFvwj88RsgoE2om2W2nwN3A8iNc1R9SCycVANcHGZ2ZQFzmoqUJfY0atq80p/BBjtrjYGgloUzFW0fG+xqoBVa5kCbqm7C7fQxcODpiXjzqUM7q/ncdpW2xhpxpV+ROSoj7ieuxg73EkQsoP+G5sgkDgC9L9CVOkL7sKhtdyw/nPsYhgh+WP40TONzbuI6te3nx9IgHeMGH3HlC2qPmazkGN3EhONOmzp3FvLY1JXmKGg3Qri+Nhl1pQqOX7up4WO0/RgHcjRceVCpJXZiAmyRNQSU8wnXUZ0s31S617GcUaq9T4wlcAUuPYLstekai3Fou9FPotBa2KCBe+i1Xd8DxTPEbj5+TOvqwnk1r18q/ZqUV8Ds9vrXz+wlsyjw2E3bafJ0kspBKJ8FMtTjyN1AucRrjic20/yDJDbwkQyjQgt8aI5KxcW3IQKC7g0g2JvYA8q+nn23BupjSt25reSx8QsJYIuSn3Ya36BKCUWc6/zwl81+R/j0gwrJGMwNVE3lPTDFWHrAjJ3Yce0ZvR8VOcVs2kPqamX0LLOwaRqUD+nT/9miCCe50GT+dKXKn6PwLJAEmkHeMr6hq4510GxHcCE166yZnSVxHbwKl77FOnrqisUR0kN3vb4oSX7XfaXeRPhZRYJ22sq1giWa4iVnr3b5nG07nK7KD19ch6J6D4lAukEAaOF3CTs13zBylUqAhwKSkkjxVGDoBcq+CujH6Aow/xO6jFxk+CTzYsLaooAhBXAerB1otXgyI20QLdtc7STb8pTuaaxJY4FfG6w4Vju0rSoCdI6CO84TmRCEassoAi/lEci5ikQgifqqAyYUv0tlWGcbHg2TMheSyMTQ/QOqRyhDizvpZWiQYAPC4YqqYDO64IEUuoE+QGL/wVcjUCEgG04VgnkyYopKN+CiESb+tRzieGMhkOgl7voLE40cmKqMa5zFAcoe6fJ2iYXS3WI8N2p4TvNx3lvWvbJ4zudF5xlPfUO5SZnLDP63CACxzre+JK2nsfpUOHlDFMA5EFadHhG52tGRptOyiWfdyWNizyeKWDeRO0UqP3mQx6661SWQl6dr2ZtymSEKt4BjAbAqs0yJKBKR/XR071878+Y510t4h19uuKSkdpLQadcQVQBKoV8WjRpnVKZ0ZABOKn1rjd81TQ5UaZe2ZY8KypW6i6tnOJ1F8Dfar2tSuabL+EwcPTWXAheWuxuU9BzroNDtMpxtCyUsQ= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 70447197-1ace-4389-2338-08d9984bfd15 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:43:58.7577 (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: GBnqcoA6pCBcp3uHP3V3VssDqS8GVvC3HnhOYS93UvuxFZH7juU+dz2Og47+VfeehHXGppw/DIja2Q8hL4mmow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7825 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa2.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for MSIs (message signal interrupts) called IMSIC (Incoming Message Signal Interrupt Controller). The IMSIC is per-HART device and also suppport virtualizaiton of MSIs using dedicated VS-level guest interrupt files. This patch adds device emulation for RISC-V AIA IMSIC which supports M-level, S-level, and VS-level MSIs. Signed-off-by: Anup Patel --- hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/riscv_imsic.c | 443 ++++++++++++++++++++++++++++++++++ include/hw/intc/riscv_imsic.h | 68 ++++++ 4 files changed, 515 insertions(+) create mode 100644 hw/intc/riscv_imsic.c create mode 100644 include/hw/intc/riscv_imsic.h diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index 1592623233..0bb3166110 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -68,6 +68,9 @@ config RISCV_ACLINT config RISCV_APLIC bool +config RISCV_IMSIC + bool + config SIFIVE_PLIC bool diff --git a/hw/intc/meson.build b/hw/intc/meson.build index 77b068f673..bcfd7758a9 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -48,6 +48,7 @@ specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) specific_ss.add(when: 'CONFIG_SH_INTC', if_true: files('sh_intc.c')) specific_ss.add(when: 'CONFIG_RISCV_ACLINT', if_true: files('riscv_aclint.c')) specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) +specific_ss.add(when: 'CONFIG_RISCV_IMSIC', if_true: files('riscv_imsic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'], diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c new file mode 100644 index 0000000000..f33e35986b --- /dev/null +++ b/hw/intc/riscv_imsic.c @@ -0,0 +1,443 @@ +/* + * RISC-V IMSIC (Incoming Message Signaled Interrupt Controller) + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/error-report.h" +#include "qemu/bswap.h" +#include "exec/address-spaces.h" +#include "hw/sysbus.h" +#include "hw/pci/msi.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/intc/riscv_imsic.h" +#include "hw/irq.h" +#include "target/riscv/cpu.h" +#include "target/riscv/cpu_bits.h" +#include "sysemu/sysemu.h" +#include "migration/vmstate.h" + +#define IMSIC_MMIO_PAGE_LE 0x00 +#define IMSIC_MMIO_PAGE_BE 0x04 + +#define IMSIC_MIN_ID ((IMSIC_EIPx_BITS * 2) - 1) +#define IMSIC_MAX_ID (IMSIC_TOPEI_IID_MASK) + +#define IMSIC_EISTATE_PENDING (1U << 0) +#define IMSIC_EISTATE_ENABLED (1U << 1) +#define IMSIC_EISTATE_ENPEND (IMSIC_EISTATE_ENABLED | \ + IMSIC_EISTATE_PENDING) + +static uint32_t riscv_imsic_topei(RISCVIMSICState *imsic, uint32_t page) +{ + uint32_t i, max_irq, base; + + base = page * imsic->num_irqs; + max_irq = (imsic->num_irqs < imsic->eithreshold[page]) ? + imsic->num_irqs : imsic->eithreshold[page]; + for (i = 1; i < max_irq; i++) { + if ((imsic->eistate[base + i] & IMSIC_EISTATE_ENPEND) == + IMSIC_EISTATE_ENPEND) { + return (i << IMSIC_TOPEI_IID_SHIFT) | i; + } + } + + return 0; +} + +static void riscv_imsic_update(RISCVIMSICState *imsic, uint32_t page) +{ + if (imsic->eidelivery[page] && riscv_imsic_topei(imsic, page)) { + qemu_irq_raise(imsic->external_irqs[page]); + } else { + qemu_irq_lower(imsic->external_irqs[page]); + } +} + +static int riscv_imsic_eidelivery_rmw(RISCVIMSICState *imsic, uint32_t page, + target_ulong *val, + target_ulong new_val, + target_ulong wr_mask) +{ + target_ulong old_val = imsic->eidelivery[page]; + + if (val) { + *val = old_val; + } + + wr_mask &= 0x1; + imsic->eidelivery[page] = (old_val & ~wr_mask) | (new_val & wr_mask); + + riscv_imsic_update(imsic, page); + return 0; +} + +static int riscv_imsic_eithreshold_rmw(RISCVIMSICState *imsic, uint32_t page, + target_ulong *val, + target_ulong new_val, + target_ulong wr_mask) +{ + target_ulong old_val = imsic->eithreshold[page]; + + if (val) { + *val = old_val; + } + + wr_mask &= IMSIC_MAX_ID; + imsic->eithreshold[page] = (old_val & ~wr_mask) | (new_val & wr_mask); + + riscv_imsic_update(imsic, page); + return 0; +} + +static int riscv_imsic_topei_rmw(RISCVIMSICState *imsic, uint32_t page, + target_ulong *val, target_ulong new_val, + target_ulong wr_mask) +{ + uint32_t base, topei = riscv_imsic_topei(imsic, page); + + /* Read pending and enabled interrupt with highest priority */ + if (val) { + *val = topei; + } + + /* Writes ignore value and clear top pending interrupt */ + if (topei && wr_mask) { + topei >>= IMSIC_TOPEI_IID_SHIFT; + base = page * imsic->num_irqs; + if (topei) { + imsic->eistate[base + topei] &= ~IMSIC_EISTATE_PENDING; + } + + riscv_imsic_update(imsic, page); + } + + return 0; +} + +static int riscv_imsic_eix_rmw(RISCVIMSICState *imsic, uint32_t page, + uint32_t num, bool pend, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + uint32_t i, base; + target_ulong mask; + uint32_t state = (pend) ? IMSIC_EISTATE_PENDING : IMSIC_EISTATE_ENABLED; + +#if TARGET_LONG_BITS == 64 + if (num & 0x1) { + return -EINVAL; + } + num >>= 1; +#endif + + if (num >= (imsic->num_irqs / TARGET_LONG_BITS)) { + return -EINVAL; + } + base = (page * imsic->num_irqs) + (num * TARGET_LONG_BITS); + + if (val) { + *val = 0; + for (i = 0; i < TARGET_LONG_BITS; i++) { + mask = (target_ulong)1 << i; + *val |= (imsic->eistate[base + i] & state) ? mask : 0; + } + } + + for (i = 0; i < TARGET_LONG_BITS; i++) { + /* Bit0 of eip0 and eie0 are read-only zero */ + if (!num && !i) { + continue; + } + + mask = (target_ulong)1 << i; + if (wr_mask & mask) { + if (new_val & mask) { + imsic->eistate[base + i] |= state; + } else { + imsic->eistate[base + i] &= ~state; + } + } + } + + riscv_imsic_update(imsic, page); + return 0; +} + +static int riscv_imsic_rmw(void *arg, target_ulong reg, target_ulong *val, + target_ulong new_val, target_ulong wr_mask) +{ + RISCVIMSICState *imsic = arg; + uint32_t isel, priv, virt, vgein, page; + + priv = AIA_IREG_PRIV(reg); + virt = AIA_IREG_VIRT(reg); + isel = AIA_IREG_ISEL(reg); + vgein = AIA_IREG_VGEIN(reg); + + if (imsic->mmode) { + if (priv == PRV_M && !virt) { + page = 0; + } else { + goto err; + } + } else { + if (priv == PRV_S) { + if (virt) { + if (vgein && vgein < imsic->num_pages) { + page = vgein; + } else { + goto err; + } + } else { + page = 0; + } + } else { + goto err; + } + } + + switch (isel) { + case ISELECT_IMSIC_EIDELIVERY: + return riscv_imsic_eidelivery_rmw(imsic, page, val, + new_val, wr_mask); + case ISELECT_IMSIC_EITHRESHOLD: + return riscv_imsic_eithreshold_rmw(imsic, page, val, + new_val, wr_mask); + case ISELECT_IMSIC_TOPEI: + return riscv_imsic_topei_rmw(imsic, page, val, new_val, wr_mask); + case ISELECT_IMSIC_EIP0 ... ISELECT_IMSIC_EIP63: + return riscv_imsic_eix_rmw(imsic, page, isel - ISELECT_IMSIC_EIP0, + true, val, new_val, wr_mask); + case ISELECT_IMSIC_EIE0 ... ISELECT_IMSIC_EIE63: + return riscv_imsic_eix_rmw(imsic, page, isel - ISELECT_IMSIC_EIE0, + false, val, new_val, wr_mask); + default: + break; + }; + +err: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid register priv=%d virt=%d isel=%d vgein=%d\n", + __func__, priv, virt, isel, vgein); + return -EINVAL; +} + +static uint64_t riscv_imsic_read(void *opaque, hwaddr addr, unsigned size) +{ + RISCVIMSICState *imsic = opaque; + + /* Reads must be 4 byte words */ + if ((addr & 0x3) != 0) { + goto err; + } + + /* Reads cannot be out of range */ + if (addr > IMSIC_MMIO_SIZE(imsic->num_pages)) { + goto err; + } + + return 0; + +err: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid register read 0x%" HWADDR_PRIx "\n", + __func__, addr); + return 0; +} + +static void riscv_imsic_write(void *opaque, hwaddr addr, uint64_t value, + unsigned size) +{ + RISCVIMSICState *imsic = opaque; + uint32_t page; + + /* Writes must be 4 byte words */ + if ((addr & 0x3) != 0) { + goto err; + } + + /* Writes cannot be out of range */ + if (addr > IMSIC_MMIO_SIZE(imsic->num_pages)) { + goto err; + } + + /* Writes only supported for MSI little-endian registers */ + page = addr >> IMSIC_MMIO_PAGE_SHIFT; + if ((addr & (IMSIC_MMIO_PAGE_SZ - 1)) == IMSIC_MMIO_PAGE_LE) { + if (value && (value < imsic->num_irqs)) { + imsic->eistate[(page * imsic->num_irqs) + value] |= + IMSIC_EISTATE_PENDING; + } + } + + /* Update CPU external interrupt status */ + riscv_imsic_update(imsic, page); + + return; + +err: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid register write 0x%" HWADDR_PRIx "\n", + __func__, addr); +} + +static const MemoryRegionOps riscv_imsic_ops = { + .read = riscv_imsic_read, + .write = riscv_imsic_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } +}; + +static void riscv_imsic_realize(DeviceState *dev, Error **errp) +{ + RISCVIMSICState *imsic = RISCV_IMSIC(dev); + RISCVCPU *rcpu = RISCV_CPU(qemu_get_cpu(imsic->hartid)); + CPUState *cpu = qemu_get_cpu(imsic->hartid); + CPURISCVState *env = cpu ? cpu->env_ptr : NULL; + + imsic->num_eistate = imsic->num_pages * imsic->num_irqs; + imsic->eidelivery = g_new0(uint32_t, imsic->num_pages); + imsic->eithreshold = g_new0(uint32_t, imsic->num_pages); + imsic->eistate = g_new0(uint32_t, imsic->num_eistate); + + memory_region_init_io(&imsic->mmio, OBJECT(dev), &riscv_imsic_ops, + imsic, TYPE_RISCV_IMSIC, + IMSIC_MMIO_SIZE(imsic->num_pages)); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &imsic->mmio); + + /* Claim the CPU interrupt to be triggered by this IMSIC */ + if (riscv_cpu_claim_interrupts(rcpu, + (imsic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { + error_report("%s already claimed", + (imsic->mmode) ? "MEIP" : "SEIP"); + exit(1); + } + + /* Create output IRQ lines */ + imsic->external_irqs = g_malloc(sizeof(qemu_irq) * imsic->num_pages); + qdev_init_gpio_out(dev, imsic->external_irqs, imsic->num_pages); + + /* Force select AIA feature and setup CSR read-modify-write callback */ + if (env) { + riscv_set_feature(env, RISCV_FEATURE_AIA); + if (!imsic->mmode) { + riscv_cpu_set_geilen(env, imsic->num_pages - 1); + } + riscv_cpu_set_aia_ireg_rmw_fn(env, (imsic->mmode) ? PRV_M : PRV_S, + riscv_imsic_rmw, imsic); + } + + msi_nonbroken = true; +} + +static Property riscv_imsic_properties[] = { + DEFINE_PROP_BOOL("mmode", RISCVIMSICState, mmode, 0), + DEFINE_PROP_UINT32("hartid", RISCVIMSICState, hartid, 0), + DEFINE_PROP_UINT32("num-pages", RISCVIMSICState, num_pages, 0), + DEFINE_PROP_UINT32("num-irqs", RISCVIMSICState, num_irqs, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static const VMStateDescription vmstate_riscv_imsic = { + .name = "riscv_imsic", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_VARRAY_UINT32(eidelivery, RISCVIMSICState, + num_pages, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(eithreshold, RISCVIMSICState, + num_pages, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(eistate, RISCVIMSICState, + num_eistate, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_END_OF_LIST() + } +}; + +static void riscv_imsic_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + device_class_set_props(dc, riscv_imsic_properties); + dc->realize = riscv_imsic_realize; + dc->vmsd = &vmstate_riscv_imsic; +} + +static const TypeInfo riscv_imsic_info = { + .name = TYPE_RISCV_IMSIC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(RISCVIMSICState), + .class_init = riscv_imsic_class_init, +}; + +static void riscv_imsic_register_types(void) +{ + type_register_static(&riscv_imsic_info); +} + +type_init(riscv_imsic_register_types) + +/* + * Create IMSIC device. + */ +DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode, + uint32_t num_pages, uint32_t num_ids) +{ + DeviceState *dev = qdev_new(TYPE_RISCV_IMSIC); + CPUState *cpu = qemu_get_cpu(hartid); + uint32_t i; + + assert(!(addr & (IMSIC_MMIO_PAGE_SZ - 1))); + if (mmode) { + assert(num_pages == 1); + } else { + assert(num_pages >= 1 && num_pages <= (IRQ_LOCAL_GUEST_MAX + 1)); + } + assert(IMSIC_MIN_ID <= num_ids); + assert(num_ids <= IMSIC_MAX_ID); + assert((num_ids & IMSIC_MIN_ID) == IMSIC_MIN_ID); + + qdev_prop_set_bit(dev, "mmode", mmode); + qdev_prop_set_uint32(dev, "hartid", hartid); + qdev_prop_set_uint32(dev, "num-pages", num_pages); + qdev_prop_set_uint32(dev, "num-irqs", num_ids + 1); + + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + + for (i = 0; i < num_pages; i++) { + if (!i) { + qdev_connect_gpio_out_named(dev, NULL, i, + qdev_get_gpio_in(DEVICE(cpu), + (mmode) ? IRQ_M_EXT : IRQ_S_EXT)); + } else { + qdev_connect_gpio_out_named(dev, NULL, i, + qdev_get_gpio_in(DEVICE(cpu), + IRQ_LOCAL_MAX + i - 1)); + } + } + + return dev; +} diff --git a/include/hw/intc/riscv_imsic.h b/include/hw/intc/riscv_imsic.h new file mode 100644 index 0000000000..58c2aaa8dc --- /dev/null +++ b/include/hw/intc/riscv_imsic.h @@ -0,0 +1,68 @@ +/* + * RISC-V IMSIC (Incoming Message Signal Interrupt Controller) interface + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#ifndef HW_RISCV_IMSIC_H +#define HW_RISCV_IMSIC_H + +#include "hw/sysbus.h" +#include "qom/object.h" + +#define TYPE_RISCV_IMSIC "riscv.imsic" + +typedef struct RISCVIMSICState RISCVIMSICState; +DECLARE_INSTANCE_CHECKER(RISCVIMSICState, RISCV_IMSIC, TYPE_RISCV_IMSIC) + +#define IMSIC_MMIO_PAGE_SHIFT 12 +#define IMSIC_MMIO_PAGE_SZ (1UL << IMSIC_MMIO_PAGE_SHIFT) +#define IMSIC_MMIO_SIZE(__num_pages) ((__num_pages) * IMSIC_MMIO_PAGE_SZ) + +#define IMSIC_MMIO_HART_GUEST_MAX_BTIS 6 +#define IMSIC_MMIO_GROUP_MIN_SHIFT 24 + +#define IMSIC_HART_NUM_GUESTS(__guest_bits) \ + (1U << (__guest_bits)) +#define IMSIC_HART_SIZE(__guest_bits) \ + (IMSIC_HART_NUM_GUESTS(__guest_bits) * IMSIC_MMIO_PAGE_SZ) +#define IMSIC_GROUP_NUM_HARTS(__hart_bits) \ + (1U << (__hart_bits)) +#define IMSIC_GROUP_SIZE(__hart_bits, __guest_bits) \ + (IMSIC_GROUP_NUM_HARTS(__hart_bits) * IMSIC_HART_SIZE(__guest_bits)) + +struct RISCVIMSICState { + /*< private >*/ + SysBusDevice parent_obj; + qemu_irq *external_irqs; + + /*< public >*/ + MemoryRegion mmio; + uint32_t num_eistate; + uint32_t *eidelivery; + uint32_t *eithreshold; + uint32_t *eistate; + + /* config */ + bool mmode; + uint32_t hartid; + uint32_t num_pages; + uint32_t num_irqs; +}; + +DeviceState *riscv_imsic_create(hwaddr addr, uint32_t hartid, bool mmode, + uint32_t num_pages, uint32_t num_ids); + +#endif From patchwork Tue Oct 26 06:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584129 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20849C433F5 for ; Tue, 26 Oct 2021 08:09:56 +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 831F2610A0 for ; Tue, 26 Oct 2021 08:09:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 831F2610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:39784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfHWs-0006bp-HT for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 04:09:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBz-0003kr-NO; Tue, 26 Oct 2021 02:44:17 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:57198) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBq-0002ui-VJ; Tue, 26 Oct 2021 02:44:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1635230646; x=1666766646; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=4ohb9pLFrIaui7DcAR7ePvhMEq/w3F/txExAAUA5uWQ=; b=k+9bddKAh+5CvZAuZnarcUgRwx7d4LtPkjVvxL9HKKbSMQV2TM58treU MCtQAMel7GyRQe1XX2L8DDZZUdnGhZpmxoocn1K8q7foGx8HK5EzsxmDG kMByGUOs2vHZ67O+c3g8t5S+dgDex9wUX69vF11FXeLJM0r9mpCort753 oxPz3eZvoOn+BqHvhYSwoE52IybyHdxW2YLoeHMjrnLMZwS6Gtn+iLukt SIf3ej8vEo2uD0TyLeRzzryTM8ITtAr6eOpZEwImjjzLogiDU5jwB19uo SVJsImwfSs8WojLQnGn8I3WoU0ybUuJ02NYjDsnqok/iBh0Qb37lMWjkq g==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="295585017" Received: from mail-dm6nam11lp2173.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.173]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:44:03 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KgfJNQ8TnY1s6q5KmvIe5h0i7x+/F2AjXo4ww6mAkrGxbV0pwVWvrpNwpzZ0TdlQHR63XPJARcd4PYeqrfBJFBp4DQfIMjreC0dx3/HXWh3KGJGBfPF/xkN4dwt2vUYwzJ3ZQKPoOToR3hmYZmXjtELZ0BQrckts+31LkC+aIAnCYYNAOjSEGWpP6IlcHc07dRI9T4+sPGft1Jg4SYTmnOSx3v59SCUF+R1GNNW2K9hfpYQfqtX/jKwm9sdJE0GU3HGb1b+wP2avQmhpwq34/ull9i2AqKiMGAFr2U327gzPCgbfGRl9pul2LE/xH9OrdZbJGrFDt8jRPeJoV/fkbg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Wu8Ll/zwhdSR96pXgwDH10frWRXFpgZqYSGof5UZFhg=; b=RRRAyaJn0ov6qDZIF3pa3FJHOs8wSQBnpCJYNNpF60xLRYD+ptWc9EnLy3k3jikTOB/vPQp0aje+52fCJQtaPwQYZhnviAQnZaX/NwiEGgjL7Pr901sQ4azpgCoqszWRDoiCxuNBLjSoj+6L/BLoJO5dxQSuqEMQCZDTTWn6QwXxALUb14ydf2IT84261qcvCjm917uHkOftB3ZhdzT7By7lTPuk1hgSl1fBTX4nOChriKOVh8x8613gKQrHOh16AouU4qfuak+g5UmkYza1j7mHyWoNttygMOnHSXu6MR+yZCQHqfftdUH60GFAksIA+/SNt8zwqLHKqfvlaelGNw== 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=Wu8Ll/zwhdSR96pXgwDH10frWRXFpgZqYSGof5UZFhg=; b=WfSMkJj1fV/+KbPTPNHiec4M11xPRyE39rSMd/wiRbM4sKBLGeb3emqmH98PQMJV3mw778bXeK3FZ83o3HrqpUIWbyLzOpl87quBW/GQKEfyR1c92zlVgRblDNHjPQR++p8jtdMKD1aROgPxwfmBl584V6G3hLIAKwgVOD+UO8Y= 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 CO6PR04MB7825.namprd04.prod.outlook.com (2603:10b6:303:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Tue, 26 Oct 2021 06:44:02 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:44:01 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 21/22] hw/riscv: virt: Add optional AIA IMSIC support to virt machine Date: Tue, 26 Oct 2021 12:12:26 +0530 Message-Id: <20211026064227.2014502-22-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:43:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fefbbf0e-7bf3-443e-b2e5-08d9984bfef8 X-MS-TrafficTypeDiagnostic: CO6PR04MB7825: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:935; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pH3CuqZ/tMhytsMe0smlbI4HK9WFzfH7xFG4Caj4pQjOlbl4i4tVtfmH/cFO6PwaD8JnmrBjiIy5LsjPKm2PmNIqUbFMxlj55cmbwWWLJFbXcOHyzjEiBqeobGn2N5zbuODhVrD/zrIzj/gdvNfql6TByi3cfmcCglI1+FLCXGsD4L7pa0VIPX7/jG3U54IORmosJsJNHZZ9NtrRjSukNWxQXphuRl+tfIyqowGtU2Jp3BJZAHyJDXc1kSC8G5ueoMhveHpDqoXttyF441BeH9JGLpQbKnQUohhOlYj6BJzcDBFYbqnaXrqEVxTsbIE0zcosO5g1BoEPejW8+3wTCbZlB3cIRC5/vMW/w1m2pSA4AEJ3F4FBQaDN0X9UVdnUhz+m/lyu3Q62v9n/dhON8XIb2Igx8VrFqLgNxvpEXAFxIlzXfxIidyJ2ufLdYpLiFf6i60ApNkG4xtYbE5Nu33YlZ6PfX0iao8BqO0XlfVTkvrGOj4L0t0Lg8OE9+8RqmhB/0qBVwT8PO9sm5S5XRrFa/gpl5SupfL18nh2Ah5ByvIRgyB0F9An6Zlcr9MhWsbGB12vw33r3KEG8+/l4QPqzqzz+Ddt3RwZ67YmMVM4OaGhn9qRUMpE8z1oe/i3GhCbxW5AugBl4TEs7KJ0HUEEqUzWbB+EoWiV4/6kKEwheiMZFS9ASbmuHvXnFalsMucBa+DxGqEjuV47v1xyp4g== 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)(366004)(316002)(2906002)(66476007)(8936002)(66556008)(55016002)(82960400001)(52116002)(5660300002)(508600001)(186003)(66946007)(8676002)(36756003)(54906003)(38350700002)(38100700002)(6666004)(4326008)(30864003)(110136005)(1076003)(86362001)(26005)(2616005)(44832011)(956004)(8886007)(7696005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O6NsfYXwJQtApgDjRgOb+ZJ2DsuY2a7UiL3KuWIbH9Qh+7FSd/4PTqSqFQ5o9hi+EWSjwoxiHVG2Fy5sSgX294H7j7/rFgZu1Xg7fiPzQl/4sWeCPcCDB1UNfFTKKw3hI3OcZCUgWO4KfPR8zydozNe+ocG4AQ3IkG9JnQyDai41J5EEw7QjbneEDNIFnStW+ya9EuFDSqx+Tb7rUC6cqnWm6tMPa4REQLmKP+psnBLDnVb/aPvWlfxElPv2lg+p1VIxZNNCBNOoP6FZ2rfQGuQ0VZcWdlYfYSp/BsATOcDN9hW/vlu2giyAEMDDDnaUxnaLvpyK3O+yS/aNSgfrUbusA5KQKZDQRyD0YC6ukUmnA1/bfrH0uTFxJ//QUB7LIImmxF9Si8vfujVwZ8Xo0u0fAYVNGVjUnNURuFpU4xvRquu/AgIQsIeq/irkzk6gtCF+s87YsW4zoZ5Y3CCEtozBVS+xji6wAA6/plz5zVrYHONgD0CZWhRhNvPAGPqxQqS61HD8w71DkKYmKikSop8cwdth8yBLo6ispEGt4XdnALN7tLrPdnEgPgChcGPANHiAFJd1FO59Y7+SbtkLlCS3cBxmR/py/Dgf1/wUiWU3A5kxeKg0bN87NZsV/8DAM5Bij6/S+uA3bv0ZP06FTXVm/0OIsyqqnwFm9tt+bTYQEcs92FMizk7wYLeT5Nz0Ry0OMdeiV+b/Yko+ui0rUJcq3Z1Q34t+zuE8FM1wAv1n0qclQRTuCcu7GnDQIczXJf64Tq51rVaeM6cmYKlYg0zGyluW5pYmRAq3j6zYMNAYnjCDuyiXfmMB3W4WHDIZzm+Ph3HpdawVwqMHIXh5DQNwL7qWQAyyy5zJp1jH9VTmRtvY6PlAd/TiPrpHQy4ykajHvb739WRcs5k6IOB4uwaPyRcoFbFnyjWa1HZDo8wV8n3AQ45y4GRhtt/SHBwmpv/NL8crPnijOtWI+zO4XwiiWYbL0vPhT9MvM6OiEQq9/Wx1K9WR4podVOzeILSpj/GMwAaYWvNHrBerP3PRcwF5f2P0t0i1ex6ebpg0b1I4EWhCu+HtZ4cAIJS472gDwo8Rccf3PjPznHbIcwtPtAEyRWSDoLPfiSUY6hiRv9K5jC+jLJ3+00l2x0ceS3j4PMhFEqJCVrnc7f2+rT4tELPhyu4pNeAixy7bV4OVN39byJPFeK9bBPVB2dfEv1b0LgFN1NpMRG7oINkSMqS5vVe+0QshQcWiSnH2BlaMcw2nJ4gpQzTAN7/8Y57tj4h8euIdNKGPtB7ZfA2jjWryM2+lX2BYQ5NyJjayVBrmUUxLtPucszqtvQJNQqmSmAK37oU8MJTjcSyBwhBlaXatjowacORxbwbEi7Al6NSGJk4CgyAalK6hef4igevtB+qZLRGGnQZNpyNFyDR/J0sT2wr1iDiV11RJ6XyX8io5cCshCegKJCyLTIY47rponpqKo74OukPH/OzGXNpQFIa0L7dPPcTzZZXMlyYaH1lJkNxmcS0fLy6cB2719KWEBTYm6ANagXomWaF4F/GpVsygyj2e9JyxA167W7fmLFbs6RnAdZQ68XpdqXjF18lYzFEWYMMTLfT23+btph1kj6Ma2dj6T2jO6RGzDBOBTACc04w= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: fefbbf0e-7bf3-443e-b2e5-08d9984bfef8 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:44:01.8660 (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: pNPjbt3agsrcZshxLnAv35K13O9BBj4QNx8evT3B/ddBC5ByWwxwdb6ngoGsRnmwMYkCeRAEwJ0uAmdktgc1Cw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7825 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We extend virt machine to emulate both AIA IMSIC and AIA APLIC devices only when "aia=aplic-imsic" parameter is passed along with machine name in the QEMU command-line. The AIA IMSIC is only a per-HART MSI controller so we use AIA APLIC in MSI-mode to forward all wired interrupts as MSIs to the AIA IMSIC. We also provide "aia-guests=" parameter which can be used to specify number of VS-level AIA IMSIC Guests MMIO pages for each HART. Signed-off-by: Anup Patel --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 430 ++++++++++++++++++++++++++++++++-------- include/hw/riscv/virt.h | 16 +- 3 files changed, 363 insertions(+), 84 deletions(-) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index c30bb7cb6c..91bb9d21c4 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -43,6 +43,7 @@ config RISCV_VIRT select SERIAL select RISCV_ACLINT select RISCV_APLIC + select RISCV_IMSIC select SIFIVE_PLIC select SIFIVE_TEST select VIRTIO_MMIO diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 4e21b485aa..4dcabcc8ef 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -34,6 +34,7 @@ #include "hw/riscv/numa.h" #include "hw/intc/riscv_aclint.h" #include "hw/intc/riscv_aplic.h" +#include "hw/intc/riscv_imsic.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_test.h" #include "chardev/char.h" @@ -43,6 +44,13 @@ #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +#define VIRT_IMSIC_GROUP_MAX_SIZE (1U << IMSIC_MMIO_GROUP_MIN_SHIFT) +#define VIRT_IMSIC_MAX_SIZE (VIRT_SOCKETS_MAX * \ + VIRT_IMSIC_GROUP_MAX_SIZE) +#if 0x4000000 < VIRT_IMSIC_MAX_SIZE +#error "Can't accomodate IMSIC in address space" +#endif + static const MemMapEntry virt_memmap[] = { [VIRT_DEBUG] = { 0x0, 0x100 }, [VIRT_MROM] = { 0x1000, 0xf000 }, @@ -58,6 +66,8 @@ static const MemMapEntry virt_memmap[] = { [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, [VIRT_FW_CFG] = { 0x10100000, 0x18 }, [VIRT_FLASH] = { 0x20000000, 0x4000000 }, + [VIRT_IMSIC_M] = { 0x24000000, 0x4000000 }, + [VIRT_IMSIC_S] = { 0x28000000, 0x4000000 }, [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }, [VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 }, [VIRT_DRAM] = { 0x80000000, 0x0 }, @@ -309,7 +319,7 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, { int cpu; char *name; - unsigned long addr; + unsigned long addr, size; uint32_t aclint_cells_size; uint32_t *aclint_mswi_cells; uint32_t *aclint_sswi_cells; @@ -330,29 +340,38 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, } aclint_cells_size = s->soc[socket].num_harts * sizeof(uint32_t) * 2; - addr = memmap[VIRT_CLINT].base + (memmap[VIRT_CLINT].size * socket); - name = g_strdup_printf("/soc/mswi@%lx", addr); - qemu_fdt_add_subnode(mc->fdt, name); - qemu_fdt_setprop_string(mc->fdt, name, "compatible", "riscv,aclint-mswi"); - qemu_fdt_setprop_cells(mc->fdt, name, "reg", - 0x0, addr, 0x0, RISCV_ACLINT_SWI_SIZE); - qemu_fdt_setprop(mc->fdt, name, "interrupts-extended", - aclint_mswi_cells, aclint_cells_size); - qemu_fdt_setprop(mc->fdt, name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop_cell(mc->fdt, name, "#interrupt-cells", 0); - riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); - g_free(name); + if (s->aia_type != VIRT_AIA_TYPE_APLIC_IMSIC) { + addr = memmap[VIRT_CLINT].base + (memmap[VIRT_CLINT].size * socket); + name = g_strdup_printf("/soc/mswi@%lx", addr); + qemu_fdt_add_subnode(mc->fdt, name); + qemu_fdt_setprop_string(mc->fdt, name, "compatible", + "riscv,aclint-mswi"); + qemu_fdt_setprop_cells(mc->fdt, name, "reg", + 0x0, addr, 0x0, RISCV_ACLINT_SWI_SIZE); + qemu_fdt_setprop(mc->fdt, name, "interrupts-extended", + aclint_mswi_cells, aclint_cells_size); + qemu_fdt_setprop(mc->fdt, name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(mc->fdt, name, "#interrupt-cells", 0); + riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); + g_free(name); + } - addr = memmap[VIRT_CLINT].base + RISCV_ACLINT_SWI_SIZE + - (memmap[VIRT_CLINT].size * socket); + if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) { + addr = memmap[VIRT_CLINT].base + + (RISCV_ACLINT_DEFAULT_MTIMER_SIZE * socket); + size = RISCV_ACLINT_DEFAULT_MTIMER_SIZE; + } else { + addr = memmap[VIRT_CLINT].base + RISCV_ACLINT_SWI_SIZE + + (memmap[VIRT_CLINT].size * socket); + size = memmap[VIRT_CLINT].size - RISCV_ACLINT_SWI_SIZE; + } name = g_strdup_printf("/soc/mtimer@%lx", addr); qemu_fdt_add_subnode(mc->fdt, name); qemu_fdt_setprop_string(mc->fdt, name, "compatible", "riscv,aclint-mtimer"); qemu_fdt_setprop_cells(mc->fdt, name, "reg", 0x0, addr + RISCV_ACLINT_DEFAULT_MTIME, - 0x0, memmap[VIRT_CLINT].size - RISCV_ACLINT_SWI_SIZE - - RISCV_ACLINT_DEFAULT_MTIME, + 0x0, size - RISCV_ACLINT_DEFAULT_MTIME, 0x0, addr + RISCV_ACLINT_DEFAULT_MTIMECMP, 0x0, RISCV_ACLINT_DEFAULT_MTIME); qemu_fdt_setprop(mc->fdt, name, "interrupts-extended", @@ -360,19 +379,22 @@ static void create_fdt_socket_aclint(RISCVVirtState *s, riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); g_free(name); - addr = memmap[VIRT_ACLINT_SSWI].base + - (memmap[VIRT_ACLINT_SSWI].size * socket); - name = g_strdup_printf("/soc/sswi@%lx", addr); - qemu_fdt_add_subnode(mc->fdt, name); - qemu_fdt_setprop_string(mc->fdt, name, "compatible", "riscv,aclint-sswi"); - qemu_fdt_setprop_cells(mc->fdt, name, "reg", - 0x0, addr, 0x0, memmap[VIRT_ACLINT_SSWI].size); - qemu_fdt_setprop(mc->fdt, name, "interrupts-extended", - aclint_sswi_cells, aclint_cells_size); - qemu_fdt_setprop(mc->fdt, name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop_cell(mc->fdt, name, "#interrupt-cells", 0); - riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); - g_free(name); + if (s->aia_type != VIRT_AIA_TYPE_APLIC_IMSIC) { + addr = memmap[VIRT_ACLINT_SSWI].base + + (memmap[VIRT_ACLINT_SSWI].size * socket); + name = g_strdup_printf("/soc/sswi@%lx", addr); + qemu_fdt_add_subnode(mc->fdt, name); + qemu_fdt_setprop_string(mc->fdt, name, "compatible", + "riscv,aclint-sswi"); + qemu_fdt_setprop_cells(mc->fdt, name, "reg", + 0x0, addr, 0x0, memmap[VIRT_ACLINT_SSWI].size); + qemu_fdt_setprop(mc->fdt, name, "interrupts-extended", + aclint_sswi_cells, aclint_cells_size); + qemu_fdt_setprop(mc->fdt, name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop_cell(mc->fdt, name, "#interrupt-cells", 0); + riscv_socket_fdt_write_id(mc, mc->fdt, name, socket); + g_free(name); + } g_free(aclint_mswi_cells); g_free(aclint_mtimer_cells); @@ -425,10 +447,145 @@ static void create_fdt_socket_plic(RISCVVirtState *s, g_free(plic_cells); } -static void create_fdt_socket_aia(RISCVVirtState *s, - const MemMapEntry *memmap, int socket, - uint32_t *phandle, uint32_t *intc_phandles, - uint32_t *aplic_phandles) +static uint32_t imsic_num_bits(uint32_t count) +{ + uint32_t ret = 0; + + while (BIT(ret) < count) { + ret++; + } + + return ret; +} + +static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, + uint32_t *phandle, uint32_t *intc_phandles, + uint32_t *msi_m_phandle, uint32_t *msi_s_phandle) +{ + int cpu, socket; + char *imsic_name; + MachineState *mc = MACHINE(s); + uint32_t imsic_max_hart_per_socket, imsic_guest_bits; + uint32_t *imsic_cells, *imsic_regs, imsic_addr, imsic_size; + + *msi_m_phandle = (*phandle)++; + *msi_s_phandle = (*phandle)++; + imsic_cells = g_new0(uint32_t, mc->smp.cpus * 2); + imsic_regs = g_new0(uint32_t, riscv_socket_count(mc) * 4); + + /* M-level IMSIC node */ + for (cpu = 0; cpu < mc->smp.cpus; cpu++) { + imsic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + imsic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_M_EXT); + } + imsic_max_hart_per_socket = 0; + for (socket = 0; socket < riscv_socket_count(mc); socket++) { + imsic_addr = memmap[VIRT_IMSIC_M].base + + socket * VIRT_IMSIC_GROUP_MAX_SIZE; + imsic_size = IMSIC_HART_SIZE(0) * s->soc[socket].num_harts; + imsic_regs[socket * 4 + 0] = 0; + imsic_regs[socket * 4 + 1] = cpu_to_be32(imsic_addr); + imsic_regs[socket * 4 + 2] = 0; + imsic_regs[socket * 4 + 3] = cpu_to_be32(imsic_size); + if (imsic_max_hart_per_socket < s->soc[socket].num_harts) { + imsic_max_hart_per_socket = s->soc[socket].num_harts; + } + } + imsic_name = g_strdup_printf("/soc/imsics@%lx", + memmap[VIRT_IMSIC_M].base); + qemu_fdt_add_subnode(mc->fdt, imsic_name); + qemu_fdt_setprop_string(mc->fdt, imsic_name, "compatible", + "riscv,imsics"); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "#interrupt-cells", + FDT_IMSIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupt-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "msi-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupts-extended", + imsic_cells, mc->smp.cpus * sizeof(uint32_t) * 2); + qemu_fdt_setprop(mc->fdt, imsic_name, "reg", imsic_regs, + riscv_socket_count(mc) * sizeof(uint32_t) * 4); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,num-ids", + VIRT_IRQCHIP_NUM_MSIS); + qemu_fdt_setprop_cells(mc->fdt, imsic_name, "riscv,ipi-range", + VIRT_IRQCHIP_BASE_IPI, VIRT_IRQCHIP_NUM_IPIS); + if (riscv_socket_count(mc) > 1) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,hart-index-bits", + imsic_num_bits(imsic_max_hart_per_socket)); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-bits", + imsic_num_bits(riscv_socket_count(mc))); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-shift", + IMSIC_MMIO_GROUP_MIN_SHIFT); + } + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_m_phandle); + g_free(imsic_name); + + /* S-level IMSIC node */ + for (cpu = 0; cpu < mc->smp.cpus; cpu++) { + imsic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + imsic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT); + } + imsic_guest_bits = imsic_num_bits(s->aia_guests + 1); + imsic_max_hart_per_socket = 0; + for (socket = 0; socket < riscv_socket_count(mc); socket++) { + imsic_addr = memmap[VIRT_IMSIC_S].base + + socket * VIRT_IMSIC_GROUP_MAX_SIZE; + imsic_size = IMSIC_HART_SIZE(imsic_guest_bits) * + s->soc[socket].num_harts; + imsic_regs[socket * 4 + 0] = 0; + imsic_regs[socket * 4 + 1] = cpu_to_be32(imsic_addr); + imsic_regs[socket * 4 + 2] = 0; + imsic_regs[socket * 4 + 3] = cpu_to_be32(imsic_size); + if (imsic_max_hart_per_socket < s->soc[socket].num_harts) { + imsic_max_hart_per_socket = s->soc[socket].num_harts; + } + } + imsic_name = g_strdup_printf("/soc/imsics@%lx", + memmap[VIRT_IMSIC_S].base); + qemu_fdt_add_subnode(mc->fdt, imsic_name); + qemu_fdt_setprop_string(mc->fdt, imsic_name, "compatible", + "riscv,imsics"); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "#interrupt-cells", + FDT_IMSIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupt-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "msi-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupts-extended", + imsic_cells, mc->smp.cpus * sizeof(uint32_t) * 2); + qemu_fdt_setprop(mc->fdt, imsic_name, "reg", imsic_regs, + riscv_socket_count(mc) * sizeof(uint32_t) * 4); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,num-ids", + VIRT_IRQCHIP_NUM_MSIS); + qemu_fdt_setprop_cells(mc->fdt, imsic_name, "riscv,ipi-range", + VIRT_IRQCHIP_BASE_IPI, VIRT_IRQCHIP_NUM_IPIS); + if (imsic_guest_bits) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,guest-index-bits", + imsic_guest_bits); + } + if (riscv_socket_count(mc) > 1) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,hart-index-bits", + imsic_num_bits(imsic_max_hart_per_socket)); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-bits", + imsic_num_bits(riscv_socket_count(mc))); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-shift", + IMSIC_MMIO_GROUP_MIN_SHIFT); + } + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_s_phandle); + g_free(imsic_name); + + g_free(imsic_regs); + g_free(imsic_cells); +} + +static void create_fdt_socket_aplic(RISCVVirtState *s, + const MemMapEntry *memmap, int socket, + uint32_t msi_m_phandle, + uint32_t msi_s_phandle, + uint32_t *phandle, + uint32_t *intc_phandles, + uint32_t *aplic_phandles) { int cpu; char *aplic_name; @@ -454,8 +611,13 @@ static void create_fdt_socket_aia(RISCVVirtState *s, qemu_fdt_setprop_cell(mc->fdt, aplic_name, "#interrupt-cells", FDT_APLIC_INT_CELLS); qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", - aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + if (s->aia_type == VIRT_AIA_TYPE_APLIC) { + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + } else { + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "msi-parent", + msi_m_phandle); + } qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_M].size); qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", @@ -481,8 +643,13 @@ static void create_fdt_socket_aia(RISCVVirtState *s, qemu_fdt_setprop_cell(mc->fdt, aplic_name, "#interrupt-cells", FDT_APLIC_INT_CELLS); qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", - aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + if (s->aia_type == VIRT_AIA_TYPE_APLIC) { + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + } else { + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "msi-parent", + msi_s_phandle); + } qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_S].size); qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", @@ -499,13 +666,14 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, bool is_32_bit, uint32_t *phandle, uint32_t *irq_mmio_phandle, uint32_t *irq_pcie_phandle, - uint32_t *irq_virtio_phandle) + uint32_t *irq_virtio_phandle, + uint32_t *msi_pcie_phandle) { - int socket; char *clust_name; - uint32_t *intc_phandles; + int socket, phandle_pos; MachineState *mc = MACHINE(s); - uint32_t xplic_phandles[MAX_NODES]; + uint32_t msi_m_phandle = 0, msi_s_phandle = 0; + uint32_t *intc_phandles, xplic_phandles[MAX_NODES]; qemu_fdt_add_subnode(mc->fdt, "/cpus"); qemu_fdt_setprop_cell(mc->fdt, "/cpus", "timebase-frequency", @@ -514,35 +682,53 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, qemu_fdt_setprop_cell(mc->fdt, "/cpus", "#address-cells", 0x1); qemu_fdt_add_subnode(mc->fdt, "/cpus/cpu-map"); + intc_phandles = g_new0(uint32_t, mc->smp.cpus); + + phandle_pos = mc->smp.cpus; for (socket = (riscv_socket_count(mc) - 1); socket >= 0; socket--) { + phandle_pos -= s->soc[socket].num_harts; + clust_name = g_strdup_printf("/cpus/cpu-map/cluster%d", socket); qemu_fdt_add_subnode(mc->fdt, clust_name); - intc_phandles = g_new0(uint32_t, s->soc[socket].num_harts); - create_fdt_socket_cpus(s, socket, clust_name, phandle, - is_32_bit, intc_phandles); + is_32_bit, &intc_phandles[phandle_pos]); create_fdt_socket_memory(s, memmap, socket); + g_free(clust_name); + if (s->have_aclint) { - create_fdt_socket_aclint(s, memmap, socket, intc_phandles); + create_fdt_socket_aclint(s, memmap, socket, + &intc_phandles[phandle_pos]); } else { - create_fdt_socket_clint(s, memmap, socket, intc_phandles); + create_fdt_socket_clint(s, memmap, socket, + &intc_phandles[phandle_pos]); } + } + + if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) { + create_fdt_imsic(s, memmap, phandle, intc_phandles, + &msi_m_phandle, &msi_s_phandle); + *msi_pcie_phandle = msi_s_phandle; + } + + phandle_pos = mc->smp.cpus; + for (socket = (riscv_socket_count(mc) - 1); socket >= 0; socket--) { + phandle_pos -= s->soc[socket].num_harts; if (s->aia_type == VIRT_AIA_TYPE_NONE) { create_fdt_socket_plic(s, memmap, socket, phandle, - intc_phandles, xplic_phandles); + &intc_phandles[phandle_pos], xplic_phandles); } else { - create_fdt_socket_aia(s, memmap, socket, phandle, - intc_phandles, xplic_phandles); + create_fdt_socket_aplic(s, memmap, socket, + msi_m_phandle, msi_s_phandle, phandle, + &intc_phandles[phandle_pos], xplic_phandles); } - - g_free(intc_phandles); - g_free(clust_name); } + g_free(intc_phandles); + for (socket = 0; socket < riscv_socket_count(mc); socket++) { if (socket == 0) { *irq_mmio_phandle = xplic_phandles[socket]; @@ -590,7 +776,8 @@ static void create_fdt_virtio(RISCVVirtState *s, const MemMapEntry *memmap, } static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, - uint32_t irq_pcie_phandle) + uint32_t irq_pcie_phandle, + uint32_t msi_pcie_phandle) { char *name; MachineState *mc = MACHINE(s); @@ -610,6 +797,9 @@ static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, qemu_fdt_setprop_cells(mc->fdt, name, "bus-range", 0, memmap[VIRT_PCIE_ECAM].size / PCIE_MMCFG_SIZE_MIN - 1); qemu_fdt_setprop(mc->fdt, name, "dma-coherent", NULL, 0); + if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) { + qemu_fdt_setprop_cell(mc->fdt, name, "msi-parent", msi_pcie_phandle); + } qemu_fdt_setprop_cells(mc->fdt, name, "reg", 0, memmap[VIRT_PCIE_ECAM].base, 0, memmap[VIRT_PCIE_ECAM].size); qemu_fdt_setprop_sized_cells(mc->fdt, name, "ranges", @@ -735,7 +925,7 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, uint64_t mem_size, const char *cmdline, bool is_32_bit) { MachineState *mc = MACHINE(s); - uint32_t phandle = 1, irq_mmio_phandle = 1; + uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1; uint32_t irq_pcie_phandle = 1, irq_virtio_phandle = 1; if (mc->dtb) { @@ -765,11 +955,12 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, qemu_fdt_setprop_cell(mc->fdt, "/soc", "#address-cells", 0x2); create_fdt_sockets(s, memmap, is_32_bit, &phandle, - &irq_mmio_phandle, &irq_pcie_phandle, &irq_virtio_phandle); + &irq_mmio_phandle, &irq_pcie_phandle, &irq_virtio_phandle, + &msi_pcie_phandle); create_fdt_virtio(s, memmap, irq_virtio_phandle); - create_fdt_pcie(s, memmap, irq_pcie_phandle); + create_fdt_pcie(s, memmap, irq_pcie_phandle, msi_pcie_phandle); create_fdt_reset(s, memmap, &phandle); @@ -902,30 +1093,55 @@ static DeviceState *virt_create_plic(const MemMapEntry *memmap, int socket, return ret; } -static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, +static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, const MemMapEntry *memmap, int socket, int base_hartid, int hart_count) { + int i; + hwaddr addr; + uint32_t guest_bits; DeviceState *aplic_m; + bool msimode = (aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) ? true : false; + + if (msimode) { + /* Per-socket M-level IMSICs */ + addr = memmap[VIRT_IMSIC_M].base + socket * VIRT_IMSIC_GROUP_MAX_SIZE; + for (i = 0; i < hart_count; i++) { + riscv_imsic_create(addr + i * IMSIC_HART_SIZE(0), + base_hartid + i, true, 1, + VIRT_IRQCHIP_NUM_MSIS); + } + + /* Per-socket S-level IMSICs */ + guest_bits = imsic_num_bits(aia_guests + 1); + addr = memmap[VIRT_IMSIC_S].base + socket * VIRT_IMSIC_GROUP_MAX_SIZE; + for (i = 0; i < hart_count; i++) { + riscv_imsic_create(addr + i * IMSIC_HART_SIZE(guest_bits), + base_hartid + i, false, 1 + aia_guests, + VIRT_IRQCHIP_NUM_MSIS); + } + } /* Per-socket M-level APLIC */ aplic_m = riscv_aplic_create( memmap[VIRT_APLIC_M].base + socket * memmap[VIRT_APLIC_M].size, memmap[VIRT_APLIC_M].size, - base_hartid, hart_count, + (msimode) ? 0 : base_hartid, + (msimode) ? 0 : hart_count, VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_PRIO_BITS, - false, true, NULL); + msimode, true, NULL); if (aplic_m) { /* Per-socket S-level APLIC */ riscv_aplic_create( memmap[VIRT_APLIC_S].base + socket * memmap[VIRT_APLIC_S].size, memmap[VIRT_APLIC_S].size, - base_hartid, hart_count, + (msimode) ? 0 : base_hartid, + (msimode) ? 0 : hart_count, VIRT_IRQCHIP_NUM_SOURCES, VIRT_IRQCHIP_NUM_PRIO_BITS, - false, false, aplic_m); + msimode, false, aplic_m); } return aplic_m; @@ -984,23 +1200,38 @@ static void virt_machine_init(MachineState *machine) hart_count, &error_abort); sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_abort); - /* Per-socket CLINT */ - riscv_aclint_swi_create( - memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size, - base_hartid, hart_count, false); - riscv_aclint_mtimer_create( - memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size + - RISCV_ACLINT_SWI_SIZE, - RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, - RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, - RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); - - /* Per-socket ACLINT SSWI */ if (s->have_aclint) { + if (s->aia_type == VIRT_AIA_TYPE_APLIC_IMSIC) { + /* Per-socket ACLINT MTIMER */ + riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + + i * RISCV_ACLINT_DEFAULT_MTIMER_SIZE, + RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, + RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, + RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); + } else { + /* Per-socket ACLINT MSWI, MTIMER, and SSWI */ + riscv_aclint_swi_create(memmap[VIRT_CLINT].base + + i * memmap[VIRT_CLINT].size, + base_hartid, hart_count, false); + riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + + i * memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, + RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, + RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, + RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); + riscv_aclint_swi_create(memmap[VIRT_ACLINT_SSWI].base + + i * memmap[VIRT_ACLINT_SSWI].size, + base_hartid, hart_count, true); + } + } else { + /* Per-socket SiFive CLINT */ riscv_aclint_swi_create( - memmap[VIRT_ACLINT_SSWI].base + - i * memmap[VIRT_ACLINT_SSWI].size, - base_hartid, hart_count, true); + memmap[VIRT_CLINT].base + i * memmap[VIRT_CLINT].size, + base_hartid, hart_count, false); + riscv_aclint_mtimer_create(memmap[VIRT_CLINT].base + + i * memmap[VIRT_CLINT].size + RISCV_ACLINT_SWI_SIZE, + RISCV_ACLINT_DEFAULT_MTIMER_SIZE, base_hartid, hart_count, + RISCV_ACLINT_DEFAULT_MTIMECMP, RISCV_ACLINT_DEFAULT_MTIME, + RISCV_ACLINT_DEFAULT_TIMEBASE_FREQ, true); } /* Per-socket interrupt controller */ @@ -1008,8 +1239,9 @@ static void virt_machine_init(MachineState *machine) s->irqchip[i] = virt_create_plic(memmap, i, base_hartid, hart_count); } else { - s->irqchip[i] = virt_create_aia(s->aia_type, memmap, i, - base_hartid, hart_count); + s->irqchip[i] = virt_create_aia(s->aia_type, s->aia_guests, + memmap, i, base_hartid, + hart_count); } /* Try to use different IRQCHIP instance based device type */ @@ -1156,6 +1388,27 @@ static void virt_machine_instance_init(Object *obj) { } +static char *virt_get_aia_guests(Object *obj, Error **errp) +{ + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); + char val[32]; + + sprintf(val, "%d", s->aia_guests); + return g_strdup(val); +} + +static void virt_set_aia_guests(Object *obj, const char *val, Error **errp) +{ + RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); + + s->aia_guests = atoi(val); + if (s->aia_guests < 0 || s->aia_guests > IRQ_LOCAL_GUEST_MAX) { + error_setg(errp, "Invalid number of AIA IMSIC guests"); + error_append_hint(errp, "Valid values be between 0 and 31 (for RV32) " + "or between 0 and 63 (for RV64).\n"); + } +} + static char *virt_get_aia(Object *obj, Error **errp) { RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); @@ -1165,6 +1418,9 @@ static char *virt_get_aia(Object *obj, Error **errp) case VIRT_AIA_TYPE_APLIC: val = "aplic"; break; + case VIRT_AIA_TYPE_APLIC_IMSIC: + val = "aplic-imsic"; + break; default: val = "none"; break; @@ -1181,9 +1437,12 @@ static void virt_set_aia(Object *obj, const char *val, Error **errp) s->aia_type = VIRT_AIA_TYPE_NONE; } else if (!strcmp(val, "aplic")) { s->aia_type = VIRT_AIA_TYPE_APLIC; + } else if (!strcmp(val, "aplic-imsic")) { + s->aia_type = VIRT_AIA_TYPE_APLIC_IMSIC; } else { error_setg(errp, "Invalid AIA interrupt controller type"); - error_append_hint(errp, "Valid values are none, and aplic.\n"); + error_append_hint(errp, "Valid values are none, aplic, and " + "aplic-imsic.\n"); } } @@ -1231,7 +1490,16 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) object_class_property_set_description(oc, "aia", "Set type of AIA interrupt " "conttoller. Valid values are " - "none, and aplic."); + "none, aplic, and aplic-imsic."); + + object_class_property_add_str(oc, "aia-guests", + virt_get_aia_guests, + virt_set_aia_guests); + object_class_property_set_description(oc, "aia-guests", + "Set number of guest MMIO pages " + "for AIA IMSIC. Valid value should " + "be between 0 and 31 (for RV32) or " + "between 0 and 63 (for RV64)."); } static const TypeInfo virt_machine_typeinfo = { diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index a26ef4a295..a20b80dd1d 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -24,8 +24,10 @@ #include "hw/block/flash.h" #include "qom/object.h" -#define VIRT_CPUS_MAX 8 -#define VIRT_SOCKETS_MAX 8 +#define VIRT_CPUS_MAX_BITS 3 +#define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS) +#define VIRT_SOCKETS_MAX_BITS 2 +#define VIRT_SOCKETS_MAX (1 << VIRT_SOCKETS_MAX_BITS) #define TYPE_RISCV_VIRT_MACHINE MACHINE_TYPE_NAME("virt") typedef struct RISCVVirtState RISCVVirtState; @@ -35,6 +37,7 @@ DECLARE_INSTANCE_CHECKER(RISCVVirtState, RISCV_VIRT_MACHINE, typedef enum RISCVVirtAIAType { VIRT_AIA_TYPE_NONE=0, VIRT_AIA_TYPE_APLIC, + VIRT_AIA_TYPE_APLIC_IMSIC, } RISCVVirtAIAType; struct RISCVVirtState { @@ -50,6 +53,7 @@ struct RISCVVirtState { int fdt_size; bool have_aclint; RISCVVirtAIAType aia_type; + int aia_guests; }; enum { @@ -65,6 +69,8 @@ enum { VIRT_UART0, VIRT_VIRTIO, VIRT_FW_CFG, + VIRT_IMSIC_M, + VIRT_IMSIC_S, VIRT_FLASH, VIRT_DRAM, VIRT_PCIE_MMIO, @@ -81,7 +87,10 @@ enum { VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ }; -#define VIRT_IRQCHIP_NUM_SOURCES 127 +#define VIRT_IRQCHIP_BASE_IPI 1 +#define VIRT_IRQCHIP_NUM_IPIS 7 +#define VIRT_IRQCHIP_NUM_MSIS 255 +#define VIRT_IRQCHIP_NUM_SOURCES VIRTIO_NDEV #define VIRT_IRQCHIP_NUM_PRIO_BITS 3 #define VIRT_PLIC_HART_CONFIG "MS" @@ -98,6 +107,7 @@ enum { #define FDT_PCI_INT_CELLS 1 #define FDT_PLIC_INT_CELLS 1 #define FDT_APLIC_INT_CELLS 2 +#define FDT_IMSIC_INT_CELLS 0 #define FDT_MAX_INT_CELLS 2 #define FDT_MAX_INT_MAP_WIDTH (FDT_PCI_ADDR_CELLS + FDT_PCI_INT_CELLS + \ 1 + FDT_MAX_INT_CELLS) From patchwork Tue Oct 26 06:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12584035 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 131B4C433F5 for ; Tue, 26 Oct 2021 07:29:43 +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 65AE4610A0 for ; Tue, 26 Oct 2021 07:29:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 65AE4610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:57338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfGtv-0002c6-FN for qemu-devel@archiver.kernel.org; Tue, 26 Oct 2021 03:29:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGC2-0003lT-N6; Tue, 26 Oct 2021 02:44:19 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:57203) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfGBu-0002v8-9E; Tue, 26 Oct 2021 02:44:17 -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=1635230650; x=1666766650; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=HTYIOb6C2qHs7esQRqgXBd67VP3nWWSgi2maOSH4iPI=; b=RjIgxYC01P9AprcJSYU1dkWx/SqGH1QDyutZ26QfxfC2z9Yxm7Rqtk7p HFxsOWVbmWBzWbdIEsFRL8tWf+1ft2LPQujb2vG79O4bEpEytGC5k3qGb O1M7O1lww7SrRQC9uM28Gxlb/kNz+wDbfe8vHav3++LoLzwEj4FnTOan8 9b8vL4lFsbVQ1E+6dlPJcIrLap5pBEnVb7oCBP3pRFXpa0GhefjY24Pcz ueG7V0gm4lZUXZSZgeuImE3OBAqcGcoTShwDlxGXJ8CBQhZswmx90nGhH /FVNbruly+rHzns25OEMwNgZPA95SfiDHcEjjcjXQ1ereEQauv/Xsaqzj g==; X-IronPort-AV: E=Sophos;i="5.87,182,1631548800"; d="scan'208";a="295585019" Received: from mail-dm6nam11lp2176.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.176]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 14:44:05 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aEODKE74mGFAlYBBZeyflvAYHvrjt7A9z6tt6wDFLir2bAEaUr8x86CwkAhK9NQ5NLNOqYpDEQdbP1yy1IQ2QELWgwAvkNIgAv8HRk5vpolSLETEqoNAbJNegc6W3g6FLzQq0rax870kBO3CybRt6ff58nRNCxX1PsCJ8VLnm/zaND0MNlefy74pEzTegEm8AGK5kHZCx7kC/hnoE4D6AJD8CxBZH5+4NqXjd+0TKlSFVl+h5p8i1bZMfsbH7qjMR7QK+Wf4Ofs/5AXCR5hbhVPU+vZkpFSEQyFmXSZJzX290fsseYyOWtwsX/cNEf+7fEK4k3MD28fD8vcCVcQudg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WsjCn+PCJ59S3KqnNiw/JxRHOlAsA8UYUUIigy2RXOA=; b=JWBINRRw6cCvW5OkHZzosy/FdgJ/qgVtfPeThXf6uka/8qaIt4qoKXgRa7ZBAJ3wGNyJTn9ZqsJRspoRXnIpYN4GMrJSzsFNa28qVFqReuepx5Ky9YWs8jO6J3B6mm4CpjUzqNEgyZ11Gdl+C8Z3jfZ4W2aRWFLCoiBWMcYRHPikOM7ZTWozAjc/PBdJqb1SubOGEBiqjVfgKkuFvdPkdEYRC4rc9jHneKQmBwBcQP7/eSiJU6WamUavxXSaDuF2Y13NUhq4ZzEJYHu1PUPcVJwtbTNwpE/L2EHUh4jJbI2STMvyvnp762nhh8cvUE7wRoimi46aGaiXwTiVCVGpBw== 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=WsjCn+PCJ59S3KqnNiw/JxRHOlAsA8UYUUIigy2RXOA=; b=SKCPUcZyNuSREO3Mv++6sw1ZweKKhfr8ERIQcitNozX2GYpmYG2uiKd0xhJkcmKlJbd7ycv0puywZG/kis12RbIdQA1A4aINsWzn3+wFfaoZDrd4ehTeI7JevAXFZl1IwKPT+itCPuJ7kTLLOAHL3rxeDOERuYXrQMwYUIul2v4= 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 CO6PR04MB7825.namprd04.prod.outlook.com (2603:10b6:303:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Tue, 26 Oct 2021 06:44:05 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4628.022; Tue, 26 Oct 2021 06:44:05 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v4 22/22] docs/system: riscv: Document AIA options for virt machine Date: Tue, 26 Oct 2021 12:12:27 +0530 Message-Id: <20211026064227.2014502-23-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211026064227.2014502-1-anup.patel@wdc.com> References: <20211026064227.2014502-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.162.126.221) by MA1PR01CA0161.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:71::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.22 via Frontend Transport; Tue, 26 Oct 2021 06:44:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2a5706a2-91de-45f1-83f2-08d9984c00ec X-MS-TrafficTypeDiagnostic: CO6PR04MB7825: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A52X3dhDZlNi4X/aTuascIRjj16qMCZoiWu5seJoHdZYG/F3BbhB1X/4gI30nRXGuO+sDkMWpAnbwHF/UMYtrQyYm+760BDJSQUOj1FEaP94Ugx+8VR0ywBQ9qeliJrRw1rqjHNS822Ksw2/XXyBu5lm5g7JeeKR/0oUgvQMZenSO0UhQKKnhATzh2+ALSh/6plt372tpRGszMLhfSNtE4Pb7QimuNThkOkMce2jl+H0PTFxxc2cYaeYJEwKNhh1/yP12bU0ZCcP/BBIh3mk1ChnEevXXguZ1dQNMadzc33HiN0BniwQkh3AFk4lCc7EaCN9AetnkEgkNamo5Luz+24MA+cOwwyECangYTj4Lbka++ldz2e0UYAD4tGptp55BOBkUgI0atom8W//pQqTfFLXhRe4xulOT4B/fJnftkzgeMMVBl1zW2cFNWjNT/Oakl1Uoyc0wSVF3Nr699gkDqxnObXFS+bzZOEOOktuk/XyMsNaScQtPmszfl+AzdSJuYht+IjTy30NPmjDdWz8PvkCiie2mnG/0gM1jkCMRcayX+8kEdnr2CvTW93VTUnwdJKgEsOPijHPID0OBFccrJHJm0e4ngxczGQiK3FKBfJLJl/a7H2Ckr9a3T2nFAZbLtAlPbVn2HnSEz3+nk5lWhga8IVSfrO6oBzHkGreX8g85GFIAuYzt9NqINdI+hMTlQ93ZamV2w9pNnMxqpq/tw== 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)(366004)(316002)(2906002)(66476007)(8936002)(66556008)(55016002)(82960400001)(52116002)(5660300002)(508600001)(186003)(66946007)(8676002)(36756003)(54906003)(38350700002)(38100700002)(6666004)(4326008)(110136005)(1076003)(86362001)(26005)(2616005)(44832011)(956004)(8886007)(7696005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bSvq7QhPQFfiydPDcdtZk8obY2naLbg7VWvQpv98KeF5Z80gFUpCBYl7AV5Ve6cSDq9ZDkweLgU08oIEk2RnXepSf7F5+J0kdy/TDIYIgTJLThuiEwjcLP6yaY42WTGt8YLW2AvlSLPT9esbaL/ju7qNJERrvM0KVKBxZgKp1f7B2bJUbRWFGFh5vEBxLrWa8QGjdqNVagqxWJ2g+srvoosc0I32OC4d+Do8LM9cdSWXULnfNAJbK/j8kLgrFHykccPG30rWHbNTl53AWMqYN34bxR89gv79GHPveMiMc9SBsVxxbrnFR27LIGGcZ8o7lUsERXIgW+DUR2A9DiOdofS32ZUYaFyw9R5uZoUgOe1u0j9YBgiovnvDtjBpexRwHp30u033avnjhUuDevNlT+2oJFLwGHmED6zI4dFO3EW/uZg53YBNV32tpLom5byHMbVno5okwZkaSH+K71674qx/J9PItX80GUxK/2tSPd0yOVaf6vhSw0JjYerDpPRWHyI4mRHrT6Z9T8K/Sfit/rLqC1sdyGczG74aduRJ6Nj71GWp2598LDRaAQXpomNYYZDbCkeXEM/vrjpy3ivY/Rdaj+4xhLF6lrVOEMJK+3GHyv/O6nN7PyXOfG/FNX7gYKmjuhnG2ZENBZ4kGjI4HczxrYtHBFxGai5TT1ggrHzOJZE1hTvHadx5UoHqI9LPbu61GsCTftRuQDurSHC9PnKYepxPieXHjrgUG4WHx6fLJuzKLhYP/EaBbT5pr/ZCLPbgMGwTsptSpssRYV/ekJDYrypGtX6tVs66TmWflrShy13qRleBfr1NUJ8o8j2zFieyo3lPZeQ4OrQ5XfBfG50PGjQnDb7ax+pSN0BRvE18e6ZEdF9r58czzN1PKnlxg3Ze2KACJj38UaJQQ7a3M/ULlXQ0PTOGcJ6shdd47sZPo9PTpllzbo4lhrst8255e/LGv+KERClhfmQNkJStKNBlsrRk2tIZLKlbPFgsXuebg15nrY8M0m02dQnaEzsG+t6M/f9xCPXkRpwS0WbMauiLxVcwRq+LWleyWdUAUs88mOaW+h7lKEseRK91MWIwaohx4ShpUw+5eMdKMGjEmd/NyVsLRwOWcwzW2ui6wtz5uj7rmqtVLN+iHmtz5ZcwYAqjOn8aUjUyGhwbTtDReAW/GTn8KjVd+6EZnl47ALgadFhcoX+t2u4VN/RXvJ4jkSBe01vR6uN+Gaq+FgTZRUf3U9tcMDVd1girwAASeFk3vnDwKNzw3q1IgbtJLaRfkZFRyPW1A6iB9YVISLbB+o6BHekF/WFLhAQzJMf/vuJS5XsyHPwrab4BOd6Uhq0OqojdkQUn/j5LXrparzeXaCc7KHBOd28z0TuZBhLUH0YA9XPR7XNXOaOL56xqa7AtMifAY1Uty1tO1Ss+suVvT7HKXDYNscHWn4zlgO/ZKhIHiibHVaflRatD3DF89Q3GzopskAtb+HFZoH8mEZdhpYk6VxswZGl4eR/llreDbB2DdnyfonYn2ROm+sgI0T+RH6YzIr9O2eoD5ivxQPkvBPxc8ErTOwNTHk82tt0HPq1MMCibHXc01mds1cOREtjP38JRodFxM/jsrOYqKybdBtWcT3Ao7Ex7oyYR7OrRKHM= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a5706a2-91de-45f1-83f2-08d9984c00ec X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2021 06:44:05.0968 (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: 7D8bXtQFHalYqpv73vl3tWKfXIhyYN8OB9Ct/aL9VsKWkvKHGWqTOIB1+lJ6yYcnE2N3VJUC/VTa+i1QakLWYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7825 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=9269cd5e3=Anup.Patel@wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Alistair Francis , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We have two new machine options "aia" and "aia-guests" available for the RISC-V virt machine so let's document these options. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- docs/system/riscv/virt.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index fa016584bf..373645513a 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -63,6 +63,22 @@ The following machine-specific options are supported: When this option is "on", ACLINT devices will be emulated instead of SiFive CLINT. When not specified, this option is assumed to be "off". +- aia=[none|aplic|aplic-imsic] + + This option allows selecting interrupt controller defined by the AIA + (advanced interrupt architecture) specification. The "aia=aplic" selects + APLIC (advanced platform level interrupt controller) to handle wired + interrupts whereas the "aia=aplic-imsic" selects APLIC and IMSIC (incoming + message signaled interrupt controller) to handle both wired interrupts and + MSIs. When not specified, this option is assumed to be "none" which selects + SiFive PLIC to handle wired interrupts. + +- aia-guests=nnn + + The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest + having AIA IMSIC (i.e. "aia=aplic-imsic" selected). When not specified, + the default number of per-HART VS-level AIA IMSIC pages is 0. + Running Linux kernel --------------------