From patchwork Sat Dec 11 04:18:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 1E51CC433F5 for ; Sat, 11 Dec 2021 04:21:35 +0000 (UTC) Received: from localhost ([::1]:57252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtt6-0006eH-Qb for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:21:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrh-0003qe-92; Fri, 10 Dec 2021 23:20:05 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:50812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtre-0001Y5-57; Fri, 10 Dec 2021 23:20:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196402; x=1670732402; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=0DykbVMGDmQXMjlMl/xXQF8Z496TJTBmILAKOLJ2BEM=; b=lUqq2h9PNnaj4FrhWP2QExHJLsZsMJEKW4F1gxXX9Q3FSN5nycmsvLXW 2Qlbde34XfSFhDwR3IjoNfFSqUK/ZnqyYiSZjSjUYM8TqZJWSNMzcxuST wOQt/FcIeyTocuQVozpdRUeTqaqbFpNoDHp8UAGkXt0Qx2Z5otnoh8fNg 7iREgg7FAA7J92i3mjmJ78RM5wzxP95mEVCLzxUnMteHbYO8SvptY/V5w dd3Ty9SEGxfoQqjuKaPQD8UMmzkOQSerk1dby1tyAv3JH9Ppe3m4aqlX6 zAVc7rw9xzaOzqEm1VBQCnLHpQm/QeJj4Ojz2AcxJHvdgUNqVFQ+K55n2 Q==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="186970358" Received: from mail-bn7nam10lp2106.outbound.protection.outlook.com (HELO NAM10-BN7-obe.outbound.protection.outlook.com) ([104.47.70.106]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:19:58 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QkfRpotqtacIkMUzTKjUXiHowA4/GamrtGOA5MYTIxMKQynmJfflxcgmzrCRuEsMiCg5KB2u4+BN47qBsabZr3DFfujEF8CFKoPn4wn1AMHCKmHxFVmbdCNbOlTzUOIArYt9Qmo8Zr5NlCO/EVoKJv8pccg0zJQhL6nm2/CCWqfEKH9ZZpSO9atsk90TeAOsjOcMV8iXQm0LLg/wDt1WIKHHIiptrZWBlmRJpQ1mkBTQi5FlIVVcOpabHshwcFyoDIo2UrmQHkN/8QxcSVW/BjRVEhWP0YyrkHMFtiKxYg8y21/FcTE3UbteCKF5fAdKskpRlgW3VajDeCBj6450oA== 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=P5leADCzlzQIucpedF2hgyHTqRLOBubJ1FpN4u3xkoo=; b=fb0hwSDoYF8XH6HOSgMzICXUKE1Vycq0EjZqq/Sofb8sKZgAYivxQsUr6T56ZJ7BLKXZyLje6ggHqeEs8YTDKSxHB5GinBPCFXYR9CKmc0EAHRDAFpos+FcwJ6lT9IkKiHkMbMnkVJ9UUS9u9e6SdCTqqw5M+joGSUcFU4x+pqYxfwm/z1VdBQKZsWqFedU1iheOGQf5Q46XLVYY7ZWEe3TlbtAGUssOLQAHCJX+tvXF+XU02W2Oq8F8zpUGK6vuhhi106JHesIgpW9XMeonyqqVPcLqjCsQ7j0++hA9mv1DCFNCmbojfVXUKzIE1grB5x8ZwJnDYMFtO5yAFPCo4A== 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=P5leADCzlzQIucpedF2hgyHTqRLOBubJ1FpN4u3xkoo=; b=TpGV0+uvZtqHbm285dLZpUQ1wnhblu0TkndPSIfzKR3gI0UUkYKRnwofkBnVi4BrIXDg29y45mrwRJlf1RTlKI44c12wzB5d6/+HYiepRzecF1oGZi6graUEJ8v5pLrxb39XwT6EwmmnV356VTQucx6lH4yHFT1XC0ceC3YHUEI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8265.namprd04.prod.outlook.com (2603:10b6:303:150::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Sat, 11 Dec 2021 04:19:58 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:19:58 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 01/23] target/riscv: Fix trap cause for RV32 HS-mode CSR access from RV64 HS-mode Date: Sat, 11 Dec 2021 09:48:55 +0530 Message-Id: <20211211041917.135345-2-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b11c1caa-065c-4ef9-0327-08d9bc5d7d92 X-MS-TrafficTypeDiagnostic: CO1PR04MB8265:EE_ 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: w1jfQ07z3e5Bjk1Un05lYYo0ceWTZZfLixyR70BT/5jbffcaAO2AO9x6u7FfT6VqAIneJjpL8Tx4aVyNUtJiarLZYG4HqE6vKDlqCCAVclRXrEcPoVGxdMsOjbiLhQiq1MrOJOa6y0FjDakDe5x/oEmHrJloX7NHLnXiX5y1aDiUOTPlD18enjbB+FVSobQKSGmC95MYeZNTniKnubZsdv76uFUpxoix5AzXklhOIMwmsUKlqFzPklAXuqPyqNFD9NpVnx+ipbRWNRGUWLgb/40D1aBCSx2tuVKGpCcnymZ2XgBGKjNfd3Y6wdbSssQszDUXxym4I7XY3t0j5AV0OeolLzTkbtuEN0kJ8AXQakgisHaAEiu30DluUxUXmMiNBjoyi8dhxnnWW/iLRPbl7o11mbGQO2dnvyx9fzTGN5gmD+FYfidRWNMVr3cq/7L2UVY6BGPlOLiOS20m3+J+6pmubmVBQsM9RWiwRkaVLvigkBT4r0S8RFrBgkZ/Xzf88gEddej/7bAJNHu7C3UBZCGh9gaqK3ZOgDAbthzz7xnM+BjdKtuOXOwN05xqTcjUwHnYMcZjk6ur6ZY5SYDczCJOaI7cAILTkwcNcYkGXqL2zCcCbQNiO3C6OuCOhqjvt2ZT1VR0d6lVZZQWwHqzCXXKvdnn8xcUS+VDUzcpOKgstojxM0gzmvO66T9qDYbd1IzGOj+Lq+tW6+8JmDf8BA== 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)(54906003)(508600001)(110136005)(316002)(4744005)(82960400001)(83380400001)(6506007)(2616005)(86362001)(36756003)(186003)(52116002)(2906002)(4326008)(26005)(5660300002)(66946007)(6666004)(6512007)(66476007)(44832011)(6486002)(66556008)(8936002)(8676002)(38350700002)(38100700002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dXd5BrClfL2sg4g91RguPJaG1G2D++ZCeyw+/JSRu2DXi6+nV99fKWwwaJ7zZyfrPlrA7UVaiUDNNDdZK1mVy0l0lo4gIzbACi3AwvoJ95Ed0O0yanykD+kjQS/4dxBqF2BG2SjiY4Oycl+Q9cu6sJ8mU42WabEVxAX1oR8mOwVjsD55V27tJjhlfadQnDpXxURbSZsBnH5GWXzM8W1ikLeovCK6Q7qHq8fp9rrht7LMxAOyDesCl9kw6rttDKU+R+egqLTzVJgb84VRVgQErRlqGfi+qssSEhcFUXO/qZOwYwJaH34y9EqL9neoofIptkjvVjWgK+4IHx+8nApcfz0OF0JmgbC+aPco2TakmzvP4glQzxANkKYYYDcHZCfZ3YFVeX6zIEW7g/swaKhsRb6fVVLpU0TK1nvNZp5YkfITFZFOT2BMeYIzs1PX7+LK/8+x8DfXVyWgOEgGvWRAqPBz72WAIzbXDVU+/jrKlNSd+w0myXtlBevF9RHawX1E4Jz6TXWwOnxK5YlfahpnRUvNdCWZLpQ1pbva30bU5JP1zIbIZKWNU6Ymtgcfm4AxyBNispOppwdN8GCwKwqPlZ/P9T3upirH4ZgCbayhsl4egInHYRgovQ+PsT43QHisy+Y8zs+n6gJacdV2++w65GSdheR2p9UGtnKzOSRBw5T88fW5IaVB485fXaxKD6U9xto8wVMNNK1+eI2CzTUatWsTbIGU5Sq7hhnLdOXaCrhu6e6su33RevD73uvHKbMC2jVAZKFK6sbCvTYJ8HrJHLWimdS3V/iaCKue+eUoBzzN5G9Jl1ZLfFUbAi4pvNzngbKl2/cKB1hrPKzeA6+pgvlWqVZY3kfk9qoAcAu5f1k3LRueV79KTKPzdfPfE5VKtPlwH6kJ8pOh1JPJl3fI6u4sZn9NTD9/0pM8onWFFQW8ytS/2sWDcQ4XDt+VRY1y8BeX4NHG5NR73mw6RFTTVM8C7NZumKR6XV4N2a2Jl+tCmVOlNSCMg89v+uwNMg40ToYL1YPEQdHZJ6ARCdNqzmTkGM7j9x19Ey3/AGnuRE5LI1TBM6voyJ2EyGKzw40Tn23SapYfM1lapLRg95QVe6JI1kPsh09BnSXYIyD0OhoNoLuSKETntIplxlE91hKWdoZacMW76+MSgQVSx9IpDr+q5s7Em63yCyM2iYf1rmzlyxZyRBaussiMqJ6qcKdsvo/ScgKFP6QbQcbjFzBW3/+7lKElE++sMqXd130YleBOUP/3JfPZZJaj+VaVKe8uTzm7BRUmn34H+o7gV1PT+mNP6OdhyZAz/jS9oQGYu7u9aziUmy+onsOIFcFLIiTYDZYO7UpU7sQUzPv+hZ1aBITg/h50V5QgMIIjUKWaXC14JY/RO4HaaRb2dydSZdNP4CTwt6iLQ8tTk0Y5yuGfath63XdxZ3UcvZEn1/4cLjnBAv86VqwHqefMzz2C8alXcEoP2EWmv756b39Dx8S716BWLWWfSPg2k2IKZt/W6rX9pgY00V3EOOKoatRnr4lseA6eaXemAx13seVHiPvONMvYA1d1VWj9Ofxvm99UO8uclDOMAtEFtTvyaKS3gGGsAkniL13wA/04NBVsI3TSsXnv8EXsbC3neNr9JGm2EZg= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: b11c1caa-065c-4ef9-0327-08d9bc5d7d92 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:19:58.0899 (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: B6/G1Zu5MjFV4pjmb6RlABNfwcY0iRmWZkbjr+IkvMf9AO8n6tZx+inM0SVUBPvfRKtJNvZ8Zr/cOow3SYWbcQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8265 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=972e533d7=Anup.Patel@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We should be returning illegal instruction trap when RV64 HS-mode tries to access RV32 HS-mode CSR. Fixes: d6f20dacea51 ("target/riscv: Fix 32-bit HS mode access permissions") Signed-off-by: Anup Patel Reviewed-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/csr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 9f41954894..d170c7fd08 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 Dec 11 04:18:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 90ECCC433EF for ; Sat, 11 Dec 2021 04:23:54 +0000 (UTC) Received: from localhost ([::1]:37772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtvN-00049g-KB for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:23:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrl-0003uP-T0; Fri, 10 Dec 2021 23:20:10 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:50820) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrh-0001ZC-Jm; Fri, 10 Dec 2021 23:20:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196405; x=1670732405; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=NAVv9AOgzbZpHGJSv28sw8nxZ+5O3OCQrQmssfmKeOE=; b=mA1mDA6CP1upSafR23GcauTp/LOmp7WVKS4B8T9J9Daj24XuHpW/eXvB y2AVQ8C6j7UVeS4XwuHFBZDSDasWZJ9MBd59NfWQ7wDnw3ETRTjNcS6ny 8GbCWaWp/qSfeR6MPczDolZKWZ10StPHdMq0tAvwBDHonKc7g+k96E+U6 /pwHUWyZDlmf0xxJX6+wNzVIWeg7FrDBJQ3/J1YINUirQzp3v5y4IUZa+ q/SDz0UtP1uUWD0Yg7y5idTl3SWqzZHAbXRwsrKOhB6xYb6ZuzD0ioLhg +2z6QrWEJ+oXMh4x/+TwKW3sayrU66nssVKn17+waa0XgZil8X8jBZt3l A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="186970359" Received: from mail-bn7nam10lp2104.outbound.protection.outlook.com (HELO NAM10-BN7-obe.outbound.protection.outlook.com) ([104.47.70.104]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:02 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I4/WvPqcGTIEo9V+IHDoCJxpMQv3zdfHmbqASWln5LZdBAc5hEwbi+t2DwNsi5PyXlEoqFwK/jl+gy4hlVmX3vUYw2Fsi+toa8hrcXwWTp6smTT72kx8JQEbd/PLwXdhanqg/0jimlQnThmXOQbxPXv85mMHex3XVzdtoB6uESoKhYKrXIjpytWUjTwSAPZ9s6VveYWczF1APoy/E5DmJpNz4GZ6q9wj5TFybKb9zaHvcgEaEvrK/FefCGZuxIEQJFDY4NlNqLvdvbXYYByt6TJaqw8aTNL2imG+h/EVnO7JRQFVqjT5Ti7MdiByQvL0UQ/ZVbA6YyF0guhloij3Jw== 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=79INbsxQOMMapqgcKLEHx0iL5XgqVItO7DVAveZ0Klc=; b=PVH5seHIx2rSGA80bO5qP+TkI1jvT6wEFsDKwTm+w5EVW0jm3q7wM+6aQa1IcrrDwGIh8XZWJOocXp1r1im0lhfqGqaVbbuWItWIewborMaIJ6hbF5lpK25soVYbiqnEoiGmAUwvuy0O16aBh4e8//f1gWhZO8cfUe7xlcyl2OF0Ld7dUPzZ4erfq3LhG5SIl6Fu4QbPmrIwv+ikUAgqJM/GfpC7Ct4AkXYgu06N3kMTmgQccg+HOu6proHPkcsULyXjeTazcQedoBZkMJxhb4n08Ra0ETRDqyT7J+H2smXprfJFYICicWPaVKIBRJC5UgI4JkOVfZxNshCjyikgvw== 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=79INbsxQOMMapqgcKLEHx0iL5XgqVItO7DVAveZ0Klc=; b=eTF1xhLDEsO5SpYus9WrNA6MzNAT8EXGC4mtrmboa7kKkOBYasZmIl6wK485e0LZXix404oisT01sPYDuHt4C7ZdBBPxL1czHL4iBMF6NuQuv0ixDRzdi8LNbGtfJoh2v26fZNv5wrfyotuwEY8KE0HIstzfzPeQiC/IEIMY44Q= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8265.namprd04.prod.outlook.com (2603:10b6:303:150::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Sat, 11 Dec 2021 04:20:01 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:01 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 02/23] target/riscv: Implement SGEIP bit in hip and hie CSRs Date: Sat, 11 Dec 2021 09:48:56 +0530 Message-Id: <20211211041917.135345-3-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 518365fb-a9ac-40a1-fc0f-08d9bc5d7fc4 X-MS-TrafficTypeDiagnostic: CO1PR04MB8265:EE_ X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:229; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8rCUnNfddB12lZdKeDz5V5zwX5qmjfgXp/umqWNOC4QDJC0icHWsn0dQcnoojhbQmRsK2etiAEp7mm55wmRmAjn2278bJCcph24KPT8miHhpVokBhewWlmwn+ut8grUAlOziva4+O9oDr4N/3al4hjA2Yoyg85S8NQzE8TBULVtw2KUX4LaQfAyUAXPg4ydjK2dB+B/ASH822+xtRAaVV98+3fwRYSOsWQjrGfDlynzcuqUuL4Ame/gNR51XMivxFjcRgJ7PxDaGyBhfoq9ljBHr2CK+quyT8/Etd868nAWZLeMLlK6DjDePQWzLudtAVe+L2zBe1bRVvsra/WyaX4UnkBt/BNj1kiFpV0XewBrTwNeJYNvWkZrmzTaLyJGzppmNMGJBG4fWlKUK04sxM+R01XXoZKnDnDMUQzNyLVYy1UrL5g2nbkNzzJvuYIQk+UrLcm33bnpVYYx4ZSV4qTJ7brIi8YjiGp2nTUxrKQ9Llwy1ndp6oMRwgLpfTa/riwwdr1JRVy7J5AAJH28eREK2ih7FsCOQ7j+Fl+XAX4IjnEOAYjN99n/MsbnI6BBUnpYrJBXGfk+QCqtt25eQU7BTO9tyuPiRaJwsbGCuRHJ+FX5MIUIdTs1fRyUKySy90m7HB39rsBDv3GtFdemfHdgK9xPAm9YU6XIaY3Jcn6ZDlQBLcSEhdDRqHWse/MT+o/F1QcdNizI4yIV22lUu1Q== 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)(54906003)(508600001)(110136005)(316002)(82960400001)(83380400001)(6506007)(2616005)(86362001)(36756003)(186003)(52116002)(2906002)(4326008)(26005)(5660300002)(66946007)(6666004)(6512007)(66476007)(44832011)(6486002)(66556008)(8936002)(8676002)(38350700002)(38100700002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: L3UeBR143gfIb3dfweESOCtDkxj7gFFhsWx8O46FCmCFL8cVeBtWSNhWQgBvVClOvPJUyjtsFyEdLNJDILkG8kMsyR76qSqifjef9P8jatcBIEumyBPY9Abt2Y8mfb6B3SLPQpBYz6lAf0NiEYVmEIhj7KCX/P7tiAsPFGj++dRXDKtMEz1PaJIwPjfUz5J5MX8lwwACs0xJLEXnM5LYgfcE2Ge0w65PJzk60uIVOZqVJPYGALlwNeHqviyw5EbUQZ3iB/bYw3S8cxFGLlNCjd76drSkIMoKvkggGrBNn2dArcRDuJQGMb/hNeTWnGjW5VA9lopIKbmjzR3T/hWKQo82TTRvIwJYAzGVuDoQM2DhNG3WDX8Mv55Y29+e3csXpwtZ98i9ywqeCgkCn9XDnx3k5aUB7yvcK6wEMeRSmHMDh5bPfuKJ0v2gsvmB4cPcDFLEHc61qXHohDnnkG571BC2oSwNADJzuy5iZNqjvTCXQR4lR51qaKzel2M+L9VqIz4OaVVuQbfGloPdogNN2LVytJAfSo9tdAmzd1W5GdJCpuvotAc/BiQ/xwrcZXd26r4YZLwdXpnNTn0Nwbw8u9eoYMCiXCwB3OrHgogPCVKPnrG1eUJ/h1UlGS//2/YTJHffuiITlo/iViqNxMKS9TQd36S8bmrCZA7V6NNpZKzLS6RA7ND6Q9tU39ZWDoHZhMC1Q0/QV3rG03J8KW5d7raZ0Zle88Qh9cyqtAk/8DvvCgrxhv2wqdxrsGealo77WR45Cpehwofx3/LBg2Knlqzxe6AxszuvtFnifJVn8Re7Ev1lO2wJw0JA/BX/QaRMVRlSVBRUtRePSJ9qnWuAxUBalatIQ7BJdL6C84SR5DP22FqBP24S/WgMraljrpqa7V0cYzhni+qq5TvmdYPh+B7aHPOqL6YdH8EyNIN0JtXmy5cHha+6rrtPr8/4TSwjyin8eEUnB/4wVdINJTqWY36jNF5SHd4+DurzekRt1g23h9QtLun7ebgV4KBPeFMktcfC5nYP4iJJjPtuo4YRSP7+cs+Scvc6JQo5as2W3jK0j7uwRDSWU8koxnKKC1mnEU/rMrmQVjDfJHBphAntJ9mqJC6np10ducHSCv9gO+1xLNQRg2FTNsDgCMhTctLILqVnpTsDqeDwdZYDU3M1y/iyaW23QE5cRo0NHaWcldCKm6KUM8IoNcShTI7A5HPgDpaO1ApfHn5prf3YyIM1Bn7L9UgtQzmekFBoernRwuZy52u/zfMTvqlK+tqzI3qW1Wtj0vVh9uXvSLWC6/Q1oIbfWg3q1gDdFYDvkrJOM7/0sDAzRMpciSLvaR4sJieDjOPWco5s3DF9Ze61lpvmVOadgjpkoY43+3a4Svr1FcrJXWe9kkymN44kaCRiExvqDrxevP0OaS6576NlQfmEx6eP3itObyE97TFJyUNqHPLYX1F3kjnnhJzDu8UDnYMr6TCk8SVT8VmarlPfYE5RgBjdHY7bUe8OLkwc9q7SBhqB0e3PZD1016htuJYUZR+lFBF6IUVJw1bhRTMVBZW3E2EbKD/ls7giG3lFtpYVxNAiqfL/BMGdoo5hC9kQ1qBGmhX8P5Jm+QVscRMhAJzY6HBKfFXD4d2Z6lmRZAfHWKo= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 518365fb-a9ac-40a1-fc0f-08d9bc5d7fc4 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:01.3576 (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: k5XE1rF4YHbX+YVePv2PoEvjNeyQ+/acZNk4eCzpBzgFdAiE5OUI2UnlJ9j044O2d92fM31GRlC8tmVeOybRvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8265 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=972e533d7=Anup.Patel@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" A hypervisor 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 f812998123..f3b1b9a775 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -372,6 +372,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; /* mmte is supposed to have pm.current hardwired to 1 */ @@ -610,7 +611,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 9913fa9f77..c8ce77b1bb 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -524,6 +524,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 16 /* mip masks */ #define MIP_USIP (1 << IRQ_U_SOFT) @@ -538,6 +540,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 d170c7fd08..56e8d35217 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -418,12 +418,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)) | \ @@ -683,7 +684,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; } @@ -699,6 +700,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; } @@ -994,7 +998,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; } @@ -1112,7 +1116,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; } @@ -1125,7 +1129,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; } @@ -1133,14 +1137,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 Dec 11 04:18:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8F081C433F5 for ; Sat, 11 Dec 2021 04:21:54 +0000 (UTC) Received: from localhost ([::1]:58460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvttR-0007XM-Mv for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:21:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50276) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrn-0003z5-Uf; Fri, 10 Dec 2021 23:20:11 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:50812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrk-0001Y5-Ey; Fri, 10 Dec 2021 23:20:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196408; x=1670732408; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=bh0HuZeDD+bnjRnfuGWuQ7hiLk/cDCpIzlI0IJM3pDA=; b=ITiU7t/acvW1wFJSeOB1R3h9hnTCtm/u5+4/Bk88552EbYHjz7pX9uKw jQ/Ce7OvVjbw3evuwLHKhys3RRO5w5X+GF3CpTGIiUoRQDWlT3PTq3kG/ sZEq6YL3cL8m+Y+ibIMBJsjc2vS+cnd8P6v7ksQh9943ECsgMbEYDNDyt MwAU7+PA1Esr76+gqh0uNwPImaVO3RJW5fBVmK8p4XRPhCmJSXdotWKuR YNFtadfRB2MoVJZ+uvwqMvoHbzQH4jrmQ8JCk4lutIpy5EVyG3XmRWdiU t+aH0fFCfv0ND1Mo1PIBBxr+EQ+JDJSDwxgBRnXQfPVOQof1U1+Zklwo0 g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="186970373" Received: from mail-bn7nam10lp2106.outbound.protection.outlook.com (HELO NAM10-BN7-obe.outbound.protection.outlook.com) ([104.47.70.106]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:05 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V6P6kwNzWusBDzfnX/8nL5gd8ueUV2DXH2rtJNTrx16BvA7L8gg1LhMKp7vvewHOsiweiSEkoSQzhKSj3nPBjle8ssXg/JbWFKyYrFUbbIyGcaOUib1d0pwNcbq3y00k77y0Y4dWC7N6b96djiHGVAm3AF4DxgjCDn7eZoQbVSDyuY9LwkY1LywgYmSVCL89HteBxWnQQPS6kbv2yArQfV46YSzzCBxKfZqZUroWiYMEbuRfDdZvXTcc549+61CVxMFly+HhzKnNFy0uFUoiJYjtoGBmCpUe3qFkh0thpxlPed1HKZahKhCQYVEEIZ68T0qQ4wosz0A04ipgEdGlWw== 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=1XONvP6le/ci9k4M8P9M+2rQI6mS7sJ56CWHybSiUU0=; b=ALUgBU2c7NX+N9eRGl1r0fbUbkZbSNoJXFMMb5qazSdZaj8TZBUoxLfJ7Jm/LXVQoiDfkeaVxtd639Mt0ndaP0mannPCVOl/mbKgkwY5AVx71QIEKnnvlXslxizMKX6oWvsgN7F3FUXzRO2M4zIOjBWZ5Wg5afhSFidesvt/woGLfa7oKgVIvpnJCubsX4Y0LDdIX/6Dx8eC7/T1VJ5uoq/ZA3NMtbJ94r/+qLTtJ0vFUQGFnWAhBoTjtEynWfTvH9CcZhJahpwMO4par33YPq7oCLN2Ev9PIvwWO+UmsVJ/MAArU+dKpcbR9l+Rcmzimc/oRyfx5EuvdFVwUyJ1fA== 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=1XONvP6le/ci9k4M8P9M+2rQI6mS7sJ56CWHybSiUU0=; b=s5wEQtYbJmOfaG7J9XjAlBeryTLLgHjPpVTdZ97uOb6YjphviHakmKft0RFnlvwBaLU9u2YOZ74ozM4JbtqDFOu7rQmepN6juo4F4tc7OVAyLq3Tlx3hHeexomiCap1hjZLARI4GLWT8fB4sH6KDI+U8yBU87U440+0HKa/jlDI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8265.namprd04.prod.outlook.com (2603:10b6:303:150::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Sat, 11 Dec 2021 04:20:04 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:04 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 03/23] target/riscv: Implement hgeie and hgeip CSRs Date: Sat, 11 Dec 2021 09:48:57 +0530 Message-Id: <20211211041917.135345-4-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6271c4d-dbbd-4378-40e6-08d9bc5d81bb X-MS-TrafficTypeDiagnostic: CO1PR04MB8265:EE_ 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: OBV2ojZG+pzSr3NqYtHYiusIOJeIe+w3D2aI5WIdj56/BmnIWqV6T+D2rKC+MfZ+QWhLlEibvfZEkrsW/UsFWjQ+6KHQ7J2XC6z9A+JBf1B2mBJT55OUDn30R9in1gKqw14ZgEEIMDwObqwWsUxsohmup/8rx//4R37a4SUaDN1AhBho+t5OnxVn2F3kBf8lnCD0beaZOYn0qFO4yHfxeOBNV47aC/uJFda2KXT8jTB3mwQt4C0duI9oRmdQbp0SvOr0C16iJncFV8FdXssuW6FGGuuSaBqRVHLTUfK7qHsFEB39DgLBWSJiLp8s7Kkqrgb5bZ9lR/0OgnxfqlXOrOlarkL4CT7fxNxvVhY7vWZqubdhVOOaE367kfIRYl7YTngY7I7Lubx9fC/EB93pKTV3g7auexK5xq4MdcGj0HXjShB/u2fI7D/tQXd4ikd++dR1+FTBfDK8irMn9wH2jhKn41r2s1qSQfOAdX1p1H+mME4hMLUrqFRagbHx0nayzsMoPCHvTWCq45MHOxUXxDoI6K03yLazlD5XE6S7bx5nElc4KX+Kog7nvxuIfkDZ5k8BjBYSuk+xWAEts6yZvOj2ptsnA91XlB4/O98Ejggn7cCAHCvVI9POF8lV3pGvuPXM1OLCGKGWP4G4QCUbGrRdTbu4OOnxjGPO3oYZTR5M/US/6zTG0n+M/E+x7Dm6+EFF+78pULv0Y+PxGak8IQ== 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)(54906003)(508600001)(110136005)(316002)(82960400001)(83380400001)(30864003)(6506007)(2616005)(86362001)(36756003)(186003)(52116002)(2906002)(4326008)(26005)(5660300002)(66946007)(6666004)(6512007)(66476007)(44832011)(6486002)(66556008)(8936002)(8676002)(38350700002)(38100700002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: motA+K3iSAwHRRExLV5WO1U5O1K7bCj0c4Yb2iEMAoRFpqQxa9T6Sj0+3s8xtNWoBebTWtwedNzK/fMHfhkKu+RFi/OyCZiSrSgUR1peVnsAFOOkxq+zLz1wjQc+B3/7OX5jC/IrW5YU/Jcv95Mvb0nsqRBaFwFMflIGwgaRMW4NKEH74PYLUkLxRX9MlmM0aV1N5fjJeFTN+lfyRmz3nciOpWNlUIf4CPGXPWPB4jk/O8n7iU5Bh9uiGJx95klPndZkUBMf7tbirLjuWNzHC7U9v3nxCmZAyfcMDyVZxcj0JkmjVZcxPH5XIyov4JR1MAKlp7kUQGRuLTZAd2oPq54TNyw0JM0Xdo1Ox85QRpMhf/yrWJmA9RxJlsklbmyK4JaTwh/LP6/7zvctg7rVBWVBqUAetM1CZa+LNTU+hNFiZztJZ+Sc7chlU4jLHh0aQdICMPxmYhQx5VLs2hw28xt1y7X1Tk1J5yE0rqI4/T6hE9rMz2mGsXNeEod8savn2SUjmC4ki1FFLA3AAnmQHk2W/AAW105zuKVYFi0QanxSr5yO1ouFjv/EZt+oE8JqojCvXqf6zXTbVqxcAgt40aWwO019GloGjz0mG+RsRQqfixIMEb5cV5ZbrIfZbfKWWHBwEIUIh1xC37mF3mrslpZ9+7dYl3Fewy9t041bKXMfa2ZGTtIkXzJJ3vyK9l9hvkvcpdaen17HwmgJc7EbYjChoiP5fgdo3PrAYG2fQ3hV/mEIJl1ebEWBH9itmNJ/mgaiVqVydLnJa2D6cGoJp5e+ceKb13tGEgxnadcGGEXJIf31Yu95v5ZdW5A1yDZzqIY6loyRBeWQKxFMxamk6CEFatrfIbGYoz3ZU/KuSapsUsyoIibdjoNUYvF1PKt7+G6SLr1FVfkzI5ks8uPipNKK9oNpzYd4QJj5mBELQqqFyXDZaC3JB4Q0D3Rup7GtGE2quzhDCKH0zmYU2bEJzchLeIuwOchaYJMqpECvCPIE+7fgjV2eBbtI6Dl8dbOl3ZHQPeIe6Iaq1o/wreT28Jw2qu22fNNEfiDtI7PzEqTfswDiYRSxzVCY3/RqlvDMyC3jXLN+MIFd+34WzFqvXh9S0So6afzf5b6zNAR2FdkHygxW06OPBGdOW76Oky4DJu6ESGTWsoyty87A+wFmehuauszquS52b2cu7lvSyKj4JPUyjTq+Oay0ul3KyQyllz1hcajYexCOVAywhbCYygud1SDse8L23HCX27lV2ikwyrFzXPW0mJVwLI3aXOWggJtu+4k1nhUHja7X1Woa5JKdZxKeiaIexOU+/kcjVIFCepj/HoFe9+QEGIfJAIdU9HN4ZQ0eLNyGKoOJb5Ng+8cvKuN8SPGk9S0TV4cFBVQ2+mDgGi+qcUufCUzxIx5vhCr4PiMObLIXtnulyTtRkhe0z0WRVG1dnYKGEytbri7vheyqUTq8MtHPQm2SSd7Z1kMNTL3VzWbzhM07QMoQrOSu3147xQmVE0+90YK2Io/yhVVY2LWka4eG7kqX6FfygcXpc1JcA7NyjM+8CxUx5Um9XSZEzg6GZxe0VfiLPd4kLNh+C9oqUnJF+SlVNt548VJu1cpjDHBawzgQ+xKtFAQxeqEkS+G0UPN/sxAiC1E= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6271c4d-dbbd-4378-40e6-08d9bc5d81bb X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:04.5867 (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: KPN6fHq/71XNVfLZZt7tg6V9VUeVa0h3IGCwFBs2LETTSu3z6XnAJTbJcnbYF4MIi9p+I5mxrdTL1ey7h8UnmQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8265 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=972e533d7=Anup.Patel@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The hgeie and hgeip CSRs are required for emulating an external interrupt controller capable of injecting virtual external interrupt to Guest/VM running at VS-level. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 61 ++++++++++++++++++++++++++++----------- target/riscv/cpu.h | 5 ++++ target/riscv/cpu_bits.h | 1 + target/riscv/cpu_helper.c | 37 ++++++++++++++++++++++-- target/riscv/csr.c | 43 ++++++++++++++++++--------- target/riscv/machine.c | 6 ++-- 6 files changed, 118 insertions(+), 35 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index f3b1b9a775..da58a9654f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -582,23 +582,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(); } } @@ -611,7 +637,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 0760c0af93..92a276f109 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -149,6 +149,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; @@ -186,6 +187,8 @@ struct CPURISCVState { target_ulong htval; target_ulong htinst; target_ulong hgatp; + target_ulong hgeie; + target_ulong hgeip; uint64_t htimedelta; /* Virtual CSRs */ @@ -350,6 +353,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_two_stage_lookup(int mmu_idx); diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index c8ce77b1bb..0c6ef6e51c 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -526,6 +526,7 @@ typedef enum RISCVException { #define IRQ_M_EXT 11 #define IRQ_S_GEXT 12 #define IRQ_LOCAL_MAX 16 +#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 9eeed38c7e..bf28118ff5 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -140,7 +140,11 @@ static int riscv_cpu_local_irq_pending(CPURISCVState *env) target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE); target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE); - target_ulong pending = 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 pending = (env->mip | vsgein) & env->mie; target_ulong mie = env->priv < PRV_M || (env->priv == PRV_M && mstatus_mie); @@ -247,6 +251,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)) { @@ -290,9 +316,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(); @@ -300,7 +331,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 56e8d35217..e5234a1964 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -803,7 +803,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)); @@ -811,6 +811,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; } @@ -973,7 +978,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) { @@ -993,7 +998,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); } @@ -1112,7 +1117,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) { @@ -1125,7 +1130,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) { @@ -1162,15 +1167,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) { @@ -1198,11 +1215,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; } @@ -1891,10 +1908,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 ad8248ebfd..76dd0d415c 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -78,8 +78,8 @@ static bool hyper_needed(void *opaque) 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), @@ -89,6 +89,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 Dec 11 04:18:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9BBBFC433EF for ; Sat, 11 Dec 2021 04:26:52 +0000 (UTC) Received: from localhost ([::1]:46802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtyF-0001mU-9F for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:26:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrp-00045M-OR; Fri, 10 Dec 2021 23:20:13 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:50849) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtro-0001b1-0B; Fri, 10 Dec 2021 23:20:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196411; x=1670732411; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=q7HJvyM6su8e1nBdjMd/Rp/HytoK1PeFnCenN5sb88I=; b=PlAGqDcDDnYbJbkwo9AOzDhuw6ymRUmeKrmXdsWt2O3vWz9vdJs8Ozxx ewQKEGazv4kecSHvypUIR5oje+p6IlfsHk3WCk9G+BZPBtL4g674/f5+G Kh8eYP3fADE3WsscTfFleWaYrR+jeltNR5aWeKF8dqDB60R4d5dAeKveX 0RPCbPMDgAUy4z29K5+HOEnDzQctIirKfloPheL6CetF2IhWUVtNEdJ5I B4aC7ViFXDzxWL2m6F2eVAGS28mrIsM7UoZiMhbEgCs/dFLhcLxqXCJB/ 1dV13ke1or60GtAsHtx+5W/YEM3obbu12eALfWfLpT1VDTphbrffQhOXV g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="186970379" Received: from mail-bn7nam10lp2105.outbound.protection.outlook.com (HELO NAM10-BN7-obe.outbound.protection.outlook.com) ([104.47.70.105]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:08 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FtXiilEJPxZ97hHdS3O1RU958b9OpPc46rWjCaeL4B1s9U4J3bWQNjnjPMzgYESMBLKrCdwBacfmhUutvkGRILaArc9PmD9chhE8ZVGnbpmooQZJLBQS+YarVVHlGSklhRY1pVoEnxslvkHS5837e5u09euWkWs6M2VxD6AaCzv/xaSaxTtH5WjiuAxSU4SVibE9hVnJ6BEgZ2CBdzhobHSxSXDUpmVuZowi8riLxFcjyLFx/9EmgurJ1z/2JmqhTu2DlvdKUh2OCnDpUuYF6yY8s3WPs6LCE1BetPwNSeiGxdJKLZcxvZCwVHnk5sYLUeVmCkWYFL48Egulb4sRNQ== 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=xsFPLqWIZAAuJbnR2m/3maGx+2oSdXKbiTI9Qq/KBPY=; b=G9LlQlugbmgRD29hO7M2GnAP48D7h9nJkbhDmD/fUDANLJPQyYqTFtwCzWnH8zeSldifyHLL9iBjH6nI/4yGkHIDO9QIhWOUXZlczlLDVsl/a3V7sdlveFs11Fuxtn44f3q+bNj9d/+AX5ZurWGvTyOIWDMUcp2ETIaQZFKF217Sdg7RgjU4aJ1oV45niTBfUUzVe/qtjmLzS8p+PXDfD0g+ztby8R9gGVFUnM7i3W5f+f9q90mlvar1mMasn92zaUBytN2PtwKDqmRLeg0H/5+WzwQEIIgObC8iJ8lrN3QuFDar+1Oa8tJcnd5nAXyJwixnvTJR1GRz1Zgm4UE4VQ== 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=xsFPLqWIZAAuJbnR2m/3maGx+2oSdXKbiTI9Qq/KBPY=; b=G9+kng4FNf7xDtIRuRMTbQICohrzI7wqvLIKebPq4pYIOCxoUwuR8Twxvonmjj0Ebf/f8hiWmEjyrKCo2FcA9p5Lr0ac33KSJ9Ip7TV5KvILb+Lpn5j0RUZZ5a/+l+jbik7ZiCKiNWFCQxUEhPH+wQjwe9UhE3tpcnLA2L2kQxQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8265.namprd04.prod.outlook.com (2603:10b6:303:150::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Sat, 11 Dec 2021 04:20:08 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:08 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 04/23] target/riscv: Improve delivery of guest external interrupts Date: Sat, 11 Dec 2021 09:48:58 +0530 Message-Id: <20211211041917.135345-5-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a45b494c-10f3-48d6-be78-08d9bc5d83a1 X-MS-TrafficTypeDiagnostic: CO1PR04MB8265:EE_ 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: TThEDXi9faaZr6XgI7P1IJNlxTa0Juk2j43KypLJrr1h+zKeKTcNH7l5FWr+Bt2wwahIaZRVvxN05HBvhE2zQ/bFeL0s0x//CWVWvaVCTz8Z+sg62qlSfXgvBRit5MDH5Czfm3dU5P9FATf/p+HNMgIaNBqufnAf7GBFXzyIliMMnb/oS7vNE6EUE4+7aKEDzCt2D7e8Nhd5NFaG1ukmQNmoejZBFi3ZwJ5RMrjiUJk+vMWHBycfpOFnC0p5pyROMiNWyTPIADEYlxJgSlx5FVs+faw3GyfS7+dL72+NEqn/GytuusGqykbE6JB5eru/dRUjki3D4qHWMb5GbLHpp+P1YVNMswDZiFsno7bFMTe6hAIKZx5BjfhRhpeFd8muLehyo/gfwtYV5FsG6j0Vhhz0GN+Q0RDKBtDlQNijkR9zOOb/R/Ja2C9TM7662g5HLWemzBo6GNB3keYKhHZVltXfmrIdbQPXlxGW461gPhJVn19TZsV5pqD7ryYWcKPcJW/m+nwKedvYOeXHhdkX8ysMqChaKZ7YMSQhdz8Kb07YjwGmRhmma1UA88qx0dP8iEbs7Gt7io6MoRPF2S+j3IkI2zMjbzpeZShPL0ERuJCYAUGJjiatpt7Ffsy9mV5FezbGYTIM0oxqdUMqftAKLZqYmQ6+F0vOhXmv4BkpHob3p5nVk0P/dlvw+MUuTsS9owPgxWLzG8/RDKSi9VNcaA== 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)(54906003)(508600001)(110136005)(316002)(82960400001)(83380400001)(6506007)(2616005)(86362001)(36756003)(186003)(52116002)(2906002)(4326008)(26005)(5660300002)(66946007)(6666004)(6512007)(66476007)(44832011)(6486002)(66556008)(8936002)(8676002)(38350700002)(38100700002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hxTvTHrRw1pnv0ot8/lPf1+lSHu9biwrN9FphDCIcbXUWZSF7X2jRrE+b8S8m6I/cs08NAmmpOwgMLQweWaD9/Q3zcp9zjWRTeEFFtGjbQUQr2n1QHdtttGKLtmOubwLDauG/gD9SpHjZnDHGb4+tvltLAoMeZ9s23jah49oVGNAS2rkWFUXOkhXhx6PxXrrtKXAk3n8jy4W3HNKb+PJulYB/RFp/BT9ojUI0Y/cKk5wh5vdCU26lwq7w1asWUauMlSkqiFt7QDC7lTDyI/uL8WSY/+dBMZ32d1bJL3ji0T7QZDqaOPwkhnu1NUc3C9Sr/Gq8f1H545mSHBR6GNP/HkYMmV59diJQbNC0FiADlGVe6AvzuWHsuXKXOqPMOL0uNPW/DXSPn+uGfaxHi1knj54gvxYIAN9VDL+AQvXeJJxAqiuIVf0vK0+/Pmco+BVEVO8QBkV7h8JH10VzSpkej/InnkLrDAJIdTQyFiPX2qUfTR6TxFinuKT9fbeOe3S779/z6j52wJ179lgm0Npap2vlkiOuoEvvAePyHWeCyLEeKI6xSbg09O639fteSQCoLEhS9/imyX5xKqIIei9Pm8yEpVEhr4Be0E5/LNFhZxWAWT0Z0TgZx1oPkum/cx9KQA0xCF6ksx8r+DkH+jNR8O4b6w/8BbYdaMz/6JpjCsYLYr2LXQyXLHbl9Ug1uOeJAdJxbYnhym0neZDvxfPHhAp129Y9nYHOoP3uF0gVXTHWLX/Q+04TBL7cHhF0TWvm92zZ1ldSUwvK3xDeFlT78JYs2bCdn0k/z+QDv4fjJyRyRYnYeI1tK94s/XUOEOfSTXLSKgMI7qF9O0e1oEtlXsZ7jp1FQSGHdR8sqp8INKKWUI2PMzvSiKjPaQAZovA/1FqzgIwZ2iXYEv+hS1KyewNEHlSMOx/+BRBYYhRohD+uI9ROvQ2z5bt9pZZBR3TAx6uQzqVv9D8F2Yrmh/8yin1Uox2FkLEqt7wQf4+7LliDRaBSBjI78oT/8aA7m0jBvrwZM3bSQV/+kAC71qfemKPoKAqPLLvvUQhe26RPsqLaia5Rh0BR+35kIqj0lH8gD2XhtDP8VcD/eWxKAwROmu9KeXV07h6Qfo4FRGoQXeybIR7nYDz11IWidoBje6Lx3LykpG5YoMtm4z9498OVS19icqeGKFYxvrLnjuN8I6s18RDf4U//BG4PXrPoCex9WI5InbNXPIAmTRcowB3cgccg3md+hlqrJjyOFrHE+GjUs9etQeFNFsSCKc89Wd9yqtOuxS+TMQjeAUk3278FHy3Aw9GgLi5vxS1L8h9/7VJ+NXI0kmZQj4WaTv/E3YedruII/gJ+aucZrWpRRSwkKPqqAySkmTIE2zJdAHYcEcG+Sz9NVbMw3x4s/mZVEp9pcAzMOukCAAZIVf0OYL3uoL1sWa/84FUIVCnZsbCXmZO2aa3Y0JTMBjsqQPBYGrUKjkab3JHkEMz2cLTWvy17xoAW3a5Ll4Z4y7kjVbpzAx+S+dAJyl37iAyw3SYv+dyiymoGocTXQxpbmdlwwaNhkuW38Fpc5R1tZbe/wwaznvkVunSK0RQvRzwE27dz1+ABLh3t+qJWFWwGGN4kjAAoI1hslsd2+YuV0Yu12b7Mc4= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a45b494c-10f3-48d6-be78-08d9bc5d83a1 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:07.9781 (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: YyhpSrfywTwdh8y/fLWoQJSmDbhsrpCZKmed0nhXPhCDczfpiD1xu3DVqjy0gf9hK7KpcsFbVbqlpG6s733zow== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8265 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=972e533d7=Anup.Patel@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The guest external interrupts from an interrupt controller are delivered only when the Guest/VM is running (i.e. V=1). This means any guest external interrupt which is triggered while the Guest/VM is not running (i.e. V=0) will be missed on QEMU resulting in Guest with sluggish response to serial console input and other I/O events. To solve this, we check and inject interrupt after setting V=1. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu_helper.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index bf28118ff5..1fa9f0e584 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -294,6 +294,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_two_stage_lookup(int mmu_idx) From patchwork Sat Dec 11 04:18:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id ED6E5C433F5 for ; Sat, 11 Dec 2021 04:28:53 +0000 (UTC) Received: from localhost ([::1]:54994 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu0D-0007Vf-1E for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:28:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrt-0004Kr-RO; Fri, 10 Dec 2021 23:20:17 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:50855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrr-0001ba-Nc; Fri, 10 Dec 2021 23:20:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196415; x=1670732415; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=+Gme475WWzmGn+2DmsNWn2ANgiNS9dTlc3rx/RHkgpc=; b=BbnoGm9iMAv3tcEUTZ2kovKnv7kIotpqmLKNQ+Rmz9atB+yB/RgS13w3 8aYkX6HwkN3Li0jrHZfEHoCEYr9+7y+s+Y13Dt3xkKOjkTjKQbNwaVOh0 TcYnB/8BoyFHyIOzKsD26XSpvjC3yYc2qit5Pf6G2LjdmQZRFUnJfHNRT ZhJEieGSL5eGmTxrdYnmsa5msXtCTapHjQA352gnoWl09r2LRWMU27kol NBm426nCi8GyUe53TMn/xP9nYiA0ao9aVLVQDiwcGAW9KugyPmy9ZQ3Zz 3OzUS4Cql1Jk7NLIo4hhdVb58PbEY7HlKnw3hJU9npIaDWeIA8sWp51ex w==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="186970392" Received: from mail-bn7nam10lp2105.outbound.protection.outlook.com (HELO NAM10-BN7-obe.outbound.protection.outlook.com) ([104.47.70.105]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:12 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KG/buJRRVXLuHJF+nLFlQ+HV9JAGCAbxPQn2eqYXH6ZURFCGIZ13Cx+k+Rh/L72OM3N7/PJ7udykrg7inRY87qTnNzdY6js5QQYJn9JfMfW8pY6T6Eo9RsK7el19YijPeJfV7pyBZVs/KTHlgm0rurz0M1/1JlrI5M5XL32GUD1oqWCx69KmuTSmU42H5H4E9TUE+P+mIX1aAkWT81xxxSjgjKTScxN8NavBMlxojIduhb8NllTSiY9abw7UKCou9NX+71hTBJKoKajPZNiPWVHPGhxvG18I29N8ztvpCx0sNsM5b76ASv7kuHyn/hcbNKzlDT2EjxDjqKwrTaDYeA== 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=YmwzTLjkxC2PPKa/IurSF71wvNLaUY7qJTcenD20fe0=; b=KnDQOKrAMhfcbupoex4U38SI3Rj3EVLyGe1Hnmq08p7Ny6xemFk0r/+gbd3tmWKaBV3y3xpZxTGXuJVodtlxx4/BYmbI02ixUEdaBo6RIje3XdnIgZWoeVe7ud5FtUX1spvwWXEANks4OzvSY0iiCijalwhgZPj8WumV86YHrhurmltrZVl3dVE2jmj3yLZLQ5QDjkytsSA2I7sg55gZlPup+lRox0vmlIfoO2esCulgpzbCu5lwcc5uD6AP6J1wpiyfdhvY0nIW3b/jWDpxbKN455Rpg6con6FWOlUKtdZrTBOCt+J/8/WO4ZGU8/2MJ7tdgksFwoyidzcPqMvgIw== 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=YmwzTLjkxC2PPKa/IurSF71wvNLaUY7qJTcenD20fe0=; b=PxIhNvi22JwCFyqd5utrX+4yLHCl+9fN7BIvoCCIpBPYkuxWR2NonKpF3ofBFvKrMijhXwPFqx2YT09D03Csi+Y1L1x9pKAffgjgn+1yvaV/NxdLhzhWUKkavhfRVGQ4at9kiFA/BBoG6MVmnQ96TrTFOlNIeH4bKQ9ayvQI4AE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8265.namprd04.prod.outlook.com (2603:10b6:303:150::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11; Sat, 11 Dec 2021 04:20:11 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:11 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 05/23] target/riscv: Allow setting CPU feature from machine/device emulation Date: Sat, 11 Dec 2021 09:48:59 +0530 Message-Id: <20211211041917.135345-6-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 06f85a11-f0e7-4e2b-2892-08d9bc5d85cb X-MS-TrafficTypeDiagnostic: CO1PR04MB8265:EE_ 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: xZYW6P7A4veTmsxFeeBslkqDEorLH2iJBwIUMiPbL3T5QvFAPsFTzO6jLYTLTO+qn1uQH54vQgxPFsVbXC+k0ez6Rl5H7EeU4C54nIZ9A8iPqJL/xTJjZEoNJ7hrS+IKeFVF1UnNsAsm6K6bJypSIM9aTTjFgw9XTySY5FzD7w+738ulLvLQJ9+rkNKUcCNkfvC2szbiIiA86nvQ6quLDgmsJgGSAPd7GsY8GESlYoK/Qi9sZmN6z+amE2D4Wi8EKKQqyZy85QfALy6xAPr3DhqUe/BQ/b5RPGqFex35qAAQABz+PyR6dJMH0AMUDFgYOGjSOu5Yx5iIecH/racTyodKRFD2+A/CqJM8Eh76HvCIH8mm2OUXp3N2TclqplJINPG31SB9jHmNn6uOvgKStvRkxA6r4q+FCP1Cmhhi/knJW1oOjEv0lHitYYb3/Xpdl1g865y3akjFQgX9v3nKBp9V/HLzGbK2D6xMGdCQIs+KWBKTiPyA2zbkOxS3/5BiOqfL4F699He1y511P7dZgX8WfjdmNOqcieKsFBF8+NvCoxLtLKpZBPfKJRGPTjSnVOIAEq04w+ms6lidviNFm5PDV3fGVH7L/qf+IXwhTzqIhXUy/Vg5zXYYBvPFKoMuubmsGhUHeu7FIol3FiW+NJkT6dbtoxKmOGWo9y0XZzPNn+CPlkzbdXzH0PIUZ0b9akXcB86E0Fajx9tzOdqsbA== 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)(54906003)(508600001)(110136005)(316002)(82960400001)(83380400001)(6506007)(2616005)(86362001)(36756003)(186003)(52116002)(2906002)(4326008)(26005)(5660300002)(66946007)(6666004)(6512007)(66476007)(44832011)(6486002)(66556008)(8936002)(8676002)(38350700002)(38100700002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5G7+5wDiDLzGrkz93B9pLk3hdE2P+pqJTRMyW7l6ZCbZD7fjLmjGJuA3mhm3koL1E0e5GGl5agC0FEkVXgAVfKyEN07bTgpQOcO9tzs5R8bcit0Qr+I0nXKkWcmkf0tHdR/ia4ZHVCyoLbkdWqwhcD0CkCGMBitoll1APoqr+1R12Px3u/kVpIq/i0LbBG8DSUagkFCpOG+AWpkjUZSuiditGKqiXX1CCWlnnVnFgyte5K+kLa3iOIgiJINzgZ/EObAGm/ScWygQ/arYKJGRW3RbpC6YJ/HkDOz8vhe2w05nHH8C7fHG9YVovH1P2Nj0ssHncO6rz5xwek2x+hZkpibu4FX6H4KldHqd6A1K6gADjDZC92rhvMBPAKNY/nzSGsdVsHK4FyoCSbdZfKc9ue6Mjaztg7raV+Yd0SjSMdt1SHCgbkS7d0Z05T6V+vWhDrPx9GeafbhtGN5c4N/idh57VyBREcomnLKi9WItZWo1B0Yrpa2RAFxjm1An3+W721BaNEs0SADaoPgO35DVorzrjofswi7A0vaBuViydbhFUGZDKqnxAr+qLHy2KA65pOLfsqkA8WdOehtNm881S3nAb3Pdo4suoi/6mIj4P28KbEMKcxmHj1qNu7TEJsqLQiicd74wwn0YmUIoq7edsYgg9Lt8X2kofXhdPJefit1k+GfiOpyXC5dVBmUImF2QZQB5IAqWahdQrhf8ykFgQm5HdRZXrE2+ho37hF+f8dFMuqiz5ANchhclIusCb3nEmVVgVLuJpBjkmtpnO2QkmcXJVSl1SS4oe48Btihtvu1mZst6ifSQi5gsU5Ue8L1eEDkkdd8bY8+7S1WZ/SHAioPvwWzry5OoIrhiglSVP4Sz09vKlDoYpyjDt4eWGbRKe69LRPRdYn6Lx5Hm62n6VtY1L2tPx6p1ttwGyPi6Erb7qoEcb749ygoDn+NfOZ0OpYDuHoKt/qAyJBUHyc/nkCApQC9lRpGhArDrhJ8dTkZ2noGzmzBLctigHsVYJukwrOF2dmCVg7n4geGx4+J0MUCBJQSId+qbhtLoAI+anKmxYSwWR12fdL9y+1crjrY4kKaRxWWYQzGiN7FNXRFCCFh9+4RwxBqWN7yVpzn8yAHBQXn42guaMUqIvQb6IhClM7+Yb8A7DPrSwTfua89oElk+cSSYxeSyIZ7kXchP1sbKMVrsk3cUbjAdmqgI9Ryjo2MhWUE/DrZNQO2X61S12LATZR7XEY1k8Q2nqHn3IDA4tAF+KOH4XbvA3IwBpo0DbwUt9x/7er0u/U5moFd05e6AIcdnb3eNy3PRA2RRJ1pQmR0MDVj0EtxzjHhYdf68e3x3qaS2++LY4BpiLtfdT4HYq/xcx9pX9AYEBUfp38wNB6yM9PheAQwVTz2ULKZzX/osNUHZUyyjKb6TZK4oDODAuYP7R0D1esq2tSHjo7ljDAV/haiEbqj4MMRyAwlzf+PS2FaICRTZdQmOgc9LU1PdPc7KbIufpiHK3XmZSKef1JlTyaXzrJeiCJYnn4nrJRFIRslVHZ27igPK5t/q+oo4eF6cL85nLo51AFUkH+T3L2YClwbxayzt0wYdslfssMES4T006hX+opFeZBoxeZyum0GB5Scx7RcRGVQZ8X4= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06f85a11-f0e7-4e2b-2892-08d9bc5d85cb X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:11.5424 (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: gwGE4pdpUoFG46jIdJ8kTPyu3ksfKKZKeOZ5KNtBRuRQPI6UpZtNzLlLqVZ2gL0skIsMqC0zgduriof1/iaL5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8265 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=972e533d7=Anup.Patel@wdc.com; helo=esa4.hgst.iphmx.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The machine or device emulation should be able to force set certain CPU features because: 1) We can have certain CPU features which are in-general optional but implemented by RISC-V CPUs on the machine. 2) We can have devices which require a certain CPU feature. For example, AIA IMSIC devices expect AIA CSRs implemented by RISC-V CPUs. Signed-off-by: Anup Patel Reviewed-by: Bin Meng Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 11 +++-------- target/riscv/cpu.h | 5 +++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index da58a9654f..827cff0d2b 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 @@ -434,18 +429,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 92a276f109..48637342ed 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -339,6 +339,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 Dec 11 04:19:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 986FEC433F5 for ; Sat, 11 Dec 2021 04:22:21 +0000 (UTC) Received: from localhost ([::1]:32824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtts-0000qk-Ks for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:22:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrz-0004aQ-Mf; Fri, 10 Dec 2021 23:20:23 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:55682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrw-0001dq-Jf; Fri, 10 Dec 2021 23:20:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196419; x=1670732419; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=16jcH+x8/iXJ+CRqyPvXQNuVzkC9FDU2I0fzwWm56aU=; b=Am+m5TwzxU9rOwE19IPlohDG5d4gxDT3Y6eXvamOQn3LeQkTjvHx0cNK wZOMwC1CPahgmAxsLPuYwHNc5llPVr1qagbEC+8EbxR2H3hMqq4twXI9I sm8R6rZUlRqkrC5TLbzPN/G19Q+jJ/pCAQGVl065pQA3sPFuZTV6DdFoY XlziqHd58u86dHc/Wby8Kn6UCyuwuiBTwfik8bFXZxSx3JM5g9dJYbXXK Gct9uNEmF0N485bZ6SLNJC0n5nUxaWPTXXMntL90vn7hyBn+3nqbUjy9z 24CBP9Ap1JUIW8W5rjWtHdnZE+f+qjgHvbMjMZn7B7qewUMBMTqYCfpmh g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="192773041" Received: from mail-dm6nam11lp2177.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.177]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:17 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mngmp5YqlFYTfCWG461pH+8dRKtcu2PKJ2T7StBLecTFVDS3nJ2lio2d9t/8BmIsJHWAGpbLYp/mJTNmu29k/wZx2q2ZYE12gmTGMBbFf45+bHU+CUtKOnmiTB0v0S9h57wHYTVNzBkpp7j9pDBM8+AAz9ThaX90FNr9H8DqCyHxRbgsb8FKbOl3sikn1GJSHBp5+VgZTTDBaDt8Qb+O9+sHRokeXM8E+xhmm0GfE+1H1ATfpwMAa2r1KL55JUjtTYCrComRQULeueJ3zP+ajbV9BCt2tmYdjqGzByL+71KvWNAwduX7jIhenMXk/5kUdpvhJxsbXTkpH66DgUqYmQ== 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=/ta/6CSZ8C8fueanQlAmWbHoGGdaZyqopAIgqOA/Efc=; b=GK961Kl6occiMoedpnipJCklRgtqaBGc8aRSV8o3lFD5pRQFYMfo/m+KDPiQVd1OdjWF0ZiZQgpd+bU/SHpsCDiY++eIMfPbNzabKsWHbRt0x0+btO2ni5b4pJQiRs+Gq4OmE8+ZZ5a19TRQzVsMR/+KJS1ckoItVQkUrhfMhxSxwsH415YFo9GcIQKQSsegd5oYDuJwSzIsSMQfZAsy/bTBhHmrEAdCNT1JXcvCdu0MwkU3M0qCsW91cYLYPKyfLSdda95bfd8G/iaJ8itUNirl5Ey+gsFeSr6Iu/C6a+uH1736mHCgmwI1NYNjnj6dtXkGsvNPrviZs8ETfIVKJw== 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=/ta/6CSZ8C8fueanQlAmWbHoGGdaZyqopAIgqOA/Efc=; b=oicEQK8+3ES1TSZL99+/TBuMTrYyg2Jmb5Y6puuY/q/cR9ejIXS17Zazgfv7MttmosIpBLd1uEm9/IKl/lqDEQ+0b6SLBgjvN2PCQbbT65C0PixeAIykShtCyVvaPBks+CJRvK3FquUOqUdHFK/NBc1TbFwhUsLN6BWANl+/DIY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:15 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:15 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 06/23] target/riscv: Add AIA cpu feature Date: Sat, 11 Dec 2021 09:49:00 +0530 Message-Id: <20211211041917.135345-7-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ee91a234-26b3-475d-063f-08d9bc5d87d3 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: x3B7Z+tlaSn4mG9ysagsGXtpFD/aYcJOO4iX/6qGrvDxhKI3duI89shGScWxzWgSmlyfflOnJKnl8tQ7XD02km9fw6f8NE323yOnpC0RCgyDbjm95o/JNRwGr6KyswctL5H0ZODQ4gYcoBKo7IKBI/OS+IseWyZrhh9fVH3kbYTnQh7MOzb3pOOWY8ZGsBLZ6JKyLvN1ygfMrpLICxYbulac7pAi4oab5Nn9RNpd4NnW/oC2pfaOC27lTxpfZUl3RufaDnCtdznFQmY7hiJw/Y/wSSU0N1PDv9kdrn1Fl1nt8re4DCouCGEu/L3TLJIizW3tojLFwMFs2VZVTJ5MzRtNuI7lYYtyUox21PwivnLEO6c2uxYkNZRqT5bdy9BAsEUKka20Pi8Anw0r6lc4T189vhESTM5ma6w0mZ4y0JtVIbj2D9HV9Qf00j9fMXkZdJy03b5Vr1O8Pnk64YH+q8iRdGupuYraZsCLLqzW/+v4cpw4WGSB7bkUKb94sU4HinDu0KEidYc4Lly6bA3CnIV1NJclpMgyuX9n+XNjR6mvUY/iBTZgUv//kh+hySUm9oOMF+sNZUfnRK/HZIDR5qzWd3s8d5k2s23IPpLonAgXkhvhqkQfQ0xnZs7jZzZrRFgyZo7/IjaS4RaSZ6RBJLagHklCuHBjeoT+JW6gJVFLgDGK3xr3K2mPBu1uaFnL 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4744005)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7YNF0rVdnZtzyNuNXMhvW2IwNb+Xk3k3LgdsxoF6Tf7PUnfcdXhb639nqc4FG/VirFur+ytO7tx9w0i/BWzeW5GxMVIMrnzgsdKGFwpXFZdCA/5lmoXV09T3SDDjYh+yrukuTT9irAHqvY0Q5dXxvtP5Rq8iLOcDg+4zL3fb/2B5E1HQaQcALt2n9Tjr6TrPa2bP1c4homRtXllMHLcU2McvfosofyDDtoB8IOPx27gv9R/wXrrgcRIpK7/QUrucnzzvPBfUnf95RGuNvK+gZFPM6FviA6BZtQ6ceu0hAAeOYpn6gkisodQ8/Rjpclu3DbMPYKmzGUaeY1VK9FjloAnNObd44SLj0JFfuMDH6JNA48Je7UFU1ByiD3LcnbfVExVhXSKd2s6m5h/0mZ3aWWPSYUKzk0qPWhekZVmBwc1p49rkMiFtNYrFwVM7rXdmGV7/2MY+N8L2y7jODkK8F4tKTS3ndbtM5BC6JoyG7uvmAoMCh/0dZhyjiqqyWFnuMEihOJSJ+14RfJ6If9aep7HBqMue7wEho31NhkgmeXKIejt2fZhbvQF3H5lAma3CMOuZVKBVwBfahbHi16++cd0zC8HehyraMccC3YuIW56/xR53i/L/Yql7vjlUj2HJMd0CW+npXFWIF3lH0A1REyvtCHI5jYK7FVLFPTPRT0DkbVvMklN+dB/R7WkVYxvhC93fuEJLQ2cSTOkQqvcSuI+puPpaE15u6yn4Br5EPd4gGNAEQ/CKqkS9rVgLfX5vZH9ERwnuDd2PFKwglJaBhEzrJ8K2jhNLZSbVjdHTcIE5FXIJSvwuk/lzCTU5qV8HpmlZMZBpxEJKL2BpqxR61CzJSdXiPlMs5GBwc2oBgZq4nwnYu+SVou2m1Es1IK2BdnsV2SP4Rh8dWji/pH6SVSyz6cn6vGi0s6mv5MqAD6bQFNtDX6Kv513BzoV+SRq5pxLB2eEksRsKso+unwhjvIkTu7fCX9n54JmyM/MN0WpK25MTTaqwVUFntpxq/BU7mcaaFFaboqjRXAPGH7XLk8hhD1BjGgv8S0DUXr1k+g/JHSx4gta0dF+Sn84MfLuuzAWtIAKJBOrGrBDhxbLqDluZrHh9Zov3OJDjAHEmWktzl1CLAJ1REOsJmGEC8lRNsL8+jILxxkZ2U1e0xRjzHQgajTceCkrgmnvYfZbU82bt/cJwej6FCM38v6TYmYo1E0HqIqxZs31i9srjQrnKifUMHVstzuQEf0IwGUZQrLjE2ejesuQ2v/4QCJ/5KRTw5M2bSdd5R5jqKpve/3i8+7W0gjghcB2d3zoVHK3AYhyEIeazPeoTBjG7JvzIfZD/aIuWyGYHh8FUxc4mjN+l/TsWUsPkYn1LZIKY6DVuBmcZwsOcGkd6f6Aki1oi0G6tNc3kbbNzST1DgYUfwLugeDY98eusDLBuxaPz2kYlWpjjJhzzj40xZ4SF4uTRWT4QJ1y5E2qIcXQI356+pc28FbE+ZKEUS7NhnHJ78dgKIgE00eY7envl+bBGJoFGoMoUa5dfwu0Kj0pneLN0LMqe03DSkPpKLq02KTW4KVd56oBZlhHvXKKzz3lu0ZlseXtj+TGVfEftfwk9fIi1/D7yzxko8JuBocMm6GyDgY68/1k= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee91a234-26b3-475d-063f-08d9bc5d87d3 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:15.1070 (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: DxJFLJ+o352FRXrHSDOmEA9PzgPtsqoQPpjfZ7Pwl/govNHhebYscpdsDtpTbg9FVrK+21uuwH/z0/nJGyKU2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.141; envelope-from=prvs=972e533d7=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, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We define a CPU feature for AIA CSR support in RISC-V CPUs which can be set by machine/device emulation. The RISC-V CSR emulation will also check this feature for emulating AIA CSRs. Signed-off-by: Anup Patel Reviewed-by: Bin Meng Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 48637342ed..6e5b6acd44 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -75,7 +75,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 Dec 11 04:19:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3D0C8C433F5 for ; Sat, 11 Dec 2021 04:24:07 +0000 (UTC) Received: from localhost ([::1]:38986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtva-0004xO-Bb for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:24:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50396) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvts1-0004fE-J5; Fri, 10 Dec 2021 23:20:25 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:64471) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtrz-0001eZ-0I; Fri, 10 Dec 2021 23:20:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196424; x=1670732424; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=UEdtD4EX+z39wBqXMoKWSXaSSc8Muc4cvjAZezt5/Ao=; b=r46YvMrV+w8MKbTdDeOG0arO6Yhzoi2vQ5nUUNx/tp8spmIrdMsCimHW dLnNtFJ6F+DSNndkhrumBedC3K+hRb6a6hD1cPS9Qo/uKX1rbcZ7+RWAZ kKKBz9hReZewf1+q3ZV/05juzX/+jpjZxIF5oGT74yDFDVQT8bUDn00W6 eGVxUDck+/58Ur81MR4euaWH5feT2WzYQNSx1Yv4QWegTozKtUJ1b8Ftn E8oXobRgp/dS/cYUzD0i/G9P6SjI2AK/k3qGZkLc2KeT7OnPN4MIJCVMG vgZhctdW4xRXPmlT7rLC/zFWKPLRvlFZqHGL0aSqUy40HPagr4TyUkzYi A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="188998791" 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; 11 Dec 2021 12:20:20 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iHjk9ET865npLN8zDxJqaNh1R6tQN59MH4aWz9TpfSem22cdQQ7SctHqD1RTfF1hctmS+4uKG1owWlrBfPLqZrVLrKZHPmArCR15kD/SImzhB+kB4yjGuvqOMM20q7AqQRw4ZFupMO53GqB0Q8SoHMRI6XkPdwwSuY10ARC5YqlrMZfGkoYnMRSzPB1aFhiCrMN1xHqLKjw8sgWjgZ8wh/BFZmGPAntGAkLRPJ1LaK/8PE3zhcQtNMwRbF+ytQVQ3HoMRzwe0qg471h3qui2xiG59htBmNmgBhSLfOQG2rYUVeDMokEXAA2GwHr9FJiUWE5juzYiGIqSIVR8ETBKdg== 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=wusqrzVdRlW75i3Yn+9bYWPM8G/osKnZYY8EOYeIqyo=; b=LfDhsIiHjHJwhYNtjvqs41GbydzKLuRzJo3CUjqSFB8F2OM0uMGEXvYgkcnI9xDU2BhdEVErTr47xY+Gn9H3HfvbV40U9sID1W02V5CBvdawTcB2KDi+/OVWgtyZCVkU8EmTFxlFTI2SvTFS/9dc68wkNKaCRqc0OrUNhPEAnJ76Ap2rleRKWf4/mUZRY7CHtkMIYH7GTbxxyMwwox+9byH6TML/qyscM4Vrj7pR0bhq0iheDEDjj9fn+V0nll59N6nq6O3OdqV+ziullI4c5tviiKM6WRL8M9a11ZxKULMTK0j6oblmxoprY45M5d/rmDJgaihGUVgXApwNH59ibg== 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=wusqrzVdRlW75i3Yn+9bYWPM8G/osKnZYY8EOYeIqyo=; b=XrlfDA2zOCEEtrUtycHazGyEtT62gktc6LHy47lQsf6q+ebyvVBq50PUPBacd8AHJ825LRyOYMS53y4mUTikRO/beCoT5ObytZ+QYtF5UB3x/YUce5/VNMXbp/zkQcDMNG9w4MkUfR7vX/Zv/k85VaxtuvKX3cn0ilS81IGQy+I= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:18 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:18 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 07/23] target/riscv: Add defines for AIA CSRs Date: Sat, 11 Dec 2021 09:49:01 +0530 Message-Id: <20211211041917.135345-8-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c75621f3-1894-48d7-cfe8-08d9bc5d89c7 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: 7CZZw8+efmKj57OmHIFWEpb2RgMDO0HNdIioMqzUwEPwfoP6u6O9rEhPKJNFrNlQIWBMbeWp1J8RGgWMkOFVFKsdGqtZ/9KC/5gIb1yH88YAf3EuLQQmadqXvXWcYXxvdf61TE68/Psci2Y2R/azVjzL2dJZdo5NZernaLX0C+VMqp/XnRIKHnS5Y/aRKvMpwAPGZQl/oVan3aALqo4Wl75PTwUwpW4H8BZQiK7IjWkfZTfJosa4Zm1qGLWdBt3faV1Y5BXoDqqOWXXwdl2z0n516jSSuUPksWXwp9kueinUWdCSF2jSuzSctbsfuwLS76Bxi/qSXe5ddoC77KnrsRhesIVh1p/3iFRMCGjspZB/UYfh3A0V/jrnD5dqXjWmYDHxrg3oKivmTC+Fp6HAmBAquW6BSLCZPCNJcBxfnXVjmvgB3tf2FSxzqVjZs+p/DeaGVZaxpPWUs8NY42koHDMXgcXU6NpIFu1bF6nDUf5WXxXwcXTsQ4G/tR2l5uFd+aUgRypPT70LUqhvc3tVt9qqYfpcNiDsk8t5W3iMIV2ovkxinSQhgAdHVy3CgDNbXBcWMes487SY++KEAtzzQcJ/137W7ze/v4EddEYGRPoHJMlcCGN/wsXRKAGRIJUB+XOj6LUAqRHDBBUuJspLpcETgyA+QARNHRujN7kfo2Rpw5Ta46vclG2+DQ79UKiZJjE7BnYNAqKNUBtGqT2acQ== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oYB69FSg49OuoZwcE3Ibf5IXaQmEsVnj8DxLgQ4ucCvY8vE/6RZvcfJYR9nbSyqnUpOVKZIjZ3X22/vyQ7g0u27ovA55rVkUXtEzwqYAL7QBSMzxxwrplMXr8mSrQc8mhfDY6yPeRdcDWIzLU+xJNtVOJPsOawXi6sgUWi2cId9/8K1yBRJ/XB5VQcAUPw/EVTayk/8dBjWENqPgBL2xZawR1xX3nsYnTPyI/0YqSSRZWorv6wdCTkNIhD2zoZ9p+W1RIDeQfdwb7am4FqdnPsVc3YrIlcopfY1I3p+4XGXnnrXJ9O/CvMP6DyGUkPW/hrW0aomcBOxpSa0dBoq8uhHnIS3Z6wWYVpuV+n7tCXL+fRsYFpU46TrX7jMFeTU3JViKZJMzoyGa5nH3+QT2En05GAT1nR8chZS0UK0OMwiHExywL0h0YUFcBP6PVNIz/0apLEMvM22tN2czBxpp18/+qgltq+6nODCgUDZN+TC8HD/lq9UqBtiXnOeD/jSK5IKhWRnDVCtgFk++EZdTbGXb+yRrIFI91S4QEPGlZFS5lPkw6qqzjNYSkTMQEpP2b7aO8o+nNVRird7Rk9Ger54E0NEuJSw22vqaFo3sOIQzxuRzS0NlL32hFfqlVVma9wvpOJxnuHbTm8sgfacXU7NlJ3gxS+Rp+IGjCueajwdSo9xExe6UMBnwAZizdpwu6VTQUBlbOdg9C0GTShQVHplPK7aBb82hYv8bZkqX4NK9Y8hbQ0wqgL7VKxLJfbKY43ucMr972RwFGoWNwmSqkCmQlj3ZAN4GVw3KXlifcdycJ9EI8meTiMB8yE2nKb9F6xCIr/77uWk73uAKXF84/rmXa8O/0/52S6SJh+4SjalxDpCZPvkRWPtEMClLnaXYTJaBSgV3vTsWRwHWArQwgp93ORJc2yaEwWwTS/IF/JALfbkCRhShwZsSaFGzcs2gCjf+V5ffRFHCGQzHvyaScQQiVCSExX2jzKIVbNXRcQjeLyJIbg1dYi0IVSqrPfQRHNYwXCyQ2ZNbLM1FemjA6YPdmdnFTOW2bxviIGkcV3Ia85Hrwh/no9tRpnJ1p6Deya0TW1Xgx11NoYAAAFIa+5H+vniWA/2YNaqBUAB5TsoqMv5y1TG7tPYYR631Q2ypyy3M1SdSrN+0sg3MEz7UBlUuhL8u+plD4XZm4ZPc+tqpCqm+CZgU8mncOMT8SHo1qLRXcxiQuX2FVzROEyL7F/rryHZmckxsU2zod58qIH9O4KkHRjOOs7r5sYiyvKZslUcJPizdsuoveJ2eTR4YovujL/8TRAEGsiqO+hquaRkR72wRnogsCMR56NusBCVzhjP2fw3uoEuM05VjK/Ma/4fLV5HVQpgMzKHs3XiOr25ajIvunpcvuK9K7kThHrB90zz97llT9IgN25ICE2uAerTxdI1uIGO3ulZgZX63zcG3HqclA8lNeVEj35WUO7nQo5ceAhfylqC3nT13rbeiTSaymKwj8G++seBPK27wWtLT9iv/WHW2wNB2X2L3JBd1tNhJfhLL5Q5UibTFlHKQ2ViAyePR3ls5pZwdCyEgcIsldwXziSneGm/1DYWeAOSZdeRvAYwwabeb76BFvDRP6IV3DETzTWLZcAg6U+egRb0= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: c75621f3-1894-48d7-cfe8-08d9bc5d89c7 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:18.1220 (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: nlsiTQr+Vn8VRNl7ZvEIepFXujWe9PNhV1t/GxPX07gq2NOqo+plwsLW5VxU6TN4YyX9LHB43JWuDR+Yhj2JHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.154.45; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The RISC-V AIA specification extends RISC-V local interrupts and introduces new CSRs. This patch adds defines for the new AIA CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu_bits.h | 127 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 0c6ef6e51c..5b28e73506 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 @@ -619,4 +691,59 @@ typedef enum RISCVException { #define UMTE_U_PM_INSN U_PM_INSN #define UMTE_MASK (UMTE_U_PM_ENABLE | MMTE_U_PM_CURRENT | UMTE_U_PM_INSN) +/* 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 Dec 11 04:19:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0DF15C433F5 for ; Sat, 11 Dec 2021 04:27:00 +0000 (UTC) Received: from localhost ([::1]:47490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtyN-0002LD-78 for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:26:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvts3-0004m2-AF; Fri, 10 Dec 2021 23:20:27 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26471) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvts1-0001fs-Bn; Fri, 10 Dec 2021 23:20:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196424; x=1670732424; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=w/PePLC3/UAFWVolvvp9sy9+thvI3YOBHP8eA0Zyp0c=; b=Lo/V/nt0XecrJrlHoQMN5yQNRW9FOoPyxW+ypiSrucPUFgnRzuFFE+4s rZ02DhSFSiZTGHh/QHR6eRyeaVuBRe3VARnks+apR2393ExmTxNs8hmDW kj1Y2zZsrJM9j8eWj/wxkMXred1XXbi5sf7seUkmWknA7EP5YT43hBtnw 6TkOvzH0qx2TBso0gwrNLyCACeA69fHdWIIFVXO7/6bhQf9U/uXAQAiPF scjw5DshdCw011+RyetEsT61bNtfp8nY9mx/4I9R2hXWlSs+KVMbUN5d5 W+6ukGO5j5+yFqGotcYABJyN9DrWygwlh1+9Mxlcgj2HFmNbleOvIlsHY A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989930" Received: from mail-dm6nam11lp2173.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.173]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:21 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j2/dEgLzVW6XgFV1NgsUQFdjnG2GV+Fl8JttFPk8krXI0D/EeOX6DegIM+/oUMhObAOzdlav+PyhVYZ35Vl+JJXQwt7xYuJSLk4Ini6EiGbe5kCbciDuAV6eDjVhaHGrNfYEcIcInctuVV8ywlC1B/LsBnxvOrVSGIVExg2vKqSRzdleC+D1xQX4lEpZk5U5Tei9tPrXtmn/I6Kj0uzzssOuLZ59N7PU2x9SR5dB2UA9c+VDpQ1okkmnEDf3RCiF/prZ/FH0yv9Abc+t3CjZg0F19+rbeADBzSwr8f8nkZWHUlNmyE7PuQpkwQ6TyC6E7gtyx7CyUnM0nq8AsORUEg== 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=ULCto4yQUXboBhWH4p8ZK8j5cRhfU4bPW2SOEemG3VE=; b=bZT0kXF8rD8PORiT1thqmbR1p/YwVcJVJXqSvkbkjfANBhFutGvCuM6FrmgMXGTQ/gpgCnsxkVO/NTkCVDt+MT4WnDA0FW8aViwecpny3lGNOZKFWHfdNDbMGezYNCQVonn1DH4A/crFozfKo0kqAzVTPubuJ3/OQK50iQvOgRnetNJ8iB0RUzyyLJSg0LwuJTY02571G80OR9I+Rrjm74MbIKHUfhqQrNGGU8A0pzT6H91/ckXpcs7xqe0u8ysTbUZBr5Na7mEXqf2s3rR3aq3ckZ7D8gPzw1l6TTv/C7IVyBA/kLmUzcos+vY+N67yMPCH78TId34HKhSOHi3bwg== 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=ULCto4yQUXboBhWH4p8ZK8j5cRhfU4bPW2SOEemG3VE=; b=XGIXZ5w6LhcWQXh/FJKoFZJYMd05/qvky05d2+66IZ+wGh04krc3GGNKu6JNcl9MA+NeeZlQaMLVFqWJvc8fLwFgUO8UazC7lIyV+Lre5ntxvuARDeHSLDDoK7zMNLjTAJeS9bgGB3Szf5MSyhBKIkSzhKA09oepbDMQz4R0cwE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:21 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:21 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 08/23] target/riscv: Allow AIA device emulation to set ireg rmw callback Date: Sat, 11 Dec 2021 09:49:02 +0530 Message-Id: <20211211041917.135345-9-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a4925935-eda4-459a-0398-08d9bc5d8b99 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: ZweAVPfw62fwcr4mu0Jxv7I+0hbuZwlzCjkWSOdmNUowOB03+p6KXz9EDKk47JeZthZF+5E/zHiiQviGbWs6ko3sbIR82+RyjmNmP8i1sb41a1MIp3J9QmXUHT3lUMhrz7WmG7SeY/c7kUdEd2MHNzm7dVlDKXdbkVhLWhTA34T/JweKtab8QnWG83AVJ0YiN7PwYYDwgTG5MUwdrJDsJWHM7sr1ca/TnmKmYer4T0r/wWeXx1jikCpicaljM+4aUaseAJYs9zSPeCAFn2VIFYJd+tzuBsQUsNWOLfh+eev7fOmY29ntG/qDRnYv+zWWj+Sg/LboXgzagRl8Sp9xJygOsYbzbBzsTeLqOo6asemJ0ZG4kZou1WnU2qWMucUWG6R7fZF2+A1kwbqzw70fXtra6KcdqXFs+BrBWRfILoFUH+Re9jvJcEU+rZ8SoU5l96lg2vodDN6rwReGKw2AXnFaJ/Clwum+QfeHMjdxuonEb1l2QRr2pn/w+G6CNmeuI+qbT0ruYGqmp6rBfwy/bpSod9ODhj30LocHDK87clr2vbnV8s+iLihff3hwa0yKbNtHAHpdkk0BFPS7thM/LE2qrP23V7D2DtxpzaQBm1mz9FnMAlzIZ+v+dyLXjnajGaRoHKJRlx966hGk/KJbgdBlIQlUbHg57X+d+y4e0Zi4FXD5VnIE4Easghk19UxVuZuGzmvvbB48TJaPCczJLQ== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9rBD9l95WQP4Pw2a1aVpqWguyl2uv3/Pgoo8rwOt/P3vVaM/AdM/8p3ZMhlKsabqUZuCjoSSFx4Ff3XBoQ3UZRAxuWTJIqenhoAhFDZNuJUfW2M7DIhOrWGjQd1ewAr9vbdWNJtM/Kur1ZzIp5FNtCmR4XI7DIJwRRMzfgCKD3gmGYwHgQ7gxh4zHOZwRP+4glrQQdKFSP1xMH0qNyWs8Dd6yZWgbAFaagUhrvV8ePe0b+NIKjLXS0o+ZEtjflX2cWvVHyFNTuKQJlC+Kd2jpTc8MXSWhN0YcCa921NcNydW7dWrPQVc3NAqAQ10+D5rGVA3ti2TQnSe94EfWUdSs2sOHdZMfJORJqVHTF4lWrZzkm05SKFJROqBumn0a0cq8m6e0i9gtxpgAUb1eA0cRWzhaaJJFUa2Zv2g94uCEGi4G3W7FYv94cM5sJyNygg59dai8JhAeZLKqHWKSM5gwnSe9Kg55ZUthPmdy5g4llQ607DYVS1LGFznDljD6qDEi0kJZvFMkNNzGImdTJUDosOTynAVasTHwxofIq02vOIY2z+8SGy2Xh+XyN9Q+fHs6MyiqkQ24ekEzeQl/HAoF7JaxMOON/6Jql7JLtuO7+8m00wQ1BqLptUJ67UJ6aL+ebvEL3V06aVsNu63PPQLufLxYkAPbw9vfr7dBRM3ijWhSB6uJtPz78DMz9sbWQjOq7jTuRt1d7JGgvZHt/57FC1QFjsD9Fp1JiFAZaMNWVB7Ags3Qf/x8YpMXLIxNuOsG6MKnJaiS63nHOIxse/Yi87MYO6Zaq2PjYOJGCqwEP2EcBrlDvENU1Uv77XUzDjf7JnFcxLptyvNIVhz9OMTAltvFxthLCcpsEo8IxIQ4DTyimFz/04h/dTnM7jwIayaZvYF5ltPb1ftXtDZ4ouVmcKeJ4CpdpDVn5zDXbRSsCx79C14Zr6jutknMdb0vFk48KtNLx5xyS/OwDzWSKjDMKGEl6EihT0jQbM/epup+UOKhGQNE91fiGQAIrm+i/4mh+JUaPkHTFRQOFNXgZFn1wBQDl2wd/8RVKSfdkrPH+WMjEn7gFzerCSRra1cLqmstCFmg9fkv6xhfyIy4xZkpG9ZDZaNkt7LAp5SXGAqXNbW/HCSBzBb0CSNHy+M3Ddziip8rIkwNM/NKhpYDNHJpk8Spq3AXR+iGiC5eV2SMUH2TK9GvRQ5QRQ6EJDMenasMHmUrtyyj5G6DE8QLz3JZtwTm4Kx5b+P826a8F9l2NqZgIH5OgKrj4Pi+uxv8WAcf0fnhFzIzNxNgshGEfZ2a9y6N4K2gmXiIR1YoWqr/lv+VUF2mWq1w0vb4C3zetN6Jb4bgUGYGhbGP2IEtjFNDqVpCtRIv5VxF0JtOm+WYzVxAYKUn/xadW0Ga6HhgbUs1CrOIx8LIA8ovkl/AdOE3wgmYR7o6okh5UsqMuD/018qkb3+tQHOTPYOKSj8NBilNwdtzk7Wv0QAp1PK8p4xkVBYvULLmnAPHiIYf1Lavt1NS4g9hE2ttL8O+xQ+11K2QOSJ51CPxD8UZ8x8xVUISZkKmHfkpTCM5q9rapOxjSs35GawwBfF9fo6bYvQvSIuI+Vg58QiTEILRBlNuP2yRIdHfZLN/YV/tOvVoF52IRo= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4925935-eda4-459a-0398-08d9bc5d8b99 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:21.1239 (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: GcGHaWgaOImX5vTazmaXevKN2n2I/NUQ4qDwtVEPOuWUfHpcPPS5rsJG+JEbyawEUlM6W9Sc9Rj0Awy2cgtqag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA device emulation (such as AIA IMSIC) should be able to set (or provide) AIA ireg read-modify-write callback for each privilege level of a RISC-V HART. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 23 +++++++++++++++++++++++ target/riscv/cpu_helper.c | 14 ++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 6e5b6acd44..df1d792951 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -240,6 +240,22 @@ 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, __xlen) \ + ((((__xlen) & 0xff) << 24) | \ + (((__vgein) & 0x3f) << 20) | \ + (((__virt) & 0x1) << 18) | \ + (((__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) >> 18) & 0x1) +#define AIA_IREG_VGEIN(__ireg) (((__ireg) >> 20) & 0x3f) +#define AIA_IREG_XLEN(__ireg) (((__ireg) >> 24) & 0xff) + 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; @@ -391,6 +407,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 1fa9f0e584..57c07ba1a4 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -364,6 +364,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 Dec 11 04:19:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E4319C433F5 for ; Sat, 11 Dec 2021 04:29:02 +0000 (UTC) Received: from localhost ([::1]:55628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu0L-0007xJ-RP for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:29:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvts6-0004zw-Ua; Fri, 10 Dec 2021 23:20:30 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvts4-0001gi-12; Fri, 10 Dec 2021 23:20:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196427; x=1670732427; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=3MjoCe6nmpaxlAmJOJ2UGH5e6XF9Ni/WdjG4Jy6qh1g=; b=ZjOc+oUR8ibFgqNR50wdonBVcViIoFniv0AWFrQV3s8LRpB0MyyFPE3w NcfRMHx+TsMezk+8PMBFXiEb8OQxj58AeUCtyEJh1NWgr7KamPb5EAP65 Jh827i6PSKHaD2NAidrU2lYuiqb/nB1ERixmZszxBjUhh2b0xtpNksrm5 j4oz+Dus7Dva6mleJtzq7+5c8VDqP5++aUC/TCt49eX0dgNOPSRZ+p3JN B+cwQzHlrE2nzCY1wMgZTkoV72vVgZD4m932ImLaQ3GDaVjLCnUQ8/1K2 dBOgwmwfDf9cfNmYa1NhyVBYVTRr6dKHdghUw7YqKsFDfmlbG1jv/69L5 Q==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989932" Received: from mail-dm6nam11lp2168.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.168]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:24 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lrd/EWuQ6qKHCLUbNgXL+8AKQj5pm826Vb2QYZNOhBd8EyUL0qpYFafQkUmZeYhqsHzmlk+YrxFZGzcOoYrcbtCtPoSQvrw0tSkUHipiG6QLlTqFDIXkFTtYc2CucYM3K63ZoZNOGEx12ArCcc6GmlY8J7jngBMn2zplwq5hq/aZ9lKKxGbITLYqXx1/1nyWqWxiep42KDtvPqbJqwRbadHsNRkO9y2hOa+iCU7Ac/XSZZHY9I5hqHI5VnRHykfT+j/hG1OqDxSb1oYTP4miWWSjxBfDzgRKCr1Yjkq12qFiX4FREHDIi4kmj696qTmn6fPSfk3HqO1YDOe7IsGZEA== 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=vLdA7dRrGGUg1CGXDzpntXzrADvAVNpXUAZ1XSnMwm4=; b=iWvSZObXn23391ZpIDAyk6reZNQ46WYChi0kJSMf2JtvUfsxpxYkcx9+bxmT7nw+iTFZwqToQgSPRll/oklT3TicjLLF+Zz0zz9f/Fw1gQIVZ27ek3nQSIY5xAsj9DDv5hz6PYuq0hqHBg91Ao6ec57HdesPNNFaeoDN2iLHEXVgxAkRWJmR70TXZvTGjinVMxtD9XrIYbkxPFm7Awbl698FgRLsLCs2qZt6ogHulaTJErdRYA7N7/DmAVC3iiLnn1WZnrQAuJbMGShMZsUZP7yYJ2uHxEIR2xulpz5kqCDvuzGD/0D2B0CNJGwcyVjVF5M9YUdr0kOOwL6a6TUyGw== 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=vLdA7dRrGGUg1CGXDzpntXzrADvAVNpXUAZ1XSnMwm4=; b=C+aOZcDJYyB65gIZ6Grsv+YQQ5jxJlyArQl+otVuTVpzFtvLDFyKM1EvgWR8fTifNKFeKK9X3OBE/VfNHB2uQSrFF+3aZspDCLlM0o+7DzqYE7fgnAD627L8j7s4aZ7bzXWbNpInYyJfHV4K3PGmsLeRumw6RZqJeG7/zugHXBI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:24 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:24 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 09/23] target/riscv: Implement AIA local interrupt priorities Date: Sat, 11 Dec 2021 09:49:03 +0530 Message-Id: <20211211041917.135345-10-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c9ec7b25-0450-4045-7946-08d9bc5d8d60 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: ex4pmRwc8nUIo+7X/SOBCpiQvRyPIpmA3njsnF04J1GwJwFuUA79UWJ13kuM4RPLrOo+hKmXMojkYYlS3khpnxTVv8R5sOYA+nSXuio1C0kiIbT24pURAfgXfXzhQ/SRRxamZQL5FLtpZCxnPi2Eym5vTTiQoxc3dVPpc6o0lW6lK9HD8KwZz2OnifPzX148handCwrc8mJuIK5e75NJEd5SV7MkYh8PYbL9KZUj70h5HxppFN+j4XwhXTnWLoGiiVlkTLUoeO+Lp4d/cJSu9JFmry4DT/yPKzcz1vEfQnJxGg8wXPB0Q1wmxc8DL1hO3YSlx5xmyygyfcVlveweemm3SzyPjVavYC6oo2dQC6f6bjv1loDHFPeZ/pqYYqNzgQICYL/sAR9ZGpXTokU5fAuP1CL+6xjickZbQ3NRE3HR2wqmhRbRA47NWMd4kFUGOYoYOi0l48BZDffjNrsr3ccJLT7R7s+eRQiU7qgYfg5fzEGf9hPF+FvRDkkPsVqlyKSMieMzJh8gtcC1qEmYmMlgmodPgnF2ssi4sT2q5mQNga6cRijQkCCLP0tvyNCaBHWvCCSkBu2fBmUEFFMHz5la6/s+fSNL4y2jWpnJ8bnseea+WAmQnlc5z9InY17j6pyhi/qAsW0xWBKxD8zQLisnQB70HgwXrG5oykMTKcne2aY8iqpZzJ6i49LNTmiDBlus/IS7yuC+j7SfNie5KA== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(30864003)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jICZlyFymxo587vtTAoNdrPu5d4BgB0gu9dNShhgh5fdf6PTdOsmp5R/I7MFSccnujvOsBIgQAABuLylFZRA6aUjp10AouQGodl914njKQRM2uplhkVdBjYKcnmLeBPRLtQ+kQ3ydCLs0LpEvPz5d8GMc8tXQt5iCxy5OigNvq06Lzc6pwOi06ps9ZFbK9trr4Q1N+R0p9FKvyJ4Vy/W/b5ZXzbT3gGRulaAfic47VcufrnfzbgS6aHgAdjxGK+YUXgiaVl20RLrfmXIcrkc1MZv1M1w5j55wOjKB8KYVL/B74CeB3+tvUc4DsPSn431yq7tCwIHUNcAcmnii3R42m8uNpGVElksHHkB5ECh2bY8NrT2DzxwtAcfqoTFXiTcCMagkSczJs1baEvyrx+Wa0B5yFGfvvfkGtqdNdS/OXpnsMAtUx4XU1CPZwQlfPNpBXdOBkdtQr01AYvK8bTnRadkUW+ANUU4VU3DMgNtFkzTIaJfrlq+wxK8aGN2QAfuFFCh55yuyYB0nCXYsYoDqF79iLSP6SCJ2SqL/s654J7H+nDNszGsNNjX9tWyWdEf3JeTf0G96YMz9NXZPnXagT+Vbhv+W2l3a5F4FFBltbJaYMlPShN0AWad592v5aBdc31b5RpsDHpSTrPhTwNA62JdEwilH3jLWLU7Xdx70jDlO3mcXuoTxJBnVufRaWO63y0EZD0vk8DiUJdkf8KkuMZSSSGOaG2Ucykty7C3NQ7ixTBLXZJRqCCX0YjXrgQZX4388co58wmP5bVKuqiCOTcCf3/3qBrdTGAgsaaHqiAkLZUKnT/5EM8uiR4RKkRtjelBCT84lSqmUEQjTSXdmwOjSytXX06vfgVBoMOzTP4GDYZdliPA8I1l0QhTQMu7lfZ5iJC8tspG2Q1cV8J6LapEMgQF9Dj2wwCeH5Xmos849sjQhkxTT6B0+BPwMWBsUUf4SftKjp9R0WVwQEVb6qvbShVL+clqA7uBgGUz4ga+caDIHj6XMJ+COM4i7Tf1zyZlLbvAUNwBwusZqWquebPuMRXmc4l7hyDg8ISw7v/D0ibfzUJkEY9SMc55Cpin3FahHECtKC4WruxGDiWq1AyMmeN/olr258mKKnRsR7E+PK4fk+Szn49/DDJ36xOd19PIuC6M67ANBtC0O/xwEafZ4VlD4AlqaJ/486Gn1sSLbTZ1I/yI5uqBi9JzRn7yFjMi7GwEFO5vEnKeruT9XnRs6pv1LyWnDIxt1RP9HIhmKfCY48HscnIxiNeCKkmMrhNoNPLtLGmF0scHsQI3pIL9hCvjL2cVL5//2zRlZGkO8KlOJAZ/uEM6UFjB+59mSgB1daRr8PJA4kGwkDWXZ/3b+0ydc45hBVivqsKblGuo6nhyAhWlBivyE5LwLloqn0wYADjrJEvrU8uC7LBOCMxI5nWQvgP4GwGSZk81ujt0TFEiRfe3n+fP6z/Rwy4/Sq3Un2okEC2jxz8qI6czsW2NaTXATHKY57aQXSab/BGz1FxHEz46D4N4ELIqpxUk5eRR0SqQDTMC53FyFWI5wpOPJihA4oLK7zgtxyOYnW1+e18VUKJf0Whppyd+DxFWFTvyG30HqrKwDA9EnFQt6d+jZGu+jaZWLyB+/Ayv68E= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9ec7b25-0450-4045-7946-08d9bc5d8d60 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:24.1713 (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: t5j/zk3UKK9o3PFndIVnTUYUDIWkUjbL1gPvgXl9YDplThSZ0lloPk+evcPUrJ+leCA0rSSVvTtsfhqp2DJ0jg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA spec defines programmable 8-bit priority for each local interrupt at M-level, S-level and VS-level so we extend local interrupt processing to consider AIA interrupt priorities. The AIA CSRs which help software configure local interrupt priorities will be added by subsequent patches. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 19 ++++ target/riscv/cpu.h | 12 ++ target/riscv/cpu_helper.c | 231 ++++++++++++++++++++++++++++++++++---- target/riscv/machine.c | 3 + 4 files changed, 244 insertions(+), 21 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 827cff0d2b..916319afcd 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -348,6 +348,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); @@ -370,6 +374,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++; + } /* mmte is supposed to have pm.current hardwired to 1 */ env->mmte |= (PM_EXT_INITIAL | MMTE_M_PM_CURRENT); #endif diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index df1d792951..69d9c42ad3 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -180,6 +180,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; @@ -192,6 +196,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. @@ -374,6 +381,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 57c07ba1a4..033feb3463 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -133,36 +133,225 @@ void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, } #ifndef CONFIG_USER_ONLY -static int riscv_cpu_local_irq_pending(CPURISCVState *env) + +/* + * The HS-mode is allowed to configure priority only for the + * following VS-mode local interrupts: + * + * 0 (Reserved interrupt, reads as zero) + * 1 Supervisor software interrupt + * 4 (Reserved interrupt, reads as zero) + * 5 Supervisor timer interrupt + * 8 (Reserved interrupt, reads as zero) + * 13 (Reserved interrupt) + * 14 " + * 15 " + * 16 " + * 18 Debug/trace interrupt + * 20 (Reserved interrupt) + * 22 " + * 24 " + * 26 " + * 28 " + * 30 (Reserved for standard reporting of bus or system errors) + */ + +static int hviprio_index2irq[] = + { 0, 1, 4, 5, 8, 13, 14, 15, 16, 18, 20, 22, 24, 26, 28, 30 }; +static int hviprio_index2rdzero[] = + { 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero) { - target_ulong virt_enabled = riscv_cpu_virt_enabled(env); + if (index < 0 || ARRAY_SIZE(hviprio_index2irq) <= index) { + return -EINVAL; + } + + if (out_irq) { + *out_irq = hviprio_index2irq[index]; + } - target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE); - target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE); + if (out_rdzero) { + *out_rdzero = hviprio_index2rdzero[index]; + } - target_ulong vsgemask = - (target_ulong)1 << get_field(env->hstatus, HSTATUS_VGEIN); - target_ulong vsgein = (env->hgeip & vsgemask) ? MIP_VSEIP : 0; + return 0; +} - target_ulong pending = (env->mip | vsgein) & env->mie; +uint8_t riscv_cpu_default_priority(int irq) +{ + int u, l; + uint8_t iprio = IPRIO_MMAXIPRIO; - 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 hsie = virt_enabled || sie; - target_ulong vsie = virt_enabled && sie; + if (irq < 0 || irq > 63) { + return iprio; + } - target_ulong irqs = - (pending & ~env->mideleg & -mie) | - (pending & env->mideleg & ~env->hideleg & -hsie) | - (pending & env->mideleg & env->hideleg & -vsie); + /* + * 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) + * ---------------------------------------------------------------- + */ - if (irqs) { - return ctz64(irqs); /* since non-zero */ + 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) +{ + int virq; + uint64_t irqs, pending, mie, hsie, vsie; + + /* Determine interrupt enable state of all privilege modes */ + if (riscv_cpu_virt_enabled(env)) { + mie = 1; + hsie = 1; + vsie = (env->priv < PRV_S) || + (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_SIE)); } else { - return RISCV_EXCP_NONE; /* indicates no pending interrupt */ + mie = (env->priv < PRV_M) || + (env->priv == PRV_M && get_field(env->mstatus, MSTATUS_MIE)); + hsie = (env->priv < PRV_S) || + (env->priv == PRV_S && get_field(env->mstatus, MSTATUS_SIE)); + vsie = 0; } + + /* Determine all pending interrupts */ + pending = riscv_cpu_all_pending(env); + + /* Check M-mode interrupts */ + irqs = pending & ~env->mideleg & -mie; + if (irqs) { + return riscv_cpu_pending_to_irq(env, irqs, env->miprio); + } + + /* Check HS-mode interrupts */ + irqs = pending & env->mideleg & ~env->hideleg & -hsie; + if (irqs) { + return riscv_cpu_pending_to_irq(env, irqs, env->siprio); + } + + /* Check VS-mode interrupts */ + irqs = pending & env->mideleg & env->hideleg & -vsie; + if (irqs) { + 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 76dd0d415c..cffc444969 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -92,6 +92,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), @@ -173,6 +174,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 Dec 11 04:19:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E6674C433F5 for ; Sat, 11 Dec 2021 04:27:54 +0000 (UTC) Received: from localhost ([::1]:51236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtzF-0004w6-SS for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:27:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsC-0005K4-Lv; Fri, 10 Dec 2021 23:20:36 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvts8-0001io-IR; Fri, 10 Dec 2021 23:20:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196432; x=1670732432; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=ojzk+qENhEgkfyUeBnglnjCzVeFnmug2KXqCTZ0Y7WI=; b=j/BU2vNBGG8mnNZfbGfYvh2d5eaMGfnERd2jyquCbEbblTfhHcrPf04E /4DfFI8YO1yVOGfb/cJmvPwR12Hkg9r9mDoBe+EBn4EnIijWDUXvHBySO 3jeonwqyRP7o1WB09wXzbnlKFf3lLQsB7DwiYLzEmQAUWVFr8wsbddw9X XHO8iZTMoG13vLZMQVeGv8VYaO9/QDAM9gszNhh0Fyftw5/4hLGYAdKHp WNFcGzKaWOej7m9q8+B8S8e3CjEMT/ywIyz+E05BOCc/q4UUW7zqFRqfR GVisW9tHmU5gjLlfTNeQmxaCR6f3kTD4xEjYnkitskqys1bYrpw0GWfOe g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834357" Received: from mail-dm6nam11lp2177.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.177]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:29 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffBqKoch+4lJKV69LvBqilv9DP7XktOhOmP1cX13s+5AFCusIDEGeDyfQIU6bX2Cos0fZ30J2TjJoUZjR56DxzaG7w/Lj4t4A8XG7YhPLe7hDjA5trZjPJLhdmEGj3eNqHeT6RTsEas2P2dVApPeElUCKbF4aZ81KgOew3tq5icIR27ptxxo/b5O/j9/k3kj1nwWewWZhl/pVIAx7hxF66QHWS/KOCg4cKOlsT3tskgZ+ov/89DwkOwjaWyKZcPOghBeoJxKMAZPIf6HOmxl/7mBfyOhERgGJU4WouOFpjJGZt1TVLjqVd8hQtSvc+slAgYsdTr/iwz1BMG7zWlhyA== 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=Vzo3UOPPDgIWXM2FkTKl/s9dkvjELReckMweQtVsTPA=; b=K4cRchO4X8oSS6v0FLien3e3A4cz6Pyp9YyH82il5KWmXAxtLDsaetZzHxwQWmADlr9Nj6EIoQikhLz9IavQsOXiuJ7PdgSFUCvr09nKwixSHYBfwPYFgQIMWyZgomQ1ky5P82666O24GT4gRkIvQwAYUIQgWsRieJMXiNUT4fR5fPlpJ+IzR0wzEnnLLmsFP2D9W3RgooGbZsVEpr+4RJEDMw83fcUkwHuolUtPw1vYy7IgloXGdF6mMv9DPUYcekEdPGYnM3KdMBEtvTNvpqEmTqfgCEcTjgjWGlhlTPQx09ZebeunqSe3K7+4yaY1ca2smLSLkb8MfXbWhyuO+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=Vzo3UOPPDgIWXM2FkTKl/s9dkvjELReckMweQtVsTPA=; b=yw9CdNpefQy/n24CoXZLhZ2eBP7mZljGd05p3u7CRNqXSo7fLv3W795oCAPcJ7Pyaw16Msl2xtYkhdfhCfewIThp1M6FhvdanOyIpY5d+G1YZzVn5YY/QopPHdCncO9k6hTWbubeNKTKX4hOmXpqdn7BGBqzNWtbDANkPt8FPqU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:27 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:27 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 10/23] target/riscv: Implement AIA CSRs for 64 local interrupts on RV32 Date: Sat, 11 Dec 2021 09:49:04 +0530 Message-Id: <20211211041917.135345-11-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 87dfba4f-7543-45b2-8c83-08d9bc5d8f63 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: JMG3AuDcfokCSVLFAcqPudveBXr087GbZFs8GhkZxgSYrtfSdCn9M88CHlUko97ULzwSybWEn5INRRuln6gBxuKmoKhhEuStbVoy+HFw/feeRsMenKv84ds3NBhWb721UpEXVx3NpuYSwAio9PR6joZoHvGUQtCzwLotTtqkNF3NJc9c4/zPQ3ZxylvUlzAy8C/bMOYjv2MCHsV+U3Rwvgdann5KNaOMqPttF1zvM6lMa/Om5IzqvD0RBls/zRzHwH+e0v40bEtBO3AFZhbr5tB06yEJzXBBGp0AsMwhyqmcjiT0tFS4aBj0uv6MBmPWSF2V+FbNfj5w4lSc9VuykjP058MwUrbqqs5zBjIDedcnzhfcVmrUost+xZH/lSOMjNZtpofZX/zY70lfkiNVmTlXlrB/HDV7pZ2a8ZSPoHt7apT0vyDmmrgq1a8d/QFtwAPaOw1V5VhJhuz/IDikfukQGKMtOq8k7veYuUVKVwUgxXTnJX8wpkFkV+QU3nL5vYGPshFf3kPtFGf4HIWmIjipHfmq+ei/tXzt3rduk9e30yAd9xH2KIb/3oxnD6MlMQ4zMAlx9akz0KMHatGH4NHcGRLRNy2hWz1FR8UjJ32QCxEyZEdyXcWeso9/eJlTt/ahnmgUP2CfgRr9QtSSfB3bAQQcDwX2ccWGE8h/t1q8+ATQyqA1NiSqrMn3WCTnhCclSz7huYHKxiO935YEEw== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(30864003)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kPGZcqPRH0CK7AV2l7oyVgMAknsLZZdFsx6PSMS91gtTpMNMegUa6ciZJRlQl9QfvrN7XBDTw4HdYHCgIj0RFx2UIzOnuFb3unu2UZFHJdyBGjjV5GWtBGcRpmThNpN4CZL8S3Ae/DBRVAbwjgqqjKZ8GG29Ngh1aJLzMTlUkNfKwLqbgA6jnuQ0XacG35E6Wfed1h6c9vxB4jWLfBbzzxlqwniGOvJpy9hLY8bi0/GR0niJUNN7PIN7McHL1fONRk3Fu0lGceXxSu0Dce35xyMSoDw7OUKYXHDr1Vzvv5/9WrDP1pj0Hg4Sk0f9dEDKIKoVhRFvc5iR2yjeKCz5iTOiEaGS3fJ1ulM4WCg2bWeL+3twpJ/nsryTnD0jsgum1K29hgkTA+7uW+TkkIA4rHmEB0C6x4KFodoCmtBSjPeLAuDSGoL309Gey94NszzzyFtCZ+gTT8q2MJV40PADYIwZqSAMfa5MCMPWLfbPLH6PsvZ6Gqgqvlw46YpvXBNAQT5Omv+onmq0sZlI9i/IjzPoD93Q0aVozkUi3raR5mnrL8iQv7joTixYAN5PW7tmOL1dEolR5YhTvEr0gINoGNPkPypu0p9MdYE0/xXh9AeLYQLSr5e9RTq8M0yyKx0sYcOir/9NnfqYCJ0uoQi/1g+8BO3Zs4FIrjMgrpwyREXZw04vGg+7xfaM5RTXhiDyvEEldAdARzHjPxrI0qJx4Nj1V43SMC7UaB1aVIeNjkA9aki6nvvblJf+o4wK7zFlfiAqZCFqFl30QKS2mvqu3QfpqmUg31G+C5sZ9au+/7TgS75DDs76BFngHf5GDSFX+RMz3ELpoRmoIsATbdCwFbNlpk97oJKke++k4rbnqpK/Mo6pGPUb1mzgBadSynL+4fpS26Q1SYc37nMZ+nvT7MRHzM3EpyCdHZSZhkiDP9wFGG+b3tt6qe3+e0riY5CIePBb9J2bWr5Gh3IKpU8H6tCi5VNtSarpWhNQ00ipyIiXauPyNoW/I5iBS010QVoIoA8Y8p+Wm6NWvnO2nVnfagZu1inhRjwhawwX35yi0LP9p/P2+gowh5QkcrKmc1HVGIXgAMDPDXOOJVyEDZz91ycD55gyHui8faZNxshdpM/YpKrOPB8wl1Eet+/f6fV29dAxF24hk5vKpbjme1yzf29u3OtXkTUEzw6keTmlKCTZVJMG4ePO4sEbrFBBqsxwkA8Ktc7lPyt0IUYUFxgGl019PMjCgNi0u0obhcrI/ScsoX+VngSteoRUVSRi+Ierx6kgksikVsUIRdpZpJ4L21+lrWEVFcfsWqayhJatSgyM2SePJFGEXIQ/36ipFo53KUSQZDehZGBp/XJF7wUxjfCM8AZ6BxsNvFZSGV7tePFhlqYgPGFyq+BgCg8/MgUp+jfMpnTe5H/GRiDLRssEqPLxzwVrq4d31r8ma1yQy/uON1WVZrbPPVUAkMdCmftOkapZXM5vh3SKOcqDr4u0pqVfF0GEGSqVXRfzZiwKc1kuiAkKGIHzhDbOSmi9t06a0IWoxVj7bwawhrKmMSVcfsn5JbZHzkQJqPVafnQP47fERmx5WH+iLZ/EeisRoVp+MN3wUtmlAlWPp525dQ2TGVvewRTu+2PfaewPcuFggi0= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87dfba4f-7543-45b2-8c83-08d9bc5d8f63 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:27.6718 (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: Nlm4G/cus1al7SARdKZt3x4Y8fa0lUivCdVPxUisore3/ayPwfXmFFuArAPjp2xmQ8dEBY8s1b3/BegDpwZNbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification adds new CSRs for RV32 so that RISC-V hart can support 64 local interrupts on both RV32 and RV64. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- 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 69d9c42ad3..8b14fac9a9 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -160,12 +160,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; @@ -187,7 +187,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; @@ -414,8 +414,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 033feb3463..e387e9b1e1 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -503,7 +503,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) { @@ -514,11 +514,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)) { @@ -1221,7 +1221,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; @@ -1286,7 +1286,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 e5234a1964..d9bb5ff649 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) && @@ -202,6 +229,15 @@ static RISCVException pointer_masking(CPURISCVState *env, int csrno) return RISCV_EXCP_ILLEGAL_INST; } +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)) { @@ -415,15 +451,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)) | \ @@ -672,40 +708,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) { @@ -796,17 +899,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; } @@ -816,13 +919,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) @@ -842,45 +976,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, @@ -973,38 +1174,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_VSIP, 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; } @@ -1099,30 +1373,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; } @@ -1139,18 +1477,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, @@ -1870,9 +2209,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 }, @@ -1885,9 +2224,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 }, @@ -1901,12 +2245,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 }, @@ -1918,7 +2266,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 }, @@ -1929,6 +2277,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 cffc444969..44dca84ded 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -84,7 +84,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), @@ -194,10 +194,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 Dec 11 04:19:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D9A0BC433EF for ; Sat, 11 Dec 2021 04:24:45 +0000 (UTC) Received: from localhost ([::1]:42578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtwC-0007N6-Tv for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:24:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsC-0005KM-UX; Fri, 10 Dec 2021 23:20:36 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25426) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsA-0001jP-Kz; Fri, 10 Dec 2021 23:20:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196434; x=1670732434; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=24EAMZxpMI6FmsUZDTP9hMEtQYI4pjAkDb7oRtKs0B8=; b=ciWZnM6RUVNk6sqWwjnUqElt4cqsQKdybIKmf38hWV1QNy/a9Rttduno RVSLkkCRjiWtaG9MrxxTjTEhfcvuLrW6fMJNM96h6a0sIHJrPPQVzMias hOZcH7sOsQhk9uAu2pBsRO2tPXzO4ws0JKx3tOc+Mf162PF60hFNv6OrV Hb/daBXW3XuOX0UEPDze2p4+S0Kq48vCbVIAumNFjlWewXwLhn0HvBtpI e2ga9ZdPEyQuYyz9XoLfN7aHtzNdBtbtj1pFF1j1yVHrlDNV485KMfmjd Dd+9SxDuHMEGbHt+gQymxF39vZ0+yySQc/BIYUuKaeQh/UL49W7oxJv5h g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834358" Received: from mail-dm6nam11lp2168.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.168]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:20:31 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JCbbR5E5PDlhuEilXyNaPQdxvqjrxa3FqAxA+KAKD4qV/YgCzVLePW7+9eDbaVr1nAlNHbw7v+alGsKvKypJJF5PD1wQ6AAG12bWEWxkZrwabVGoJS16qTjTDydGFVfmANpLpn6dEg+us6HsPK9Ck/W9oBH3kZns+ox2Daa3U6SRVH4sKU5h/cPdDaQfr/2EPoCkWvTDg3HK+IAv/JwV/0dcjaW2+NrpK6ZgkBddALapVup82WdRJvRERqogQyD0W0+tsixW3vKHQWqzoyuGEKLjLfPYnqiR+70Y+OyI5WTO+PJI4K6kPKzwPv+Ajc7jiKYOsrBrV54NLllmMp9/2w== 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=OJYBpE68Y8N/1t5nC3n0imz30Bef72KhKiqO8RBIJiM=; b=nSRUYchxH4MydhIDQs9kQYEp8Bl9zHBtLosSuqSHUCmc7+bYy9w7/73EvBljSPqYQ6MmIgQsadvyfvATo0FlAkPzwFsYkk3wi0TvYYSzSgXVosa1uNyZl+KglnVu2tUqvxSftib6EgBsRaiyIAO8RuKnQwdaq0ujPbhMOlz9bflRLdP0x5Rygmk8ctUBXQwkeTmA3A7vrVkILD7prcvvBF18fgspEHea0hkHKY/7ARfN/fi8KtlxJUZ4S1fz3+DhmeD93T8SPVbbJbgc/BnTdIJ0/LHddJi+khllrmr+VFAx/fqtAFxUnS3ZdUJj0dD5y58Wh7uLewA+l0MFqVYQHg== 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=OJYBpE68Y8N/1t5nC3n0imz30Bef72KhKiqO8RBIJiM=; b=lx6Oxz3IXKzoIbSsi7jcGUISgj3ojGAKVeLD/g9dSY/UWrcVw+jTyYRLcQWoyA45fznJKuXoJFCUAo3IpnwiyhhLJuJ1Gq6cLArb6yaTNMqMxxxRT46bHs2dWHcZWp+s1OcdupgPziSuvZUWthqG4eVbF5Zc8R1BmtB5+AloYas= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:30 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:30 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 11/23] target/riscv: Implement AIA hvictl and hviprioX CSRs Date: Sat, 11 Dec 2021 09:49:05 +0530 Message-Id: <20211211041917.135345-12-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7c153188-0151-4e31-b625-08d9bc5d9153 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:1247; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3bLWnljQbIDGpTbNOSbSHN1gyMsEc0WGgeMiMiRW0cC+WH1OsO9f5RVDnWdAICgZFDYboVn2YpbnpoGcX8GVdHft+YZxjOMVLpgws/iint2qA5kRrjGlSWSFc+414FIP9nvtDvh0qgttlb0j31yqq/QqHqGNeaH98/ZaRXN1DVjY9LqGfnHJ+lwwQj8FXsuCL6RrDAiLWX3kJoG4ZZD00KV9FF8sZIttVBQyWlwFzf0Mj+TXPltUnB1R89S/qiowV/wNywC1vWxLOs3WEsh9a0JunJsdaoFdDDpUGc+QOB1/LvdovYK4P+wuQqeVYtzLb/7hD8anUlOKbsqtVXcV0wTPET70mwlFvateRhWfhGQbOmQhMFm/9iFsgJy23BA+Mf80mobkUhCxGyf8nU/GYiqu2wqfO/HP33itBfTRK8Ddv/jb2PTcvghOlANHOV66iZ9+XuWhkbT8aamy14eA4GAI3RsjTbihi0en32C6hEz8ds8/0V65cYcDNuauaGaSMAgn81E9lVtZQXHzSd+t1PyFD1/FmFfeli2xfPs07Vy/PowCjKmn2lTr2c38vdfOEJkEFTjn4Iazs4PXfbNJTHXQIJ1a1TKlqNOwNE4UXgGC1jM0y5K9MXYGVrF7B/Yxptmb8nmBdFXkLJ8ao1rhcnJWszLikTTgAENhq6r4UKYD4PwFDItACvPeZFx4MsgN 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: htvid00M/wet1x+TsoOBFTS37S/oov9g0iNLhynVy8OX6/Ev6QAIDmUXXD8gIASOq2s5HQWqqw5Aa0AKJu1uzGayPl5tHHHmsF9gx8wGznvoZsoemdaNgCYhu30WYZBqg4mrNNJt4wR6Y0XIyRJhepJAI5UdZp5CPgx1je6rkxBSai80ckTPpp1aN/sgtW2hkbzKF2F2R8gGy4FQPBzWGR1SHa5o+OODXtnbRTRGcZFBzdAq3QCHqATPqlh4iYtkoiHcA1Q5VaLPpRyfT9/IZNMSFEAz5Df/8rl2QyDiijQfFA7LkEn4uKQRo6zDWUFxBWgFiqvvjI/FcwhB7c1sHPmM+c/3acVMZ2tmfnDIhHJjYBDYvWvFFoHGx5uMmN+DM3Dv//oWqpn0lT/LmggN8twmweclcljUsMRCXetsxcOyZ/+haSDjULsgdvrEr1eRW9Kg31duATO+578JDUHrBZcOaUUcgfFvFJeCmwCIIZgtAcc6Gpf0gZxoZanrhiXGK/4+b1YUYZ3V03MZfqE3jLpSWXkcciRmxvcCYZ84zEiYWdj+h7IdPMmFScck3clEojsbAzqhc29yW21QeAHI9RtygAkKmb108YyIrSiqwidERUheJsyx30GvRLsn+jFWaXRCLI15fNjG5jHASeHFKJdUXB1yI7Bmg0PpDrnofFCiu9pVSOtcp+hD26Gnko6s3otDrIzvwqx2piWu2tVDeF1m2ZDp3jEVij2SW7RZ7EljLaSgZeTaaOAGbNYxigKRCWhvLHmYDj5Fb7UxxXgYC/BrKjp8z2ahrSc5XgXuml6cbHj6nVKvdsPcqiy/7VxbVF81mLgeS1o1CU32PgEKiXUPK4rSWC6U2nO0tn5JI9BmvDl2dS5CqnWsyP+7yrFJUQHQ93hytlS2sIyb9K390SBqEZ3HHXUutmt4SJevFUtUcAyH+khQLhkU+DGNdUsrW0GhY50LhP99RCqaYo+vXE7rn9MH16IGZeoawXSZXj8gJ7RkB5VOY/7QNmc1RpAvPzggSwU9E5p7gvoLWIY36IzPoY81ajfxaymAWK4PNNf4xMI7JLZchp6quaCuNOHIxNutNpqFRMwm+eY/mfp0mjX/48LGhWeK76YqNJz+kHo6EVC9BISHt1EHrRQtEuKvd1yogtRWjMe6RSL2s4EguKIzw6qhKYefhd+7tQP4Jt1W7mB32q1bnPtM33FnyX7CPDnfZ8WZjAS8pPQ9ftAYDEZiafw17vgANUe55vlALK2Cmo2qdLrIeGmQhtcWxXYuNdQyu6WSmfeuU3TllACq3+p7tuak9vE3FAS/V8p8lRmU2RJD8pmiSzR6S0HvTdLnd4Uev9sxPPvUYdGN1eCkxXuDe/A8zCaejC2pV1mfZhxqmFm4jfilJjCScnFjShIwU9oWYUNkU1yBgOr2IQzX/KXQeyOh4+a3kmu4vTgNkXk+LDX0pgIjckVCTzT7uPnQ3+wwSm1YoMXXZ8PGV66q+0Rj/5sG4GsVTeR1DTk8umzyrCKBPJbHsa9QZpp/fln6GqhffraeON0JgsLQjXbX4O+mu4hfaAfDEy0LXqOUVtl+hLNIw/PD8o9Pz347DlzC7fuKLxrzRnGukP+Vhn9LHUi/yTjCjVdj1a+wiaHucQg= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c153188-0151-4e31-b625-08d9bc5d9153 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:30.7204 (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: B4Lp7YWGU8THjLX9xMJj8clYXX5fZLpZXQ7EnvPLyKeqZHFLCXyb3uK3UrdtgfbVMOfRWWG42g6yHSUagDWW6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA hvictl and hviprioX CSRs allow hypervisor to control interrupts visible at VS-level. This patch implements AIA hvictl and hviprioX CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 2 + target/riscv/csr.c | 126 +++++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 2 + 3 files changed, 130 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 8b14fac9a9..c6b9cc0f2a 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -197,6 +197,7 @@ struct CPURISCVState { uint64_t htimedelta; /* Hypervisor controlled virtual interrupt priorities */ + target_ulong hvictl; uint8_t hviprio[64]; /* Virtual CSRs */ @@ -465,6 +466,7 @@ static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env) return env->misa_mxl; } #endif +#define riscv_cpu_mxl_bits(env) (1UL << (4 + riscv_cpu_mxl(env))) /* * A simplification for VLMAX diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d9bb5ff649..968a65bbd2 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -229,6 +229,15 @@ static RISCVException pointer_masking(CPURISCVState *env, int csrno) return RISCV_EXCP_ILLEGAL_INST; } +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)) { @@ -1041,6 +1050,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); @@ -1239,6 +1251,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_VSIP, ret_val, new_val, wr_mask); } else { ret = rmw_mip64(env, csrno, ret_val, new_val, wr_mask & mask); @@ -1625,6 +1640,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 * (riscv_cpu_mxl_bits(env) / 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 * (riscv_cpu_mxl_bits(env) / 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) @@ -2277,9 +2396,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 44dca84ded..f027d5e307 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -92,6 +92,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 Dec 11 04:19:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C04DEC433F5 for ; Sat, 11 Dec 2021 04:33:04 +0000 (UTC) Received: from localhost ([::1]:37754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu4F-0006lT-S9 for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:33:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsF-0005TI-9I; Fri, 10 Dec 2021 23:20:39 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25424) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsD-0001io-Dt; Fri, 10 Dec 2021 23:20:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196437; x=1670732437; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=221fwonuzmUL4JpIyJCEMOjOLU8Bl5oGgUJUzKoMB84=; b=BU5uzC7p0dhTHrA3yqigH59vJxi2f+ZpqAH4due6VQ4rL5mLdfyFwZEi LDbdWCe7YIJhdblusz4VNROw0Cz7C4cyIF9nDoZND8QqxTebPW1JeXqWg jRSbcv9Mh98+jXS5ipCaPsqp2VtQa2T1/O7iAJUYzN/nF/TYtLHruk5SA yru6Bc679Kyy/KbIfCNm9uNToXbRNRjXKYZ5hHFMIsxDqnKRxMNfsYDiv APsysieV/QgtIbT/iTbH/ClyHmPo9GIgasB77HmBK97QFRyY4uxnZFwPx H71xRMS/X6f89G0z90L0UZUIjy/7L1UcEgC4FjAgssjlUHJZg/9qcb0XJ A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834361" 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; 11 Dec 2021 12:20:35 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N0+JfK9WvxvdBQzsbxngaB8bRRTC/OCJyjky31WVtQ6d3NcemJKY4heCTW6pNMb33r5b9gMGppAxJFM5tB1Y2WM8P1UKA/v93TBS8RCkw3fSGBRov5bDxY58KDqESFpJGV9osdayA0urmVID/7L+/+BxrRdA0PcJmdsKTCMOFQRVmqbS45v0PsWwYdbC7k6Q16FYbzhSWM7KYm0IaK8YgEQlIYFeAgBkNnHoZDZ2nBj86Fdxc5vlu/jARUvRaVPh5AhuauZy5CFpPk8ze1PU6dKHw7n2dcY5UY8OizCfNJaqVdzAt5ja4OClcr+bze+O/da78dljCcRkWQyoGXtQCg== 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=lgfw4elSnNVa5zYmZylgviCKbU/BAyaHgG/ELPE8owM=; b=KGh6ZYms3Nej5s1fHqVCdUTeG4hK5i5QiHwwvrtrrbpisQ+J2TWCN+rB/VOFkrgN/UUc/0za7Gq2rXv/zJD6KX0RUs6GkvO4/3YhlCgcj6owuizxIc8+BhLyh9c1B5uQd9N7vut78EC7msjjqoa2sQ5NXu/LmTcUnXz0nOnqHMw4kQ5v2qW21IJBeTczU1gZElqQEnLjS3ZYPWskg99TBbj80d7vBW+DPygb3zsWt+eEfI+gJCIv6we4cQOO6EsxwCxXIj7vVeKNNzfV9xnV1C77JpLvG881mnWEGKqUbN7TyDmcchokEDCo19h77iIfraHbvuAAiZOEJeyZ+4y8rg== 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=lgfw4elSnNVa5zYmZylgviCKbU/BAyaHgG/ELPE8owM=; b=WRR5ASNgthZNJ/SDfQHtrf8kNdAAX1wtBdO0WI/hultMRcGYhQQK1dbQTLFwPShjNc+ZWfQTHOjrfU0iaLExsFVekR3zFqq7EnPvFccpoIBRhsBmOXc7lBMdQixy4/Juq3kR8KAp8UFcNGzFokeClFOG4d/0t29iXnt2JotJf0Y= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:34 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:34 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 12/23] target/riscv: Implement AIA interrupt filtering CSRs Date: Sat, 11 Dec 2021 09:49:06 +0530 Message-Id: <20211211041917.135345-13-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9708310d-ce6a-4127-1bc1-08d9bc5d9346 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: ncqxyylNNZm9rz/BApOtbL0VX2unUHpVbOw9H7KP7On9NbRB4rG4TrQZ367KUvNvfPAFJenNktebDjMYqiejuYdw1t1KRrUqZoCvUWTrQyQhdK9La2Owg0RCQ5qEvKiOpQjIwm8KMwvTuvHjehSgI8HhKOy7nGlraqKbea2+emSdLttc5oJMuutnEOfAam7NpS4qcl2cdLGHwmhIbUQhygFRvVAvNAYYgDsVVMesJW9sepWnB5bHvPK3n76E1qrEszERGjdSNUXka1IzL09VHcCWECcMoGFxq/opZ8w28urmExBDmu5DIeeDuVpuAQZZyOpLBRJgGxs0WoSzZMixMj4X31RZOVLnEQ5HS3xT7ddrQ7redXmNQCdu6zePpqjoLxZk5dJBV9OdxyPfzMhXP0a4C+mgBtOwfEyRsXIy6Z2sLphDi4T81oftWJTJagZf6Vg55Zi0wMX5CExMj/7qwZ8gwboYojp9qb+eC4UoRRl0q/YwLNVdV4/4boRgXXwcOaGWwCVo17C6Zw7tWh8zSR+wZ0i1wPu3KaJvFyE/X840CnpALkOz9b3ENRNdKnn7P5/lu+EhJXCZeM08rQbVa658dnpCZ1ogEc8ptC8IR/Rdd0EUmlH2CWSOCd4ysr7BK1ak+CRWWXYVZsC/iCLsLeCF8yZfVDl3aOs8H9K6jeGHWENWgu2sYCI7WiCydcrKeVAVCNeoJ/4SobKGbnugAw== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: siCeYc68xQmEYRRNiMGsvYNzSTYy6wp5cokmXWh/7PivK0JgF1A3kTjCojQyqhoMk0c89NSouAHFuR3CvdXd2OqWXhLyHeaVNfXc0512zzpZI8A//+tdDxcBhQ9PAkhSG7CQmQzRS3CnNSRzxtdIKLI0xHpQ54iZ3itNTa5SX9DV3UymC2oQ+g7LtOKDn0Xn0ZCO9og7aWLqvFydy2HpmW+A+zuPud9V6ElvUD/bFUjnAK2wMuMLgLooNB8jLDtoCymwnxOP4zCgcb1IHOePENdLqd+O6kyLAMXhrkCOd1xklbt8VWLoeEIReC5HGZbtDRvlevcvZ2dnQBwxCJftLT5UbWKbPOLMo7Gk0tPk4nX8gT6QRNyGEENtf5yqgceLt8MGFAXVoDdln8+yx+QH6w/jnGhs1GOhRUf4BKIDBm8gelCR8GuTJDPedeXXvJ6X88/+U8t7KGwV1bY/7mxgPhzsnqKnFQd5RzV1VSax5C01SnRLRP3ASg+TN4NEUTYF00ZaiLhKszEmf+bmZ+zLxpiDqsa6dvzw1HlmJ4G/riUXRptDybL3GdEFp8o0h/XVaY5XzUcEiLris3CcGRX8nsn8QOwD0xvxTr3unz6SxcZrmNyw17yA6Ry/3SFl4WpROstUD6ag2oLs1ZgaEmWQv7V3YRxgOqBuQNCWqKRrAdND0PloFPFzbpvhBZqSpW2zjIathUwCiZo97rR5/URIcGa7uV1jZUirwa5I9A7NfaeD3d+4NfVkQBdHMailJMYRJZJbSXqFrYqat5XZJg3qe3D9Fht6j53hCo3axXZFFJXa56VzFmVuYqBwwzNtMkabq9PH1RQ6E8AVleQmyNB6bwLHXEVwTkgdMDytehQt9HJ066hJgHugAvtxdSphGI8oa3/w/clUaCA1uZxHbmpDGgcqrhmqKulTWm5QEdzapyiNHzayDNmD2HJ1vOy5L2aJa4BYRhOFLCDFyV8pU1rrgtKvXw4Epj5jY8mu7OTLM3o4V3halfSa2iTfquSFUwdDFZYWm9hrOICGP/DnNCyH399DP5K0c2Vc7tzDrkazGf6WZIM8bkMoxz3PNp67rXHZGf+Yx5J8aptbxTEeEYFLjD2AaFdUIIM86OhVHO1cY5jJv2RV0Yz9gIKuvddzq3973n6m+awCjTuHBMaIH2HFLJU1dRu+pox5OiqcS5zJWsVRml+2/gCMc80CESwBnFGe7pBWadKI/TFyWoblgG3bM4fpjSIa9DDKGPMfg77nyhuA2yKF0MG23YBEtm1NnxiKN6N1NkGy1I4kjADFQIpEbcfksf7tb4SCG9oV4x5ihdWOmKO/Nr5ktGe+84udvlinXngraVWBkZWjFqDhmWoJXgV1zO3cTBQ6pXbWFzueFhHabvUnGIgLQUGLfof5ekKkWpPX0mS2PUA1L9KnNVkPNCBHWaFyU3sFLgA8ihODCTmDzr0NJC4eyU9P76gkeaOdYzii+4dJGmJfdguHp+/QZBgCtVivsUhMx2WpgYYW5yrf6w/h/XY7PY1WkNqaAuQHE4wqSu2K57mxzLAFPrRkopCutfHf7kMm7t/rk9TCBQKxyhl12DZpd7PbvDOw7JD2WhP6WLmjEsWKezd4U7KrsjCQC/pP3yYc+bU7Z0yDd3U= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9708310d-ce6a-4127-1bc1-08d9bc5d9346 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:34.1430 (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: quqjrrxXYAabRt0GdwmCxaEHq9qh/bFPDC43cPILenLftK/1VfqumnTvpZEI8lyUtylO7jW7KuCys0GXdiEtSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specificaiton adds interrupt filtering support for M-mode and HS-mode. Using AIA interrupt filtering M-mode and H-mode can take local interrupt 13 or above and selectively inject same local interrupt to lower privilege modes. At the moment, we don't have any local interrupts above 12 so we add dummy implementation (i.e. read zero and ignore write) of AIA interrupt filtering CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/csr.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 968a65bbd2..4b3edc1043 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)) { @@ -525,6 +534,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) { @@ -2343,9 +2358,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 */ @@ -2397,12 +2418,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 Dec 11 04:19:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 38C54C433EF for ; Sat, 11 Dec 2021 04:35:10 +0000 (UTC) Received: from localhost ([::1]:42790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu6H-0001mM-7E for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:35:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsP-0005zG-Rc; Fri, 10 Dec 2021 23:20:49 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25446) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsN-0001kV-4q; Fri, 10 Dec 2021 23:20:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196447; x=1670732447; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=WcT7rY/pyMF9kxvmVAqqhyGPiF/mLi3PZm2VyRrC9hM=; b=hzulLSS/5jA+u8Ykq84EUyguQGy3thXKokNmxJwRr6LhOaYCv0oOp0Ix lpFK0QWocUaoDEOWVMzpCgOkPukRAtxCac1atbsEoIXag16ww/K/OvMBc TzXDl4k2JnzwJ7zfq2e9Ayy/yDF/x7OH++hhkiOsWsCRIChI5ZoLiQT50 x09HRRky0W/7JnJ4vVAouYS0L48Z7jx79zXp/ViynueXzlsXg9N9nqJM+ yb9OXVQUBhHBNfXHjYLJ25Rvlynza/yZnQYs341voOWopN4QSFGnjMfFN /CuFMfiNvKjZH1H+EKQFU54wbrwy+xgenwqUY0qDrQS2bjigXBF15T9U/ A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834369" 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; 11 Dec 2021 12:20:38 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gsO+f5Nq4Ogo37kVVxF1GMouGebjp4fwoE4c7aaZvO8AEFu0SADKOwS5REFjt8lDU2wMrjvGCcGyU1/v9rHfZ24bDNnz8Zg53c99S4NO66qpvAtThzuAUTWLc9xCr0RDLSl9YNagfV3IvLq4iwyFQ93HRQU6nQkdmbuErOP5jJY7Cl5V1r5r52lpO0wzSXNA7U+Ca7/PVlm22n3b01c8Xw1C6lJnxHHfd9cBLEqqabz9CMRHffoA0pQZUXYKfJwhLqJJkMCFc7RL2snjqwfR9EEZeWwgr0sNivDvBltCyumJw0Mmul3ouPC7pNKbjQlAd0GRWNXRSytYeQzwJWNy5w== 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=Ai81awGXgXiVVbp5ejcwCHhlCEeaLWUpNjS9u67JKOo=; b=GqOJyATKG2Reex/84bLAG9Zgu+KtT0j0ZkbcahHul0nBwPsjECE0UO6ebW9YONOCjBfcZRxaOVW+kktKbD4WOT0zS+OcEd7eorC4MCwyc9GVuw7Yelct86iv48dfqFgiyui1F0OktWDLcyaJFheeG3I4demwhgli47cBiuvsTRDQk5MIqt6OYWqbVuvrVeJmRatuRoO1HBMzeJKInOnC4AeIe4ragIMLOdIh2KgOAsPZfqo62OYe0qdmjK4chQZ+IOFYzjOBenXQlE2nY/XcThB/X9DbfIEAWnA8XJZ8nWX52soQPDBCDl/BqTWmjVa843+ab9VjCd/TVnG3fFmn8A== 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=Ai81awGXgXiVVbp5ejcwCHhlCEeaLWUpNjS9u67JKOo=; b=Yi+ow27XCXu/IPmD6A+8gJvS/UQPEJuRD55p+NcVDFUKsr0269CmTPMXPorM2ppoloEGvbj9SshvXJpb87wLpTexsELWG7b639n6QmhoG48+eFWfJsdPbmxDGhX07+RTEFG7gmi1T9VNImS3Mv8qhjvQfuijUzBUUdRNqFDnTb4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:37 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:37 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 13/23] target/riscv: Implement AIA mtopi, stopi, and vstopi CSRs Date: Sat, 11 Dec 2021 09:49:07 +0530 Message-Id: <20211211041917.135345-14-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 339dc0b0-ff39-49dc-4500-08d9bc5d951e X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: Hs3oJzRWRbvBgseFpz10n00uHYJXElnH9MjWLEz7I+VKofSFWA+TwPIj11ifioHTA6u2j9Hf4s5S5XOuNzfQNTypdcukn2LTA5bG/akb03XqUMjOr+dqQR+JLdMcNPx9zqt7DD0A+VF004CP8ym266FJq3yYGDl6X/aec8YQYZ+1YxRPohZ+vtyStB7Quynp3j+1RMyVRI12DlRuXc3GrgbAALqE2mztExwLt/7f9eFuvBYZ9iKhX5h0XokQUKoyRsnhRSEnyajTWFSeS9ZCFL8+aM8Ut9+kQ7wSfWbWeLngQQ3Q6MeljU53Ob5/QUxvRcOvY65HlMjWFDzEbgPf6cjW3qNPjrC0H7XCcpEAlLfcLvXMx5vrIgHSXiASrJDkboizjIAJwApfXa7C9xgC22QqaYnWzgGSLIuT9+QTcQHocwMNBdq9GEHUU38XesEauHf3i6Mt+gEJ4KansYnRvhFdXm2nR6HwLwOej0JuEiKgsj/aMmt9fe+Qosrkx8N8EnrtV9a+VN2DOOFyRl3fKMvp9+vxmLVrWE6ltnz3u8/KX2bmcUj4iKIp5xleVLTuSFaPysEjzbLJHqLwFkUJc4Fn5AjzMaIHNJYnPBXCVI0E1ZjLeKhyiLhdDEWuDkDNFCE6JOTlg+yQ80VkrA/GKG3lLZPlfF4h65Et2IysFZPgAgkC69ybV7RGG1UXtxyAcK/fOgWOrUEigbxeENeKbQ== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zMjur4F+K6dq65qq3tIy7zXjLa2NV8MMYXIe4x4A0F5JMa+3BmfsIIoyLF5VBX9RDSmEua+4iYUaaK3LNtA5DBau3JPA90qgxSN6P+ziQaxJyn5LYumiczykKgezqmgmBB6Jyz+NY1d9elo2sBWIjkaaVvecwu8NZOLZR/vEQiZR6g6pngjWMCYwf+L9fDaPzKJOheWofs+oOwbJdOKqMQNhtEutlEDp2+gagjDoHl/dwcvmO37AvCxf1Ub7gsffJlSJ7S5aD4L8oPvEKzjnc6VfpjT20vaWKdFKidixJhAyZf+sBYnVMbZuJeaHMerR4iMpkBTQY02o0Ehjm2Xg4SYhAEPiCTBDGeaIzv/uJ3lS5wAovRMeXNm3LgouKMRP7xh1ujoE0GNjbzl8G2ZxiGAYIren+JMbKBLlwAzDcjbefV4dmZqXf8GdcKGZo2HDk0mYxDSoELN21ItCYnE+1uKpWff4IEu6Z7q73W5QbYEtu4JiasWPBBAkRVGWiS033Zj6zQdjSQjTDNFhHEN1Un3DtYZ7LzbbQV3Avp57jLzBVM4qBLS8qmjUB5L4YIfpQgTAU1o48ammRfUDCaZfXxDZx2ZVBw2PYkug36QELdLs/427ghXbk78keVd3+PUYFHIyVLWleQ1MmyobtqgLkv5nMBhwbEkN1T8J36ppofHzm+MGzWjinIOILvr97dBvxflpDBIHzzSPfSkX6+ivVAuh2r3wXwRY/5tUB+fpQ0ODoTf5KlanDCz0pkzcW6ZedwE7q0QCcYjtFaNfmvca3Z/TDEZF/UPFnXwvLcKHKjkK5c3In+EBZgVNWnQQr3/xPdz6r9DqLCosVW7vcEwRRXRRHlh7f+rGkemEqRY0Tcw0CyON+bJbxwcNn2aKBOX6wog3ngwJz4ZAEc2I3Z0oTu/UbXg1tcr35JCS1h7FZeFYSuYzHGrxD63lXJ0klI9yLUa4Qkl+SVVpQy34YVKIgZ9/Biry/ciaG7Kl6LBW3ILfW7nFNForANkTTXXRjTjL18hqYG5u2N4rp70Eo6m6d1sX00WA3ilI3+dWFzPeBqXewr7n2KyVx3c84qC9zJTBHJqlHA0UKk//HS4J/hnpfWBqgR6EFFNRcNlbtkqdh1ORBSyFngrE8dx3AC/Soa39+lMoqn2u3HQKWkUQoKbCz5gey3z7JODi5POarcbuWCgsrf1NSSx2gLzVmlGUBkEUT6+s+yNFrJ+bZScHXPvpbPnNtQBTg1ZhGNT2KsXKpFyOPAHtsp7MNcwk/Vm1YYqfjhYIqbognrTNw29tsChCQ2k9hbsaAk1gYreUNHu8orfF/fR3C2rdkjW+avQMOT4HzGG+U8xaAGxaUySy/wW5m1p3wifc2ymwXZwSRzOsjtu68Y1mbz4zC+Vqn9/+HpAdp/KFf7mf300k+FVlcfOLohuF6lqvIy2aib9aTWAN3nza3JOJVhRLuNwCqcJ6Fke3KgoeaNRZg/HgM0zW45nm0CCzRg6dWGjG1LkjVcONsG52m9sUfMV8eNZ5cZQgQi8vZbXzRfVmiP7MUSQN2uo3KX11SD/7wMZoXIwdTrfU+lVVN/wYIsTHJ4TNx2UaJuygUlvVqvTpeMFr2cqmiYbGZHbFAIU9zW5He3NB96gFZqE= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 339dc0b0-ff39-49dc-4500-08d9bc5d951e X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:37.0967 (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: LLQO97m7ctfQCojenV5/USHc1cv4b995pcLdXJf7OxfYJ1L9cAEOovRvvE0z/Dmt/SQf7ZUCSQqk2frgBeeR9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification introduces new [m|s|vs]topi CSRs for reporting pending local IRQ number and associated IRQ priority. Signed-off-by: Anup Patel --- target/riscv/csr.c | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 4b3edc1043..6f613d182d 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)) { @@ -833,6 +842,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) { @@ -1362,6 +1393,121 @@ 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, + riscv_cpu_mxl_bits(env)), + &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) @@ -2358,6 +2504,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 }, @@ -2385,6 +2534,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 }, @@ -2423,6 +2575,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 Dec 11 04:19:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6F86BC433EF for ; Sat, 11 Dec 2021 04:31:39 +0000 (UTC) Received: from localhost ([::1]:60516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu2s-0002su-J7 for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:31:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsQ-00061Y-FE; Fri, 10 Dec 2021 23:20:50 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsO-0001kd-3S; Fri, 10 Dec 2021 23:20:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196448; x=1670732448; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=STRNeT6sDpE9GJ4Bosh++wA81WocT2uEDHjK46kw6xE=; b=evVXR0WFc2fxieSn9NZhadCSUhrzvY8XtGbRlrSOTlzH31juuL4djYrq ig+HzwVGT2IyYk9SEaV6/6o0u00YaJFgnItlQYKpzAcwnx4b9MosHGMIE UPs8mvpBE/5XKDBcSnDbmrZtNSo5ajlnLlNZdmbQ3PviW2pA6hAkTzXIv 2LiaSCpU2FXQP6kZ/k6bf4oA2uIHqoGZAMRECk2s0bi/HGfHoHa072O7X nQvKM2dwKp45YqIqm8ELVHSXT0c/ZvXDKXniNFvxTjovIV4bsQoqZc3tJ cFGT+t6CkTm1UVDjxst+iUvi2UTLzPMZO7pH89X1gzvTL5iOSfEvUnrAi g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834374" 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; 11 Dec 2021 12:20:41 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g3KzWzPWHKDmVfSHXcrUB9KxWF9ecbCcBAcbUaYox49kgcx5fUDDubvmh2hNXsufjyh4Vk0LKaIhkh/BAvNvxEI/zk3Zid/xRS0YmGElyTC+m8o+WksYoNyS8th15v8gwzyZWgd/AyS1LduqmYVKJMUnTWXZE1OczOykSHZhtZKHq1La1cWTmPpXBJkVytVbhJRC+u2VG4e1U2YxqnHvJVJ5M4vgfeNludyopJizgQVURnvEd8q6OG2iN9Hrx2nOT4/TPCJKIiwUvJ8o1Zp6xTRDHBQxnSd9+1RuEmLeicaVSOznV2HtkbRKdlJk7quQmVMkIXxZNYxjuvZJyThanQ== 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=Lh8RHToU2fSiEsJl7X/FUk3VMxZRmSMQImkf+OaGg3k=; b=bCEiAv8YOGIzVDXQfuhIjTztfD1fp8VkL9YjhghXeLVSIjWXzuVIPoAZxEe5voHsoBy5pxH87qFWOWwJC8XTXmc04Sla7XU8Uxevi1RA78Zony3sfs/takaXaFPVXKG7Tcm7BWuV+wLvCAUd0FgXTmA4m7TsMvq9m9NDjag+TKp3E0B/jqXdv1ikFG0ICQjGlkZBvVzFtoA8sYwd+rEIUN8KAr2MwnGPR7t+SpB0nDNQchHfCZQb2WqCxfzVEBt9zH2I/8/TOlslEYEehPqWySeBHIExrNpCbw7utIwfpaLrbr0aTjHfO/QF8DxsGjQFevZOV24fAVEnh8RdxbvDiw== 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=Lh8RHToU2fSiEsJl7X/FUk3VMxZRmSMQImkf+OaGg3k=; b=S0SNLGSVMtIBcU8OG6GnzQYhTcdnT7lgcbrBTZgwgomhs4LAQ+BEbY3nPyQSvfSnTcA1rxtEAxU8tYyOLzqybWnS8w4aU/JYEJA5E3SxYL9HgIozE5d+Orj//+n2EXTtk3NrrEpK2/x3330oLKf3r6EnmH5UUfh1oqLa7ZAXsk8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:40 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:40 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 14/23] target/riscv: Implement AIA xiselect and xireg CSRs Date: Sat, 11 Dec 2021 09:49:08 +0530 Message-Id: <20211211041917.135345-15-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 96b6e0cf-eb60-4f06-7748-08d9bc5d970e X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: uBBLT6ZP7oS3ZOp/zVbCkLXP0gOslP0r5Pj2qb+VWnCOraSSrgUAKfTounGMEdFYiJOl76CfEq0wuw71n8YNoIkkjqq7nquI4icaD56mN7a3MniQUkDBeSQdMVa8hRdYAFrJaCAAS6EQ4URXuSDQGCF2YQLIk1asmreatkyQ7zTuuwraXDk/ed9u7YgtSCeUKrPAZuQZleEVaLMVx+b28N+QgIAeVOKC2lolEi19sGHOGgw5UkGyZEprodzL+hrCm3VPq9D4Djd93fPiNJXHt/v8tZXG5+TJ66ogUoGpgCbpfJSxbTTmLXTjhSbOKrzRfJWHN0o3PwCfX6wPL89vkmNseVU940TBTKkLJIziIM8gGRHZcG/4i8H8HmvGWf82M1+OJJTdoaf0uEKQhuEGaSJmcMsl+E0dDqKrSUZaS3wqYWCcF9JZ2JRI+1zyasp3StzhizybuLY+2xaHOAnnhaxMzqvgu51QvqnzInXat+vcDQxR9UREGUlf0d3Skd2B61wgN2X9oNTx34I6jNWDfl8J/jRCaXA0Qq3dkBVpg5t24qO6vzcQpwT80niUi22yHJgCYaBIw3CpUZAQIkZKa3hxyXoXCjE5HK9WsuLr68I58TdhNQg7+h2vZ0AQQOWLWibSbZmATvfMzuidm+4HlAkwEdzweuPSauDWeRFZmprf8py6tzAXRsBrUmoF7MvK 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dXl0NF8T/uanX/HS5X+Ko2hEcHBcklETFtZ5KUi4dmeUFOv/03c4YYEGXJ/4s8oXNyNDw4gLydKvyGn31hnm2weiSAAHT7NfulendqxGWk7mMUYppKRDHAzmTq9X3lvk78nn0jZtpx3UVG9ycGxd6bx2KaiJHt1gPDwpM9mfSAgdl0SdM82nKqcCJ4mQqRh1OAVyQSLYFJI/7vNtq85Tw/JHcrLYNq1x0zMf5SU2vaBAVEm7ES+Ue+EB6f6MMa1wAYuO6bFmBFUwW1Xndp870K/nP0rj29zw94gzeomS46e8YI3u/9/hT/dDa1IiB3V3h4Orz0w2xRFBlHtQ3dync8FLCEhOMdVwMKZVVPwzKyJiGBUZ3l863hFkovl3MDR8vhmk0pSEaSrYW7/qcvKbprl34mSEB6WJCzVXCYSTGGK5AABHf+t2eAS1+kuJeS1lE/GpVEqPD5hVY7YWK3vp7KEMMxq1O8IF06MBxQXPCBhscc75Rfs25F8S4Hqh8Ai3qdrYHiJb8oxSwuVFF5hERrr8Ulka+UINegrhOTEHxDwZj07BCcE5s+5Zq3YMFCrbfSuKVm/XzauZt2X9sExZ7vSou6/tPfYqNji/TTaIJYS5mBeHtaS0LLA6mJbCHtVszRa0hg8rSaolQYFQqL+razaom4WstLa9UaYNW7uQH9ZejnZwm7mqkpKnwNWx5RrpqW01MVhgmpaguGYMYraevhLM6Of8tCs45dW9LiRM55nY3sDDW568NcwZltYtRyK8FBVEPPVmKhqxajxK37Go5PYyh8bzI6p1vavaiWG27DCseSsuIV4M3EcUBHUYkAUuQsnvLC9oheilKRMJ0J6inVc/CQmm1MWUVBYINqeUqtUJ5s1JtIIg55nWBIqIyCEhNb6cOk/vtk1LVFjbu6Q7cVhCAriDBflLuv81+nsRCotoie3L7HH2LSeet80oKCWcz1YI2Vxjv0hGz7AT8geUAtG4dh7ejY8DRcch2cUPDPAkVtKacDGDsV+Yttzx5/SJioSbctvNeUyMV/H0SEZoHstEg7Gb8UsBClV1jo3wTBB49bGeB826i6zPm1OFrjrVYu0sFuI5kDPM+abYYhLhWWc2TJpcJziZmeGDoV3lBmXK6orTRhGmfPaD9CTdwrpu8mb94Q2u/j/TdWCp3W88ZJT6q9qaGZqJwhriqOddMvAf3TCGMIg+CbXY9BWSaSwLOtiGJ0Ajzu/Jn1O79lWLQx/NdGCYofe8TS0OgRJP9BHayN70gEwuQ1FmUE8NnHoT0hW/oMlnEHNqWO/BkxzhjwLeVRbTv3AbQqElHxHeI0qw9ejkxV7YLT+uo7o/uaDERD2rPlMIcy/eChet/8WFfNWhdCXj9F5Y6/vO3Z/jlrgOjbKzv22khOY1avuGCNJk8CFtW73JyHgLWpmiLe2fvbmOywPy2XquLOTjZC4wHlDIlYjlBjnPb8tWpc9yKY03qSDDNGZcqqf5xRup6YKRmfuvB6phThr30U1m77RUsZ89Mw3u0pXb8dQd8/5xWpRM7RCsgHh+vE6L6+vCCZQyN6vo27oC/HoPCIamjk87lsAVy0Gu/szQSh/25nhLTBoBSO+m/DylMJ7Zlm+0GzgEElUju+Tu3aSgob39YvExPRQ= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96b6e0cf-eb60-4f06-7748-08d9bc5d970e X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:40.5517 (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: 438loQfiTg/sE0jlUArnTrxhrMlr9iJmEG/xrSvgU6LqWAu+Iy5GqC57oSgvhAiB6Nf3SIGBExyAKo8GDw1Fhw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification defines [m|s|vs]iselect and [m|s|vs]ireg CSRs which allow indirect access to interrupt priority arrays and per-HART IMSIC registers. This patch implements AIA xiselect and xireg CSRs. Signed-off-by: Anup Patel --- target/riscv/cpu.h | 7 ++ target/riscv/csr.c | 175 +++++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 3 + 3 files changed, 185 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index c6b9cc0f2a..a43e38dd2e 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -184,6 +184,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; @@ -213,6 +217,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 6f613d182d..a8d169e6f4 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -864,6 +864,169 @@ 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 xlen, + 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 (xlen != 32 && iselect & 0x1) { + return -EINVAL; + } + + nirqs = 4 * (xlen / 32); + firq = ((iselect - ISELECT_IPRIO0) / (xlen / 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(riscv_cpu_mxl_bits(env), + 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, + riscv_cpu_mxl_bits(env)), + 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) { @@ -2504,6 +2667,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 }, @@ -2534,6 +2701,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 }, @@ -2575,6 +2746,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 f027d5e307..376a02a36f 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -103,6 +103,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), @@ -210,6 +211,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 Dec 11 04:19:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C91D4C433F5 for ; Sat, 11 Dec 2021 04:36:43 +0000 (UTC) Received: from localhost ([::1]:46882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu7m-0004fH-Q8 for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:36:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsT-000697-6s; Fri, 10 Dec 2021 23:20:53 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25446) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsQ-0001kV-Iq; Fri, 10 Dec 2021 23:20:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196450; x=1670732450; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=pjoMmTGTi/kHHoHz9FsWbchb30fLuMol0LCEs9ozmig=; b=CJfsnMFlTW34nLbz6wKdprHkGLlorQjTbZ+4a+nPtGpicyOI9fqRM1mb vj+cA6ySTy4XbEYFQcuP9F/y+MuLuboVj+u3hz7/365tgZ3Wi8u6c7zpw RQVUwueXWsg1LfDZPUtKMEH53KI3iUZ/OevRzQGmT8xc10qkoPy8BCNkw QJ+lj6kH7ivU9EC3Kwz7/DJevdynvcYyZT2dgd1KVCwW6P4fYc3RANgYt ril6gu5Z/H5GffKnAwThkLcRKdQZxetRj4217cbh+JhnuIuwheCnkpjUL ro/ROFkaYbwjzPk+kG3oYOr+yRwjSQjjXSsr2GbGOFcn2GCA2fyzw2dpM Q==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834377" 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; 11 Dec 2021 12:20:44 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z1GRwl3xCO8L2EnNDMvtJc54JAIekdHPuWppeNQgS7BhpypaGNM4WGPmNGtF+gPVKyVt+ViwZE+YG9GRpTym3adn/yBVA+lDXjM3/2OJiWL49k7+dOyQ56VmwH7UvOAiysY6/t5wiVF5cgA5kGK7uyKs769rgF7ayzcZEdZOVr6rX2/KQVOxYqG4tln1liY1xhGuqoRmw7Rj2gPaltaawEsi8FwR1cD5qM7Ot+Gky/FA226Y01ewmKeDjFF+2rDl1oBzg8GMg+17pc39DQOZ/8X7Ln9A6oW8UYje1GYnMvnIugtzbHnMZ/KRRqAYZMAH34El9pWG4aZL4brIKMebIw== 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=jXZUkGU2zFcre/4U94gZAjWM68SZQXXTHS0wuBJ2dsc=; b=kluInBrWyiy5aByOu2odbqcX9kYLhTS4OqyI7szSOLipdznrw5aE1/5UaRoROfMqnumpPPe+aJV4xKnSagzThrdW3i6B/7MoSLRjUpzlJ7bbHGcpJEGoI2xnE2auru4ydkxXiyCmXRwqPzF3kzPSZp1WLLDz9ogMrl/tZIir0OsHn7zgJrEkR3p7tOeSPIxsNUaxMzYez6y4/mHO6Z2pNWPFQkgnQpu6pSrPwNKopBd8k11yqlq2E9sIipdtENfWk6ZuGWfJPeZ7YrqogikL4Epm3Zq2oG/G9Y2y6kpcYPeaDbfvYMOMpzoR59myjINn7wGQfx9ve7lTtNps7n7Ixg== 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=jXZUkGU2zFcre/4U94gZAjWM68SZQXXTHS0wuBJ2dsc=; b=Qyk3QuZTJUata8+yakyFrrXbO+rI3evfFOJ6CjMAiDz6NNm9wx83kKsgydryEqJC4sGzQDfOHJ4WE5jhgHOyp41+ro/1UnlWjpHJmXNxji7qjG5p5F3Lai29LsBF/+Z6MJVDrA0UP1MCXyjKl4gG1j1kOtJjd54BNEyYQ0MJ/KE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:44 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:44 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 15/23] target/riscv: Implement AIA IMSIC interface CSRs Date: Sat, 11 Dec 2021 09:49:09 +0530 Message-Id: <20211211041917.135345-16-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1b822785-94ed-4111-b952-08d9bc5d990c X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: MtJTfQRxqeKj/u7V2WYUFHHpI/oNJnA5Bz4I+6bcd1Ru3tvuRC9TQDtzfvuwv/9+KRF+leVaz/R1W5bL/nA6J1gSVS/Oz/wKQcCfbcZkGr8TUMfZ0h3ytMmLYQYu1qKDj7PsWHgSQRM7IaJqAi1N0IDW1KXaCMsvbPDjnlcYtmH2SzL9EkrXnSBAzf9tNLwsloNjKNlC4OrPmW3Y5FUtcYtdWIKmfxfBKgb/1o6KuQ2iyF5my1jv4GhIfLJi5IrPT26HSMTVqXkIlcMcEV0Ejk5RI7pZ80ood9CTNVLZ/Al51DaW4TIJTVyeMxE6uuEkUZLJRscUv7v5dqcA55rppSy+jUKm49H8mZVQJw9a0sjo07m/brwBTHDssCmnufdjlU1pWy8tia9onTo6oPrJux/xGhZEUwnhxMydDEn7vNbcDOPxSklxaHP831D7Y54u2h7/Ptd1c2ZjU+rt/mdK5ahDAyj8w+7WQi75fzpM9kiXZB/aGZ4fCdE54LfP60quks52BGXC1HYSKP2jlCkwKSPFfzHTED2M4IKXv/xlqbQqLo8jYH/slrUORz11DmT2B1kaVNVpooUZ8qdCd3VjW6ilRfbdrx9eqbKlGoUZxAArVSM1mzJj9ikbN1JxYuJuqCy4BYqfbYaHGTfpP2VNmwtUwL2HNEKG+zdC26iiWw6tX93ui8aXWE5Eey1koiM82dG2I2tqzR7j0M9A+mEsUg== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HImYxUWXuemHJAA1ftRx+b/1jGS6YQVDTbH1p5CHpMKpMYIqRjMfLlj0wkJ4TP2GjPv0d5VEgHzKz+Q7rfghylUeb6UeuhZP+mGqIwfq5Tpcm+98NxD1X3ydwoU3D4g0KRz1rmKKucgtspmjcPewaGovz36MixOvZCk+pzzQk65U80TtBW9deREEa/NCFxlOPMLQ3o9RNG+M5ZfCSJz7Aa+e4RsRnBGltzieCqgXGRg63PMnqLJnA8MbMF5JR2tw9TE+UURhlDwiQLdLA1mBy2QvBQZUcbdezNdJzzPCXb3S56cOdPoBVeNcOmCrFdXVoegueReDa5qW2JSfLheMPLYqhNrDk9aD1t3cVLRaeY8AF3BNtKWxzB6yzdRCLYL0vYmGY1yajpOvLUmVw+U/NE0Yoz9NqadtC9Tb7MDPjcmrDtm0zxOScFUehokVdPI5zQnImhjSiuwH+dIHijK/3lfKQX/g7UiTt8kNMEs24L9FJt4RBF4jIf/vKzqyq5865Z1lGU6JmyXk5Ird03UOQWQt7gIDTTaz61NN0NHiVXLoZ0rMhjXVl18wla5rApmxwdP0XnEEWKzbWojZevLXld1ATvZInV6gvC2BaEHJJjvT1thLFrHLfOWGL7H+SWuRIVq3GnL3I74keeBtvUaCsM6Ye8HZz9UO+NNvqLc8qFVTcL/fQMWP37oWxziUSvKKakV/c7rBMDvzMUUOVmrJQFTLcjH2DdU8a23kBBZSctP/L4pLZ5o9hAn43U7YtorkQaM4L27JGtXTPyehrmGQ5yFSNEX1WRMQc8AexLKeq8uaMQOLh7hnKCpWhqyFatoi7mVHroRbdjNiAGp5dcNk/UxnNokqLgWQslS1F0BugdLmjnuLeAiBqMaW2otqzj6gY6tnozzZ7EgIN82MC4mbXMpF9UH8u+RAXHCgsriSDutPPyBov99bL6pIB/zj6xGyQu0P5n6LH80mYeUAlntFR5bcGcG0V6f4fv2y5HjWtEdlXa5zRFdqm9CyMT5c+865xTz9uodrLcMJj1UCHppxriHhI9vT9URXGX88r9/48ef+TjHpgc2zQWIsM2i4HZ8G1sB8m5hwtMySd70cFp6j6/A6F8DvFdg67nIrE+3ORmBkTYJeMU9GMHaNJ6LJhatnRyJr6KCrqFeeQrODirdjIFWnXM4SkHrZ7pvTRLXc6YdmA5LgYopGGHAkh/AlbNr57H6hdjYos9cMO4AYv+W3zfPLHKi70X/cBjxn7+l10jgyJuDqO6T7XubsnLptlQ1bvxykI1x8fw4qvxvy85gPcK/DK5FgphbELFm3cJ66Y02P/DLzc9dzZF4xTcb8hzABDwPEfCvcanyzr4D9Oi+5kf9fIyb25GNCH/dfh7uLPJmijpOQCPfZr5IsVZc/xU0iay4Ofv9zDAyI2AtUtgsFONb6MtdoWeqttNh7bI+vuX6wZAJeG9oukOqrCildjeV2EaDc9aJVzVEnq24wXt3svioYYThFJ2kAZIg7OySAqMwa/dhzGFHrtid0mvVedgslG5p/qyyO+g3S5i35g3L4UE7McLEeIRVCtepJYmg2ADy6MHIJ0HAyRez5Cvd6JJFDjGUE3ZYorWt4/iDfwmk2zwPILBeQZ6cLaropbbhtEfE= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b822785-94ed-4111-b952-08d9bc5d990c X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:43.9113 (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: T60/A7aJQg/o5FPxiEzg6aTvfuzF47UcQrOe46hzJ0Rjn/i8biVyx7KDRRQ4zWMbDqScHGpUxAMHfBk2eR1UMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The AIA specification defines IMSIC interface CSRs for easy access to the per-HART IMSIC registers without using indirect xiselect and xireg CSRs. This patch implements the AIA IMSIC interface CSRs. Signed-off-by: Anup Patel --- target/riscv/csr.c | 202 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index a8d169e6f4..6bd15c1e7c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -875,6 +875,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; }; @@ -1027,6 +1037,177 @@ 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, xlen, 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 */ + xlen = riscv_cpu_mxl_bits(env); + isel = (new_val / xlen); + isel *= (xlen / 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 % xlen); + 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, xlen), + 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, + riscv_cpu_mxl_bits(env)), + 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) { @@ -2674,6 +2855,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 }, @@ -2708,6 +2896,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 }, @@ -2753,6 +2948,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 Dec 11 04:19:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E41DBC433EF for ; Sat, 11 Dec 2021 04:24:22 +0000 (UTC) Received: from localhost ([::1]:40406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtvq-0005v4-1P for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:24:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsT-00069c-B2; Fri, 10 Dec 2021 23:20:53 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsQ-0001kt-NQ; Fri, 10 Dec 2021 23:20:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196450; x=1670732450; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=Ca43ESS2+1FZjA4ratGOaQ0wK7DvoP9IjTkQxMgpfaU=; b=QkUgtt4vLJ7Und1/TfDh8/NMSs194mXS8EkbHUbEJjEsC6UBtDeMLa+G 9bBG8m9Du9GP0UlKoAiMEJoliViorqgcNbq+OYvcUCxfBBriqVAsBLFxw m1U6J9RMeoD65/8yd74hCaSHOUwaENiKzOEqq9WAPIS99EKCATUqM7V3u j/le2P5iCfa7e4unvim5ppc6scajLxJVHNYlmNVnLfwtwnON//qrUSxSG KXa+wuZnwxKAwsk9xKM52Cu3zo1WQT1gQNv3MD5TAaOoY20DTAS3TFESJ UjKL4CGcIvDxQmS2xqkkOC+nh7RUVXPbkuu+mgt0UxYlG1oTHi6kpVzFt A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834379" 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; 11 Dec 2021 12:20:48 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RrrtnQ42B0jG513uV8iTsaSgvpgMO4sk9cgN3nHV7MX4wBSlqd9v+EKhuTJqBw5Kc597amaqVaHLuZN6ANiBvRek+nkJKoBSi1kC8viCX6Sp4uGWGw4ULuggsK0ZKwUMdkYTcSThWIO2c7aIx4M+oKd5CT0YTeWJnhJmR+mrp2X5BWlSAjSrdqIRK5wK0BorGg4OQrbn9JfhqYg1ptLb3NHLIXv7lHK7T5MBjDXqWgg1Pfa9NHp5Ie82MCxDfieDFI7MesP2vQQSxzLl/VF3iAfPHdyiRCtgU0jiXeIrasyvB1DkrC7MEO+YiTm2K89om/hwc2XnQUVU/XsKkda2Ww== 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=x9Rh0/3dKyAHNU/NGWl9qvR6SPHWDoz+TuZ5h9es8Y8=; b=DWhHaM5OnaDmhOsHFKTgMNxgfGGKM5zZmP2GM+iTZWZv5sbshSGnei8DT/ZxwMOvFR88NUkTZpcXlm0C2Kg9oiyEZTdtKh67Kblf3YP1u4nIWxVHCdWW2z59OVnFoBnQmSvlUxfFp0kFqeshggBqYSjZdMbFKq8JhPimUFIqWlkKaBbUOO1w5V0YJACPC0WjqYVOEgXSThMhd9p8Lj95x/w0tCFU2s/sIGmM1ZNdqlgcVoegJIPrMYdsItNU474jmuHTAdU0ARmdB6FPlPc2ifYZ+G7zb0tDtvLtFKK/4ilQAXeBIUWasLl8lPQ1JvY6xHcMimjlPSEaC5T10SxMUw== 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=x9Rh0/3dKyAHNU/NGWl9qvR6SPHWDoz+TuZ5h9es8Y8=; b=HXtLDPCFSbCry1HotKcjTayfQP26iIFLzM/El2XeHLexCYQnuPeeEZtSK/rX24xB2X4eJTZiDP+Aw+mnX2hvSFP+hgdm7eVCY8wtD/GQAo+v634l8K7jmeFc3hXcwG4YwlY6h7UyyUuTCeh69mDJTZmkB0W1qBcPnIbC3ecrgzQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:47 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:47 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 16/23] hw/riscv: virt: Use AIA INTC compatible string when available Date: Sat, 11 Dec 2021 09:49:10 +0530 Message-Id: <20211211041917.135345-17-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3499239e-965d-4c38-718f-08d9bc5d9b1c X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: h8WmL5gQhnWjDBzUCfOUWtxbZ8Klss77KJmYffY88U8NqawF2067vTerK3aOrurnuUDedG0hytc+QBS/4YomGQhV6oaHOJEC+cTnQOlSpt4uvGx59NEMufx+K1a/0I3T6Rlnqo3mY6XpEmLRSqz3qk+Wu4p0TTgWUDXzPg2E4wd3SPZSHg1Jan5xJ+UznuohHc9o8AFCvdof8IOZjoTSHBHHgrQiwHcO0ONgPzp+tka75IIB+gbaVixerqdqOnjXpyZIC3k+iXljLUKpR8vsmOfz+GLbEqTt6exsPttR328m55f3RjxbJ9zFF8D1Cwusyq9it2RgJnynUV1JcW4ktEnNvlY8RQss43polDaG7rwQTttsL0POlVxkG26xgZGpz9pPdytgHAvitK+dWSNUYIk/in6o59spF2Zn4WhmV3Ldw5/6hw28VB3006c7wndleq6+PS+9p3Gm7Q0sJUgvsgbiG+uHSMPhDuYo8jw9NXiiLYKh41lAtlHhFCqyX/iPOlkKj0ZOkRgfUqGk89ytdTn/TPM/HMA9xFUAFJYq88+GXJf+33NKCzvFBMnl/UTxEZ528nPq8S1bNzDuafT04pYtfxoegMvtJgO1LpxDkCmuCaQG0ZwOJyuPLQSDe+d+hTYeFZGZeKA6O2gpS7kvNzYuXj9Kvp21S0MmuT4wbeQoIbNPyU3yzpYodtizyXFR 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2l1DpqP5s9Bwe/Ry46NQ4ZDWrKLJ6VD1MWsfPgSMWHBEIT9i1mPMxloCFk4PzVKn5oUxiM2Eaq27P5CbVpQKhNGXpBuZt+x1Ecnn5hxekAIzrtDW8h6HFO4SojOqhoQC57axHHRfcP27gTvkGCxJUqig8F7+s8W4Z275kEUk3VRdtME4pu/BhX4iBvKW0WC+cr4FjipgsRGvrNgQh9HZR7m4jzXaA6O/rqBgNRdZzrufw7UazAAQqz/DkEVAtAD3tYN/4SCkCUc1Y4s6ELLsnJQfjjNA3HnNKW78TArMiNvqmgeSmH6eBmiIssVbuVuH0s8u8i/zRvG4mbSA+OYNo/XH0WPAue/PsPs9JyX1sv2zG6/E/tJVv2A+bt0l08ku/IvhYU+fVXidmlEnMIwy1+GaeZvLWrc+D86nvgexkGsScIpB3nf8SXLcOrEUubZs9Gp/dGFbFHy3ymeOahT7cMiwJoQn3Vq10A+H3F+RiK/LfIN1q8gmOXtPXWDawUlPbV1AQ/T6rF778wQI6ET8SA4SMHEeZqKZPc/a9iMyZeBq+Uq2MtIMa4BauDv5GmYsNV3JJo+rR9q65Jt07YJm5RJIqvRk9p1tcRFuOYQG2FryBtOCaW/xOO4cI99Cs7vmkwF/aiJx+pHPtCkbNNTNB5r4vcZYReULjcDROkYawQsk6nd5Ny6r7Syn88q7syFrRx/6ZcfDtkVxVp8iz6MOxh7/yu7CpLnzufK/505O1LwqH8DQLltKJgbZGTfMuIBqv7tlxxcJurSaXHBTGcmRrTflaNsvuAO0WteNjH874s2BcaYc3+rP2PZuK8LYo3XVQUCHZJW9nHBW8mMozueYezbyFAQTEm8Qs6uN7DECmDjD7iL02rQ/nemEm6Fjq7Fz8E1UOGA4Dpjj7rm0hDRaAevu4A7mn7dajnT9eVJ8k28Ia3E8dc4x2BSPAXxxr9krI4ezt3BNR1kbpo60uOuMEB07eUNNOPJ+Jmf2npWwMsKUO6YlXqqw4ujnBiGeA+5SuIlG2P+M5uSL4A4ODrlmOhir0AJraPR9rHLTjFactAdqmmWojadsN6fARAKQqtdXtq+TRE4uy2YJsk+W1Gd5dPS+X6Jqyh4KK8RManz+JSeyUNXXLnoyhxyXbbENEO9Gw5z8gcXJp8b88RoihzwvoTJh5D+UXS4f30VP+zvG5mFdWxUrnWiYm6VbRpj3qHEtAfdAp6k0HJEJWS/ppmXiLSTJL67z2i2Ko9dNzlyAk7X5F+oB0Jr6524WPk+T7GUlDmkMHklb4SrumOEYv48DYNry58JxUk1R1suB6NRmhiSOyiCkGDDSVhUO2XVy0vMXqIxadzl80BcTqQH9DUZdusbj4gVmu3Std+u5NrPieJnlZEUxj9GRgN7B9Y8fOurE5WNk3EO5j/ZAxPmlM+g9AdNf34aaqiW69mDpqGIHp7p0sBLJrEt5Qy4+PD2dCju9Zgkvqw/SRDrgYwLkAnjKrinYS3wBS1HRVlTxqv32dTMS6iYD2RhwpGUFglqVS/8jYpwaPXCfQtk7+a8/wNfeyoNQXUtFIVh62+FFY+8Q1KcDGQ3gLpQBdW5947lno1Apzy9U2q1ZuSD1nNZ/xhW746rFe7RRu5hu8z5Pi0pE98c= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3499239e-965d-4c38-718f-08d9bc5d9b1c X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:47.1511 (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: hbXjfKFZpuBHW9io+mTtEMuuqq9qP+WSgzYgDnp122MBFwtjPxSTFzNBSazk+kk97HlBlCkvcyCo7bxle2WSWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We should use the AIA INTC compatible string in the CPU INTC DT nodes when the CPUs support AIA feature. This will allow Linux INTC driver to use AIA local interrupt CSRs. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 3af074148e..936156554c 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 Dec 11 04:19:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C11ABC433F5 for ; Sat, 11 Dec 2021 04:38:26 +0000 (UTC) Received: from localhost ([::1]:48982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu9R-00067O-OH for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:38:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsW-0006Ev-9h; Fri, 10 Dec 2021 23:20:56 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:25453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsT-0001kd-Kq; Fri, 10 Dec 2021 23:20:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196453; x=1670732453; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=BlkkmH3Qqoe2CvdNqWcrcRBZY7JHvDzwuKVGLXIPL8I=; b=HMJbPRe6xvcWwTdwrWKLUa95eHtpL4Swpe720syYgWwPYQRNIdWMdOas 4HmvOZsujWANiOZm1cRIKckYUtKlh5knIa6ohFY1+K1b5JuxqLHdko4Vz MQbL7LPDAueq3uks2F55TDPZMFtjQll6usT2Zx3hmMXCv3GI2K/oQjzIE yqZJuEG+2VkZcQMx7zv0GdPkwaMVc4k8jlSKqyv9GwmoYjhSmdvcXNXt7 qkqzhMByqbscdRdv2eOqB3BeO95VtYCf88H8aNEIN8Yr3aLBF7UJWd4Cy qDRzq8cDfLgG4K1OFCBeF7SO/PmR7mLSMuxOGBsOSWj02C+9VM/KnbuN/ Q==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="299834382" 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; 11 Dec 2021 12:20:51 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VVVr25qlRB68wxu88Dty15zcTmecT4aHHHVUv3R3tJlDDWYGtOrTAvvdKkr5Ydn/dXyuTWrLVk7I3xi50YnK5194wJ38CA3QMLrMP/Ywce5CWAKEPM7qam3lA4i/0sdUPUlhd5whqBR678CLJnSYVXixSHTVgqB2+iWrqjWsXMxkCCKGiC9rIGy1FpS1MQR2jAHFtLSOzuemerzDSm+rA3bpJGUQ3nx7d5S+R6gX1BOdSAbtdaOeinxjdq5YrXQh3stj+kk86hUMa1cDa7tl5E5i5nY491YxcJ+lfiIgFL6q6Drii7kG6lRgeHcRcvAVjABbuwyLBpse6Lc/F7QCuw== 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=D/WpKizTvuokegO3I2DXCYUcJ6CKYjAE6XW1wzbhRqs=; b=WN54pFbq30orDZydOg5lnnkWpvoOGRRlQWYFRHOiaNHou0yufTFwjqcGaZxHWVmv6Ragde3Xwpd6cjrkcMWXPvlx6h5SMrOamKwosKnB8gdVyz38u34xsuv+hGqsQvmq0YnNLByAfUkwZzF7HgnjdWC4qVTJGtGtT1ua2vo5Clzm/wwQKbyq/QzyyjGCJreugXaQ7WUkiUiK9ykYoCdkLkM4Cv0NVIdQkU/ZKBCznODHrQFvMhlY2tCxtAkQRNj5ucvkf3DRUAA0gNzzoCyFLxopdPCSMZOd/LAujj7UAkKAfJD0GgX8MIEHiNaTx/0YtoZLS0b1pKIeqFjJFXabKA== 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=D/WpKizTvuokegO3I2DXCYUcJ6CKYjAE6XW1wzbhRqs=; b=esVQLeP+yA6ShE2sqYzKriNAuLuSEHEcfalnx+HschamcrmjAf7nzjtQQV7ayeRffAzSR8mEfQy2E+OwMzypyNp7+8o53B9q7YBFcXol89uQlPTDAgxEhJeDG7W9U8T+SoGgliuZF/QMaVgVabI8Kdyq2rW7YRm46R3e55anlnU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:50 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:50 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 17/23] target/riscv: Allow users to force enable AIA CSRs in HART Date: Sat, 11 Dec 2021 09:49:11 +0530 Message-Id: <20211211041917.135345-18-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e6a9a9dc-4c1b-48fb-84be-08d9bc5d9cfe X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: fQKaebsuiwpViadfvsTyWMivRmrQtVG7bHHmgDHXqR/zXENagd1By6rRheAlC8L5cAi0pqqAvy4ShMfSVjZr4thQaX+tVHqTUb1EtejYfonDz2CF7royNrQG1CFowl8ydvemr4/xWJd8HjsxdmF5F8kYdxIJZhLkIaxz0weXJwbovYpisUb3/3rSzGG5VW7OQhAhOO8YJw6d8peorrwCp3TTHfikaSMyBPiQMD5YJZIFaE4Bfy+3FLovYjMvJqv1eqIngFWY1KJQVKzORaWZui+ANZ/SQKQy82aQFTWADUX9JLFblHCAiRty/pf5enKwZLWT1bRGze5bjLU0fQMPkl+Rq50XJj4wbxo2jd2g/BHc4en67nXR53WOs1ZwIwfudgkrSxWJoNiwahRGvf+2HJvmbuLEIeH3whaG7pBhAcSP+KuTUBb7HkGGKOqq8a9F6zdsC4BEAWLQBnyZv5GfO/t7B9eAyPs0PeTWAmonqmP3AaQS8wYG6z0vLrpaP7HgqqXPhxn3w5RfnYUutVppTEEe3Wub7VQruaBmMOvgPP95++hqAkf3s/6UOK0nSI7B0M0sEJ+sZMgvk7WXfUlNCFn9vKrSPbbXM2asA3fQFJRkIflqTyQvEjxAQgOh/c65Es0zCpkOoWGIII4ThGqnEZUUEYOG4iLKtT+OJCzUjtT9BY50j6pNbO9uMTu6ast5rwjN7hotc16x5yWTn73PxA== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oD9E+e4KQjYBJvYvpSBdUcqXpaUhgZE7gUmern9kKpX46rpsQdiJnjEUkVjIyv4YOSN8KJqFeU91wSkXZFHNpIYYKRYh5WTh/2RaLF/AN5Qwkn8sW4pW9HbraBvdjbiiyjh1ozWD9ZOJZHRk4XVRdEKQ+0cZ2RvdP63fOz+1sIgILyIUcOcvelH1rEk1S/hNpxo25YlMlh4G8XSFCOO7aG8CK/35SvZroesBvqG5ZhCOoJEMqGu0gz0DIdNPj2BG+bcYGvKVsiNDqjJYzKkNaEF52kkfUSMHn865lnm4LaNg7t9IrjLBNZUKBrAPJR8m6SOTd3hvfRd3MUGFSVkhrI5ZiW+RZbXtOgtAVrbzZK/f3vZJ2S11qm5Lk1k7Omn1L9zIs+UQ+2TxVK9smpU0ZQZIY5ncJaanYxEmeVlG1043xyQ40PT3bZ7301JmQJbArNY+HRlj1BCBrr02KdeRudB1M9lLYHg2Oli+blqKj6PjdudyNZA4QowCfuR8zceqxZ4Cl/uYT26jz9fv90vVSQ3QUKDLEKl+x3RBRPjGryA0bhRgKu6T2bNYYU0dRM5Lp1v4zC2hrM7DiWMW2kQXpR/McRabPIxTTX/prCwga83AEHs6Xv1r1S0rQpNQnZI2LCp3wv9BWhYLjzLIujinj+/Pty2N04LlBgxfo6zQgotX7+Mg12gh9rW7VG+CDx4068nJAbx9UWTu9tPfnheNTe/QCVIZNztKlrJKzbWw+RaGFcjbZ0OUTE8+C8pDBK8A+zNPdKJrIN0xif7h7AZKGBie2hr7U6++6gZOf1vbhuJ1FlrbB8iEJnXKEKDB8teB+Yxt2U8e0fmfWIGYA2Ah1Y2hyqBs15k6+eziuPk8Pl/zOaSY3/7SmMG42AapIWI8mp35wwkMcFGChbBPByaBZozi3cnpgV535tNLBLb5Pl7rgyw/M3Ycx9infuK6r/zuNbX2FT4Yhrkp2Dg2aF4gitbxE54xJiO5czNgeGn/Sq/lABHeoOirMiOHmYWalODtLh8wAgw8wf10YBxqgUgxC4iwDlN2EF2NN6LQojkraRpwcUq+bVX/1Zb8KVSNboxAyAnqAA7pqoOp4nmaBGVuk0BlaHZx21QPc81SCVL5QXKtyDu5SpyynqG2IU1Kk3WHpv4K9SJZRbbRkoO5dvCb5w3p9WTmAZugSqKM/6pacC2H09Sq9KA9GcZ6saNkAAB2MLXzSBhSa/5Xes1jO4Xa4I1Os/ijN7nNvZYT6Nb1OG0Xb0xVPVOCZ0Tox3PcdlmdufRG3700zAEmYQs1s5EYL4i8bUslGFVCSWNyBvm8kpAKB1YTkpOJGb3e0X9ZiuRBegedlYYw0VQDjBaQCxjAY3Ui09qDj/ksC0qYMuAr9XBvzSw+IkEB1xjhbV42hwl1hprQgp64JIhc580ntsT0s7CsRbR1NNIYwSBUHjc4TvWDOx6WOUrTeH8rzMecAQunDpOH93OLkJHeCZaERMVNX6GlMpjVYQn4JX6iols/En7dsQQN+KWo08faGv1oSnYciDo+4HpHFHRp/H32hEjgiPPsdExHatpzqr0HZc92i7XX0J5dZafgBKI+YlWW23B12Y9UIAgxco7fxCel4bl8TLucE9Sef3ABkgS9FmtEcGg= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: e6a9a9dc-4c1b-48fb-84be-08d9bc5d9cfe X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:50.5291 (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: 8MTR5uKLGUQhPRf9CTXFM0/DE8zjgN0P8fWmDXeW8CetnC/rtn7mdWPL9St2Z10ras5wvst3vUxVsorqzCWBJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=68.232.141.245; envelope-from=prvs=972e533d7=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, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We add "x-aia" command-line option for RISC-V HART using which allows users to force enable CPU AIA CSRs without changing the interrupt controller available in RISC-V machine. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 5 +++++ target/riscv/cpu.h | 1 + 2 files changed, 6 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 916319afcd..4042839785 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -463,6 +463,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. */ @@ -689,6 +693,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 a43e38dd2e..d03a90e277 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -357,6 +357,7 @@ struct RISCVCPU { bool mmu; bool pmp; bool epmp; + bool aia; uint64_t resetvec; } cfg; }; From patchwork Sat Dec 11 04:19:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 71DABC433EF for ; Sat, 11 Dec 2021 04:39:58 +0000 (UTC) Received: from localhost ([::1]:51242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvuAv-0007hE-KP for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:39:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsc-0006fa-I4; Fri, 10 Dec 2021 23:21:03 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsY-0001mA-8n; Fri, 10 Dec 2021 23:21:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196457; x=1670732457; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=+36KBvgqrGfN5+wmlXT52UMAsfg9KJ/2Nw1KGvzjR60=; b=mL8uceAUucvBewLMzVLzz7DEGABZS7YXJ6TRestxsYmIBEeZHBrfMLvD b887KdD0dgd4PVZ8Ykp8Z4qGyKveYYRw5B4uy4QtWwnlI0/KPbXClcePu qjzYCB5+WxLZlOkBOm1Oi1Hl4xDkA7IL0Tv/VoLODf0o/eTfCQwzMreDz Oyc/DlJjOh5DjkLMtSeg42XJJ+nk0J0CwLkf+RT1dQSiRE/ODiKpzI17M b1EXuvrP1l7tGRxXs3l8/ZNRQ6aZYiqT84Irv4PU4djj7s9UsZfBh1hd5 xfv+d0vLfHgGVeHdDFLOiMR3O9a/Y1eDxMHmcun5bJyxXoarstfJjZ8u5 Q==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989955" 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; 11 Dec 2021 12:20:54 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FtC3NSLH6Xo8fcFq/ptIjZQjSTmHpPdd1q1oIf+MJBm7PxqQObJMJsqAIPgzZpr5V3hfufb8EylvU0iwCsZDb3tk4FgFGeqcsq5b/fNZfu/sWXV9vGw4OJc0WqKUEFtfYPF8v7PGe19tSG19wUC6+2zzDh7RImJPjNWKZaKfRmb230f/STrf4R9TlTHR/RscWSiJWDG/cjGRrTemIOtIrN8Sla0RyXQdJ6B+SyS5ikbBNrTrscJORbcQ4z6hhcO8E/bMElkKwKoRqmt1pVUdp1CJa1PQ0DqJrYMNSJkTp08ufbNTaX5+DsCwyxkMK3my9F7Dwcph2GZIopRqR7dqFw== 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=x18SoAZ7f2qiDTNXNU6Z7fMNlWWQqFgt65cR2MfEEX8=; b=fi7o6TIes5mTrtN7elcAt8mbDZr8hEe3//mQq++FJD/g0MRKjtb+RrsLin9SJ/7MNCG0ohgGE6TLpIzVaWI/mGNM8m7bRSrgwqHSKWtm36SILG/8B7mN7XHPRAgprtjZ0y/WhnWmv5Mq38pk0hYPvT7RZTuQo9SqEkF13gNggoxUsCqBfUu3RsthzI+zZM74L+h0VjalEZSWtz4dtpIvc8++k/fAUx97f8Pa+Nmd0GNJUiizMyoZ7wTbcJf02JERBtLAVOWZabSKPKWpBct0SJ3/2jmaNLd4NML34+uB1bFPG+V83Zcybm+BsReAJuZ4PInrdimPkmZO9m53KthiIQ== 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=x18SoAZ7f2qiDTNXNU6Z7fMNlWWQqFgt65cR2MfEEX8=; b=hOOIsQYuh9t4RuAt45f67MmOZixF6fVTFqhTV/GBYWN5FGYqFfo+B8pHR80GnxFuMyNjLXexWbg9DTdFqcOwnAD14TJRy1SstodH9n4bUqoAF7TXjByjt05dvcidEiMn0V/ykV31yGw5eYatWWZo7KXEw3SO1ZD0MGRvqchlitg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:53 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:53 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 18/23] hw/intc: Add RISC-V AIA APLIC device emulation Date: Sat, 11 Dec 2021 09:49:12 +0530 Message-Id: <20211211041917.135345-19-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c6e2e480-0b90-4fe0-7bdf-08d9bc5d9f06 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: 190vrCqHbJR66uXDZxeYpoZVFZ3B5jYJ62WBzbnvBMOQZeb6z+GM4BLDCOg8IQRK6W22PcsX1wOYpqb4As/lUv7iJ9eVWV0DAsqoC2BpPeInorTYQdBv8bm5C48tvJ0XKdw5Vpy9fwik6qBtqfk9ycd9t0mWuEaa6gJW27uf/v/g21xqSeviiGZqJjUyaXe1tEGbodr5XqiBcrKgBF0CWMTUBddNliRBD946E4Xn4IUAkLCFWKa1jCqk7xOTWG1G2ydfyyvUnNvCp0JB/SJ6BoPt5CnUaab0eWSAwGmwGN/fEHp7QQe8kwRQnEgsmYmDwdMlSpoZ19Bye2u79mfmyjw2akbvUPZ686Bi3MlekcRznCGwGjtRm+6SowQrhJR+KwwChVtQ28aVZIWhpVKZVBCqFacWbZUg77tYQgcteHKCHaySSOoXd1tZNGAoFh8GhvB8gOpbNmsgc6wb4ypBqVROZ5SycZ6s0Ott0BTLKP6WdkNI+cSMDNlZGJECWCZdlwJjouToj796zUfE0htETySRLq44Iz/v6bF9VXVF7gcaw/E/ohJ7sJzqytmzvCknQu2Cd55GNalpn7EKHA9yYtl/dNovQ+EXRV10R2+n4QAQzPh1lC6/Ix/wPUjjUVFLHV5NP0roSt4uwQkwYOvxLAYHuY84Ibp5zTN6lXoP4xO7D5L5pB3C99itJP/vN2312eM2WKlrTq0qPI6n8ORFPD09GSRMyuYwT+tP+3+puzuwKiVU4LNjLtFY1en9ZjRE2lNQA/kdzGj5GOv4magJJIUAQ6Qo+rdHZMRRTyGei4A= 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(30864003)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eoNH1mLmFOPuBi/oNZp2ZienTdSyXtDnrVtc2V1714MXOYqyHbKBQF7f4g2KeEaaA7aekIExtnuxTNshfXSeC3biPM9SxpRH3YV/mE1SN93q14j7DOWOpomwNPMqyJ3QMY5w4KGctjeRhWuhMdWqvVj3PQOfGL8jRFqnmDxxliJ2TK6m0mWs+DI+dhM4vu03mhQbTVzhrEqCqWm/ISRJdE01uc1S4xLgMmJRSl5Iq1JRR72WTATJVHAFEUvrnAh065XmmP5tajpkewfWLO/wv1QU1Pz6c/Qp/BTxMvCCHLDhL8HsPpd7e/jN2wddKVvWsfCi0AYudRAQbEP41CoWDaT9Izpamk2qqYBEH2k5Soe24O1TNaWW7aLLb1W+SGCzo8Dd7wpu+iJbuWctxIVPA7I42v8MVq+seDLBkQ9R/IotmNXm6UlIxmUssy0oVGvjRrUy1X23vf1WYxlL4vbsf8yeqC6FumehdJ9U4MbyGAdyg0a6sZD1LRziFuJbpltlxhSpRtn42I73XXXjqEAu19sV9M/W4ay/XQqLhmAR+xCStVTNc/BIpM411OqlpJcOVtnfznVeLRuXkYWX0B9OvoPRkXvjbqgWfB/VeHeIeghKO0V4K3DkMkMYWa+1jYS1YLizLA6gwACHUfTExRhA5jkO9ADOQ1utxyEpkeq3jUHIR1RbVYpHnwzySNqXVRquOOIAUYo4YXq5bN/rw4lRcq+4y9ghJ9Mqd0zNypzu5p9fjqeDkocD7Pa3/gnuJr6CqYa3XVVVkFK97NbLClyHZmiIMI1BXSTP8EKiBv1EHbZiOMvY+r9DAn3ZBB9SUgj4QULL7CR13xCbjg4jWVrr3UTQzagNtifQVvBJR5xEDUWc23cARHlAM0JVcMiBN4T5rhxdVYnjc8UIG4FmwkGpkjFre+VgTWsmLIEt6RNXz4L2xdQU9RQ7Lv1EJDVh2D0kNmnGykhk2GR9xaM36KKtqeCKKp1jlGzWUvQNW1qwWrVJOP6mvSQFrw98apwbQ5h7Be81pjNf/hHbSqjSpb6v3paLjbXAZN3+kG7yiNgcUg1IRsG97NLdIafJsepRJq3EPVvMWz0ymlUxCb6ApWfzuNQgzLFX7AJE2YecNl2fYn8Tz55nLmAD6oXFTCL6kpge7+urJUS+LAWsAK3Nv+iR+euQj04S6nTwBUmIwypa9C/kyj+VwoOUtSN/skLPAuOa2UGwC3wxbJBYT8yc+6LV5kYwJffsQtTMP8qWEcREN/Xo7SHW5YYeJzlFRIdUOz50wPA5v6X9/LvET69B15LmVgWdY+Ln+Gir0WRX+fCuECzPpKWsjF6D2p1bTvkHXqbF8lcPlv5LRRZglNMJ/haqwyftywXe9WA4ZbDkGsO08bURxJW1Wxx0bR77dN51Ir4EvZ32u5iGJtVnZKJ4pe0fhpHGbjqhaqM9bblmUQE8zEpk5QXj105Pz1RStCL8pxpATYPpi8v9OypUKYDgnOTNlwpiFZj/kvVk0XhWRFUMegW/rfZg9S8y6o1PHIKJFFueQS9Kg3XGu9Kqnd+YvUm/6DdiyBKicB4dSP7qKrICoezhHHOhjm9oA0VySU+FUOTl+26n+n3kvK/ooR3N3o7L7Ml6sot7qpSyR33c5o1vnqY= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6e2e480-0b90-4fe0-7bdf-08d9bc5d9f06 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:53.7180 (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: KKMU91wG6l02asCGYOlF4WeS5cG6MG3r85+78D61MqnynwiTG69g94ehk5pI8LFops2wbTxix883+w9xSrL8WQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for wired interrupts called APLIC (Advanced Platform Level Interrupt Controller). The APLIC is capabable of forwarding wired interupts to RISC-V HARTs directly or as MSIs (Message Signaled Interupts). This patch adds device emulation for RISC-V AIA APLIC. Signed-off-by: Anup Patel --- hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/riscv_aplic.c | 970 ++++++++++++++++++++++++++++++++++ include/hw/intc/riscv_aplic.h | 79 +++ 4 files changed, 1053 insertions(+) create mode 100644 hw/intc/riscv_aplic.c create mode 100644 include/hw/intc/riscv_aplic.h diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index 78aed93c45..1592623233 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -65,6 +65,9 @@ config LOONGSON_LIOINTC config RISCV_ACLINT bool +config RISCV_APLIC + bool + config SIFIVE_PLIC bool diff --git a/hw/intc/meson.build b/hw/intc/meson.build index c89d2ca180..77b068f673 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -47,6 +47,7 @@ specific_ss.add(when: 'CONFIG_S390_FLIC', if_true: files('s390_flic.c')) specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) specific_ss.add(when: 'CONFIG_SH_INTC', if_true: files('sh_intc.c')) specific_ss.add(when: 'CONFIG_RISCV_ACLINT', if_true: files('riscv_aclint.c')) +specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'], diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c new file mode 100644 index 0000000000..f4b8828dac --- /dev/null +++ b/hw/intc/riscv_aplic.c @@ -0,0 +1,970 @@ +/* + * RISC-V APLIC (Advanced Platform Level Interrupt Controller) + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/error-report.h" +#include "qemu/bswap.h" +#include "exec/address-spaces.h" +#include "hw/sysbus.h" +#include "hw/pci/msi.h" +#include "hw/boards.h" +#include "hw/qdev-properties.h" +#include "hw/intc/riscv_aplic.h" +#include "hw/irq.h" +#include "target/riscv/cpu.h" +#include "sysemu/sysemu.h" +#include "migration/vmstate.h" + +#define APLIC_MAX_IDC (1UL << 14) +#define APLIC_MAX_SOURCE 1024 +#define APLIC_MIN_IPRIO_BITS 1 +#define APLIC_MAX_IPRIO_BITS 8 +#define APLIC_MAX_CHILDREN 1024 + +#define APLIC_DOMAINCFG 0x0000 +#define APLIC_DOMAINCFG_IE (1 << 8) +#define APLIC_DOMAINCFG_DM (1 << 2) +#define APLIC_DOMAINCFG_BE (1 << 0) + +#define APLIC_SOURCECFG_BASE 0x0004 +#define APLIC_SOURCECFG_D (1 << 10) +#define APLIC_SOURCECFG_CHILDIDX_MASK 0x000003ff +#define APLIC_SOURCECFG_SM_MASK 0x00000007 +#define APLIC_SOURCECFG_SM_INACTIVE 0x0 +#define APLIC_SOURCECFG_SM_DETACH 0x1 +#define APLIC_SOURCECFG_SM_EDGE_RISE 0x4 +#define APLIC_SOURCECFG_SM_EDGE_FALL 0x5 +#define APLIC_SOURCECFG_SM_LEVEL_HIGH 0x6 +#define APLIC_SOURCECFG_SM_LEVEL_LOW 0x7 + +#define APLIC_MMSICFGADDR 0x1bc0 +#define APLIC_MMSICFGADDRH 0x1bc4 +#define APLIC_SMSICFGADDR 0x1bc8 +#define APLIC_SMSICFGADDRH 0x1bcc + +#define APLIC_xMSICFGADDRH_L (1UL << 31) +#define APLIC_xMSICFGADDRH_HHXS_MASK 0x1f +#define APLIC_xMSICFGADDRH_HHXS_SHIFT 24 +#define APLIC_xMSICFGADDRH_LHXS_MASK 0x7 +#define APLIC_xMSICFGADDRH_LHXS_SHIFT 20 +#define APLIC_xMSICFGADDRH_HHXW_MASK 0x7 +#define APLIC_xMSICFGADDRH_HHXW_SHIFT 16 +#define APLIC_xMSICFGADDRH_LHXW_MASK 0xf +#define APLIC_xMSICFGADDRH_LHXW_SHIFT 12 +#define APLIC_xMSICFGADDRH_BAPPN_MASK 0xfff + +#define APLIC_xMSICFGADDR_PPN_SHIFT 12 + +#define APLIC_xMSICFGADDR_PPN_HART(__lhxs) \ + ((1UL << (__lhxs)) - 1) + +#define APLIC_xMSICFGADDR_PPN_LHX_MASK(__lhxw) \ + ((1UL << (__lhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_LHX_SHIFT(__lhxs) \ + ((__lhxs)) +#define APLIC_xMSICFGADDR_PPN_LHX(__lhxw, __lhxs) \ + (APLIC_xMSICFGADDR_PPN_LHX_MASK(__lhxw) << \ + APLIC_xMSICFGADDR_PPN_LHX_SHIFT(__lhxs)) + +#define APLIC_xMSICFGADDR_PPN_HHX_MASK(__hhxw) \ + ((1UL << (__hhxw)) - 1) +#define APLIC_xMSICFGADDR_PPN_HHX_SHIFT(__hhxs) \ + ((__hhxs) + APLIC_xMSICFGADDR_PPN_SHIFT) +#define APLIC_xMSICFGADDR_PPN_HHX(__hhxw, __hhxs) \ + (APLIC_xMSICFGADDR_PPN_HHX_MASK(__hhxw) << \ + APLIC_xMSICFGADDR_PPN_HHX_SHIFT(__hhxs)) + +#define APLIC_xMSICFGADDRH_VALID_MASK \ + (APLIC_xMSICFGADDRH_L | \ + (APLIC_xMSICFGADDRH_HHXS_MASK << APLIC_xMSICFGADDRH_HHXS_SHIFT) | \ + (APLIC_xMSICFGADDRH_LHXS_MASK << APLIC_xMSICFGADDRH_LHXS_SHIFT) | \ + (APLIC_xMSICFGADDRH_HHXW_MASK << APLIC_xMSICFGADDRH_HHXW_SHIFT) | \ + (APLIC_xMSICFGADDRH_LHXW_MASK << APLIC_xMSICFGADDRH_LHXW_SHIFT) | \ + APLIC_xMSICFGADDRH_BAPPN_MASK) + +#define APLIC_SETIP_BASE 0x1c00 +#define APLIC_SETIPNUM 0x1cdc + +#define APLIC_CLRIP_BASE 0x1d00 +#define APLIC_CLRIPNUM 0x1ddc + +#define APLIC_SETIE_BASE 0x1e00 +#define APLIC_SETIENUM 0x1edc + +#define APLIC_CLRIE_BASE 0x1f00 +#define APLIC_CLRIENUM 0x1fdc + +#define APLIC_SETIPNUM_LE 0x2000 +#define APLIC_SETIPNUM_BE 0x2004 + +#define APLIC_ISTATE_PENDING (1U << 0) +#define APLIC_ISTATE_ENABLED (1U << 1) +#define APLIC_ISTATE_ENPEND (APLIC_ISTATE_ENABLED | \ + APLIC_ISTATE_PENDING) +#define APLIC_ISTATE_INPUT (1U << 8) + +#define APLIC_GENMSI 0x3000 + +#define APLIC_TARGET_BASE 0x3004 +#define APLIC_TARGET_HART_IDX_SHIFT 18 +#define APLIC_TARGET_HART_IDX_MASK 0x3fff +#define APLIC_TARGET_GUEST_IDX_SHIFT 12 +#define APLIC_TARGET_GUEST_IDX_MASK 0x3f +#define APLIC_TARGET_IPRIO_MASK 0xff +#define APLIC_TARGET_EIID_MASK 0x7ff + +#define APLIC_IDC_BASE 0x4000 +#define APLIC_IDC_SIZE 32 + +#define APLIC_IDC_IDELIVERY 0x00 + +#define APLIC_IDC_IFORCE 0x04 + +#define APLIC_IDC_ITHRESHOLD 0x08 + +#define APLIC_IDC_TOPI 0x18 +#define APLIC_IDC_TOPI_ID_SHIFT 16 +#define APLIC_IDC_TOPI_ID_MASK 0x3ff +#define APLIC_IDC_TOPI_PRIO_MASK 0xff + +#define APLIC_IDC_CLAIMI 0x1c + +static uint32_t riscv_aplic_read_input_word(RISCVAPLICState *aplic, + uint32_t word) +{ + uint32_t i, irq, ret = 0; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + ret |= ((aplic->state[irq] & APLIC_ISTATE_INPUT) ? 1 : 0) << i; + } + + return ret; +} + +static uint32_t riscv_aplic_read_pending_word(RISCVAPLICState *aplic, + uint32_t word) +{ + uint32_t i, irq, ret = 0; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + ret |= ((aplic->state[irq] & APLIC_ISTATE_PENDING) ? 1 : 0) << i; + } + + return ret; +} + +static void riscv_aplic_set_pending_raw(RISCVAPLICState *aplic, + uint32_t irq, bool pending) +{ + if (pending) { + aplic->state[irq] |= APLIC_ISTATE_PENDING; + } else { + aplic->state[irq] &= ~APLIC_ISTATE_PENDING; + } +} + +static void riscv_aplic_set_pending(RISCVAPLICState *aplic, + uint32_t irq, bool pending) +{ + uint32_t sourcecfg, sm; + + if ((irq <= 0) || (aplic->num_irqs <= irq)) { + return; + } + + sourcecfg = aplic->sourcecfg[irq]; + if (sourcecfg & APLIC_SOURCECFG_D) { + return; + } + + sm = sourcecfg & APLIC_SOURCECFG_SM_MASK; + if ((sm == APLIC_SOURCECFG_SM_INACTIVE) || + (!aplic->msimode && ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) || + (sm == APLIC_SOURCECFG_SM_LEVEL_LOW)))) { + return; + } + + riscv_aplic_set_pending_raw(aplic, irq, pending); +} + +static void riscv_aplic_set_pending_word(RISCVAPLICState *aplic, + uint32_t word, uint32_t value, + bool pending) +{ + uint32_t i, irq; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + if (value & (1U << i)) { + riscv_aplic_set_pending(aplic, irq, pending); + } + } +} + +static uint32_t riscv_aplic_read_enabled_word(RISCVAPLICState *aplic, + int word) +{ + uint32_t i, irq, ret = 0; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + ret |= ((aplic->state[irq] & APLIC_ISTATE_ENABLED) ? 1 : 0) << i; + } + + return ret; +} + +static void riscv_aplic_set_enabled_raw(RISCVAPLICState *aplic, + uint32_t irq, bool enabled) +{ + if (enabled) { + aplic->state[irq] |= APLIC_ISTATE_ENABLED; + } else { + aplic->state[irq] &= ~APLIC_ISTATE_ENABLED; + } +} + +static void riscv_aplic_set_enabled(RISCVAPLICState *aplic, + uint32_t irq, bool enabled) +{ + uint32_t sourcecfg, sm; + + if ((irq <= 0) || (aplic->num_irqs <= irq)) { + return; + } + + sourcecfg = aplic->sourcecfg[irq]; + if (sourcecfg & APLIC_SOURCECFG_D) { + return; + } + + sm = sourcecfg & APLIC_SOURCECFG_SM_MASK; + if (sm == APLIC_SOURCECFG_SM_INACTIVE) { + return; + } + + riscv_aplic_set_enabled_raw(aplic, irq, enabled); +} + +static void riscv_aplic_set_enabled_word(RISCVAPLICState *aplic, + uint32_t word, uint32_t value, + bool enabled) +{ + uint32_t i, irq; + + for (i = 0; i < 32; i++) { + irq = word * 32 + i; + if (!irq || aplic->num_irqs <= irq) { + continue; + } + + if (value & (1U << i)) { + riscv_aplic_set_enabled(aplic, irq, enabled); + } + } +} + +static void riscv_aplic_msi_send(RISCVAPLICState *aplic, + uint32_t hart_idx, uint32_t guest_idx, + uint32_t eiid) +{ + uint64_t addr; + MemTxResult result; + RISCVAPLICState *aplic_m; + uint32_t lhxs, lhxw, hhxs, hhxw, group_idx, msicfgaddr, msicfgaddrH; + + aplic_m = aplic; + while (aplic_m && !aplic_m->mmode) { + aplic_m = aplic_m->parent; + } + if (!aplic_m) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: m-level APLIC not found\n", + __func__); + return; + } + + if (aplic->mmode) { + msicfgaddr = aplic_m->mmsicfgaddr; + msicfgaddrH = aplic_m->mmsicfgaddrH; + } else { + msicfgaddr = aplic_m->smsicfgaddr; + msicfgaddrH = aplic_m->smsicfgaddrH; + } + + lhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXS_SHIFT) & + APLIC_xMSICFGADDRH_LHXS_MASK; + lhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_LHXW_SHIFT) & + APLIC_xMSICFGADDRH_LHXW_MASK; + hhxs = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXS_SHIFT) & + APLIC_xMSICFGADDRH_HHXS_MASK; + hhxw = (msicfgaddrH >> APLIC_xMSICFGADDRH_HHXW_SHIFT) & + APLIC_xMSICFGADDRH_HHXW_MASK; + + group_idx = hart_idx >> lhxw; + hart_idx &= APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw); + + addr = msicfgaddr; + addr |= ((uint64_t)(msicfgaddrH & APLIC_xMSICFGADDRH_BAPPN_MASK)) << 32; + addr |= ((uint64_t)(group_idx & APLIC_xMSICFGADDR_PPN_HHX_MASK(hhxw))) << + APLIC_xMSICFGADDR_PPN_HHX_SHIFT(hhxs); + addr |= ((uint64_t)(hart_idx & APLIC_xMSICFGADDR_PPN_LHX_MASK(lhxw))) << + APLIC_xMSICFGADDR_PPN_LHX_SHIFT(lhxs); + addr |= (uint64_t)(guest_idx & APLIC_xMSICFGADDR_PPN_HART(lhxs)); + addr <<= APLIC_xMSICFGADDR_PPN_SHIFT; + + address_space_stl_le(&address_space_memory, addr, + eiid, MEMTXATTRS_UNSPECIFIED, &result); + if (result != MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: MSI write failed for " + "hart_index=%d guest_index=%d eiid=%d\n", + __func__, hart_idx, guest_idx, eiid); + } +} + +static void riscv_aplic_msi_irq_update(RISCVAPLICState *aplic, uint32_t irq) +{ + uint32_t hart_idx, guest_idx, eiid; + + if (!aplic->msimode || (aplic->num_irqs <= irq) || + !(aplic->domaincfg & APLIC_DOMAINCFG_IE)) { + return; + } + + if ((aplic->state[irq] & APLIC_ISTATE_ENPEND) != APLIC_ISTATE_ENPEND) { + return; + } + + riscv_aplic_set_pending_raw(aplic, irq, false); + + hart_idx = aplic->target[irq] >> APLIC_TARGET_HART_IDX_SHIFT; + hart_idx &= APLIC_TARGET_HART_IDX_MASK; + if (aplic->mmode) { + /* M-level APLIC ignores guest_index */ + guest_idx = 0; + } else { + guest_idx = aplic->target[irq] >> APLIC_TARGET_GUEST_IDX_SHIFT; + guest_idx &= APLIC_TARGET_GUEST_IDX_MASK; + } + eiid = aplic->target[irq] & APLIC_TARGET_EIID_MASK; + riscv_aplic_msi_send(aplic, hart_idx, guest_idx, eiid); +} + +static uint32_t riscv_aplic_idc_topi(RISCVAPLICState *aplic, uint32_t idc) +{ + uint32_t best_irq, best_iprio; + uint32_t irq, iprio, ihartidx, ithres; + + if (aplic->num_harts <= idc) { + return 0; + } + + ithres = aplic->ithreshold[idc]; + if (!ithres) { + return 0; + } + + best_irq = best_iprio = UINT32_MAX; + for (irq = 1; irq < aplic->num_irqs; irq++) { + if ((aplic->state[irq] & APLIC_ISTATE_ENPEND) != + APLIC_ISTATE_ENPEND) { + continue; + } + + ihartidx = aplic->target[irq] >> APLIC_TARGET_HART_IDX_SHIFT; + ihartidx &= APLIC_TARGET_HART_IDX_MASK; + if (ihartidx != idc) { + continue; + } + + iprio = aplic->target[irq] & aplic->iprio_mask; + if (iprio >= ithres) { + continue; + } + + if (iprio < best_iprio) { + best_irq = irq; + best_iprio = iprio; + } + } + + if (best_irq < aplic->num_irqs && best_iprio <= aplic->iprio_mask) { + return (best_irq << APLIC_IDC_TOPI_ID_SHIFT) | best_iprio; + } + + return 0; +} + +static void riscv_aplic_idc_update(RISCVAPLICState *aplic, uint32_t idc) +{ + uint32_t topi; + + if (aplic->msimode || aplic->num_harts <= idc) { + return; + } + + topi = riscv_aplic_idc_topi(aplic, idc); + if ((aplic->domaincfg & APLIC_DOMAINCFG_IE) && + aplic->idelivery[idc] && + (aplic->iforce[idc] || topi)) { + qemu_irq_raise(aplic->external_irqs[idc]); + } else { + qemu_irq_lower(aplic->external_irqs[idc]); + } +} + +static uint32_t riscv_aplic_idc_claimi(RISCVAPLICState *aplic, uint32_t idc) +{ + uint32_t irq, state, sm, topi = riscv_aplic_idc_topi(aplic, idc); + + if (!topi) { + aplic->iforce[idc] = 0; + return 0; + } + + irq = (topi >> APLIC_IDC_TOPI_ID_SHIFT) & APLIC_IDC_TOPI_ID_MASK; + sm = aplic->sourcecfg[irq] & APLIC_SOURCECFG_SM_MASK; + state = aplic->state[irq]; + riscv_aplic_set_pending_raw(aplic, irq, false); + if ((sm == APLIC_SOURCECFG_SM_LEVEL_HIGH) && + (state & APLIC_ISTATE_INPUT)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + } else if ((sm == APLIC_SOURCECFG_SM_LEVEL_LOW) && + !(state & APLIC_ISTATE_INPUT)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + } + riscv_aplic_idc_update(aplic, idc); + + return topi; +} + +static void riscv_aplic_request(void *opaque, int irq, int level) +{ + bool update = false; + RISCVAPLICState *aplic = opaque; + uint32_t sourcecfg, childidx, state, idc; + + assert((0 < irq) && (irq < aplic->num_irqs)); + + sourcecfg = aplic->sourcecfg[irq]; + if (sourcecfg & APLIC_SOURCECFG_D) { + childidx = sourcecfg & APLIC_SOURCECFG_CHILDIDX_MASK; + if (childidx < aplic->num_children) { + riscv_aplic_request(aplic->children[childidx], irq, level); + } + return; + } + + state = aplic->state[irq]; + switch (sourcecfg & APLIC_SOURCECFG_SM_MASK) { + case APLIC_SOURCECFG_SM_EDGE_RISE: + if ((level > 0) && !(state & APLIC_ISTATE_INPUT) && + !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + case APLIC_SOURCECFG_SM_EDGE_FALL: + if ((level <= 0) && (state & APLIC_ISTATE_INPUT) && + !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + case APLIC_SOURCECFG_SM_LEVEL_HIGH: + if ((level > 0) && !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + case APLIC_SOURCECFG_SM_LEVEL_LOW: + if ((level <= 0) && !(state & APLIC_ISTATE_PENDING)) { + riscv_aplic_set_pending_raw(aplic, irq, true); + update = true; + } + break; + default: + break; + } + + if (level <= 0) { + aplic->state[irq] &= ~APLIC_ISTATE_INPUT; + } else { + aplic->state[irq] |= APLIC_ISTATE_INPUT; + } + + if (update) { + if (aplic->msimode) { + riscv_aplic_msi_irq_update(aplic, irq); + } else { + idc = aplic->target[irq] >> APLIC_TARGET_HART_IDX_SHIFT; + idc &= APLIC_TARGET_HART_IDX_MASK; + riscv_aplic_idc_update(aplic, idc); + } + } +} + +static uint64_t riscv_aplic_read(void *opaque, hwaddr addr, unsigned size) +{ + uint32_t irq, word, idc; + RISCVAPLICState *aplic = opaque; + + /* Reads must be 4 byte words */ + if ((addr & 0x3) != 0) { + goto err; + } + + if (addr == APLIC_DOMAINCFG) { + return aplic->domaincfg | (aplic->msimode ? APLIC_DOMAINCFG_DM : 0); + } else if ((APLIC_SOURCECFG_BASE <= addr) && + (addr < (APLIC_SOURCECFG_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_SOURCECFG_BASE) >> 2) + 1; + return aplic->sourcecfg[irq]; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDR)) { + return aplic->mmsicfgaddr; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDRH)) { + return aplic->mmsicfgaddrH; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDR)) { + /* Registers SMSICFGADDR and SMSICFGADDRH are implemented only if: + * (a) the interrupt domain is at machine level + * (b) the domain???s harts implement supervisor mode + * (c) the domain has one or more child supervisor-level domains + * that support MSI delivery mode (domaincfg.DM is not read- + * only zero in at least one of the supervisor-level child + * domains). + */ + return (aplic->num_children) ? aplic->smsicfgaddr : 0; + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDRH)) { + return (aplic->num_children) ? aplic->smsicfgaddrH : 0; + } else if ((APLIC_SETIP_BASE <= addr) && + (addr < (APLIC_SETIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIP_BASE) >> 2; + return riscv_aplic_read_pending_word(aplic, word); + } else if (addr == APLIC_SETIPNUM) { + return 0; + } else if ((APLIC_CLRIP_BASE <= addr) && + (addr < (APLIC_CLRIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_CLRIP_BASE) >> 2; + return riscv_aplic_read_input_word(aplic, word); + } else if (addr == APLIC_CLRIPNUM) { + return 0; + } else if ((APLIC_SETIE_BASE <= addr) && + (addr < (APLIC_SETIE_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIE_BASE) >> 2; + return riscv_aplic_read_enabled_word(aplic, word); + } else if (addr == APLIC_SETIENUM) { + return 0; + } else if ((APLIC_CLRIE_BASE <= addr) && + (addr < (APLIC_CLRIE_BASE + aplic->bitfield_words * 4))) { + return 0; + } else if (addr == APLIC_CLRIENUM) { + return 0; + } else if (addr == APLIC_SETIPNUM_LE) { + return 0; + } else if (addr == APLIC_SETIPNUM_BE) { + return 0; + } else if (addr == APLIC_GENMSI) { + return (aplic->msimode) ? aplic->genmsi : 0; + } else if ((APLIC_TARGET_BASE <= addr) && + (addr < (APLIC_TARGET_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_TARGET_BASE) >> 2) + 1; + return aplic->target[irq]; + } else if (!aplic->msimode && (APLIC_IDC_BASE <= addr) && + (addr < (APLIC_IDC_BASE + aplic->num_harts * APLIC_IDC_SIZE))) { + idc = (addr - APLIC_IDC_BASE) / APLIC_IDC_SIZE; + switch (addr - (APLIC_IDC_BASE + idc * APLIC_IDC_SIZE)) { + case APLIC_IDC_IDELIVERY: + return aplic->idelivery[idc]; + case APLIC_IDC_IFORCE: + return aplic->iforce[idc]; + case APLIC_IDC_ITHRESHOLD: + return aplic->ithreshold[idc]; + case APLIC_IDC_TOPI: + return riscv_aplic_idc_topi(aplic, idc); + case APLIC_IDC_CLAIMI: + return riscv_aplic_idc_claimi(aplic, idc); + default: + goto err; + }; + } + +err: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid register read 0x%" HWADDR_PRIx "\n", + __func__, addr); + return 0; +} + +static void riscv_aplic_write(void *opaque, hwaddr addr, uint64_t value, + unsigned size) +{ + RISCVAPLICState *aplic = opaque; + uint32_t irq, word, idc = UINT32_MAX; + + /* Writes must be 4 byte words */ + if ((addr & 0x3) != 0) { + goto err; + } + + if (addr == APLIC_DOMAINCFG) { + /* Only IE bit writeable at the moment */ + value &= APLIC_DOMAINCFG_IE; + aplic->domaincfg = value; + } else if ((APLIC_SOURCECFG_BASE <= addr) && + (addr < (APLIC_SOURCECFG_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_SOURCECFG_BASE) >> 2) + 1; + if (!aplic->num_children && (value & APLIC_SOURCECFG_D)) { + value = 0; + } + if (value & APLIC_SOURCECFG_D) { + value &= (APLIC_SOURCECFG_D | APLIC_SOURCECFG_CHILDIDX_MASK); + } else { + value &= (APLIC_SOURCECFG_D | APLIC_SOURCECFG_SM_MASK); + } + aplic->sourcecfg[irq] = value; + if ((aplic->sourcecfg[irq] & APLIC_SOURCECFG_D) || + (aplic->sourcecfg[irq] == 0)) { + riscv_aplic_set_pending_raw(aplic, irq, false); + riscv_aplic_set_enabled_raw(aplic, irq, false); + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDR)) { + if (!(aplic->mmsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->mmsicfgaddr = value; + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_MMSICFGADDRH)) { + if (!(aplic->mmsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->mmsicfgaddrH = value & APLIC_xMSICFGADDRH_VALID_MASK; + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDR)) { + /* Registers SMSICFGADDR and SMSICFGADDRH are implemented only if: + * (a) the interrupt domain is at machine level + * (b) the domain???s harts implement supervisor mode + * (c) the domain has one or more child supervisor-level domains + * that support MSI delivery mode (domaincfg.DM is not read- + * only zero in at least one of the supervisor-level child + * domains). + */ + if (aplic->num_children && + !(aplic->smsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->smsicfgaddr = value; + } + } else if (aplic->mmode && aplic->msimode && + (addr == APLIC_SMSICFGADDRH)) { + if (aplic->num_children && + !(aplic->smsicfgaddrH & APLIC_xMSICFGADDRH_L)) { + aplic->smsicfgaddrH = value & APLIC_xMSICFGADDRH_VALID_MASK; + } + } else if ((APLIC_SETIP_BASE <= addr) && + (addr < (APLIC_SETIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIP_BASE) >> 2; + riscv_aplic_set_pending_word(aplic, word, value, true); + } else if (addr == APLIC_SETIPNUM) { + riscv_aplic_set_pending(aplic, value, true); + } else if ((APLIC_CLRIP_BASE <= addr) && + (addr < (APLIC_CLRIP_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_CLRIP_BASE) >> 2; + riscv_aplic_set_pending_word(aplic, word, value, false); + } else if (addr == APLIC_CLRIPNUM) { + riscv_aplic_set_pending(aplic, value, false); + } else if ((APLIC_SETIE_BASE <= addr) && + (addr < (APLIC_SETIE_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_SETIE_BASE) >> 2; + riscv_aplic_set_enabled_word(aplic, word, value, true); + } else if (addr == APLIC_SETIENUM) { + riscv_aplic_set_enabled(aplic, value, true); + } else if ((APLIC_CLRIE_BASE <= addr) && + (addr < (APLIC_CLRIE_BASE + aplic->bitfield_words * 4))) { + word = (addr - APLIC_CLRIE_BASE) >> 2; + riscv_aplic_set_enabled_word(aplic, word, value, false); + } else if (addr == APLIC_CLRIENUM) { + riscv_aplic_set_enabled(aplic, value, false); + } else if (addr == APLIC_SETIPNUM_LE) { + riscv_aplic_set_pending(aplic, value, true); + } else if (addr == APLIC_SETIPNUM_BE) { + riscv_aplic_set_pending(aplic, bswap32(value), true); + } else if (addr == APLIC_GENMSI) { + if (aplic->msimode) { + aplic->genmsi = value & ~(APLIC_TARGET_GUEST_IDX_MASK << + APLIC_TARGET_GUEST_IDX_SHIFT); + riscv_aplic_msi_send(aplic, + value >> APLIC_TARGET_HART_IDX_SHIFT, + 0, + value & APLIC_TARGET_EIID_MASK); + } + } else if ((APLIC_TARGET_BASE <= addr) && + (addr < (APLIC_TARGET_BASE + (aplic->num_irqs - 1) * 4))) { + irq = ((addr - APLIC_TARGET_BASE) >> 2) + 1; + if (aplic->msimode) { + aplic->target[irq] = value; + } else { + aplic->target[irq] = (value & ~APLIC_TARGET_IPRIO_MASK) | + (value & aplic->iprio_mask); + } + } else if (!aplic->msimode && (APLIC_IDC_BASE <= addr) && + (addr < (APLIC_IDC_BASE + aplic->num_harts * APLIC_IDC_SIZE))) { + idc = (addr - APLIC_IDC_BASE) / APLIC_IDC_SIZE; + switch (addr - (APLIC_IDC_BASE + idc * APLIC_IDC_SIZE)) { + case APLIC_IDC_IDELIVERY: + aplic->idelivery[idc] = value & 0x1; + break; + case APLIC_IDC_IFORCE: + aplic->iforce[idc] = value & 0x1; + break; + case APLIC_IDC_ITHRESHOLD: + aplic->ithreshold[idc] = value & aplic->iprio_mask; + break; + default: + goto err; + }; + } else { + goto err; + } + + if (aplic->msimode) { + for (irq = 1; irq < aplic->num_irqs; irq++) { + riscv_aplic_msi_irq_update(aplic, irq); + } + } else { + if (idc == UINT32_MAX) { + for (idc = 0; idc < aplic->num_harts; idc++) { + riscv_aplic_idc_update(aplic, idc); + } + } else { + riscv_aplic_idc_update(aplic, idc); + } + } + + return; + +err: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid register write 0x%" HWADDR_PRIx "\n", + __func__, addr); +} + +static const MemoryRegionOps riscv_aplic_ops = { + .read = riscv_aplic_read, + .write = riscv_aplic_write, + .endianness = DEVICE_LITTLE_ENDIAN, + .valid = { + .min_access_size = 4, + .max_access_size = 4 + } +}; + +static void riscv_aplic_realize(DeviceState *dev, Error **errp) +{ + uint32_t i; + RISCVAPLICState *aplic = RISCV_APLIC(dev); + + aplic->bitfield_words = (aplic->num_irqs + 31) >> 5; + aplic->sourcecfg = g_new0(uint32_t, aplic->num_irqs); + aplic->state = g_new(uint32_t, aplic->num_irqs); + aplic->target = g_new0(uint32_t, aplic->num_irqs); + aplic->idelivery = g_new0(uint32_t, aplic->num_harts); + aplic->iforce = g_new0(uint32_t, aplic->num_harts); + aplic->ithreshold = g_new0(uint32_t, aplic->num_harts); + + memory_region_init_io(&aplic->mmio, OBJECT(dev), &riscv_aplic_ops, aplic, + TYPE_RISCV_APLIC, aplic->aperture_size); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &aplic->mmio); + + /* Only root APLICs have hardware IRQ lines. All non-root APLICs + * have IRQ lines delegated by their parent APLIC. + */ + if (!aplic->parent) { + qdev_init_gpio_in(dev, riscv_aplic_request, aplic->num_irqs); + } + + /* Create output IRQ lines for non-MSI mode */ + if (!aplic->msimode) { + aplic->external_irqs = g_malloc(sizeof(qemu_irq) * aplic->num_harts); + qdev_init_gpio_out(dev, aplic->external_irqs, aplic->num_harts); + + /* Claim the CPU interrupt to be triggered by this APLIC */ + for (i = 0; i < aplic->num_harts; i++) { + RISCVCPU *cpu = RISCV_CPU(qemu_get_cpu(aplic->hartid_base + i)); + if (riscv_cpu_claim_interrupts(cpu, + (aplic->mmode) ? MIP_MEIP : MIP_SEIP) < 0) { + error_report("%s already claimed", + (aplic->mmode) ? "MEIP" : "SEIP"); + exit(1); + } + } + } + + msi_nonbroken = true; +} + +static Property riscv_aplic_properties[] = { + DEFINE_PROP_UINT32("aperture-size", RISCVAPLICState, aperture_size, 0), + DEFINE_PROP_UINT32("hartid-base", RISCVAPLICState, hartid_base, 0), + DEFINE_PROP_UINT32("num-harts", RISCVAPLICState, num_harts, 0), + DEFINE_PROP_UINT32("iprio-mask", RISCVAPLICState, iprio_mask, 0), + DEFINE_PROP_UINT32("num-irqs", RISCVAPLICState, num_irqs, 0), + DEFINE_PROP_BOOL("msimode", RISCVAPLICState, msimode, 0), + DEFINE_PROP_BOOL("mmode", RISCVAPLICState, mmode, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static const VMStateDescription vmstate_riscv_aplic = { + .name = "riscv_aplic", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT32(domaincfg, RISCVAPLICState), + VMSTATE_UINT32(mmsicfgaddr, RISCVAPLICState), + VMSTATE_UINT32(mmsicfgaddrH, RISCVAPLICState), + VMSTATE_UINT32(smsicfgaddr, RISCVAPLICState), + VMSTATE_UINT32(smsicfgaddrH, RISCVAPLICState), + VMSTATE_UINT32(genmsi, RISCVAPLICState), + VMSTATE_VARRAY_UINT32(sourcecfg, RISCVAPLICState, + num_irqs, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(state, RISCVAPLICState, + num_irqs, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(target, RISCVAPLICState, + num_irqs, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(idelivery, RISCVAPLICState, + num_harts, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(iforce, RISCVAPLICState, + num_harts, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_VARRAY_UINT32(ithreshold, RISCVAPLICState, + num_harts, 0, + vmstate_info_uint32, uint32_t), + VMSTATE_END_OF_LIST() + } +}; + +static void riscv_aplic_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + device_class_set_props(dc, riscv_aplic_properties); + dc->realize = riscv_aplic_realize; + dc->vmsd = &vmstate_riscv_aplic; +} + +static const TypeInfo riscv_aplic_info = { + .name = TYPE_RISCV_APLIC, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(RISCVAPLICState), + .class_init = riscv_aplic_class_init, +}; + +static void riscv_aplic_register_types(void) +{ + type_register_static(&riscv_aplic_info); +} + +type_init(riscv_aplic_register_types) + +/* + * Add a APLIC device to another APLIC device as child for + * interrupt delegation. + */ +void riscv_aplic_add_child(DeviceState *parent, DeviceState *child) +{ + RISCVAPLICState *caplic, *paplic; + + assert(parent && child); + caplic = RISCV_APLIC(child); + paplic = RISCV_APLIC(parent); + + assert(paplic->num_irqs == caplic->num_irqs); + assert(paplic->num_children <= QEMU_APLIC_MAX_CHILDREN); + + caplic->parent = paplic; + paplic->children[paplic->num_children] = caplic; + paplic->num_children++; +} + +/* + * Create APLIC device. + */ +DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, + uint32_t hartid_base, uint32_t num_harts, uint32_t num_sources, + uint32_t iprio_bits, bool msimode, bool mmode, DeviceState *parent) +{ + DeviceState *dev = qdev_new(TYPE_RISCV_APLIC); + uint32_t i; + + assert(num_harts < APLIC_MAX_IDC); + assert((APLIC_IDC_BASE + (num_harts * APLIC_IDC_SIZE)) <= size); + assert(num_sources < APLIC_MAX_SOURCE); + assert(APLIC_MIN_IPRIO_BITS <= iprio_bits); + assert(iprio_bits <= APLIC_MAX_IPRIO_BITS); + + qdev_prop_set_uint32(dev, "aperture-size", size); + qdev_prop_set_uint32(dev, "hartid-base", hartid_base); + qdev_prop_set_uint32(dev, "num-harts", num_harts); + qdev_prop_set_uint32(dev, "iprio-mask", ((1U << iprio_bits) - 1)); + qdev_prop_set_uint32(dev, "num-irqs", num_sources + 1); + qdev_prop_set_bit(dev, "msimode", msimode); + qdev_prop_set_bit(dev, "mmode", mmode); + + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); + + if (parent) { + riscv_aplic_add_child(parent, dev); + } + + if (!msimode) { + for (i = 0; i < num_harts; i++) { + CPUState *cpu = qemu_get_cpu(hartid_base + i); + + qdev_connect_gpio_out_named(dev, NULL, i, + qdev_get_gpio_in(DEVICE(cpu), + (mmode) ? IRQ_M_EXT : IRQ_S_EXT)); + } + } + + return dev; +} diff --git a/include/hw/intc/riscv_aplic.h b/include/hw/intc/riscv_aplic.h new file mode 100644 index 0000000000..de8532fbc3 --- /dev/null +++ b/include/hw/intc/riscv_aplic.h @@ -0,0 +1,79 @@ +/* + * 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) + +#define APLIC_MIN_SIZE 0x4000 +#define APLIC_SIZE_ALIGN(__x) (((__x) + (APLIC_MIN_SIZE - 1)) & \ + ~(APLIC_MIN_SIZE - 1)) +#define APLIC_SIZE(__num_harts) (APLIC_MIN_SIZE + \ + APLIC_SIZE_ALIGN(32 * (__num_harts))) + +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 Dec 11 04:19:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671649 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 61910C433EF for ; Sat, 11 Dec 2021 04:27:18 +0000 (UTC) Received: from localhost ([::1]:48952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvtyf-0003Ln-Gw for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:27:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtse-0006la-S5; Fri, 10 Dec 2021 23:21:04 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsb-0001me-Ci; Fri, 10 Dec 2021 23:21:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196460; x=1670732460; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=yw0idvJ2tezCQ7QaqjcFU9KlPuUQQ3yCLTRpnCP0FTc=; b=rXJTfjKRGoD5m6MeDPwn65EE/aTqPRbYsxA2KjHBKzXA6kXiQQhadrMQ FMGRxb73dmNcBxss0h6Khx9QYsTIohDfuqE76WqpaMMxc0Tk/1FP7fqxA IvLSmR2TEeWFdDMuQFpr4gTP5gFGdquqYBAOrZi/qlMBwA800+rcsGYay dBhdW2hnWGlIoGLsLnBLktAkvpLwnCR+CyADEKGK4GFcSrASyIuxb9qg/ 86Z4JwLOAQUM4W1EIdbwovrPn4U6U7xbkU8Yua9eZuYrx8Hqm3b6BqJyJ VARrYtkJP9ZkYLvq3qVdSyooNxJX/izE33EWkL+K6RW7ZrXywJjMrg5wt A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989962" 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; 11 Dec 2021 12:20:57 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ITA200SVGBO+MMdLma3pIIurcaf44TH7ZnHWdZJ6XlGhbEqo+hE3f6H5RtHIKpDjQQViamGrcQjONvVM1RhMWRaNfYCB4WY170imPMReiVc4ZHoaQ4hZkpscUpLTb5algWQexX7aTW5VzY5V6TNLARPagqkvhGtOX5PbC9wFLi7f9tM7SAWF/0aeaeNaHByAcGWMhUMLZJDwG3ysrryOoOICBWazN4FXZWVCmGLGPQm7ms1zp0ooB8IFJYPP1Z9JCYScXZtkG2GuLvnzwZTsyEQ9a5LwcrwILuxMWvozK8ng9N/R4GAELm2lkn6+2eeR6e9T8QCp1AfjXZXIH/MpDQ== 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=zPLmM8s4lkqwegiLKEkPFKB2miTOdgMGWze+r0AYapM=; b=R534vX8bt4pkfody5MbipHrDeHzSE0/7ySfBx7IknZeTE5UcrbAenqxK214SpAQF/GvC75NJchWXrAFPL/ZjsxeE/udS87iPN070OxAhY3gfnqehtVnfuGfsqWxyLF1UlP2ft7sLTvP8+Hz5dIjJvswOIsST835BHUtmoj7hzXqapIYrZz8NuiZFazSLAEseEwGINl/lRl4Th2QlauroqOfc4mPYwhvrmwzUT6bXa/xnAzOUuhSUOD7yDS9wtKldMBqzigAAKjfn70jmA/Jaxt38V5Xee3xXVZwqhMXY8hWbuGp+7G+KYL+R8PGPz8xXlP4cTxr/fAAC+XNqgm7piA== 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=zPLmM8s4lkqwegiLKEkPFKB2miTOdgMGWze+r0AYapM=; b=qdTws5Ldnc2S3AtK1w3AR2wzdW/9CxZaVlo+/cmaWeqThTiDzePVLDG2eLZbHgquw69+56G3qV5TyluVP0n5YdCsny+wZMUK4uEYYtYrkUkggw3FuJCVTXb3P5/4KGfnfiht/2/bTKrPvL0Nan6CBX5cHgGLMFt05mkqkBNvaxM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:20:57 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:20:57 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 19/23] hw/riscv: virt: Add optional AIA APLIC support to virt machine Date: Sat, 11 Dec 2021 09:49:13 +0530 Message-Id: <20211211041917.135345-20-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 86b65ed8-7b10-4f81-9fd2-08d9bc5da0d9 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: L/THIdXUDNkkkyIgn+rrl/pg779CqJfy2S0oMP6KcRtkl96w4gLQTW/tWsyHNMHKjtm9kesPLhk/5bSOLFWi4xwKVQWHCltqnUjAIPVtb4H5uYyr59FBi4ajPDxH9ucEgmmKhFQ//18LHcAr5OP1Egy4r15pEYmyuguQonMsqd+LL7cKiN/zW2iQHCBn98Xr5Cql40okgDoSqXX9i6dw0dJ9wypi/+MzH9OUYhfrPXooHmd6Trt8TTV15lhyE5oiB+RakA1JncW5rHwZ57Iiz+UdnA0XKL/nJV3oTffG/KAkAed0IH0ex+vVmVLvBUyJ5r+ZAsV4thW0wVLsYliZrS1pcQDGKxGU5eoSAxZWCAnL/vFRQCna66WcAxSGnwb2L+/3zsdVHWv+vNh9uZmnnQS8n9QwRQekl/1ORhTCra3E2lti0eT2xXyBqjftQOIPuueFDVDTrcqtzk/tKimYhrEcXEfdl+LcJ/61CpFR50qf2ilshoBneA+5JOMCslIftGgVb9IteGdMdrHAojJbVEzaiuuuC7lNT4bvCLd8boWEUU1Hm78g0JAh6A6nnRcP3Nt/2jxD6FscM/0yN2Ok+P2HCpXa6ohhoYxX7D5YitBFNiRUkkcYZq1X7szB3u1ihzNgF2JZZrdea1KYowWl+bpJm3NL/xCYM9Gvn8fYDuS5pnfoJLxPpvpPIpbN1rFqSqyxjna9gcwzt3R/Sv9u5A== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(30864003)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: d4uurYvL54FQtO6o9tKk9t33GHZt9750hK1Ppk/qWPZqafL7AR8aOVBA01guuOT2Bb9mtz4/gIThFsgylAVScL2VYWxz4bnDwqJul2n+ufYYB+qrlwyx/JsEBjXXEQ/M/qvNK8bNMQPhjelXqafVbqrfgnVAjlYYeSm1ZQ8GkBIrpIQg+ngi7RFOxPLp8m3uHYVF3O6dnMusgI3vd+tzmIxeMtUMivh1ODKSwY+6+629cMeiVVbIuFcwh/n8kaDyTOUSdXxVTMP+zJIcE05FDiOB/PUXi0UKWgFNzLUF9KPcgddyEsxswNnPvMvgeu5wgDGn8GcheWJ+BxYo6FYAzNr0hsfbbwbKTdaJVi+g9O9RCID/ZATNcS7CPNFs9noRxgNrRhUda0/s7uMoukItfClYcmxrasziaY2wOvWlFvZk2ZQ/oYqYsEsdLwD4/VfiVpBQ9dtawidcY8SnN+5hrTPFhbdJTeK5WwK68C3+kANptqf0NanOOlrsPuI9Syn8e0NUPBtk3I1+07CyWt6rMeIf74yOS/NnZ5IMWQ2YxK2IL5EltfxlBylOTeIM+Jl64Ir0LoMNCl5GjC2yUyzA3a1m5EN0ZIQMbO/cLnQGfRYyMU8z5Yeh4esNZSMJT6aPXfYP6lyvLng4eVE0ImGKdzqniopQE5o8gmYa1p4jBMAD+m8lrg4kjAaSbLNv8teYXQt76b9XVx6TDejd/XUH7B+RJWXD8k3q8RhzlQJVCUQPJssZpwDSooUHptWN+bMXthTHnCyu6eGGmr8FW083TyRA5Q+orBzfVP1pOp2UbRQlKoSDsbquUH2Fnb1XgPcy7UcSu5gV02wQv5r3rJ2jh/ZDPLrKkp83QV3H7Ekme2WIEwBWuxNDAx0yppsplCAAmRqqTS220FI8Wp8AFWF0a4cOJr6zuNCIbDQSINoEu9PWgRZyH5zGXwRO++ksI2y0BhOh4S+qM2bTKw8UrHprk05ZW4q8D9l1Kx4YImi20c+vrozniIgTnfh7m2v/issZ3p+E7BMWrYQgP/oD3lgQZGgJxfq6aPP7WLwhYw2YDilXx8OXF2/TIKTfKatDIzlAEnkxOiC/1z4N/T1sXb0JYtyRSMGjhvjUjgyAW6bguIvGvMiTEz4XUqeAF3TlpBVOXjJLOHtHmG7TgiSqIyEN7EUulFsXntL1Wzgkw8VxvCWiecR5UQgfp4JdzgtNA7qV91OPK7C5WNpA5mIKfs2a9iR1IYm1Ax2+VMXYE9Ehy1InEhguVyiLOjtWj8wtzMR7nyuWVtPeZRF8Xtl6YTze5Tz3jeXO8FmQs03yr6IK8LBNPp2YZ8ZmMiHRScw8izWEfDjiasfzymYOHlyDsCD+UwHxtys9WYcM2xwAuH0fOowWRXDUUwhcybWcPUtLM0Cc0yWjsnHplLkkSRKwVCAfaMLZtg0yNoPRYZR3V5tyY/rsdJfUI1TNq6XEQxzzZWwxWxumTus+ZEFaip/bR0sg3eX6tvcmWdk5pb6mtbM3sJmOzRlIlzgd+LR1gVmv1o3AJA8nEI3RU88yXb91a8kqWXPVx91c3e86Gp0NFYvXEnL8WQSQWc1AQwiJy+PzhZPfZR3ycAs8IVyvcgTG5P3fnHAZZUkE0ikx817EM3uquPs= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86b65ed8-7b10-4f81-9fd2-08d9bc5da0d9 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:56.9525 (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: mbHOxNIhu2JHXPPj0+Mrzfq5YiGBBjdlkJmak1ShmBJzXQA5j+/H6ZnrZhGpSWdBd1NOPu9GLHjIE9X/QmDbKg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We extend virt machine to emulate AIA APLIC devices only when "aia=aplic" parameter is passed along with machine name in QEMU command-line. When "aia=none" or not specified then we fallback to original PLIC device emulation. Signed-off-by: Anup Patel --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 293 ++++++++++++++++++++++++++++++++-------- include/hw/riscv/virt.h | 26 +++- 3 files changed, 260 insertions(+), 60 deletions(-) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index d2d869aaad..c30bb7cb6c 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -42,6 +42,7 @@ config RISCV_VIRT select PFLASH_CFI01 select SERIAL select RISCV_ACLINT + select RISCV_APLIC select SIFIVE_PLIC select SIFIVE_TEST select VIRTIO_MMIO diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 936156554c..8aa9f8a988 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, APLIC_SIZE(VIRT_CPUS_MAX) }, + [VIRT_APLIC_S] = { 0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) }, [VIRT_UART0] = { 0x10000000, 0x100 }, [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, [VIRT_FW_CFG] = { 0x10100000, 0x18 }, @@ -132,12 +135,13 @@ static void virt_flash_map(RISCVVirtState *s, sysmem); } -static void create_pcie_irq_map(void *fdt, char *nodename, - uint32_t plic_phandle) +static void create_pcie_irq_map(RISCVVirtState *s, void *fdt, char *nodename, + uint32_t irqchip_phandle) { int pin, dev; - uint32_t - full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * FDT_INT_MAP_WIDTH] = {}; + uint32_t irq_map_stride = 0; + uint32_t full_irq_map[GPEX_NUM_IRQS * GPEX_NUM_IRQS * + FDT_MAX_INT_MAP_WIDTH] = {}; uint32_t *irq_map = full_irq_map; /* This code creates a standard swizzle of interrupts such that @@ -155,23 +159,31 @@ static void create_pcie_irq_map(void *fdt, char *nodename, int irq_nr = PCIE_IRQ + ((pin + PCI_SLOT(devfn)) % GPEX_NUM_IRQS); int i = 0; + /* Fill PCI address cells */ irq_map[i] = cpu_to_be32(devfn << 8); - i += FDT_PCI_ADDR_CELLS; - irq_map[i] = cpu_to_be32(pin + 1); + /* Fill PCI Interrupt cells */ + irq_map[i] = cpu_to_be32(pin + 1); i += FDT_PCI_INT_CELLS; - irq_map[i++] = cpu_to_be32(plic_phandle); - i += FDT_PLIC_ADDR_CELLS; - irq_map[i] = cpu_to_be32(irq_nr); - - irq_map += FDT_INT_MAP_WIDTH; + /* Fill interrupt controller phandle and cells */ + irq_map[i++] = cpu_to_be32(irqchip_phandle); + irq_map[i++] = cpu_to_be32(irq_nr); + if (s->aia_type != VIRT_AIA_TYPE_NONE) { + irq_map[i++] = cpu_to_be32(0x4); + } + + if (!irq_map_stride) { + irq_map_stride = i; + } + irq_map += irq_map_stride; } } - qemu_fdt_setprop(fdt, nodename, "interrupt-map", - full_irq_map, sizeof(full_irq_map)); + qemu_fdt_setprop(fdt, nodename, "interrupt-map", full_irq_map, + GPEX_NUM_IRQS * GPEX_NUM_IRQS * + irq_map_stride * sizeof(uint32_t)); qemu_fdt_setprop_cells(fdt, nodename, "interrupt-map-mask", 0x1800, 0, 0, 0x7); @@ -394,8 +406,6 @@ static void create_fdt_socket_plic(RISCVVirtState *s, plic_addr = memmap[VIRT_PLIC].base + (memmap[VIRT_PLIC].size * socket); plic_name = g_strdup_printf("/soc/plic@%lx", plic_addr); qemu_fdt_add_subnode(mc->fdt, plic_name); - qemu_fdt_setprop_cell(mc->fdt, plic_name, - "#address-cells", FDT_PLIC_ADDR_CELLS); qemu_fdt_setprop_cell(mc->fdt, plic_name, "#interrupt-cells", FDT_PLIC_INT_CELLS); qemu_fdt_setprop_string_array(mc->fdt, plic_name, "compatible", @@ -415,6 +425,76 @@ static void create_fdt_socket_plic(RISCVVirtState *s, g_free(plic_cells); } +static void create_fdt_socket_aia(RISCVVirtState *s, + const MemMapEntry *memmap, int socket, + uint32_t *phandle, uint32_t *intc_phandles, + uint32_t *aplic_phandles) +{ + int cpu; + char *aplic_name; + uint32_t *aplic_cells; + unsigned long aplic_addr; + MachineState *mc = MACHINE(s); + uint32_t aplic_m_phandle, aplic_s_phandle; + + aplic_m_phandle = (*phandle)++; + aplic_s_phandle = (*phandle)++; + aplic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2); + + /* M-level APLIC node */ + for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { + aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + aplic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_M_EXT); + } + aplic_addr = memmap[VIRT_APLIC_M].base + + (memmap[VIRT_APLIC_M].size * socket); + aplic_name = g_strdup_printf("/soc/aplic@%lx", aplic_addr); + qemu_fdt_add_subnode(mc->fdt, aplic_name); + qemu_fdt_setprop_string(mc->fdt, aplic_name, "compatible", "riscv,aplic"); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, + "#interrupt-cells", FDT_APLIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", + 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_M].size); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", + VIRT_IRQCHIP_NUM_SOURCES); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,children", + aplic_s_phandle); + qemu_fdt_setprop_cells(mc->fdt, aplic_name, "riscv,delegate", + aplic_s_phandle, 0x1, 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_m_phandle); + g_free(aplic_name); + + /* S-level APLIC node */ + for (cpu = 0; cpu < s->soc[socket].num_harts; cpu++) { + aplic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + aplic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT); + } + aplic_addr = memmap[VIRT_APLIC_S].base + + (memmap[VIRT_APLIC_S].size * socket); + aplic_name = g_strdup_printf("/soc/aplic@%lx", aplic_addr); + qemu_fdt_add_subnode(mc->fdt, aplic_name); + qemu_fdt_setprop_string(mc->fdt, aplic_name, "compatible", "riscv,aplic"); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, + "#interrupt-cells", FDT_APLIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", + 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_S].size); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", + VIRT_IRQCHIP_NUM_SOURCES); + riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_s_phandle); + g_free(aplic_name); + + g_free(aplic_cells); + aplic_phandles[socket] = aplic_s_phandle; +} + static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, bool is_32_bit, uint32_t *phandle, uint32_t *irq_mmio_phandle, @@ -451,8 +531,13 @@ static void create_fdt_sockets(RISCVVirtState *s, const MemMapEntry *memmap, create_fdt_socket_clint(s, memmap, socket, intc_phandles); } - create_fdt_socket_plic(s, memmap, socket, phandle, - intc_phandles, xplic_phandles); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + create_fdt_socket_plic(s, memmap, socket, phandle, + intc_phandles, xplic_phandles); + } else { + create_fdt_socket_aia(s, memmap, socket, phandle, + intc_phandles, xplic_phandles); + } g_free(intc_phandles); g_free(clust_name); @@ -493,7 +578,13 @@ static void create_fdt_virtio(RISCVVirtState *s, const MemMapEntry *memmap, 0x0, memmap[VIRT_VIRTIO].size); qemu_fdt_setprop_cell(mc->fdt, name, "interrupt-parent", irq_virtio_phandle); - qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", VIRTIO_IRQ + i); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", + VIRTIO_IRQ + i); + } else { + qemu_fdt_setprop_cells(mc->fdt, name, "interrupts", + VIRTIO_IRQ + i, 0x4); + } g_free(name); } } @@ -531,7 +622,7 @@ static void create_fdt_pcie(RISCVVirtState *s, const MemMapEntry *memmap, 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.base, 2, virt_high_pcie_memmap.size); - create_pcie_irq_map(mc->fdt, name, irq_pcie_phandle); + create_pcie_irq_map(s, mc->fdt, name, irq_pcie_phandle); g_free(name); } @@ -590,7 +681,11 @@ static void create_fdt_uart(RISCVVirtState *s, const MemMapEntry *memmap, 0x0, memmap[VIRT_UART0].size); qemu_fdt_setprop_cell(mc->fdt, name, "clock-frequency", 3686400); qemu_fdt_setprop_cell(mc->fdt, name, "interrupt-parent", irq_mmio_phandle); - qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", UART0_IRQ); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", UART0_IRQ); + } else { + qemu_fdt_setprop_cells(mc->fdt, name, "interrupts", UART0_IRQ, 0x4); + } qemu_fdt_add_subnode(mc->fdt, "/chosen"); qemu_fdt_setprop_string(mc->fdt, "/chosen", "stdout-path", name); @@ -611,7 +706,11 @@ static void create_fdt_rtc(RISCVVirtState *s, const MemMapEntry *memmap, 0x0, memmap[VIRT_RTC].base, 0x0, memmap[VIRT_RTC].size); qemu_fdt_setprop_cell(mc->fdt, name, "interrupt-parent", irq_mmio_phandle); - qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", RTC_IRQ); + if (s->aia_type == VIRT_AIA_TYPE_NONE) { + qemu_fdt_setprop_cell(mc->fdt, name, "interrupts", RTC_IRQ); + } else { + qemu_fdt_setprop_cells(mc->fdt, name, "interrupts", RTC_IRQ, 0x4); + } g_free(name); } @@ -692,7 +791,7 @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, hwaddr high_mmio_base, hwaddr high_mmio_size, hwaddr pio_base, - DeviceState *plic) + DeviceState *irqchip) { DeviceState *dev; MemoryRegion *ecam_alias, *ecam_reg; @@ -726,7 +825,7 @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, pio_base); for (i = 0; i < GPEX_NUM_IRQS; i++) { - irq = qdev_get_gpio_in(plic, PCIE_IRQ + i); + irq = qdev_get_gpio_in(irqchip, PCIE_IRQ + i); sysbus_connect_irq(SYS_BUS_DEVICE(dev), i, irq); gpex_set_irq_num(GPEX_HOST(dev), i, PCIE_IRQ + i); @@ -757,18 +856,75 @@ static FWCfgState *create_fw_cfg(const MachineState *mc) return fw_cfg; } +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 = riscv_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 */ @@ -779,7 +935,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); @@ -829,36 +985,27 @@ static void virt_machine_init(MachineState *machine) base_hartid, hart_count, true); } - /* Per-socket PLIC hart topology configuration string */ - plic_hart_config = riscv_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]; } } @@ -957,7 +1104,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, @@ -968,14 +1115,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); @@ -991,6 +1138,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); @@ -1029,6 +1207,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 b8ef99f348..43603a769c 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,8 +81,9 @@ enum { VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ }; -#define VIRT_PLIC_NUM_SOURCES 127 -#define VIRT_PLIC_NUM_PRIORITIES 7 +#define VIRT_IRQCHIP_NUM_SOURCES 127 +#define VIRT_IRQCHIP_NUM_PRIO_BITS 3 + #define VIRT_PLIC_PRIORITY_BASE 0x04 #define VIRT_PLIC_PENDING_BASE 0x1000 #define VIRT_PLIC_ENABLE_BASE 0x2000 @@ -86,9 +95,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 Dec 11 04:19:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 2EC4DC433EF for ; Sat, 11 Dec 2021 04:29:47 +0000 (UTC) Received: from localhost ([::1]:57824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu14-00011X-4L for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:29:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsh-0006vJ-Dt; Fri, 10 Dec 2021 23:21:07 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtse-0001mA-6a; Fri, 10 Dec 2021 23:21:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196463; x=1670732463; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=fOAchqjkolUbB37ps5uTKl3VDo9zkK/jShvdEMakJVo=; b=Cn4xXdFxFbzi1+v8xrM0UzugTxUagpsZ3g3WhUOl3Gqy0JCdxHdy9LxP P0Y8DyFU3LKePKzId6hemOy565d2MoBScC9PAxx9Ou88CL7d22/0i7uH6 KlMD+hY3CuDiz+qaMVq+37lMzNeLyTds05A4z+0oAJjW+Wjo8P2/jxLBn G5bH+j5jC1y66TmOx3u+eTpy998bsglf+yE2DlUDywt7kHhX1UdfBycCL djZniobYIyMKBxBB5Zkw2b1BpVnz+JO9d4pVINL37WY3mMDKKEIjZ1kLA tS6VVJdctXr4YMSSXb992vhDS6G+/aZUcBI+ic/SArVzySs+0O8irpPGy w==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989966" 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; 11 Dec 2021 12:21:00 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xyfa9JuziZilfgHqV2DmA8Wh+DnoDRzjfJTXUEiFM3fHRMZtDKLpJ6cSrBefEv7AvCJTVlLemkMpYXSglBG+poHnnYWiaCWMziedavnk3XQmy5cMZSdWLtUJT037reuhUYZOGActA/ux1jC1FbIuzGDYiewPZnxWyK9oVTLwmB4gFWr/S37JN+1NKK4Z4gmUuRrYrVO+jLv7G2x4lktx2tPJV7yytXqkE5/ANDyZQXWkme1QMxCD3zkOr57smnd+sCJIW1MBiJmjkHtSuV+7eWuUNUHF0nf/EOip5apAbSXNsNi9B5D7KJIgp7ZtrkE0g6lQCZ2Khvnf5z+ZBffVSg== 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=2zeCZsiS2aPLc6NjilQl0rGSvw/3LmFh3p1Xazw7pwE=; b=IZhYxdMcP7CHN8aQSop5vLOssqgfu0CYR7pZ/lsPaSu1IDMSdzPIb/iVTVu9H/M/qDDAir3/NjG/4UzbZCziHApRl9GWdiCgK3YAM6YomGVZUwhXbxbz9FOXkM77zXO3xkwR2eOqca+kimbgPLF7VmmHlw1AGzoE5offPMpT3SU8awI/yvokuSx4l1usmP0Ngq3/rMxsgwMOFrUeZVd03q1pPT8JpuTNqMmmtTHvoUnPktNuj8CWuitsay2ifpqRIkFcECkvkHrxUHsULeoeDyVUbNb3GzTJ60eFnZbXXLpSeyGBJwYoIjT48VWNswteDVeysX1k0afNw4mx8obJ/Q== 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=2zeCZsiS2aPLc6NjilQl0rGSvw/3LmFh3p1Xazw7pwE=; b=uiook6lb9/LNtx2MP5XyRH7Ut0dEMjuZlztuPgR+fNxbKsDy03jBYhCPpyQV4683bFSlAa4z7Gk7sEy4irQumvfGFpXd7J6Z80phBCoq/vuZ81FnHgfh1jkcR/AogaSt+xB8dZCzSAetHZOcFN7a2nG3bK8Nb5VYSS9EXmX7YIU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:21:00 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:21:00 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 20/23] hw/intc: Add RISC-V AIA IMSIC device emulation Date: Sat, 11 Dec 2021 09:49:14 +0530 Message-Id: <20211211041917.135345-21-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c914f1f3-a44e-4fd4-d611-08d9bc5da2c2 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: ZU8WuRFo4PGNjT3wB0K/8nt5iRII9Y25u30OqW1dqvzbvQyi8qLf/Ew37lUgE756RlbpaiGkmXwjE6ok/IeoEjqwwrmmQmAeHFJd/bIfN0mKZNCsnTxX2xcmksqNfraiDIeg45JunFFOdZdZHxcIIlYYD5uVcWnSKNsWOOsd+9ihDuo2R3B/L9KYhrazupfVzFp+V4ySUkGwu4rtl6J2zzatzn6kLa3Y3yPVM/2mrqRdAVbi89m4QccoLI5eH8u2MELOq1Dq4rfGO3DUJmksSHrWW38hieMdVhd063d6DNcGLQs4FeRH5w8w1Vf23oJChr20DitvsrER1DsM8e77L+TcSfV4+SZTKGqq1UXd/WmerUOQBEyEnsygmi27oH1YxUGQrqjynrBfBIylHREWxsNCpzRdcDtuiCQVA/SEP24D84uHIe6ws6iGhnCrLe0lkdSynlVDZTvNjBzKp7MRo1s8tSw6+etfZWwaV1ttzWqIbPTce0qp6ZGSEBWqGZBk08oDRD0ly6m2Chqq+Ivf/eSFD1Uz3GdVrbcsxaEqwxn6q6LnuZXOz7vreCZ3iqeLhj2l1jN2samgs2GK3i409CyzHtTE1FN4B6fAlQjgrdasmlVpZzDi51hNqbtWPn5aiAutIbU1bzpcfXx1P4JnlLmmgkjNSPC9TkWXxyI8j1Y1GkX19z5AlbfNTisJykWAt6VR9DUABOeAMsznwnS7UpiggnTUMwXsVubo6w1sJg2axWV4h+uVGdkYjNthXhZzYoA5uEgAkXkLcJW9LscqbtCg29NZ7zaB4VX17JQFXN8= 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(30864003)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EkwijUM9Cm/TiMZ2eqFe6SXXER6twtsRfBJFF1dbnS7IFPGwzJ6bTokn1cgB7gTF6543MBTckew3mTtlhi0MssBkVrQ2DmUaYX0KOXN+H/RFU5IR475py+q54arLy7MKGvIU0rfYpJou3pV45NBcTJgTd+jA8K6WVxHHg/4ZJTMfVhqIX5Ojyz8aBZAZfyoJBjaNmakkxd62V/vE1LnIU69/i3oVCgHyPeCB/PmQZdTkRA304Z0vOWga63WU6DDy1BdUGBuzvAK7Kf/gv4BiDmg8x0l8WYgU3i7I3dZbth2twrAVbd6vH4cscpXZn9kvTPXlUJQsoz6+tUjJV2rq9cLgNGQN9l+ZaFnJ1sbpNXtvimKDr2kVmS1cBd+IgBL35f8DFby2+8RPTz8hTeyCWVV/B5nmvZHbNE4NUjjdfWsZX9JTWyxDoxobmqbktekkNtX6LGEnq/jbxfRG00e7Bjc/7yvQhzkhJjkZnrX4Y2+vr58EoPeh9kVJ6eC1Vvemiqwp0OlXIdIS9lpu0jCPHvWhLWiFZG81G5a34r3ft+tIeNbw98sVJDx5KXFNSRQNXb5ST7DvD6S25vMEPv/thuhcOl5fWgDG9R+NX0/cvhM8IqYfFB6EKE3j4JV0/rz9NmxlMuJoElg8AQ+HITtdNrpV+wHrqpckVhsRhyxPoVjbiONSGRnwPdEPlKWTaMEUJyLrmWBuA1bfWLBDWluTMayQDSMDcQQ+DspIOvA4WGOC21FiEmu2iohZfSTX3THCEIUz1Jf1j6rbSUv87Z8XcwantQLIf6sdUL4PCUle64Lz8VOkrk6fUGUnIyiqtu9NJHVtXzt2/zrzZ3LOXEdfE24zo9EVt1xlYRS2e0t6feLf3AcV/pvAP1OVcmJ6e7nCqTPwbM+lTO9QYKW4s4436DbwkfEoNRj9Ku6Iihl2yhm8zyu/mo2+zoHAN6RiqT+dzjiimlFnJ6YrNnkphjck4Bbg+wWbQ5UGYGFhBvP0W6YGXa2KwdEIlFHoLDvveM0bKAFm+yN883g3E+5ydEp93sMx6HDBtKESPkOw0OoNDfYMLgKuT437dVE5fy4llCSpIqjMsl7+yxF9wHiTXhqsUdbbAJWJvuIUiN1zFSLll+LFfoDgpGA+vTmJRsdlsl4HGqR9Hm3UeKSV8zWrSr/jUVSSVcDGpKHLtbgBTe0WM6BIDw+miwqTLA5UKQ1nPEYgB7Ecdmon6yzfGOAhiX8sPyaUnR9A85+xvOgLxgHEqXtdk6J5Lcw9puig54kIYOzgxbY6dTZjkA5NnaUCImCI02zAn7EmKmor5judCta1Q2VhEPTKh2MezEOR6Lwglh4eyHc73Di0dhH7cm3I+NlUIiF+Bva4/oLz3jY2IfO5kqr/OeSlSNA0Yiu+zJ6pQtFhlxKt0uOms2thtHZj7WZ9bV4PEPDpGkKor8dmTmeiuyjcUBVEDPyEjWInB571VOhsqtRIvAZYosOPksJLWFtrHVtPN6/06PQl5tSmQYDvsqElPLM7n6/VdozYGIu8Mh+Z2vCSs9H3SC57qJHXuYc3VuGlZSu3mK5pnbvCtGkJWOd3pe0Psiqx8qSod89/TiQB/DLjga6uMwcOFgurlfC1S787E6O9aKCibFNKKw+wU28= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: c914f1f3-a44e-4fd4-d611-08d9bc5da2c2 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:20:59.9856 (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: YhNo3Wyakt8/XMxF3MC4yOwXIgLmunEyJnHVYdW/3MinFwsVfcJ/QFhOvAOG3u3aRhjFohnHb2Pq45MSYAuiGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The RISC-V AIA (Advanced Interrupt Architecture) defines a new interrupt controller for MSIs (message signal interrupts) called IMSIC (Incoming Message Signal Interrupt Controller). The IMSIC is per-HART device and also suppport virtualizaiton of MSIs using dedicated VS-level guest interrupt files. This patch adds device emulation for RISC-V AIA IMSIC which supports M-level, S-level, and VS-level MSIs. Signed-off-by: Anup Patel --- hw/intc/Kconfig | 3 + hw/intc/meson.build | 1 + hw/intc/riscv_imsic.c | 447 ++++++++++++++++++++++++++++++++++ include/hw/intc/riscv_imsic.h | 68 ++++++ 4 files changed, 519 insertions(+) create mode 100644 hw/intc/riscv_imsic.c create mode 100644 include/hw/intc/riscv_imsic.h diff --git a/hw/intc/Kconfig b/hw/intc/Kconfig index 1592623233..0bb3166110 100644 --- a/hw/intc/Kconfig +++ b/hw/intc/Kconfig @@ -68,6 +68,9 @@ config RISCV_ACLINT config RISCV_APLIC bool +config RISCV_IMSIC + bool + config SIFIVE_PLIC bool diff --git a/hw/intc/meson.build b/hw/intc/meson.build index 77b068f673..bcfd7758a9 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -48,6 +48,7 @@ specific_ss.add(when: 'CONFIG_S390_FLIC_KVM', if_true: files('s390_flic_kvm.c')) specific_ss.add(when: 'CONFIG_SH_INTC', if_true: files('sh_intc.c')) specific_ss.add(when: 'CONFIG_RISCV_ACLINT', if_true: files('riscv_aclint.c')) specific_ss.add(when: 'CONFIG_RISCV_APLIC', if_true: files('riscv_aplic.c')) +specific_ss.add(when: 'CONFIG_RISCV_IMSIC', if_true: files('riscv_imsic.c')) specific_ss.add(when: 'CONFIG_SIFIVE_PLIC', if_true: files('sifive_plic.c')) specific_ss.add(when: 'CONFIG_XICS', if_true: files('xics.c')) specific_ss.add(when: ['CONFIG_KVM', 'CONFIG_XICS'], diff --git a/hw/intc/riscv_imsic.c b/hw/intc/riscv_imsic.c new file mode 100644 index 0000000000..753fa11a9c --- /dev/null +++ b/hw/intc/riscv_imsic.c @@ -0,0 +1,447 @@ +/* + * 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 xlen, 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 (xlen != 32) { + if (num & 0x1) { + return -EINVAL; + } + num >>= 1; + } + if (num >= (imsic->num_irqs / xlen)) { + return -EINVAL; + } + + base = (page * imsic->num_irqs) + (num * xlen); + + if (val) { + *val = 0; + for (i = 0; i < xlen; i++) { + mask = (target_ulong)1 << i; + *val |= (imsic->eistate[base + i] & state) ? mask : 0; + } + } + + for (i = 0; i < xlen; 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, xlen, page; + + priv = AIA_IREG_PRIV(reg); + virt = AIA_IREG_VIRT(reg); + isel = AIA_IREG_ISEL(reg); + vgein = AIA_IREG_VGEIN(reg); + xlen = AIA_IREG_XLEN(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, xlen, page, + isel - ISELECT_IMSIC_EIP0, + true, val, new_val, wr_mask); + case ISELECT_IMSIC_EIE0 ... ISELECT_IMSIC_EIE63: + return riscv_imsic_eix_rmw(imsic, xlen, 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 Dec 11 04:19:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D0909C433F5 for ; Sat, 11 Dec 2021 04:42:08 +0000 (UTC) Received: from localhost ([::1]:53600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvuD1-0000yW-Jz for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:42:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsl-0006zO-AN; Fri, 10 Dec 2021 23:21:11 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26535) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsh-0001oI-6S; Fri, 10 Dec 2021 23:21:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196466; x=1670732466; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=aK0D0TKpK6IPA6eplhquvuZr+86wF5qaLTaxQ0Z38y4=; b=DxcLERo6TVTkNqpaGY5fzkU67kMpMec6smfoudk5D9ZlnbsNVXfTQ9H5 j/EsQKKH+Qi9EZGguSK9TQqqp9dkufKa9zJysS8tC/OkVbehiGkaEBcU9 megDUPexKZrRVuGBXZnT1n12Oj0IcA4rAnoXhJO92bkCDU3BrfpXXzK52 WJ5i1u6EHBkLfbrvQ2pdBVeSGEcQZNvWXA2wTyoutYvYd8Rsfmsok59aJ FoRTceWh/vgtjVVUfgcw1bPOBZReWzC3W5KboLTDijdXO4ppAbfIT9VzN We0mItzte0kEh4QmnbOP3MP2iwj5g1iF0zKTc18+9igvI+wtzK66YbOYh Q==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989971" 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; 11 Dec 2021 12:21:03 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lay2wk7+FRyu/XLUtSn9uP+HGDLn0qRMgUWA8R3MoKuMVLK1OGQ2u/Rp40ERnKpgas5C2kJTK/AHlaw3NvzdNYRATybXqEcgqLfr3yoGnh7sWeYjsG5yCUA4UuHfRXbXiV+y5AHA/c0I6s+R81JB/QG2Us8b+J9R6ssMEnQLuqXP0tHD2zLwA2jWrDMY6GpdZvO4cTtvJLyNa2LK/6K2lkAanN+FuZJ0p69iucAf0SAfsX4VawJIG+hrkq6wHg7PSRcJ0BjbdF+iIEMCU0nirayk2LajzGWxEVOmSSlTdYr1MDLGB0zGExzwf66kHa4IBdB7YZqvcKe4kd1TArAbPQ== 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=bgRnhl/5gJAgzDhY/BbjiB0pEvExLwRQbRJ4/osgkNY=; b=XGzqYSxAX0qkr8XdfUGXNEml+O7l2FU0f2USu2b1ruwNkxm/Q/0frSW3tMZuUVPXBoF0JagjZv+e84W83HTwGr9cFew+yknAD2Hgsg59OAM2Cl4jE9QRK4pPuHuipUSScxW9NTJzVb7lZlWn+5zVYxxI37rDyQk/Ajtc5KwxQBjH86ItdOjzcJtUUzyhdAN5Z7UZKjLT3+zb/NwcnEzEhoNDLgKZe5m7NnuLKhRTcIGFvy4THBC7fV3bEwtBr2tuIDY2Ys0VID5+GBMZQN6GwAWzVnGfpADzT2/ivaTlIPHOnaH80bJ3zFvJC8tldnekLVF+gwFm8Nu/yJix8CCN9Q== 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=bgRnhl/5gJAgzDhY/BbjiB0pEvExLwRQbRJ4/osgkNY=; b=rEcJXN1qwWVSTruLVTscjNo08Y1kO49bISO2w5DTNGuINiYdkNcH5KUyziQYbkI3eugb0Plz63/Y6JoYqrBd2YpyoiJkh8nMdj2Z0nxSoOKZRVueidB/13dIrm7gTMS3uBqRflHg21kVyCKzFUqzrr2B6BnMYN0Q8A4r5Mt/Awo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:21:03 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:21:03 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 21/23] hw/riscv: virt: Add optional AIA IMSIC support to virt machine Date: Sat, 11 Dec 2021 09:49:15 +0530 Message-Id: <20211211041917.135345-22-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2158b769-a124-4a8e-5f15-08d9bc5da485 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: 4/vVpJqszM/sfQD0wTAGPGzpYM+z9GabEgfSotiPcut3/uM1UesA65M+XsLlu2iL9MmGVYfqv2QTCzbVp3S2G7+CbB1XYtOgEAJoxxVwV8XXp4Kd7a3jVU+GButdGL8EeJ2jf/uLndePqGomAPq92xxJNJ/njzJ7oX/GSwPwosrFniPEjXBaCz1JKw9QNLAeTNbCTE9rF4EhetMrBejnai17l40T+1s+42ecejNcJtChoHAFSkpT0ezSXAF1g8BqwlmT54fFF6FuBeKO+gcHIduqLbms9pRoCQhXy0wlhAgFKZn7N0sg112R9YFTJN4MnfkLbfX2TVD8CEt+pJyXKONcZmFWQZ5qa2kjrkGfJ+rxPfK/3NvfSgwuAo6vswQhtzYJknLpQCSO8GjviF5Oc66p+djSV4aIpOE304tR0eOam9CJoCAUa+iVKAQh94JCf0PmD/zQ2kJ2VJ0Z5iBNS9+EUarztCWS52vNcH2rkZmaJ7L/pAtLrQ2kL7DehYMI+efYLer+sf9ti5n9YfiQYdAUIfdUmZwDwb4BJMaUCs9cUn3aKcCKJ2i3iFmZCJJqqCgOFeF0Fi5kTY6FKx7KQRenvexnXv0XfXlQ72QnZBIJQKUZCexhTu7A23qvpYOvRo26MjDjz0B+eLymeAv6go/OyBO8p1uwZK/BZq9NU7uJL2sRcfu3aqK0t9qUVtqW4WSsvBrVW8ldM2v23my3cw== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(30864003)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KggpMcbWRMqGWUVHvmx3EjqHin0jZ8F7OeBLLULiL3kH+kPBid4bcLcyr05FhrfkGiV4RrFki57yt8Y3Ji6MYQzJWjyzEhAalyejuDG8DI7C6L0QEvLCE/Mzjlmpf8ddmG8CVqXFnGFc6EE/w3eMTYmiODPIiI9kIFEMv9AFas+Ng9DHyoTC6wafrZ3ptHsaUZQJIbpz4j2iFexJSTqAzhcnMFpEa/oTOCZeY5xKUncR+7DM0bP3mkWXt+Jm68yFYdaIe1ahRd8dZI2U21wxHmrWKTKqaFeIjptZGJRIptgcI9rM/0WGLYNei9Akc1/pzEMslEW4kJ3rj/efMP0vyeG82laoZX/Kf4ru+qWkBQKxG+23RK83mcSHdE+P1s/EIhP923gL9BH87BEyrNPyNDOus23QiA0rbptt4MEgwHyCIxUfovtnjAeddwcl0ebo5jm3xSliRXBzhWjrxv+HbE/yq1jIgBfTvDyjfSvZKhtbOXkPKRCfz6h8bObSJl5gU3LfAqHiJxB//5MjAQ+hLnz55z7XDzXKVu21UuvhJxbzFro5iySdBBypD2MX4BF96AzwrAegF0HKu3RPya5Mw0PQ0r967s8AyYKpC0os1dHBKciRcyrVQQpixNx90a0gOAj5D4u9NQ89IOevAIaaUTMGThJhnbHNpGvfgMVrKAhS7n/jFOM3xoBT4Hi7sbuqbFBseGuD0mnGHLX1tHU1lVkoJat/8nTO5qoDau90V35HPGwuCvJH1vIxYWv9VSnPq1GtQhgdRAo39BFVSQoEuy0+MtkEyGFTzrfedVTxWPkDlFpfsW0JT3thFVJiuVxVTh2D/TXEid5isX0mTxAk0vbFlK/SEGuw1V0plhHgQgCl2sqrhlF9p2dySNWaG+e+ESi9mgqLG3uqQdEKiBefRIjdVAwrpOUbLjjEaRNH+kY19yhtrBGm81/+KF+8P7QMIztIpy8/cxutLkrxEm8XSAHRSXF9XhefNMUXOzH/M3o21lhzyZLP2YYmWfmLZUtW+GJgCuoG/RbtDsJs51WaIpgAxlcktmA4DJpYo9sr/SVLI+i+nr5BmuSwZ8/vWeV79jLnmbPoC2MPG7EWT0A6mCCjoyqtrYfAdafd9dOB2UxmFUsedjcJgVkxgnkZk9aYnudb7XRzurzeTRXdY14AKXS2wbu3vB/8DNshsYv7nlbUCTEPjoMgTb59ZV2zc1y5bKbXUtyy+dkBzWXPYiG/2qH4NQ39GEmqWX6rfeFw3BdjbGcs2kN7I3ef2lA8xNIZ4xOwSQG6aYoBQRt9Nk3RaFVxBoGnpOkGyg5eDt1+wovnI6hdQ92sb4cFl5HcErWObs40yyGITCBCe2Ys7bzIC9WI0ZmVhVhN75ni/vxwWAGQLytHuFe7ZQnf+iSXMPMoL/EZDcXw2Zn0b0BqnyKSg6N3GtoLMSJGy6eFD/0kjHx3EQGNYohrXGfD6Z+sPmwb2bKTGRjvSbrhu96PHlSUaRKGBh0DD8iztTBdstcevR0s7iiRqsYNWIAGVqrSIgIACAmRR30DdBjG7hf8PzGHrSUck3s2zIIzXRUjJMac/5sa4378q0Vc+mozqpg1xBJ7iIk6eFyHwxapAv4tbvDvSsreewayWN6yes0lzwV7vSs= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2158b769-a124-4a8e-5f15-08d9bc5da485 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:21:03.1600 (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: 976DrRoc0oS3UE7TBaANk6CHnUSUW7KC4UVMaMLwWDS4KwRwW3d5YRNAxG3FFXPgHh2+JCqQlq2AHLVTMRuq1g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We extend virt machine to emulate both AIA IMSIC and AIA APLIC devices only when "aia=aplic-imsic" parameter is passed along with machine name in the QEMU command-line. The AIA IMSIC is only a per-HART MSI controller so we use AIA APLIC in MSI-mode to forward all wired interrupts as MSIs to the AIA IMSIC. We also provide "aia-guests=" parameter which can be used to specify number of VS-level AIA IMSIC Guests MMIO pages for each HART. Signed-off-by: Anup Patel --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 434 ++++++++++++++++++++++++++++++++-------- include/hw/riscv/virt.h | 18 +- 3 files changed, 369 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 8aa9f8a988..74e9e333d1 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,18 @@ #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +#define VIRT_IMSIC_GROUP_MAX_SIZE (1U << IMSIC_MMIO_GROUP_MIN_SHIFT) +#if VIRT_IMSIC_GROUP_MAX_SIZE < \ + IMSIC_GROUP_SIZE(VIRT_CPUS_MAX_BITS, VIRT_IRQCHIP_MAX_GUESTS_BITS) +#error "Can't accomodate single IMSIC group in address space" +#endif + +#define VIRT_IMSIC_MAX_SIZE (VIRT_SOCKETS_MAX * \ + VIRT_IMSIC_GROUP_MAX_SIZE) +#if 0x4000000 < VIRT_IMSIC_MAX_SIZE +#error "Can't accomodate all IMSIC groups in address space" +#endif + static const MemMapEntry virt_memmap[] = { [VIRT_DEBUG] = { 0x0, 0x100 }, [VIRT_MROM] = { 0x1000, 0xf000 }, @@ -58,6 +71,8 @@ static const MemMapEntry virt_memmap[] = { [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, [VIRT_FW_CFG] = { 0x10100000, 0x18 }, [VIRT_FLASH] = { 0x20000000, 0x4000000 }, + [VIRT_IMSIC_M] = { 0x24000000, VIRT_IMSIC_MAX_SIZE }, + [VIRT_IMSIC_S] = { 0x28000000, VIRT_IMSIC_MAX_SIZE }, [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }, [VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 }, [VIRT_DRAM] = { 0x80000000, 0x0 }, @@ -309,7 +324,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 +345,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 +384,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 +452,145 @@ static void create_fdt_socket_plic(RISCVVirtState *s, g_free(plic_cells); } -static void create_fdt_socket_aia(RISCVVirtState *s, - const MemMapEntry *memmap, int socket, - uint32_t *phandle, uint32_t *intc_phandles, - uint32_t *aplic_phandles) +static uint32_t imsic_num_bits(uint32_t count) +{ + uint32_t ret = 0; + + while (BIT(ret) < count) { + ret++; + } + + return ret; +} + +static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, + uint32_t *phandle, uint32_t *intc_phandles, + uint32_t *msi_m_phandle, uint32_t *msi_s_phandle) +{ + int cpu, socket; + char *imsic_name; + MachineState *mc = MACHINE(s); + uint32_t imsic_max_hart_per_socket, imsic_guest_bits; + uint32_t *imsic_cells, *imsic_regs, imsic_addr, imsic_size; + + *msi_m_phandle = (*phandle)++; + *msi_s_phandle = (*phandle)++; + imsic_cells = g_new0(uint32_t, mc->smp.cpus * 2); + imsic_regs = g_new0(uint32_t, riscv_socket_count(mc) * 4); + + /* M-level IMSIC node */ + for (cpu = 0; cpu < mc->smp.cpus; cpu++) { + imsic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + imsic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_M_EXT); + } + imsic_max_hart_per_socket = 0; + for (socket = 0; socket < riscv_socket_count(mc); socket++) { + imsic_addr = memmap[VIRT_IMSIC_M].base + + socket * VIRT_IMSIC_GROUP_MAX_SIZE; + imsic_size = IMSIC_HART_SIZE(0) * s->soc[socket].num_harts; + imsic_regs[socket * 4 + 0] = 0; + imsic_regs[socket * 4 + 1] = cpu_to_be32(imsic_addr); + imsic_regs[socket * 4 + 2] = 0; + imsic_regs[socket * 4 + 3] = cpu_to_be32(imsic_size); + if (imsic_max_hart_per_socket < s->soc[socket].num_harts) { + imsic_max_hart_per_socket = s->soc[socket].num_harts; + } + } + imsic_name = g_strdup_printf("/soc/imsics@%lx", + memmap[VIRT_IMSIC_M].base); + qemu_fdt_add_subnode(mc->fdt, imsic_name); + qemu_fdt_setprop_string(mc->fdt, imsic_name, "compatible", + "riscv,imsics"); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "#interrupt-cells", + FDT_IMSIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupt-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "msi-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupts-extended", + imsic_cells, mc->smp.cpus * sizeof(uint32_t) * 2); + qemu_fdt_setprop(mc->fdt, imsic_name, "reg", imsic_regs, + riscv_socket_count(mc) * sizeof(uint32_t) * 4); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,num-ids", + VIRT_IRQCHIP_NUM_MSIS); + qemu_fdt_setprop_cells(mc->fdt, imsic_name, "riscv,ipi-range", + VIRT_IRQCHIP_BASE_IPI, VIRT_IRQCHIP_NUM_IPIS); + if (riscv_socket_count(mc) > 1) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,hart-index-bits", + imsic_num_bits(imsic_max_hart_per_socket)); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-bits", + imsic_num_bits(riscv_socket_count(mc))); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-shift", + IMSIC_MMIO_GROUP_MIN_SHIFT); + } + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_m_phandle); + g_free(imsic_name); + + /* S-level IMSIC node */ + for (cpu = 0; cpu < mc->smp.cpus; cpu++) { + imsic_cells[cpu * 2 + 0] = cpu_to_be32(intc_phandles[cpu]); + imsic_cells[cpu * 2 + 1] = cpu_to_be32(IRQ_S_EXT); + } + imsic_guest_bits = imsic_num_bits(s->aia_guests + 1); + imsic_max_hart_per_socket = 0; + for (socket = 0; socket < riscv_socket_count(mc); socket++) { + imsic_addr = memmap[VIRT_IMSIC_S].base + + socket * VIRT_IMSIC_GROUP_MAX_SIZE; + imsic_size = IMSIC_HART_SIZE(imsic_guest_bits) * + s->soc[socket].num_harts; + imsic_regs[socket * 4 + 0] = 0; + imsic_regs[socket * 4 + 1] = cpu_to_be32(imsic_addr); + imsic_regs[socket * 4 + 2] = 0; + imsic_regs[socket * 4 + 3] = cpu_to_be32(imsic_size); + if (imsic_max_hart_per_socket < s->soc[socket].num_harts) { + imsic_max_hart_per_socket = s->soc[socket].num_harts; + } + } + imsic_name = g_strdup_printf("/soc/imsics@%lx", + memmap[VIRT_IMSIC_S].base); + qemu_fdt_add_subnode(mc->fdt, imsic_name); + qemu_fdt_setprop_string(mc->fdt, imsic_name, "compatible", + "riscv,imsics"); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "#interrupt-cells", + FDT_IMSIC_INT_CELLS); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupt-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "msi-controller", + NULL, 0); + qemu_fdt_setprop(mc->fdt, imsic_name, "interrupts-extended", + imsic_cells, mc->smp.cpus * sizeof(uint32_t) * 2); + qemu_fdt_setprop(mc->fdt, imsic_name, "reg", imsic_regs, + riscv_socket_count(mc) * sizeof(uint32_t) * 4); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,num-ids", + VIRT_IRQCHIP_NUM_MSIS); + qemu_fdt_setprop_cells(mc->fdt, imsic_name, "riscv,ipi-range", + VIRT_IRQCHIP_BASE_IPI, VIRT_IRQCHIP_NUM_IPIS); + if (imsic_guest_bits) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,guest-index-bits", + imsic_guest_bits); + } + if (riscv_socket_count(mc) > 1) { + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,hart-index-bits", + imsic_num_bits(imsic_max_hart_per_socket)); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-bits", + imsic_num_bits(riscv_socket_count(mc))); + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "riscv,group-index-shift", + IMSIC_MMIO_GROUP_MIN_SHIFT); + } + qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_s_phandle); + g_free(imsic_name); + + g_free(imsic_regs); + g_free(imsic_cells); +} + +static void create_fdt_socket_aplic(RISCVVirtState *s, + const MemMapEntry *memmap, int socket, + uint32_t msi_m_phandle, + uint32_t msi_s_phandle, + uint32_t *phandle, + uint32_t *intc_phandles, + uint32_t *aplic_phandles) { int cpu; char *aplic_name; @@ -454,8 +616,13 @@ static void create_fdt_socket_aia(RISCVVirtState *s, qemu_fdt_setprop_cell(mc->fdt, aplic_name, "#interrupt-cells", FDT_APLIC_INT_CELLS); qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", - aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + if (s->aia_type == VIRT_AIA_TYPE_APLIC) { + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + } else { + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "msi-parent", + msi_m_phandle); + } qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_M].size); qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", @@ -481,8 +648,13 @@ static void create_fdt_socket_aia(RISCVVirtState *s, qemu_fdt_setprop_cell(mc->fdt, aplic_name, "#interrupt-cells", FDT_APLIC_INT_CELLS); qemu_fdt_setprop(mc->fdt, aplic_name, "interrupt-controller", NULL, 0); - qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", - aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + if (s->aia_type == VIRT_AIA_TYPE_APLIC) { + qemu_fdt_setprop(mc->fdt, aplic_name, "interrupts-extended", + aplic_cells, s->soc[socket].num_harts * sizeof(uint32_t) * 2); + } else { + qemu_fdt_setprop_cell(mc->fdt, aplic_name, "msi-parent", + msi_s_phandle); + } qemu_fdt_setprop_cells(mc->fdt, aplic_name, "reg", 0x0, aplic_addr, 0x0, memmap[VIRT_APLIC_S].size); qemu_fdt_setprop_cell(mc->fdt, aplic_name, "riscv,num-sources", @@ -499,13 +671,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 +687,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 +781,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 +802,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 +930,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 +960,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); @@ -884,30 +1080,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; @@ -966,23 +1187,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 */ @@ -990,8 +1226,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 */ @@ -1138,6 +1375,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 > VIRT_IRQCHIP_MAX_GUESTS) { + error_setg(errp, "Invalid number of AIA IMSIC guests"); + error_append_hint(errp, "Valid values be between 0 and %d.\n", + VIRT_IRQCHIP_MAX_GUESTS); + } +} + static char *virt_get_aia(Object *obj, Error **errp) { RISCVVirtState *s = RISCV_VIRT_MACHINE(obj); @@ -1147,6 +1405,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; @@ -1163,9 +1424,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"); } } @@ -1187,6 +1451,7 @@ static void virt_set_aclint(Object *obj, bool value, Error **errp) static void virt_machine_class_init(ObjectClass *oc, void *data) { + char str[128]; MachineClass *mc = MACHINE_CLASS(oc); mc->desc = "RISC-V VirtIO board"; @@ -1213,7 +1478,14 @@ 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); + sprintf(str, "Set number of guest MMIO pages for AIA IMSIC. Valid value " + "should be between 0 and %d.", VIRT_IRQCHIP_MAX_GUESTS); + object_class_property_set_description(oc, "aia-guests", str); } static const TypeInfo virt_machine_typeinfo = { diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 43603a769c..e12e8ddcae 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,8 +87,13 @@ 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_IRQCHIP_MAX_GUESTS_BITS 3 +#define VIRT_IRQCHIP_MAX_GUESTS ((1U << VIRT_IRQCHIP_MAX_GUESTS_BITS) - 1U) #define VIRT_PLIC_PRIORITY_BASE 0x04 #define VIRT_PLIC_PENDING_BASE 0x1000 @@ -97,6 +108,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 Dec 11 04:19:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12671663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 86751C433F5 for ; Sat, 11 Dec 2021 04:33:08 +0000 (UTC) Received: from localhost ([::1]:38036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu4J-0006y9-IF for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:33:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsk-0006zM-Vb; Fri, 10 Dec 2021 23:21:11 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsj-0001mA-Aw; Fri, 10 Dec 2021 23:21:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196468; x=1670732468; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=HTYIOb6C2qHs7esQRqgXBd67VP3nWWSgi2maOSH4iPI=; b=Ps1GraCMibUI+rpth7sh03pegvreUv2bvYwxYfpyXmgNnkI76DO5TE3I VcgIR8hgGRH3wV2WBcolfoExeqw3qbsDPzZIHmwnkewJx6nrRHYa2V79S NrFqXniMNZPVr1EFeWWk0O7vubxrG3XfLPFoRKX0NKhxVWZydUoOPiFqw EDABxLtML/pUfsK+Dc/sAK8UtrPWMpbF+O+RVIZxt6OXnaL2+l68pdnAu UcnxJ/ZD2fVryAbmNJme1iYMXqojHuaZLtuhYTlja0n66P6OwcoVEmGIz /E1ivXhyimI5uMlwy+XHCNhTQ1/auJYxdONZcLU7Z53WujYMWihpuluwm A==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989973" Received: from mail-dm6nam11lp2177.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.177]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:21:06 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EH+eslENPtmVcg6J0zgUnmEiJTVdrgpv8PPCYWaRju5pXHW8ADunN+fkp2saq3F21tVrXmGRh5bmz6aIwQRlBiyOJXB5tjLg34KmNByVN5XQf9GnMJRRKfymvAVdjVAN6uVrcE9fMyP5eeIC5rmKKKnp2lEMRyExe9Hr8gT9w4tU1UZ17kCSntaPM8+pds3NmgUpvEidExPoCXVPU/fuijoXtwPIaS0uvsSTUxxC6Ok1+wgL8t8hXVIk5mjRnQSAZSwo9RW90dEX39HwTuEdUrspjoKO68EOZLD2QOuZCTyuPCaTwwQVaSCJkXmyaIQs49QPtog0BRxTu1X00T6vcg== 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=fPB0ekPnr8SLzg7QYUgbgDe2mDgepgC3xv7V5/GSERTBLHYh5KIlxYKC6GRl9ju6v0Itaa2HDY8ThoYeO2MAUKMdAyAHygPBNZtmtu1Fe6e6KrQ7CxafIBOrz9+pnJ4koYJV2dyjS6oejajI0Evz0POzuGqg9gzoD+vsX1XZRnRrVk5Gikygv8pID2to7E4LSpc2RyywVG0LhVJwfPvR7Uk5vNd59v6oDvyQ9++UuQ1drdR/Z6XOjjMZBn9nSSBqv9Mv19f5qKP78kkmY8HEuwItAfGBQgh486/QxPaBGK3sNzkMtDUyvEisd0LORYn09n5TEVF3vpd5uugElW/xVg== 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=juNVbmK8l2DRIjdkzk4Kij/8GMmNZGsqCcQYDk94JoIMKy3gub+GHgWAdEw3BriygcgZdQ0UgeUFLoWUgL3xXoxq1pVuSAJKiBwYm5TXM7yI7iny7oTsYuqJedFFpvmhuaoWLsX1nw0lR3rJP0NaVpi+noAsUwCYfQDc7BX+QfY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:21:06 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:21:06 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 22/23] docs/system: riscv: Document AIA options for virt machine Date: Sat, 11 Dec 2021 09:49:16 +0530 Message-Id: <20211211041917.135345-23-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: caa7c4eb-fab9-4a67-213e-08d9bc5da68b X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ 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: KYiQAApquuh4smn/Gmfrk9s3ES4szfWBltWYtHJks70q9P6NNSMxi8LjvD01xj8afLVjyO4/BbMvx3Hp1prHpfNWNGU6X1vub9ncLMPKab3NW3W+p0dz+RLV24cUdY8LE+I6hIHqU9IixeGnEWIhkt0UuxpBQMuvDxig7wSn6myp6rhumqPAWnJbTLUGtfDhVJJFNSMP/xb6Gj1BqN0U6ADDywq8sFDu1rJkcc+MwLu8pMJhISdiqAq3EV/+TShzffJgvuwiNiaP4AZyoTQn/TzwZ4fDSx6BYoa08CXQ71EwOyEB7y2f1ckfYxyvqZLv/F4CQirSjkYc0LW80Zs7522KVDCL/RgWvGHDIdloG1CpJmWL6pr+oyiwSzEFBsgXRbXyU7TASa+L28rJcqGdOnl9h9TiQxXA2avKR+Vr6jQSWbVk9fwj840gYlLn6VP2zWDQtP4xuKCAJPcKfrwrFYM83dB1JGz3jmrWql5HXVEdzWblHYRvKyHz2skgc1ZkG0ty8Rd4nJXj0jlOFbHE85yt7SaTdryqqklKgyCVVStLxhTi2tOFvPIKZHC4wP/zNbISfjg5/T2IhKODexaYd5mBzErYmA0AAuip31yYjog28SLzYcPfcgbP0pWsxe5QK7RBfy2SPxOnaHmO7NBdwlxBjCLwMQz1zGG2HTooy3CK12lIVzhXDEasI2xDqkakTPcIneSC9d1OyT51zSengg== 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)(508600001)(54906003)(44832011)(36756003)(6666004)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S/IBWa69OBZqjjfwCr8pYKBjC17dR/ixldkrncSJAxLfl/mghkB+w+pfvlqILYPPGXOEWRkgOgJVT+ZAkYRsw1eBZtxY8SrOt4rqo2j7ynm+zznSnyl2hj24nlEiipunz3A2+vy9yn37lBWPDLD/kLN2H5nz9lZ7bVD/EXUTwUdbUTDlfwF1ptFavxTQ+JxSvVxfw+vNRPSt2pxvZuNuioXF8HcOWu3K4i8gi0oO78VMO6YZE5Hfj6q15CRSSg8S/fFtqx2rX3ATeu6SlhRBDdFYKQxFeBUyxnXEJay2pjGxhVmGN+vMZtbF7xUAXuMve30Okk5IenaKBg3uhOSjUuWQa0exL82KPjF4PbSK0ROkiahHdndL82WuIy0Y8ClNkQ/W1f2hWNCn5Jll6JNhweMI/bcuWdGhtlOhFx10iiSxND7gtS3ZqCYNtqbBfnhlmFF6oWaVsUYO3sh1nlnQDP4E9nBbvDaZPYnaXSf6wML8B8x7UV4vEb4MknHqmJQbP+kREm/u9S0+3yqIgcYS6b3bFGNVMNHsSS1C54vIeveqkoRitu9Ss2LCoJGSUPRbSs/bxhdeEg6XLn3G9GjhWb3jHQWfVYRXjxpCquYQXQsz+LIrjE7MpPORdxC6Y5DJKGB+bG0jFVxCXETummXwvUMkcJYXbpDA3bwIYj0dz10NRhRrQZKcUWdWw2cmr9ivU5hNxqgWpIYnj+pCGuYutS/lxH0zcM9bv8iA/sLJf7qSrCHWgAVWn1VpPP8VRLROu0pr3WXCI5ZXtq2zQ06P9+zqeoxmZaUTgVJi6L9fLOn1q7OYQ42JVavGMk5T5QTlevvjFa7JXGJMJuq4S+HrIMZXkvuLBMPS5M9S/IK01d2wUc8rK08ApYoEDN4jkVUOXzkl8G3VCmfbpCYhHhw7tdDcFkNixCX8o0JVoHYqft8EAPM1otfjUm9ANgprUX8duxyvYbA9A0m8frfuxs0TcD19Umz9FjdawCsKUhhd2eAj6ckUlND1VhJiZMHjk4GEr2M+zf6lFwU2PXqWnLM2fHTGfP6/+nGDVGuo5ZgnbflSD2Qpxg0NebIKQ/E/o5U4RMEcIB1grGRRbLH82K//xX46tC/pbQtEBeMSj7Xe74lIKhc44t7npnt+pFmtiOdiQuL6H0SxoDtDz9fQ12SrHLdOY0Dx4xKZ/18mikb1Bo6WwAVS/pQIdThLoLmEvKWOKUztU8yfmqtzsteSKoTfzugXeNVhEvlkdQO1llycIZM3M3AsTPaPB26m3TtX7kYhprYq8kPGnM8RCO4mxnvk6DI9AukKI+RwyLWmM+JPiIHGw3rvWgiY2Z4/M63d8TWvJFbVoRT4o82sX9SRbxlQyWIJ5+80VJHh3c0h20XgkrRnCvT9SM3TlNhGkfEhY0UCvj31aSCHN9DEbiTmwltVitIt6zzdlOfk1pWTJM9zzYLfICKU7YKcpxiyRwio7E1fRxoNGrfwSukL4c888X/h2OtF3vh0NWCxPBQl3VItWFxuDeSsm1QNQDGgSW9oE2Oi+wJPQdJPlQKfiP7Hx0rALzOCgfw+tWJEkAaLVdNFNH0spuCh9G+Wi4kM5RyaA81mPV154oObZCrQu0q3kKhQSA6nQfCrI3YDokWvwvpzZCA= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: caa7c4eb-fab9-4a67-213e-08d9bc5da68b X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:21:06.5032 (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: xaiVCLw14mLV6IUxRlYzPTUMrLrjRR4i08+CBMbruGdZP9kxDrBUiKq5oqj7Emhi5C3CNnxW7O5G4Y7A+OrL6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 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, Alistair Francis , Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We have two new machine options "aia" and "aia-guests" available for the RISC-V virt machine so let's document these options. Signed-off-by: Anup Patel Reviewed-by: Alistair Francis --- docs/system/riscv/virt.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index fa016584bf..373645513a 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -63,6 +63,22 @@ The following machine-specific options are supported: When this option is "on", ACLINT devices will be emulated instead of SiFive CLINT. When not specified, this option is assumed to be "off". +- aia=[none|aplic|aplic-imsic] + + This option allows selecting interrupt controller defined by the AIA + (advanced interrupt architecture) specification. The "aia=aplic" selects + APLIC (advanced platform level interrupt controller) to handle wired + interrupts whereas the "aia=aplic-imsic" selects APLIC and IMSIC (incoming + message signaled interrupt controller) to handle both wired interrupts and + MSIs. When not specified, this option is assumed to be "none" which selects + SiFive PLIC to handle wired interrupts. + +- aia-guests=nnn + + The number of per-HART VS-level AIA IMSIC pages to be emulated for a guest + having AIA IMSIC (i.e. "aia=aplic-imsic" selected). When not specified, + the default number of per-HART VS-level AIA IMSIC pages is 0. + Running Linux kernel -------------------- From patchwork Sat Dec 11 04:19: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: 12671667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E6AFAC433EF for ; Sat, 11 Dec 2021 04:35:29 +0000 (UTC) Received: from localhost ([::1]:42964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mvu6b-0001tv-19 for qemu-devel@archiver.kernel.org; Fri, 10 Dec 2021 23:35:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsp-00075j-72; Fri, 10 Dec 2021 23:21:15 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:26544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mvtsn-0001pJ-CC; Fri, 10 Dec 2021 23:21:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1639196472; x=1670732472; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=pPIEE8XbGesfEk2CBjMqcYQUkZKDZfL00tdxQ0VJy04=; b=rOz2H6JrgRyTmVDdUusMIZmFS1+hCkjM40oJFmiHLhEeuzrabhQ62Teo eIHWDtb3nWT78Wn8hSij0gZUVX/pOpG8xrht3aluYaM9tZeneUW2sB+Xm eIkmgy/bw1NewOBTJa4H0t3Q9Asfyc0+nayQygyZjOU1WWND1D+ijMG1n tIl9b4kgJth8hfMpB/j7e+XzH8vYIAbBNvouS23+3Hnb6Gx5L9uKyZ9tZ 1udTFZAgzGAarNMuXUpUYZ3N1drgD+S3zfO/aUzrYQ6jnIK+kxK3WBsRa bWd8S2CFG/LWImNOJ7uJploAfk/eY1elilHfICVweVPxTBUKKWjW0z1zD g==; X-IronPort-AV: E=Sophos;i="5.88,197,1635177600"; d="scan'208";a="187989981" Received: from mail-dm6nam11lp2170.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.170]) by ob1.hgst.iphmx.com with ESMTP; 11 Dec 2021 12:21:10 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dwKfa4cUkDUaTlzRhbe5vlZ2OWDos8I+oP1hO00TdE1i1jXY2M5teIe9Y4QzvgYzFrZgV9YjLs4d2Vf1JO1U3TmS6L3em5PqfZwSwacRRS2rn9qNFo393dtMXQZv7Fd7jSaGbcXDKpiNyrCeFNjHHJGoLfLtsDMbh1VAwky6qhI8NrRV1MsIotuUO9nvM+g8lvog1HrJWThJB4n1ZEf9UoFd4NMTrELnp3ldSPXVM/LteawPvm80cJS+JHmFUXGyJFVVcJ5bGyhQHWJMTokqSlYTB51x55mnPSQaeYqQRNhWk2E57T3JX4TDdOQ8yNkDzxvAIzqmtzwbu4/wwGs+/w== 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=blKRCzYf4VqrMj6ZYziZUuretpdWAdzPvDSvdjdV3pA=; b=S0e722Xx7tk0LHTCoguyGzdk0y39rIuHy4Q8RLOfjkgu7nGh1Stn7PnilECQg985ONS1x0+UgKrI9PQ1+4XQ1M0dvvJaAriXzUV32ZF76ETtciU2TE65MQEMz7yEEHXOmNNmRYYWrzGJyLGbso2GYgRczkxw8SaKgTR/RhxfwU8OJNyYHv3v2tU33Q+tPEMMmBMqZnOPjxDdR+jo3NnT3z7wILz2z4Kkh35h7XYDX+kGqujIEO9eaxxJPgoiNo0hXN8jqclDrZGxO8IA7IIIkjVnOrUHXMIh+C2tXivXBqksHDu6OesAyGdcmdAhRtQkVPSebRXeKoDAQPhIxS+WZw== 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=blKRCzYf4VqrMj6ZYziZUuretpdWAdzPvDSvdjdV3pA=; b=tASBBaRfOVG5vpaiPYWnTHZdbg1n+j91S48EUCGqaMfZR1ca2vTXcgqyxp1oqkySymxyrxTQhDxIk8SKTaPaKC+NkuDmaqcn4aIgUZ6meahX41TS94YcOAm7CZBc1KqeDHJ/yA2gdOEFAj+yiNEqxO2jzVirsHPeRbhsGDVDPo0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO1PR04MB8268.namprd04.prod.outlook.com (2603:10b6:303:153::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.12; Sat, 11 Dec 2021 04:21:10 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::f14c:5516:7743:932c%4]) with mapi id 15.20.4778.016; Sat, 11 Dec 2021 04:21:10 +0000 From: Anup Patel To: Peter Maydell , Palmer Dabbelt , Alistair Francis , Sagar Karandikar Subject: [PATCH v5 23/23] hw/riscv: virt: Increase maximum number of allowed CPUs Date: Sat, 11 Dec 2021 09:49:17 +0530 Message-Id: <20211211041917.135345-24-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211211041917.135345-1-anup.patel@wdc.com> References: <20211211041917.135345-1-anup.patel@wdc.com> X-ClientProxiedBy: MA1PR0101CA0041.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:22::27) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7b6fb0e-3852-4cda-18f5-08d9bc5da898 X-MS-TrafficTypeDiagnostic: CO1PR04MB8268:EE_ X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tRkgjvqTc52K/hBKtUXaIoj0ev0xmh6j5nrqvfC1tHR2goMGZyK0TgobQ5ZtwvTsHnJhSdnjni2579JM7Aq0n6QiUgJy2ZA00K36UNn5g/6ldpBlx6bqE0pcCO3IgmJBrCuTXn1sd7YUZP3JfK4+1F5X5Clri/AZmgTcStFMXRb34pfDe6m/sBLpVIhxgvvXT+ultmCDFOrMWf7F4fhojuMsq+vhNWGeVO92beKbNb2gfT5OaCgA2+O5YHmqHE9J5EqSiH+pYhm6Zo2P3BslDE6mcDShv7vZW4qBX1O0rAlxK1RxPIKVaO/2FNLIJ8AIpIlSwIicX+aR9hkYvlW+jJlxJJ9XXhmFkrksF5Zc3OBNV6lEqgFAca6XsYYo3kYfdN8iyVE1MFV5FxvOH9kzt7X0iY0RfB+m0hPlyLt4SCqiaIbNAqTCewJ/esysSyzDc0ZU6Yke8hw+PY9bZBL6vkw9P9TLuENhxemtVedRcVtfRYAqIbB8T5Qgj27FE4cu/HexNZ9F+AfRZ/SbHuI55V5qX23cV2Zpz1fQGyBCEpEOJuMKcb5WxnV+4zhaUl6gFaQ095eZdSrSBaXudd+0ojQekHv+MV9tWgkyBZ48JJDwCvRrHwSvH+8HUkfWMVDHB7gIS7posld4ZrpwbSG/0x11XXVQyHiut6RszU/HiHXMObzrezdkL788vFkkpJ9vi0y0MSP8d0OQ+YWF7ahQdg== 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)(508600001)(54906003)(44832011)(36756003)(2906002)(8936002)(6486002)(66556008)(38100700002)(6512007)(66476007)(38350700002)(52116002)(8676002)(83380400001)(4326008)(66946007)(26005)(6506007)(186003)(2616005)(5660300002)(316002)(82960400001)(1076003)(86362001)(110136005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IOcVEefp44K0UXQTl8XHwRjjOg7/s/8lvS8/FFU5Rwmkcw9pjQQwWpkeTKItaRqmXUSjLyBZafnInDdtaiDl4JTMnL6ABRtxXqL8AEPVDtkmvtOrFd7H7djEAEMPdtV2TXqzkDvGf9x/sp49et1j4rbsPfyGdmqqv+sAM0zQFWTkX4exPp7BEYPr4iNbtqsfQK/uK8LjlYCdWk/sGSSKVT/7IWxafLZrt3d7+hf3V89WUW58wv+T/dBQMj1lfWUUoDDtYepmeQ9j3UQ1OhJ8Kv2fbfiSPezGlI8JG33ybSy/ISzt3RQa+mTrQB5s+m4WHxDUR6odJB3k/VgeMCJOG5xvfdvgr640dxyxdWEL7KpnQtipklPht4KKxJMpdghgGNvgvWVma1zPXS17hMz2LH15udWhsiXCP+eIHS6316t5v6fOf66F7CYPMkWZS0Eywl6JVjSlkOKhEENB6nJOlYQmqr+1aN6IVx4M7d6SbogG0CdSvAt2h2PDgqekyLS73HBVOe945/9rBL7FdJEKvkQejF0WR81tj7WIXR3Cm6D/gkCsu0Kw3DOKdos4IuqMtqzITjptooG7cWtuPaFv/be2lE/bFwraEA4hTzkvPpQsefnOoDMlWhbqssILBuNIdHcRI+CqjPqBhjzsL0XfnCwRAAVtC8tSrWEz/7yrvd2/vtfTVI37oeZDLUNuBk9UxgnwxhFIRNuanes8FOpVa9PVlv8CZmkA53GA57A9VqhW4kJpdrEbq8lyKg3HHJ3f5noPG7XrY5+zV8lZhPw8xhfkb7+Hq85E9i12BHytrSaNmji5jxm31KB61ZLB+MuT+9lqE455ervehypfbZlwt6D1SjnSJzhEBj9b9xVDXSRoQaC1jmdoJQ6FV1l7ulvTNk9HvszB6SAaz+4bLemo2a7dQaAYwGKXgKKXMoNvp3i+Zov1zCup472l4MrbbfXNi1YvQG1ktHzevW4o5ztW6NA+mVevttgIyKqBVaALZIkgPIGUOsIMtirVupITeCis84sMHpJXeMRratUr8YxbuehIKYxqxEZG5XXiBuISrMxkqmUw5c6bV9Sh+eLzaCh/5fD2EPGURiFyQL6kDwSDztnFXbfcEHvLYBpP0QV6F2LSPgBU3Ryb325/HTNSIZHbOSFX8XuBLFXvwBiqNly9xJrnit3L+vJA1TwBdstNuL7DPnDGjMH8y+dJ1ckv4owcHDixWEF/dY9ynzG0o7fh7SRNcp3cPq4sFJTheeNzFNtkSh+nJZhfMC8+ueRM+Hmh9tRYwuv9ID7teO4hThZnWKNXBlNdEiJmwFpdpJfpOLgZ6Lq/RzfTDLZ7XIIDuHDZjBECOaTNaRi8cSsM2RxjplCEtPqFLhfqgAAGg9OkzK0/ArTEaMU5ZohNLIhkoz35Klxb/8rNh21veNs1o86JUO0uoKJb4L9WVBYegITF5XpVRwb45nXVRFLDS+iElhnVek0cnm+NNtUR39fH08uB9BHbJLaU/dqkjUQB44Rckw79N5Ry4UxOTN+FE8RkgihNZBZNalGjcicREj9W7ho5xwub5fZ4cMdDbNGaMy0eF8Cn0eGwznqqIzy2Tra6i6+8MUvvvqI/ZMuMnAKuPjt2BANXnzoumCaeAdY+psLJZMg= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7b6fb0e-3852-4cda-18f5-08d9bc5da898 X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2021 04:21:09.9437 (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: M8Mqmbp/vdto4PwH1Gtfia+go1z1c37rNpZNmpBnOMwZH2CIkOsMaUoUQeeStIkH3L5XxJIbEBalK5o/Ixjsqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR04MB8268 Received-SPF: pass client-ip=216.71.153.144; envelope-from=prvs=972e533d7=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, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-riscv@nongnu.org, Anup Patel , Anup Patel , qemu-devel@nongnu.org, Atish Patra , Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To facilitate software development of RISC-V systems with large number of HARTs, we increase the maximum number of allowed CPUs to 512 (2^9). We also add a detailed source level comments about limit defines which impact the physical address space utilization. Signed-off-by: Anup Patel --- hw/riscv/virt.c | 10 ++++++++++ include/hw/riscv/virt.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 74e9e333d1..68ab915525 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -44,6 +44,16 @@ #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +/* + * The virt machine physical address space used by some of the devices + * namely ACLINT, PLIC, APLIC, and IMSIC depend on number of Sockets, + * number of CPUs, and number of IMSIC guest files. + * + * Various limits defined by VIRT_SOCKETS_MAX_BITS, VIRT_CPUS_MAX_BITS, + * and VIRT_IRQCHIP_MAX_GUESTS_BITS are tuned for maximum utilization + * of virt machine physical address space. + */ + #define VIRT_IMSIC_GROUP_MAX_SIZE (1U << IMSIC_MMIO_GROUP_MIN_SHIFT) #if VIRT_IMSIC_GROUP_MAX_SIZE < \ IMSIC_GROUP_SIZE(VIRT_CPUS_MAX_BITS, VIRT_IRQCHIP_MAX_GUESTS_BITS) diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index e12e8ddcae..62d8e9c6d0 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -24,7 +24,7 @@ #include "hw/block/flash.h" #include "qom/object.h" -#define VIRT_CPUS_MAX_BITS 3 +#define VIRT_CPUS_MAX_BITS 9 #define VIRT_CPUS_MAX (1 << VIRT_CPUS_MAX_BITS) #define VIRT_SOCKETS_MAX_BITS 2 #define VIRT_SOCKETS_MAX (1 << VIRT_SOCKETS_MAX_BITS)