From patchwork Sat Oct 23 08:46: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: 1545154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=DsZjY7PM; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=tfP1/Uuu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbvyr1pFyz9sWJ for ; Sat, 23 Oct 2021 19:49:08 +1100 (AEDT) Received: from localhost ([::1]:43486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCiA-0002GN-0Z for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:49:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgd-0001uC-7Y; Sat, 23 Oct 2021 04:47:31 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:9749) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCga-0006sl-Cv; Sat, 23 Oct 2021 04:47:30 -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=1634978847; x=1666514847; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=LZY9aIog688ACRn9v1sFVo0EZJ0feFHY9C5xQBrGttQ=; b=DsZjY7PMHzPdWsjrdb4h35sdXAZ8V6qMM9Wld8Li76qWJVeZzQw2z6oG m61QH1uD0drlkdW9zpCnq3RBWelg40VmznQFBzpL4H5FhO9xZYcCAQSYW W/MCz01lzfYVZvae51FOZNbMUAe6KkxS8R9/L2xEMh8Q16HmYb0PgFllE 5Vs1V5Sx3RupshdC4P5k23s34VpWt03NgCMT08NZdq+pWdnJ5tzoPAX1z qonqZD+B+WN2CwregG6qtuuIB9lzp8bkOJAyg7+m/u4aN/3vFwKfEBjP5 h09/Bz4Xp+Tz+PrYroXgGhrRYisOnA4QjOJ/Wo/VVGM6wjh2qfeepY8Kz w==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="183665040" Received: from mail-bn8nam12lp2177.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.177]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:23 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rrd0PGOWbjRcj8edUrHjIZNX4aMPHKutsTBG5/u9u1y9eonRZnvnl9f7vQsgX9Mw+IZR2YiAKxG8gk6JoEmZPmnm+OUEL1wmeZLRjmRYGl1fJwLr0v+sGt0VpJ0QYtYqfl8+zFjI7+r8wPiTyR1SPRsDVg3BETTAzOAm9ksTo7pdKCtEPytjsUQbSSVVR84ElDwE4jetgmLQG1+iOINsmPgATa9CeM33pQE+yvLA5oQkcCyc1eC3D4m+Hh/PNS0V6o0cPXTpjp54KbmB2jhWwYsyENail7BSX6StKANEMRWGznej4qm2RlknkCbBD6yhegS7ELrd+ozdNBuLXV/aYA== 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=LOpT0C0LSlasfRuoUyJuRBONXawM3+eTO3hxdkXjtubZh4PMTkDKLr4MNPaKgt+LUaMYWVJrE/zDGVTZWzsjc5v6sc1iuuJRrsUHEmqmnOMZGXxv7NYEu3W1Q2SzW+uaxOrXru15T0T/ws3nOmuDcU8gqomIpk/DFzuWYYQpMUv+hWv03VimLXaeR3jnEGH91FFPPmelyNSmNsCYBe1UAMeDYM5UNJu97taQ6KJEpli9VSZniw3WI+vszqK13jc7l7cdSlUnG0hWXnahgVhmNKPWj8TTqIqnPEy30pHMESzELVSsXOqjKwkNlHOutxe9vvfvP+YeIcK5HuUcFMP2dw== 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=tfP1/Uuu4UXuUes+HB7W9MXkFiQFL7b3+UW6OEN1RIHzWAOWf2Ggh/T/MVbjiFbg/SpiLJG7U6qC6OF6RZtTzXL8T17buV8vvqGRNCrlIWnul1fEtnX5a7BuPHmvLsONvRsa2HQ6lRdguzwGkT19wgSfxzOQFJIasAox+28P3SE= 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 CO6PR04MB8345.namprd04.prod.outlook.com (2603:10b6:303:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:23 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 01/22] target/riscv: Fix trap cause for RV32 HS-mode CSR access from RV64 HS-mode Date: Sat, 23 Oct 2021 14:16:17 +0530 Message-Id: <20211023084638.1697057-2-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0d1c86f6-6eec-4086-9020-08d99601bb4c X-MS-TrafficTypeDiagnostic: CO6PR04MB8345: 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: CDgwonXXO2McotUkMNu0Mp/nKb1NJssE7kdPiHt6BaJt82uznx9uycHH7QLjoB0AUbmPJxf9B6tjM4az4ZCO7gvH5rS9milL5cpDmu6MRYrqt+9GNpnpTgJV7qGzvQq+bm6cYYAXk1UDPMboBmuloNPnfYHqknKI5zix083Vd4ODSiXrJkYd86+19Ol/azskzopKASukBZTTt5eAS5Cuy8OsexA2ZX+kmrpjk/6tsE2B+mJnSnNktYnZ6jHvgMsGEg6JwTZ7LZUMInQ0z9SQeTh6xuyVcX5a31sZdw1gOVxdBlQ3hJJ+5pvb4KVwCQycDVMuO5h6nmXhWl1IhxE+vL5Dj1SyR6j5eq19YR3QDvupRpMDkwdPxiiRK591iv9/H3zxOKP93Wq+pSnurB99jZpWO58Pfab/BTVB1JnFUT4HaPvuX6sTiGWVrZTny+cnTMpsaErIYQjvm0J3dFFWFHS5QJA6Gn6VntaYmFPuyWyR6w7t3QhuzM7ec1+Cq98zCJ5rN/i1iu86M9Znb+jtkxkIKOUh86M/fpqF5gakrklunLzppIdscj5qjZ0R6q+iqGr2j2Wuj6BLIImqTNUN3bqUtbTNcJTubQ8CGyu90sTYXdHHRhXBsK4Pj5US9qZjq0ergIQgg5voW/gkc8zVf+Ce2pW3qj1GuR1499o52ToIJ43jnuMUYPnFPMaU8NnlKCOrgwgjMyICRYiWbp4+0w== 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)(7696005)(2906002)(1076003)(55016002)(52116002)(4744005)(316002)(6666004)(2616005)(4326008)(38350700002)(5660300002)(38100700002)(83380400001)(956004)(82960400001)(508600001)(110136005)(26005)(54906003)(66946007)(44832011)(86362001)(8936002)(66556008)(66476007)(36756003)(186003)(8676002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6W9ysVD/wfRFrFipwKwBG49WElfihvsHmUq+Jw5+i15yldHh+8OQd/QoC9e+2Lht2jBoN8VjEpwrQHA3uYBZ2+6DhFbIgHFxIHLOSG4QJvnTI0G9s3iUmJ15VcNfGb9u7RcKjsheUiZL7bFChapTk3izjVoG8sLvT1IvMJUO7r+4K21e0tQhrhhy5ncAz0anbhawho5kxfceA6FNg2LVnt8YAMsNz9xYPNT5lAsXLv5zxrIMi6jt2G+LUm7uT07x7A8wnFFeJfinatu3vmY/fR62KpoLliWzsnxqaWpygMosoEftiJi2ZW+SWSPERnGKbyJ/oCBbduAIYbJZDbjtbumLO5PYiWVpI21FP0usW/DYDFlMjBgolVRH8MjrQ1cGdz9pLvURy6D/uHpHB99mQ4T7j2PssvW+IbsVHlJb4VSJGax9agpwsjrAySFM1WEP5rCAGw7UksWtmwVheBJJjMn9eyT5f4vM6R3n0IkfnNHiEYaDgBh5YOruWFMWSEBbIOZ6PgDq+03zt81dg3UKJg7Q0fxwFWVY1jF0slffQ2+95CyroTd3uiHNmNQV3jzzLZ+2mOHRCjIFhvN6PbH3zibLX+sNdjusFBdeolNd4OJqF1XlXZvmNas3uYstKtBZqySVF4zligAG9ickhDUdh3YwIMfC/zBLuleDgmdpxgdOqmDoUAG5WZPqZlnCBpdvTh7KQ3bOVtuJw4a0rGqgQVwTLWVlDYubQIeOVUDTUnt2SMpCYFiGY9gHzd7kWYk9NOF8NcYgh/z/PF5YtXMJSnSErD8BWzOB4naHQNItGZucrSx8iVVD8aUbBcbqHoI0SJ5JieLhdRyutNXOoSw8Tqqi0QEvzQpAqBUWjdzAZeJx2zrLiCEn435s+o+ITTHnR03LOR/y/nKuWbg5RdzIfrdPbSBC2JdSEAq/GbF9VSoslHCCjeIdk3PklbuwBl49SiWupduzaNtw9XLSy/suH1TBhCz1dB0hTzGOQwf3z+oe0bOydgnei/pbfzr9LFQ6fR1Fuj2Qt6KBKeRanLzz4pVieL30XytIQiylLDxKWEfRnn8Re6h7SVzg4euogZkWcB19Y/1wNFifVEUsH7NkAIz+gK9GTTuHESpYwYhzHZvZpJ/GE5gZw5PmEk4/cFcfaOPZOjReRstadP9owA9Vl1atTAirmGQe8eY+p+2sDGjc7KeSYQeQXM2/2BZxX5Kqajl/unBtIN1toaISVcd1OZgt+hTiyCl1HFjbm1xobSw4w/6YWwp0KEcrSZAwmZuFlAsnwW+MreybbR0lKVrCT39YskUiEaASG42eH1UoNzJq1t+jQiUXJJidBciypNfo1PgzV39MbJnDY5mYHqR6Z3OmrHdqHqfVKVJmxWGC5c1cBoAHULe3o+M8U1b9mscdvBPgB4kCUaM/dO/furLfvbjICjUtyTlIxnIKGQsVF+Bwe/GKlhMhTMiw4PgFNXT9lAY1Ew0/QZBPGC+TrC9VhMIBQnNbSgc9+GSoNJ1q9kUwWCeTWLg8urSb2qswqPpcxDkS2EAgcwyOKVFO9rv9XlPC3pEFQCsIX8WjhMbvu4grdnLBNqZO/3wZUvxhk585VVLfs9sGNzpo3RlWhSwg3hdQEwwqMq3PeEQsaMO+9W8= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d1c86f6-6eec-4086-9020-08d99601bb4c X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:23.4700 (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: wMYf/2FmTNxktIcbMubzrjFZcIM3swI035B6yq/6h2sG/X6jGrPZkWtYQkRDUzXE9GXfL7VEwcprWgDSJYcCig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8345 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=92346df24=Anup.Patel@wdc.com; helo=esa5.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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+incoming=patchwork.ozlabs.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 --- 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 Sat Oct 23 08:46: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: 1545155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=ik6LqoxR; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=LiPQOrPv; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbvyw1vzKz9sWJ for ; Sat, 23 Oct 2021 19:49:12 +1100 (AEDT) Received: from localhost ([::1]:43616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCiD-0002MT-VR for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:49:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgg-0001xh-Cw; Sat, 23 Oct 2021 04:47:34 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22395) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgd-0006ua-W3; Sat, 23 Oct 2021 04:47: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=1634978850; x=1666514850; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=XMbfyezYLlZZPqOTSDDPiQxcWawUqBfVM4lykBwoyOc=; b=ik6LqoxRam3yDPbzNZMKiVqwcvlahvAUEH+YGzs6KPPXI61w2aY/67Gd 9/Gy0/eHUYUKtun0g/u5JqAdb227uU+sHE0JvJoyOCJFrb4bZXBSRuw3G 4K5N8es7ym/YeLcQw7L3lxiIQX/GR4glzVmlyTL2zCDhnJVWA0tWd8xRb SvJUCgawnoo4fs6W4vcchmTgi9dXqSHgSQtv6TJ8llI9Ib3kDBbPvoMVa nZTKsggTH59RCsbLkPbNJHWqirvGLDcHwANmZLu+ez2gmaL1dXP+j7wQi CLlS4e0JXvH9i5q0uEh/PQfM1zVqo20uH1AmCyjMHZujM4DMkORvwikF3 A==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437369" Received: from mail-bn8nam12lp2171.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.171]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:27 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Fc4TFWd8pMIFfqyK6ebjt6pV5aZPjjAqhMYheCYKleMsg5JY+CWAC5Ll14W9FzgE6K9yUrUkBMmefmvOSEt4c1K6kTRxBBplgg5SJn6o/yfKLiusYKu8DUTPtGAskgTDtrFspHYm503Z0azdBLPxEhPMQ1hRkBmrc24M7UIbHFYti51xpqL/o2p9UV0WXl3xk4SqFYZ8nAXEMsECVQfp0yadnqqnMeZml1tVgN6znCUiNyT+4zM2Mwje1teO/XwN6jmMEFGsUL9dlHxrJTDR1Az2aUYjIVpvMDKNR3audzm2k3Ed21z08TmkocpL4HpsrOqJfBjeysZJZv9LqNveRA== 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=FrO8NOYiPWRNT8/JvdYfwt7fzpachZgcHzo/CGMa+mdEh7XkvgM3kbnKxLxBzSr3eiUqW1ls2kfEdF2JZKdKrs5H3PKCAyonSxuF4N0SWSDTbHbckiDVT4yWYGJoFo5SoIK2o0yHl3l7SBj04r1DPG63hCCsv5pcbVPBxXnNuNC1HNjcijJVn2305NPrDE8iAKWg2p+HBpXIq6G/S2I2+uumNA+QoET0zLcnYZTyjyjR615UML8FIdjF2uikD/fS/D8/8TGa3Dzj9aCueUCqUk2SIHg75QTEsfROJUsIqPH3Jt23NThwLA+kfrNjghaGtc2o01/jEBVFhpQxXfc7cw== 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=LiPQOrPvWnukFeoytrs0BdArYsX7ZtrMTeegTw89K667vCsJa18IIRbp56ttV6hKulZToT8kztux2O0MV0i17kq048cLyxfnsgDf/q6gEov1jdaMssz5SKv1NZmPPdfyg9+AZUbo6Pw3UWfOptmfxL9XkvQWT7ekqpfnRZLbZ4s= 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 CO6PR04MB8345.namprd04.prod.outlook.com (2603:10b6:303:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:27 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 02/22] target/riscv: Implement SGEIP bit in hip and hie CSRs Date: Sat, 23 Oct 2021 14:16:18 +0530 Message-Id: <20211023084638.1697057-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5432dc81-0be9-4f2a-6892-08d99601bd56 X-MS-TrafficTypeDiagnostic: CO6PR04MB8345: 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: 5bEqq3MyailNUo5wdlm+ZuK+w6e4RhgaupmZt33xfHXWhP6IVmDknLon7FraGRMjpdNQqK81WkNcjrPsq4XROKntz5CR+UyIMopXFYkcXZdcI3wqtDum6joEquJoRIchvQLp9ffGtkx+HogHr3wMuTBUhxU1xzksAc8jL0O2wwl2qzuykFOHPU7hemITXba0MklJR5ARoU47KBav0LptRp7nCSiNbh0f8Ct0LwQrUMWcz4T91Yfi+bUJWVPk6NxQDjsvUZFSJ0PIMtayouEAnR9/Ljr9KErmaU/UmDMq3GxOmr/IluouCeFuty46sMwLYG6foWdwQxXnG969SzAxmzoVxHlOt0hW2kD3eTC+i55E1Re0i0fmxy/dXfSZtpPNrPFCffJFw0ghCUftn8lqffCQZANYUj5qao3Wcof7yH+NuF/ikXlKuU3JFgUXPCDE8bIFAfB+eeW6zz2snlsZTyP59RHpGr1TO/h8OlZBzBxIHiXMsx8Onxxnsii8BYyXJvt8w13djeo+eqDiKF9xlKS2Htx0Ob1kGx4OIHuSwLjEnxf+uMAhVE0UHUT1J5Gevri4A+FoF/1KXSCYGDBW2wI95EBMgNF/3FVJjTxPqhaUBoeQRTFwZ7I0B6iPu8THKUbfTIrMAadTiUYZzAPWSgLTq1ab5JB33zQLNGTD1LGkE2I36Cjsy2YaOtPJjtz5T3pEInsAmXE9CJrXhA1erw== 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)(7696005)(2906002)(1076003)(55016002)(52116002)(316002)(6666004)(2616005)(4326008)(38350700002)(5660300002)(38100700002)(83380400001)(956004)(82960400001)(508600001)(110136005)(26005)(54906003)(66946007)(44832011)(86362001)(8936002)(66556008)(66476007)(36756003)(186003)(8676002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o2ExaFjF4U+jj5clR2j7TmC8z3/F7pgsViBsMshMvJtqpf7fZxOOAAROl0k1i1GMZ0s0xiirZJfZSs278fh0nfTc1HmfgzVMk2sanCq3vE1ZM/6Vv6cqYiDdYSZ2X0HP4ufxYzTuPOyVHqK8/Yhhx6MPz9ubY8aMyBT95WWmoovKdFeEkaa3PWG1XcXunNxPad7rpEcDpN5S8A/QJjPNyikiFVYW2DClvc6nsYfTbsTp7KVNDw0iz0EJ/+PmyJkuGLyN8e5hj520EGLhbQGsS/YEb11pm32FG5JM0yFzpnWWDMZYMqxPmr+WwPd2pF4f/pJmn/SE96LOPtJki7Wn36Odv6xdI1W6E8NMEotrVsIcSzLnRrZucmRRBetbVAaP7bJeuEJEXWvnVobMk2UShhAEdF6K/vHGCW+PgHPDngyVMK67WmQ2Nhb3kz/VbbYsOXJc5PzOH7s++ojvUwEYwiOT/9MWmn5Y1Jki9eQ8dYOqCeriF7aC6+6pOtTdOxqCQPgEjnKGio8QA+91ZQJrrWjgHUmUZjZV8WxPRrMmhDIq43Jwbfr8JBUjUlaVM23kXq9i1CRMIQfKvIbKOhJyfOnzgx6Bj0LtW3olD9jHirUKj7LXzKdm/kTJBfXT7+plgwYVGCfMNqDn2TqX/TW/H6mRY5E6A9EM/zyHXQSbrR2Bepga/YMVIvJMRZXo3INFC7m0g1+umDRZbmsMx8nNO+COfTIWh3pg5Z388qxdDfUBX9jX3TGfxKIjwqJlb7OF7J1d7kjMZMPRqXDdPxACyA++27S0vUmWTJOqgCIJlSLLveu6mbRiKeGeFF/2XeQsRkep6Pjd4fHbo9W2kUWYLgPDtL2NZzbPaWA1+zYj5guvdri6dGi7xl09wGa4tWn2FqnWo2yHOSOUBSTKhfc5y7zIeHCDbez4I/58D2Y5H3NVmCVuUCkMUo1Rm/mRDl602ZHGMcmiH7HNMOr5Ksodkek8p83ZHUOWy2QmNAobA1Gp/uUlEOTcYNe0MdPxhDShVDNKVvNOn+Tn+K+8g2x6iOaYomnhv6BrdNemIdPjDdD6/uP6AiSFA1iUFcfJWyUkC5uri8GPH0Lcsj80rcZ/flvEpW6xkFRXdLw5FwAncy/+uefe7VB0UsMh0VS/ciu0jTqNga1AQ/3yuxbIfLiC0L55AO3DZAvi8ejYQknHMDF4J6boElMFyQX2g8MAjQs/UDOPH2FjSKTASmPtQhGmSXUKGsZxMKEuIRFRYz2hO0FD/MZ1MxwWE+G8M0dt3Jqkh8dbZWgB2iTrChA2Kakn5fnDVqEdLC8kRZvxfKqT5aPKOCjUlDlWAdkYIxUDpw59WFEFIk2DXHwe5cXwj3vIgCYq5qgmNEr8rv3MpBgIdsyD/XlowMzn3ejFiWYyA83n6P0uZFhn3hGafhshb3BT87yMWBb9YnIo1CTHAMPm9CkVWJ0UrTAF/XOe8MYs2JOYgHrViN+pQwFKh0ki+s3AZHttqbbkWxGEB8P8TsBQDKbTKxn5tOQ8pBqskr8Y/OMVUxoKYAcRZN8s1CtbvTCC7ZmYHAuLc2l3WKTvzEnxyUnAQodW4XaDv8UuO1RzPDnTywJKlnxBunG8TER9AmRdNeGKbS0Eg0GAiJ7nU1pKg2o= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5432dc81-0be9-4f2a-6892-08d99601bd56 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:26.8721 (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: NdInlviTiQO+pMJS+RvSRxhGQTM+9+ZKoPQGTqspyzcH1RzLyJ9WYBIoV3VsIoD8o2PDBGy1Z6uCDvu99MCCsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8345 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=UPVoqJIK; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=tl41TWSV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbvyw4tLXz9sXS for ; Sat, 23 Oct 2021 19:49:12 +1100 (AEDT) Received: from localhost ([::1]:43852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCiE-0002W6-Eq for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:49:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgl-0002B1-Al; Sat, 23 Oct 2021 04:47:39 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgh-0006w2-7B; Sat, 23 Oct 2021 04:47:39 -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=1634978854; x=1666514854; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=cCSVrMFQZK0YBYECnnhAPfLUnCnHNqNNUJ+jWklO1VM=; b=UPVoqJIKDMhf+vac+zr8SxNStJo5AA09Om7wxAWuGM7oWgnOMMlhpphO QaTv6Z6WePA6V72yyrub+BeqUmB0kZwVVWT89bX8PEq7F98WSkT55uvt/ pJRfopEg7SQku9qY4qL0WDVohAHIgJdJtb+TITMfnI4tNKOK/z8LeqdPB nV7pdqCaRCDI12ezDrwcV93CavDt0vDkEq5PHXRwFldejTXdGoGiBZpND uJ0G4AohI+DTnnOWIB7JMX42A8JZHfr7GJk5+55lp3URP0VTvSxsLqm28 Ti8rasFEq+vaFx7CURzEKT7r5wxhVnGeYqVIpkkHC2L/ZolrBsUOoGLfC A==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398049" Received: from mail-bn8nam12lp2173.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.173]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:31 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ING5KvtZeZXK9gSeI3H7904CaGDDqE7OnrYUUCxUuVbdNYBpuIbPscS9u7E2LsbuQ+30k0zYwpfx72V8/cRE0DR95HzPXQt2+9mQa8DE8cCEM405oAT6hnVPkcQAf+fnmB0KbAocN71VzBElW6qh0RO7e/gKTxP9bKL9FiCMHGVvAu79TXj8jjxqBtaKb5Ec9bMF8+sWFtlr76UtWFEBZjbm/rJDDzcd+Ml+1QubA62QCbPNQJRgnXiEAeM1FXf3GInShi36GmjAUf7w6LA+G86JlltxYlQf9stJ88Bz3e6lkn7H3SM9XaSG9K0hzQl0MlIOyVPHyKWnuw5PbjkqYg== 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=kWZvuv2H5/jtgOCBI9vPiNNnHwF3RUQeh/x7LBZtEyufWWo0JPFfQ7gwYTJi2lx9ecCzwycEMwpJqY54LDEIkUml5UlIlru52lALSGrFJBHKOa119rqU46g0ifK4ng9iZUShs/7SvwNikjI9ZNhFVvMio0V0z/snBflZQAHcMQ1jkjW+kMBm4rskXi+fUQ9TZh+T8GavR1yTQ8mCzaxPThy/pMYcS/B57lZ2a7tY1uEZtJfZdTjLJ53RkEHvS7Pm+Jf1Fyfs83359+pl2OgOwxocbnEmaCXmzv699EcxPyETpcFGcTSE4Sji3I5q7xKy7Yd6oD6A35YJrwPMkYcBuA== 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=tl41TWSVND39SntmF9nNSOQSEKDnbF8Su/BMqs/9YpgkqIPUClAPySef3Ra9Qyw13XFsqeMHj5M0aRsig6GmmlRPIlDDQLVbahuCeK9zDt5gP5qNwc7BODTrljf3QddD5PeikYDQyZlqesNMLAK7EEt4ZBxyMSpm+FDtRPQgy9g= 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 CO6PR04MB8345.namprd04.prod.outlook.com (2603:10b6:303:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:30 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 03/22] target/riscv: Implement hgeie and hgeip CSRs Date: Sat, 23 Oct 2021 14:16:19 +0530 Message-Id: <20211023084638.1697057-4-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3a1b2dc6-47e4-420e-a51c-08d99601bf5f X-MS-TrafficTypeDiagnostic: CO6PR04MB8345: 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: tIBpvOWFAc2e3WdR7FGtYkL3mFOS5/+nVvyVeb3xMwt9SrTKV/NvK58zc/BAIW5lgTpeqfuyGVAT+O6lUdyrddgR/DbS+EHFtikpQzC7hmTe5OGnuw8IfcZpe0JAsDETe+0YNNr8h+sQ8nsxEWHSKpw29fufCJxus8/DNRrTl4LUSY8DMcgHu4xSmTFrr/so8QOflM2+1t0Nq6LsY/WwnJYremLAavVARC6dKvM7Sf+XnWAAM9AKmTl9kOJBpqGWDmmlBNZw5ag+rg+s/OVq/HV6a4HDz3Hx9MgnEYWRqkuKvqJnGVL0GsdAHX/BWIrUeSRDi4eEwfPTwmqbtkpLjDQe8gwHl21F1AnIkvrodwmscX/8Gro6HthY+WCMLZs6Q8bP+z2Wy13GDUPdbU0w9QSJhij8tqGc0ZRRXlJOSbM2RSEjNW6/Rr/wQtRoymb7MI0zQQSLBUCoOCikGPpJZ82Ip493QmiGlq4Vc+KUW5Dg0km9SLpsJGObYlPHGxJfp3T1Wm27brmzzFrItnXPu11TD0a4cCppbuu05s4Bx9MI1clLwJ12EaKu9WXLsOYlE7NBI1Qea47u+feMMntO1Y0F+tKx4SP6bFfZHF3T8qjmRgTYyEUfu0PiQmq9v3P24wQKAz7LVcv7G6Yg6EMMd5TsT5l6zW4HwLbsA8dXE0S96C2gYV3o9sLwoOw0SjriESbuXGy0CRnDfsEufZAk9A== 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)(7696005)(2906002)(1076003)(55016002)(52116002)(316002)(6666004)(2616005)(4326008)(38350700002)(5660300002)(38100700002)(83380400001)(956004)(82960400001)(508600001)(110136005)(26005)(30864003)(54906003)(66946007)(44832011)(86362001)(8936002)(66556008)(66476007)(36756003)(186003)(8676002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IVDMkJyTG0YqIKIrvx3FTAOrRaUSu3Cz3Vngr99yPuSlkvIGMy3T1By8Wee+TAMs+0RMCgON1XPXzZ3IUlNaZR0eLtBPsXa6uMlYQzhC9oYIg5zHM7RnHhKx7D9WPu4zaJJ13gBp6/otREiSQLhyF0/7RWRgR+zoGZCyk9diA3E2ijQqu6qFCnFXmfKNb0DbwSzS0LfAPkrXlAfbUxTWj3xJ6uh83jlrw7RF/BeD1BBYPlSD/OWVzmDJxKsKl/glCEEK+kxSuZR+xDHglqG6YFWHy3Y9d/TrI1SGdNHFYhGmJGJ34anNsDj65ZTZE78gI+WkfYbsBAMVcbSbmc7RVxV51UFVSHqCPKpMXPI3InDfKNf+53zCa2xUCSqZh42kKWwwiljW5ZNISJcnHiNQDdiPKt9WVXUHP9F+aVZVwmnyq4rCrI43ES+1z9rVakK/op2AoygKJIpuUqpwFQ2zGYip3574gdRIr8OHK+yzt1QFWWILiBUOdUePHn/lq++yYOUdHRVpK1OFLcqahkRa4IRPyDrvlAaG0s+o04K/pOt8X4/pBHAXrWaKKtyfdzLwfNK8mfcCuPGKlj3uUDJdDN0VRg/0UKWAxCx/kEKtliFrObRgXY3/oTLe5YttfdV8cSQaBzXhGil0PqOnmu7KkQH18FT8skO4F3n/Y+yrGlJT6Z/0GAyE9ZFV3LpGdF4dMxyEcOjQs2O+RKMd3zNa3JxSw57nQzMjjDsXEEZfOLDnCGterAakcjal94mlchybYJgrMuwU4BzbMaxfrfti4re+0PfkvCSoYeaqfM86e4+iTjL0S74VB/iN6neHR7YCSBj8moSfnexouTfMKr2aL7SKtRYJbaBVR8fFMu+wG314jUlDvlMra4Tx2r3UMPw+SI4bUWP4ljm3K5CfMJ33LBbVmn9WAKRWrbx8wB6whvYGopqDLNWkZHWYY1q+cnxlotireWdG6J5SQ9mTMA/BCeaYRFlD9Vi2PPkNEwTPoCeUYAbRrEuAS5FVAkI5FEo7DSP3AhAqumEd6DIdHzTQC8/HAKVdkUwQOmv4vejXKetfrA921PvQ9hwKSIBWDsD4AwBLaSokmwP1SZyp0nboXVft7boyxM2pfGeyiUNKqMfEu13+/tDPSNwQCxVjJEdmXT84c+kh6ZAKA5TuqBhu4Kr6rs7aeGQNAajhOnIpk7aE90hshg6Z2Cd7H9HNCvQ7IVvyu1/Ou5+UvpXeXIoWjmCbq7Sxcf5/VB+pEgX4nS3PXuYIjucnwEXcLfU+LupmStdWFbung5ywO4y83dExxx1KYvBsIPQoHLZUaRqxi+Y0u/FL3H0k8pTIj4yQhBZH7s9adVqNi7xY4rwZLYlMVRIa3Zux5szV2GjRAFLdXb9hD3tN912W9Tccn8Y8PZW4oZcHHz/ZqufU7nvxSgvw3cDXLffFdwcfpA9rknNuk2CPB2NgOTXvJ/JW4rBMXeTubPHB7FL1sNJoUPZ9WR+pKCcYdm1RksXFHz/0DawAYCupf95j5EgiAiK7X24qWD9moQelP7d948LiwlxVp7PuNAVypc21l2GchaSnF30wS/DW1ESI5EbwNZjNzZlyy2x0GFFX5ZZgPLHZnuvEgCss80b0rOOHur1MIqit3vhHztg= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a1b2dc6-47e4-420e-a51c-08d99601bf5f X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:30.2482 (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: waw/KhhJNvV7Es6tP3qEpIybFH19bGCmAwvkuEp+jQeidktEsgg+9LQnZuPFWDdegvUZy1uSj7385GisNtolJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8345 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=cmc4gWJu; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=w0kpnPdj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw2B0gt5z9sWJ for ; Sat, 23 Oct 2021 19:52:01 +1100 (AEDT) Received: from localhost ([::1]:52440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCkx-0008Ld-5G for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:51:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgm-0002CY-M0; Sat, 23 Oct 2021 04:47:41 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43328) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgj-0006xZ-Mq; Sat, 23 Oct 2021 04:47:39 -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=1634978857; x=1666514857; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=z3qIOXYfVWykrEEtE+DZx9v+O2iQ78PhkBTRuSZjnU8=; b=cmc4gWJu1Ep93IU/tbvSJFTjvtyHMCmbAjiV1maePHqV+ypcnT+vhulj hY4M3dc9/t+3Z6TWUArZqylFVYrnn4N/BCgXoeThhFULyq83eZi+2oh6r skj8fSb1Ewa+oQJyPKmfO6MfvotOs4DQK+kZtPg/h1WAapaaUGuA68UWk 2ml6AAVr94D49VnRdY4lfxMPY3k0S8YFgygkdkgv7QV6/aNXyP/hxMOq1 yiyrgiw/UJBZdGBHmuY/UwRLVnhTZh/dKkICAEgEbIQ0uNxGnsHxKSAkP AC/5/tdxUNorp6reXEtZvkXPwf/AGxv3DwUZdk4dmGau+aeT5ky41ym0h g==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398050" Received: from mail-bn8nam12lp2173.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.173]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:34 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=msVIqjkCbGlo1nqTRnjW8yXSTxEUjjU4n56usKteL1zv9ffhf6wMmrgMiYOkUD9Q8VZ1fJ2com8msoudI5EUQlcCkwQZ9/DELDFlYCRI2DL97yk0jVDTdCzmcmdNLXvQvbd1tsCzVFK82pab+W5i4WakaWGGlMwSISDkuWC+de3fJWzeKmsQYZdCDJdTMA3dAZyAQZAkTYAklzCGylow1NzvQqYx03EwcfpJHB5aJmK5pbwtvKcDvExPUj3rLBqVMZsk3nJ0ksbfMqir+iczj4fPPAyGi4YiaVXWaCRt2+tZIDYv2UTZb1pBp/i9IqAJiMFmjEdr5PBavOk+JQg0jQ== 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=E7sW9BIrZhYCk7B9a92fG/uvAEq023RbIYoW7Oq27h4qMo4p0BCtrv/YPjq8okfFeIdusecfTkw+maD0QBVE7nM72v06PrlpBFyAEN7RZKujML5NYHvoRqex/ZzEngx+2jIzd52UtPzkT10GPL/7+wInrwEpJWO628pCUBnO5z0KWvSH7q/TNdu55PrDIioLbH9fDGa5vshp8TjeybKkHgrZuCcoVixHqzus3SoYxGjmcUeuePyNdhQtggynI1hlbd05CYqTsQd4//stKEj0My4TZCjZdLsOHs6sikWakjFUM1HG9DSj9uj6+GSPcA1CazIttomYCGQjgsM/ZBLR5Q== 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=w0kpnPdjj+Z7nU2l+1RoeH3iYyCiNgZHIHr/WPCZEPmBj9UaEJfz5UTa44t24V58u2JIavvg7oumvpBHiJkt8CIKnd1kmLC2Wfb9WcPsG5leNV9kZYKYLio8FPo3fZlzy4B5mxaCQ4DzvUTV4vLrDqskv3RB0NqemGcCekpLug0= 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 CO6PR04MB8345.namprd04.prod.outlook.com (2603:10b6:303:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:33 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 04/22] target/riscv: Improve delivery of guest external interrupts Date: Sat, 23 Oct 2021 14:16:20 +0530 Message-Id: <20211023084638.1697057-5-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4d017869-ad23-4961-b3ad-08d99601c152 X-MS-TrafficTypeDiagnostic: CO6PR04MB8345: 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: vqOIG8dzNRZB4lHjlTpwB0vGy/wLv5gK78+A0tqck5gulP8+AwQA8hp4MSzsBXiAB7e5n5y6gYQ9TCkr910vORvyxsXZr45ir+9v7/VPGcSDQfrEluiRrM/0gDGZ90SVMK1HRzpW609FhcKrej2kUiznf5A3FfM9ovnuc5mCng3dgLwA1QHNekU4ep9JGI35AIY/cV3EteGRCN3x4MvP50JUCfZK3eunSdZR92UM0G+YZXusY3yoWKnFJKyfKNjxDxQb7jAUPVq0DVF6Aea+zVcLsJ2dGjnNqgN+wTPPAWIyw5ekYQZsxwNS6SmFi2OZb9KaZNBWYwHJQnrgOfLAXjdoWPhIVLw1OvCFuuNCmFGUvTZUtJYolxv6jnWvqofBdaUMhtinoQlTUwMuMrOLNr3vAEk3W23h2BB9+x+BLQUCbZfA8qj53Mw7Nra/eaURtMXnj5DLAimA3DSzVLjO7JRoPnb+Q6TBIFb6wE9y9Oe+oviSItcQgggttnOPJ5RQVWsc2gNOE3a5uEp/Y7ts46yZEEUky+e/qDswJeOvUKn7z10HTRpqbvtOHLLFIggXD/Lyr7w/JxzOhSW/13K60h1ySfQAlPQa7eT2b0Nr0AFnK7q+SFACbmgOUx9fFHB+9Jo9uqCLJe8NbskFJIrLUMaM5BuNTZG4SyBCGkG7rjpYkpr2TNQUCksQAkaFDEz1EdMTHxMv5zY2oeidPsKPAw== 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)(7696005)(2906002)(1076003)(55016002)(52116002)(316002)(6666004)(2616005)(4326008)(38350700002)(5660300002)(38100700002)(83380400001)(956004)(82960400001)(508600001)(110136005)(26005)(54906003)(66946007)(44832011)(86362001)(8936002)(66556008)(66476007)(36756003)(186003)(8676002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lCw4kETka1wl8wPfi3gSbDQy4QPOJiDVsxawUId/MI6hkyU/46p/2mt883je/4uvj2NAjW5sB9vV34XFWwsDkmruEo7Ll+nq7CEPQH8nvcqUl17VsgXXNmEeCRr9jYu7NV5tZH8/+3TBtmFJ7VtGk/pEDdomQnBOs3yZwsHmZaq4GxvH5mBBGL1Rsa8bPJxlSx6H81P1fAPVluOzhDj7OqBxbaacOBYsoAxqz3zAMu0qcgIST8Rs7ioF0LVj3eavIatKQgV8qAm9XGIQY3oT7NxumgHhCjJlucAGaO+0Zv/WJBp6siHQQaKFcHMes7Lt3cB3ih6polFTWYLaVfZGmV64qMMhmJ3t36scZKgonVCa4QZRU+BAu6qxS1GtAXzZ19KYDvgM/Stn4DFjvomnPo9CGfKYazXik0gXi+g/ZZc0dKAWoplyexcoAVfmIE6ueqw3jUnyypSLtvCCFit5D/GsRoGs1ocJJunP7NUnbKJO9MsxiEq6xHC5giNZm6weMRXdqL6Zh7L5UxgCmP1/c8INov+7qKrfFlneEbuk9VuTml94ZNB1gpk3SD57Eh9CB9nMaiuXZcfsVsxF63XSORva0GG2itN7qqtLaGq5u0L97poU3iOO7yyTHaC/sY6Pt9553h1JOtrISHbdOk43dDAxqZb3btH9IZ/ygQrhnfLf/i5LXJC5ZPcCCFVtjXFIkTQule+TUDu48RjFOPCqCcS0OlKtxpgRyhMGgVz1l+XJDIKN5mHs2aVIX/CcVpJxAvthSHrmz2Jees2ajcg2Vv+mnu0Ti0fJ8gzYUNMdJkOKUtgtvb0jyH67as+sH1Y678D4X7C4zRtmrezGbk54ulgsxJmSCAZpf3Q2SFsdzfMs5kL8YnpkmUHU9mQFnjL4YXiP1NZ0MgpQ6tyCJ+vmZMH10hwxinAg2YuFkk8GczUmI6u8Sf3MCFII7xXGhyEW5uAlvBCID1rxhQnQksKi2RLHfSfzoSobsRNfj1No7f2MreWHmpN8tRbw5KFDiJ4K/pAdJKyPNz2jGdq3M4TT6gWAzdkYXxJGQZ5B78KnVbx9cMj0AU/uW4J5LyItNLNYOGC4XlIiO2JmLJ4WykBNOPVZftHK1KHtb0xUL9G2t1B8j2aatESU6BqAOOi1Rsx1asm4xsaJDKMiDE9OR45f3YtdrxJ/yltP9HHRV0B7OXv+hZY1kiYP1R+7134rcVGZoydvetM/4pmgkN6EFiwJvzYfUsQlW9TNMXQ+nbXKKLMtP1SkTvAVUsqxAavvGQTlyzA2NhQfF6s5oaicWB0iwE+GHwisK3H1erjkvymnrBBj8umK/7Ma6ZusRcQqoYuHKpXqB0rc6xOeSc2dJ1erv6HEgfZyqVxMrdEKuDot8nzBNJ5AR2iYMYBBBo1gGQtroMnXNcrA74lRaOSm9rkdxAjhmXbIUwg+kZ3ZhOxBHiWUcChVPt/3ebZeJ9XZugS4mysbQxkqdfS/rMhrQTa7AGzt63ys2IcMtGCEzZm3/WdVwDJRnE6hcHuO6+cZ805euSp2+zYmPSjLedbryHtACanB7yKccMqGnWDoGBOC8yJwLuesrNW1RqFFh5FqiJwPCYqOdAULN44fceHDLlZ5ywiaWODrT3yjMSA4BpCgn3Y= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d017869-ad23-4961-b3ad-08d99601c152 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:33.5507 (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: 4sZFwdO4KGhyQIEecGi5d8T9IxkZyaxfb9Ws70O9fI0WOFuAVCAT6XB1a9LO51nn4PPQVact72glidVz2DFBBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8345 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 --- 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 Sat Oct 23 08:46: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: 1545159 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=hP5TujX8; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=F2l8ZzVP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw2F3y69z9sWJ for ; Sat, 23 Oct 2021 19:52:05 +1100 (AEDT) Received: from localhost ([::1]:52992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCl1-0000NX-Bg for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:52:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh2-0002kV-Fc; Sat, 23 Oct 2021 04:47:57 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgm-0006w2-SV; Sat, 23 Oct 2021 04:47: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=1634978860; x=1666514860; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=F4pbNsiSyjXt/w3RGLt2kpfldLdxI9pJ+NPektJMfPQ=; b=hP5TujX8kFtD/vBhTZ4sFN8lsRoSl80S6Lll738kXbtWwObd5eM9yXe0 Xm73gwvw/K4l054Ij51V1GFQENffuh6ui+6ut3O9pJLwcmHSWEmKrnZJS 83vYAISlPqoEIgD93uMBJttEb+ceN04P55UtVBzLX+YXyke6b5iKGawPG +Kj/5G8688av3K8xqXv5EqMznj6O9uBmw4RCKItiyaGxKLHmDivNZQZy2 PpQO/Ct6S1SB7Nd9Bvv56nEnbdLdBm9ScJ2szqBkYGK8JE9gTXUajbAoy KVR9N2DtrAslAmEjlo4ozWZScFiINJJC+y7f80Q2W1rurODqbQaTPBLCg w==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398052" Received: from mail-bn8nam12lp2173.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.173]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:37 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kOM7qUFxXt63jYlSVvGvmw1jgubFnHkALyll0etrw2KeCzZe46AXvnWZsfJlnkE+4K84lBrtmh4aBglGW0j3ln8sFKiOxUIEVnas8Aa2gCbEcpdoQHVl9IUznn66zZnxXd4TllpcX7bNDpByr4oAis6zEKAD6N6axNKuMqJ+v88nWX6dXR/hWqqbHfHC8yo6ZqgGEf/iKlhNDxq/12A4yP9pUbE5aVO/ncTK1L14I6PteOK8OAlFjKGqrqBk64hPB2vAEIgKsJkMOiVTSPVMnCY5/k5dULTaceVBViHOZGMwyHal1+UQtE1G9OQwTKXT1myhdDjS1FaBknvi3jlSIg== 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=ngT1N/f4VVIYpLpBp47dScmO6D2TnW7P4e5ajIRJqKvj3WeroYX1TzjYZALF1tQXRlum+7sBF7kWVgWDArlSDJfMn5IOW30ywXAKG62QNsExvrDJtHYOYvMUXyr2bJ+H6K++0tnwph0UOSbOVVP4ZmyyYMi5hCFhaFNUyh3B4oQYV7loIk5P94+6LZ9WBOpBywp5Ia3m2edRvNVThuhXQj0fVUW67zoZUgNWzwKjgCDN57+Ki9ZMWCSi46OytnwkoGotnDLc7WZQ7Qs8p6Sv2dfC55gyjXEi5tB790V4/MoMzmvhNuX5Ii20cp9WKQGLe2mUvJv2Px1DR2LhSA7XMw== 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=F2l8ZzVPfmB6R79eepI58d6FcpZOBO9nC0ca2iGAZeft27cxxZzACGHHgX42TR1L6NjRRbdfGd3wo0zo5w/zFPD1eFhfMDlTkj5cY3vm1RS4Wfd7ca6FIllwDnEe4YYBKzn5Yz2lgLcqPrA62G3ReAhsnvYosBkZgSUx5bXQ91s= 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 CO6PR04MB8345.namprd04.prod.outlook.com (2603:10b6:303:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:36 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 05/22] target/riscv: Allow setting CPU feature from machine/device emulation Date: Sat, 23 Oct 2021 14:16:21 +0530 Message-Id: <20211023084638.1697057-6-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1effa527-7888-4904-54d4-08d99601c35b X-MS-TrafficTypeDiagnostic: CO6PR04MB8345: 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: E1rf21hXA6bptpuaIjWMs7fbnXsrw2dC+Scr68/0XgsIAxYFLggXXfDEBX1dTW9DrtnMRzBfKwrxyaNbdSbZQ29PiKh5x3zXxrhgMmCXvxTiWGulAlc37oiqIe34gNzWikoCUDz6CMLoP50sh71LhJFGnr1XjZ+LTDYH8BW6s3X3JtJ96z/we9fwOJQSuow16xjkoEwl8hQjIXHIiMEDN1sNtuMDP0aSJ8ZDDzHm1PkoxVgD7Xd3q19vRPfXkG7cYz6hYC48DUwsE6TZfPX00g2Al1rEN0I1rfvId7swK6QELxAIK+k7BsXwCiLq0sHC+9DmLkTQwcOhi4YWV7p6FWpHYU2EEhsfaf4X6tFH1ZHNv26ZQs+cTVtZBV6tXgAUXxNNY7uOPHdYpUtNswYdTMCOWC6ufXK8/zkjT4MHc42JRNp9SV5T+ik0Qg36dA7fVJkkGdILnKs9s634/QGLdQP52vxpiveT+qBGFNtEXATWLHd6ycBru06a8cecc6SpHWRpUOGif2vqJFpC9YczfDSyX2gpFzvxeo+LEyU5KwzDILS4rC+XzS/eV67q5DQfzaMEOriyxEcGWmkQLtdYFyM9I8HpXJigaQDieVnNh2oHQRNEjAfUQXDPY6x2WkWHjkR/mDfFE1M8VR+2MOv57w3wTTukZBRtqwEOS+uvnAvtXxg+73UXVIwbsyFUbKaYevEaM/YHAtyGjG9xWm59hw== 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)(7696005)(2906002)(1076003)(55016002)(52116002)(316002)(6666004)(2616005)(4326008)(38350700002)(5660300002)(38100700002)(83380400001)(956004)(82960400001)(508600001)(110136005)(26005)(54906003)(66946007)(44832011)(86362001)(8936002)(66556008)(66476007)(36756003)(186003)(8676002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +ulDt/3pIA8dXGv7pf+UjWlMSv3/tVVz5UbwkibSU2pr5td2q6JTbj3rq+pHRD3DWOEZdnp/7y14ztYJNAsgl5FRA9wrmodkyWHmmL/tkeDcMfoJpBFA8QKmD+50PQXc3Tra7DlE0OUaP8ddvFt++0E2Bp5Q8CfE8/QM3Yv6/Vzwu0TL6Wn9oEK46U3kjiTFE/v6/Wh5YR3/xpl7XV0Bs8Svbnw1acbyoPIOZ/0tlQExABydrcly7QTgUtdaqVpRM6y1tgt5Ul/Ov17XEFnslFMZbam7axTiurwm+tVHd9Q2LCFo6YJZ4acbWv1hEY3H5tiYL1Bld79aEAAwJBfdgeZMtuAbwuPY8q0dtR+58U1qzrgwl2VXwXiW8fLK8vn4EiANzQv7LsgDwbK6jnzuFdy7NsQg9SQ6mVPUpZ2ISKL43oskbqm7sc1zbuLC67nDf0sN0hBUBdHKFNAN5tnOls+JiZsPkAvdRqagBNhczC55y9xSG85ndHpFbqX0knfKHqwcmAMv30tJoEU8WVJs05ZO/2js1GWV7J3++Hkz5NfSjbGFkt7qLIkddsgIA+eua4/o/rjWK05jJePwIVNEjVWbTXjcirdbFZB9dG4eHoGnERt4amcQ8ErbIoI7dtwJR/4/NGN6oGE8pNQEnIAGQ7j/ycgZFiyJ8FAyPVmEDOK43tXQvBUx1AhuYqj+wEsaDMPpvoltysw79X6bIgWUXjFb2r5YD7Cl7Wv2DpyRNCt6JZb8P3yoyslePPJU7iL95nK/FccnMpUD3KgbZt0TdnqAbN8LM0yWmTtikDjcJNUU3WCC0QVaEgtx1GlT4cVHHuG1jB4/E9s59vUXZUC6eIOYzULOoajanrUgiC5E/3aJCadaP3EKqGkLpUCWXGORFmlcwqLYgvG/hrfYSeIyCjvIAhsQk+3SttdqjfbfNUvhGn+Z0axG9uYLT6s3VjZrkVloQb+92m+5VsbM2KGRZZSh1Xua5XAJfu+1OCBdV/vL5QaCoCaj9pIZTbBabckyt0LPV3rsCquc1uz+dPc9/V0HXBbB4LotCl9/a6aCLxABO4sZZxoFdByMdCuwpe3zd3wUf7Inhi7RD9RCs87Srq2p8+calM94oQn76psdkfkazNFgkmP13rJDHN3OD4IqNGf8tg+jIRVJbqHHv7+DKR5rUV1ki6welbG9PoV6oDtxWeMpSMWbJLFOr//Y1W0gqqO/kPiKjhzGC9F5nMTYOyI+1H9ZqCZTuAQrsAywORv9gz5+MwjjxjSZvmieRvp6C43hC9Gy2j7Saoex/f4DWrEK0tzBSHPPX+JRf8T8NAF9+cC0jJDmAwiFj66qekeEZyuEX4a7zrjMhypmUgwngIE8gk0yH58J0TMZNQ2Pl2n8412zTPSqzvywEg0gM+IEyUoBivx/wNzIgjpkC2OD4ePiw8O8i2SJkMgHI8Bi3EbMSL8FeuPFGvAlcl/k0dcnwZvLca/VoXE5lVrNDYQF8tMBNmmJ/7WLH2EvbdTCf/NHIX8PeBp+mjYBTTtgF+c/wnFOMP1sFyvq5N+TKJFPjYWYDIOP9PnxP+oUQe27XVlIpq6VH9KUWOkn7lkmTCuy/esF3Gx9Y54xEOOFqNiAJCw4XxIVHz6C4ueLylx5lM8= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1effa527-7888-4904-54d4-08d99601c35b X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:36.7706 (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: eU21bYxSx8qNTUjhXAt89d8wAk4aSk9UQQwFmBVhdNFO6gTJLePoG0ChCrLn+ogB+10phE6Vu6GZlS9SgAkN+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8345 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=Anup.Patel@wdc.com; helo=esa1.hgst.iphmx.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_HELO_PASS=-0.001, T_SPF_TEMPERROR=0.01 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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545157 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=ZAwqFyoA; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=kdrzeN7t; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw1j1P4hz9sWJ for ; Sat, 23 Oct 2021 19:51:37 +1100 (AEDT) Received: from localhost ([::1]:51896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCkY-0007zZ-Vd for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:51:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgr-0002Ri-SF; Sat, 23 Oct 2021 04:47:45 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43328) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgp-0006xZ-JK; Sat, 23 Oct 2021 04:47:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1634978863; x=1666514863; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Nx9wCl2PjPZzfxgMbTLUztdO8ypGA2pn2dH8yP9taUo=; b=ZAwqFyoAxL2VbeP6agoijm01a67WL35R8WNvbPwlpsleAZFJqGjfoupx URrb0YkBTHRpAqMHPi/I5mrMpwcd3/zdyRYSspBLv5/Dwfd+OwYcd0vHu HGXFPHWyESr7910fChCzbSJS8ZhpBauEbXpf00cRblhRTiNPI/HQh3EuZ KLThreOd8n3KBSr18sWkAaxpzZQa8R6POz8lWwpnbJGk0w1OS9ZUt6yMI 1PUF+4M7YVXKkcgqYPq6xjY6oxavLNj4fJaFPkdT4/2+N3NSJWAmZJdio mxQdMQbFmmMU1rWvr4l4fw2FM5VJElb7/4V6p6G6UAQZitBvmmzMWQnij A==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398053" Received: from mail-bn8nam12lp2175.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.175]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:40 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j2za67qG95e7IPFHRlnv5lZs4ElB9eza1klV7U2x4Iw4nao2O0Wz8IGb610sCiZP+83qVuVTHj0KieQ1EyS9foGFSoPi8Kd5K3IMqxAPTrljEACeocQCVm7QYMPWxJ+hbOEGmn7vjND6fW+xzNqPVb2WcPuYP9S/hZ4wMv+11WlkdCmS6eBIJw6FF6mf3VRANfemVZcGN4z1VLFS0h3Go+c+VSIV7fzQzST6FMlCWp+d9dIXIKfRMySkNkPLW5rZNYO6mDu3vPbD9MlvnQuOtUa86wAYiHqwMjpldm+mMQw9NEsZOr21U4QlYPLvhZlbH2Pwb0VA9HsiL5jBsTGbog== 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=J/uUctjNRq2ydDZ+ylA5EpOMP2afgSW8mNtTk0R9/PmddWL/DB3PAEjkLU1xkSq4GoVQsrUbf6Z7hNJLjXGA+Cyul/QM6lRfnDOJuQWI9GIXBX+KkT/HNefKgF8wAKN5rtUQDlFgYm690ZejSL9OxPm/xITKqz2riDX8VEQTS+LITfv4RcolxmIdPJqMwJ8Ge/ML7bz7RX8+RFuVy/bjkEiR1SOesWPFuyhn2VrYuy7TzBVZtNbCrkA8lg6DAp2tNGturywCu/74JvwfrHtgowgRnW0978MwTfFdri+DZ5cXUGaZWxq4ZoktwnrUM8Lw5ZxmxechBDWy8Bm/nIW/Hw== 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=kdrzeN7tM6Y7QqJTlmlVURQUqN3ngMRXJW5W1zlXoUXoyGxJGeb+4aTtRHWkC5oIEH23TqMoAszwfbd0USsUhoAClqH2AP/rDe36unbVzIIYfoxE8FR9Oa/J2gaJUfdHAOor+o52GxLNve6JISVRNYJjCk56KhhLQ/28QWWD+10= 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 CO6PR04MB8345.namprd04.prod.outlook.com (2603:10b6:303:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sat, 23 Oct 2021 08:47:40 +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.020; Sat, 23 Oct 2021 08:47:40 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 06/22] target/riscv: Add AIA cpu feature Date: Sat, 23 Oct 2021 14:16:22 +0530 Message-Id: <20211023084638.1697057-7-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1cbb8b3a-6733-4cd7-d137-08d99601c544 X-MS-TrafficTypeDiagnostic: CO6PR04MB8345: 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: 6899eGAHReOaciqZsDVRr/67owX1qCNN80qNHGa0PsXBaUiFMIRHLvSlGsZ5N+sg2xZ6284/06PDOQdJdFDHcrds3R45ZK2K7UNd6yPV92va+G4XjY2HPARpjAlObCsYPgRJMTo6sIIKWd9Iks04CSr04LjX+58KpOISpxp3Dj8cq5yVuGaT5GRDn1xcTwl49cm7V/fE1kWYIz2OmR3008W2wp+kr6Vs2t7TTBSmzRyqNzZPCpEXfdyd02BdEhAcLaBHsfIR0Gl6EYPi+ILKS9DaQKH92WxrXvZNseBGjfdqWwMxm8oO1e0FIpvYV6N/xp3l8JiRUxNJtxpWFDc/AgZzG8Wf1Ykm335m1EHA0UJMe1hRWB2c+XofaSOuWOEE22KDBBwSzvC5L+xc5TaRYTuzI8bNn7bldPHXe6DDb2v7nPIgdDwsaC6MD3seSKXHnTJf5uIMCiQ1Z6ZTeQQeaZIceZh/H4iTkACYvXmsTY0ELHLAj18F2cTQgc6347ZxY7LlJaN6u/S18gyr8tGjebeIRMkgvpz+7zSOPr8EFnRObOJT3UcrPHsBEqAYerBSP7h5BTotlGvOLLqGm0uhJiEU9vd/OliKlfqmcNO2meFnghcmc/+O20CD5uJQQE8PziPzAgvljAjf5iRKpXXWFWwakyL/i7y0bRBXTI2kqQ7iFBu2wog3cYujBIvyxcG1M9WAbT28jydHvbcHbQG/Lg== 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)(7696005)(2906002)(1076003)(55016002)(52116002)(4744005)(316002)(6666004)(2616005)(4326008)(38350700002)(5660300002)(38100700002)(83380400001)(956004)(82960400001)(508600001)(110136005)(26005)(54906003)(66946007)(44832011)(86362001)(8936002)(66556008)(66476007)(36756003)(186003)(8676002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: njaVmuh5jPaJig5ijfJDgcYbvuS2leWFKGEeue4RBnfL7bZgOkan1Rnnz9Nd/RLVB7xze0z0VfLBhijOts1Uijq5CyxmMEh+bLl74w6TygUWEiEp7HZrWgmlnVKNmB0eYygvBbXGsfovwq+UzQNSNxjVq9Qv7iEeHXlXLTSJ7agPiWmWZDXqlHPE3a2c+9Q6l3eEpgUzJjPgfDABfLIogT9QxpgHN+xGQ1RqGFnAjroJbnSw2043R4usPpjstG52QVU3QSA5QB/u5qS5VmTUPibnhcJDpGhWlx1Gn96hV1vJTO6gBv+vNeUaQtHnEoUxqqww690PHTheZxnmAmc3RIk6yvg2jgtxFmbop2lfeb9dkuIeEgOPC35g36ecqpyHhY1tQJzbEYgZL8JSKNlngdltSmUuHWpkwMDvDXopei0YKIR1Yu19RuKVi7pqigTtnudK3dgpq6QHeu1KAxnrU8cn+RzJe9b1fsrRHTVDIO8VdO6Q4Y5P2FK274A+47LVU9offvWDuywGVsg6Y/1oMYvlgIJfzYFdMHYjb3r5glizILQlud2hQCX3X2KUlWTDcpZz7oFr2+vsxXL/ir14uc6IFa2Vk/lm6XnaK4Q3NNzm/STNNTmv90dv3R5lDMirk58fRWRbddMMaB6QGroMBkSC99t0U0avPPaYTX8WfZdlgOZ8p3tdCzrFTkhV0lrLY2JNEdhVdE8d3N7xAj6GG0j6aLFfDNSoL1bmrab+95D/ZAnMPUDZse2TVPXWhCkrUoCZrFDtSNWdPgZ9Y4GZ87Izd7sW6hSrIecnpF3pkoreY/WAkBpVNyjih8POleRYBtVW/PyoSm0ef3z3y2QS3sqEvc/praP+hgVLEy73KUPwsTadDK0dL7tp6lQC+pA6aQTfX43+g7ggqVhYQJeslEtWkPe7o383TB2KIf6v7SahYlyjSjz45FaQTNOcf2IQgcwlF4mdXYY+conwZ0OWB7bIJUMjiFlLRsTKWmJgM3xuEHDXxYuj8VI9V1jkCs2U9p7x7Qr6/iKXw7zOAzNcqdNYocgLgSiYhi+REs5tfCp4cWaYwPPS86Lvy2joh1BZ9D7sisHN5m2Iu2y2lNWARSYkRuwAkcTFvLuAemTFIdqJhiqhdxfZXmktE162Fys5EB8/pzJ44xkbJ6/XXkKYrgS52haWNyWHEBdY+yB9bT3BsE7A8ugdsJQrnCmRrQVgXGINSRdKECwYc9biCNIjOCud8jnK4+J7Lpti8ixHTB8HZn9HN0C6cCtFi8NeWMIE1jIVngfkJhINSyWCqgisP0yj7s3jYgQ9RfsBB5tyMPudkZJM9NrP0wA+cNaRPAFBLqOr8ST+jvB1P/1AqjAqnnOipl+egH7REe707usr7Olq/TJd1KfBLGxrShaUi1CDkdn8ZzpZ6BIRehOkvAQXtB7EbH1f4FsxU2FOErIPoG0+4V+luR0smJ1sr5bZ9M503GO7NpouthIKXgYptCANgPQX1l/StRp7qIkKTt2yPloGIZ7Oww4HX+bdgMzbGHg0UW/+TEcy48aw2mVD/QtBLwwu9z+5Cvi07/vwtaiYz71zgMNF9TdDsxaicibKBLNITKIgxsPa/ozSv2loKmE6bMickQVHrcNOzdltxjSfad8= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1cbb8b3a-6733-4cd7-d137-08d99601c544 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:40.1865 (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: CLol95xHRXsfqEeVIiDJK/k525rlfCRXs0d9JIGYGCATS0tZHF6niMWeEJcDajW7cs/ZC9njrz7O7/VO+RC9ZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8345 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=OagOroTv; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=HhtXsuoP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw4c3FB4z9sWJ for ; Sat, 23 Oct 2021 19:54:07 +1100 (AEDT) Received: from localhost ([::1]:35726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCmy-0007ZP-9F for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:54:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgv-0002eG-LQ; Sat, 23 Oct 2021 04:47:49 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43328) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgt-0006xZ-1t; Sat, 23 Oct 2021 04:47:49 -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=1634978866; x=1666514866; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=VFsPm/Le0NmunV+Z0t7675HUmm8YKZpuqWcYIU4WpSg=; b=OagOroTvVY71w0bmQvJeafMmaqayunCxf7uW8kNisYxkyrwfLjb1Cni1 1exn88cpbju/0hR33RbxpReUu5Tdma10q49FC8TwXrMKGSC5R+kgjsPHY u84qtT6ZUoem0Ddu4BBtB1UEqdtVfPHI9A/py0ebvAdEf4xLwC9PTSuHy z1rIZKdwmLyuVmBtzW6fdy3aiYqfkdkiGYrYt4Zm17m6hKgD2gQ8D8g+9 rK2z1hLyasDJE1eGuUCbOZ17s3Epmf6OUEIGlIrKai27NPA6uEMI/Yk8x 7onjla2vvogm79Tf6RtTTHr4iJe4FuPzuJIoASfkli+ChtOD2BcysU27q Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398055" Received: from mail-bn8nam12lp2168.outbound.protection.outlook.com (HELO NAM12-BN8-obe.outbound.protection.outlook.com) ([104.47.55.168]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:44 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lBCIQ8MMtaRDSaCkSrUNrPtYLEWbAlJEIAHTXym3p+7S10C1PlkeOwcuqLjOYXTf/CUR9yYL5QOj7GkcVFfHWnbhrObfax6hWbgTSpND4u91/+OuPUzjPLza+nC2nmHtWepKKbvnw5je6MbOR4PGKUI1pFbJzWYhV1jMAV6H++aa7M2kv1zt7YxDRm0jBKZYLisF7Vewjq+ohzis/oIQOw5981Y3t9XBXHAV/Ko7qWr57gApf4FfFBpVJlYeXAPodliwjVHsS+u8rOJPb8PtMY5dne9QyTf05gvhScBolFVrvVlg3LaccEPtaVkTvgEgeJU249mETxhC8rf/jNBbTg== 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=bbiyBGCA+HERVkd4d4OhIZko5s0rYMJRfP3YscBnHlXADW0zYv63WnrN03Js+/HqNpfcI+nWiMd7E8TMKJVV8N9iBvYnJC96j8rJMWnHCQk62JHPjvM1Hb0Vys1A6ttnTmcR8ioQ6KpL7NGn4VSaXWdUfgqiPEqfv95lC77StmVCzfu9NfrJq4a1FQCKVF/jUcii9yWl89+ZXPsw92qm+aO3zOkBuikTpx7eKua397QOi3iOFV311W95jPUV0niv9qy0gX/cEivIzS/3dfn8JKW17wxoWwovhVnrsRIiMSOMvohsBzNk7080kyqIZrdZjT7HL0DJQy4KJPNEl7FtpQ== 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=HhtXsuoPn8KNASHAAglZekr2jm16jmmJu101szjpZ0UfVX2CnPEGvKklzd768FMU6c6Xyw0vk1MpIkH+c+JNh0kpfgkF8LbpmW7EgOYK7ZHJ3A9CWh+h3wZpQteAQfzanBQXJ4BTdr5dpDc6ed6BJk0u660y/3m8AACx0uVsxI4= 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 CO6PR04MB8345.namprd04.prod.outlook.com (2603:10b6:303:134::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16; Sat, 23 Oct 2021 08:47:43 +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.020; Sat, 23 Oct 2021 08:47:43 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 07/22] target/riscv: Add defines for AIA CSRs Date: Sat, 23 Oct 2021 14:16:23 +0530 Message-Id: <20211023084638.1697057-8-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 620fe688-eee9-45c2-8f72-08d99601c74a X-MS-TrafficTypeDiagnostic: CO6PR04MB8345: 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: L0eWOL66EDUsU35Bu9jSXxMErNEsj0V7WHvgAJA3PwCCV0k8Btg+zriKWG/T8Gheu8sfvC8YdVyqAqPusqT2mEUAQUkU8rQ7s6xknaYZnlnqdaSPHuKFyGsRRGgBeTU3LS8P0OjsL0D1Cli/Pc+JPrc8jmfOyFkE7mjSpExc1GRSO0rq3v/r3Cu0tsQDogKHCBlLkemgPvKlG9HH17wX06rIPIm74MEwNKGBZObDPFxqSSm1Gz/01NeM9h8jxzcPP7Vis8I3JK6LgKmla+mD6o3aAuPtdSU2cCXIahLeNtoR8gTHD8tOeM8amoogLaynXh4gR9ru4hqDSV29iB2NnF+3IBojmfcVgx8tQwRpkxyPWHm6HJu4ljk4Mmt9KvT2l1geh1hzd8Tn7awywas+5iSiIv3ZO8XIISNifQSO7e3oW5yauKqlskS1X8ctwsASxBqOIn0DQvK7AOwwV8jPU77VA+HeESDMprIMEfi3O+fS94y84ZliN0g/5ZXMoDOum9Igt/kkOhumO1jvN2n7kyET8D3jBmIhVA41CjbwOhBwXabmLxTvUiR8+UqQZNjS9HUQee5YCoKkX6C7Sh5Q2x90cTQbcQbfWWc6Qczn5QGVMNMBfZm1Ga9A2CyWZc4WCgcJtKbIr1q1Gl6wdD87fgxX7/RIy05fbH3EQQGNto3O71mLRCrwpTmetbZ7sWmB6C7/je9wC7sgvyPni3T1QA== 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)(7696005)(2906002)(1076003)(55016002)(52116002)(316002)(6666004)(2616005)(4326008)(38350700002)(5660300002)(38100700002)(83380400001)(956004)(82960400001)(508600001)(110136005)(26005)(54906003)(66946007)(44832011)(86362001)(8936002)(66556008)(66476007)(36756003)(186003)(8676002)(8886007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F1L74zkBjibqXMNGK9OIL4mqNXPVPLGX3yJx2sTzBeWc6K4pzpRxSnkhAwNfxqVyWtAgRV2jxkK0hL+EPVI1dQ9wc11hNGVanFVq9BFJEOmS5+RbCVKbYg4oNqa8Z0nyhiUkfRxc38gk2chJSb4AlAIF80nXiVSo4qol78Hc+4DuNAamv6ecQyHBun7ViZYuRvfSimnm+03vbMIaj88XFUWNWGpuIrOdwy6YxNOmAmH4oDzASmI3uyhLoXD2hv2IG7Ekca0xlvQKfmVDJcaDX8cTO+fwDwA/HJhHdK8bLjvUgwMLpv00DZvFoX3o2DZq4mmkpPDvuWfYHxfQm/SiZ512J5Sbqt1GcVgQEOdSmMB1tj5J1TCA1zjKB/Xxvd9imathizdi+sKBnojvoJ6zv1+2fhohDvinPAFBmsp+eqGsJUWZrWnl1xj0m3KANNSWnL0QmJ3IwtSEoR3yaCN3HDKPvfwaQfOORDQuAivk6qTsp6JBUAES+fznlTheHv7bo38wcNu4KeJ0goHRVKl1wdp5Zn90d+eI3lDaJuhQ9jcarLCWVEM6VjFq8fpzWMFTw3ZC1M8RWk2HSADvLjEMDrNGHJFXbU212yi8k21wvJrk2K/nllCeH133BYvDBrhy+5GegK6JECpG9qdYd/OGSukciaFkcS7zV960frkf41SzeP1UmhuKwu9G39cQ1v+DvcqGn/AodLPBCAl5Blup0c4SSOlSNUmkVJTkV94/Oo+AgqgNZQ2c222Kp0pcTzE1wHp+7FNLntzQBH1KTIuy+NnAXDI9Q6qjJWYogv91QAFp1DgIgnd5yNH78MSUG/95AGEGa4fCIHjktazSPFZPEgEaIUSXN8HsU/qgXHRyeI51fGxRlMmsvuJXLbBqu2BkfACRVA1OLEVE/LzCIxDuI6K4VcnAJWWcuaHIqhEOxxBXiN8CbiT+0RdC5StMIU7V3t46Q3NEvXxgNStNUkg/hXP7fAZK6JFCT03n0T9G9cVhAT30wXKwQ/dj2CvS5xtuvNdAsB2VcEDsqi0Ml1eZY6u+bVqqSTew3/P4STz4Yqlc9zKXfNPZsbGzQsRw86eQEBXV86zMuST4KNM6Dnv79/tJG+VeUACozUFaGbKJNGBwmWV/aSJ8PBu9kCZGSqfD/sLILSWhXXhJMpuniPHIJdqWrt1K7fvVxyFWWxSTk19LSSFdkbeChEk1cZdoLloGctijcgiNjfFLMSUXJn5hj+j24wEQYhDS/ga78mtJElKO6ETzwkTOh23Az9kpW+UyxWss5t3v8d9+0mqbvXHGUMdpQUkmmiXELWy3D5+dKZKvBlwx3NnpexJn5KfNETtMjtCePILFYiXCNbm94RanRR/Pogk04ZPpTFXS6lAIbhBpkD9Q/L4CJAPZPvUOw4QHHF7cCw7pvpJNAZiowIi0JzZR9fmnt2KokO1MFEpDKrS2B0OiUCyx+kJyCqKLjCofyEGjD/PR6j03zUxvgX7DsIbU7Zofz/dFM9SjZdAl1cZqeCsUrBC2oa2VGI/0HyyZM3iHsi/gQm9ZzHoSAJiIW4YanPvojwjzJ9kdtoTZyfMVj3Z4EZ/w3UqyLcCjiBsoTETU9Db9iDtLL1AESXlDcqXSWaJaZMmI9iuzd92P7A0= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 620fe688-eee9-45c2-8f72-08d99601c74a X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:43.3636 (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: gplMMa+LvQsUf4OHElblG6N/t3NBZvPxYfyeSneLQUyJAG6Bu9wAmrkLh4QJvEYMwQHmuCdiy7KaH80Qeg/q6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8345 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545167 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=be74hvjg; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=Zhz0Mf8j; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw8c131Hz9sSf for ; Sat, 23 Oct 2021 19:57:36 +1100 (AEDT) Received: from localhost ([::1]:44108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCqL-0004n1-Sv for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:57:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh1-0002kT-HJ; Sat, 23 Oct 2021 04:47:57 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:3769) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCgw-00074P-0g; Sat, 23 Oct 2021 04:47: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=1634978869; x=1666514869; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=NGwNLy3VtsuvzQvknfNkvFHGtfZZZZlsEz+En4k0Ids=; b=be74hvjgGGPnzo0GAOJRaLAVdyDWroJ4NRFxvYL0blB94IF0eTC+zb+P BtViOuYSyuFHcrgoHWBLGQmeCqXeE7ZSAIyYRoTxEOO6Ti20n85KllRzV twCSXOxpFszDWu0AZtDNPq5gtC6ghFgBjaFxkbNPTpIJDQ71gO3uh7wAW VoI+FDp47le7KUOtRLf4rLonF8pgXtAJL3yz/Azt+BEJR7CszeAF+3WXv 17m99esXsfuvRx2toIrBo0yNvdTAvfgnADxlI9EpfmMNzr67P8rRiXzAd sxpTnV3CbjwkQhFKgXS/5cgudIYMmX1LaQrW4EW98kjniqfVoLC435nDr Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="287539676" Received: from mail-dm6nam08lp2046.outbound.protection.outlook.com (HELO NAM04-DM6-obe.outbound.protection.outlook.com) ([104.47.73.46]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:47 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lxOmK7nSgeRmJh5rkfPsKd1ZVZOJbcTjaSHhFrZAI6KALlpbjk2eSqlLAg1dWCz4hAswDQa3FTzvG0nkg3PqbuEpG+l9f5lIAE1gFdz863MZC1oY2YYsGP4NUHBINevYeIYljp6MwYZhDlSkkFZ027tUm/XKva0IeTiWsIZK9nHdu7/3lyHgMX/b9BKUf9tBp31KWxGcimdN+MaeYzGcqvKhebnTRKNuFpyakHFmnFyEca7EVKOL67g807N4t+p+RelJjkqtZbUeRdv4okrnOIEOiI2Z9vhXzIHfMEcZ2cuLVisbYSeLIQMeD78kp7KN0hpmx0VA7sKsX7gnUdq+SA== 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=GsydG9/1U6aKyIwVw7z9p493nvK2HDio5wG4/r5n2lkwz4p1WmdwKWGp6JnkKSUff/6Z7z30hY0GYrOg8maFL0F1x5BBiTBM1srgzc8238OtlB6o1tJG/7hb7H1mY4PXRwJ9PKdHbVZni1cEmAZKmxhwZyksnTAsqevuWuPDm2r6EDjQHmRqAxOMepxvqnZuiHC6WIHRU5flg26Ay1L2N5ydbY6t/PMPG2+aFoGgsp+fXqpYTnjHox25emiNBBKF6BXDKFIVRbxkQWTenkIuoe6lSxcp/1pyOBxT4vz3MlwV78zsSYVZ6wmbtCqfueVe/7Uh5DA3DKHb8h6PUhUg+A== 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=Zhz0Mf8jSbu62fEg2YL+tv+TkSR9HlXwFxDM2YJQcTnioCIV8eWJzrNW+7DmeoK822Fqc0OfKSZp7MCX9vhj9lb3ReRYFmAHPYGuQp6m5fjhD6iVuQxx2Cr4vsrteicxxENRg7A8N2lKyF6aADG9t67gTSYRf6DuLIiJ5y8fAzo= 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 CO6PR04MB7793.namprd04.prod.outlook.com (2603:10b6:303:13c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:46 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 08/22] target/riscv: Allow AIA device emulation to set ireg rmw callback Date: Sat, 23 Oct 2021 14:16:24 +0530 Message-Id: <20211023084638.1697057-9-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1bf698c5-7398-4a10-8613-08d99601c91a X-MS-TrafficTypeDiagnostic: CO6PR04MB7793: 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: kSoDo4e9KX9TG1ND4HzUcE+Jos5YXf4qhy8oGgPxc5OCRCbKph+KzmdfpuTy5ceDYjYOSRXJ+DhibOPp30pSAPye+ziAEjQEWm30r9/jNSoYu7qIrvEYd+rhBYcwAP9bQ08GKuYoZLqbUQTkWcIPHdlhsqhoJhMYPdjiwF5XnA/E+3QJxSYHu+mE3Zoc5cRns3Gaej0vIYWg9iesNN5pM9BTY77Qw9i3kNiidNz5y0lIFSqk+IhXXfWi8E7i5aoNy3jGEgTeWQ1ltttjDCiWKGSXdFcDNUwiv31GOlTQFF3jumZ5zO7/0Vx86GSNDJEJB6IETp1d4YWyP3dcEgG/cf5nTMDml9pCIvXbLXQlWkZmqSHv91eydUoaayQnmarcK2BTRjoHS1CRFkYeU/JbjND+ecR1gzJKoHLgm7n5+H5B4AjPNA/HLeVn4JHi3HnXIOrlupSV0C2SRtRZcPPKjUetzrJO07rOx/+TSQZBEEL1vpxqB5CBMkr9kK39g8GSKxhw0d9MrEzGWE2PPQfnPqb5XbWn1d3BLZ/kfG9gqCQyVVWimU1KqDWevlw34JLP+CSQ/EwSwb8r9f+kJ+tLmBkHD/I5MnBmCo7AXYLy6yjOIN1WlZAPhqtZdihdhnFxQYKesQKpYbVasPBszAuB8Ub7s9L36vppqxU6N8QICiZFX3ZV7CWEIUrqlG4rgG/9q1l7bzygHVHJXTPEHh5HeQ== 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)(66556008)(82960400001)(66476007)(66946007)(52116002)(186003)(956004)(83380400001)(316002)(6666004)(38350700002)(38100700002)(2616005)(86362001)(4326008)(36756003)(54906003)(508600001)(2906002)(26005)(44832011)(7696005)(55016002)(110136005)(8886007)(8936002)(5660300002)(8676002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GaLv+AWdsiQIQ4Oi/xP0Fg4OnZl6ZWSm4G0ND0ehGUuknvkR2qNRJOe7TV+AkNgS9gmVt0dowMGqB4ry4h+Fo8N6LRf24Caj8plLrPGFmGaF2kOmVkR/5bLFzWddO+4e8HNcSKYPMRucNlCd/FLw69FtKwv4xm/UlcHPRLPejVnXsZA5EgETM6fyBMbXjOXBMP4hsPGNQxp2j9/amA5hZ7d0KzCW3cBwPrPeZAgRcPMxX86hpJwUqOjvhNBxnu28UXgLl1JWWIHk0v3Tow0aSwpy7dsAzeyEZokHH9fCQqodz3FDpwByQOhVV4o51XpAEBkhJ/NRnzFvM3L+ok9GRGeLg+w20KTas8ObK9xXEj+KB69+2m5X7CIeCS9t0WJDo49Bm1DjeHKR59bmPHYN3zas4Y6PbRtvJ6xBO3c6Q8fYesuAfFx7IqRtLSI05jRpa3Tn+pKtVIXFT3gJluSnh2N+cj9qkst37DDfWVosoTwt18pmiMNK1kfy+O93jjqZImASYAB1chuPumyKZ718+UILiwNaF4pctu2dF6+mt5GUn0a6TrXddjy4R/gp59LNznYAphcGld8+lg4Em4Mj860NDQHsGEurh/QGrDYUwtfQZR6pN9qaN3W+HMJsSOxQ4m2YZKynmhMtfXUAiIxZaVZYQQewVlwvHRpjp4KaLJ06c8yd5s0OIVsnTJy+yRFK2DYlVZppP6Uggmaml080+IlNIDcm3AANKDXuB6chSUUfSymzpAee/HHU7H7YnBlYU6Rnn8uNambkEhx0lw/mIvUeZMQeclgTPU0Nf503NAUpoNUcPve/T8tX7N9FgfsF1S7VI8auRlAZRAMTU9lc7QInzSkeIDjyyusNon2PbNX5kvl0+pJLAUckdd+ZJaXgHDvUpi4Um/yd61zdQKtXedcmpb5rEQGUgmdOM81BMFfle3UA4duUlUEOe/E/v5AbVn3qE8ajVZHksa/W9y9E0kEnudl0S7QmkFu901UtDFPs1Y8jzDhao5YZIysepOyiRi65T3TGU7oNI8Cl5Oyvssoz1BUmD4SC+tLqXMPfCy/n6oVgoHjNwek7vHmKM2So3VuYBvNJR0WjpUmzMmvjF25K2L2BiIDlF+FN0l0nkCPsat/w/EtEDdjVLYRgCeQQxXX5fMB+9PzhT+O7wwBYhc/icnp9oO2HABvv5iCPtPMQvMOarUfil0aTeBUqh7ecWI57wyuJ0EjCDaIknAWr4JJ+XlxHgC84xdzdC/jnYZxJ65YD9gpA7WCRkqVZbTSdm4eZdGB7OnlzOZ/N9+YoTJWIEBrWvx9CEvWPHwyl/nQ7MfSxnqznSF3k8unTkfEBwhlww2XwUFWQ9ch80qPileI2Z4AmUnI5Vs8gCI6jhy5p6IkM0pRJOlMKLtTzHDN1cQyYEZAWW+koTQZY5htjYfHcAnmvba58YYeylQcZp7poOOG9Ngzm5fCNI4J8xQ2k+20lLiVRx2VVOwamkjj0XHbWptZYe7mo9LqOgcMiJeNrLSj+r0oprb82oPcgYnV6iNXV53V+yGJ/6Sm4NkdqLz0sEdgiFW1iCHo19mQ0TPXH+sYTuzwTyQxhUJYyaBiDpcW3XAtwwmaRngJf6kbgJLpKqEY1GdXF4oHclzP1++s= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1bf698c5-7398-4a10-8613-08d99601c91a X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:46.5944 (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: URgG0OG0GznEzCc7cmuTHaH5OBNvthF4cy37VUS4x1OObLw90p408W/Fi7rwMiczX7g10VyCRiOgUGfK/RNnHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7793 Received-SPF: pass client-ip=68.232.143.124; envelope-from=prvs=92346df24=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, T_SPF_TEMPERROR=0.01 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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=K2kpEW4W; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=C4Gn1hcl; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw432wqQz9sWJ for ; Sat, 23 Oct 2021 19:53:39 +1100 (AEDT) Received: from localhost ([::1]:33288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCmX-0005ya-4i for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:53:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh4-0002lj-PQ; Sat, 23 Oct 2021 04:47:59 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:19442) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh0-00076L-RJ; Sat, 23 Oct 2021 04:47: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=1634978875; x=1666514875; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=hOBcfWOZyMxNSEnsrYeNAdCfPEAYfe/PEWI99yI9jf4=; b=K2kpEW4W3PYt7V2U53rtWkCFu9P5700grXwUMFKdiamgwD1dzGCz1aRH rgFUbZh0qOnJLHwbONrhxzwl34S6QG9jBZG0kpzriAZH2KMrijt4AhkG8 hYQ1BCe84jip8W9SQaxfCm6WGYrLivOV9E8rmQdFF8VNAfTei39gxVyaE Qy5ULiZuvjPdqo8LJT3Ma6utLL+gIpYKkbK1baFN+LVbU8H84A4EsaTAN rZBrnkw6Rl1SnqsN1eNWT5OTQ8BPRXIkl51i6zbYziMWHK9Z8jlU6WHCl gnqEUjpqTItlklI5nm1UnyI2GGmVyF/8HZ59WhUKLgN16bu0xv7Plk1OB Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="184603444" Received: from mail-dm6nam11lp2174.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.174]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:52 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GRwP4bx8sObvjqBYsrWgww9VEtQgF/DBWRYCjDsffHeOOVV607CmoF6L0VmKxDRzqOdbLfS64veZ+L4ERVa0ayr4ij14At7abhQsoHzxcHS0TlnKglZY4MZUW8MWJvdx7188jUSMHSRhEGL5fmdASPocM1gV9kFO2zbVyCtkYVONWlA+LYjKWsuJrvAo6yVP41n2i+EcgQ8tnz3OvntkU1/kvmO5mppudFCpThzH160SO4jg1wfqnbRjn/JyvrJFU0e6uyhmrd8YPu6YYmVQOwC7kQNGZoMq6rF5OV0ScqhFfGGUH5TTLIiREn9bftY8sVjQ5NeA0enjH8IbB2VcFQ== 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=hBVDo6SYdJ2VSkZ1RNRXMO+bFzFMDn+rPy5RwqQfTCQbLepdt1FZAe/RcQagMgKw0nFXZpu7a5zEl3/4TDcM7Y+FYNEhJr+0ajQ1EElL/KPSnW08lKJu05FYypEA/Eh/0zcC2cG5h2wqIve06aGfgGV7Ux5VISZIQHqbtGougolqlrNJ/C27HNyc68BVI9WP5LPmt9LvwXmyItvuz7s/N4PYJ3PYQYJdjgblKG5DZg4OGrWTNlH+dZcFyhFVanPhRlV0G04kYCx25s6/7TaAC95E3ms93e/lXmjQrCvyENc6+iA18KxmAym151uDcaZdpLgJP4Fcde3Say+ba/FbDg== 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=C4Gn1hclR8EJ/VIaLeIbDOQs8t/n3xRX59DGxCF4lA57UTvbmXraPmDCq56HbltQPoa3ZPweCoOMaUOPiZ4KOZjivvFBj4+lWQcun86pCW7Fw1m9l+EoOU5ek5Ka7IU3YjcE+1iWINB2IlHHEpCiSdwusWxxehOuMOZdzxnSvq0= 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 CO6PR04MB8348.namprd04.prod.outlook.com (2603:10b6:303:137::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:49 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 09/22] target/riscv: Implement AIA local interrupt priorities Date: Sat, 23 Oct 2021 14:16:25 +0530 Message-Id: <20211023084638.1697057-10-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ef1c6467-1cc9-43fa-1ff0-08d99601cb0d X-MS-TrafficTypeDiagnostic: CO6PR04MB8348: 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: JcMrodStuGD6pY7hgjqmM3E5GWNj07/F7p3GLEZRvfzTSSeiN5Wwfg5fhUzy+GefGgPEjfn4Fe8vK/PlM9ifqhMcaiHeAVOv7/kcrp1ESTfuSVJ8ivudxABdXlY2LJ1U5npGmtxxSz2SCu8hD8Q+tCSh6dxu8EmV9SkthouTyfq1I8GwZ1wDLpWD3wUhJY3PsYrfZv/LhGPU70A6Wx7HMfh6qIJhTkxBlpwQK9yBk78SwTIijsz+T3n0OAvnLy7aav7u/apHg8QRgXyfHGHTG9ejvAHAK9pOrwLbAeZ1dTiRHxAor3dX9S2DpzsZcReIQVkQgm1apt4hGpIyqYmn6Uz53Gs0agDl/Ckvtm8zqEa6+iQn1TuqL/BDBr5NmTC+eiD0XxP1jaCHaNDx9VqkT9u7TQ6649MsJg2vYd9Pbzepjw8/p3RJPFx7ibAdM04oSo9Upm86Dj4Zj3FoO7mC4fHCfz33MyD8hnN3dybh4Dqlc7ZtV9aG+ow70hKyYjF+nzeelTTfPDOAZj4EgclDxc70lGG6WOsbbreQhqzDWNJS/PvJf24vmNSOgXQ3JOQURiG1a6Q3PF/uDp7ErO/0n5agCizS3ByF29I0RkfSDt/P9iRgKx2JEWAD9J5y4I9HsISMFtKOyo9cllp25LHz1ab2lyE0os/4SjORekuEZ1MLqNcKBfQ5BB0zyi2SAbzZdHgpopqpQqE2vTeqkYYVpg== 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)(86362001)(8936002)(186003)(55016002)(36756003)(110136005)(2906002)(5660300002)(44832011)(52116002)(316002)(54906003)(508600001)(26005)(7696005)(956004)(2616005)(83380400001)(82960400001)(66556008)(66946007)(8886007)(66476007)(30864003)(6666004)(1076003)(38350700002)(8676002)(4326008)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3YKJBN7asQRI6NgaxOuiQHGQ/95eMMFJ8NIe5DH5pzJkh6n9VUMQYTdH6nyNArWtPl5oOGTXAMWQBKxdwTDZvvGbHYJ3wRRx3U4T19/5zD/aPIgkYOkfPsOr2M7r6IUfo1doqgOWl/EeTSxXl9YlbKhPA47HvygX7P8siQ3SoPxxGbICRS0oh6PM4oK3+aBX3ql5T1j/US2Hntvy5nL+FY0NVhzBbP4gvnL5b0rCGhcGWBhjAmxbO/8zPyPWlZPTamed2m0cprMbFEgIMtTmCuoPrDNfJ6kuZpkUKmkOzueXykWn8t6RM3xvtII32chQjsCCI/vhStT7hTUqP++l/RUNgfDNaqU/2fkOJUTdJYCqzKTVje/EbSD+uG2XmaS8YmlWsVsqlIGC8d5em+/I60jwItM+a3w9qYaL1s14enaKmyPhxdtB6w4tjjMhHA8I2nKL08hA9ut3UcXPDdACSjAfPDZj8Ll75/3IABgX4jAUV68SPmTdTk7CjFDuEylbL+a21efzLJgziQh9yRmet3fBxStIELivq7BhdoydxstFxXJa/dO+YpxZoAN281oeUu4jmo9je5NwK9WDLiX+KjCGNQ5zQDbGUZ/v9jdENpb3QzHtD7cDVEVz17sJ+ak+JLSqJKnYPZ8E4V1yfkg5wXoQEBNnSbJOBAo/nQ/z77jVLG2GQhM4ojbbuV0zXhop645l3q2xB5TGOlpY4p3WYC51wW324V8Y6Jfk0nhvZHUy1NkiGaTjgEIxLgpDDoq4Ig8LkzFJJZJAWMRtvMrU9hMcSXVB+DJlJfW+Sk+uH87kw3geQeA3k8BcUlareWBYTut2t+oZGJl5TZvnRbMwFp89PyPWHFOwrB3YrpwnKQrYuzy0hTzQNMNBcG1RIYHj1B0IKgiu1j3ycALL3i4pqgMzzN2BWIlqsFc+R7nKp18R+ZGK1Q0k+YnW2E5/1Blk+mp5bbSoKBPXJfc62Mn7G++5t4qhfPZcfW7/7aANhcGMjps6vTAJr0iJ/SAHxNBOu89qNxq5gwayy4DHEdWaJqM/JQywKsMyDuAiuhmMO+ndQo6Gr9/Rpqo1i8AHZIl1pU8ZmTqf7uMn4o1MRFIWgG4nRPjOReWZkc+J4Zrc4yYY5fofcRfSIRpFG4zYXkfViukV6idpfEpYRwgwAWHDUlx2zYT5tDAxpAHlqyA1Jv5ZjcNDsLHGCd2h02VHwoH937bUKPKWWUVNA0Ex19x0TwmsAtqjVBIvOoXrpdRqLj9J/M0cXNjiZdEzRFP9l8TZS5+4om6hMysKH2uaiBJ3885C32SrrLra5aKhCCOO0eFHhsVaztMve6ZVRSDjiY0xnj0wvxMpfB2KdPY1pt4XM58fkKVBS08MDMgdGvl42kTslHYTeMX/DVV1Db9fjLeVnHdCkvcTElMngjr91CGleknN2HL7GOFQo1aDVdyP7gzzijF1Jn6fvX6ueuHdiyZDosKhq0JteuGUmvXll0a6AkOzhUUIZC+qNL8AVJc+qo8foqxSWwqE9CW75Na1ptKdfkglGYjl84X4zvohA/5Cz28NN9j2K/SHmp5ZZwAfHHiWQjCPJy5f6Y/whSr7+AryHI8Iq1rojFyJaoAOFzrEQyh94sH2T+y4SBxx+MWTQ+4= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef1c6467-1cc9-43fa-1ff0-08d99601cb0d X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:49.6649 (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: Wfvz2KEgovu1qEetjNZFU/GEX8Cbym81tYQwpUtlx1mIVD3BYfh/NXv3OyXNdgzGnlf7+AJQR4rgueukw+ISvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8348 Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=92346df24=Anup.Patel@wdc.com; helo=esa6.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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545164 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=VZqQIdbe; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=btKA5l0x; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw4y2SFJz9sWJ for ; Sat, 23 Oct 2021 19:54:26 +1100 (AEDT) Received: from localhost ([::1]:36274 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCnI-0007vb-3F for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:54:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChA-0002oh-SF; Sat, 23 Oct 2021 04:48:04 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh5-000792-Nm; Sat, 23 Oct 2021 04:48: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=1634978879; x=1666514879; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=rKP8ERSSBeopz63Qg33Ie7Q4IWAK6FD4XKl/43KmKp4=; b=VZqQIdbeT9ODVwyi6p0CUZbnVB1BJkqMqQ17VOvdnke8nr50ggwRZbDi VPTerFhs7uKEDb9zNkuSennv3IV30lBWgbCgmv5iLQu+EdUWJOjmtPAzQ sNuNMxpINQlnNxSGgIdzBWMZNUT7wnkjyDxsmMUud0t084IPhJe207h2/ OU9ebRAH0K5/L0H/5R3DEYtkfDLtApNpQlzoWZzdljFlCenRMToZbn7Yx 8R77qFITllkOimLHLhIYt3twjzmT4znAdN2W3qyIbn10w7mgncdS2DpO1 /cvqia+Vkvl5J4MVrTVHc7ylMEfLcKjTuNBtnwgtqnVc/UrQxFZ4UWkRz Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398057" Received: from mail-dm6nam11lp2169.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.169]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:56 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V8eIXk9fH1POK8+lxK926VH5IwQg+RG59h7nehLloVIh2jv7CQm5cdfKnFlQ0L+DFYV8NY5rKlQgXBoMh0iIaVZ2k+clETsxBnAE+10kGGwh30HBGxyMaMUEFERWwOjRx0+vyMenzVb1xnHmQvpn+0nm42wKzX7tC/YV6g8sNA3J/5MabgXmPdEk49rktNOMoQat/jxh2nyWBxf36O3jA23FOw+mlxmbMaZnusm6FwaKVOvXNUaq39kCVagNY/Zb+Fpe5YXitd2KAOBfPbrbhGJQ/mztMaQ/h19ZYTSHSO2cwerqqzwMixz5WDmjMg2Ek2fcfKFkaNimmGvEohA5iQ== 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=VKc0GPkF8zENPAWoGZtqOzCRQPAn6QdFMwPpMXrv1wek86wBsKqiZo07funLpOT/8CI41AzFHgNH6y3dPA40PNzU98/mdZIMEBb17M9tieDpNe/RuGCxKVc4miIKJFPAkCk9Zktv1x2RvBFyYvEVmcTsNRy+EOENKkUd7hAxqLVAyi94he2WEMTGK9/mDuyWu6jp6JQasaX/v03YP/eirR0KrqCc31kzXS8sj3lak4Sq0bdHQAg4oYxKbYSPYtyWZA35QZvOR70PkedqJm0VWN6smG0TyMj7iHqmJQFHbsPCD4e5YL7sWBGTsSRvqRMG2dwILmZn3sCfQdAxN7psJg== 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=btKA5l0xe4/gFA6FmV93uN+0DmN/0fvIuE9TS7wQFtHmnf2TvjyWjJqMTyopkPEvPR/f8gRG41kxNQQ/VCjEKlAwlgQ+ZhEJcugCkJyU4nvQbGO8II6UoYiEA9BA6MTdnOyhTN7THx7rGdG6a94KZCrtlpIO5rLPpsX7I3K/FlM= 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 CO6PR04MB7745.namprd04.prod.outlook.com (2603:10b6:5:35a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sat, 23 Oct 2021 08:47: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.020; Sat, 23 Oct 2021 08:47:52 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 10/22] target/riscv: Implement AIA CSRs for 64 local interrupts on RV32 Date: Sat, 23 Oct 2021 14:16:26 +0530 Message-Id: <20211023084638.1697057-11-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a7dd575b-13fc-4159-f31e-08d99601cce1 X-MS-TrafficTypeDiagnostic: CO6PR04MB7745: 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: kBQJ+KPoERWDiJ5drLKlyWYAhLGFvlPeQJO7EeCkdhKbQ9G11H7wrFgEev2Lq22OtlPlEiMYm9G/CAGHfTc7G4Yp9o869maRVqDe2Lj3cdIVwZ6+SWICE+ENkstsy7/PlN5LmV3eadwiSUwxhy3w7bWv7DKELCcPRUz5D5rXdVZHLXXuUtQbB3cQBbeHbfTQCsKm+XvOr8D8j0e/h9aruwC8AIkGDeWXia5V6M3DsdiLqUtmftfrb5ykT+oHEQhPZu5t1DO1hOaYnrsWCpKHw6jZkGRqD6ZtKY/gp5vX1qGOa5uBZiWlEDqzenBsPeH8NkN2LSIcSyRmDSYWRsu8p9BBGwqsaHpdjOLV7er7UJ7I+N92TPnAqiQfbZIaSplLxFvm8UUYyy4bFQhYbeDE1y7iZ9TsSy9nJ+HOyJL+iZ4cCEQl4ZQITiVt1fukLykR9QD70yJ6PuU1QScTNhtEIa98bVM8YCDezprS2xw3Sbf/+iWt2sUGTnVaXNwrxv1BMnnxfYp6w0HjDge7CB+LMWMgE61udR+XT+SB3o7p034NWsU/GqOJYQgLG356eFeJzFJzMylLxdLFluAoax8QbKx5PBLJqF6vi9kRsQZ/BRN12CGen0XKZLoMsM4rFExMLnzJajoSIEhzsUIQvJkWijCy+yxcFl/vKfUSj/drIQMz9eUR23zkphehTZJrXmpjX+9QrUfxfqKXFHZnn7qtOg== 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)(8676002)(110136005)(5660300002)(186003)(1076003)(54906003)(55016002)(316002)(508600001)(8886007)(86362001)(36756003)(956004)(82960400001)(2616005)(83380400001)(26005)(44832011)(8936002)(7696005)(6666004)(66556008)(66476007)(4326008)(30864003)(66946007)(2906002)(38100700002)(38350700002)(52116002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7hr7Seb5o4HZxIP3ImGAzNNZzgkduWTUTQIxbQbxnaoQGQbUkoa5pAMyceZGgLq78UZmHRcbV7/T9bSKxD8Rb2vHLWnqonL/CruY1LhkZ2eabTlKXJKJe8wBZ9rvbvvQkdnol7ZW62dJebhsERAMjQBM8HfhcNBtENRwgyXgv3HMp7Mdui+J057pnih5aBKsWwYQK0oCQfh7Nkm3ENjYep3sYNs9ClqOFSrkzs8xLugjecF4fGesOy32KDJ1XnY/Xk+sNVMqAEMputgj4dfzIcbH+6D+YkbWqGoQCwXTmHxB7DdL9uRe4fHCNifFRz3g8k2H0GbdxqONnWB7Gi+ncY1FlX8Ywe9+lU35Lfxxj+p3p2DebgKTrrwgrWsXitWNdrVq93EenL2haeUeL21iZgY1Z26C89Jd9js/FnJpqf8M/9/cbxHkLpbE+f6Jb/lIIlzCKG1TNCRaPAPDeIE3SiCWO/Oj8KNRn4dTMiHsVo8GRvQYEEUVPHGWDhMTmk1U2r2mfnZtDiCFENqpdLG3nvmMa2E3vtIiij1JtVkDK1xfhQNc+hyPdjIfvz22Fx6Ih9q6GxUYA1jkwpWGYs/HXgd1PjLFsVCnW2iQ7theak23hLfPGxzJj3r1HLLZkVGG2p24dF7Kl55lYEOYwNLjdtkVlRvJE9KRxqmptD9BSQfqX/8AEumM0SQX84hh71LEMykZhBXY+UoLPvkexGdPRyUQ2lVA1sJ38daTG+PZ70wAWOisirwCda0i/o9V05OKHyTH4tr+/UxAQrBYvuHn4fx7UJsRwMHsDuxAIluwi+cVYxiQ1NSi8qLzIuwdRJ6jH9XbBEidfizgjxeFVX/3JqJckU7n//Dmh07qhwydE44IiKNmvrlt8AB4c0TQS+e+Gd9pZi86Zul7wD0fj94SelvHMKGHjK2S7W5BUG1AFm0qmyEaYR91Unkp/rsGsKOTOIxdQFNNR5dySj5KCTwLgTwaxHC2pyqO5OZH+/KIMmBZ2LWVEIalEfg8aJsfbVRHk5iUG1yS2p55ReDlNdjfM3no9sopXUGElDMrf0spK8z348pyPU1F3SUYzYXkHf096JSDX8MVjiTLgZUVNB2yKkeVr2hcY6QPlbR04pjZFr41lAyDYh9igseRVzy59vIQg02XY1T+QDo49BMKFfH0ACPyI12Chu2+IkKDCQpUrHwokmEm8sprVkXfreQKfxbWHC72p4UsmkN+PoY2ahxz7mbUwd/rx6Ng792l+faPpAOcBRgjLfIautmjWQPqZK1qkC3Pku4A5B3ZqMJvOoRocYHWFual7QcdpnSlPktMD8pfpIHdgnAqhcSb4AAg03P/n76SHYTcv+D/kPhyoXUyhtsFihBt6GRGA9vNmp4LlOxtXzl0qGPGLhVx0FnR3eXzc07UFDDe5dL9HvoD/opQ868vWzEHEqunjyTZnBPS8KevEJ/uhvThHr3XaV8olGmi6rHtuPH1d7IedKt8FOkIQRg986ounsRMUgXbUmY+0vfrrnuIocVW72B61lk8gnqVzPV3A7pXFP2UpsFgIbVGXpYd/kQcDeHTk/dIMf5h85zL4zWSlKBvW5upUaa33vxEx0cWhBymyRtgqyhuxhMxYNaorqTd8dq+nWutEWGvltg= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7dd575b-13fc-4159-f31e-08d99601cce1 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:52.7792 (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: AqyGsNRaHgZ0BSHDMaeXPZ1gr39Tmn4tBdZE8FkE+Brt5tuZ2SVDGzO6Ix9cgdNoJ6dXV7APtm3VyRs2wUd9YA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7745 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46: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: 1545169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=qV8oC8iO; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=N51b8T2j; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbwG15PKkz9sSf for ; Sat, 23 Oct 2021 20:02:16 +1100 (AEDT) Received: from localhost ([::1]:52606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCuq-00023I-VF for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 05:02:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh7-0002nI-MF; Sat, 23 Oct 2021 04:48:01 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh5-0006w2-1C; Sat, 23 Oct 2021 04:48:01 -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=1634978878; x=1666514878; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=CtHtkLXiLMCVmNIUwSdHSamCeIOuJ4YxOeC1MZGTmd0=; b=qV8oC8iOZv8DFeiFH3UK8wsiftvpuxxytokx+bSoaDN7Kez/dxr+K9OY 4HlrDOXVtLg3EEHtMkjTmDznEr7G86xCHj3UfCXNEyNjpAqDQcx0dyePT Dq++LRqrFxSaLhsAfQUD2LBW1diro8Deb9TeZ7tZ48Cth6vqiXIFnia8v gmdLP6Yoc3Xu9yUIfs4glOHW29GmmsDB2RV4vMZVC3gvSQtzkf3Jjagkt 8fwGywYPBBxzKqo1K3qvLWSLZq3QmIvvkjgIm2kDTK0lOGSKTCQ0XmNWG GW7c1384lr3F90CRG/4FcufaDqZy5OypVCIg3vwnLRcjJDDfmY5X/ZsW6 g==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398058" 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; 23 Oct 2021 16:47:56 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NSdvcnCPzHSzMYTqx8Irvhmpj9nXa41i45Y4ELuCwv9iLaKuoNhj9saYGX1fLZs1rmSWpghIRIOLKdhbSw7Kuzhr5j+qyxsKr+w5//DrwnyDqhvrJqaCnu4aa26UFr8h2o51n/LATdL3cdzVJ/65asZDg0P4G7Lz580FfsmcjhStzlyOkgnIDNFSlqYstGpE7ccj7KP90lson/3+fTokco9ekh3KSDchqCxB8l13j7qNsizU5dfcYvs4qyv+6A5djGgHvLfPmqC2WtR7s2u6+BUrZJDXteQoYpF2XO9lXfOjvtYxkLfbFHARgrFih141FFvNb1mEUEx1eERv14axHQ== 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=QvmBDnDVwEmOyIsJs12GezQ8ze/mA0WUdGhkY+Vlrnkk9eTV31ejmdhSANiWQC5483hRtaKJ4Ef3kfwu6B401MqTfEb0ym2EmDzO0j5C1IdsZbZVNg/TDI/uyL8xf0gc/Zz8RKmPIhtjzYlQXZGiIP2o3EXGvaSeCppvkEti4a0AsUeJkyGVOq2Ac4f7UCTRAHoI71cZR6Yh1PWXFI9g7aHsgez7j7/QEQQ3BQyAEGOa155qJS0PjjdUL54R7NlJ+4b2HrRH2bZ67Z1KmYSguc7G8fgtaEa6DIf2UxDxM7PB42a9U4AJfR5D6crceAoU5fq65ztZskEfhDLzST1sLQ== 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=N51b8T2jPzjKoDtYZRC7vcUKkItpqMf7poC6fdAKP6W9drlQf/izEI3pQykos9Xgm5FP5DD+vYHbLxu/kdhGiu8hmtTD6nqu19aUzYF8tzuX7oToHisYw+znI2+lII0peODKcd/xz2Sp/y/P/Z1pT20kCqSzosfhu0CiLzhb390= 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 CO6PR04MB8348.namprd04.prod.outlook.com (2603:10b6:303:137::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:47:56 +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.020; Sat, 23 Oct 2021 08:47:55 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 11/22] target/riscv: Implement AIA hvictl and hviprioX CSRs Date: Sat, 23 Oct 2021 14:16:27 +0530 Message-Id: <20211023084638.1697057-12-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dc0e605f-e15d-4236-8f20-08d99601ceb5 X-MS-TrafficTypeDiagnostic: CO6PR04MB8348: 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: /2fRQCBAoXm9qiMJgqGFwC29TxRA+lVrb2WRymf8CO3xAi2Jt6hvbyu5i1Z5ANs8OxWEqtP1+zwPva3dsSBaPgoNJvk0XfDBsL5mmU261MdH0jmWFqeSAGwolnJCvN/ALLrQL+v0ZxsI862JKNEqEPXK1Ta8wcNx6BtyAPRy+g6zMFrLaRfFKgF4K8vs04P6J1xxtzcxN10iy6rx8Z3Nifc11MfvHMjph3L0XxtUXp6VhQ6GOR5pE4w6c8i6qtKd4Q+25Pwlb3bbU2+vUhYeGn3Ybl0ASvgk3G3TvPEIUMrGx4gkfAvdWkTMVqBX2bZr1wqIfzE96HT3uPp0atDascndx4PpE1DUDm7f6d18jdab2sGljKWmG8Rm9YgTN7k8ekLRsR8B4WHUwutkbO18FUMHVzecax4XFHHBhDvGec3+v3fCXAJd0xXUQjcnTIsFGUx0sYHoNPbTtMuec0rqmyzGm4PytN34a83b/cM2ntWusKsmwJhXQmXiV1rSCNlUvIsRbVun+13tG5nZjTibnOUCruRTDRumss26ua6JLiIz/yYmawYOiA2EwD83g7nwwv4U/cok37BQqEW3fSLhYnIi6xFrbCZ4gX6iljfKbQDOImpreF5X3v6D4SOb7EnMko0u2wQoJMF1hx+57+01ftHLWiu45MQUBWNmZ2C0ldAkvsXT3Zsdm6LG7zP7rFgC 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)(86362001)(8936002)(186003)(55016002)(36756003)(110136005)(2906002)(5660300002)(44832011)(52116002)(316002)(54906003)(508600001)(26005)(7696005)(956004)(2616005)(82960400001)(66556008)(66946007)(8886007)(66476007)(6666004)(1076003)(38350700002)(8676002)(4326008)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mjRs/3V8MHr5ixCGz1ULC4R64dHEXWO1tWklxw5DE82sTVZoKHZ6Z5YUurD3ocqFXka/R92Oak6YpnzcgKREu07uiJFKxGflJ60sR0IbcQd/5F6gtGRd+v3X0AuqdNGfLbEAK8nVGkgLGB9u60p8j5PKyKwNWpGG/zMEgK1JXWc9LAhuQ+3mVZB4vRredq86/6Q8G98kBGGspeRDp/DR5fTU8s4Roe/De+N39tk1HbLMaTHgMAJfFB3bt1iWTgN/ddWlFfn3a5048++J8IS+63N3r9Ezs1Ux5FXVCJCf53UcYYjrzg5VlGc4dSiqo9sWwFghO8LGEzer5UsaKBgwH7lunVu2pn2bEo1rZuUYuI8LMtw3Qu5fX1xdtn7wvLl/bXza3pQhOFDXeiOS+4sg6TzoNljNVBiA8FVmfOtJbB9ZMv2P3ioKPanDkiguwsNXQHHAHlJZgKtWrVCvakT78LbBw9Eu0VZE2PaVAii32+5RNNViF25039VJM1DnPT5fAMGG1Rf2aD1R2pUPt+BKoC1m4tlHKuuX8Vczd+EFFIEmRf5GFHcnQ7bJMna8GS7tcaoPDIkGOOn5Y3zzr8BkoER3z4+DPyYUwRrz+OW5EUq6O5blwtA9RF55DklXdR7ZPYN5zPoflCOLs1RLln216yZVft/HzBAvcFAeeWXQjKAB3l94XdhObsOIKLVzxR+AxMmU7jvLmBAk+Y70cYC7+EQfVsEDUcPKH17jMLHnRXSWKIE+qMWJqONDGXrdgS3Y1d5TG0mHAIQq+UAveJGVxJ07Bd+tfNMbcjAGFqXJPjnY1GQ7MCQ0E3Zh7QSlFbG4fQwigsT11Wizvz+FvZP0cEmyBvBVk7Bp7Wc/PYCLm87ejFGGqJqzHZIFoLXncQ/P4dnY4eJf+D2JwTwzCy7OalLUJ8mcJ9XJidCj2EHNeNI2gHJtO58t1Rs4vn5b0Mc6axEQxfqDBPZ9ycQh+VWCEU1ujhWW9iw2Zld+DAVB6j/3Dodj/B/fx/tL71YDzAgURDbjA3GUKKeGRKg7heEvjMoNz/oKTY3uZ6erGFhxeotfKoOCVwsLZCMlKVZ81AQ0VeKZX+Ej3r8GxWxd9q5i2mHFiZkwXLfvyR5wkOWEgB4p02ZFmqodPZ/G/hzrL4tl0AQ9SRZ6/5k2Rv0XDrj49IO4h8cWgRyzNKJQWgFjatjqNqlNSA5yNg0wNkbUNcv/0ASpFnY0pGWvdIQWcCKl+3KKdIGZAt7PNs2iZx0gU0V9MsBE7Z3B9i0TgzBSSqOTmZ+A5uFqJ50GLRznI9tSuE+REI0VlI26XLWu8H7Vc/4R5qMeJGdcJhn5mfaTTrdnZYVMy7jMEz36MnQHB8UeX6OseCBEk70vBWfG1VvTff74PCOls1GR4nDsD3kfK168T6jQxE/2hzoGLR39b2m/aGweUhWo4ZwyTKcoEhfQeGzBEkQ397wCPDRRbvknVmt1oDespAVa+XYmGVA/0OvnRl1S2BPSRv8UCbrqpJJkteL7bNxIilo1Oh2wvxHaMmIUubF36iwe8ZUBazWwiAVYCpjlM+U1PNw/2nGk/9Hy0QmFBnw1atpzzqE57RMZuALcG2sJpge6xcf5wW/ETAIoaW2/XVxpHDx7agtN+nceMvI= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc0e605f-e15d-4236-8f20-08d99601ceb5 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:55.8158 (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: vzmMGGH6TVuvjCGXSltOzWmXbOldGX5XKwhIqRUhNiXFIVzaVWXJLBLp0MsUnR4EVU/cE4h7q6sjherWbcVyIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8348 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=SP9X90/9; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=fy0ol7af; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw2r0Y2gz9sWJ for ; Sat, 23 Oct 2021 19:52:36 +1100 (AEDT) Received: from localhost ([::1]:55982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meClV-0002Lv-PZ for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:52:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChA-0002os-TM; Sat, 23 Oct 2021 04:48:05 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43327) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCh8-0006w2-Ar; Sat, 23 Oct 2021 04:48:04 -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=1634978882; x=1666514882; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=xQ+uoogFLR4BdpvIx+FQYy5pY3pNfH/hNMFmtvUv1i4=; b=SP9X90/9Uo2PPEFGN+GC9fzGlfnABLZgCm5MoEzjnNKfLUofAYH9o1xz PSNzVwcqX5DgCZbVaRKK0tAknf7iy2FlTkbsLraSf4xusR4janWl7Nqry IToSjw6OnXvOlSu+cU51P1OC2LMI0hTpD32eVKXizjViHNMgMvRVVkVfL FcvD1SI/+LcuZiGD+ul3j5TKxUvNeGG6qDna1tbE35Sl/O0NV1z1e6cQu 0UetkVy9szBdlOrgbLQo/heA/BC2wshOVjE0kgfAun3+nuxl4V+kGz88L oJKVSrqvjDzvatJpVhSC25Knp6Qm9/q+N9E9E5bLidrYh2wdjUWIYh848 w==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398059" Received: from mail-dm6nam11lp2171.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.171]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:47:59 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mx/fmXcd2y82zHnecutJ8HQfegPyWEqNP7gJ1rVmUGkD5nZLP7lq1YQMZDPTwNbdev5DtfpShS6R8Ocx3pib+rGA2OIDND4EJ1L3GhlYl+lfbjDIANw9RqVdcr2/SOJNrQBqONIFGGlU00+LaGRGV/hrk/ConVcjtQJgmbRNE2RIApEN5WZgUrR0Y7/a9gjmtaQth1qWOqdSEzS/F8zw/oISLly7/eEa1gTdfAN8hnf7pikPWCpGFjLbimCUSYsiklS0l2zqMDSB5ZS10syy0Oc6uArCqv66fdo0xVOHl8XWWeqf1w8aIBBb8eA0tHfq8pgD5LiqdrXUi3WJCSJ9xA== 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=nqaHUt62LfzC6WpRwiLH2k+Uu7hGv7iz0l0ZZRkiRJu/uH9SRUKUzvMlGv9JX2GDT9vWyMIGBFakwdca1i3jr3G1mMWeuq5A9XnDA9gT4PdkIBAC5FAKPKjvenRxKM8Ehk4Q+EdqSvMJEMjcomz4DcReRrcEj+mMDJ24F31NGOh6p2tz7JY9UEgCL6Bei627LfcncuL8Nm0DjCGApZujtgJe6UX72Z4l5ZNq6rbkm8qwe/OyvpGLDi3q6RrHEnh+WKbtyEnuEnEuD1dMwnI/8dpsZRdDbJbLrVQoW47bpg3dF+h00FF4wQpTH/0WuE4ma2EBdfiorINGbWAnzafT0g== 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=fy0ol7afXJbDf4Zm+Pvw+6aw9Lccu91WexGxOLG0bmrOxpeFU377nJIap95GmYlejA5t5hZxvrUiooD5LH01hkAw2IgFdXM86mkcKzaHCmHgj2lkH6dZA2sNEYcCI+6JjrNl/4F5D/D9Bka/aFgQ8I6U8lDXGltAOiED0xpVNQk= 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 CO6PR04MB8348.namprd04.prod.outlook.com (2603:10b6:303:137::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:47:59 +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.020; Sat, 23 Oct 2021 08:47:58 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 12/22] target/riscv: Implement AIA interrupt filtering CSRs Date: Sat, 23 Oct 2021 14:16:28 +0530 Message-Id: <20211023084638.1697057-13-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0692f013-1492-4a2c-1414-08d99601d07e X-MS-TrafficTypeDiagnostic: CO6PR04MB8348: 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: 8VXxWqWwh6dhR2gsxW6Hoo38ooKRCnq9nJnhShlYfC3iyLUeaTD8MoLhXg/7/xXo2846rZBQcPHhrq5qd31gnFrjeyyY6UOq0yGUnb0qcsmPh/1/ae2if8n1k+Yv8YSkNzfLDV7jFuiRKQZ4fofP8S2y2k3PFAS7EJjyJpxkPN2Eh5D1l8fjl/+GtE38InyPN8cnn5Pph78dA2mAknWgMfPnunRbAqfqfFCm6u5gYAqLXqGxmmuKYVti6aF+d88ZLtdOPtcdwbVT4H/FKB2n5NwHV+SYjj8f0Zpu5SsR8Iy1Qq0qFeFP/MNVVd6g2BOt0a07BPsyuVqjQzU1hL/GQSZzbOJIBa9gmOQ92JgDrw3RwSCE3G8ABv/xXUoc4E0qaawDQpEtdbFOayiEUWF4cv3dJkLEFrh6ax+clUWzBB1KJ+ahvYuxudvZvk6oLEpreE2cyUuP+X3GArCgcVaV1mALBKk/wO2Tv4hXSyQCZbW5ENsyFEFc+7bP8QCfPJ9nE/p6JP7cd+XtKK1yFeaYEZUU9xPBNaNy7mqDK/j0T4Eza8hoq7bEq6UnF5ypS6ww3m8PDGYD7cs+wdciaoAkehX0A3ANESZORgBKb+JvB9zNVj1nfQEFPdoLDILt1Tq8Qzw+B06LLlNUtTmLVvNYcEHTRBsdkuH3fOTB/Tv8dHdVuCyJJXAW+CIPTM//sDuI+5MrpYhSMMp3gurfjgjafA== 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)(86362001)(8936002)(186003)(55016002)(36756003)(110136005)(2906002)(5660300002)(44832011)(52116002)(316002)(54906003)(508600001)(26005)(7696005)(956004)(2616005)(82960400001)(66556008)(66946007)(8886007)(66476007)(6666004)(1076003)(38350700002)(8676002)(4326008)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yu4tT3aFcEuwmEZ5iH6EWWbdv2Cgj/U7sc5qtePO7lOcTXgDe3ATgpujAWyizwzP5B8CQ6P4sVwJbi1C+kwW4lyR8BZP08vu23+JaBhzF2Skj3Enb5HjLQEWiT3D7TBeG1wo05vCj89vfxUuOY6U1E0L4RDvYWNBYXqrlxH2ZBgH8t4etUrs9VkY3snvqThwHBacR08AKDvlkz7m+zyDPuSFlzUfoPS5ZRBvGsajnpqo0SZ5yaNZnMqsaiwB7SjwZtpORRhK9WBoKctNdfN7x2fMuT6cPiFzFLt8ONZy6AI8q8TtBo3My+Xh6HedlkuSykuUkdSEKbvAxPs7n8AJGL/vOqXjf9LQ3lgyAkAy8dU9S3f/MEBsEqx6o2ML9lvd305uHN17vGuiYdpCiZapZTJaRhhwdo8RUSpcv8nv8UdfyIGks1DHsS5FVnrd/KqGL2zny144bOW1TLcN1y8UF10mqMwSrk5Isq8xlZUIYzwE+iNTz43d7oaguztQWI+UghketRpBzxk9+6/GkuZip3GGlDykyjYejZBa7VoVbmfUZdJiqoG0QP5ksLFzTN7SuFFCyToJWVWLj3Lruv1ArSUud61PgI1iVOMBR3HIUXfsRaOYFvxNJEuDkcgiMgVYsZtRyD2aEVAxzNAdpfHkMe0GKMJT10FCZP53lUq/4rulJLVM7d6TGJiQ5FK+CyKKty3d+jYUi3QkmuYwZxwtU10o08mrb2NgG6V8ZSzicrawIRLJH3DopRbgdcDMMTRsHn58yKA2olu69MoBKu4jkFzqtyHcCKeGKc/lm4Dl4s2erl5JkisI854JMMdVttvIn7utFYo/2PF9h3XZhEwGxXRkz9elePIy0up59cHc0wI8IwKHEM7+mBLvnRMG6SoClksd8MwPF56pXGFm5/6FeESr2kz5BBQf3OcaOmrYU1CPFji8gs4ABmLdfVGi1irRJK2T8513KubavFoPTRHF6FmCEtloysHgv8vXWw27b3tuJAS4PcbhyUgPhitFC8eHMjebVAzVNDF/YSbSP8q4qa5D6uwWa9Nop5FNBrxia2VGBazkniNJ/ub7Cl7JqcG2LR8wEROE+CV/UopO32zLLovqJC/bKi6OWg88eLikESt9tk1RQ4T3a4/7O6WB+Y9xJtihNbDpSvKT6bls7Ne9zhYy/6TXO7E4Zbr/ci8s25hAqDazOByNxKY3H217fXAbp7D//JfT668t9TTgYT6kYUwxk42EQqSGEKBjZc7xg6gnz3adcYZFrj3h0M7zKtQ09zFw4HyPvUg1itN/BkrsBSiXUWW9VPvkgfElHYFVN7C88HpO4AFXx145Uz+f7fzq11zrjBMbZDfr7Kqxp2usisbeaa1JFM/lIGpdoUf1ks34+enMCKKW4S6S8UE3bBxFBr1S+mjsNYpw5H2/pE6ebdqyqBA2utIvHNxThRjdNxrPyHo/0zD/Z0OLqW0lJ9BZ2FAqIlFOZ7I0QGJmp+WealmMJDgot7KOw31VMB8JR96hUlrTa4+KiCZ/qubFs5nTeibDBOHX3JUsu9mMRaBCpl5xEeYvEk1pRVwYhU11H6K6tTxmmRe19/nvBkqmbWEYSWk2J8sjV6K7K9riCMmj9fz2VXJZIkeLDZH+iwVBnxo= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0692f013-1492-4a2c-1414-08d99601d07e X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:47:58.8236 (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: S2hfLMJocJcgLV/0NUA1M9z0Uw9rveHECy8zZJU7ykLXjCAkshLW6f2U0vhjMr9BCm4cdjaqOBnc/xprhENzfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8348 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 --- 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 Sat Oct 23 08:46:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=PwVWrhw5; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=lZQT+IBT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw7P58Wbz9sWJ for ; Sat, 23 Oct 2021 19:56:33 +1100 (AEDT) Received: from localhost ([::1]:41904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCpL-0003Hc-Go for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:56:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChF-0002sr-TJ; Sat, 23 Oct 2021 04:48:09 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:43362) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChB-0007BL-Gn; Sat, 23 Oct 2021 04:48:09 -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=1634978885; x=1666514885; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=8hCfvF6U3YpAM0d9MZNIIUkZmdVvqrgow2wJTWop+lo=; b=PwVWrhw5bKAoMmcs9aVFxxFniA8TtRFJm65LOLJdbVjaxD10okAEdPAU mJhufRFARIasELMdcqJpC++vWKyAJ0iTj8+xlZzz3zNcYcF89FcW1YBFu fk+29UgpJSOAmMhe7OLqhN1BBBi7E6r/SnyyafQ/GlkJuXQ8m2j0Qw84d W+3gDQ0o1fyxj7B3mXSVMFx2JWOuG0AscWJBEpEf2FPz6eMdupbg10x9K 3sF+EO+7JG04TU7aMAlQXStpkydjRCVuv74bP4CN8rSAwlsQb7xFE3mNw Mr0OjrFlSL6DxPTgPaw/cHYOJjoiP+j6RhTYjTydSK3/OMrGBU9xqCVqD A==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="295398060" Received: from mail-dm6nam11lp2172.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.172]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:02 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bFfND3nKKg0crIdRjRAGrKjzvewli3j56w70YdCkwZ1nMdaKSf+ypKyegGjpQINm9A5gKZt+6oLKuc7Y3DbsQavAAfeaVfOTG9QMbwjqdqeEhXSdM8qpiE0G6D/CrGXTQocdX06JjDAu07LLwg10DFPFgei0v85ju8Bs5KMAZA7xvzrSVoQS5B9cAJA7zPIO5q9rJ2cb9Zh2lRYZfnbCLXMYWhJkH1yK5Lv0oszWktgzDUR85WyYOdV+aSWGHOwwSYDCnp7TGJ9jWleAzyeqj92kN+7TruckZj4+AZd1Awke04FZBMBhAGgH9ySJigunlMrc7gaavjIB7nRoFFG7aA== 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=Zbg7JdfjPqh5x9enb2psA2aojIs5BuunqdCrwLhLd48pNLKXZ4Ca0smHjO0l1Q5RXt1/zYxB9+TpvlUPspZw5w63E1n7tWBQvinwP+wX3u3nwi+GNkBrOZ1WsiSoVAL1Hc+yjAv8TziruuHZJDB6wS3P7vifVxH9UxyeMCLvf+f2NhjfKBS+NokP/cGBchmDEsWEn/XBzkfXNzGg3vvXeicvatJ8Va62ttdnSxg0wb6iAhTMChR56hIvYT8lblik42nY9xrnUQxW5TVNBaHcYDTBCKccLuqIHBNqdGqj84CyBfWaab7fDArGNbkaLYCXROO/p7YsjhLyhqRvZXQ6Gg== 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=lZQT+IBTJw1rrk32yGd7mYr+RYNwK3eiBn6Q7zs315M6ChUj41X4jB2jL0y5+hUaFOp8GAabKjkUyjWCzDpPYXtD9eBpPXTs2Y7RGUu/mBobUOXs7Uwh7cVHi/2X3clrMlxPOorXup7ugHfZojykfSB1AUVZCXU9CIkdrnYFphA= 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 CO6PR04MB8348.namprd04.prod.outlook.com (2603:10b6:303:137::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48: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.020; Sat, 23 Oct 2021 08:48:01 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 13/22] target/riscv: Implement AIA mtopi, stopi, and vstopi CSRs Date: Sat, 23 Oct 2021 14:16:29 +0530 Message-Id: <20211023084638.1697057-14-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:47:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 22208c32-1145-4c49-3802-08d99601d24c X-MS-TrafficTypeDiagnostic: CO6PR04MB8348: 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: cQ7mRgckzm8bx0LSxE9k4MhdjNrs1mb/odmXflh4E7Lf9sY6Hj4EBOJ9NOkYNccMJhLt7YBgTz8ly9tNjxvFneFv0LAVQ+CCGLmmKQC57iVxH3nXpk9D4txHfjlwwFV7qNxdkcZeln7EAPx8XpZ2GlnEN9xWw+40TPNA6wy/sFqnrpSvRr4ALPowC+K+01fgAURRs6Ing2VGgUK0iSG0T5mDOUOhmD/b1y11JC96z+SjzYhE/4aVR4WeS+wjwdmSNp0qiyC2sZzEkQgTwOSvnY/HiUIopocD1/U5+sBeru5DztRnz+s2Wb73lH7etrGs3XTwsDXne6qGxhDbGlMnOnc0bPMiPbW0W3la0aWxH6FEx+gJKqmto/KgzBTKOQXb1C/7luOjVMGhFty3n/e/1FX/kQSmRcrdpIfZSUTGaSUZencT5sqXfoxCLwVcC6/1L3sA0QP3jqw0DfkKhCt3AjhLLMLUEaBFpykVFsK8HCG5jKMit5Sz0bYjl3EuAwQqb8KqUMAPTTkZb9tB5BEBVV64FBtjHcifESJvTSrzFDgyUanLhZOhcCTRxqJ4zR5IciCuPmA6lcIopbYhhemLKoXHFfx1ncmZhoRRAuluDnia2G9CSr4DbSUY7DP8WfhWqQ0Jjy/nn0XK7BSFzDhdqLT+w4oVJ3GFNlslY4o3uKxq+Ao3jX+xfSmXki8hkpEtYc0hvXtfIyMA4dn8Ga4ZCg== 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)(86362001)(8936002)(186003)(55016002)(36756003)(110136005)(2906002)(5660300002)(44832011)(52116002)(316002)(54906003)(508600001)(26005)(7696005)(956004)(2616005)(82960400001)(66556008)(66946007)(8886007)(66476007)(6666004)(1076003)(38350700002)(8676002)(4326008)(38100700002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: N0wi+fB2n9etZBvLS5DO+y53nIUMzVxmy7H7spyqryUkZzL/FNOpJnVdBQcK0SkF45iqpKX8Xu8VIttHReDn5fxQsYErcg11rO9jx/AIsuf7zzcfL1k67y1iADM0QUoiF70J0iitLGkImtdqQ1K+DvyUo23GgHz9q+loj1TcNzmiyEGIUdJEI/wk8AsWIMqqc8eGhjBr2L8gAagVpr1t7kmTklDLr3gECe2sSeOK9XvlDOtYef+TZPk7e3kidMw3/qcv9rTubptMF5vi1UXsJVFgMtfm8vvP0Bqm0FlVOu4mQHiK3fyMU0f2NCy1Wr2DueatGhi8PAoC5k2gC/d7QGhjeeZ5u7uojlGIFbmffMMVraQSN17wU603KrUeh8q6FESHOYxcJtlwIl5W24gjgkWEyqmgxAGYVnY8hozTKSgbJP1ntGvEFkdC4nYeks3HTnAEmf5vk9qdk2N++YAZ2/6Bs1ZWmsgm2pnvrq5+Xnd3c26Og/eOt8MCkJvtzuY4Q67ET8x498MiLAXpCBR+oBXBjAkXiSWEJeFyxpWWzZGzMxf1X6akHqIjXadBuiJAtMaswg230A9NtlZepYCucF8QpzEawMjdCk631MJxkx3EEDo45G0kaHPzoTxakfeUcl51DDwcNI/aWw0m377Pl6ZV+JCeRgs8M0PorY7hFeO3eEhAcwTP58nxgodbK0H/f+QpxyJnbbRP1xfDgxxdqhgUtVzzqySP3jDvRp8cJh1BzXmVmbM9PA9MCEQO0bHewnyhJb9VYyi49Zwu2RLUKd9FfP8ar5VtwrRLJUC+qBI37RkgavadsqARlM9kGkgPAyhX8ByJFW/Mlj3Jv22nOrsZWU8wnKCfzz6xaMn1MD21zy/H+ALkARZlXbYuPyijUZKLibfrhIJmYlQCTyPowESRUGbsFdiKA7fK0SwUMSu1O/lpz8sJH2hHmvecMjKYoX6slpt9cCXbAAp0Kt/V+7/XipAXL0FaVv0O+ZG61TWaJ+B3VcfiRnvZIdB96xIt/7/DeZ2qLxTN/bQHAWhj9Q3E58mleqsufXAYzBmQu7zBN9zEuDg11vhsbFec647Lo7CVzjTIjbydksbutw26CLUgylPaOb2jAX3kn5klYohNnqDSePqTdep1thHO+oowbN73eEbvZRl2z15HR0H47RL+snmQB5HENn7geJcOo0cieNJ5KCng1v1+BuOoZcn/3r5rdMuwp9WH9cGx8ftLGLtVrp8D6CtGL8nUDd3sN8OOVhq0tboC8B4HD+4v5EYUiLTCn/0tBtgNO/biGuZU4BRw7zxmWvbq9Wu/6t0u1vHnkXMvgqeh946tC7n7eGH68W2L8i9N7qvXTvnUou352p524QpW8aukRDMQTFBuVzxN9Cmec2NWtXE+XfXA3ZXBaBn4CHRVwTVnB5kkbTJCxzITIV3C2pMgkWmHPSoM4c+qaStKJ744TcRHu5A6sQ9l7B9+LS8hviLKMX6zjdYTl5f8sQXLPgy3sSBjE306DSSn9P00QPio2PKEsZpSrMfZQKbWs1mCzjxiOBTsGmqjJt96FkDuyN79jdF6U9rxuY/fsa+YmvYf/uKMpK6Q/dOG3N+0qpgIs32eaKZb8x5lgGlW787fKQ0mxHRPR6kcAcU= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22208c32-1145-4c49-3802-08d99601d24c X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:01.8702 (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: VluDCTYGM1i6iw+n0v8SewnIgppDqU6nfrzXBrmmFVG/mXJBeJcM2tPdUSWBWvO1Ew4qLRUhVp51+vet6Jx1Yw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8348 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=bQj9/NN4; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=WyOosiSC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw9N0gsrz9sSf for ; Sat, 23 Oct 2021 19:58:16 +1100 (AEDT) Received: from localhost ([::1]:46322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCqz-0006Gk-Q7 for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:58:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChN-0003DS-T7; Sat, 23 Oct 2021 04:48:19 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChL-0007Fj-CD; Sat, 23 Oct 2021 04:48: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=1634978894; x=1666514894; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=/m+pb6B4KK3IKZzdxau0a214vI4jr9MbdzhsMRb843U=; b=bQj9/NN4VLls6p0U7vLJqStn8xmc/FvZ1rpw9qXdwxlRjhAVM7sL0ER4 VflP1Nr5xbolrtQwQ/9zPqoZTeQj3724pmklV5Vart91vW+xh5tjyiNs+ B6kp6RuL5dlEzUP41gSSFjszwBJuO9OYYLt8iNRrFzlBSKotyS6+FobyP t/2jIHfWQZWzBPCm+yEXu0bs2q6Oy/KSY6D4waPmChJjEWVQYA1fB562z fma+CTkJOHh8JzNln+iVz5pzAWRAxnQhkJP4T6Dc5hwngfmWYTxI8jnkM dBJRxVyONf1yyhBM4xF/+dz3M/Uu0IuhQeF8taeekUV1F+m5KlG/yA/+u Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437381" Received: from mail-dm6nam10lp2101.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.101]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:11 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=izIPXdFJLnfQyXf1mO1mpCe8uU5yzwZDtSMnREpn+9a6zbQGxGqsL0iPoNK01Knw1V6hPoss9Zw28fAa1crXupWN22hQ+xc2dcAtn4fWcqcEY3KXPbsmBAOF2kDh4f3JJTfAw/kCrLyx1cjQXzQSMtyv6A0kzti655ez8YhmY7QnqCDiVeGwmqPy0ER1gm6H6uXq95FtePr8U5yOKbeBKtDKriPwh2onrAJ9Saah50Xa4lAKmvZApJUz786Ww1G6evj6mIJWgclXjPmlbbyvRuT+HOR5aBvTT7hc4xVaOP/Mch08iJo8R9r+5CvI8p7+EwO8iWiaHhnwgGgV6ogNVg== 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=I6ern8iVV7/ofkYpvYP80W/MxyFxumffTOHK/0rQzQSoC3hXpp8uTgiM+ijh2RYZt8SQwSh0vauUMY0nzXtTZmATfqVgh4Psg7cnHnCGMjPNAcewUZqJGnL3ok8MzLmo5wJDDRaJcUtKGxStEQyRYkCpMhs5febGI90YCSs+jX9nb+QFxOZcatVIiOEumo/4xHUXFBtqbFUGg0aa/3IwcEGdaxDoI0BtxAm7MDDBiBZByXpWheTITpPAIefgrWJZRdgQ9x+EJvU2iZ0BbAXoxF/kAMwetlP/sa+NF37QgoOIRzaBA+JNMTcNjW640KoF98muzpbr5W+Z5PCSPy7nCA== 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=WyOosiSCTsI5nm7hB9N+haDJx7jEBs753EG4xDb9tXPQ4nrPNzxArgpNI6FMcN1OtAGFlco0L5fMjQnnPQm6iO1oYDiLXLe4rNVzfY+81FhBjzcsQqrsM5dFndXIkSiWc9k+jbKfmc+mj/ko6hkEYp33sNejCkgY1uRADQkotAE= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48: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.020; Sat, 23 Oct 2021 08:48:05 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 14/22] target/riscv: Implement AIA xiselect and xireg CSRs Date: Sat, 23 Oct 2021 14:16:30 +0530 Message-Id: <20211023084638.1697057-15-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9c0636d1-629b-48ca-fde5-08d99601d418 X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: 0XeBfGJS3mFRuYdhAAU3XZI4+2mJRp4+q47yGkc6/Mkh/9V48ofvG462sxi2EJRkNyKeotWc1+lBe9R1B6KZpV9wWdxNHboRcNK+ohrdTE4ZBaAzF+JWA9KrqbJEZfWU6+fLB4gmBDShZIMg5bXw9qXXmIlKTlc4N34vqnxhhnWHDDD1XMBorNvn2/fA/E7dSibjbFAbR1fLIqW0s6cswLnRPP2F/K3QVeWjOpTdp1bqRoppAshhaiWN60nSmJojbI6hhWBOrGNYcsCM7rd96mh/YUH/mbvQ6w2BwGCCmyJKpMYwsFMHaIQKTuNrOyYrqC4INzVZCnBVbcGDn1JW1ZH/9tc74wbZ2NAGhiICeVYIhpUi3JRjFgcFN/s1d++LYsSQ0FY9zhjAmvSry5siUlrZmECoxFuNtU8/i2VBngzwgR0ioPSzKNj8rLCV+oAviBjbS3k4pC1ki/3lArMO+bzM6umm5/Ev4vpKcZC5Kuu04UHxkRVLQR3YE+oEV0oT99Nev8D8UpGejBKZgFl2Vgwxl3fq6WicyeFDFG4zAlKLBkOeQr9WKRPtIky7FifT/DDCo1LpAUgK4ywYwkWGTeXes3yJjEgHCNEkno8zmbLv1J684/oBvCQalz4ipYDW6p/PS80bJ3ezZrpPqYtKwUMVhfvlMagK97tZ0EOKJ2ML87iK90IcBIeMzMWCFQPu 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4lAtxJGm2zBA/iE8abqHgo5SQHhbwEDtrVZTZBvXg0D1FcOz+02M2jd6yswvEPZF45LWX1aK73PC+3VlKaXGAbxNJufU4wGXgkT16XZbMOheLTQMBYdnvUZb6y/+4L2Nnpdl9xulIR8Y6fHQCEDlwm+Y2S3kkdIFK/8Cwv+kYrHCo3vgKWyfNH9gXm2NGr2kWCv7qRi70JHPv6x9bvFCBhSONEm5FSLQyTn3aZ5deAKxRUYS20mioEXhVmtCaIzqASk6mPCawzDQ0B8ljLew0J3Vvfc0naa/O3V2B9yLYxiDFvCg5DVbOxDjbocJmxiDztotZO41C2ftK4p2bFcVkwm8G3cDshRxrsi6NzirnPF3nwEkrRzyuA2buapXD5X2AtYDPNmcfAoWDSRdOnHcw+arruXOr5y+BbdIuOR2+JNVxsPtW+Q82pSUglQXwMte6QQX6rffuzODBPRHK6QWUR5yHU6fwHAGRj0QSFRClKD9NtMfpNN7ETtO6cJd4ttzyY3Bi0zPTnPty3uDwgogacpxM3zbl6GihehZfZZVsSa0hq71GmemffwIc57sCTXLbdb4FkXNxxVhDEhtfVAijcbJzmE/1si7QgG/aqmroCVOMAwQMrXo5ra7f22LZ6+uuWN4MpnOBTyihvTTfKEkqDDGtw67dPDfI/RTFKHbgvrlx/2dxqO9z0WDWOpF63iq9D0KNUx6tiRxMPh9g/21iWO9DXcWh9ocCoGquIn6ZmkL9LDPyddglfPAxg8n0X/I8i4WjBcGlnZJFEjghsCm3X9SoynK2+6PN0lAg6sXUwQvR216NzJTV0uYBFZCZTRHVRwGT0lYm3CUNExB2wHCJv7Kp2haUdVmPF3cbkPZDZShZZI+qPziLmouYzZI7Y9r/sjF2Czu9iqOwtWPEKD22GgYGCzFOceBU1eiK3DkAgjl3wBqNerKH7XL1Y6c7WpqNHQ3tfnaUmP780CoW2kU0/++HL5sQKJ6g6s4f4hllhU8Ztk8KcB1HLNUcfXeNx1MDy7++xNgwZ4xYt6hufqM4RiR3iQxu0NP1HgXg3DKcqPX296o87BjKVRS0vWIR+sD5jFGCrrK1qNFTcYvlQQySQihnUYemovMN/zAieX2/PeRo+dejFYVdtI8HhiqLE6Ovmkm6Lgm6+3biEd9a4yErYzL6RvB3verC3NFAo9+x85kLqGbMNvnwtsMb7BTU7aCwu8kbMu04MfU1qNIQ3Msb4T4giaDK2O2p0dsz7x4DUrg4X46dfTJn7u0XxgHRbJolX8rgMy82MwDpUUOJYOubO5pQxgm4jJzxRX1Ft7+iFUZ06mbEkyGjdOlLHQ5hOApVAaYQCyTd91wOK7lNABVm4eKWjYGBcAd0OOM3uSATIs94TeMLk3gcixdbnx9QvqFFagaIOiJ7Zmb6yrjttb3BZhtMR+y5XDJ4Gi+/++GYXfxkaUd9NatJHcwzi2i0AUSvg8PhFmUnQpDNkGLEK49cPP8yiWDcyVsp3T7U70nJq+DoqX3p5d0PGd3f+Utu81qmR6DzNnh9xIxgL/ztoSrBM05yw58k/3H/4eRvzQzqWu02oX1Hqwfa/eTdiAzG633BNTT5UhsI3OqbEMMdtrTAY4xttk3WLG6SOZ4OJ/IpXQ= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c0636d1-629b-48ca-fde5-08d99601d418 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:05.0422 (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: TelNMoeerKJh9rvBcL62nza574jFWlxvJOzi52xpYuiWy99+8FmqMO/zrLaMN9vH1thV1XAyv8JCivvA08PcZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=UcfJdeKf; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=ItVHTtfx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw4C4cxgz9sWJ for ; Sat, 23 Oct 2021 19:53:47 +1100 (AEDT) Received: from localhost ([::1]:33992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCmf-0006RF-DK for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:53:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChN-0003DQ-Lc; Sat, 23 Oct 2021 04:48:19 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChK-0007FK-EC; Sat, 23 Oct 2021 04:48:16 -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=1634978893; x=1666514893; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=YalgbHXxM2191ElR0bM+PDks8VpaQ7psxsle5UZzVnc=; b=UcfJdeKfUDcEbDL0O6+om0UT54iPORGWoneC8ZsBZMvy65SOTN9rbzFO WyMm9zsPytqRTIYoujyyi+tPaiwwRgSksWb854uzJZXLkpg4yE+MBEYku 60PWhuOYM+OOej5OMolosqm7SyfoWdZ3ry7XrDt958UVPPggIh1WVJTGE ClfexJ0ILtzj3vZ8dBZcF2UXLxfBixjLpMMPI3ElcMigdNAFkDsWZwsZQ i2YzQCqiDs98Oc7/ykA1354Jh6GUtWdE4KZTKdmsAtmcTaqZJjyuMBHth OFnT1rZA2yQ++QBE+nVBTZBtnP0027HUcO8qivG1xasjUW+mEc3oLjYuG A==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437380" Received: from mail-dm6nam10lp2101.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.101]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:10 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ne4LZCr6zXla4MeYhPLpXg+O+OK1xQ7kFk7gjr6Ez+e3MgrsI05SF5XRAv+9DquxQCB0lLn1Tq85jjW9XECzJTZ89b2GgeEEmt0riul6H/h83mq3Ot3Aqd39YjdzKRWpdnx1xSLbEIbse9BLA1ItLf1U/ubntX2QJOR3+p2GiDiPMoYog5A9FVuWKjqrSSVQM0vfzKw+fhxA/7VLOIOVJFAmEbiNhvzdAJpI6IpGgLOkzVS3PrjgEcggU4X5TNouCKg6mQkPTu7sfB3zjUbv+FlYgAZoDdQyZbnk+RbJAzqu8/H0XaMwn14VXpELhWsvOq0aOU9RrBsW5qWesmWwqA== 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=fd7aIaHCZD4gaKfa7M+SsWNu4/IFv5qLtSzS3OVrWsTbEZh+YKxkhzQwTeYc5ZAEt6ZCB1t4Z7xdTz9JiCGrY9T3sd2IMfw/zrscgkzfIc4OAaQz/UjPgojDlwFlruUeakGTjj/f6+IJ96mVufM7OBRRrGEYNipC9wPEnL/65XNIMRnUv3WCS07sscTp1KlANf2g9N+ZC8R4FmOP3UKKeYYbOwBGoDCQ2YaA/8r7hOgedBWaMi5JIhHidcu1jW7gLtNZ9KvY/Gwbna3eqiNtyN+Kmarsos+rYTjB/yIHXw+SBaqktfnbRMSz+OQf/nvaezYEri0pUyxX2RFoDOfAMQ== 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=ItVHTtfxzljT/sPU7cQt4LDcaiflcHhMktodknkQ3wd8XtKGhRacF6CuXrEjmyyzCgxiwwBG42EDlfbzJYQpX7BC3ix/5a9A2MLCYahBxGDwy++CFvUJ29UkyQhKKem1PThueL136cVMaCUzbwF5wvRRq5wTGbmviwwgL6T1XE8= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48:08 +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.020; Sat, 23 Oct 2021 08:48:08 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 15/22] target/riscv: Implement AIA IMSIC interface CSRs Date: Sat, 23 Oct 2021 14:16:31 +0530 Message-Id: <20211023084638.1697057-16-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0f118d05-a8ef-422f-707d-08d99601d5ff X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: vaQMynUEEFAo5+P58MIl8rgsjAF0b4CuVXcRxZqFgU+v8XEJaAYw8qhLfMyl8yzNCfKOT9dhJ/+FKwJhurwF75CBI0atIXfcxMHcF3I3iF+7Mqoh2EIx+zytTs6L8YDxk9gFnPLDMUuzolGqaDaMHcaFHUlQFuXK603qU0cDo+iDMDoGQJALzgFNBJa2/IDussTfeh7AWNcClp0/pYAcfhNhKImU5twE96AnKQbBcfiJS4CFv3/SaKN4dvLu4Wf0/UNlf06fqMSvlzTVl1YkSBgiVBfv1SQYVQPK8WkXFPABWi5TVlnG+uqgnyJnA3YfUmaOc4CZejbwIjKhSVsRPIZ4fNxt+D2oGbelIGxgnCovPoWg0VZJyVWV2qmkBNB8y+Fl2yoK8sVXC330D6CGRVNDD9GL0GaUzPkRTBIMBjRnG/uQg2Z+a7tWQUyrzFCQffgYO3JevFW9yLKT/aFCPzvAepuHckQ5RwZNaDvJuqLhVfX87EjTWIhGhk9VmXzKsvneS4IbiA077Evnr1GjOj4l9D/3JKw2HIc8cnOtjIpuV393WXKDkliJocS8aEtxibFVfi2nBkiAy8JWpVcwmD30NZpzwlsXcbC+qF8mq3DZSIFxTBGaylmp4J7ZX02HFI6PuwY9AZcSbnkjAZVrjUYp0afZ/uvHib5d4vy8bhhCXLDaZxQFFryvc58mR0EC 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FMmOmOTIxLpP1iKKavJbkHeGCpXNlTFZpxNna1STcBPiFS++LGw9rLJ9r6NRGBmLKehANKQph5NGaTSP/a6h7bojO0wXu3DsEacakORZwIMFdQugYnfe/0J1yXmZrY96v6RLSPmUPUVYFSFWKE7ZFXPaSrMCcO6l9/HqtglXZ2HikgY/s7ZV24+zHBac2mcvKwgQg+okHnKvoacCypV6cKGjLJGmKoH9WGHSWdIZ+RWAuqvysBFlTXVlVUOfyzs9zyS9VQrTwLFNWfTvzpC0+0xaw/UudQrDOJhVsvYRUgMPFeshUTgsW5dQUTyfHcJ7bsfisrl3+o+5vUk3OOx6io5pw/HZBRXkULzYMzh9mS+SuY0yECFB29AYy9w6IvSOWYu+x4dIt48HcShZ1dtakNfwLaYxSdjPrZlkrMMnqqy0V03Ypt0bA941TnOC+XpQUOVT3K0u/nheuQIGnRNttGH78/X8nER8s1ODajxXLccGbO2j113LLHLR8/+ZBWK04uzc7a/6OyZGITsYtmJ+ZrDQvFwaX3SCT0A7k0ho0QtQ/yGxqxhMhhMzeJG4kqxaUGL2Ozbk4WFkrVM53TM57goB3vm1/9AuZUrQvLwFY0pkUt4HP2CIAL9pZbICHTkBTKepsNtkaxQLNEiMSnCP6u+A9vSptEkQiiDaJ6SGI4mb3BG/Rypo6kecO8Q0OJa9ecSxhM+JtFm5bMv/9TWkMLFk1aO7+3ft7kzAt+RVOQdBlMxOtgxsiwLtz5/HgNyTUlR0Kaec+tvrDlk5BGk+ehgElwn4sx3/+Lfr/5e1OvweR1PrZB6bN2WbFOxhC60FceEJla8CPmOUAxW3h0NMviZV51UU+m5Qp61zR5e1JZnrWVA4THfLeuMtjd9izVoReKJolHNzaPHu1rD+rxZNbg4pycHQ+Ob15wMV6Q2t/RTEruI2T2Boe3uoXKTW8w5YC0np+gTL9LOszM5kGm0qbZQTtJAhdmuMxCOMSO+8ZxyMS8nOx0u0hF7DgRXE1MbBiyrd4DPtM+dvT13GqxPDdb9rcmnkwCxYSB5+MICIK6LJVtA1yeviY6i0ajGjatYOUE5QnGY2MuaTi62BUC+Sp5woT7n1NDNxQ78Na0hG187RAwYXAxmwloRsUWostzgolvzYSM/KxsnTJr4grHUSq/keuYP1PKUp3iH0BBwY2BrcwSXWXeuvnVQzmQ9PIVEOc5ZSrkoVx+pm952OA/d7gEjcwETRIvYl1IIKFIR8lcoARGevmtEv8iFO7YWiyd5SuXEUU2MpOhvznVqYgmrfQ5sxNPhnhF1mIvgbV0LpWwB1dMLG4p/J6n7Bls0K9Qtq9tbXzB7Qh1kIm9GpJeZqlzcR27zknOhvaUWSVrVb3OAR+zky4aA2F4fkNYJHnNC5GjhJLfpYrzj2thFssq5cfXvoaefLG3anCp/caegPO47vSouojt5lA33VaUvGAkSwBZB+aZwyvfyfczx8wrZZQ32kYuMZW6D+PIdGlQAdxEa+XUk7BWu9MIERqXAHxIW8IWCO7V3A+dbtah/j4CP6UdAVQ1WldwA+8qjO7JJqG8VJNVsrs24CdRy4sL9HwIuWjlTxHfkxKaQV73dhQUBjZcM5NiynKldM9iagsNMXUp0= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f118d05-a8ef-422f-707d-08d99601d5ff X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:08.2243 (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: pVcf0bkveVklvuc2ozIzUtaRbu7CYMzxDXUlNsp0rDAYG0xwuXrXdSCUfy8waJcYNu1hAFefx8P29La37B7R2w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=FIiCZVry; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=wr6pMhQZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbwG73T3Fz9sSf for ; Sat, 23 Oct 2021 20:02:23 +1100 (AEDT) Received: from localhost ([::1]:53392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCuz-0002gh-45 for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 05:02:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChR-0003Fl-Dg; Sat, 23 Oct 2021 04:48:21 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChO-0007H2-7e; Sat, 23 Oct 2021 04:48:21 -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=1634978897; x=1666514897; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=EjStFy0Uux4hB3UssCPVRcOfhMK4l65TuN0t3V/k6aw=; b=FIiCZVry9dEnejgIjNDo5nBZEi2K0hXsceMAhKeFqL3Q17z/OeniiKYf /1lIYUuMdLIGoRFZkdIgVcZNmFDBeYdGNN5nVbaVBSOZTI5i1o0ZEvT3z XHotDOMvKZ8CxrUl0NHxyZpBcIq5oxJ3gEK7jH3gc0Tg0jsEE8wyPLvHA An21snUT+NkAjIH9n/yOjmt3IbfWL06hiOLhU9+fgK5XIuQGZceqAAWFh b7hHCaMw0NJ2s+dMwzoTAGHU4dBRYe+KYRBNfcqUSGmdSwfjyQed+NfV6 NtnpN5FbJ86it4SmvOysuqYzKTngn1Ct91CM62FIPqvniaq/YM8RVlEAY g==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437382" Received: from mail-dm6nam10lp2101.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.101]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:13 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GQClvBQMd8f+hvl8m/e0/tmhRRtyTrnkF9Q+TnrcgmovIf6xEKe/8iEC4LBWDR1jbXkc9bDuHr5sDHqL6+sEWxkMYH9gMn1CjYFKqcOKDNfJTAPF1uB74SbCvUCXIM3+405vII/KMtgZOfw47t+XhcgNTjf8/MaQFPkRPlW9ddYbzO+R+ABv//4qIfItUe3xeXZrkUhd3Bo3whXHhrTRsJl6cRM4yLTlldnv7RCOUFIsHYlp7l8TgALsrJlngVqgxadPuiZUyBYuEisoW/ygfU+9UeqCJkBVrR72ZMTfRmI4OkJXnPux2/UAHeyA+vcb0YQ93N/68bsyYZuILz1ekQ== 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=kU8cqoZNszvsAqYR+eC6e9vzBVsSIHw/rPba+AeeNmO5zX10pYXFZirxdGBzJcVe+qs79drpE9CSsYQrVud3sP1uCWkvhZurb3nTkWH6RTQ99m1vla9NN4VAx19tK4/SIkaMEEN3NNFJ7I9DlA7sJ6vOMEMxrExYMX9NM6zj0/dehj/6IyJy0coZkEJ8eHIQGMqe8/X/APC3bNrHt5SmpFfHMXn1n/xzz0e8xeVwS7kgZmr6nw9iknYPuzVeAhN9AVzjfeVBeIOSlNzjkSS3mipeX4GPxaMm1V5tPIDoBmdyIN4h9SNaALmwoAlEaDhdh1XIUelCZSj/PTDMQxabLg== 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=wr6pMhQZSkU+BzrosYzsyXZreNh698cytxDBQiSAmu3q6iL+NPJZHJMflJcKKBFhFfNXiHmA6Rmc+jOHOXl/WO4UPDv2ToyFsk3OY12NDZL0fhbD/D7dSBpmshuhH4Ga0DEjvvMFFfjaVV69orCmnMw9WePDkEqKvf5OM/C8/IE= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48:11 +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.020; Sat, 23 Oct 2021 08:48:11 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 16/22] hw/riscv: virt: Use AIA INTC compatible string when available Date: Sat, 23 Oct 2021 14:16:32 +0530 Message-Id: <20211023084638.1697057-17-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f81c5fa7-b326-4f30-b704-08d99601d80b X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: ZpgyF7/0+iVWRy9nVR2etJ+7GyeBQ6mWaqbvfU8RUI+0AqRARN7B0Uao6+iu+05s7lOaVqpunOsnvZ1EC8gLmF8gQuaa+qfVLrDJl6xF/kOP7Fc0N1fm/VkjWvjdImW38+N+9aMVVL092ehvHpDQ4ShlqZ3oTBswFELpdJ/4SxmF5LD986eeS1zggVfE+9nf6EpCGnYUIK6Lc0hxEx5C9Y24l6bhO7rpCntKvuZhRUUH7+S9ghpkYyuJqUKWpADKYHD2C1BsdHUXLmJ5nL+pxifdBFLOnGseC1W/TcYZHMGVHid5sVA8NJnTcL0atm9dwUb3+XqOvLacWqR5SzLqwNlP+1lZhWFlc98N9y3W+Rk6EHy4PjZ67V9VClBZrOSJaShOf++rirjeQqvA8vzK8mryWK3yS7esZOXunsAI+CzMJgptRGwY5pPLkjDuQSASFXJtmLPy3hTOo4fS/85P0IL0YHd9z2Jq1V3DI1Jwa9ben3RduweR09A2iCdoFlUspJc2LOYZMbrS7kFWSsUAutBpvLWcb5M3cBxA+/UmgQtQjFK+t3US6mAcl/mZeNA8hjCFF8wbM4BvismY/lf+B2Dysv4KPKqB2+FAvBItuBMfMB/+hzR9ZbT0WwKZugjfMhy7OB5tJVsR//oCrj5UP8v5j23hrVL2VhHlQAwHiJZUvAblOlYVJWEFrEV5ss2V 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3gExWZHoHo25YAEOYpreOt2LtAtwHc8zqYVy6F/9QpRM2Gl/xv2aMrEhGJzCDVWdkvpxfJa7jak8C78/5m9vc9hq8RRpboeet8zMWFZkycfhuYrvjITviEdhBHXNHOtBqbIvLykiv/OnFHzQzQ+lF/q6oAi5R219f7VD2vGKxmmHkHgZGwUQLzWbl1R3b0s4rSYTRJguC/Ds7iwEgOvMu0QSoQwQLZxqdIgSqYZRmnYZYNObdo1+ebCEKDdZ0E+LBrHm3CXIx8EtO5uDEygthPz9BOAvOCWefmDzC0liSAQNPbT5F3gdyN5m0ylTIcJyn86aw5nw083DvEWQWORmsrPmao1KhZVUv8XY3ha9TGXRNUTdRXugRJOO4nQEQihZVWU3emn0/h/Eov/K9lHEj2XBQSzjip9PGrFHY8EsrQvrlM0GFy9psn4j54MLQwgOwYe2iji4e6zE24Zw9M/MPZokL3d0xWqrj7D55obcnuzjw65u6BXSWJie7HQVB5KdYxOUGsbKsxPzUO7X9LKaWrjgk+RBjhCqxCZqVdyiavLjDT9MFiRctpm/D8sC25s5V43UfxpwfHDj3AfmqsGqSbiuGq3PY+R3tW6WW2ys8OOSgr2LYyCa2A08GFA6z545qD5GC325hGFRgfLOt0jM0ljI0ZsjN3UMTJEe68dJbeQmAKSHg8noHF4qTOg3pb8Hqy4JceTRXxlqjRM4T6ZJVqRJvO8NnsDbkyj5eKrcpm7YLwk5DoHImeNxFrU/czfQsZgInAUYkH8eykRPJeO1ikZyOBoqFriMY0zZrAiipkr8KwjG6CDel52SdYuNqxQyswxMYIr5bZfshsuE3bx6LJOv06knFiFCZiP4WE3FS8MFnhqjwXXPTM5fKAukTRS0d3Dk5O7ryXm5lSUDKfr7ihsJnnxNE3gqaHtCWoEeqEoWA1ZTOUjmF4Pqeg+52PwDOj+/TqTnVPd2/KNY5krD47hfffmNWDenaEln3Yu9IYnK7oOyrD99mxnwjtkx/RhothI4L5JkG+V/ClxdBJZsCgclPc/dNfPpZgjzhNJAfDEVPwJtoCvCGew6pD6rfGe/4/60ZlyXOewRWJsGooGUeroRPRTXZBDBMZU+iREwbO4VMf4v4/k0ZeaPNFxC/Fr6zhKkW1gONKF/9LiS92AKcT0/6j6I9mfOf0b7DB92Hl5MA8vVpJsGyznqwmy7iylnoekbsaQBQUDs+iyMmSMAOS3IV4Vw5LNX/ymadE0il9IWJyDdLFFBdO425EDquXBaTqI+LBby/kz4Xb3UPLguBAKYZ5iOfUdi03yQDZRIyuw5rQbY+QdGuFVstQ9Sj6senhSu9zo9ngx6VpxFqxKuD89nDuuNqF2tPtFMxc/4+QFN+r4+uXVfYMWxkGnw5/QpjdO402m1hu8vB9Wbx2I2Ec6V0+Q4wXd6Ug8RE3RdITA1M5CdZymw5idoCA6x3kccEwT2m0kucZhohLbf7J+Mcw3HrWi6TwpZJqb2FiLTRKW+ANnUTBA+vSWoW/3RVh8iZKg+iLpVPxjoCsVlIPh1rIEaKvM5L+WgMmHHiiA458UwmnQXvUx8la8YPxjPWcpds5ElU+TyDSiIkH2JBTxk7Jvry8Vs1j2gv0RElKhNor8= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: f81c5fa7-b326-4f30-b704-08d99601d80b X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:11.4949 (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: R3BnKAaZTO6DnAnNTOi38rJ+lFF6xRfkWbzvXupnpJpw4Z2Joxs/EzJCmxL4hocE4EpsPXb8TbiwRSan+qXbXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=LBR1cpgW; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=Abl9mLBa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbwL33lBYz9sSf for ; Sat, 23 Oct 2021 20:05:47 +1100 (AEDT) Received: from localhost ([::1]:32792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCyH-0007mP-81 for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 05:05:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChU-0003Ig-DB; Sat, 23 Oct 2021 04:48:24 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22449) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChO-0007FK-AR; Sat, 23 Oct 2021 04:48:24 -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=1634978897; x=1666514897; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=qesbuuEt1k5lDjm2lc3GrA5LxA6lJCG8dTP6OBcwp/Y=; b=LBR1cpgWXN4nHti5cbHJ6SH4QIdK/lyGJM89XcYz5sofJ0VbqBjT5EQy bugy4pFANFfYOeC5DrLoWzk4qYwYPDBEBGg8lNLeWg6f56ByZzgU7IL3U xG7YFyLbCHpFOyr8NwG6O1KzwbtoSr8jMPKCSb6ZxGYesSEIG/yF3sMr0 oNw0gjcPKGmtRodX4kO0Q06A6RK7UFn2Z0fDD6Mo1SRgJetMoaQBT9txJ CPj0bgGZ49U4UpV2FfTkDjlXZk6W57+EIWmrtuVFRf7wyn8qgJFFKQhjj ZQRu1B2BjF2LIu6v/pSyd7cZIUfy8+7sqRGMJ9lOi5YsCGCHmUpxCMC6J w==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437383" Received: from mail-dm6nam10lp2100.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.100]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:14 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=edBustvmxIqvmcqje/pwb3zy4Cas0hCPG7t3Bp/3yjlaIOEk6G4NVzfyFtptkwtZjmzlv88le77mjdNxTbEBYAiSp2tpG4MoUAVcHDPy+kSP3Dtwr5ESVT5ecqmBOKNhL/iiuyBNGOOc+QScOFPIXLGVj0XjpX9wCUR/SVQmV8cX41LJjUnhHq+Q9Me5zJ3vZI257N+ud22414HRrFmCM9YVxJE0eeWuhzTIlIJJlkc4VXHCIeffS2kXNq4vKekfYEo3Nj3nKNp2PrO7L6LtN0J2OerduSSkKnmRrpxEt89aPwGuAnSLU+VxYxOWfxvVqv/wDcLyiz7GPQf2ASXPxg== 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=DAg7qtkvpWDX5AhE79HYesCvkyCSSNtLdZ8IqE9mEeZH82CAbpi+02IPPJmdbCF/Zsqyng5bNK66l0Dh4CuBFKQJ9n3N274a+P6ECxMClHVL9cCd1sV7VroR+mDchu3BFkETQj1+KpKylUX6paVrWRBjaxoTiCcN+joUCEAwCgM7gWj7q1L4Q8Z/9OxB1vketRoweTxQ3GuP18zVPws9Ku8dHVsyN4vXHgV5WE4SBpGinQ0mfPEaBqarRcBQetNYm8WM5G4WFo2p4Roy2lNTVIGaVLjfaKBJ8C0q6U34iH7AmwiKGHyLF0kJs2xTm9RKBcTcd2QePWOkdrbHV0VJWQ== 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=Abl9mLBa9KyUvjKEDESIfdey65zQg3WvROA69dQ4Bk6dCrKlWRk8KIsZ1n1Tnz7NWOK33CS7f8qW0R5qch9m1JZ42B1zSxnNqdwT/tc1/AlbIj6EpnK140DHdZ8whtGVNO3vc4XM8CpFABYG4MScTPHAUENho5F3tD42Da01Ijw= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48: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.020; Sat, 23 Oct 2021 08:48:14 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 17/22] target/riscv: Allow users to force enable AIA CSRs in HART Date: Sat, 23 Oct 2021 14:16:33 +0530 Message-Id: <20211023084638.1697057-18-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6d7ce5d2-afe6-4de8-d8cc-08d99601d9f8 X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: 5MkIHqoIVc8wJekTtbdn6ou1aNrmNk13rFcLVG+jPj34p/AyaAQLz26N8GnankuAgoQSvRKypRxl7NADnl/5oEcJiHqrs2WAcnGQifJ765+o8ha+5X5uClpgcPeNkwfoO5gMrK+NP1H8cudPucQoy8BRwKh2jcwuySxYF86/XD8VRhIVpCJFDH76KaFMU7ExrJn9cJsXc3pbJ82Et3/E4NQnSwHtQgfxalogJQTce7hBye3WP5unG+Fvru9P90reoQ0JQRG4y9nFY3ueIsoUFtx+qFq5Qwc2VMRRNkrl+rDjTHIMzPqH2U7znJVJmi1IVrRL3pXdd4dAbp3WKkBSgalvhzgC3OI8v9p70eksoQXY5req7FAMi9vNt5PxB5xYSHLMx4TzoHXQp7MtqSgmeqLAPrGZ2xgupiKxgoeCfDRl8dasP9Ltlg2PiYusmcyYV3YXOc+U1+nopNFitR2CkMJehpl0PGFXbX0BvzOySTZBBaDQWzfajdTztyBw2qZX6F3U4EDwW1mRKofsO0jCjrdTb59K+EjQAw2ivFJTUo2ZdUuYGbUW8Vg1nqjFEs3BSUnwRYTp0zaF0Dad/EXxuUJe+lQ+XICFAaa3Hzh0N8xLaoF37tcLCnCcrm8x6U+4Si8W0Lb/K4vBLcHBFhVbrVGEcmWlQq5hVaUX7VrBgqhxkkDT92JRwkrlJaKwucPilAx3xNip5Eh5s4zlxI5kLg== 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hh3LybofD+jkWtyPW+PkoBVSZC+e6gSiH33G4bWIRhq2J+yTvoNGLp80Ptm/gxHrVBljx0589wC1LPKkK48fzdWBRhK4CtW82YMhxKPaJbTa3XSaz7hPRGVsOY7WhqDosLktwP0/cMly8L4V7J24TaOj91qlWCEN7UcBiwD7e4xyQ2wQdPXtISIr9AmDLGHoHf4SnBBU+bJDME3FEOMOwYmz4e9++f5UDZ+VI0HF5j7GCIIQPey84jRWtT+ziwfE9KI+47aMhT7NILxgtuK9rMsGFH5t1vTLu9TvU3xMmyAAPYf+tw+VSGJyL915IPdwS9J0Kyavo6kmavuyTnrDDN/KnjKNJVREjgHUYiM36iMHT8ziRTeyjotPogAScHkqZhVqLda3MnDmyxI5ZK4hoUEFD4vqIykpnkqHio2iyVEB+RhSHu67C6vrjOfdkhRKTOwQ3sNc2ANdrefH2WRfqjrvcbWPm1Ip9HDh7B47Wkw8oWuZthHnQE0febSydvzNoaAEYtUDA10Rr3rmkHMpi3dyT/6U3Ym9pD8XLJ5/32aROeldyWEvYJW0uewJhHguKYWKzRma3USve3f2A86FXLH3Wb3ffWP0fq/QVF36/bAEE36GmaSM90BFew/oeK9ZA1v38ffG8YK0aavDM+H7mPl0jWFXnLtRW+n7YH21X0OLVNz6o4vXD3gA+37xya494Rkrl8/g1GyQPEcd3CBQLVc6Ct6pQXvJPawWBKaMmz9gSOjgNx+hhfKAUSlYj9DV4EKKTrF2K9SAse4Fv/e+XeY6rnICliB+cLeTH6V24kwoTKQ/CAZMXQKyeFwmjsu6Ub0fRRJD//l4LGTFx4nqde71A8z4BcJqmzU2hny16WgP13+aqWpIuV4lG1kQfBBAmP96Ij9Y8D0eJAhP42MtY4aa2jhf8TNpAwFVLCcPgHVQh7Y4+iuz+IKTyOzaH62/ILraBQzfv/NsYturpWugG3SlTUIOkmbaDYi449cczGRQS+vErk6deIK47xF9YuSazsLNEWZ6WCePBV/A/0Bookoj1PXmYu48nqT1aLT2L3m4Be2kjj6a7FZ4zDMsfCveDnf5KSFuj02zNwUcYUg2DZtLPnvtq9VXMHal3ggGp9KaSLd4ThzXOKTerZcLaoVvYIOo+CUlevAkZTl+TxEnbLE3phuBUfTataVsW9tbNusWEnIgjZYSmA8QuQlLteQfIO4ZqyBnxJ/oiYg+BZHHt2Vjn7GZ3a/uT0Ds/FWyrsLnbw+dKQJ3a3DgwdQJ/7psUN/bodpwF+pbSG8vrYMYrJ0c8BuLXRhH52RVlGJK9kFbcCPrh1CoKU5YVnaeUu74bnRJ2j3kEdKdvs6FuSv486lKksYSXVTFsZpmrVrznS06jQtE+wgbzVHFgyqtOAcqBABFsU5DtGl4b+jib4mTfCxNtfvnYObD6amEBGKcMRPoyUuQLX0csq7ldE7ZOsNozBcHREe1lynhQfWGtZXWjUfQZiNVKnoyBlSNhALy0VksLf0hVbRBEMw4In9YxUIIqeN274kA+8aclTF2kXAVRN9hz3bJpe0XaKOvcanM2N7Zk3PDt6dAdsSuvFT/bO3IIcPp9TiG0OrTL3jw/mNfwwEtJbFLUBIYrPp79F2ONhs= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d7ce5d2-afe6-4de8-d8cc-08d99601d9f8 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:14.7028 (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: axcI6NNbxA+pynTYcMVjle7wmNMW7cTbLyx7y6VAB2/4NAnrm6QyQnhe1+/s8pmJ3g4MzjXOW5QHNUDqtyqEFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 Sat Oct 23 08:46:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=LxI6EVfM; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=V4WJ1iG+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbwPR3QGXz9sSf for ; Sat, 23 Oct 2021 20:08:41 +1100 (AEDT) Received: from localhost ([::1]:38754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meD14-0003V4-GX for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 05:08:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChW-0003Lq-Be; Sat, 23 Oct 2021 04:48:26 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChR-0007Fj-CX; Sat, 23 Oct 2021 04:48: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=1634978900; x=1666514900; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=+Qy6G5VJJXJ9tGrMmWOuTUHFe/waSOQh5skzBKLuXPk=; b=LxI6EVfMME4ndt8crJDVvd32aHrLrqdH0gWzNYAu/5nGss/7OXpYLnlD Fa52/YRYyzUSSrJYUYsnPrqUorAvp2NXKgEYixGcogdaGEX1IWXQ5nLH0 fYVjsNlY6zVxP5gSmsz/twCEAKIDFk36vW2dvmvL7W/D2bHp1/HC1A3IY AclqgXl8lVoFzHCvUu1MMgBEMWF4L+dwKFiK+cL8psajDBlmjlpq1t3FY 54N9ufO2vtf84v6DooZZyosk+740RZh5F/vF+ue9l58Y6vJNS5ypYTZpU aodqaxKQepy6LvVhjTXlJ8ywoR5+FmuwkfSvVZbsAtAV2gvdLQ+8QlyVE Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437387" Received: from mail-dm6nam10lp2103.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.103]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:18 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MahuJlkw6zqIbhN+HYlb8qjYXOMX1v/4Fni7IC6sBmhU+kk7jTuh2HpbY6OMOz3mRtDZE5IrtnQ1sEgEGBed2XST0FT0FfHwW+i0yJD1QT4ZoDZNVlLFn1b6duIW9nU0/qa373WAy5jvnk3qlTjZVNE00zJxGS/6EIVdULzI1CaP5ufUntZr5yTpmv4AXpM6CgErs1J8pXgmM6h0YzFhxNT57ciYoITjASh9GjndvxS9T2YqJaK9lk9NfM2BwcnbllQPoMWUtniXlgVM15qHJQTe62UeUlif+aXbDFXfdqP+YU9lz56a7SZcn/t6zZKXKR0iWAwFktlrsDjdWaNwnw== 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=rwy5QZ825Z0lIKqVh8zmRSrtrhWyLdmvg0j2+kijEdk=; b=KLB47ktDsxiS7yUcua0sd7V4GQxJ+7dq5WfqCI1fI96c+4o+xCCxdShrbN/xET/hs3JrK8NW9mJQViwjQiDMnsG9E2gGn0bdFDRa4VXdPDHtPJCWXEbUNB1htIEWWjDsYlaeXzXSrD2KRZy6seImNxtRobV3UCBRSvArP5eyJ9JaeGcU6AizSNN+1ojpxZ2UjqKvJFk6tBc7L/n58iGFwSGVuoW9eNIWdLoegfEzSuhDPEcpqSvoGusN75B4pbh6oYddh4Q8qtZLMJ8FhQ6My+6PWjEr/Ev+lVaqWNb+MUwEPjekDty/VYC2KvD1/k6mDinF9vLMwdBKHl7tqRm5eA== 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=rwy5QZ825Z0lIKqVh8zmRSrtrhWyLdmvg0j2+kijEdk=; b=V4WJ1iG+6ZeVoPlT67OgodgYOVsID0iV6aQvCAfQ22n5JFoju1Eac0QWPGbVQrIFAqo5Gnt2t/uJ4TURH5Fg95xtDAvL6LHldXTiLyI72DCv6El4CG6tsO/TMhUse1LcjYueJ7f25zlc5AlLYIoRlpNH0yeSaxgJj9wE/1BjugY= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48:18 +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.020; Sat, 23 Oct 2021 08:48:17 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 18/22] hw/intc: Add RISC-V AIA APLIC device emulation Date: Sat, 23 Oct 2021 14:16:34 +0530 Message-Id: <20211023084638.1697057-19-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42a28ffa-3a2c-4301-53da-08d99601dbbe X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: tVXbhRdhtrs9friRu7xv1sYOSs15lr/P19EADRn0VVCUxRDXz1uF9zN46rlMC9E83C7lHRL7j7GDktXDboSi2WvvEpasRM/sMy5lHkaC/YHYSYk27ysH2JuKuG50l+S/10wOeKCd6lRMB5Vrmh/erp0/IOAmkO0zp4jLYSDhn4oxY5qQZbo2SkJB58692NsAB+tIktZph0gPcQwZ9eLr6UfEjbbva4CfYyKgCizPiIUMPsShuben8+EB6i4/goJpNQ1XEGg+efamnd+5fIeJud6mu/UWf53MPp18mQGV9UsAbKHuzoiWGaZWj0M/JnAmFD12T78X7n0zAX+Gwat+HTbDY1dVpSxpSRzgO9RGe50Ymt1S5HKjQRBiRXauQFlOzaQQkoKCWbEIw+zuF9F1CFtkLDWtui3UVEtrM0Xafh9CNzGGtHN7n++8Pzm3RhOaBSqa8XfoBywYPOa3twhx4KDedo1BGNnlbLaScwx/ne4AFuug4siAGTXSEh3JAEJ0H7ssQGMitR4xzQxQmATf4kxYQUKiyB1OkccGGTElS8Inu1fBYCkfXRl6DWGKTRxUYWJho221YzfbDBAS3cGDSXogKQC0dJsZuNH5d9tSlrgQxf3sn6YLCOjBGU6cWC7PzmUuVmBRhWhzUaaSddyxi1IwO2mSgwCHTi5wYB8an2OE2ptzT9d+3L4uSghoZpZrffA+uF0GdgM2EO3qegoiIrkntFPmAjoML4KH2S5s31mRnBtxT8VOhHd1uH/S9qbmBC3fYgLEZqemIwmxQ6c99LQPNgYpUu12oBXPFvvxXcs= 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(30864003)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UbfbyWC/+Y4qcyFBsGqTVibIKq1GDAbVRqLualpk3WQvhq+NZxwkxn9yPhsXXssOVYvrj15KM+sVSyCKHfJUq6bHCEU2wLQXMPUlO15J4GB1jOE7adExswRNYA6mtoHACl2b1ZRQ0PzJi4RLOYHEL8Ly8Yfg12iq5+jJsZZ2FH4JvpdQz0RqHhIJEuoU6AIEsQ270M8bNdxHNFJGQ66/S0WQTn5Y2Q089UFPvZJwtxgDvzW3fAgo5p7GORejMvPxl7zx3fX44WvHGjBrX8FVn8I9n2uAV/HTvwDZZJa5tDVIkJJIivATYriUwpkcg8oq44O6GUB7RAjiapJ1rGrmfWrNxrW3WirwEIKBIPtOT4LxLATUDN9J3PVW7fTffiKWvcqOKZHq2fQnblQmzb0CxaH4y5Nu3kW5GbDfYMkhjex/3Z/OX/qC+2mlOWjmEw0GQdmsFZeNFPAzD7vc8QAs2ojsWcOVfxIhDY/RAagzvx+8LcId7VitKCtIkJ5qeP4E+4LSA270Sh7HPyTFsQ054wZon/c1tS0kDsTxE2oRVhiI0Ajjh9eaIFjlO9d7zBFAtZ/RgFkrJDdoz8/wrZ+PSiAJX1eK+0dy2IynqzaOvRfBrtnzEewYfmwM52FTktRcsvj6BIbNaKT+hc9lIFfg/cW2Sze2TdkIV68jPCRtqLEBtbzed5UNKPWvtoTh3m2u+ZnWYeZAqxCLmbiXRBSyCkcpxeqDBXVCz2s27UfFSjsCpdOkTbbeHRY1jrmYGkDkcF8ExaQZ+NEjGkW+3EkX6nn1uedRogJAarmMgkjs1mPTCL3dIbDpiL3FI6zFxcAUwoKd82x1xBSVArkbd28Ud0BiG4zHqjmJabZF56IvktQF8EbkVMgR1rWQDwJHEnyhm0D2BmoOrSbCXRtmhiuYs/7SI4gauSsI0ZpVGPXp/XDrpgvz0MP0kvj0Xxgb/2JHwkMRwzgkAPwEn1X7WTvaxj/cHvb2qE6BiESLTBRG1/KkMIeX5HGUCrJToq4eKt64vKUDTL/gB3EFepAm68/a6hydAE9c+sCejV/9W19iv9aXVminw7Gm09g0NtdmoXOgitUtQBcAbAqc0S3QqPN4+3I4G57jTgjCcvsQJKn4dQbf3olOrSSbPHUoBI5rfQv07BGzGCZi0LMcCj66KbKkk4mcPVAgxAe58of6B2yLAI9ulctjKMluoKpunyEeQp+QD108PUvQI/4KjvZfiSrnOS6EjJ9uHaGgx3c5eqKu7HlWsZDBFL7QZe/1AP5xGvLF6VQTWITxyc9sKKL4tXQXxZH52VKjK2NyVoOAc5FtfCS9K2mlj7w9XensgtT9mvQjpMYhCxrjjpBEoqEbe/KZRE5aKq8lAuKd8dhGjLwHph1XMFFQHjs+U2g7NA6RgUyBTTwHXPL5w6kpw7s39IVDZooq1AAmituHMX1nLhNJvF2HKDsSIoKh3UOrtgmOcVP5OEXJ45un+/0xj09JMdn3Ushq0J6qrn8p8/WJc8FfSK/qmw/VwUr5Vzf8F2yQbI2t7qsWoApCQZymQ5+xVx5T5IL7AzJvjL/jJfo2XgAl4Pq5B5gr/EAWAKAyFiwUJHnvIPuhGVCNr2cSq9uXrg4EVi2751k+JsOIntnfNXQZ6jY= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42a28ffa-3a2c-4301-53da-08d99601dbbe X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:17.8698 (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: SFP1Z4lXF4lMtEJCF3GJx8a58ZwphSnwKe7jMmPqAfrw9C+sD/wlHfjfSmWPyHYD35axadzt82Ip2DZokmE10A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 a1d00aa48d..76d7ba08d0 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -48,6 +48,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 Sat Oct 23 08:46:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=iudIOZan; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=OFnT3lRa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbwQv4VmKz9sSf for ; Sat, 23 Oct 2021 20:09:59 +1100 (AEDT) Received: from localhost ([::1]:41822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meD2L-0005ab-EC for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 05:09:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChX-0003OH-Pr; Sat, 23 Oct 2021 04:48:28 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChU-0007H2-6t; Sat, 23 Oct 2021 04:48:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1634978903; x=1666514903; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=T8uzaFLPBg6czKLGT0WUHEYuqiI70L7zm/107lFdDjw=; b=iudIOZannu30nmq3YQBGHHvF7K55IyRgnjSXngOnCZghPaZoR6mBhL9y wZG7Lgeki9doupE3fn/H07OP1Y2vZk7/L3+Tav+i1rTYVDCQZZg/ZRP8X DcromMA0FuwTT5RIyRQ00M3U5/Wh0+5xGAjv59z6NhkU6WJn3BtGtTUQN HeN0l7McIFRAdJjCKPZb0U4cViy8gtLFk6AhO05+RitXE1DadoJS/fKyU iqFQhTKJhyD16EHv18SiuPhJg47wt+IjylZfpE5QMpxRrhvTeoZzIxu// lDW1DoXeBE9NUt5O44FWWaOcFveBpTRb7C/UaTKRtrTdyRytZC6q7Zc8y Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437389" Received: from mail-dm6nam10lp2106.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.106]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:21 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=futGCBtenVWrOTxMp0sbqMTpmIxNtJdMeeyvQItD6Yxzr5wVrfy5H4teFRETloLgSnEJNd5Xh1Kfx+0xYNfJC6q+CSgnOxc+ZicVdWSekaGHFmt+feT07hNRR+76H6mYmqY5ai+mTncYCrckvMQx/CdrZRWLBa14/sxJ0splPTxOViC8z8gMYNcdYoB7sjH1izJhUzMPub55YJpwIjVE2GWqxV5XYraVBnEMA5rUENI1YeUYhFc5T+DTXcvXVPsKA90FBdseq+PXe3uJZQQpKjVFwjAl4jXYjhlPmmZHhojh7hKc8FP+kY4lgNwSA/e1tOtfd28HpC5CbIYTRgWXTQ== 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=1CXhq8zkmAtHMaUTZtIm/NrhBctS4MZ7WNweQodPMKk=; b=ZtReoWHrryWh5XPEHDvsl82wuyiDodzADSIJnEEHTCDMMWPpz39kRyz5b0bF/k3FsjrHhqFZHUnO4IyARfZZHtQnnSTS50rwwxGfkPeSNk/8mJefRNkf87E2dR34blFy/zV3xf18yxXudlnHMzqXrhNL3xq6Z1BU5ZhWAsSmQjCAAcgmaUJ/n7fXsfyJIXO3daVLgtzfuHukQ2jtwIZJ1zNiG5kRisNx1+vmWoWc7tXXSJcX+JqXY5YKvCgYWD6CNP1+HQ7xKjEyS0pLgJc6CnwzByuKSQfGd5q1Ab81HXYHOvOx5hECGYRT2ktWZy9sjEs14WqPXEVmRGltRZrXfQ== 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=1CXhq8zkmAtHMaUTZtIm/NrhBctS4MZ7WNweQodPMKk=; b=OFnT3lRaymcdYwT9pP+3p1e8/o7cVVDUr1yab6niDzUqZn4dv5NTSfYEItatvrnyycbmKIQvK5mQ3xMEeBbfxWGay4x9Grftndjv42ra5RY4qoorLbH9/4oSMXAojVTU4Qruc+1+K9yJnIUE5Y1ATHdEjopTlm5IoQ3kB3/zL98= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48:21 +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.020; Sat, 23 Oct 2021 08:48:21 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 19/22] hw/riscv: virt: Add optional AIA APLIC support to virt machine Date: Sat, 23 Oct 2021 14:16:35 +0530 Message-Id: <20211023084638.1697057-20-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8d747de4-31be-45a8-6852-08d99601dda3 X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: Y8uG24XSr3lZgwaHRbdLFVr5BHefdbGx0qyngIvBbfAa5fQRmGm45Z/kduLtwdRoi8FFaOAxtcR0zbi+9lBNxleuu1M1IaAsZ6kf+IttgzUbD4fxWYL9hnSdQ0Bmfxs7cOv1+UcuT1V6Ltiw/0VeNAq9c8/ArOyb0Dt8yG+PLkxr5qV1RRigdByNAsCSEv6XzFrdyDiwwv9Ha6PyHKyu2H66zwdM80yXWkfA3BDfLq1lrDYzAC55b3Nl5KAJ1iiKQrm4mhSnAUq4h3b2iHvJUtFKAXE2linEq8/gY/WZ1YQ4i2aQ6q2sRQjoP9M7aYFi/9UbQ+K4cBjhfXdMXqpowm9gCD7vitH8XdqkV/1mlYuuml1WMrrHZbq6XumVU896QztSF9f3iAVZGkgB5TiuBVitoBZh6LtZ7R3oUdRZderQA/j+0ZFLDgJK6lGIzXwcr1qWkEElT8dfIpNwM3dKCiGT8ZDk+DV6goQxazbngYIXD0P5LbU4XWsFG0Roj70qq9XXqSzXvdplnJ60XxHTcn+nbTZtRQzpahPb1D5ZPDfygP7C3/RUZZzLM1CnxIHm6eQ8dXPy0/WDACECwd1hSXrqhS14k0iXqegmRCyzhxLHG9pBlwNaNSKoG0JJ4veuJH8JJi0KHLXakOIzjTo7fAHmasCRcK+8hVF5WtxEooy37Z50UHvcv4MgptgPxFWZ 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(30864003)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZAhheEYykZSo6+wUF00/RneK4Y9mRpYyTtKhkk7Z2rFqLm8eKox/lhI+mISepC65yNkSnia5OtNBIV0xu4SJMhww4+C6RiqmU0y/D2O8dwJv4LpFCSCOrQe9dRNHta9NlLSgVYJiP9skLXyZ4IGXMvf7oYDXxEhHirLtQydUinFG9G6WdHN3GKL6ynI3iTF8rrNzlMnus9qT9DkgAzQ0YGGuk6Ionth7PQtLlkTE68O+bBrcTqN8SJP9yn7glIX24AB7blLJT+nerXOxcQndLmDR1yZHfG20liTrO8We/2VOZA1NX2meOoJxEksDnmz+BfrzR1DgOlKXAO9JtKhrWMkwo4lKs4bY3dH9cOvWlXtLD/2OoClMN2ixmW0xWrkrvejQplMbMznb0opor1rrXYcUrgchKBOORMObHvSEP7e7ufmp8KlCR1niV+5RKUYqFkFStm6i0IfTJtmpJcGiwSi3rOc9MkkqboV8dmLoDsVEHDxeKWY7E7lNdZ+cpdyoM4l5eywYzSvJTzsnLUWYTJLz5hHD3XLTsnrC7gWmkHJMkCjQoVKYkEfYclbIVvSYQ6HL5ZJVtMDi67+nxBrqjGxJNSscc2/BNv4kGAJA7JgSKKgE+HCvsmofcb4uYZe9xHbOav3TQGmW5ZakhUqCZMOCABq2WrdfRu7H0tET5yp0hxhm3d7XFii2yuKQc3NN+p4uOIXKosa/U8YyrY8jmxLj4NLU6l//2bvxWHqXXjwzGTOoVCAZXQfNoJB8c84m20lTa46TpOgaxh+vpIxmhoDWsrVJCBWg65v4U85iYmQqG2X7p4azOh3HOecySetdud1qpIEu+aBBQw9ZjWxD8Tngh/CWlIXF1Z5mz2VIlcmjYZFhY3yf+APwW9aeQgGBsci9b+squYVVj5ubf71fKqoTsAv02bhzmTiDBOubyXwDlCTl+GG40SuyJAUqm22txPLAfGwP6mOkEX8nTGp+K1XuuoJXAu7zfFvDLLKgRaIftvC8CcoJExzwsihngq7h18ENb4f42RVQHppZPIE1n7kFEvkF8px0a2NuAFMmYDMnPoohpjrfU4LK/ysh+JaVZQwCwyQOtT8jqXeOu1qdMqf6xksVY/KiE2hgLJMNbF9xbvX2pTHJ4iUoP+pRP0UOyp99rdg1wtFG/yHq6s153WbSg/J6z9ysLYGO2sm9ZzZr2TvNpuic2MmK2134CNJNdi3rrsn7hTn9L0PBPo9PlvY0GWvBwMVrnRNLVAGkvjLqurVc54KRxZxZE6tOCrYK5WALiRcz6DQgHo0Kd5Heb7dmnBg6y9Bt77X8GAOZksMuto2Y8axVAuXsAZA88shtCbhLUORkNHqSkFy/Tj0BVR5gsLdKuIxxsZLn6q24wXmrVvsaZraf4Uun7nD01O3Zru8Y2LGHUsj4PiOYoPROGVCBaNZrK44srpIIqyMzCU3W2wyHxa8A8S+vW+tPlBJiGyFr8fVLtyhW2cKfvH1kxHYZ2EUa+KI3GJZcZtU/qwERUjFKHdbdIhwvBJEv1JYBUoOiCfPfMlCRAUK20JaRGwYepou78qjbK9Ar9hO6GQeRPIqG6Rk3aWPTkFsvrFEqh5lZa/XCwumfnYtl2f95Y2bxZ88og+VeCc8fuQZUyU0= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d747de4-31be-45a8-6852-08d99601dda3 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:20.8876 (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: pJ9+bZOpiB1aZOh/XTE5otxZ9fudt76mcORvCgMMpEdT2+sML/9hWrWd5uNwFabsQRxvJJQoAOyNRO/IgmZ/Zw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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..48ce616432 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, "aplic,num-sources", + VIRT_IRQCHIP_NUM_SOURCES); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "aplic,children", + aplic_s_phandle); + qemu_fdt_setprop_cells(mc->fdt, aplic_name, "aplic,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, "aplic,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 Sat Oct 23 08:46:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545166 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=YpIJgZ4H; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=DaBDRO2/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hbw8C5tscz9sSf for ; Sat, 23 Oct 2021 19:57:15 +1100 (AEDT) Received: from localhost ([::1]:43286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCq0-0004GF-PD for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 04:57:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChb-0003RT-4h; Sat, 23 Oct 2021 04:48:32 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChX-0007M3-SP; Sat, 23 Oct 2021 04:48:30 -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=1634978906; x=1666514906; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Ak0uup0d96hc2wxT3jDMK4AIjD0uXa2oJIOfn+7lg6M=; b=YpIJgZ4HLH0Zf3gTU8SAf+x7RZbdACLKOUocuXWBAn6s/OaTi47nhZtB rAuOLxSSZ1Fxo1LrM0oOiUv3tFI4IRukZPs8ave5hasXbz3OS1WR70jbP jysT1MXOxBT5VYZsn5nFljjpfOaT61tNoHWBli03dBoiDj51u4qc9Nn5+ t/UO7YUOadKdd+57uii8XwpNgbrJS8pa6puqLhYQ0RpuvY9bMqkx6vUpY AXgXnuyGALQG7RPi8Qw1uiQ0W/nEOIYoqbJfMPa3Oy0DyhZULtXF6R0xE 5weCZXq8hUE1E4/+td9Qe6nuTCboh9+DRu1Nw7cUS6dgHDmi6a9mxtp9X Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437390" Received: from mail-dm6nam10lp2107.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.107]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:23 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KPpKcQFWoUtpXhWEt7FHpbXMDqUopAprNocpZqAAIBdgIIi5YmgI0T76pNt0RHh5w9RudOoV1lM6HByNJJ6fF2FonzeZKN3FfXOjmEvqXiT8dKc32OxmXC4Ih0qem7Vu5LnmlNChwE6/159Y9timqTvq24Hvsu3JfeuVwHFZfePFp409QYfSJxnjCSZ1AD3T3dXafYHv6TJm9n5JNXwoalwKv0kZtMybOV1FN8p/ZEoXdg0X2EYKaqVqqQoP36G2XH4E7im4aeB1W/hNGMAwCW72EObDtU07xOcWdNO3CSd44lHjGgCi2/lrtmSnn9tGf2ujPna45j0Osge2eHyl3w== 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=wPJSo40mxOP2XRJtZP9ssE6sYMVg/ZRrTALtjXTtDP8=; b=bdJ60KKnZcz+aJn3a6UeZiTnb5gUuygcq1J+yoLtbrVbIv0m4JcijNhIyYLmCFqLiy4/l5K5vgIu/5jPS2ToFh8SguB5CFJtBBBbEgtJR2MzU2OS9f36EqgoG7+gfr13dIluUo6Twf5lsBtYgSzqLA0A1jwq1F9yZ9c4qyhfbd3b7nEphn+gICNCW8i2Z3ZfwCGI2xdzjPBo463v8FpHsUGLxDI8yY9NN657r8ZCa9IAmbTX5ZJxI76CppKMMgmQIuReEArZ30lgt/De/XgKZ9d5IB+S+iR2hIDkohGNmd6k+cSDynR+40yssTEJi9fMnIyJNk2Y69P9YMSwgpWsAA== 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=wPJSo40mxOP2XRJtZP9ssE6sYMVg/ZRrTALtjXTtDP8=; b=DaBDRO2/FntPB0Ek0SUQSUTrXwfBGUvQg12Jsu+KSA2qGwZfb5G3w2pvgMYe4CNFsUG5fHAkjYE07PWiBIObhfyS/7POx6j1WqpYFk08/77B3XfoYWLKgjET1/WG/RH+ZEtI8yEJRlqpbEbQ/gSG/7jV2/0kzUeP4cfgzdvuHbk= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48:24 +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.020; Sat, 23 Oct 2021 08:48:24 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 20/22] hw/intc: Add RISC-V AIA IMSIC device emulation Date: Sat, 23 Oct 2021 14:16:36 +0530 Message-Id: <20211023084638.1697057-21-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 58bcea6c-d0b0-4b7b-41d1-08d99601df76 X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: wDZgcTR8EUAfa5eEdhjKqNdWjnCsELKYMP1JvzU6knWus7WWguh0/0XfPyV0ab/O6fw6DI3X23RubNClYWt9cRvwZtnFBPOKgk0k6FVycW7vBl+Q6KLDFeF0mt21PhAjUpeiOHYd625snJrOqzlyq/28MusiGv0XuRn65P9dKbc07wu+rXZZQ111WjLSOQ61VWnFOjOqLdBnaZP6k6yIBXMoyVkRvz5tkJFmh5CDbPnyxElKes8JgRp3f9BaRDoTIqgkXshJZmTlJ52SMjg7IhpoyzMO+mN9Zqm5JreQ4gncJ7rijSOEz1ZX36tGz+U6EyYAeVv05D9GBOwgWU6UzwPkkRde9Gro/ur/x2HPJ+Hguw3R+qKVlkiNYo9kNOLThnf9XSf9oNxHymljzImfrtBtx/Ntfn4EEWgMsrINfI8uRqg1h0hpdhZ61uLC/mKNIFBaJvJXFnicpzX8UfC8w1PheTTBNyej94iL5LgPnWYGDbwOqVzg6GfPRKDdI5UDHuDybRrACxnr8+b1Hqygtz51iEufcg9NYzQ/hFB7YO3R05gjlfWFckzfMChHIKl3gG8az1Sbix2l6r/8S3ILi7WyLzkpeB9hhTmSPej0RpAMEzU1pvR6vzoIvKsnuT9C0xDcofsdncKvnjHPfUDrqFUF0O6CmnUJMCt4rNhzk6AykaZ3XZydDu1aYgFuYP6CQyVdBQZVx9nEMDuW3tzNMlJNyaeOPkU/4qAvnYNWUJikdyTBvHMW2U570iD3VWyv6VBwQJHCO9D4VciVFpF7CltkWUjDv9CuDoNiJ5w4Dys= 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(30864003)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tNRobAdGpZCVIatp2OxPWV6GSRoPY0Hl5Lr4TcbWUZzVfaXxR+bFuNUWGFjkpKSM5Bdr8j4pf1/QfHua8LcEUQPHSAJKAQhdUS5ayuUdyw3dR0xUdxAC4hPe2ZDU0RsCwy6QFJNIF6wv7w7k9tR/FPVkZGjT/o9TVx0xZ9nM8r2QoI/eYUeGX8dWkOXn25yMPkBlOPpefRpcJESsAdOxsEzT8Y1Z9T9xwDK2Yf72It/hXwt048WttQDZgoUEEuHneX55P0Z6Ygb2WAQidza4pG5AeHlpg6xHw+33LUQ4Ks/QOIFQBin4pLGp/JIIAwgoiaHlHx7kFx3Y6jN/odlJzGgULTpT46D3BBub4L/5e979ZKZuhwBKBqsmGAVmRSw3Yhtism+9f6dZhaSG/QufhQshxkiYPDCJTQNIsJrC4dl/jffO0LZnS/aaz0er11hakT+2zvBuOk+pPYOe4Ci+d5yOceX3t6+Dtrjj2B1a40QggPgfMPb3EWPv/27MZjIxyy5RfhuB7wLo+iRPNzp8I4q8RxMO2iaJwHU1VSjrF200yW1763TtdZNsgKKtOMv6zSZlUazR83lAOZ5e7CZ4Ql3p0g5UPCjvPTGqqu7+CMyb5QgOJgoNI35SIkZA5Ar3RJ/qeVYJyYyDKEBJMNN9+K/enew7GhjxZh0EgPRMjkDGbKfp7q8sFH0m3Ruozuc7sn6XA6MO3UtIKO9YgpBH0I/moIoGKXO/FkxtjimGlkyNlDIzRMafHLNmfK6BJ3SbBOVcAWDcxBcmTG24aE4XlKxJxsfRCdApLykpksNwOQ1sK7kzD4yRlNy2/jkZYYoCc+3jUw5BZPdQMmJlDDw7uDEtluFfGnkPSqZWHRZlKydc2Mg5ujQJBkt4wo0lfb1Bl9xaSWCXPwyupFW6crodx194EMUj4q4ki6SZvBCO/ZqzdA3UDmwYWO6rwU09KHSxzQp+D96uid7DVRWQ3BRWOniTPMTTy5plP7G9Gzhj747WIiWfz/ewcMcxquXbMNAnzuI0AZ+ZJDA21jppMDW3y8sp+p6LFZqkMqMPQmroTQvK4Ybyu8bl2+z//YIi+m3AGlc0qnmMyICNsRJJChQl/X1BfAB9WY/mNL5J3sOpPIWwXB+QvsTtcAQFXK+S8dsdO/fcqdVr7GioANB0OKxh862a2GHhwHqjCRPq8Y7C+enpzO/a/dMRv5TL+z14nBDQyObiK4Haf5dK97wYcEAlP1pzI9YabwYAvuSCSvXjx9m2iBTHvZX+tUHB5jdBW66P5MMeecHhJ4PuoMI/f7lhOjiSfdYc2pnjrBAwPPR+cFqh7m68va3LgfZlU5ChO8o6a13rY81cLXeg+uPF+/ckvN5mJbiLW/qee763csfng2gp7VmQA+BQJnCpgZ4X8mgfsJz30hTjfpaBl5PvVJ75xX400FC9tFkLRPJopkpW6W+nY1V3cJcXyoTOnb6tUqRdb3k9uug32fdRNC6/lVwrLwcCZbd2SocqgZ9eRdjXwkyiEI+0f9gOtcCH79tICLMkZXFDgjVZj8X0OtFscmMgaNeGyjX8CVL15oHqPu8JSNEA3tYv8jgsKb7ZJXa+iMYwMRKEgpJSPB69igaW9z6mHFhn174uS1AM56p4FDKGEx8= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58bcea6c-d0b0-4b7b-41d1-08d99601df76 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:24.1034 (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: U5E8+vva+/xIO0/F0WOUI3EfKWS1EIzg7Day7peQ6INxNxXk351LkSnvlOvJCA9hQei9hvC2lNHjGF3SCMWyaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 76d7ba08d0..3721a6bc39 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -49,6 +49,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 Sat Oct 23 08:46:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=VqPDUuCU; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=iIDgBnWO; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbwTm6GM2z9sSf for ; Sat, 23 Oct 2021 20:12:28 +1100 (AEDT) Received: from localhost ([::1]:45798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meD4k-0008TG-LE for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 05:12:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChe-0003Xa-Vs; Sat, 23 Oct 2021 04:48:35 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meCha-0007H2-VD; Sat, 23 Oct 2021 04:48: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=1634978909; x=1666514909; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=zYMw8cXWmjLrf5eflLTPsbboYC4ZFOBpKHjE4iPA7H8=; b=VqPDUuCU1v74X4n8tQEDnzeAAvVSQ1GcPTu2CPjgGi05bJROHgYeqzLa y5BZmgbzg/CG1C5gh1kpb/HFIfCmE6zvyqf8kXFJ1FgvtRn3LZfdlp655 DoRut+CbXcg6/B3kocAPSlQHvqlFGbEOsqlQs7gpk6L8OkaOAtbJRgy8F +i3OVYp04UawTwG8sMCpI90LPWGDM2mZu9hj/xZoGtNNZYFwhiBrapqt0 c4G14siPJ4UxnNYlbIC73oFEMytZZMnRVhOrYX8+B6UnhG5VTNpTGNviW BQKFcdozaq10Gr+YSRyBn46BeUFK8hfk6N3lo2xSKgL/PNEFPSVLqq2ZZ Q==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437391" Received: from mail-dm6nam10lp2100.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.100]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:27 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LK5jVELJG8y5FtByeKp8sKjSWpeljK9Fvza76ppN7xvEGtywMAfhb+AGK1FrfyerdS/F3qbFHxy4i79svZvBBY9RdduV/wsnpBFd+9oVSWmVQRZkcDVEoDC1EnLI+vOz9v5nXAUthSsSyF8qKGwKstU0EDHlbBWQik3BS4hYPqYWXo5Whm/T7c4fVWMgFlFNJxTexbenSR/sck+yiUKIVJGltEocxD/tPdWJphU3xTDsTgfT5vjEB70z6QV1V1kDNztxdbC7rh4H5BSSv+qvQ4DODJB+xHTliB0LqpgGSxG9g5ZZbOZMzRumHnLZYTpDmo4hWxLYDrJiQTfVtvE4OQ== 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=yb9mpyRbcJQ5drLQbspxraCw360G5qSSjJTmw1o/aCE=; b=kKFxNOn7JDkWupimcPhiPEDbOOKEUyeUQa5N4ergLCORcwuToenVXCwO/feMFSrnrI3iXkCS0RhyGq/hhKgtXFWcRsQn0M0A7izkZBkI7nvHapwkrd4kLTIyPoRsn6/0NDcRHl9m9VIMfPqDkmldHDf697SvzGqbar9t3jTLSBcapfG72/t0sDtQyno4UUMrG50wDZUwnX9/w1uAKJ/xM6TvVNs9hf5h5FrUbsOzKats8TAFkYjEWuI4x9YzVeTbQR0p7pEMjyrkx3X51FUf4caaKkfG6eRFcd3I4KTCDHwI8ot139um9WcpTN33yf+CyTq2gFx/mo/PXC1NqG7JfQ== 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=yb9mpyRbcJQ5drLQbspxraCw360G5qSSjJTmw1o/aCE=; b=iIDgBnWObgpjtM/d51OYZbWu6gm9jPtjVa17bIKOs2anG1p6lI/5nMu3V5VshCPyc1idM3K+s7k19Oy40n79+6bgA9NVNHDj8Mz6KZnoY9mc6AThGWkSKLSDVBGUOimBkEIvWvntkFY7332kuyTGwmtdLsteX2HURaupWSR8ZJE= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48: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.020; Sat, 23 Oct 2021 08:48:27 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 21/22] hw/riscv: virt: Add optional AIA IMSIC support to virt machine Date: Sat, 23 Oct 2021 14:16:37 +0530 Message-Id: <20211023084638.1697057-22-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:24 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 31671c10-89f0-4cf0-9aa0-08d99601e164 X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: R1LepUQ3XOQfsMKKPcdEunmEgIUNXNoD3QCN5UjoskWaKBnXyzQA9+IYwde2EVV4XXbKu2EIj6SKMx5budhvSJ37QtSmVkLCf30LuXDwiycINL77tUe8KoiFFR/viC3FoLpg6RQCyLI9V+sNvQ5sZ/DCOxdMS3TKWhwhUVhpY3NSFlhLnCViwOYbXzNBNM9aUkurEiDn7vIqZz9S+LjutfkXtjM3168zhO8t7hBCAKwokg9RDuAQKJAysXNxyUzxGiHJxyRaEYpx8XkoimxhObnHJ9mbyApKhCsOd8Qyc7vQjxsAdAqKRg61FYOs/gxsb5gSq/Vu+X/1Vmh+As2zUWZZW1bShmLNyq0ak4Kc2yTjv7Mb+26/guEsv3TWZe80LpWKge+o35qHLT25gNBoOzqlpygJ3cPg6sp4151rrWP7bE3Y72Gmo2E9wCVAFpLNk5jgugexz/QCqmdFbgH7mNMBpd0TR1YvrlB6y5pd2xX6tIV9ncNO+K1ulVsHS6eYGLW6b4Xjiy0DPxOUxB5tFb6LHo4EPnXQpGAZrdD2kQaSsmkjYwDZyqh5gkIIjwCyMsOSvMopYpx8wOC3sDIIm4Ntet9s0lxitEdMmIvasRuaZLPDLZdM9Ah0uasa2fIwgTMa24Fmb058IjmQvQGbJK9983VU8hWT6D1FDq34K+U8XebcECHhXVuBl+Tt8ZKRAg//PA4ZAmY8YkZPtQj0YQ== 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(30864003)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gbbPRM2elK/D0lK9+n/uRG9pzKR5zn2489S27BUYFvC/yA5jJMPTp2SeWahprXtNDNsHT8c9gSBWwxnvgbPClOd71yHm3zmtvJ91wmqL+5bI5xR5N1b0XEyuwiOvJ0s/I35ZrY0B3gdI4nNxS1qBrFG45lbmD2t/fWBx6a00g/I7oAHF4sNJ4ks3otkEf2XnChFil15HWvbj+wMWw6MLINXOqZa/HjSR2Y5oI3YPDdGlY1ftPeH1x6fujFerNx/lwbraHmLk6/30BTyq9cUMWCPl8aCBzMTTXI9OInIvgSyf4C0ZmSOK5+36G8oMA9gf0J0N3ekk+BeLguwtMp5G+l6U71HbhqGAF4FjvErlUslzVXMqHs/t1H3rDBfMSoVLiLAiwarAghdqfTuou/+79ydUgpQiCY81X3BaRtwJLNLTXQNfrXkr5QT35icURSLyVLZ3dTjUHXWypE15h8Ss0ZJr2JjqGC1Fw9FSp3sAmDzvyoNogu1rw1ekGs/SdF0A8DSNE8StFRCR42+/Fou8qhi3hg9geiSyTsgdhqDzIjxo779kBrl8ACgCk7NVx6CRIWri2wVZZ2OdVcT5pTA49SWHS41LCsIAaV75QohLwHp7hacj8Dl6PFFy1/DGOe0C+iQHidCRdbno14Lnbd3kuk5wWozPF1IV1iIlcUmAgCJ2l69BH/6zwVREDLyvbx092hjE1QswaN/BP4wC9WhqJ/xLn58+n+Zpb13Q8USGDSQ5pcA9IHUMB2eu3ViOeC0PCbiFZIUTQje04Jmqeiz80PIBOV5q2AHMQosY8LpjQfKn4y771OxGvyMXswVRJa9ZEKi+pdoh+qKvMXWMuvixeC5oKbzH107pUlkLePrncY13CHtV5/k5Mz8ZdaUM0iO7ZZr79j4126O3SX6jKQ/2zsOxmHXR1RCQeEeJkHOEuAuAjuML1kZhlt24E6Mw5ACf9q87oZhJvn+bvvhAbE5YJmwLHQ9HAv72vgrxE476LOkC6vopPF0bxHKkU+XrhK2TKBtzS6GIe8fDF7WCfKulrERUREQyxYWu2F5Qc9j9UNhrQhCCtgpK+Ds3Obd69hJNqUpyOu7NLNkUQt0xiX2Iw7zf4UGNCosylqoxIylvAx/MYlV9lqwJUUVTwyNSVT61XQMoYAKXZb+Z52mwbkVQqj6beMa1+UOslPauZfmZbrX3wq45DpsbHS9Tzkuh3bOupTuyzpoDJDXe3R2Cy94Qf2DSjQ8KxnhfrA4YuTXVrPqLmkWHzn+Vgm1Ke2WofmATzEp2kKiLQb3HeBG87SX02LO9/gawv4KMvjv8fwVeLj1SradfGJ4r1xD94bYfmHDqIcGBXl456fo/DLIUUAxDDq66mCBCCh7u8EQ8GGzUSLCMdRJBKB6k5vH1xdtA/8oBEJBVUAxeh4lKR8WCnmGzKv3MUVg5eRzBRfHDUOjaqAMwWRg+ei3aGR6L8ZsXVab3pJUpEGXniMAV/ggpHUK6otHDHRqi/B01G64caj5clvFvNFanhtXc9eDEzGCws+lkocLpGE3LyNfI/hm9CgqnZM+KTagY16oXdmY0ufcD7Mcl7tTbnK9RBy4UVQn8N+tBbWtjkqyk3kvFwf3lKXUCJoWXomw8JE7sTgScHXjVgfo= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31671c10-89f0-4cf0-9aa0-08d99601e164 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:27.3880 (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: 7Yc5/Kq3VX5pBNN6rJGzdpapYfXz/eKWTjU0LDnli0oBC97fWEngIM5QESbsCkf2xZLqQ1M4nXyY3vIw/p3yqA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 48ce616432..3c3d1fa0ec 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, "imsic,num-ids", + VIRT_IRQCHIP_NUM_MSIS); + qemu_fdt_setprop_cells(mc->fdt, imsic_name, "imsic,ipi-range", + VIRT_IRQCHIP_BASE_IPI, VIRT_IRQCHIP_NUM_IPIS); + if (riscv_socket_count(mc) > 1) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "imsic,hart-index-bits", + imsic_num_bits(imsic_max_hart_per_socket)); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "imsic,group-index-bits", + imsic_num_bits(riscv_socket_count(mc))); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "imsic,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, "imsic,num-ids", + VIRT_IRQCHIP_NUM_MSIS); + qemu_fdt_setprop_cells(mc->fdt, imsic_name, "imsic,ipi-range", + VIRT_IRQCHIP_BASE_IPI, VIRT_IRQCHIP_NUM_IPIS); + if (imsic_guest_bits) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "imsic,guest-index-bits", + imsic_guest_bits); + } + if (riscv_socket_count(mc) > 1) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "imsic,hart-index-bits", + imsic_num_bits(imsic_max_hart_per_socket)); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "imsic,group-index-bits", + imsic_num_bits(riscv_socket_count(mc))); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "imsic,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, "aplic,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, "aplic,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 Sat Oct 23 08:46:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1545171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=jgdSq2BK; dkim=pass (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=aeCnCVHa; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbwHr1Z57z9sSf for ; Sat, 23 Oct 2021 20:03:52 +1100 (AEDT) Received: from localhost ([::1]:55982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meCwP-0004PG-VZ for incoming@patchwork.ozlabs.org; Sat, 23 Oct 2021 05:03:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChg-0003et-Lc; Sat, 23 Oct 2021 04:48:36 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:22465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meChe-0007M3-1c; Sat, 23 Oct 2021 04:48: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=1634978913; x=1666514913; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=HTYIOb6C2qHs7esQRqgXBd67VP3nWWSgi2maOSH4iPI=; b=jgdSq2BKtHasYrSdOqT55aDASMP8XIEGOyf52Kfnwd+gmwbq9OeDoQ5/ n9x5wmDi6RxW7TbxoAoaSASwklL5AkfRlBGNE12ex2QtdqAerUbY5qh0w 1Ws16NJXojT8CLzYnj1RIq6+XOtorMLcULBd8SLDU8GFBrKj/lLWIp5BV M4xu5lOV3d2/gmXX32ksp6E+7pSNFoUnHzX/Sol4Kd9nsIj9pkJGBrCO2 ZEPIB4tP1EVru6AICA3Q55nFRyOeHCk28cmUrwfaJenmH1uwk/Om7K23c ZrZ1YFYm0go6K6NLSkCx+dXDt35ESw3ugERYkWbWQF5tgcKXvYGffJyLP w==; X-IronPort-AV: E=Sophos;i="5.87,175,1631548800"; d="scan'208";a="188437393" Received: from mail-dm6nam10lp2103.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) ([104.47.58.103]) by ob1.hgst.iphmx.com with ESMTP; 23 Oct 2021 16:48:31 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Eo96c+DA94Fj5pUQTJ5FyH6svz9RcQ788HHpARYtBiXWqTEWm5yfR3M9CXHKohsnJPIoSjzyVQysMFAskteRJOgPaElRN2VirD0xEKqlbUEi+YpjdCxLe4poR+kv4qlkwow/QBsqGKOqx5RoHP0pAfXOqG/0LWeJKEJMtqYRbRXZ3ouxfxjr5sUFsqKlObi/LcVZd38dfxtdfuppQh9+sPkxHzIKK6edfrHzld5U0Hi9FKskUdo5IGg28LHUQnKOelvIpAmSJ1HEFEQIA9Eb4V4kZUFJ7daiBzObpzPYboU60i3oJNhqF+y+DEKqp3gOYLgVOBnFIpeVCT7jLN8M0A== 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=iVcjAzOJ5IiVA35pql0DAAZueeF6HKC4cJHPoh0UbVpHlpqFP3isPoQDGIkAhL0AwLLjjdXtGGtvLy/BTIjsoqhK7RTmAWJ/BngoZUQ3Y7pa3nflZup3QXP/T2caU2YuzR0FfSZ986AqSgKFIn26lTLfHm2sA3HgbP0aElU2QyEEc60ibXBA0s/pI/ws+YC46V+qtpICZ+miiXLQA6U5qxrgQo8efsqdBE+ZHXhiNwa86BdlF3n+N+fdhA/gZ5MuFX7gE+B6UDljfG4Fo+UQUZ74bBUZ5LxwQc/UjE47DkAH61qE5MySqDKH1K2CbmflRYY8n3sYcRdR5m4HkMmXNQ== 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=aeCnCVHa97G05wkozQEIfTC4FFepckZifigxcpuHcnNqZpLI7unbBLj8CBG7y1TMnAmDQiXMQOvTfkQupGUPKZ56XDWRyaF/VtM2lyMxBlZ1UPkgJLr1O07SM6eNuYgbD++d+HDea/zi+MXfy3KpgAclvdagrqO/oHyUA5/jgpo= 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 CO6PR04MB8409.namprd04.prod.outlook.com (2603:10b6:303:140::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15; Sat, 23 Oct 2021 08:48: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.020; Sat, 23 Oct 2021 08:48:30 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v3 22/22] docs/system: riscv: Document AIA options for virt machine Date: Sat, 23 Oct 2021 14:16:38 +0530 Message-Id: <20211023084638.1697057-23-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023084638.1697057-1-anup.patel@wdc.com> References: <20211023084638.1697057-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.179.82.21) by MA1PR01CA0111.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 08:48:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f01bebac-0b99-495f-f7cb-08d99601e36f X-MS-TrafficTypeDiagnostic: CO6PR04MB8409: 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: VmZqewpIl9vXSobVQjqp/IRHVVxdWOIKLOISNF77Bp94fyDag2q7SOnPEdsaxh8vraGqjY5nTQej5mPb09DUGhkWuxfpy/S5LGf/gOsABRdhXIWOwCTaFmNfKcx9+VSiLE4ioZQ+Xi6xP2bR75datLZWm5RT7DvaPyi5AqfBP3v2CULSHEIQS4RVU+2STcWB3w1wpQUXkQsZeZd0WvmbuN1EK2QUEMLKSCdGTTHpe1Pd9zDbQdRj3UL5ZWYaKx0wHV6i+3N1NH40xXBocs9HlCqNkTUakaAKKBJL1Arybjrqq/Qp5BmfxU/NRhKvqsEbC2J9q+oI6KesAosAxAr/qV3QHoRJXU1HWlsAthWBEonQ4VQgOU3TBrOkR1Rlf5gkOcgWNwJk2g7cRqq0qJL4sbK+UWPVNHjE/s3Z+2jDPfx2jf05qasvpEAOLn1ZGdTwznggs4Uq0UvHtJAjchaVfq7fCNewBWyoSMosAOihsz71UxeW4CZevRDTp0NqeZgQs+xjDTe5l55K1gvl8hr4SPh3+UosZLPXMHBB+9mrXYrAhVYXQNuY+pBW6FAKnzgZe0p0GtpMbnUn15FEw1eZPDorIyotBY90EKuGkV2b40G7zPnQSxT4D+eS5ufu2F0tKcO6jpsXkPTqPuDR2WmYgToGLfRgy4gIO12sY+dZmA0lGTY9s+URrbf5gIw0KrJVnaEyHRFHaIRB+53FIA6Owg== 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)(86362001)(8936002)(1076003)(66556008)(83380400001)(44832011)(186003)(6666004)(66476007)(2616005)(8886007)(316002)(66946007)(36756003)(4326008)(26005)(110136005)(54906003)(38100700002)(55016002)(8676002)(956004)(7696005)(52116002)(38350700002)(508600001)(2906002)(5660300002)(82960400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6sOFJn3xiavxDNXTdrZuJiuf9n0kk1XUDrI41h+dqpPPAGAl+uc7L/quQzxhgdrxgMrGeMe/C+m8fzKVqy73NDn4SSTArhAclx58JZ/6tbLBOLs62KHEE7wFkIcWGLj5kMbD9trlRx1ej26sPR9yU0pKcR49q+wYgSh8FeaZ/P+BQnkEXzK0QWAZhgcp4ofL/P/SdnvgSsv80IitvC6bS6dxSwPkxrt4ainorwg6UlkztEU5qcEiQ5wtLiYPrtE8Fve7bXusKW0m0pqgHifsOfhH+6Kw+TViJdPTDSdwMWxjaJcbi9XTbL6fPWN8G/OGE0Gvsa+xXTAZa6wnbiaTqI/t+Ye6CHmwsDFM/WEmtykvLV/qU+EGjcwOYi4iWPJ7kW29enCRc+WZKiYhDBXHVim8y7uZHohFUf5be9Sk9G0Jc6seNx+IM06d3s1tTBaPw2aaDFGkghXUHXd9ofZhv7+4WHqecgXsgRCOZtjOK97oBTBBw59CohOC6u/oJ4OG7xiWMSZDKdHrZU8i1mvQHzmkREvE1xMzh/Xa5ubNX6fNym+yfAEXSbK5Q/sMPY1apbRhTZ3tFBJ1AmOTnUf39NKwnkTQLQIThz6pWf29ht4EWmu6d1igqQJ7TvcSbBGZCuHyhpuCgdYIhpabE8FGcjXMfbrmMfN15UxZPPsb3hb4693EcYim/Rs3SCXGaTIvKbRnXVXQuevJWEE8KneNxSRNEhG/aZI5jbSDp9onKzUyiiyD69kK4VGu7PyWcFqHrlnMRbZurUCLyewPHbmpPKyfrFaNhqJPxbrpJce5lmFBdb5BiELGVDFtZ9THh768PxHRYirrOsMe7zmZe0YVHW60ICD9kusP+ueATGtrG8tcOxAIAFBoFrxY3h7GDikd0kQnzh/fGXp3nwBPQmsgPYneIkrlwnoLKUAuC0Gmtk2xSLqTEquK5spUwU4kroyct/utJUceMrrZajWuVbejJyNZRn/R3ivPqq1ich3+bZ+jU/MuP/VBt6D36USEU2B1fsOUgS08rNZcs62y33oxDJ4pnqnZO1nsqT+EAMEwjD+Bf1d//e8px9YLVJld4LpMsrBPDtPZFbveilbXurc8n6+TMq0XhzuAq+QQKlbKJOslzTk2+N0oxpIz3dumOxAbGxGO30AyiRhlzpQUzQO1eP6A6sUVGuYutxmvsnl8+tF/heJ7+evdx+qItSzrJMiHGWNM5jasB/SwdP10yrlW4KX7f8xreQv9EPd670giwo7t7QXxVx1UZO29dngd87Tl3E9LHexQMhJF0lOtCSRF9WjgjgRXPZZjYiIEueWoiFrVZQojc9wTf3YIj6EMR7P3TrjZZnDweBWbJfnvXXDskBblcX95DUZokP/qBb13hF4NcOzOqb4qRPZx1EGjva8m4QTtCUQNi19VpFMOV93eHPsw9QO9X27wpxq7S07exSPJ4oJ/7UMbDJUymxCs2Ea8iHdq6wQIMQRkgkkcPO5QmF9QsMD120C5DiQVXzGICMH7YPtcduHSjFPi1LdtIe2//pejA6AAqNGiL2lWjI08WF48kG6TOe+gqMlrGGng7Hxe/Ky1bm9rBSm6wp/So7sIo3lZGBkCeo1NF+x3qT/P/WgQSNJsBTjL+sv6/Q+c6e4= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: f01bebac-0b99-495f-f7cb-08d99601e36f X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 08:48:30.5939 (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: 6qxp+zTh68j6ZPR3cGhPXcW+FfxFLsX1XEEQ+v84cIYSQNvKq3PFrlU32yLmVCN5ZweZa58F2FzcPhqvOmw4nA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB8409 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=92346df24=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+incoming=patchwork.ozlabs.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 --------------------