From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556802; cv=none; d=zohomail.com; s=zohoarc; b=JBs9cIbv5dCq1tUXhuKwtAIaM3BjjbmEKpXbu86HjW3i6RqoshO5B6RY3fGO1y34NJBNvq46vZuKpiBz1NuZSFpQczeG/sDVdMe0lmX0vVWo4qCZoimc8d01EVR5CbEx5l5Wb9j02lpsunBlEbeKo2ilp93BFKm4AVPMZBUuQnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556802; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VGV1KWy6owzcRo+p6zTE0Oo94CDkgww6jTyroYlmkBY=; b=HabJ30NFmb8IkCq32XUyUVAjdjouVEycI5Z6qcVvnk+EpJgOAyQ/z05DHyYenveYUh4y5+AQDAPUrbiPWmbVZsGQPXyq+r2ALmZGPfvmkN+q99ppFJsyovwKAI1bQWK650Y/puPE0d0sWVdOVATz9QsT7pDSj5xB6HD95hw/RgI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556802337136.55745968634176; Fri, 13 Nov 2026 00:00:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCE-0002jp-TX; Fri, 13 Nov 2026 02:59:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmC8-0002j5-4B for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:36 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmC6-0000BQ-9s for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:35 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD5717W367205 for ; Fri, 13 Nov 2026 07:59:31 GMT Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwbx344pq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:30 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-37233fa9a08so19012eec.0 for ; Thu, 12 Nov 2026 23:59:30 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=VGV1KWy6owz cRo+p6zTE0Oo94CDkgww6jTyroYlmkBY=; b=GUOczB0FLPywA+BUWqLKt7n4HMN eJs5mmYwhqP4szqnOTFeRk+2PNJINliVR/SEvlFTZT7t+W2+EYdA9UE/hP+/wipq KCj+IMrBH+1H4FKrKMgf6vDYprYm5tEf/YjI00vsNbCQb1D+TwC0PapbiQE6k2v0 FlNvD8tQYJCijD+lk0xQwR3XmGIlCsJlnwzbkRS3DdgLvTtB1UKrnhGNhdhdUGbu mHEH+/WWXwVwUyd5DWviAkY87fG9VEXQFTIl6owY6lCKIgkzVRPaoUg/Kum/c+jo v+rH3cX6Bmnz3m0XTtngEE0tfxlJaUmvmXvjFRyW1mz9ioVOvQO3dLy8Zjw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556770; x=1795161570; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=VGV1KWy6owzcRo+p6zTE0Oo94CDkgww6jTyroYlmkBY=; b=Bpfg7f5gIoa8iX07+ahC1Qeh12TTqjSTTTqXuPuVqdjSzJ/K/1M0i4N7iV0tVEuy22 KmWqnAvw2lKrdW0q0yyDZGUsHyPzSkdN+d7UfE+0+MTPz29apbZiR+5vPVETIy+EAdjk qcpyllPThuSmjUmzMl77gSK6ksQoBALeO3i6UyehxNwYDVykhf0lFQhGQkC2Yjn1IfEt ocFuvuL8DS2GqtVF9eaCgGC9bG4beYJYimf1AJyR/CyKySvTCzYN/ksp5qUM/3roVYxq lKQF0DgaTpf4JHmWck6jicm6Zwl3rLBiwOPTh4BbCZMEnPbA5Jfz+UVuhvVQ77KPpzYL jOvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556770; x=1795161570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VGV1KWy6owzcRo+p6zTE0Oo94CDkgww6jTyroYlmkBY=; b=DuEbkBS/RasS8vpTqrBuDw5cF7xDvstnlF6LjHITEgKt3bwAWoHprKJsZkLAJte/KX 5OC5+R00on0bRyBkMcnoTvcsemJKn7HSQgH6/wTYotz/zs662uga0Xo5Nw9EHUU9em/S Shu8/7xm16GqZ00PbaePBYK412hAncfCmvEWZ5owsqqA6IbUiT3vcINyfMKYswxr9xJD qACLDyhevxM5SJBBHvwfPhMg9skHM1+jBYqNPYWJjH/+obJ/vuKQfVvMFgcprJbUNFvC iJu50hrF8QfX8OVAvGdgxqBBCxX4dEIWH1OPWxeBStuJqmhmATWHMevv6xpOjOIZzT4U 4H5g== X-Gm-Message-State: APuU4Z/VRTBO/8CmcfFLKOjH0r9dbVApTFiV6T3qSeVOeKTH0j1v8myy gFTDjJNlSEX+MIwk+7PUhr0AfDPTYDrdL9yGVGu0712gZab4jQO7SU2THq1MRcQ/oxzTbaPsHZD S0adqknL+0K83BsCqTHFn7A/GGQY5kfXS21g8RTRvJ1o/mdv9g24fEx6C12TLtkQEiA== X-Gm-Gg: AYBFou18rw3WQA4ndCuw+csiDqSDhHoV9tP26QKM/0rSeyLknT3RN/bUzYzBRmMve78 KZPgF6N9xraOTOKnBBjX0oWKtVaN5xtxlR/amZpUr3Th1Ioqnc9GFJRxbLvkXaQzdLBM9+32R+M 7zWyqkb1sIAh5l7TiKWxYm7fk0ubXAr9hLDCwmQUENABrimwyTzm58bXO368pqI2/9o4YVg48az pdUp39iLEzr0ze/PRvh6hS3DaSpfmojggcVdDYt2AblLlLxheaOtPh7ryww4G5S9fkrF91PO9Re KHEgDMgMEFWJz+M409I7PuSQCVOFfgKJfjRcW3PTqeRm5c+ujUt+rgmIVYcgYzzgmwEhiZ8jKyW yQmpMS0FYccitqhK1FNGv7fsSpVNcgG+tnsbbqGZk2Bv2bpN6mWAbqVrDudJb12E4jqxLxX2b7l bfTTEzXPMIW2AD6KFL7YwTy2D7aZG+6ECcNs+rVnFUBXG/sZ1tCiFtvHIbL2B87tIAIf7jivhgC Np8QQs= X-Received: by 2002:a05:693c:83cf:20b0:376:6ba5:6090 with SMTP id 5a478bee46e88-37964e03109mr2913911eec.1.1794556769721; Thu, 12 Nov 2026 23:59:29 -0800 (PST) X-Received: by 2002:a05:693c:83cf:20b0:376:6ba5:6090 with SMTP id 5a478bee46e88-37964e03109mr2913867eec.1.1794556769132; Thu, 12 Nov 2026 23:59:29 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v16 01/10] build: add optional librpmi dependency Date: Fri, 13 Nov 2026 13:28:56 +0530 Message-ID: <20261113075906.715870-2-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=S+5MU4sP c=1 sm=1 tr=0 ts=6af6c362 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=b0ZNuq6sR8mh__2TUtUA:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX12AuQQEWEfTB HeeplGpWkOTBsnzoWu8LYu60Ov9HSO+3v96QYWBixhb3LNanq1uukhY/Ces96Er4ei3EaKtoiY+ steYIcu0F/ddVipGFHuk76uPe9Xox7ATq/x/RwMwkhCuhORBZqQELyX4i4o47x6YRk0zdXjrcCx QNqnhyH0mUUYT10oMSa1TPCWNvGd2KMnlAFg6gTVXffSQUo+U9Aeg//3MIFnB2ojEERmkNrYzeQ 9owQIXKCqudzRwFKv88EBwDbtEnyJYi/itWC4gb1SBUCmFfcm8zKjIqYwxoxnPftl4yqqpMJHv/ DBffJTl7v+uZAvl9Z6tlcyBjtUPmuroUWgEmvZAdfpjR8VPA4dgElGXAyo9XFlruhvjiWH2VaVd VyuFMBv4PPA/dPigM6yph+5jkW8CHkgaGnuQqo7UMYCuay6XKJqzU4NglT1zM1CEhHNkKMSIZrV /LXLxwukjAN6gsAAg2Q== X-Proofpoint-ORIG-GUID: nHZWrAcCWcGwdh0KZ61t7v6zfLxIl8au X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX9cTawTzABohE bi4Gnj1UeHkUl3NJt+4PEXCRZhOtfY1g4cVflsCSdmEj3PIFx5KRurc8H1sF6nT05LQ20gJsP4a wKy1rUskkmzprk+ZRVUIYJ/XesL7UcQ= X-Proofpoint-GUID: nHZWrAcCWcGwdh0KZ61t7v6zfLxIl8au X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 clxscore=1015 phishscore=0 malwarescore=0 adultscore=0 spamscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556804543158500 Content-Type: text/plain; charset="utf-8" Add a meson option and config probe for librpmi so RISC-V machines can opt into RPMI support when the library is available. Keep the dependency optional so default builds without librpmi continue to work. Require the System Suspend constructor used by this series. If a found library lacks it, warn and disable RPMI in auto mode; explicit enablement still fails with the unsupported-library diagnostic. Signed-off-by: Subrahmanya Lingappa --- Kconfig.host | 3 +++ meson.build | 19 +++++++++++++++++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 +++ 4 files changed, 27 insertions(+) diff --git a/Kconfig.host b/Kconfig.host index 933425c74b..6f98dadb2e 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -8,6 +8,9 @@ config LINUX config LIBCBOR bool =20 +config LIBRPMI + bool + config GNUTLS bool =20 diff --git a/meson.build b/meson.build index 71f135f053..3dd63772e7 100644 --- a/meson.build +++ b/meson.build @@ -2026,6 +2026,22 @@ if lzo.found() and not cc.links(''' endif endif =20 +librpmi =3D not_found +if not get_option('librpmi').auto() or have_system + librpmi =3D dependency('librpmi', required: get_option('librpmi'), + method: 'pkg-config') + if librpmi.found() and not cc.has_header_symbol('librpmi.h', + 'rpmi_service_group_syss= usp_create', + dependencies: librpmi) + librpmi =3D not_found + if get_option('librpmi').enabled() + error('librpmi support requires the RPMI system suspend service grou= p API') + else + warning('librpmi lacks the system suspend service group API, disabli= ng') + endif + endif +endif + numa =3D not_found if not get_option('numa').auto() or have_system or have_tools numa =3D cc.find_library('numa', has_headers: ['numa.h'], @@ -2449,6 +2465,7 @@ config_host_data.set('CONFIG_LINUX', host_os =3D=3D '= linux') config_host_data.set('CONFIG_POSIX', host_os !=3D 'windows') config_host_data.set('CONFIG_WIN32', host_os =3D=3D 'windows') config_host_data.set('CONFIG_LZO', lzo.found()) +config_host_data.set('CONFIG_LIBRPMI', librpmi.found()) config_host_data.set('CONFIG_MPATH', mpathpersist.found()) config_host_data.set('CONFIG_BLKIO', blkio.found()) if blkio.found() @@ -3286,6 +3303,7 @@ host_kconfig =3D \ (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=3Dy'] : []) + \ (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=3Dy'] : []= ) + \ (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=3Dy'] : []) + \ + (librpmi.found() ? ['CONFIG_LIBRPMI=3Dy'] : []) + \ (have_rust ? ['CONFIG_HAVE_RUST=3Dy'] : []) =20 ignored =3D [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR' ] @@ -5036,6 +5054,7 @@ summary_info +=3D {'TPM support': have_tpm} summary_info +=3D {'IGVM support': igvm} summary_info +=3D {'libssh support': libssh} summary_info +=3D {'lzo support': lzo} +summary_info +=3D {'RPMI support': librpmi} summary_info +=3D {'snappy support': snappy} summary_info +=3D {'bzip2 support': libbzip2} summary_info +=3D {'lzfse support': liblzfse} diff --git a/meson_options.txt b/meson_options.txt index 9ae8e44ab5..62c9eaa20b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -208,6 +208,8 @@ option('lzfse', type : 'feature', value : 'auto', description: 'lzfse support for DMG images') option('lzo', type : 'feature', value : 'auto', description: 'lzo compression support') +option('librpmi', type : 'feature', value : 'auto', + description: 'RPMI support') option('pvg', type: 'feature', value: 'auto', description: 'macOS paravirtualized graphics support') option('rbd', type : 'feature', value : 'auto', diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 0f8b56bd7f..1c2ad8f0f4 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -147,6 +147,7 @@ meson_options_help() { printf "%s\n" ' libkeyutils Linux keyutils support' printf "%s\n" ' libnfs libnfs block device driver' printf "%s\n" ' libpmem libpmem support' + printf "%s\n" ' librpmi RPMI support' printf "%s\n" ' libssh ssh block device support' printf "%s\n" ' libudev Use libudev to enumerate host devices' printf "%s\n" ' libusb libusb support for USB passthrough' @@ -390,6 +391,8 @@ _meson_option_parse() { --disable-libnfs) printf "%s" -Dlibnfs=3Ddisabled ;; --enable-libpmem) printf "%s" -Dlibpmem=3Denabled ;; --disable-libpmem) printf "%s" -Dlibpmem=3Ddisabled ;; + --enable-librpmi) printf "%s" -Dlibrpmi=3Denabled ;; + --disable-librpmi) printf "%s" -Dlibrpmi=3Ddisabled ;; --enable-libssh) printf "%s" -Dlibssh=3Denabled ;; --disable-libssh) printf "%s" -Dlibssh=3Ddisabled ;; --enable-libudev) printf "%s" -Dlibudev=3Denabled ;; From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556842; cv=none; d=zohomail.com; s=zohoarc; b=kAxmyx2FC+SZwSCSNCkbQEDWKWPb4ixX4b48Ror1wfr/7kT3NAvPK+i4500O3JKCk3dvQvOcDAYPkPHZaF8vyjYvviMRpjh74cdewwiUVcn3g0Dm+i1+bIlucQab/vNq0h/oOC+lemoFZ3ajx1Rfix+GWWy9eSQ5NSBZgijnSX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556842; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KrDg/5MaP/Q9UukVJu8l53DA9vnoZxIw0GsPTE1fzqo=; b=RuYi+9fPzjEqj7+29/FR+kU0KaaEkzjDeOxHBN6dnsCIE21ki5uVh5fBMdbU4LmyemjeLxcR8MDY6I1GF0ZE7yW8YCvICHFoDtu9XzZiH4bEWBBUqXpxm3vDTvK4wWpLoMflT4DvCoAbAAv038uWiQKjVhf/zgVpZ/zU5X4h9MU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556842386436.15476099034254; Fri, 13 Nov 2026 00:00:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCH-0002kk-OH; Fri, 13 Nov 2026 02:59:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCB-0002jN-Ke for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:40 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmC8-0000C8-GS for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:39 -0500 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD57ACn3615973 for ; Fri, 13 Nov 2026 07:59:35 GMT Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwh0ajsec-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:35 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-30c58d35c0aso115094eec.0 for ; Thu, 12 Nov 2026 23:59:35 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=KrDg/5MaP/Q 9UukVJu8l53DA9vnoZxIw0GsPTE1fzqo=; b=nS33A3k9nITr7Hhpl7rrwBdN9Og i3kMjJNt9YVv3AaunEwzgMJ8MNQmfnzQYU7ybtkXgGMVlaMa2XrcD9kEKgv/Y/14 +Z6vJQISo6GMH50961LHygo+XEygNg2MMApQiiAJrcHozKOc2f+dle8O9bYy/6+w 1gho0rNfk6iau6PCIDOTAQm4FL+f5tdaJdXTcLGKf5lY439QLQVBgKTmJPKJsuKT ACG1r1Ya1mVj5vRqgqyWRmp2MKyUTXl9WlDeaELJKkbp20azG7hLDxUw0xLdd0yJ opGLZw0WFoNNiRiHQJ2Z9nRgiPtdnKl4R2f19ekwmeAjsENJcr1gFEYKKzQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556774; x=1795161574; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=KrDg/5MaP/Q9UukVJu8l53DA9vnoZxIw0GsPTE1fzqo=; b=FcYU+EPaIFZk4+CM0Xz2D7oyS/mMdZEjxIbVN5LrZFK90iGEMwgpD1zGBpSAb4qcum 5faf6e/8r4Y73M2iWPRFh/jbooZ3L8j/0FjTaznr+9b/wdwvfNy/ubDWXCt9W4HvoEtZ IsYWEr2bPxL508E9wddmVxqxoB2/lPNlogNpylvflO66Jlr3GWIHDLczF7MR7tcX4J0U tdHWg7LLANVUXSt9qDeU8S2NKQYfSIzCROrWc2qx8K9Fv2IrQu5Hpz7qMloICnI4K+Gi Qpe66fPD2GipkoYWvNbo//dXG0c5P9P55Fn7Xae9JZqUc9pR3PD7i9C183+fnVpJboor ZZkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556774; x=1795161574; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=KrDg/5MaP/Q9UukVJu8l53DA9vnoZxIw0GsPTE1fzqo=; b=P6ZUVOq4/ofDRv+04t8MHTIjnjhHoMOVVhQL00cBsWczqz78Okt8lcr2EwpcArNevY pVBt8X86iANqSRWgqMH+v40c8MarPaGje2qF0tF0GlTXP+hWHefR8+CICT+ZokABGGt4 WwgYAHP/gYA5WKcWLW+VlhD58ziGL/k3E/nUZXr2iCVY0+OSPLKdfhFpScd5xi3hvufZ 8hg5uGM+3ShbNDI7N4miOZNx8GF+sIGI9+wfWuTrZtpaMEvCZ8gtZ1wiMGd17I8M0L3m TxORRgy3efZtoU975o8SFrVFVRAC7SelbDPPnOjCgPZcl3XdhjEsY52hM/hjuUnalUu6 YtNA== X-Gm-Message-State: APuU4Z/KUgcVIKzTVShoJ/Xr7ud9rPB5MFfj4XdqSs/c9Ik12Q4rmUL0 A5fPTLlR2WvQsjo/RKMDxnYwQHY02tCo/yMpMe3M1s9eOLkygZfd6PCUEMjlk05wgVBP0bhs6G0 nuNr4hq8c+HdfZFL+kaYH6ih1nkHg15jXM2JmJZ0OHzlk3j8tmtTB640YbkY9uqP38A== X-Gm-Gg: AYBFou1g+j2mldAbwYp5nWukkYXCWnJoUJeVXwobQhQFiIIi9R3SOHY++htUEIlYC5T ugqfuPhOc3p7FK41ySQ9p46/mOANMiK9nILU97x1+6H2VEU6rPSaHPBNzJUUuaunQhQCYrI4fjr vm5sVRQSyTH2txZuO4T/7fvmA0WIkR6U/EOp9sYcLOHMBMdcTjdzEW9/Z06rMvpf9XDWwVLxA9d RKxZkxtKxob3nVGaY/+mSN5N9pirzYhytjnwtFBtfQnNlyIrMcSgpyM20TsUVCovZm4Su7jTqSI nXyHbl2+gJ+u+z0Hppty7UFa/t+MQOKVAnhulJhQP1G0dEjs+WH9khkdmRHaCA/pLPCFvs+wMRY 1dwVOR/IEE2IAMsGRT8e5oqyBw8smhbsWI+EhaQ/i3vy/CbgRTwZvs4MAYwdN5LJ1FgXUZMdbIg 49WYF7DRmkY9134nD63deNG0Vgvd+QD12aoWcfwi5Xnl4zTZAbSOdPm7Edn+qYQ7trdzbax7LmU l3UBpk= X-Received: by 2002:a05:693c:881a:20b0:36e:66d8:1424 with SMTP id 5a478bee46e88-3796047ff23mr2327007eec.0.1794556773837; Thu, 12 Nov 2026 23:59:33 -0800 (PST) X-Received: by 2002:a05:693c:881a:20b0:36e:66d8:1424 with SMTP id 5a478bee46e88-3796047ff23mr2326958eec.0.1794556773118; Thu, 12 Nov 2026 23:59:33 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Paolo Bonzini , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v16 02/10] hw/misc: add RISC-V RPMI transport and Base support Date: Fri, 13 Nov 2026 13:28:57 +0530 Message-ID: <20261113075906.715870-3-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfXxpUsYsIW4QpD U9Og9Iyff2Ttg32IH+9DDxjSttug2EhuNDxuaLH4KLhuJfyZkF5cPYxcpYvy2Wzh88x3n0esi/F nVFm6ECwQYR0we57jzRTccVWuMKgdgk= X-Proofpoint-GUID: vmj5QfHsNcO7PtoQJLQSKMichxrt9tZr X-Authority-Analysis: v=2.4 cv=N+e8hG9B c=1 sm=1 tr=0 ts=6af6c367 cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=V1jnuoLLAAAA:20 a=NEAV23lmAAAA:8 a=hwM_GrIuAAAA:20 a=EUspDBNiAAAA:8 a=bDgSmJffVkpEkReGgNYA:9 a=PxkB5W3o20Ba91AHUih5:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX8stoK+nniu+i Xx40zNapQrIO8W3Ar2aNlMgwde5trRpYg797gkg30bSu1L2ef4RcCXsPfLneP4sfkQWtveOsHMh 4gWRMP4SanJP9rUkcMcqhKaAb5qx+gbXBNduGDgXvF21hxlaLUXv8r50Tj8DTbcqX86obIRZdu+ XkfA6ruMXJmiibVW1Jn2LAprLsl4qK5yKSRHxzJrqk9V9aTsTHvOSnTLNr3oHz3PYWelKFEOWG4 sZRI6v3rljpQItSvxItHrujOAzCK6qeaDDR4Sg+DXOe6+WF3HAlD9XnSnnfG9bUN01Vl//r0RPO qUg938v6nSGGWCznoM/YyWJA1Xs4/71FwHjEGOkDO617GtLNNouNnfS+boV4ZJ/BpCpkJcAyFpu DhW0eS1NGMBWojMawkDmU1FhNn1Wa9Q2nJ4qv2oTTIFKGFo2qgl8gh1EqpwngXyZ5NlqFOiNXsS LFzcUimEp/7tyhF0zEw== X-Proofpoint-ORIG-GUID: vmj5QfHsNcO7PtoQJLQSKMichxrt9tZr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 clxscore=1015 malwarescore=0 bulkscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556844838158500 Content-Type: text/plain; charset="utf-8" RPMI (RISC-V Platform Management Interface) is the RISC-V non-ISA platform management specification. It defines a shared-memory transport, message protocol, and service groups for platform management. Add the QEMU transport backend and Base service plumbing for virt using librpmi. Keep context lifecycle, service-group changes, and request dispatch under the existing device paths' BQL ownership. Document that the librpmi environment lock hooks are no-ops because QEMU provides synchronization at the call sites that need it. This implementation targets the RISC-V Platform Management Interface (RPMI) Specification v1.0 Ratified: https://github.com/riscv-non-isa/riscv-rpmi/releases/download/v1.0/riscv-rp= mi.pdf The librpmi backend is maintained at: https://github.com/riscv-software-src/librpmi Signed-off-by: Subrahmanya Lingappa --- MAINTAINERS | 2 + hw/misc/Kconfig | 4 + hw/misc/meson.build | 4 + hw/misc/riscv_rpmi-stub.c | 16 ++ hw/misc/riscv_rpmi.c | 522 ++++++++++++++++++++++++++++++++++++++= ++++ hw/misc/riscv_rpmi_internal.h | 25 ++ include/hw/misc/riscv_rpmi.h | 92 ++++++++ 7 files changed, 665 insertions(+) create mode 100644 hw/misc/riscv_rpmi-stub.c create mode 100644 hw/misc/riscv_rpmi.c create mode 100644 hw/misc/riscv_rpmi_internal.h create mode 100644 include/hw/misc/riscv_rpmi.h diff --git a/MAINTAINERS b/MAINTAINERS index 55463103ff..7f7764b03b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -379,6 +379,8 @@ F: gdbstub/gdb-xml/riscv*.xml F: hw/char/riscv_htif.c F: hw/riscv/ F: hw/intc/riscv* +F: hw/misc/riscv_rpmi* +F: include/hw/misc/riscv_rpmi.h F: include/hw/char/riscv_htif.h F: include/hw/riscv/ F: common-user/host/riscv* diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 685b7ff1e7..cabdf3473c 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -303,3 +303,7 @@ source macio/Kconfig =20 config QCOM_QDSP6SS_CLK bool + +config RISCV_RPMI + bool + depends on LIBRPMI diff --git a/hw/misc/meson.build b/hw/misc/meson.build index fc3800baec..b755796170 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -182,3 +182,7 @@ system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files= ('axiado_clk.c')) =20 # Qualcomm Hexagon DSP subsystems system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true: files('qcom-qdsp6s= s-clk.c')) + +system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( + 'riscv_rpmi.c', +), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi-stub.c b/hw/misc/riscv_rpmi-stub.c new file mode 100644 index 0000000000..dc32b43227 --- /dev/null +++ b/hw/misc/riscv_rpmi-stub.c @@ -0,0 +1,16 @@ +/* + * RISC-V RPMI stubs. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/misc/riscv_rpmi.h" + +DeviceState *riscv_rpmi_create(const RiscvRpmiConfig *cfg G_GNUC_UNUSED, + Error **errp) +{ + error_setg(errp, "RISC-V RPMI support is not compiled in"); + return NULL; +} diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c new file mode 100644 index 0000000000..cbfea1f733 --- /dev/null +++ b/hw/misc/riscv_rpmi.c @@ -0,0 +1,522 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI transport device. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "hw/core/qdev-properties.h" +#include "hw/misc/riscv_rpmi.h" +#include "hw/misc/riscv_rpmi_internal.h" +#include "migration/vmstate.h" +#include "system/address-spaces.h" +#include "system/memory.h" +#include "system/runstate.h" +#include "librpmi.h" +#include "librpmi_env.h" + +/* + * These functions implement the platform hooks declared by librpmi_env.h. + * Its inline lock hooks are no-ops; context lifecycle and request dispatch + * are serialized by QEMU's BQL. + * See https://github.com/riscv-software-src/librpmi/blob/main/include/ + * librpmi_env.h for the external hook declarations and their contract. + */ +void *rpmi_env_zalloc(rpmi_size_t size) +{ + return g_malloc0(size); +} + +void rpmi_env_free(void *ptr) +{ + g_free(ptr); +} + +void rpmi_env_writel(rpmi_uint64_t addr, rpmi_uint32_t val) +{ + MemTxResult result; + + address_space_stl_le(&address_space_memory, addr, val, + MEMTXATTRS_UNSPECIFIED, &result); + if (result !=3D MEMTX_OK) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: failed write at 0x%" PRIx64 + " (result 0x%x)\n", + __func__, (uint64_t)addr, result); + } +} + +static enum rpmi_error riscv_rpmi_memtx_result_to_error(MemTxResult result) +{ + return result =3D=3D MEMTX_OK ? RPMI_SUCCESS : RPMI_ERR_IO; +} + +static bool riscv_rpmi_addr_in_range(uint64_t addr, uint32_t len, + uint64_t base, uint64_t size) +{ + return len && size >=3D len && addr >=3D base && addr - base <=3D size= - len; +} + +static enum rpmi_error shmem_qemu_read(void *priv, rpmi_uint64_t addr, + void *buf, rpmi_uint32_t len) +{ + RiscvRpmiState *s =3D RISCV_RPMI(priv); + + if (!s || !buf || + !riscv_rpmi_addr_in_range(addr, len, s->shmem_base, + s->shmem_size)) { + return RPMI_ERR_BAD_RANGE; + } + + return riscv_rpmi_memtx_result_to_error( + address_space_read(&address_space_memory, addr, + MEMTXATTRS_UNSPECIFIED, buf, len)); +} + +static enum rpmi_error shmem_qemu_write(void *priv, rpmi_uint64_t addr, + const void *buf, rpmi_uint32_t len) +{ + RiscvRpmiState *s =3D RISCV_RPMI(priv); + + if (!s || !buf || + !riscv_rpmi_addr_in_range(addr, len, s->shmem_base, + s->shmem_size)) { + return RPMI_ERR_BAD_RANGE; + } + + return riscv_rpmi_memtx_result_to_error( + address_space_write(&address_space_memory, addr, + MEMTXATTRS_UNSPECIFIED, buf, len)); +} + +static enum rpmi_error shmem_qemu_fill(void *priv, rpmi_uint64_t addr, + char ch, rpmi_uint32_t len) +{ + RiscvRpmiState *s =3D RISCV_RPMI(priv); + + if (!s || + !riscv_rpmi_addr_in_range(addr, len, s->shmem_base, + s->shmem_size)) { + return RPMI_ERR_BAD_RANGE; + } + + return riscv_rpmi_memtx_result_to_error( + address_space_set(&address_space_memory, addr, (uint8_t)ch, len, + MEMTXATTRS_UNSPECIFIED)); +} + +const struct rpmi_shmem_platform_ops rpmi_shmem_qemu_ops =3D { + .read =3D shmem_qemu_read, + .write =3D shmem_qemu_write, + .fill =3D shmem_qemu_fill, +}; + +static uint64_t riscv_rpmi_read(void *opaque, hwaddr offset, unsigned int = size) +{ + RiscvRpmiState *s =3D opaque; + + if (offset !=3D 0 || size !=3D 4) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid read at 0x%" HWADDR_PRIx " size %u\n", + __func__, offset, size); + return 0; + } + + return s->doorbell; +} + +static bool riscv_rpmi_transport_indices_valid(RiscvRpmiState *s); + +static void riscv_rpmi_write(void *opaque, hwaddr offset, uint64_t value, + unsigned int size) +{ + RiscvRpmiState *s =3D opaque; + + if (offset !=3D 0 || size !=3D 4) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid write at 0x%" HWADDR_PRIx " size %u\n", + __func__, offset, size); + return; + } + + s->doorbell =3D value; + + if (value =3D=3D 1) { + if (s->context && riscv_rpmi_transport_indices_valid(s)) { + riscv_rpmi_context_process_a2p_request(s); + } + } + s->doorbell =3D 0; +} + +static const MemoryRegionOps riscv_rpmi_ops =3D { + .read =3D riscv_rpmi_read, + .write =3D riscv_rpmi_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static bool riscv_rpmi_queue_indices_valid(RiscvRpmiState *s, + uint64_t queue_base, + uint32_t queue_size) +{ + uint8_t *shmem =3D memory_region_get_ram_ptr(&s->shmem); + uint32_t data_slots =3D queue_size / RPMI_QUEUE_SLOT_SIZE - 2; + uint32_t head; + uint32_t tail; + + head =3D ldl_le_p(shmem + queue_base); + tail =3D ldl_le_p(shmem + queue_base + RPMI_QUEUE_SLOT_SIZE); + if (head >=3D data_slots || tail >=3D data_slots) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid queue indices head %u tail %u slots %u\= n", + __func__, head, tail, data_slots); + return false; + } + + return true; +} + +static bool riscv_rpmi_transport_indices_valid(RiscvRpmiState *s) +{ + if (!s->has_shmem || !s->a2p_req_size) { + return false; + } + + if (!riscv_rpmi_queue_indices_valid(s, 0, s->a2p_req_size)) { + return false; + } + + return riscv_rpmi_queue_indices_valid(s, s->a2p_req_size, + s->a2p_req_size); +} + +static void riscv_rpmi_configure_base(RiscvRpmiState *s, + const RiscvRpmiConfig *cfg) +{ + s->platform_info =3D g_strdup(cfg->platform_info); + s->services =3D cfg->services; + s->service_count =3D cfg->service_count; + + s->hart_count =3D cfg->hart_count; + if (cfg->hart_ids) { + s->hart_ids =3D g_memdup2(cfg->hart_ids, + cfg->hart_count * sizeof(*cfg->hart_ids)); + } +} + +static void riscv_rpmi_init(Object *obj) +{ + RiscvRpmiState *s =3D RISCV_RPMI(obj); + + memory_region_init_io(&s->mmio, obj, &riscv_rpmi_ops, s, + TYPE_RISCV_RPMI, RPMI_DBREG_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static void riscv_rpmi_reset_hold(Object *obj, ResetType type) +{ + RiscvRpmiState *s =3D RISCV_RPMI(obj); + + s->doorbell =3D 0; + + if (s->has_shmem) { + memset(memory_region_get_ram_ptr(&s->shmem), 0, s->shmem_size); + memory_region_set_dirty(&s->shmem, 0, s->shmem_size); + } +} + +static void riscv_rpmi_cleanup(RiscvRpmiState *s) +{ + if (s->context) { + rpmi_context_destroy(s->context); + s->context =3D NULL; + } + + if (s->transport) { + rpmi_transport_shmem_destroy(s->transport); + s->transport =3D NULL; + } + + if (s->rpmi_shmem) { + rpmi_shmem_destroy(s->rpmi_shmem); + s->rpmi_shmem =3D NULL; + } + + if (s->has_shmem) { + memory_region_del_subregion(get_system_memory(), &s->shmem); + s->has_shmem =3D false; + } +} + +bool riscv_rpmi_service_enabled(RiscvRpmiState *s, + enum rpmi_servicegroup_id service_group) +{ + uint32_t i; + + for (i =3D 0; i < s->service_count; i++) { + if (s->services[i].service_group =3D=3D service_group) { + return true; + } + } + + return false; +} + +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s) +{ + if (s->context) { + rpmi_context_process_a2p_request(s->context); + } +} + +static bool riscv_rpmi_validate_config(RiscvRpmiState *s, Error **errp) +{ + uint64_t queue_bytes; + + if (!s->shmem_size) { + error_setg(errp, "RPMI shared memory size must be non-zero"); + return false; + } + + if (s->shmem_size > UINT32_MAX) { + error_setg(errp, + "RPMI shared memory size exceeds the 32-bit API limit"); + return false; + } + + if (s->shmem_base & (RPMI_QUEUE_SLOT_SIZE - 1)) { + error_setg(errp, "RPMI shared memory base must be %u-byte aligned", + RPMI_QUEUE_SLOT_SIZE); + return false; + } + + if (s->a2p_req_size < RPMI_DATA_SLOT_SIZE) { + error_setg(errp, + "RPMI A2P request queue needs at least one data slot"); + return false; + } + + if (!s->hart_count || !s->hart_ids) { + error_setg(errp, "RPMI transport requires hart IDs"); + return false; + } + + for (uint32_t i =3D 0; i < s->hart_count; i++) { + for (uint32_t j =3D i + 1; j < s->hart_count; j++) { + if (s->hart_ids[i] =3D=3D s->hart_ids[j]) { + error_setg(errp, "RPMI hart ID %u is duplicated", + s->hart_ids[i]); + return false; + } + } + } + + if (s->service_count && !s->services) { + error_setg(errp, "RPMI service count requires service descriptors"= ); + return false; + } + + if (s->a2p_req_size % RPMI_QUEUE_SLOT_SIZE) { + error_setg(errp, + "RPMI A2P request queue size must be a multiple of %u", + RPMI_QUEUE_SLOT_SIZE); + return false; + } + + if (s->p2a_req_size && + s->p2a_req_size < RPMI_DATA_SLOT_SIZE) { + error_setg(errp, + "RPMI P2A request queue needs at least one data slot"); + return false; + } + + if (s->p2a_req_size % RPMI_QUEUE_SLOT_SIZE) { + error_setg(errp, + "RPMI P2A request queue size must be a multiple of %u", + RPMI_QUEUE_SLOT_SIZE); + return false; + } + + queue_bytes =3D 2 * (uint64_t)s->a2p_req_size + + 2 * (uint64_t)s->p2a_req_size; + if (queue_bytes > s->shmem_size) { + error_setg(errp, + "RPMI shared memory size 0x%" PRIx64 + " is too small for queues 0x%" PRIx64, + s->shmem_size, queue_bytes); + return false; + } + + return true; +} + +static bool riscv_rpmi_add_service_group(RiscvRpmiState *s, + const RiscvRpmiServiceConfig *ser= vice, + Error **errp) +{ + error_setg(errp, "unsupported RPMI service group %u", + service->service_group); + return false; +} + +static bool riscv_rpmi_init_services(RiscvRpmiState *s, Error **errp) +{ + uint32_t i; + + for (i =3D 0; i < s->service_count; i++) { + if (!riscv_rpmi_add_service_group(s, &s->services[i], errp)) { + return false; + } + } + + return true; +} + +static bool riscv_rpmi_init_context(RiscvRpmiState *s, Error **errp) +{ + const char *platform_info =3D s->platform_info ?: RPMI_PLAT_INFO; + + s->rpmi_shmem =3D rpmi_shmem_create("rpmi-shmem", s->shmem_base, + s->shmem_size, + &rpmi_shmem_qemu_ops, s); + if (!s->rpmi_shmem) { + error_setg(errp, "failed to create RPMI shared memory backend"); + return false; + } + + s->transport =3D rpmi_transport_shmem_create("rpmi-shmem-transport", + RPMI_QUEUE_SLOT_SIZE, + s->a2p_req_size, + s->p2a_req_size, + s->rpmi_shmem); + if (!s->transport) { + error_setg(errp, "failed to create RPMI shared memory transport"); + return false; + } + + s->context =3D rpmi_context_create("rpmi-virt", s->transport, + RPMI_SRVGRP_ID_MAX_COUNT, + RPMI_PRIVILEGE_M_MODE, + strlen(platform_info) + 1, + platform_info); + if (!s->context) { + error_setg(errp, "failed to create RPMI context"); + return false; + } + + return riscv_rpmi_init_services(s, errp); +} + +static void riscv_rpmi_realize(DeviceState *dev, Error **errp) +{ + RiscvRpmiState *s =3D RISCV_RPMI(dev); + g_autofree char *name =3D NULL; + + if (!riscv_rpmi_validate_config(s, errp)) { + return; + } + + name =3D g_strdup_printf("rpmi-shmem@%" PRIx64, s->shmem_base); + if (!memory_region_init_ram(&s->shmem, OBJECT(dev), name, s->shmem_siz= e, + errp)) { + return; + } + + memory_region_add_subregion(get_system_memory(), s->shmem_base, &s->sh= mem); + s->has_shmem =3D true; + + if (!riscv_rpmi_init_context(s, errp)) { + riscv_rpmi_cleanup(s); + } +} + +static void riscv_rpmi_unrealize(DeviceState *dev) +{ + riscv_rpmi_cleanup(RISCV_RPMI(dev)); +} + +static const VMStateDescription riscv_rpmi_vmstate =3D { + .name =3D TYPE_RISCV_RPMI, + .unmigratable =3D 1, +}; + +static const Property riscv_rpmi_properties[] =3D { + DEFINE_PROP_UINT64("shmem-base", RiscvRpmiState, shmem_base, 0), + DEFINE_PROP_UINT64("shmem-size", RiscvRpmiState, shmem_size, 0), + DEFINE_PROP_UINT32("a2p-req-size", RiscvRpmiState, a2p_req_size, 0), + DEFINE_PROP_UINT32("p2a-req-size", RiscvRpmiState, p2a_req_size, 0), +}; + +static void riscv_rpmi_finalize(Object *obj) +{ + RiscvRpmiState *s =3D RISCV_RPMI(obj); + + g_free(s->platform_info); + g_free(s->hart_ids); +} + +static void riscv_rpmi_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + dc->realize =3D riscv_rpmi_realize; + dc->unrealize =3D riscv_rpmi_unrealize; + dc->vmsd =3D &riscv_rpmi_vmstate; + rc->phases.hold =3D riscv_rpmi_reset_hold; + device_class_set_props(dc, riscv_rpmi_properties); +} + +static const TypeInfo riscv_rpmi_info =3D { + .name =3D TYPE_RISCV_RPMI, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RiscvRpmiState), + .instance_init =3D riscv_rpmi_init, + .instance_finalize =3D riscv_rpmi_finalize, + .class_init =3D riscv_rpmi_class_init, +}; + +static void riscv_rpmi_register_types(void) +{ + type_register_static(&riscv_rpmi_info); +} + +type_init(riscv_rpmi_register_types) + +DeviceState *riscv_rpmi_create(const RiscvRpmiConfig *cfg, Error **errp) +{ + DeviceState *dev; + RiscvRpmiState *s; + + if (!cfg) { + error_setg(errp, "missing RPMI configuration"); + return NULL; + } + + dev =3D qdev_new(TYPE_RISCV_RPMI); + qdev_prop_set_uint64(dev, "shmem-base", cfg->shmem_base); + qdev_prop_set_uint64(dev, "shmem-size", cfg->shmem_size); + qdev_prop_set_uint32(dev, "a2p-req-size", cfg->a2p_req_size); + qdev_prop_set_uint32(dev, "p2a-req-size", cfg->p2a_req_size); + + s =3D RISCV_RPMI(dev); + riscv_rpmi_configure_base(s, cfg); + + if (!sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp)) { + return NULL; + } + + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, cfg->doorbell_base); + return dev; +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h new file mode 100644 index 0000000000..95aa8dec14 --- /dev/null +++ b/hw/misc/riscv_rpmi_internal.h @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI internal service helpers. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#ifndef HW_MISC_RISCV_RPMI_INTERNAL_H +#define HW_MISC_RISCV_RPMI_INTERNAL_H + +#include "qapi/error.h" +#include "hw/misc/riscv_rpmi.h" +#include "librpmi.h" + +#define RPMI_PLAT_INFO "QEMU RISC-V RPMI" + +extern const struct rpmi_shmem_platform_ops rpmi_shmem_qemu_ops; +bool riscv_rpmi_service_enabled(RiscvRpmiState *s, + enum rpmi_servicegroup_id service_group); +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); + +#endif diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h new file mode 100644 index 0000000000..c207501405 --- /dev/null +++ b/include/hw/misc/riscv_rpmi.h @@ -0,0 +1,92 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI definitions shared by RPMI transport and FDT helpers. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#ifndef HW_MISC_RISCV_RPMI_H +#define HW_MISC_RISCV_RPMI_H + +#include "exec/hwaddr.h" +#include "hw/core/sysbus.h" +#include "qom/object.h" + +#ifdef CONFIG_LIBRPMI +#include "librpmi.h" +#else +enum rpmi_servicegroup_id { + RPMI_SRVGRP_SYSTEM_RESET =3D 0x0003, + RPMI_SRVGRP_SYSTEM_SUSPEND =3D 0x0004, + RPMI_SRVGRP_HSM =3D 0x0005, +}; +#endif + +#define RPMI_QUEUE_SLOT_SIZE 64 +/* Minimum queue size: head, tail, and one data slot. */ +#define RPMI_DATA_SLOT_SIZE (3 * RPMI_QUEUE_SLOT_SIZE) +#define RPMI_DBREG_SIZE 0x1000 + +#define RPMI_ALL_NUM_QUEUES 4 +#define RPMI_A2P_NUM_QUEUES 2 +#define RPMI_ALL_NUM_REGS (RPMI_ALL_NUM_QUEUES + 1) +#define RPMI_A2P_NUM_REGS (RPMI_A2P_NUM_QUEUES + 1) + +#define TYPE_RISCV_RPMI "riscv-rpmi" +OBJECT_DECLARE_SIMPLE_TYPE(RiscvRpmiState, RISCV_RPMI) + +struct rpmi_context; +struct rpmi_service_group; +struct rpmi_shmem; +struct rpmi_transport; + +typedef struct RiscvRpmiServiceConfig { + const char *node_name; + const char *compatible; + enum rpmi_servicegroup_id service_group; + bool has_mpxy_channel; + uint32_t mpxy_channel; +} RiscvRpmiServiceConfig; + +typedef struct RiscvRpmiConfig { + hwaddr doorbell_base; + hwaddr shmem_base; + hwaddr shmem_size; + uint32_t a2p_req_size; + uint32_t p2a_req_size; + const char *platform_info; + + const uint32_t *hart_ids; + uint32_t hart_count; + const RiscvRpmiServiceConfig *services; + uint32_t service_count; +} RiscvRpmiConfig; + +struct RiscvRpmiState { + SysBusDevice parent_obj; + + MemoryRegion mmio; + MemoryRegion shmem; + uint64_t shmem_base; + uint64_t shmem_size; + uint32_t a2p_req_size; + uint32_t p2a_req_size; + char *platform_info; + + uint32_t *hart_ids; + uint32_t hart_count; + const RiscvRpmiServiceConfig *services; + uint32_t service_count; + uint32_t doorbell; + struct rpmi_shmem *rpmi_shmem; + struct rpmi_transport *transport; + struct rpmi_context *context; + bool has_shmem; +}; + +DeviceState *riscv_rpmi_create(const RiscvRpmiConfig *cfg, Error **errp); + +#endif From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556933; cv=none; d=zohomail.com; s=zohoarc; b=b2yoHbkwaQwsYHMbYwhQ7yNIiLJpaQacMAu64G1C2pY7Jg6nBlywnMOronY7twJn5FBITUG+2YTN86hO3WxY5Ou/VOOKC1iw0Z6Ep4Y3gLlyTiDQ0ab4rlqcRrCdLM+2eF4WKk/xbgmmtxhkSuaD6Ad5oy2bdmM5fkRBLkhTgO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556933; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+RI08oxs8WSznS4O0TxolmEOUBBksBccu2yfjOuYCcQ=; b=TvV238EtM/NYk2ZgkIzySsJ63PaVMTNl8ltfsYjRVsz8//29ci7Jkp+qcHj1l4Hb+h44ltlU345KzXjOeCWQCEzZXyrM2sk/rojIWyad9cnCT+/+M7eO1MOQ2i9N48UReg9Vxfr1sKVxnLapNKiKDWJ1x2KINIs5h3nmInHbmvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556933170813.7615443624464; Fri, 13 Nov 2026 00:02:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCI-0002lX-PX; Fri, 13 Nov 2026 02:59:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCD-0002jZ-Ja for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:42 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCB-0000Ca-OL for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:41 -0500 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD57f2C3120446 for ; Fri, 13 Nov 2026 07:59:38 GMT Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwkgwa3cv-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:38 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-339628f2bbaso90345eec.1 for ; Thu, 12 Nov 2026 23:59:38 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=+RI08oxs8WS znS4O0TxolmEOUBBksBccu2yfjOuYCcQ=; b=AjC6u4SytKK8n+8PgeVCMYVHCxy CeAy14GB8hOPGLSxg4MAPMBfojWQgUiGpBR6ijCMVPGkPmNwfnvcU97z5icidRCP doJ2s/LFTHqtrnX/F4Pk9+eeTGkydJY4VhMtyjUR+RasFkkVwJAYE9w09Pwbnbec E/w/phMvJYLzrVibpZYF5G48UNfSEOPp4d5wwXJ1fsm3ery329F2NgOTXfB2OVeS 1u+CfZyBCCM0ld6X8nRhCNa8jz1q9mLc0yNs76X4gfPGpGZ5EaRCwOka28HNzbRl cFeZaUVrPLj5T0tPNbJXX7WCnYNiLQad8NdFbZ4pX0OSCf0EWHughJr5o1Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556778; x=1795161578; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=+RI08oxs8WSznS4O0TxolmEOUBBksBccu2yfjOuYCcQ=; b=EDEOEFjuAWREgvsZ5l4lzD6HjFG47h7bCqSruNlxNdb6pZGalpG3QqYUhlsZ9BTJgt e/zGstsZXzZs0U12L/eAOIx/K2b6+1p6sjuyvFT2x6FD3+YX1GY2UfwYHXRmZ/A4wrpv 8IrbLP4NUecaBa1d+wGkZv5PluV6g8vlY8Ppjru99P9nSy2dG2w4o+H5vnLHbqnnh+Yx a206dR0HoC+Y1XGzCcYEX4uqQ1WM7shdlNjZJjp4C4BJjdhkJQ2cThJs/X/xPVDZj2e3 vPs8buCNIidlCkQGCtQsgDpz0e53L+P0V1+MFKv02tAvvHSHtIK89gSsW47/PrLY6El4 Rs+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556778; x=1795161578; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=+RI08oxs8WSznS4O0TxolmEOUBBksBccu2yfjOuYCcQ=; b=eU6f7c20aqQMSdnTMCuL5v+GCW9RLU0+YyH+3CVQenrPWQbdk7gAjPKKuW3pRKX5yY S9UrsE5fYg451mpkZCLHwHnSZfqxIkeS7zOs+FevDsQuj+AOdEnhHMXIMekhDII0JpDz ruRmzQAPBWQnwLHMBa47P6TAR0nHxv34X2vCvDmAdVjpk0/T+INcpiVsBdtkS8kXEjHw 0uVi14UMFDrbUcBqaooQtvqJSB3DqwNdCIa7UnVhVzHGh2qqrSetVB27jFf5EGnsevs7 5BQ7et6EHINbvqdQQc6ptzB6nl3A6h1WduH9Z+K9NPsVVS58znCW+72M4NCv6CvNqR/D 4NjQ== X-Gm-Message-State: APuU4Z+yrkhApHXUCCUN5xLXDj+5fWsu4U/r4yYMMKSZ4OpJKAI7s1ox 0QQDpmbGxsdQtGYDjF3atjZ/gtERMspP2DQHlazX/f/Hh/+CQ86LKn6ZkDb4zxXj6abcl5CLXmH oCIISaHvecu0vwjRBIDDSs5OIoNFVNtU+tSAItQMmHMeyHG+SHzcHUl6JV356PdOXzg== X-Gm-Gg: AYBFou1fVzjpvL5cVTTEOgQwkHglUncHPPsial84R5oGWJTkNwQAl3q0jupl9wdQ2Fi WOKe0udLwL31hZJVdY6PCYryEbkcnbuZ1i6rLTr83Ja+4QuNOhHtXQUGiPz4J66kM0dpgPKekV1 uLjrSzG61XuZ2FsgQnAC1KxfITEAW4x8RhgTDqxaU2ddleZUrscaZw9WmmZzkKBA9Jzx6KKsP3K XUsmz2g/LZC/PExOrkEUgkajCKex0F8n+wO0b8bmHYsGVrtp/QMfmVRq5zBoBrgkN59vJfHfc3a zQWFyo6gRfB2IYozJ+bmrhehpnuMgpphUCToZkmCO0eh+2e0vbDAlJzNnQhj5WZBxV38csRdk0I 4srkzFay28G5Sa3T/q7gFZ65/oaNmtL61RMo6/M0igB29a7umNH0KG3iALUwp9MX6R3azqEyqHC 0VXvH1cVT61Ph48wvRq2TbsswHcv0P2VTXfavP3/PooMFHBwNG5pwEm4+8IhDxqjjdiQ3Ta8yFP KeztLY= X-Received: by 2002:a05:7301:a0a:b0:36c:a1bc:6114 with SMTP id 5a478bee46e88-3796038259fmr2344637eec.0.1794556777449; Thu, 12 Nov 2026 23:59:37 -0800 (PST) X-Received: by 2002:a05:7301:a0a:b0:36c:a1bc:6114 with SMTP id 5a478bee46e88-3796038259fmr2344610eec.0.1794556776755; Thu, 12 Nov 2026 23:59:36 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu Subject: [PATCH v16 03/10] hw/riscv: add RPMI FDT helpers Date: Fri, 13 Nov 2026 13:28:58 +0530 Message-ID: <20261113075906.715870-4-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=DNgacCNb c=1 sm=1 tr=0 ts=6af6c36a cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=WNJofZAcfibaGo0vQRIA:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-ORIG-GUID: X629cler_g081LzU7wTvSyQ18vuOVG6- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX+S2rVvH9IXw5 QOd/yQdLqPbyrOBlH33OjHLL6PfYxbWooAYk4NPvaFqmOhtYU63OSxeLmNlI7rQTOcXOg0EdPUq +oUCmAhG1EghkC51fbK6jEXa2wSGzX7QtZYnIxqgVAaVYs5FBMrGnbZ82m5wVigZpS2OWnKR4FE MX291kTbKmvwBcFM3zCvDeysSB+xN7bUr2EzvZJHCLZnm9pmGV+g291koV2S7WdsWBx7zOrBye7 jZzDWI97PDcYJm1NM72BMLk3lB5HMgoFu0m6YzotqYMJXZvKJtA2E7OOUHjhknKCJGOoqku/vf4 P72O0C3Vv6Sgwx6sXBXm3RXZ3jnbb2sx1HlTCos5twIkqG5QZoAjyyv8/ojlrs8YDyg4GUm00Xh LhWrQhcFcKWShAVrRspw/7geUyUwv2J0Q3JZSNkR5Syj50OjyPK4VvZW4lMqGRbXL7jzInfK92z byPbEaLe7sWPisLdehA== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX9Bpsp88UlOP2 utFcTO5yumv+wD4S3j4PlepYIlSY3OXEIklB5u8zSp4orlpCAsi0DnxXqi5Ntlx8t1Cu8HGrcfW u747XvhhDhgl3xQWecCILnFd459qkDE= X-Proofpoint-GUID: X629cler_g081LzU7wTvSyQ18vuOVG6- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556933986158501 Content-Type: text/plain; charset="utf-8" Add helper routines for describing RPMI shared-memory mailbox transports and sibling service nodes in the RISC-V virt device tree. The helpers keep RPMI node construction in one place so the virt machine can add service groups without open-coding compatible strings, channel IDs, interrupts, and shared-memory references at each call site. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- hw/riscv/meson.build | 3 ++ hw/riscv/rpmi-fdt-stub.c | 24 ++++++++++++ hw/riscv/rpmi-fdt.c | 92 +++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/riscv/rpmi-fdt.h | 34 +++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 hw/riscv/rpmi-fdt-stub.c create mode 100644 hw/riscv/rpmi-fdt.c create mode 100644 include/hw/riscv/rpmi-fdt.h diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build index 6bdabb9544..806ba41e42 100644 --- a/hw/riscv/meson.build +++ b/hw/riscv/meson.build @@ -5,6 +5,9 @@ riscv_ss.add(files('device-common.c')) riscv_ss.add(files('fdt-common.c')) riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c')) riscv_ss.add(files('riscv_hart.c')) +riscv_ss.add(when: 'CONFIG_RISCV_RPMI', + if_true: files('rpmi-fdt.c'), + if_false: files('rpmi-fdt-stub.c')) riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) riscv_ss.add(when: 'CONFIG_RISCV_SERVER_PLATFORM_REF', if_true: files('ser= ver_platform_ref.c')) diff --git a/hw/riscv/rpmi-fdt-stub.c b/hw/riscv/rpmi-fdt-stub.c new file mode 100644 index 0000000000..0de006bd47 --- /dev/null +++ b/hw/riscv/rpmi-fdt-stub.c @@ -0,0 +1,24 @@ +/* + * RISC-V RPMI device-tree helper stubs. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/riscv/rpmi-fdt.h" + +void riscv_rpmi_fdt_add_mbox(void *fdt G_GNUC_UNUSED, + const RiscvRpmiFdtMboxConfig *cfg G_GNUC_UNUS= ED, + uint32_t *phandle G_GNUC_UNUSED, + uint32_t *mbox_handle G_GNUC_UNUSED) +{ + g_assert_not_reached(); +} + +void riscv_rpmi_fdt_add_service_node(void *fdt G_GNUC_UNUSED, + const RiscvRpmiServiceConfig *service + G_GNUC_UNUSED, + uint32_t mbox_handle G_GNUC_UNUSED) +{ + g_assert_not_reached(); +} diff --git a/hw/riscv/rpmi-fdt.c b/hw/riscv/rpmi-fdt.c new file mode 100644 index 0000000000..0ca1f69546 --- /dev/null +++ b/hw/riscv/rpmi-fdt.c @@ -0,0 +1,92 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI device-tree helpers + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "hw/riscv/rpmi-fdt.h" +#include "hw/misc/riscv_rpmi.h" +#include "system/device_tree.h" + +void riscv_rpmi_fdt_add_mbox(void *fdt, + const RiscvRpmiFdtMboxConfig *cfg, + uint32_t *phandle, + uint32_t *mbox_handle) +{ + g_autofree char *name =3D NULL; + hwaddr a2p_req_base, p2a_ack_base, p2a_req_base, a2p_ack_base; + uint32_t handle; + static const char * const regnames_all[RPMI_ALL_NUM_REGS] =3D { + "a2p-req", "p2a-ack", "p2a-req", "a2p-ack", "a2p-doorbell" + }; + static const char * const regnames_a2p[RPMI_A2P_NUM_REGS] =3D { + "a2p-req", "p2a-ack", "a2p-doorbell" + }; + + a2p_req_base =3D cfg->shmem_base; + p2a_ack_base =3D a2p_req_base + cfg->a2p_req_size; + p2a_req_base =3D p2a_ack_base + cfg->a2p_req_size; + a2p_ack_base =3D p2a_req_base + cfg->p2a_req_size; + + handle =3D (*phandle)++; + + if (mbox_handle) { + *mbox_handle =3D handle; + } + name =3D g_strdup_printf("/soc/mailbox@%" HWADDR_PRIx, cfg->shmem_base= ); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", "riscv,rpmi-shmem-mbo= x"); + qemu_fdt_setprop_cell(fdt, name, "riscv,slot-size", RPMI_QUEUE_SLOT_SI= ZE); + qemu_fdt_setprop_cell(fdt, name, "#mbox-cells", 1); + + if (cfg->p2a_req_size) { + qemu_fdt_setprop_string_array(fdt, name, "reg-names", + (char **)®names_all, + ARRAY_SIZE(regnames_all)); + qemu_fdt_setprop_cells(fdt, name, "reg", + (uint32_t)(a2p_req_base >> 32), (uint32_t)a2p_req_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(p2a_ack_base >> 32), (uint32_t)p2a_ack_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(p2a_req_base >> 32), (uint32_t)p2a_req_base, + 0x0, cfg->p2a_req_size, + (uint32_t)(a2p_ack_base >> 32), (uint32_t)a2p_ack_base, + 0x0, cfg->p2a_req_size, + (uint32_t)(cfg->doorbell_base >> 32), (uint32_t)cfg->doorbell_= base, + 0x0, cfg->doorbell_size); + } else { + qemu_fdt_setprop_string_array(fdt, name, "reg-names", + (char **)®names_a2p, + ARRAY_SIZE(regnames_a2p)); + qemu_fdt_setprop_cells(fdt, name, "reg", + (uint32_t)(a2p_req_base >> 32), (uint32_t)a2p_req_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(p2a_ack_base >> 32), (uint32_t)p2a_ack_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(cfg->doorbell_base >> 32), (uint32_t)cfg->doorbell_= base, + 0x0, cfg->doorbell_size); + } + + qemu_fdt_setprop_cells(fdt, name, "phandle", handle); +} + +void riscv_rpmi_fdt_add_service_node(void *fdt, + const RiscvRpmiServiceConfig *service, + uint32_t mbox_handle) +{ + g_autofree char *name =3D g_strdup_printf("/soc/%s", service->node_nam= e); + + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", service->compatible); + qemu_fdt_setprop_cells(fdt, name, "mboxes", mbox_handle, + service->service_group); + if (service->has_mpxy_channel) { + qemu_fdt_setprop_cell(fdt, name, "riscv,sbi-mpxy-channel-id", + service->mpxy_channel); + } +} diff --git a/include/hw/riscv/rpmi-fdt.h b/include/hw/riscv/rpmi-fdt.h new file mode 100644 index 0000000000..e74115108e --- /dev/null +++ b/include/hw/riscv/rpmi-fdt.h @@ -0,0 +1,34 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI device-tree helpers + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#ifndef HW_RISCV_RPMI_FDT_H +#define HW_RISCV_RPMI_FDT_H + +#include "exec/hwaddr.h" + +typedef struct RiscvRpmiServiceConfig RiscvRpmiServiceConfig; + +typedef struct RiscvRpmiFdtMboxConfig { + hwaddr shmem_base; + hwaddr doorbell_base; + uint32_t a2p_req_size; + uint32_t p2a_req_size; + uint32_t doorbell_size; +} RiscvRpmiFdtMboxConfig; + +void riscv_rpmi_fdt_add_mbox(void *fdt, + const RiscvRpmiFdtMboxConfig *cfg, + uint32_t *phandle, + uint32_t *mbox_handle); +void riscv_rpmi_fdt_add_service_node(void *fdt, + const RiscvRpmiServiceConfig *service, + uint32_t mbox_handle); + +#endif From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556912; cv=none; d=zohomail.com; s=zohoarc; b=YkUZM8fA1Zq2TBsP9tDMhFIE/HMxxR/UDURUXZquvGr9kVSFScFNsNkWPa9D09lmmW1lOTbhGEqmXjaRe8Po8PX1kWJvVUNhuUazzjlvRbjQFgwoIUYoIg9GUQNKhffL+Vo3ISaRTZJHYGa1bKQXOakUIBPFhJ1kO2hCM0OulWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556912; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GZ7FmIN4exKjAah0GEIRwoylvD1up4Ywfpt/j0Q3+ok=; b=YwRxthBmWskgSKi9kqbfUK4Cd6+3dKfOgorNoeYmdaVlS/GMmlKZY8J/duqQC4h9ElWKpqyLcyb/TpHy0xxjpqEBDtJuFSlFRkA2ytDKsNb60et7inhGmXLs5yV5GH0WlN0P5WtApHluoDzen1I2GSg8QDvSHIwXPgzm1AkQ/Ls= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556912357157.1045786414154; Fri, 13 Nov 2026 00:01:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCL-0002mj-CS; Fri, 13 Nov 2026 02:59:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCI-0002lC-69 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:46 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCG-0000DO-79 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:45 -0500 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD56w1N2618537 for ; Fri, 13 Nov 2026 07:59:43 GMT Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwu2mrstv-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:42 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-36f01f683deso79740eec.3 for ; Thu, 12 Nov 2026 23:59:42 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=GZ7FmIN4exK jAah0GEIRwoylvD1up4Ywfpt/j0Q3+ok=; b=iCjpGJj3aCpWsSwtggpVNyS0gVK 5MZb0NLC/Krt4CyA4lolm/BZOls9RWEx6kLZGxJZj5wNbKWCTA4D3QCiSaaHjVp3 xxdX/I1WDFuA8Ytf9DjtUoTavyoT3u+30v1qR00fIISmv02SzPCnBuBzrVr3DfyP frAbBEvBgHA5XNQlpezaFAZxjG3+YkPAfAX6+mSoIWzZt+2QgmtVrpfXwPndspoJ eap9QbSfKeNkf/jx2IQS6oyGwzt0XUKWnv6cUNmTmszyClDqyfh21QK3q1epqlRZ K8jLHLWeCxGpIFzL7aOC2/TnyW9XWjzMfxBL42qufTeJZlB9tkWqIqVIAUQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556782; x=1795161582; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GZ7FmIN4exKjAah0GEIRwoylvD1up4Ywfpt/j0Q3+ok=; b=WReLrXmcoIsvYhhRGfe0VVvG8s4FLoqjvHPtypwl2dXHEtc/xlW5j6YeuRcR6vrYtW VL+WFhsayXtqRn0JjXuI4VfsyxNhLVyWrl3eEI40NZs+Q/0SpMurI77wus4rFjiW+gEM 6TGfjFn9qTHexR3Nd+CJCrCdk/jYJLklPZj2UwiWv9pbzhZaxd9EiASsYg/d4qwwL1Aj 1Bbvm80hd3tq+W5FrZ892cLcU3ao27SBZ7EjnBCoFZlnw5LTOf1vStEL69YRFY9jdG3x 7BCbsR1McoEuiv0UFQbyld1u6LcqbvLoPgMAnfGsp3IMSfYQ7Qwzm/61tKKpueWoFPOV uK2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556782; x=1795161582; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=GZ7FmIN4exKjAah0GEIRwoylvD1up4Ywfpt/j0Q3+ok=; b=gHnSJLNVbLMwfTzXnjWsAVVakj/uYpFpS6csvdAdIJ1HwC/5lF7QUz7OS0DjnoR6Nw KZs6OKwDihZAH/BJNb6y/VV+jLd6aVF73xJWhzpe2XZVOe+4hb2lCyNhnd3KiLedhff1 74EKulSh7tFXVnVYTtXhQk3nN+w8M8QCzCP3fr8uWpgX7CyOUI2MBUQjLHnn695csvjQ yiko129TgGCsqik51xOHCDi/0C/1OZ+G4M/bOggHYru2yETZKbbDHLHU+KID3T4vknHX TucPkpNTTD1334wF2LahmDwEshfYXn8+4p/4Hk8o4VMpF2uwB7g17Gue/Cg66LNUIfvx BWmg== X-Gm-Message-State: APuU4Z9JHSNy4XTvga9Q1iGz5zVnsgXhiYfExKFeUnnWLR3kCC+j9mLp yAQ32POhyTMONIb+SVYsGKGEwka0oD2sYeQOZW0U+dPUS/nsY2ysgp2fIfBzEOHZ51Nf1Y53IYZ mbnbqHDyzUXFziAFidpcHm47fl2VQd5/uRvig914tJbBvXL0Op18mcibEVAO1p0v7PQ== X-Gm-Gg: AYBFou3SYDcGZkjFLlDc5zhDLjkcrhRlLJSwExJSVXLpvtBHb44uD6d8MslCK+WREZe DjK1R+7qzkHYscAAXfRWCzDvLtyzLTum4Fs9A62452Zg1nCdAodmBE5AmhPpJmIcVI2hh9UQOIN nKSO8vqgIGzZMjoSOQnS5VPvTuxWPrIO6E/kC3ZkRWCl57ONRdm/oAfmB4qfmUmPJJFrPD3a09J tWcE3RScAYuPb8cBwy1PwDUU6tH1fT40R9/Amigp+lY1YlYSBKG6acoIdKjP+IGdrRRqfjqXZ8E T70KwR8o2jxI8V1VUgJUVq3OvX879WwbH0v8nNRRu1LanASRy1U/yEV0ucIWF9dgtRaxYGL9IRp 7Kvt7Q7AdocLCW3vXRaOJfi8WmUOQNR3qCLhP8+snK27QWWqcl/DW6pGxZebKUkXOlOM6GAjN9b s2KPePYO/7AoxjyRh+q34sWlnedkhqTBZUHpQxy5vNpB+9l6RDk67F7+P0bJYwnEPh0Mp95fSRD SkavTw= X-Received: by 2002:a05:693c:881c:10b0:36d:5fbc:8c8d with SMTP id 5a478bee46e88-379655d503emr2290876eec.2.1794556781908; Thu, 12 Nov 2026 23:59:41 -0800 (PST) X-Received: by 2002:a05:693c:881c:10b0:36d:5fbc:8c8d with SMTP id 5a478bee46e88-379655d503emr2290826eec.2.1794556780680; Thu, 12 Nov 2026 23:59:40 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Paolo Bonzini , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v16 04/10] hw/riscv/virt: add opt-in RPMI base support Date: Fri, 13 Nov 2026 13:28:59 +0530 Message-ID: <20261113075906.715870-5-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 44OB36-wcGRAYmzYTxvGqAdf6H18sTtM X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX14N0us+47qQJ iyWcsUc9y9wIP6gkJ1Hd3M3FNAQWLRj4IQaY9AOZFLrKYcEG4drO4foSK12GLpt7IkMITl5YXz1 iVfKrSUKZarOT0N0QbYX1mbe2RbokLtsOlAere8BQGhH5AExS8MFxzGTowk5IsW1zZ3ixoWO8FS 4jKabmgN97DT+spzLn8Ch8Uxl6aDJTfB99FoMDEdKslcEuqV6C97KCqRzhPuxXQsBjIFL/omy0o Im4dtWM3X3xBZEjuzKK3kNkGbPQb9wQCnOwCwhidipKCJORx7KASe90iRitWqgzQOwD9LM0PlYO Ix0F8efl6Tuz+NfeliZPSKDOWNmRQflx9z95C7uYp7aRkob/E3QwEGBZLknpGuKmAejjkRA8CSA gmhHyLnrWWDhxFk8czS5gjIQHJXGIDRDQtLLBMCbZfWf6S8YZcHlA4FgT1gabGta/yBaxfaPwyJ hEdnyKSi4JbTo63fOPg== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfXyfqs9Fi8Y/09 8Zo4I1+ehfWmSlfbHLNhjUGKrKLLxCJVkyPvHLpm2G6PwDMS7MrUKr9YFw0i5dEBGssoUDOmsH2 CUAJbsRAxtA6AMyW10l9aBhf9iAAQiA= X-Authority-Analysis: v=2.4 cv=ddQVTnXe c=1 sm=1 tr=0 ts=6af6c36e cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=HmRiOy3tFSfIY13RnpAA:9 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-GUID: 44OB36-wcGRAYmzYTxvGqAdf6H18sTtM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 impostorscore=0 priorityscore=1501 phishscore=0 suspectscore=0 adultscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556914035158500 Content-Type: text/plain; charset="utf-8" Add the virt machine rpmi=3Don/off option and wire the initial RPMI Base transport into machine realization for firmware clients that use RPMI platform management. The option remains disabled by default. Enabling it requires a librpmi-enabled TCG build; KVM and builds without librpmi reject the configuration. The RPMI mailbox node is emitted when enabled, while the legacy reset and poweroff nodes remain available until the later service patches select the RPMI reset path. Size each A2P queue from one quarter of shared memory after reserving 8 KiB: 30 KiB per queue on virt. Signed-off-by: Subrahmanya Lingappa --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 90 +++++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/riscv/virt.h | 3 ++ 3 files changed, 94 insertions(+) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index d89fdfcc86..28d108faf8 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -49,6 +49,7 @@ config RISCV_VIRT imply VIRTIO_VGA imply TEST_DEVICES imply TPM_TIS_SYSBUS + imply RISCV_RPMI select DEVICE_TREE select RISCV_NUMA select GOLDFISH_RTC diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index de1c92463a..8a2ed43029 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -46,6 +46,8 @@ #include "hw/intc/riscv_aplic.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_test.h" +#include "hw/misc/riscv_rpmi.h" +#include "hw/riscv/rpmi-fdt.h" #include "hw/core/platform-bus.h" #include "chardev/char.h" #include "system/device_tree.h" @@ -107,6 +109,8 @@ static const MemMapEntry virt_memmap[] =3D { /* UART1 supports page isolation from UART0 */ [VIRT_UART1] =3D { 0x1000a000, 0x100 }, [VIRT_FW_CFG] =3D { 0x10100000, 0x18 }, + [VIRT_RPMI_SHMEM] =3D { 0x10200000, 0x20000 }, + [VIRT_RPMI_DOORBELL] =3D { 0x10230000, 0x1000 }, [VIRT_FLASH] =3D { 0x20000000, 0x4000000 }, [VIRT_IMSIC_M] =3D { 0x24000000, VIRT_IMSIC_MAX_SIZE }, [VIRT_IMSIC_S] =3D { 0x28000000, VIRT_IMSIC_MAX_SIZE }, @@ -115,6 +119,10 @@ static const MemMapEntry virt_memmap[] =3D { [VIRT_DRAM] =3D { 0x80000000, 0x0 }, }; =20 +#define VIRT_RPMI_A2P_REQ_SIZE \ + ((virt_memmap[VIRT_RPMI_SHMEM].size - 0x2000) / 4) +#define VIRT_RPMI_P2A_REQ_SIZE 0 + /* PCIe high mmio is fixed for RV32 */ #define VIRT32_HIGH_PCIE_MMIO_BASE 0x300000000ULL #define VIRT32_HIGH_PCIE_MMIO_SIZE (4 * GiB) @@ -470,6 +478,35 @@ static void create_fdt_iommu(RISCVVirtState *s, uint16= _t bdf) s->pci_iommu_bdf =3D bdf; } =20 +static RiscvRpmiConfig virt_rpmi_config(RISCVVirtState *s, + const uint32_t *hart_ids, + uint32_t hart_count) +{ + return (RiscvRpmiConfig) { + .doorbell_base =3D s->memmap[VIRT_RPMI_DOORBELL].base, + .shmem_base =3D s->memmap[VIRT_RPMI_SHMEM].base, + .shmem_size =3D s->memmap[VIRT_RPMI_SHMEM].size, + .a2p_req_size =3D VIRT_RPMI_A2P_REQ_SIZE, + .p2a_req_size =3D VIRT_RPMI_P2A_REQ_SIZE, + .platform_info =3D "QEMU RISC-V virt RPMI", + .hart_ids =3D hart_ids, + .hart_count =3D hart_count, + }; +} + +static void create_fdt_rpmi(RISCVVirtState *s, uint32_t *phandle) +{ + RiscvRpmiFdtMboxConfig cfg =3D { + .shmem_base =3D s->memmap[VIRT_RPMI_SHMEM].base, + .doorbell_base =3D s->memmap[VIRT_RPMI_DOORBELL].base, + .a2p_req_size =3D VIRT_RPMI_A2P_REQ_SIZE, + .p2a_req_size =3D VIRT_RPMI_P2A_REQ_SIZE, + .doorbell_size =3D s->memmap[VIRT_RPMI_DOORBELL].size, + }; + + riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, NULL); +} + static void finalize_fdt(RISCVVirtState *s) { uint32_t phandle =3D 1, irq_mmio_phandle =3D 1, msi_pcie_phandle =3D 1; @@ -506,6 +543,9 @@ static void finalize_fdt(RISCVVirtState *s) s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, FINISHER_RESET, FINISHER_PASS, true); + if (s->have_rpmi) { + create_fdt_rpmi(s, &phandle); + } =20 create_fdt_uarts(s, irq_mmio_phandle); =20 @@ -739,6 +779,18 @@ static void virt_machine_init(MachineState *machine) exit(1); } =20 + if (s->have_rpmi) { +#ifndef CONFIG_LIBRPMI + error_report("RISC-V RPMI support is not compiled in"); + exit(1); +#else + if (kvm_enabled()) { + error_report("RISC-V RPMI support is not available with KVM"); + exit(1); + } +#endif + } + /* Initialize sockets */ mmio_irqchip =3D virtio_irqchip =3D pcie_irqchip =3D NULL; for (i =3D 0; i < socket_count; i++) { @@ -897,6 +949,21 @@ static void virt_machine_init(MachineState *machine) /* SiFive Test MMIO device */ sifive_test_create(s->memmap[VIRT_TEST].base); =20 + if (s->have_rpmi) { + MachineClass *mc =3D MACHINE_GET_CLASS(machine); + const CPUArchIdList *possible_cpus =3D mc->possible_cpu_arch_ids(m= achine); + g_autofree uint32_t *rpmi_hart_ids =3D + g_new0(uint32_t, machine->smp.cpus); + RiscvRpmiConfig rpmi_cfg; + + for (i =3D 0; i < machine->smp.cpus; i++) { + rpmi_hart_ids[i] =3D possible_cpus->cpus[i].arch_id; + } + + rpmi_cfg =3D virt_rpmi_config(s, rpmi_hart_ids, machine->smp.cpus); + riscv_rpmi_create(&rpmi_cfg, &error_fatal); + } + /* VirtIO MMIO devices */ for (i =3D 0; i < VIRTIO_COUNT; i++) { sysbus_create_simple("virtio-mmio", @@ -1050,6 +1117,20 @@ static void virt_set_aclint(Object *obj, bool value,= Error **errp) s->have_aclint =3D value; } =20 +static bool virt_get_rpmi(Object *obj, Error **errp) +{ + RISCVVirtState *s =3D RISCV_VIRT_MACHINE(obj); + + return s->have_rpmi; +} + +static void virt_set_rpmi(Object *obj, bool value, Error **errp) +{ + RISCVVirtState *s =3D RISCV_VIRT_MACHINE(obj); + + s->have_rpmi =3D value; +} + bool virt_is_iommu_sys_enabled(RISCVVirtState *s) { return s->iommu_sys =3D=3D ON_OFF_AUTO_ON; @@ -1166,6 +1247,15 @@ static void virt_machine_class_init(ObjectClass *oc,= const void *data) "enable/disable emulating " "ACLINT devices"); =20 + + object_class_property_add_bool(oc, "rpmi", virt_get_rpmi, + virt_set_rpmi); + object_class_property_set_description(oc, "rpmi", + "Set on/off to enable/disable " + "RISC-V RPMI devices; requires " + "librpmi and is unavailable with= " + "KVM"); + object_class_property_add_str(oc, "aia", virt_get_aia, virt_set_aia); object_class_property_set_description(oc, "aia", diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 6e4fbf4b64..c9fb118fc8 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -55,6 +55,7 @@ struct RISCVVirtState { =20 int fdt_size; bool have_aclint; + bool have_rpmi; RISCVVirtAIAType aia_type; int aia_guests; char *oem_id; @@ -82,6 +83,8 @@ enum { VIRT_VIRTIO, VIRT_UART1, VIRT_FW_CFG, + VIRT_RPMI_SHMEM, + VIRT_RPMI_DOORBELL, VIRT_IMSIC_M, VIRT_IMSIC_S, VIRT_FLASH, From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556930; cv=none; d=zohomail.com; s=zohoarc; b=nF7FQPtzKTXIvgpJ6252KhUzvH1fk2XD1ML46Swn2vjZgg75QN3qBfEucsgzMbtuXS/ViWwYzZn7MWmKzJdffKvjM//ZbbrAAnYECrIWe9XGSJyuEjkAaoI+I5IRo8XuGlgPcDA7tVsFGNPZcnngKG5ycJUjdMN+MJZZlrTq7vM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556930; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dAXX4um4LoqWW3ME/trj57kvCianPIWUKsGcOMHIvSE=; b=l4FU7A7S4xEAyXEbJDdcWzYj3J/TXM5RCTJNmhsnfGMKmx5lT4NVjrYl9QLdvxBeLGmOpUne1/fIbfvKGwXGZ0gm69DobSUIp4F/ZcTscq6a3MyQquwPsECUhdZi/O0hQuiMfDwOAcZRKmRavjlGjDfFk4+oPgKGTKkkuJslyEk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556930483412.88870371621294; Fri, 13 Nov 2026 00:02:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCO-0002nS-Ky; Fri, 13 Nov 2026 02:59:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCM-0002mw-Sv for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:50 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCJ-0000Du-T0 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:50 -0500 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD5ak6E3147310 for ; Fri, 13 Nov 2026 07:59:46 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwvja8evj-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:46 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-36e61c89e2dso75082eec.3 for ; Thu, 12 Nov 2026 23:59:46 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=dAXX4um4Loq WW3ME/trj57kvCianPIWUKsGcOMHIvSE=; b=H1e8NzvNSwQoRwEnu8u2b4p+NIe rfuClqmGGCHNWcDfaNPv0MNQOz4SXxhJl1XDMWVZOaci6DbQjWIkBNk0Cmc3Sb1j J/ah/RE0GxWV6tHx9UxUT8eKJmw6mI7uhy3deCvc30u1935f7m+Ei6fu8VsaI1vz GqhuCfO1klOTeVBp+y4TfiLyKCSzpbj9ogtdDO1S66/yw1uRY/US2UDwB8WnlucP LPJDr7WfQhUmPI2ugmVRFZiB5zhGRy8oYGaplc9SFP3VMKozVNDNIYM18g2Hbqv9 FN4c76qBRp6zz3zJhFpoXcZCwvwL6xZS/dOjVBhwDNFmbpij1jkVhRZpCuQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556786; x=1795161586; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dAXX4um4LoqWW3ME/trj57kvCianPIWUKsGcOMHIvSE=; b=JHtWfV5CwyqSiGjqlQN2NVjEqLEt7PYNook3YxscUzjWzer2S9vH+xBnJOhezwbnW8 jxVJMCJAMLLbiJ7atpKY18k35Oj7Kvz1H42TCmfB3xJ0ZSAreF1Lnaw/PbKCrbJHTVEQ f77v/egBuepB2eAJ0mabX6mWlRMFCp6127vlkYh9fsniXMgJ/RObvoYCwG9TIY9tsTA8 MP/6Gr9PMADLElwxINASQXDSx7vhPPFNet4TDhp4MyEn3fl0mkkT+g5nfTuvrZJg6xc3 4U0yq7hFYuEGxeUlXqVB91k4+zau+p1QzhWqwY4vGsBulXtkGn90qe4mHQjqL3zd6LJJ Zd2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556786; x=1795161586; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=dAXX4um4LoqWW3ME/trj57kvCianPIWUKsGcOMHIvSE=; b=mqtdBVlJEJqsiWkidUSjVR6hod8xYjlpisnix/kItl+bTMs4BeNiXGHAIHoaT4/DKy 9T83RdXeF+xA3DJ56q1P02ASz9UtmHTjx69f7BsyAycDPQuiXeILWhEI0D56Y7j237vI PgWprVFiWugOz5+E8+wj2qmwRotNCsSmxqkHqk+zSV8TBu0s31MXGLhapQeob790a1HT mITmGTQwnq6Hr4ztGTAq9n1D0Ti4rHQlS+8Z1QlTfCpJu1Tht2A8rXaDZxKPT661irVl Pe9IqjibMCCAa0pB92IGsh5cuelkIICSwcbaaGjahBQLTAx36Zi+7JxWut6aJQPjJSmR DgfA== X-Gm-Message-State: APuU4Z9tGHXrBYz+taZYPVKK1Z9LGc6uEOH9qnQWvgLKOpFBbUuJrceh cUpvbXIx4tArsnDxh8Y1QGxamNHYuzH/yD1pBK3fh8x45hGbeJVoZu2zvTjoMoCOlqxxYw3hOGu lcoz0JKC9IdRk0I57fMj+SWZN2bydSvqL06YNfZzgvx2KqTkyiXN1WKAITmMXsiyldQ== X-Gm-Gg: AYBFou3pBBi6mPIsdM0xU7YaVzrX1rqVspANaibJXmI7x1Fx9WjKLIc0HfTx8kNa+Rc chHMTuHSeoQHH17et52WL+07QeICwyxxZTFXr+r1NA0or9EWNx8c33o8kh3bAdawhS6tvbQpZE/ StZL4oxid7K9TjE73vy6W0Njn05bQXX6QPQCFQt7nh9OuT/faP3La9TkdzYBdBls6u6lB1FJRTS xn289cnPCtfcUEK1bkqCMfLNQVS3T29E2iGaZlOsNM7R96noBS3AFF6mL+GUTFqzxU8MPBCLTTU hsJQYxM+treLlC73/Dvmd9Mmt8FydJaLgIdfJRsKooFyauUNewfKnmnqcoQAoXpWPPBd4cY9MF5 FjxX2p3+KNq2mhoLB5AjQukC2/JlE0YtXv6477LX8rByZOL3kS5GnZPHIM+PfzPyclRE3D8pbSN G5kMWGc+PJHTbmFURWY5ZRBgCdapZsDn+qdcEPW93FHhO0yu9ZThRwxRsnyy+GeykzxcwzkYYEv FcPYZM= X-Received: by 2002:a05:693c:20cd:10b0:36a:13fd:b5c with SMTP id 5a478bee46e88-379652f16f8mr2448686eec.2.1794556785383; Thu, 12 Nov 2026 23:59:45 -0800 (PST) X-Received: by 2002:a05:693c:20cd:10b0:36a:13fd:b5c with SMTP id 5a478bee46e88-379652f16f8mr2448650eec.2.1794556784777; Thu, 12 Nov 2026 23:59:44 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu Subject: [PATCH v16 05/10] riscv: add RPMI system reset service Date: Fri, 13 Nov 2026 13:29:00 +0530 Message-ID: <20261113075906.715870-6-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: psN1NBOxSioOgFgvtvi2FzKid_Nh9VkN X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX1trLWGqkfKSH TsR1tSPk15LHYvmfHkFLTGZnEvt0i/QtA4B42hMQ8nKKwXwgl3D7tK22AxFs5wNZEmBuo/vMFG4 ccPsjxM1+Bkf2ZE+tLMUwQEaFWJCuwk= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX2pyHSFlr+lik b/6qaNT+gJPd9bkwdJvpSKIWP4RZ/r66eAsBr+yKM/h+mRUazpfHBIiRHlyMJyyHVd5A/CZA+ju H/gGftw62B8OK6mpf82OuAESNX6+/d+jyAlRXtvgucg86y74GS4GBuwDRKU2q6DS3IaQ506bs4J 7Mia0BUbZwIx5tIdyQBWpT28q66zqQ6qFnuWBeMYfqKKohI3F95fNsXmLzlgI89DZLL0/5gmxrI 45nds9i9UL3131zAhZTtDJ5P/DUUPYwoyKLBrny4VpHG86x4w0FpAzSmklb0ts2cXjkm24O2AMa xBcszfNt5kUkdUqfpKzinXU6yHXCRZqbRO7WQSiYEHA70E7MZsdrLa6heCbBt4dYmM7w4XJNRs9 4fhSwR0VZyeO6aLJzkbFnfUg9m6CrANTIOAMaCNGH6yFHa0OOBJhaEQ+RX5re+Nid0nWNnrp7Sh IsOfR4n1uNjrDDpbaWA== X-Proofpoint-ORIG-GUID: psN1NBOxSioOgFgvtvi2FzKid_Nh9VkN X-Authority-Analysis: v=2.4 cv=AoN7T+9P c=1 sm=1 tr=0 ts=6af6c372 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=Q27P0EAC2tNmNk4ncAQA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 phishscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556931954158500 Content-Type: text/plain; charset="utf-8" Add a QEMU implementation of the RPMI System Reset service group. The service advertises shutdown and cold reboot reset types, validates guest requests, and dispatches accepted requests through machine reset and shutdown callbacks. This lets firmware use RPMI reset commands while keeping board-specific reset policy in the RISC-V machine. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- hw/misc/meson.build | 1 + hw/misc/riscv_rpmi.c | 68 ++++++++++++++- hw/misc/riscv_rpmi_internal.h | 9 ++ hw/misc/riscv_rpmi_sysreset.c | 185 +++++++++++++++++++++++++++++++++++++= ++++ hw/riscv/fdt-common.c | 8 +- hw/riscv/server_platform_ref.c | 2 +- hw/riscv/virt.c | 46 +++++++++- include/hw/misc/riscv_rpmi.h | 10 ++- include/hw/riscv/fdt-common.h | 3 +- 9 files changed, 322 insertions(+), 10 deletions(-) create mode 100644 hw/misc/riscv_rpmi_sysreset.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index b755796170..a091d393a3 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -185,4 +185,5 @@ system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true:= files('qcom-qdsp6ss-clk. =20 system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( 'riscv_rpmi.c', + 'riscv_rpmi_sysreset.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index cbfea1f733..2c6e694ff0 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -201,10 +201,37 @@ static bool riscv_rpmi_transport_indices_valid(RiscvR= pmiState *s) s->a2p_req_size); } =20 +typedef struct RiscvRpmiServiceOps { + enum rpmi_servicegroup_id service_group; + bool (*add)(RiscvRpmiState *s, Error **errp); + void (*remove)(RiscvRpmiState *s); +} RiscvRpmiServiceOps; + +static const RiscvRpmiServiceOps riscv_rpmi_service_ops[] =3D { + { + .service_group =3D RPMI_SRVGRP_SYSTEM_RESET, + .add =3D riscv_rpmi_sysreset_add, + .remove =3D riscv_rpmi_sysreset_remove, + }, +}; + +static const RiscvRpmiServiceOps *riscv_rpmi_service_ops_by_group( + enum rpmi_servicegroup_id service_group) +{ + for (uint32_t i =3D 0; i < ARRAY_SIZE(riscv_rpmi_service_ops); i++) { + if (riscv_rpmi_service_ops[i].service_group =3D=3D service_group) { + return &riscv_rpmi_service_ops[i]; + } + } + + return NULL; +} + static void riscv_rpmi_configure_base(RiscvRpmiState *s, const RiscvRpmiConfig *cfg) { s->platform_info =3D g_strdup(cfg->platform_info); + s->machine_ops =3D cfg->machine_ops; s->services =3D cfg->services; s->service_count =3D cfg->service_count; =20 @@ -238,6 +265,10 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTy= pe type) =20 static void riscv_rpmi_cleanup(RiscvRpmiState *s) { + for (uint32_t i =3D ARRAY_SIZE(riscv_rpmi_service_ops); i > 0; i--) { + riscv_rpmi_service_ops[i - 1].remove(s); + } + if (s->context) { rpmi_context_destroy(s->context); s->context =3D NULL; @@ -280,6 +311,30 @@ void riscv_rpmi_context_process_a2p_request(RiscvRpmiS= tate *s) } } =20 +bool riscv_rpmi_context_add_group(RiscvRpmiState *s, + struct rpmi_service_group *group, + const char *name, + Error **errp) +{ + enum rpmi_error rc; + + rc =3D rpmi_context_add_group(s->context, group); + if (rc !=3D RPMI_SUCCESS) { + error_setg(errp, "failed to add RPMI %s service group: %d", name, = rc); + return false; + } + + return true; +} + +void riscv_rpmi_context_remove_group(RiscvRpmiState *s, + struct rpmi_service_group *group) +{ + if (s->context && group) { + rpmi_context_remove_group(s->context, group); + } +} + static bool riscv_rpmi_validate_config(RiscvRpmiState *s, Error **errp) { uint64_t queue_bytes; @@ -365,9 +420,16 @@ static bool riscv_rpmi_add_service_group(RiscvRpmiStat= e *s, const RiscvRpmiServiceConfig *ser= vice, Error **errp) { - error_setg(errp, "unsupported RPMI service group %u", - service->service_group); - return false; + const RiscvRpmiServiceOps *ops; + + ops =3D riscv_rpmi_service_ops_by_group(service->service_group); + if (!ops) { + error_setg(errp, "unsupported RPMI service group %u", + service->service_group); + return false; + } + + return ops->add(s, errp); } =20 static bool riscv_rpmi_init_services(RiscvRpmiState *s, Error **errp) diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index 95aa8dec14..e5880aebe2 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -21,5 +21,14 @@ extern const struct rpmi_shmem_platform_ops rpmi_shmem_q= emu_ops; bool riscv_rpmi_service_enabled(RiscvRpmiState *s, enum rpmi_servicegroup_id service_group); void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); +bool riscv_rpmi_context_add_group(RiscvRpmiState *s, + struct rpmi_service_group *group, + const char *name, + Error **errp); +void riscv_rpmi_context_remove_group(RiscvRpmiState *s, + struct rpmi_service_group *group); + +bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_sysreset_remove(RiscvRpmiState *s); =20 #endif diff --git a/hw/misc/riscv_rpmi_sysreset.c b/hw/misc/riscv_rpmi_sysreset.c new file mode 100644 index 0000000000..825a74b2d9 --- /dev/null +++ b/hw/misc/riscv_rpmi_sysreset.c @@ -0,0 +1,185 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI System Reset service. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "riscv_rpmi_internal.h" +#include "librpmi_env.h" + +typedef struct RiscvRpmiSysresetType { + uint32_t type; + void (*action)(RiscvRpmiState *s); +} RiscvRpmiSysresetType; + +typedef struct RiscvRpmiSysresetGroup { + struct rpmi_service_group group; + struct rpmi_service services[RPMI_SYSRST_SRV_ID_MAX]; + RiscvRpmiState *rpmi; +} RiscvRpmiSysresetGroup; + +static void riscv_rpmi_sysreset_reboot(RiscvRpmiState *s) +{ + const RiscvRpmiMachineOps *ops =3D s->machine_ops; + + if (ops && ops->system_reset) { + ops->system_reset(); + } +} + +static void riscv_rpmi_sysreset_shutdown(RiscvRpmiState *s) +{ + const RiscvRpmiMachineOps *ops =3D s->machine_ops; + + if (ops && ops->system_shutdown) { + ops->system_shutdown(); + } +} + +static const RiscvRpmiSysresetType riscv_rpmi_sysreset_types[] =3D { + { + .type =3D RPMI_SYSRST_TYPE_SHUTDOWN, + .action =3D riscv_rpmi_sysreset_shutdown, + }, { + .type =3D RPMI_SYSRST_TYPE_COLD_REBOOT, + .action =3D riscv_rpmi_sysreset_reboot, + }, +}; + +static const RiscvRpmiSysresetType *riscv_rpmi_sysreset_type_by_id( + uint32_t reset_type) +{ + for (uint32_t index =3D 0; index < ARRAY_SIZE(riscv_rpmi_sysreset_type= s); + index++) { + if (riscv_rpmi_sysreset_types[index].type =3D=3D reset_type) { + return &riscv_rpmi_sysreset_types[index]; + } + } + + return NULL; +} + +static enum rpmi_error riscv_rpmi_sysreset_get_attributes( + struct rpmi_service_group *group, struct rpmi_service *service, + struct rpmi_transport *trans, rpmi_uint16_t request_data_len, + const rpmi_uint8_t *request_data, rpmi_uint16_t *response_data_len, + rpmi_uint8_t *response_data) +{ + uint32_t reset_type =3D ldl_le_p(request_data); + *response_data_len =3D 2 * sizeof(uint32_t); + stl_le_p(response_data, RPMI_SUCCESS); + stl_le_p(response_data + sizeof(uint32_t), + riscv_rpmi_sysreset_type_by_id(reset_type) ? + RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE : 0); + + return RPMI_SUCCESS; +} + +static enum rpmi_error riscv_rpmi_sysreset_do_reset( + struct rpmi_service_group *group, struct rpmi_service *service, + struct rpmi_transport *trans, rpmi_uint16_t request_data_len, + const rpmi_uint8_t *request_data, rpmi_uint16_t *response_data_len, + rpmi_uint8_t *response_data) +{ + RiscvRpmiSysresetGroup *sysreset =3D group->priv; + const RiscvRpmiSysresetType *type; + uint32_t reset_type =3D ldl_le_p(request_data); + + *response_data_len =3D sizeof(uint32_t); + type =3D riscv_rpmi_sysreset_type_by_id(reset_type); + + if (!type) { + stl_le_p(response_data, (uint32_t)RPMI_ERR_INVALID_PARAM); + return RPMI_SUCCESS; + } + + stl_le_p(response_data, RPMI_SUCCESS); + type->action(sysreset->rpmi); + return RPMI_SUCCESS; +} + +static const struct rpmi_service riscv_rpmi_sysreset_services[] =3D { + [RPMI_SYSRST_SRV_ENABLE_NOTIFICATION] =3D { + .service_id =3D RPMI_SYSRST_SRV_ENABLE_NOTIFICATION, + .min_a2p_request_datalen =3D 8, + }, + [RPMI_SYSRST_SRV_GET_ATTRIBUTES] =3D { + .service_id =3D RPMI_SYSRST_SRV_GET_ATTRIBUTES, + .min_a2p_request_datalen =3D 4, + .process_a2p_request =3D riscv_rpmi_sysreset_get_attributes, + }, + [RPMI_SYSRST_SRV_SYSTEM_RESET] =3D { + .service_id =3D RPMI_SYSRST_SRV_SYSTEM_RESET, + .min_a2p_request_datalen =3D 4, + .process_a2p_request =3D riscv_rpmi_sysreset_do_reset, + }, +}; + +static struct rpmi_service_group *riscv_rpmi_sysreset_create(RiscvRpmiStat= e *s) +{ + RiscvRpmiSysresetGroup *sysreset; + struct rpmi_service_group *group; + + sysreset =3D g_new0(RiscvRpmiSysresetGroup, 1); + sysreset->rpmi =3D s; + memcpy(sysreset->services, riscv_rpmi_sysreset_services, + sizeof(riscv_rpmi_sysreset_services)); + + group =3D &sysreset->group; + group->name =3D "sysreset"; + group->servicegroup_id =3D RPMI_SRVGRP_SYSTEM_RESET; + group->max_service_id =3D RPMI_SYSRST_SRV_ID_MAX; + group->servicegroup_version =3D + RPMI_BASE_VERSION(RPMI_SPEC_VERSION_MAJOR, RPMI_SPEC_VERSION_MINOR= ); + group->privilege_level_bitmap =3D RPMI_PRIVILEGE_M_MODE_MASK; + group->services =3D sysreset->services; + group->lock =3D rpmi_env_alloc_lock(); + group->priv =3D sysreset; + + return group; +} + +static void riscv_rpmi_sysreset_destroy(struct rpmi_service_group *group) +{ + if (!group) { + return; + } + + rpmi_env_free_lock(group->lock); + g_free(group->priv); +} + +bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group; + + if (s->sysreset_group) { + error_setg(errp, "duplicate RPMI sysreset service descriptor"); + return false; + } + + group =3D riscv_rpmi_sysreset_create(s); + if (!riscv_rpmi_context_add_group(s, group, "sysreset", errp)) { + riscv_rpmi_sysreset_destroy(group); + return false; + } + + s->sysreset_group =3D group; + return true; +} + +void riscv_rpmi_sysreset_remove(RiscvRpmiState *s) +{ + if (!s->sysreset_group) { + return; + } + + riscv_rpmi_context_remove_group(s, s->sysreset_group); + riscv_rpmi_sysreset_destroy(s->sysreset_group); + s->sysreset_group =3D NULL; +} diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index ce2dcb43b4..8a378458da 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -315,7 +315,8 @@ void riscv_create_fdt_flash(void *fdt, hwaddr flashbase= , hwaddr flashsize) void riscv_create_fdt_syscon(void *fdt, uint32_t *next_phandle, hwaddr addr, hwaddr size, uint32_t reboot, uint32_t poweroff, - bool sifive_test_compat) + bool sifive_test_compat, + bool create_reset_nodes) { uint32_t syscon_phandle; char *name; @@ -343,6 +344,11 @@ void riscv_create_fdt_syscon(void *fdt, uint32_t *next= _phandle, =20 g_free(name); =20 + /* Some machines route reset and shutdown through another interface. */ + if (!create_reset_nodes) { + return; + } + name =3D g_strdup_printf("/reboot"); qemu_fdt_add_subnode(fdt, name); qemu_fdt_setprop_string(fdt, name, "compatible", "syscon-reboot"); diff --git a/hw/riscv/server_platform_ref.c b/hw/riscv/server_platform_ref.c index 5f485b1c79..d18550b48d 100644 --- a/hw/riscv/server_platform_ref.c +++ b/hw/riscv/server_platform_ref.c @@ -310,7 +310,7 @@ static void finalize_fdt(RISCVServerRefMachineState *s) riscv_create_fdt_syscon(ms->fdt, &phandle, rvserver_ref_memmap[RVSERVER_RESET_SYSCON].bas= e, rvserver_ref_memmap[RVSERVER_RESET_SYSCON].siz= e, - SYSCON_RESET, SYSCON_POWEROFF, false); + SYSCON_RESET, SYSCON_POWEROFF, false, true); =20 riscv_create_fdt_uart(ms->fdt, &rvserver_ref_memmap[RVSERVER_UART0], RVSERVER_UART0_IRQ, AIA_TYPE_APLIC_IMSIC, diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 8a2ed43029..1e313e078e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -52,6 +52,7 @@ #include "chardev/char.h" #include "system/device_tree.h" #include "system/system.h" +#include "system/runstate.h" #include "system/tcg.h" #include "system/kvm.h" #include "system/tpm.h" @@ -478,6 +479,34 @@ static void create_fdt_iommu(RISCVVirtState *s, uint16= _t bdf) s->pci_iommu_bdf =3D bdf; } =20 +static const RiscvRpmiServiceConfig virt_rpmi_services[] =3D { + { + .node_name =3D "sysreset", + .compatible =3D "riscv,rpmi-system-reset", + .service_group =3D RPMI_SRVGRP_SYSTEM_RESET, + }, +}; + +static uint32_t virt_rpmi_service_count(void) +{ + return ARRAY_SIZE(virt_rpmi_services); +} + +static void virt_rpmi_system_reset(void) +{ + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); +} + +static void virt_rpmi_system_shutdown(void) +{ + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); +} + +static const RiscvRpmiMachineOps virt_rpmi_machine_ops =3D { + .system_reset =3D virt_rpmi_system_reset, + .system_shutdown =3D virt_rpmi_system_shutdown, +}; + static RiscvRpmiConfig virt_rpmi_config(RISCVVirtState *s, const uint32_t *hart_ids, uint32_t hart_count) @@ -489,13 +518,18 @@ static RiscvRpmiConfig virt_rpmi_config(RISCVVirtStat= e *s, .a2p_req_size =3D VIRT_RPMI_A2P_REQ_SIZE, .p2a_req_size =3D VIRT_RPMI_P2A_REQ_SIZE, .platform_info =3D "QEMU RISC-V virt RPMI", + .machine_ops =3D &virt_rpmi_machine_ops, .hart_ids =3D hart_ids, .hart_count =3D hart_count, + .services =3D virt_rpmi_services, + .service_count =3D virt_rpmi_service_count(), }; } =20 static void create_fdt_rpmi(RISCVVirtState *s, uint32_t *phandle) { + uint32_t rpmi_mbox_handle; + uint32_t i; RiscvRpmiFdtMboxConfig cfg =3D { .shmem_base =3D s->memmap[VIRT_RPMI_SHMEM].base, .doorbell_base =3D s->memmap[VIRT_RPMI_DOORBELL].base, @@ -504,7 +538,14 @@ static void create_fdt_rpmi(RISCVVirtState *s, uint32_= t *phandle) .doorbell_size =3D s->memmap[VIRT_RPMI_DOORBELL].size, }; =20 - riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, NULL); + riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, + &rpmi_mbox_handle); + + for (i =3D 0; i < virt_rpmi_service_count(); i++) { + riscv_rpmi_fdt_add_service_node(MACHINE(s)->fdt, + &virt_rpmi_services[i], + rpmi_mbox_handle); + } } =20 static void finalize_fdt(RISCVVirtState *s) @@ -542,7 +583,8 @@ static void finalize_fdt(RISCVVirtState *s) riscv_create_fdt_syscon(MACHINE(s)->fdt, &phandle, s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, - FINISHER_RESET, FINISHER_PASS, true); + FINISHER_RESET, FINISHER_PASS, true, + !s->have_rpmi); if (s->have_rpmi) { create_fdt_rpmi(s, &phandle); } diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index c207501405..1ab648359d 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -43,6 +43,11 @@ struct rpmi_service_group; struct rpmi_shmem; struct rpmi_transport; =20 +typedef struct RiscvRpmiMachineOps { + void (*system_reset)(void); + void (*system_shutdown)(void); +} RiscvRpmiMachineOps; + typedef struct RiscvRpmiServiceConfig { const char *node_name; const char *compatible; @@ -58,7 +63,7 @@ typedef struct RiscvRpmiConfig { uint32_t a2p_req_size; uint32_t p2a_req_size; const char *platform_info; - + const RiscvRpmiMachineOps *machine_ops; const uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; @@ -75,7 +80,8 @@ struct RiscvRpmiState { uint32_t a2p_req_size; uint32_t p2a_req_size; char *platform_info; - + const RiscvRpmiMachineOps *machine_ops; + struct rpmi_service_group *sysreset_group; uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index eb9db8278d..4d2b8a8059 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -103,7 +103,8 @@ void riscv_create_fdt_flash(void *fdt, hwaddr flashbase= , hwaddr flashsize); void riscv_create_fdt_syscon(void *fdt, uint32_t *next_phandle, hwaddr addr, hwaddr size, uint32_t reboot, uint32_t poweroff, - bool sifive_test_compat); + bool sifive_test_compat, + bool create_reset_nodes); uint32_t riscv_create_fdt_riscv_iommu_sys(void *fdt, hwaddr addr, hwaddr s= ize, uint32_t *next_phandle, uint32_t irq_chip, From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556886; cv=none; d=zohomail.com; s=zohoarc; b=ZIviyaprDhhUUvEvmYfZxtql5HDUq8HS+9UfaBN7RcwJL8EUEXhaXvxeegPRadfwAAjv5eBtdA0Jx5aVN+hGZnl7wEEuI0nVlXR0FwVU3pG4TT/pZ2jKFqMqo6tkuaLpAMLoUiteolGe+34mHq+j+teD2hMOSPbNkvjk48AVY0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556886; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2/MmuBaZZ46sgO5jq6e8oaEBk2CEp/95DRM7bMkZdXQ=; b=Z6gRzwMrh65Q7F9jLTZ4Y8UX6bCW066CUxO9xpazo0OWrSI/GDMsJ2jzSGZs9JWDL6I85GPAUVxzwrupEyQWwq+tsegJrf+FR8sbPIY9SslzgavHhRWLVS34kpahHHMgUlQYab5/e3l84II8BYEoqM6n/ZUVGe0r17vdCLXM5sk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556886314103.23803268778408; Fri, 13 Nov 2026 00:01:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCR-0002oE-Uh; Fri, 13 Nov 2026 02:59:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCR-0002no-1P for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:55 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCO-0000EU-1W for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:54 -0500 Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD6IB7k1164129 for ; Fri, 13 Nov 2026 07:59:51 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hww5r8af1-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:50 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-30c58d35c0aso115110eec.0 for ; Thu, 12 Nov 2026 23:59:50 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=2/MmuBaZZ46 sgO5jq6e8oaEBk2CEp/95DRM7bMkZdXQ=; b=Zpmp0mtq5aEa6LoANKuSM2TJE+K 0iL9LiDDtJJerynvp6OdXZnBSCkD9XAtsfpwZ37c/XsnQF4P180nz+F7cRaj7nVv zD2jy2ZZeXEpiY2w0rem+YEYfKg6KnHYe5VQSNjzxxgqPA5Bmo/3QLleMU+F+/x2 TZL9egqjnZdvt9Rx5pT7H09foDW8N8NjqYDt+fFcHeKktMQGboK01b5sn0lWOioR r8NPi0OAUowNlG2Vh7598loIOntCJHX2w9RESK9c6Th9CthU4AqVRBg9ekPDW9pi YO3SSQFc172/zTdb6JkjfQsWUwbS/LV142aqo1qxlZnDJWsoiTIO0ZOyfAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556790; x=1795161590; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=2/MmuBaZZ46sgO5jq6e8oaEBk2CEp/95DRM7bMkZdXQ=; b=P8NnW4h5wIuFoSk83Hfi7K/LJPLsE0AEyok86ZsB6LvWr11AE0HGUGxwARIbSZwtPo /XkLwKAck52kkNXJ1jPWkGkMPvzy2RSjIk7FW/2ggbW0ADZa+e8hzwIyCLYRwlwD92Mc JEaQVg7e6iTJQvwLBwg/5oivnE5ZBT6iJaaPNFwCDmYBVfxitu1oDDNpSjazPnjRX0sE QDGId4KymA8Yv4Jy0sayawfj7jVvTVOVgTGt3fxKiTALbzLiEIHk9TCMC56hA8H7dzdd DrVJw0otsRLukGGf4CbhfyD+g7auVKBhzQrmnn25HT3fKWV/IjSMWlAs9/VN4vjW7Bx/ JWCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556790; x=1795161590; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=2/MmuBaZZ46sgO5jq6e8oaEBk2CEp/95DRM7bMkZdXQ=; b=NttXngp3Vs6r1q9v//tDODGvnMe33OyzuBrOdf7c4wKjodNG1Ov5OWInXmd+Qczmyy T850FYRtWE6FVk+4wFNrUqXscb7D0Ochr6wtPdsjnMqqSt9POf4dG5brc7VA8b+lGH1B zeu2QpHTqED66FGygSwIswoXhs6/t5+8HQSbF9X20/D7B6qpI+jMpK0sV0MWBhq5DeHF euvEW9Y+5y2d6i1h76V8X64UB5a4e7jK+vmSLWy8oVupAak1FRlOBk+eXMGJRN3v8Wvn hkIcuju1s4l0A8F3SStUAv4FSPITqyUG4wf36GaPGUHYqnfh01YQq0CD4Hiw9Wdb2C0N uZEQ== X-Gm-Message-State: APuU4Z950PFTNiQzS/HaA98wngsj/scxfBKQNVOVN9jWo0ODpaAUYGb5 qHfdkTNr9TM5VjiXRlwifbPGXh5GF18/llcG3ZclE+aQbVQthCVoDYsVIc6Q++7ealcPnj/27n0 xtBDnngnu7Ck2SA3Ygkddsow48lADYK9dnQTneF2l931TADiN7ZzioVCyw4/d1N/uRg== X-Gm-Gg: AYBFou0xvbrDjUqn9gy8dPsndG3+zc8479vEHZC8dSHKeE7gVbGkHbmN5hDa6XByDQD to/xJGu63rY796vDlj11t2iX+trwGKsQsPclIJMn3NUZzp4SxarZ5+AxQyQCQ4j5t427a4bP1nc YbMnpDO42zoimoVXLlYiYCjCulHymt7KRWn9gbqFEtTewdA5UkxPL4YrV2IlrWbYmzLH4IURhHi u5roRVO88ws3WJc6IsY114wuGtf6HDL4if3NuDys1ZDiL1xmH7GCyV84SLJkgZKwfQNw2li8Qzb 4fTaYLw8CvnP9dOsUBWdsGFNPeAT18Vx33fImRiINNASFeFWU3eA2eZISBVLx8MVeeVKrdsMvWz YhdcbWNS1He/zTpV/kcE5aDwooKWgofWvhxgyK/FQKYIuzIJGqNyRgi2Qh6hzSHjQnMkjgewfI/ 5esRuq9GbatDe3C9L5nD124OB/tZA0Lgpy6DIXoDiUOBHZYmDV2JnLAas7CCmjVChxAfs4zYluH PaXCJ8= X-Received: by 2002:a05:7300:6da8:b0:36a:e7a:e89 with SMTP id 5a478bee46e88-379659c6815mr3069280eec.2.1794556789407; Thu, 12 Nov 2026 23:59:49 -0800 (PST) X-Received: by 2002:a05:7300:6da8:b0:36a:e7a:e89 with SMTP id 5a478bee46e88-379659c6815mr3069230eec.2.1794556788679; Thu, 12 Nov 2026 23:59:48 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v16 06/10] riscv: add RPMI HSM service Date: Fri, 13 Nov 2026 13:29:01 +0530 Message-ID: <20261113075906.715870-7-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX6dnqr6VwTl2V EftPBqnZ1N5H0g/QiNon9hMNgqM0pFU7rC1rz4iK2+qrNMRfAPV8uQoG4HM3095yKo2MSfnnOTW DoFpzx9D5DkmkqvPiWcEoS2/2iGzNQ+QD98cNBI1ge/7XHVLx5cOqcNqKRBkgC1NDpGWS9p5f5/ bJPF/sJhaVJihXREkIDY20DqSjoF2t5zFqwBOCAO8FZxwVFaGKFbH5G8vCZJHgKUSFG7Kclkswn Az+G1Ipg6quAM7zH9PEoLIWuGVp+ZKc8CHAOvbvxXg8UqF1MiBt27Fm/fisbuvIt7m5p2MRA9Ie aQDTk8MTaOmQhf7BnqZgGnce5ym4oP4YKpv0tJ4HNfCAjPd4wqnVAZxyB7sAaf/ismi3L+KZLrM iOVmG5VZg2wYVrZ4wtn1yXjvp89cN/7O7G9Lwcgt2gjyU+jGTQYoo+yR0fkwzN35U1tL18AIVFa QUGJOPY0QhIOfBrW4LQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX5tf9vIqrkWnc 3Pjp+WvEu9K9ZP0AQ5PtQDFgFE4eWYwwb6CWHH/EPphRytw0EJacmIXag5D9UMaIn6sPw1AyyqZ k91Qm4t4vXOlnswn5xhbUUXpTX9hN+0= X-Proofpoint-ORIG-GUID: GJK7QMfrako6YRJ412-rdg2j6vhUfuh1 X-Authority-Analysis: v=2.4 cv=Vqq2kO2n c=1 sm=1 tr=0 ts=6af6c376 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=EUspDBNiAAAA:8 a=quq8RQvC8PMJxjtlgMUA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-GUID: GJK7QMfrako6YRJ412-rdg2j6vhUfuh1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 impostorscore=0 phishscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556887463158500 Content-Type: text/plain; charset="utf-8" Add the RPMI Hart State Management service group for RISC-V virt. The service exposes configured hart IDs to librpmi and keeps stable per-hart state in the RPMI device. A persistent observer on each target CPU makes actual WFI entry authoritative for stop and suspend completion, while CPU work handles starts and requests received after a hart has already entered WFI. Keep RPMI-stopped harts off despite pending interrupts, timer events, kicks, or generic resume attempts. HART_START is the normal path that restores the hart power state and execution address. Serialize librpmi state publication under the BQL, drain target-CPU work during teardown, and reconstruct the external librpmi HSM object during machine reset so pending operations return to the STARTED baseline. Signed-off-by: Subrahmanya Lingappa --- hw/misc/meson.build | 1 + hw/misc/riscv_rpmi.c | 5 + hw/misc/riscv_rpmi_hsm.c | 344 ++++++++++++++++++++++++++++++++++++++= ++++ hw/misc/riscv_rpmi_internal.h | 5 +- hw/riscv/virt.c | 5 + include/hw/misc/riscv_rpmi.h | 5 + target/riscv/cpu-qom.h | 16 ++ target/riscv/cpu.c | 61 ++++++++ target/riscv/cpu.h | 7 + target/riscv/tcg/op_helper.c | 4 + target/riscv/tcg/tcg-cpu.c | 1 + 11 files changed, 453 insertions(+), 1 deletion(-) create mode 100644 hw/misc/riscv_rpmi_hsm.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index a091d393a3..6d93cd4ab0 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -186,4 +186,5 @@ system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true:= files('qcom-qdsp6ss-clk. system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( 'riscv_rpmi.c', 'riscv_rpmi_sysreset.c', + 'riscv_rpmi_hsm.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 2c6e694ff0..327753190f 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -212,6 +212,10 @@ static const RiscvRpmiServiceOps riscv_rpmi_service_op= s[] =3D { .service_group =3D RPMI_SRVGRP_SYSTEM_RESET, .add =3D riscv_rpmi_sysreset_add, .remove =3D riscv_rpmi_sysreset_remove, + }, { + .service_group =3D RPMI_SRVGRP_HSM, + .add =3D riscv_rpmi_hsm_add, + .remove =3D riscv_rpmi_hsm_remove, }, }; =20 @@ -261,6 +265,7 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTyp= e type) memset(memory_region_get_ram_ptr(&s->shmem), 0, s->shmem_size); memory_region_set_dirty(&s->shmem, 0, s->shmem_size); } + riscv_rpmi_hsm_reset(s, &error_abort); } =20 static void riscv_rpmi_cleanup(RiscvRpmiState *s) diff --git a/hw/misc/riscv_rpmi_hsm.c b/hw/misc/riscv_rpmi_hsm.c new file mode 100644 index 0000000000..42a4f3b096 --- /dev/null +++ b/hw/misc/riscv_rpmi_hsm.c @@ -0,0 +1,344 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI HSM service. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "riscv_rpmi_internal.h" +#include "hw/core/cpu.h" +#include "qemu/main-loop.h" +#include "system/cpus.h" +#include "target/riscv/cpu-qom.h" +#include "librpmi_env.h" + +static const struct rpmi_hsm_suspend_type riscv_rpmi_hsm_suspend_types[] = =3D { + { .type =3D 0 }, +}; + +struct RiscvRpmiHsmHart { + RiscvRpmiState *rpmi; + CPUState *cpu; + enum rpmi_hart_hw_state state; + enum rpmi_hart_hw_state wfi_state; + uint64_t start_addr; +}; + +/* + * RPMI requests and queued CPU work hold BQL. Natural WFI transitions use= an + * atomic armed-state check and take BQL only when a transition is pending. + */ +static RiscvRpmiHsmHart *riscv_rpmi_hsm_hart(RiscvRpmiState *s, + uint32_t hart_index) +{ + if (!s->hsm_harts || hart_index >=3D s->hart_count || + !s->hsm_harts[hart_index].cpu) { + return NULL; + } + + return &s->hsm_harts[hart_index]; +} +static void riscv_rpmi_hsm_wfi(CPUState *cpu, bool entering, void *opaque) +{ + RiscvRpmiHsmHart *hart =3D opaque; + enum rpmi_hart_hw_state wfi_state; + bool need_bql =3D !bql_locked(); + bool changed =3D false; + + wfi_state =3D qatomic_read(&hart->wfi_state); + if (wfi_state =3D=3D RPMI_HART_HW_STATE_MAX) { + return; + } + if (need_bql) { + bql_lock(); + } + + wfi_state =3D qatomic_read(&hart->wfi_state); + if (entering && wfi_state =3D=3D RPMI_HART_HW_STATE_STOPPED) { + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + riscv_cpu_set_powered_off(cpu, true); + hart->state =3D RPMI_HART_HW_STATE_STOPPED; + changed =3D true; + } else if (wfi_state =3D=3D RPMI_HART_HW_STATE_SUSPENDED) { + hart->state =3D entering ? RPMI_HART_HW_STATE_SUSPENDED : + RPMI_HART_HW_STATE_STARTED; + if (!entering) { + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + } + changed =3D true; + } + + if (changed) { + rpmi_hsm_process_state_changes(hart->rpmi->hsm); + } + if (need_bql) { + bql_unlock(); + } +} + +static void riscv_rpmi_hsm_set_observer(CPUState *cpu, run_on_cpu_data dat= a) +{ + riscv_cpu_set_wfi_observer(cpu, riscv_rpmi_hsm_wfi, data.host_ptr); +} + +static void riscv_rpmi_hsm_clear_observer(CPUState *cpu, run_on_cpu_data d= ata) +{ + riscv_cpu_set_wfi_observer(cpu, NULL, NULL); + riscv_cpu_set_powered_off(cpu, false); + cpu->halted =3D false; + cpu_resume(cpu); +} + +static void riscv_rpmi_hsm_start_cpu(CPUState *cpu, run_on_cpu_data data) +{ + RiscvRpmiHsmHart *hart =3D data.host_ptr; + + g_assert(bql_locked()); + riscv_cpu_handle_wfi_resume(cpu); + cpu_set_pc(cpu, hart->start_addr); + riscv_cpu_set_powered_off(cpu, false); + cpu->halted =3D false; + cpu_resume(cpu); + hart->state =3D RPMI_HART_HW_STATE_STARTED; + rpmi_hsm_process_state_changes(hart->rpmi->hsm); +} + +static void riscv_rpmi_hsm_replay_wfi(CPUState *cpu, run_on_cpu_data data) +{ + riscv_cpu_replay_wfi_observer(cpu); +} + +static enum rpmi_error riscv_rpmi_hsm_start_prepare( + void *priv, rpmi_uint32_t hart_index, rpmi_uint64_t start_addr) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(priv, hart_index); + + g_assert(bql_locked()); + if (!hart) { + return RPMI_ERR_INVALID_PARAM; + } + + hart->start_addr =3D start_addr; + async_run_on_cpu(hart->cpu, riscv_rpmi_hsm_start_cpu, + RUN_ON_CPU_HOST_PTR(hart)); + return RPMI_SUCCESS; +} + +/* librpmi requires finalize hooks even when QEMU has no second phase. */ +static void riscv_rpmi_hsm_start_finalize(void *priv, + rpmi_uint32_t hart_index, + rpmi_uint64_t start_addr) +{ +} + +static enum rpmi_error riscv_rpmi_hsm_arm_wfi( + RiscvRpmiState *s, uint32_t hart_index, enum rpmi_hart_hw_state state) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(s, hart_index); + + g_assert(bql_locked()); + if (!hart) { + return RPMI_ERR_INVALID_PARAM; + } + + qatomic_set(&hart->wfi_state, state); + async_run_on_cpu(hart->cpu, riscv_rpmi_hsm_replay_wfi, + RUN_ON_CPU_NULL); + return RPMI_SUCCESS; +} + +static enum rpmi_error riscv_rpmi_hsm_stop_prepare(void *priv, + rpmi_uint32_t hart_ind= ex) +{ + return riscv_rpmi_hsm_arm_wfi(priv, hart_index, + RPMI_HART_HW_STATE_STOPPED); +} + +static void riscv_rpmi_hsm_stop_finalize(void *priv, + rpmi_uint32_t hart_index) +{ +} + +static enum rpmi_error riscv_rpmi_hsm_suspend_prepare( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_hsm_suspend_type *suspend_type, + rpmi_uint64_t resume_addr) +{ + if (!suspend_type) { + return RPMI_ERR_INVALID_PARAM; + } + + return riscv_rpmi_hsm_arm_wfi(priv, hart_index, + RPMI_HART_HW_STATE_SUSPENDED); +} + +static void riscv_rpmi_hsm_suspend_finalize( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_hsm_suspend_type *suspend_type, + rpmi_uint64_t resume_addr) +{ +} + +static enum rpmi_hart_hw_state riscv_rpmi_hsm_get_hw_state( + void *priv, rpmi_uint32_t hart_index) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(priv, hart_index); + + g_assert(bql_locked()); + return hart ? hart->state : RPMI_HART_HW_STATE_STOPPED; +} + +static const struct rpmi_hsm_platform_ops riscv_rpmi_hsm_ops =3D { + .hart_get_hw_state =3D riscv_rpmi_hsm_get_hw_state, + .hart_start_prepare =3D riscv_rpmi_hsm_start_prepare, + .hart_start_finalize =3D riscv_rpmi_hsm_start_finalize, + .hart_stop_prepare =3D riscv_rpmi_hsm_stop_prepare, + .hart_stop_finalize =3D riscv_rpmi_hsm_stop_finalize, + .hart_suspend_prepare =3D riscv_rpmi_hsm_suspend_prepare, + .hart_suspend_finalize =3D riscv_rpmi_hsm_suspend_finalize, +}; + +static bool riscv_rpmi_hsm_create_external( + RiscvRpmiState *s, struct rpmi_service_group **group, Error **errp) +{ + s->hsm =3D rpmi_hsm_create(s->hart_count, s->hart_ids, + ARRAY_SIZE(riscv_rpmi_hsm_suspend_types), + riscv_rpmi_hsm_suspend_types, + &riscv_rpmi_hsm_ops, s); + if (!s->hsm) { + error_setg(errp, "failed to create RPMI HSM context"); + return false; + } + + *group =3D rpmi_service_group_hsm_create(s->hsm); + if (!*group) { + rpmi_hsm_destroy(s->hsm); + s->hsm =3D NULL; + error_setg(errp, "failed to create RPMI HSM service group"); + return false; + } + + return true; +} + +static void riscv_rpmi_hsm_destroy_external(RiscvRpmiState *s) +{ + if (s->hsm_group) { + rpmi_env_free_lock(s->hsm_group->lock); + s->hsm_group->lock =3D NULL; + rpmi_service_group_hsm_destroy(s->hsm_group); + s->hsm_group =3D NULL; + } + if (s->hsm) { + rpmi_hsm_destroy(s->hsm); + s->hsm =3D NULL; + } +} + +static void riscv_rpmi_hsm_reset_cpu(CPUState *cpu, run_on_cpu_data data) +{ + riscv_cpu_handle_wfi_resume(cpu); + riscv_cpu_set_powered_off(cpu, false); + cpu->halted =3D false; +} + +bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group; + + if (s->hsm_group) { + error_setg(errp, "duplicate RPMI HSM service descriptor"); + return false; + } + if (!s->hart_count || !s->hart_ids) { + error_setg(errp, "RPMI HSM service requires hart IDs"); + return false; + } + + s->hsm_harts =3D g_new0(RiscvRpmiHsmHart, s->hart_count); + for (uint32_t i =3D 0; i < s->hart_count; i++) { + RiscvRpmiHsmHart *hart =3D &s->hsm_harts[i]; + + hart->rpmi =3D s; + hart->cpu =3D cpu_by_arch_id(s->hart_ids[i]); + hart->state =3D RPMI_HART_HW_STATE_STARTED; + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + } + + if (!riscv_rpmi_hsm_create_external(s, &group, errp)) { + g_clear_pointer(&s->hsm_harts, g_free); + return false; + } + if (!riscv_rpmi_context_add_group(s, group, "HSM", errp)) { + s->hsm_group =3D group; + riscv_rpmi_hsm_destroy_external(s); + g_clear_pointer(&s->hsm_harts, g_free); + return false; + } + + s->hsm_group =3D group; + for (uint32_t i =3D 0; i < s->hart_count; i++) { + RiscvRpmiHsmHart *hart =3D &s->hsm_harts[i]; + + if (hart->cpu) { + run_on_cpu(hart->cpu, riscv_rpmi_hsm_set_observer, + RUN_ON_CPU_HOST_PTR(hart)); + } + } + return true; +} + +void riscv_rpmi_hsm_remove(RiscvRpmiState *s) +{ + if (!s->hsm_harts) { + return; + } + + for (uint32_t i =3D 0; i < s->hart_count; i++) { + CPUState *cpu =3D s->hsm_harts[i].cpu; + + if (cpu) { + run_on_cpu(cpu, riscv_rpmi_hsm_clear_observer, RUN_ON_CPU_NULL= ); + } + } + riscv_rpmi_context_remove_group(s, s->hsm_group); + riscv_rpmi_hsm_destroy_external(s); + g_clear_pointer(&s->hsm_harts, g_free); +} + +bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group =3D NULL; + + if (!s->hsm_harts) { + return true; + } + + for (uint32_t i =3D 0; i < s->hart_count; i++) { + RiscvRpmiHsmHart *hart =3D &s->hsm_harts[i]; + + if (hart->cpu) { + run_on_cpu(hart->cpu, riscv_rpmi_hsm_reset_cpu, + RUN_ON_CPU_NULL); + } + hart->state =3D RPMI_HART_HW_STATE_STARTED; + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + } + + riscv_rpmi_context_remove_group(s, s->hsm_group); + riscv_rpmi_hsm_destroy_external(s); + if (!riscv_rpmi_hsm_create_external(s, &group, errp)) { + return false; + } + if (!riscv_rpmi_context_add_group(s, group, "HSM", errp)) { + s->hsm_group =3D group; + riscv_rpmi_hsm_destroy_external(s); + return false; + } + s->hsm_group =3D group; + return true; +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index e5880aebe2..e56dba5b1a 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -27,8 +27,11 @@ bool riscv_rpmi_context_add_group(RiscvRpmiState *s, Error **errp); void riscv_rpmi_context_remove_group(RiscvRpmiState *s, struct rpmi_service_group *group); - bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp); void riscv_rpmi_sysreset_remove(RiscvRpmiState *s); =20 +bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_hsm_remove(RiscvRpmiState *s); +bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **errp); + #endif diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 1e313e078e..32aa13325e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -485,6 +485,11 @@ static const RiscvRpmiServiceConfig virt_rpmi_services= [] =3D { .compatible =3D "riscv,rpmi-system-reset", .service_group =3D RPMI_SRVGRP_SYSTEM_RESET, }, + { + .node_name =3D "hsm", + .compatible =3D "riscv,rpmi-hsm", + .service_group =3D RPMI_SRVGRP_HSM, + }, }; =20 static uint32_t virt_rpmi_service_count(void) diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index 1ab648359d..3a240941cd 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -42,6 +42,8 @@ struct rpmi_context; struct rpmi_service_group; struct rpmi_shmem; struct rpmi_transport; +struct rpmi_hsm; +typedef struct RiscvRpmiHsmHart RiscvRpmiHsmHart; =20 typedef struct RiscvRpmiMachineOps { void (*system_reset)(void); @@ -82,6 +84,9 @@ struct RiscvRpmiState { char *platform_info; const RiscvRpmiMachineOps *machine_ops; struct rpmi_service_group *sysreset_group; + struct rpmi_hsm *hsm; + struct rpmi_service_group *hsm_group; + RiscvRpmiHsmHart *hsm_harts; uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h index 61234842e3..f6b6023835 100644 --- a/target/riscv/cpu-qom.h +++ b/target/riscv/cpu-qom.h @@ -64,4 +64,20 @@ =20 OBJECT_DECLARE_CPU_TYPE(RISCVCPU, RISCVCPUClass, RISCV_CPU) =20 +#ifndef CONFIG_USER_ONLY +/* + * WFI observers persist across entries and exits. Access observers and WFI + * state only on the target CPU thread; use run_on_cpu() to register or re= move + * an observer and drain earlier CPU work before freeing its opaque state. + */ +void riscv_cpu_set_wfi_observer( + CPUState *cpu, + void (*observer)(CPUState *cpu, bool entering, void *opaque), + void *opaque); +void riscv_cpu_handle_wfi(CPUState *cpu); +void riscv_cpu_handle_wfi_resume(CPUState *cpu); +void riscv_cpu_replay_wfi_observer(CPUState *cpu); +void riscv_cpu_set_powered_off(CPUState *cpu, bool powered_off); +#endif + #endif /* RISCV_CPU_QOM_H */ diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 5a0529fbda..e516a6b98f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -58,6 +58,61 @@ const uint32_t misa_bits[] =3D {RVI, RVE, RVM, RVA, RVF,= RVD, RVV, */ #define RISCV_CPU_MARCHID 42 =20 +#ifndef CONFIG_USER_ONLY +void riscv_cpu_set_wfi_observer(CPUState *cpu, + void (*observer)(CPUState *, bool, void *), + void *opaque) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + rcpu->wfi_observer =3D observer; + rcpu->wfi_observer_opaque =3D opaque; +} + +void riscv_cpu_handle_wfi(CPUState *cpu) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + rcpu->wfi_active =3D true; + if (rcpu->wfi_observer) { + rcpu->wfi_observer(cpu, true, rcpu->wfi_observer_opaque); + } +} + +void riscv_cpu_handle_wfi_resume(CPUState *cpu) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + if (!rcpu->wfi_active) { + return; + } + rcpu->wfi_active =3D false; + if (rcpu->wfi_observer) { + rcpu->wfi_observer(cpu, false, rcpu->wfi_observer_opaque); + } +} + +void riscv_cpu_replay_wfi_observer(CPUState *cpu) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + if (rcpu->wfi_active && rcpu->wfi_observer) { + rcpu->wfi_observer(cpu, true, rcpu->wfi_observer_opaque); + } +} + +void riscv_cpu_set_powered_off(CPUState *cpu, bool powered_off) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + qatomic_set(&rcpu->powered_off, powered_off); +} +#endif + /* * From vector_helper.c * Note that vector data is stored in host-endian 64-bit chunks, @@ -967,6 +1022,10 @@ static bool riscv_cpu_has_work(CPUState *cs) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; + + if (qatomic_read(&cpu->powered_off)) { + return false; + } /* * Definition of the WFI instruction requires it to ignore the privile= ge * mode and delegation registers, but respect individual enables @@ -988,6 +1047,8 @@ static void riscv_cpu_reset_hold(Object *obj, ResetTyp= e type) mcc->parent_phases.hold(obj, type); } #ifndef CONFIG_USER_ONLY + riscv_cpu_set_powered_off(cs, false); + cpu->wfi_active =3D false; env->misa_mxl =3D mcc->def->misa_mxl_max; env->priv =3D PRV_M; env->mstatus &=3D ~(MSTATUS_MIE | MSTATUS_MPRV); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 49a1186bdb..ac79397858 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -577,6 +577,13 @@ struct ArchCPU { =20 CPURISCVState env; =20 +#ifndef CONFIG_USER_ONLY + void (*wfi_observer)(CPUState *, bool, void *); + void *wfi_observer_opaque; + bool wfi_active; + bool powered_off; +#endif + GDBFeature dyn_csr_feature; GDBFeature dyn_vreg_feature; =20 diff --git a/target/riscv/tcg/op_helper.c b/target/riscv/tcg/op_helper.c index f9c79fe6b9..b0fb3c2cf8 100644 --- a/target/riscv/tcg/op_helper.c +++ b/target/riscv/tcg/op_helper.c @@ -644,6 +644,10 @@ void HELPER(wfi)(CPURISCVState *env) return; } cs->halted =3D 1; +#ifndef CONFIG_USER_ONLY + /* Publish WFI only after QEMU has entered the halted state. */ + riscv_cpu_handle_wfi(cs); +#endif cs->exception_index =3D EXCP_HLT; cpu_loop_exit(cs); } diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 2a7796c382..2bd198c016 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -305,6 +305,7 @@ const TCGCPUOps riscv_tcg_ops =3D { .tlb_fill =3D riscv_cpu_tlb_fill, .pointer_wrap =3D riscv_pointer_wrap, .cpu_exec_enter =3D riscv_cpu_exec_enter, + .leaving_halt =3D riscv_cpu_handle_wfi_resume, .cpu_exec_interrupt =3D riscv_cpu_exec_interrupt, .cpu_exec_reset =3D cpu_reset, .do_interrupt =3D riscv_cpu_do_interrupt, From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556859; cv=none; d=zohomail.com; s=zohoarc; b=jET7v+O3wgwmBWsrLh/IHOTphOwpZj9WFQ9+HbHPC8hMnjpPYhCqILzKonz6lAzT0qqb5epIvkFLn7JFF9Nc4+btxNJG3NCnrjp+/owQoH63pgTxqSvMcJJjyx9GifHt+eySIvJ2yKQYg0vLpTuhP/33fk11KF/S1OaqXL5KyYc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556859; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZHzllvKv2az0qWb4xIUxeTXndEiTIog+ccG34z8PSlk=; b=Nskg4lcyL7sJPE63+VNT8qNYEC2YlmGT0s2JodVl5F0x/CqUN0DldjCxI2E8jSjCP8jeJioIkHFDdR7g8b7M1dpjzVjy5BJdvA36ZJUKDCQ1lfUaQ7CMYG5Kc7CdvGT3UfqapFRt4quZ40TW8X6CTaA0NwrEaRPhantuGxZCE7c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556859688700.5496713247155; Fri, 13 Nov 2026 00:00:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCY-0002tC-PL; Fri, 13 Nov 2026 03:00:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCU-0002p0-49 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:58 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCR-0000Es-Eo for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:57 -0500 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD57CBA1973136 for ; Fri, 13 Nov 2026 07:59:54 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwg1bb425-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:53 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-30c58d35c0aso115121eec.0 for ; Thu, 12 Nov 2026 23:59:53 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=ZHzllvKv2az 0qWb4xIUxeTXndEiTIog+ccG34z8PSlk=; b=hYDLzKpedDmbF3h1K/RtgaSZuc3 y7XAyLCkrZbdQF+RYOo1jw4nBQ4li0C0LlZqxWWr8LTg5HwW2UknyzaLRUg00ECI TNEfSXJfo8i06nMQR0h7t0AR4+tZ3lNYJF20HTT7H7q5evZYbVGowFfI/6AcwLFj Bb+6mUsXg2t+Ib4Zk/FdhAO+ALty9gHF1Y8OXtLj5iN4SxJ2QZhzPq+Um6DX/jT9 pCMy0S7QEbZDBmVJQ3jZ3Yprv130zpk7IB8geiCdXarr1FmzevWQMKfMaRWNmu0I X40Lr/zz8/IZL5hBUT+RpKOLUjqlVYU0A+1FtekcK7xEH9ho66hKJR1hb3w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556793; x=1795161593; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ZHzllvKv2az0qWb4xIUxeTXndEiTIog+ccG34z8PSlk=; b=j/gLbsUlDA7GHN8OspGiuyd+qRaGJa6SAZNC83EBuAIFaSsizywD0NyZLIRRDMHFBr SOMS0aQIWy+vI6ROnS7YS3RjNIbCYR/Deer6qRZ8F3Z9yje+/ijcGdF5GDcy3qq2/2Cb XBFSDnIQ46Cu1mcnlywP0mdEMwMwZNuFjQbmtMr9bIejXmIvn3WX2mzsO84nHKy8BgF0 IZzYxVMya9LH9zxwEnn7QEWyzK6spvkDWAZLSfwPtEPVCibh+SLSuxlfAedj3OHO4gaI EBA2ea+NAwzPnokiVWw6U42kX3Qp2cTtyOhsEYQSk/HZNEOzyCr3epwVcQsCQE0W7xV4 I4jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556793; x=1795161593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ZHzllvKv2az0qWb4xIUxeTXndEiTIog+ccG34z8PSlk=; b=oAusRRlY/+j5lmmH1C1q/vDt8ALRW4XyrKIVAiS8T/SrLtubXWvMI2hHus71WWxRPj K4YN05KYjDW/TCo2c14p/NIV2BYLyQ+344p/JfrEOL8KWAkJKbYwqiJ48dus6B2gHphT atX7JVwc2/cY79dPqIPZPPlql8hpWDqeTroucGJN+cfFO2B/9NLDdk2F4IZpNsg/p8FM k8eW4PMXE0To3I6FAMZVjQXvPsRfNk6h9t95DTTPtcTyBKrykc6XMMGkC1S+JBuZYCUN 8fSO0F8vRpqUzEeMXYj4qLC1z6gTxKO7vtGG8aZEAVWj2NFzyBh4lHQveOvsmMY8N5/L 066Q== X-Gm-Message-State: APuU4Z9NrulHjEkvOBIAWu9YrLMHsHf3O+DQ7f5jxyVDbl8ADwdL4DNo cKAaRYNnUiDp4rU7MfO/l7RsaKvapQ2CVbvMM9TgpAec5g2shYFqHoKide3mM744casyCubNqjp XDc658saAV0zkwFv8G8HbNgnZuhSMBF8r3TSf1goy4cll8/6510hNsCRZIwyB/l5JdQ== X-Gm-Gg: AYBFou1asmUgvHA05Svi/BvTt4BIyM+hFm6h9gOh9IJRZhJjmC5cJgiyZPeuCmznfed lSJmWpbjY523l3Yj7zfNIdFD1fGw7KkjozL4NKng5pTQSAntNwTNy7E7/uqLdpsaLlsq1xeKcYz 5GzDkHg3E9aqjAndKXjM0rdPDKjvXGR3QJECKZVtglr+lKe22pTL407h9iC6keT4A6KGQvxOHqn jacNZgE7v5cVSzAyKKDgosrr/ujLFSWBBbV4S6MypLj4GG12N928vnWS4GM80YzACsLZWv1/hcP eD8XicZYVyEjVtOQJAe/nfhV7+Glr/aoL/Ju6fRCj4owHcM+nK04ucGU/4wpRMW0KU1LU4MPaHu p1zfUZnyYzEhDLUMrSt6XrmxeLRTlkUEtOzjxvH58/Be8jh4ci0acvDFZVKe6iQo5r1fLJj9W4L 6SR/SyvIJxp3cWrRYtr5Ib/CyaLHUlyBRYSOyaIc7Dk7aeMH97Mn2f8TZStZm+0Ibia1e4lfRRo /WaREA= X-Received: by 2002:a05:693c:3e0a:b0:377:d6e5:e642 with SMTP id 5a478bee46e88-379652e5215mr2115191eec.1.1794556792954; Thu, 12 Nov 2026 23:59:52 -0800 (PST) X-Received: by 2002:a05:693c:3e0a:b0:377:d6e5:e642 with SMTP id 5a478bee46e88-379652e5215mr2115151eec.1.1794556792288; Thu, 12 Nov 2026 23:59:52 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v16 07/10] riscv: add RPMI system suspend service Date: Fri, 13 Nov 2026 13:29:02 +0530 Message-ID: <20261113075906.715870-8-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=c6Q+0h9l c=1 sm=1 tr=0 ts=6af6c379 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=Mh6PCMENURz3S0C0lcMA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-GUID: Dms9RoFPNcm6poHWWHGlEucjg_hfwet- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX779lNDvg36If HwLOK7Aq+phg3q8BkcBj1QUs6Lsv25EbjStnclOrl0rAazZdxVT9b0xsIq64ZLGZZP33JiuuLCP N78HkuB3oFT0Irn1ZkucEug1xGUhbPViRhO0nhBY7G0pnbVof+0cxbQUulEERZ21auuph9n4qi3 7aH/BKe1mdIEz40oROdmUfDFDLEEn6s5dXr1aaJo1ST3QTrK6VxMuO4sVk5Qu03O0ZeEbMPzvtr GpflKpSI8+9iIJRevjfXvL6cXY9mnQJg7U1jVftSQ8v7n1js4FFtjpQSia/G13hG7IzULcFoJDR 3mz6fHf2iS/Ht7og5FNIHGNeiw6LMEyKwrZ66R5E275K/ASJOWLCrRUzZ+6EIibv43GfWJUqBmT x4nVo8VnjCRN/xR0LqdizCX3nbA6i9Ae7QCZpZ95MMuHC/2FsDMvRd5KWFM1vchgimn6J5e4Y/0 mHnx0KcVR+BaSvDEPmg== X-Proofpoint-ORIG-GUID: Dms9RoFPNcm6poHWWHGlEucjg_hfwet- X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX48BMRPl/Y3Z2 RaPEbWwbpD+1c6zFgikF7E3/uCkauW97K7UdMkeGt4MWQqCG4WoACQ/5etAIk0UU6m+UxY0KeDb NFlk+TaAMGCjQWW8ZRIc60TSPlF6sy4= X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 phishscore=0 impostorscore=0 malwarescore=0 clxscore=1015 spamscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556860968158500 Content-Type: text/plain; charset="utf-8" Add the RPMI System Suspend service group for RISC-V virt. The service advertises suspend-to-RAM support through librpmi, registers QEMU wakeup support, and routes the finalize callback to the generic system suspend path. Process only the accepted System Suspend event instead of polling every RPMI service group from an unrelated doorbell request. On wakeup, publish the suspend event under the BQL and defer the HSM hart resume until vCPUs are ready to run. Cancel stale wakeup work during teardown. Machine reset removes and recreates System Suspend around HSM reconstruction so the service always references the current HSM object. Reject malformed resume addresses before accepting suspend. Require the target hart's configured instruction alignment and address width, and verify that the resume PC is backed by RAM in the active system-memory map. Validate the librpmi hart index and target CPU before accessing hart state. Signed-off-by: Subrahmanya Lingappa --- hw/misc/meson.build | 2 + hw/misc/riscv_rpmi.c | 30 ++++-- hw/misc/riscv_rpmi_hsm.c | 15 +++ hw/misc/riscv_rpmi_internal.h | 8 +- hw/misc/riscv_rpmi_syssusp.c | 210 ++++++++++++++++++++++++++++++++++++++= ++++ hw/riscv/virt.c | 5 + include/hw/misc/riscv_rpmi.h | 9 ++ 7 files changed, 271 insertions(+), 8 deletions(-) create mode 100644 hw/misc/riscv_rpmi_syssusp.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 6d93cd4ab0..1dc7aa7c67 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -188,3 +188,5 @@ system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [file= s( 'riscv_rpmi_sysreset.c', 'riscv_rpmi_hsm.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) +specific_ss.add(when: 'CONFIG_RISCV_RPMI', + if_true: [files('riscv_rpmi_syssusp.c'), librpmi]) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 327753190f..ac0a0bc122 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -216,6 +216,10 @@ static const RiscvRpmiServiceOps riscv_rpmi_service_op= s[] =3D { .service_group =3D RPMI_SRVGRP_HSM, .add =3D riscv_rpmi_hsm_add, .remove =3D riscv_rpmi_hsm_remove, + }, { + .service_group =3D RPMI_SRVGRP_SYSTEM_SUSPEND, + .add =3D riscv_rpmi_syssusp_add, + .remove =3D riscv_rpmi_syssusp_remove, }, }; =20 @@ -258,6 +262,7 @@ static void riscv_rpmi_init(Object *obj) static void riscv_rpmi_reset_hold(Object *obj, ResetType type) { RiscvRpmiState *s =3D RISCV_RPMI(obj); + bool reset_syssusp =3D s->syssusp_group !=3D NULL; =20 s->doorbell =3D 0; =20 @@ -265,7 +270,13 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTy= pe type) memset(memory_region_get_ram_ptr(&s->shmem), 0, s->shmem_size); memory_region_set_dirty(&s->shmem, 0, s->shmem_size); } + if (reset_syssusp) { + riscv_rpmi_syssusp_remove(s); + } riscv_rpmi_hsm_reset(s, &error_abort); + if (reset_syssusp) { + riscv_rpmi_syssusp_add(s, &error_abort); + } } =20 static void riscv_rpmi_cleanup(RiscvRpmiState *s) @@ -309,13 +320,6 @@ bool riscv_rpmi_service_enabled(RiscvRpmiState *s, return false; } =20 -void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s) -{ - if (s->context) { - rpmi_context_process_a2p_request(s->context); - } -} - bool riscv_rpmi_context_add_group(RiscvRpmiState *s, struct rpmi_service_group *group, const char *name, @@ -340,6 +344,18 @@ void riscv_rpmi_context_remove_group(RiscvRpmiState *s, } } =20 +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s) +{ + if (s->context) { + rpmi_context_process_a2p_request(s->context); + if (s->syssusp_event_pending && s->syssusp_group) { + s->syssusp_event_pending =3D false; + rpmi_context_process_group_events(s->context, + RPMI_SRVGRP_SYSTEM_SUSPEND); + } + } +} + static bool riscv_rpmi_validate_config(RiscvRpmiState *s, Error **errp) { uint64_t queue_bytes; diff --git a/hw/misc/riscv_rpmi_hsm.c b/hw/misc/riscv_rpmi_hsm.c index 42a4f3b096..08e78e1ee7 100644 --- a/hw/misc/riscv_rpmi_hsm.c +++ b/hw/misc/riscv_rpmi_hsm.c @@ -42,6 +42,7 @@ static RiscvRpmiHsmHart *riscv_rpmi_hsm_hart(RiscvRpmiSta= te *s, =20 return &s->hsm_harts[hart_index]; } + static void riscv_rpmi_hsm_wfi(CPUState *cpu, bool entering, void *opaque) { RiscvRpmiHsmHart *hart =3D opaque; @@ -342,3 +343,17 @@ bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **e= rrp) s->hsm_group =3D group; return true; } + +void riscv_rpmi_hsm_resume(RiscvRpmiState *s, uint32_t hart_index, + uint64_t resume_addr) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(s, hart_index); + + if (!hart) { + return; + } + + hart->start_addr =3D resume_addr; + run_on_cpu(hart->cpu, riscv_rpmi_hsm_start_cpu, + RUN_ON_CPU_HOST_PTR(hart)); +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index e56dba5b1a..8739c3f041 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -20,18 +20,24 @@ extern const struct rpmi_shmem_platform_ops rpmi_shmem_qemu_ops; bool riscv_rpmi_service_enabled(RiscvRpmiState *s, enum rpmi_servicegroup_id service_group); -void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); bool riscv_rpmi_context_add_group(RiscvRpmiState *s, struct rpmi_service_group *group, const char *name, Error **errp); void riscv_rpmi_context_remove_group(RiscvRpmiState *s, struct rpmi_service_group *group); +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); + bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp); void riscv_rpmi_sysreset_remove(RiscvRpmiState *s); =20 bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp); void riscv_rpmi_hsm_remove(RiscvRpmiState *s); bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_hsm_resume(RiscvRpmiState *s, uint32_t hart_index, + uint64_t resume_addr); + +bool riscv_rpmi_syssusp_add(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_syssusp_remove(RiscvRpmiState *s); =20 #endif diff --git a/hw/misc/riscv_rpmi_syssusp.c b/hw/misc/riscv_rpmi_syssusp.c new file mode 100644 index 0000000000..d5878ce9e5 --- /dev/null +++ b/hw/misc/riscv_rpmi_syssusp.c @@ -0,0 +1,210 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI System Suspend service. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "riscv_rpmi_internal.h" +#include "system/address-spaces.h" +#include "system/memory.h" +#include "qemu/timer.h" +#include "system/cpus.h" +#include "system/runstate.h" +#include "target/riscv/cpu.h" + +static const struct rpmi_system_suspend_type riscv_rpmi_syssusp_types[] = =3D { + { + .type =3D RPMI_SYSSUSP_TYPE_SUSPEND_TO_RAM, + .attr =3D RPMI_SYSSUSP_ATTRS_FLAGS_RESUMEADDR, + }, +}; + +static enum rpmi_error riscv_rpmi_syssusp_prepare( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_system_suspend_type *syssusp_type, + rpmi_uint64_t resume_addr) +{ + RiscvRpmiState *s =3D priv; + CPUState *target_cpu; + RISCVCPU *cpu; + unsigned int alignment; + MemoryRegionSection section; + + if (!s->hart_ids || hart_index >=3D s->hart_count) { + return RPMI_ERR_INVALID_PARAM; + } + + target_cpu =3D cpu_by_arch_id(s->hart_ids[hart_index]); + if (!target_cpu) { + return RPMI_ERR_INVALID_PARAM; + } + cpu =3D RISCV_CPU(target_cpu); + alignment =3D riscv_cpu_allow_16bit_insn(&cpu->cfg, cpu->env.priv_ver, + cpu->env.misa_ext) ? 2 : 4; + + if ((resume_addr & (alignment - 1)) || + (cpu->env.misa_mxl =3D=3D MXL_RV32 && resume_addr > UINT32_MAX)) { + return RPMI_ERR_INVALID_ADDR; + } + + section =3D memory_region_find(get_system_memory(), resume_addr, 1); + if (!section.mr || !memory_region_is_ram(section.mr) || + memory_region_is_rom(section.mr)) { + if (section.mr) { + memory_region_unref(section.mr); + } + return RPMI_ERR_INVALID_ADDR; + } + memory_region_unref(section.mr); + + /* The accepted request needs one targeted event pass to finalize it. = */ + s->syssusp_event_pending =3D true; + return RPMI_SUCCESS; +} + +static rpmi_bool_t riscv_rpmi_syssusp_ready(void *priv, + rpmi_uint32_t hart_index) +{ + return true; +} + +static void riscv_rpmi_syssusp_finalize( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_system_suspend_type *syssusp_type, + rpmi_uint64_t resume_addr) +{ + qemu_system_suspend_request(); +} + +static rpmi_bool_t riscv_rpmi_syssusp_can_resume(void *priv, + rpmi_uint32_t hart_index) +{ + return runstate_check(RUN_STATE_RUNNING); +} + +static enum rpmi_error riscv_rpmi_syssusp_resume( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_system_suspend_type *syssusp_type, + rpmi_uint64_t resume_addr) +{ + RiscvRpmiState *s =3D priv; + + s->syssusp_resume_hart_index =3D hart_index; + s->syssusp_resume_addr =3D resume_addr; + s->syssusp_resume_pending =3D true; + return RPMI_SUCCESS; +} + +static const struct rpmi_syssusp_platform_ops riscv_rpmi_syssusp_ops =3D { + .system_suspend_prepare =3D riscv_rpmi_syssusp_prepare, + .system_suspend_ready =3D riscv_rpmi_syssusp_ready, + .system_suspend_finalize =3D riscv_rpmi_syssusp_finalize, + .system_suspend_can_resume =3D riscv_rpmi_syssusp_can_resume, + .system_suspend_resume =3D riscv_rpmi_syssusp_resume, +}; + +static void riscv_rpmi_wakeup_timer(void *opaque) +{ + RiscvRpmiState *s =3D opaque; + + if (s->syssusp_resume_pending) { + riscv_rpmi_hsm_resume(s, s->syssusp_resume_hart_index, + s->syssusp_resume_addr); + s->syssusp_resume_pending =3D false; + s->syssusp_resume_addr =3D 0; + } +} + +static void riscv_rpmi_wakeup_notify(Notifier *notifier, void *data) +{ + RiscvRpmiState *s =3D container_of(notifier, RiscvRpmiState, + wakeup_notifier); + + rpmi_context_process_group_events(s->context, + RPMI_SRVGRP_SYSTEM_SUSPEND); + /* + * Wakeup notifiers run before vCPUs resume. Defer the HSM kick so + * OpenSBI can leave WFI after QEMU restarts execution. + */ + timer_mod(s->wakeup_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 10= ); +} + +static bool riscv_rpmi_syssusp_create(RiscvRpmiState *s, + struct rpmi_service_group **group, + Error **errp) +{ + if (!s->hsm) { + error_setg(errp, "RPMI system suspend service requires HSM service= "); + return false; + } + + *group =3D rpmi_service_group_syssusp_create( + s->hsm, ARRAY_SIZE(riscv_rpmi_syssusp_types), + riscv_rpmi_syssusp_types, &riscv_rpmi_syssusp_ops, s); + if (!*group) { + error_setg(errp, "failed to create RPMI system suspend service gro= up"); + return false; + } + + qemu_register_wakeup_support(); + s->wakeup_timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, + riscv_rpmi_wakeup_timer, s); + s->wakeup_notifier.notify =3D riscv_rpmi_wakeup_notify; + qemu_register_wakeup_notifier(&s->wakeup_notifier); + return true; +} + +static void riscv_rpmi_syssusp_destroy(RiscvRpmiState *s) +{ + notifier_remove(&s->wakeup_notifier); + timer_free(s->wakeup_timer); + s->wakeup_timer =3D NULL; + + s->syssusp_event_pending =3D false; + s->syssusp_resume_pending =3D false; + s->syssusp_resume_hart_index =3D 0; + s->syssusp_resume_addr =3D 0; + + if (s->syssusp_group) { + rpmi_service_group_syssusp_destroy(s->syssusp_group); + s->syssusp_group =3D NULL; + } +} + +bool riscv_rpmi_syssusp_add(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group; + + if (s->syssusp_group) { + error_setg(errp, "duplicate RPMI system suspend descriptor"); + return false; + } + + if (!riscv_rpmi_syssusp_create(s, &group, errp)) { + return false; + } + + if (!riscv_rpmi_context_add_group(s, group, "system suspend", errp)) { + s->syssusp_group =3D group; + riscv_rpmi_syssusp_destroy(s); + return false; + } + + s->syssusp_group =3D group; + return true; +} + +void riscv_rpmi_syssusp_remove(RiscvRpmiState *s) +{ + if (!s->syssusp_group) { + return; + } + + riscv_rpmi_context_remove_group(s, s->syssusp_group); + riscv_rpmi_syssusp_destroy(s); +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 32aa13325e..53a31d1abd 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -490,6 +490,11 @@ static const RiscvRpmiServiceConfig virt_rpmi_services= [] =3D { .compatible =3D "riscv,rpmi-hsm", .service_group =3D RPMI_SRVGRP_HSM, }, + { + .node_name =3D "suspend", + .compatible =3D "riscv,rpmi-system-suspend", + .service_group =3D RPMI_SRVGRP_SYSTEM_SUSPEND, + }, }; =20 static uint32_t virt_rpmi_service_count(void) diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index 3a240941cd..3aaaaf68ae 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -13,6 +13,8 @@ =20 #include "exec/hwaddr.h" #include "hw/core/sysbus.h" +#include "qemu/notify.h" +#include "qemu/timer.h" #include "qom/object.h" =20 #ifdef CONFIG_LIBRPMI @@ -84,9 +86,16 @@ struct RiscvRpmiState { char *platform_info; const RiscvRpmiMachineOps *machine_ops; struct rpmi_service_group *sysreset_group; + struct rpmi_service_group *syssusp_group; struct rpmi_hsm *hsm; struct rpmi_service_group *hsm_group; RiscvRpmiHsmHart *hsm_harts; + bool syssusp_event_pending; + Notifier wakeup_notifier; + QEMUTimer *wakeup_timer; + bool syssusp_resume_pending; + uint32_t syssusp_resume_hart_index; + uint64_t syssusp_resume_addr; uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556902; cv=none; d=zohomail.com; s=zohoarc; b=Pyf1L+W2ZJgstaqPhmANevK/QrXHimKbTZIV8KHnD0uQGdHDMMD+Bsq8l8NhZy8ZO9PJS8r+19iR9cQpHt5j+j536i/4TucLUqoQdQyr9R91vMBauDoGVfnWBuAZ977PuBc4EHjzv578O/IUv6TkZQQEBB9+2vfuFKbYgMvnnIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556902; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NtmrcfkoEnFgORxvLVobnBrxdwX1pUc2LacJatwTyNw=; b=QbPoNAM1v6UHM8k8LbURxOwz93szPPdLydFIum89dlkjqlv60t6Yatzgyy09kD2M6XK+FKy6+8r6tORpTSQ9gUiz4A4YZP84vXtMjANEEu+gr0+Ws9tZJYF9xwPBbYWskAhw3F239ylHVn26rHXjNpyeXh3L6kIYLfgviLVyzK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179455690258546.41935283665316; Fri, 13 Nov 2026 00:01:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCb-00033z-Di; Fri, 13 Nov 2026 03:00:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCV-0002pR-Uc for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:59 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCT-0000FS-Sa for qemu-devel@nongnu.org; Fri, 13 Nov 2026 02:59:59 -0500 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD56wmD3556936 for ; Fri, 13 Nov 2026 07:59:56 GMT Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwkfdj7ek-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 07:59:56 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-36f7142accfso9464eec.3 for ; Thu, 12 Nov 2026 23:59:56 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=NtmrcfkoEnF gORxvLVobnBrxdwX1pUc2LacJatwTyNw=; b=bz/13gwGnLG4kHP0jmwIoFVEVA1 Sc6oFvWwJphCgZBO7zymsmM6jpnEIH1lOprKS570rrynUwhiKMbcFY1i5cMrvbZv vfqaEebl1xiOQN1Ek/uxG23jYEavnDLJny73zavXYK7vQcMr9bva3SELh61eel2m B541T6vYnWpDyVqCJMiki37MtK2VSo/jK+XIwiSmXv9GpEWt+TIuf0aw7Ms/EqNL Im8ha7VY/+Dsn3mK3cJX5jCgguEDXfI34zQP2LUPI+AgbL2n+Wm6GlNbqT390WPX GDibjmQlDz23vwRqajNh5D9Hq6m/s9ZYPtjvKWAJbP3+nmcQfWfZyj2IqcQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556796; x=1795161596; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=NtmrcfkoEnFgORxvLVobnBrxdwX1pUc2LacJatwTyNw=; b=K7JWyKonb9bzwOcpBf2nhSOJCCib+qlJHluR3AGY54+JSP40sGUZEzm6T1tKwnKgfz E1MTq1VyZaoMxgnxgXqjyOYFY9uMsZiPVzU6pdUwOUQoXeDM1ROxacT4Fj08zKjAS0Pr WBErBewZn9KCRShLC+Mft+Id335axnxf6B6K725WCf+Eij/LCFiNx/iDMAu8suHeppOp qmds0Hq/QLl+tjCqVC1EfGXh7hxj+Fz4EhUQR3S0QyrpKbH9CNsXpTisVx306wCLaQte +Y1XTOk2DocJ7nHNhlDJ5fadiP+NMbDh8F0AsjI6k1r17eTq2eI7IpqMWYp+uMfGKmn2 Fwwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556796; x=1795161596; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=NtmrcfkoEnFgORxvLVobnBrxdwX1pUc2LacJatwTyNw=; b=s+hSmAbANYboSUPMpw6eADmC/3+TzuTbYXefaUogXGofsii2VWClGDWhyBP0ARR4fh U/AkpKFhAo3g5QKPowxZXfXToYF3zH/8IuuvG1A4YDsDJ9fk4wDwFP2S00IsSw3IbBJW 0sewNQkMhyexfOFKR4EsITmjduyZen+ET8o5WO5DC7j5efPP6xoFIQ8cjEUm2ocGa5+g kHpsXIx7iElKH0dtxkHo1FK6jH3WwKrG9cpYX7n7N/IhPhiGa1u25e6VIVZ2BXD+z45T IImCDlxFCRn+bD/Qetf3h0LpJl1VmcOMeylhbI5NbL47MyavHLvyIrcv5VlD/bQpdL2F qFmA== X-Gm-Message-State: APuU4Z9SNV+zlEC6A/jd6yeqizycEy5NkotERHAFSOW4wMLUJIPWejtA 42882d4RwAvoIYbNcItmhnbGn8rHXO+C+OJQZ5KUVM0GOP3OL51xkURHwVSWua0Hx6dHcZjL/B8 NKM19CtVjyo9e0XkXZLRd8yb5ip8KhArWwWI47/YZ+nePv7baeB7hNjub9KYc13dK3g== X-Gm-Gg: AYBFou2mfVG0ke0yqtqbPYHtoSeafmL8N75AGQvu7VC1VuWpnY/fnhQo1sVwGysjADq CaGWDZb0puHZCVVAzfW/UdWRwfaPOP6GR0HhWRuEnBhM34FNK/4Uxn8N5PC3Gx01NMF9aoM1xxw 4e/Y/YfbVXpo2WXplsKk+XuHgXfp5sF5qhv+ON5qjDmpoj0y3xM+D2U42Dcgpq/pDM34j1W+M5b LUAZGZqKD1ergduXf4PKDBS1o/rWXPT0wiarpLGSQRofuiDjWQjmQd9pD4N/bdrWjid3It7gk5Y WRJqGv9CYeCoToafO4l3Xn1/ltCrUGpSsub9CLJ719w5kBdh57GuRhAEkFFTJh/VSvXq8Y1yBSx Vw+UghwAPaI11BMTJG0qFiad4aji6S5cMatTksWfYgmK6EjFkQREMF3tfuq8qA/lzwXVm8UOXp3 HHj896POdMdhCG7LrCXzMCUf3C1BPaX3zTun9c/c1LEze/cMtnmjXEIdvr6IpyFdvZmC4AqrXNi hSS/ag= X-Received: by 2002:a05:7300:6da8:b0:36a:e7a:e89 with SMTP id 5a478bee46e88-379659c6815mr3069714eec.2.1794556795413; Thu, 12 Nov 2026 23:59:55 -0800 (PST) X-Received: by 2002:a05:7300:6da8:b0:36a:e7a:e89 with SMTP id 5a478bee46e88-379659c6815mr3069655eec.2.1794556794766; Thu, 12 Nov 2026 23:59:54 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Pierrick Bouvier Subject: [PATCH v16 08/10] docs/system/riscv: document initial virt RPMI support Date: Fri, 13 Nov 2026 13:29:03 +0530 Message-ID: <20261113075906.715870-9-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX3U7DYjhJc7yz VglJJexw/D1jWhad2qn8Gl7RuL1f5K0t94/8oL0nkWCjdMUoZ9B+YlZVOtbKIgA6g/1WjlM6A14 sm2wnysrkOtmwI3WvdxPVTz9yz2q9CE= X-Proofpoint-ORIG-GUID: tthHE_pUniv6_tkCfytdV150sSKR0jkD X-Authority-Analysis: v=2.4 cv=DoTDa2/+ c=1 sm=1 tr=0 ts=6af6c37c cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=NEAV23lmAAAA:8 a=V1jnuoLLAAAA:20 a=EUspDBNiAAAA:8 a=qErgiAeUNlDKfKC9Rl0A:9 a=PxkB5W3o20Ba91AHUih5:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfXxOgqz37qZyfN h2fqopXfEkrA+XTFDocj3N2hnyMo3i7scnJB1wu7LKdPjqlsTZZVahWine31eCz+BuhWK4DMbfB EziFVCdt6BBs2avtc06+ySBSTcGV8g68TdrZtvPMWQuQZNMlBTBBArD2MqBLryGvZUblQkN7tV2 821g/MUZiQ8Fms/iyGEL03lUM4CAWAna8juRETWDSmjuiHpN/qDUIqFFiTUp9COk9QVCFZFt5+7 OI+W1y8E9NlNlenTlyy+DV8caL3khNiQ1KpJA85AKQjY/GwJcuoNPMBZ1llvY6Na0bNXihkPidF V/39uGzlIXSpXi3JqBBWQxXTcPe/pn8o/BQ+Pa7lGdMYavb+1yB55gNXj4YeyKm9QRgmgeKQFdE XtACrUeqlWJewxKj5IPj6G4N72qpebGk1/4s0iScLECfs42w7XacA/7qpnS4J98YC0fIpz7yjEX KHRvt5TdQq5v517TLSw== X-Proofpoint-GUID: tthHE_pUniv6_tkCfytdV150sSKR0jkD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 impostorscore=0 suspectscore=0 phishscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556903679158500 Content-Type: text/plain; charset="utf-8" Document the opt-in virt RPMI transport and the initial HSM, system reset, and system suspend service groups. Give a pinned OpenSBI source build and the thorough guest-test command. Kernel and rootfs use pinned downloadable assets unless overridden. Firmware still needs explicit provisioning; distinguish skipped tests from a completed guest validation run. Signed-off-by: Subrahmanya Lingappa --- docs/system/riscv/virt.rst | 99 ++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 99 insertions(+) diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index 3c87246891..5b48ca0ccb 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -149,6 +149,105 @@ The following machine-specific options are supported: =20 Enables the riscv-iommu-sys platform device. Defaults to 'off'. =20 +- rpmi=3D[on|off] + + Enables the RISC-V RPMI shared-memory transport. This option defaults to + "off", is TCG-only, and is available only when QEMU is built with librpmi + support. This support targets the RISC-V Platform Management Interface + (RPMI) Specification v1.0 Ratified (`RPMI v1.0 specification`_). The ini= tial + ``virt`` implementation exposes RPMI system reset, system suspend, and H= SM + service groups. System reset can request shutdown or cold reboot through + RPMI. HSM uses the ``virt`` hart IDs and supports hart discovery, status, + start, stop, and suspend commands. System suspend uses QEMU's suspend and + wakeup path. Migration is currently blocked while RPMI transport and ser= vice + VMState support is being designed. + + The build dependency is provided by `librpmi`_. QEMU requires librpmi 1.= 0.0 + or newer. If the host distribution does not provide a librpmi development + package, build and install it from the upstream source tree so that + ``pkg-config`` can find ``librpmi.pc``: + + .. code-block:: bash + + $ git clone https://github.com/riscv-software-src/librpmi.git + $ cd librpmi + $ make + $ make install I=3D/usr/local + $ export PKG_CONFIG_PATH=3D/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH + $ pkg-config --modversion librpmi + + The librpmi repository can also generate installable ``librpmi-dev`` Deb= ian + packages with ``make deb-pkg`` and ``librpmi-devel`` RPM packages with + ``make rpm-pkg``. After installing librpmi, configure QEMU with + ``--enable-librpmi`` or ``-Dlibrpmi=3Denabled``. + +.. _RPMI v1.0 specification: https://github.com/riscv-non-isa/riscv-rpmi/r= eleases/download/v1.0/riscv-rpmi.pdf +.. _librpmi: https://github.com/riscv-software-src/librpmi + +RPMI qtest coverage +------------------- + +QEMU includes qtest coverage for the RPMI transport and the initial service +groups in ``tests/qtest/riscv-rpmi-test.c``. To run the qtest from a build +configured with librpmi support and the ``riscv64-softmmu`` target: + +.. code-block:: bash + + $ meson test -C build qemu:qtest-riscv64/riscv-rpmi-test + +The qtest covers Base service discovery, System Reset, HSM, System Suspend, +negative transport cases, reset behavior, and migration blocking while RPMI +VMState support is being designed. + +RPMI firmware and guest smoke +----------------------------- + +A firmware-level RPMI smoke test can be run with OpenSBI, a Linux kernel, = and a +RISC-V disk image: + +.. code-block:: bash + + $ qemu-system-riscv64 \ + -machine virt,rpmi=3Don \ + -cpu rv64 -smp 4 -m 4G -nographic \ + -bios /path/to/fw_jump.bin \ + -kernel /path/to/Image \ + -append "root=3D/dev/vda rw console=3DttyS0 earlycon=3Dsbi" \ + -drive file=3D/path/to/rootfs.img,format=3Draw,if=3Dvirtio,snapshot= =3Don + +The OpenSBI banner should report RPMI-backed HSM and system suspend suppor= t. +After the guest reaches a shell, normal guest reboot/poweroff commands exe= rcise +the RPMI system reset path. + +The functional RPMI test requires an OpenSBI ``fw_jump.bin`` built with the +RPMI mailbox, HSM, reset and suspend drivers. For example, the following +upstream OpenSBI revision provides them: + +.. code-block:: bash + + $ git clone https://github.com/riscv-software-src/opensbi.git + $ git -C opensbi checkout 2aed4ec24f5d85312e528d2a40d7009800d55aeb + $ make -C opensbi PLATFORM=3Dgeneric CROSS_COMPILE=3Driscv64-linux-gnu- + $ QEMU_TEST_RPMI_OPENSBI=3D"$PWD/opensbi/build/platform/generic/firmware= /fw_jump.bin" \ + meson test -C build --suite qemu:func-riscv64-thorough \ + qemu:func-riscv64-rpmi_virt + +Kernel and rootfs images use pinned downloadable TuxRun assets. Set +``QEMU_TEST_RPMI_KERNEL`` and ``QEMU_TEST_RPMI_ROOTFS`` to override them. +Firmware is not downloaded automatically; without +``QEMU_TEST_RPMI_OPENSBI`` the six guest tests skip. A validation run must +provide firmware and check that all six tests pass, not merely that Meson +exits successfully. + +RPMI device tree policy +----------------------- + +RPMI is currently described through FDT only; no ACPI representation is em= itted +for the RPMI transport or service groups. The ``virt`` machine uses the +``riscv,rpmi-shmem-mbox`` shared-memory mailbox node plus sibling service = nodes +with ``riscv,rpmi-*`` compatible strings. Each service node references the +mailbox with an ``mboxes`` property containing the RPMI service-group ID. + Running Linux kernel -------------------- From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556857; cv=none; d=zohomail.com; s=zohoarc; b=ahrvGdFD1rUaUyY450SeFOA+uOEtJPojBTtMSmavvzDkJ3CfeS5e627hG66kuBwrY0LGhVq0qxSFl+S4TlX/9abHRb7x42xqXPnCILpPUwkgVHKvt3R81DWuArfxITV8J3Dx3adcHIPKdVoOm7FRnqohnPyAzc2YbGrERccVKWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556857; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ta5uboKJqMJrgc6I41HxqEcAKz50S2khyAe74BzXhuo=; b=V7yR0WgtZSRoOkF4Fgps3latJBaeSlYldcftkQ0LJs79mPgGX9SRokAqT4GOqrO1OAOtUN7O0OyzkMBUphhLyrwPi6kK1MJpE40BIkizZjry+tAhU2njDWxOCROXsmoP9wb+AocCggFYEtSl9KTENvtLvQfxqZsyCx45bbGS4Yw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556857287958.465275642982; Fri, 13 Nov 2026 00:00:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmCg-0003F8-4f; Fri, 13 Nov 2026 03:00:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCd-00037o-70 for qemu-devel@nongnu.org; Fri, 13 Nov 2026 03:00:07 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCY-0000GK-RV for qemu-devel@nongnu.org; Fri, 13 Nov 2026 03:00:06 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD5717a367205 for ; Fri, 13 Nov 2026 08:00:01 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwbx344rh-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 08:00:01 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-33bf1d17dfeso93279eec.2 for ; Fri, 13 Nov 2026 00:00:01 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2026 23:59:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=ta5uboKJqMJ rgc6I41HxqEcAKz50S2khyAe74BzXhuo=; b=T+ucqPUfg0Y/Su7uVrgaeTGQEh0 LVTVKs2Ee0pjAmRO098qToKkAIJDrSX7AnlGnZmKdKAskBSDW6Z5orwAaL5nilVO ffBhrpBgoNjk1Y1WnmVju7/XKFnWuzxPVPrGBJews49I5emee3BSyECWxs/7qFPO 6yEZE3KU2hGry1dKU7gIQ7bzd4lts8c36yyzYG4NeKw/TYp2XpTp8BIOYBQd99e3 v4I+Q0NwKiFlZTQj0amI+wFfxKxUxR7GbPh795duRfTElfhjXhy1hw6j3OoiwTol +Xcif5xRQDv6osHrbNbcr8C3jIiL2s0vZ/1pbEkXzMWPmTbc8BkDLMi3nHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556800; x=1795161600; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ta5uboKJqMJrgc6I41HxqEcAKz50S2khyAe74BzXhuo=; b=duBdDIj/kxFi4XEaeBRaAqf7dd3A4Rw0F8Op4IPaNTj2CL77+31aLWDlQFiAWpwleW PRqJ2vIky6OxrJUqYUk3exL1qDHjCTtBklJqUVd4lR9xIkNW19styTF5e5vn9JARR6c3 Gc5DRI9yZ9NmQxZFTONAyBkvbFEdlVC+CddevPBYY8KIqddmZG44wIuyGTCoE/9SB3mb oTA9S+cF2AVFTc6jS0RDtIJP1k2BL22rYBCTHwp3zwQ/yQB1TN76wDESN4QLo75Aw5du fxcU/nUPnHgHfwBt8CJX+VNpxSrT9bGwIUtiwu9iBzfJsirHQWK3brGq6uDYnjA6JtKv zxdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556800; x=1795161600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ta5uboKJqMJrgc6I41HxqEcAKz50S2khyAe74BzXhuo=; b=Rn8RzXrkX0Wot6EInTEC50WA+hqufTIZRnDpCpNsB+DkBsQtnq+Q5038uqya/L0Hri PQhER4giYxU+D6lHmPETXQX04bv80yU4cHZaRxv5Rs1KW3Hci86Ne/RIeN6b4qqp9Axk v2U4GusQaw88amJaEoOhYOcPKHZCszZpHDgcGZ+3T+4n01oun9u8cfoedj+piYSMtG/e /rYmO5rgGcBGRx2iwv/Rb9awj0FYOjcfGUv4Ov7Jq+fT75OEFXXqDLcOhJFIkzOYgqVk Oq6u++eCDUjTDmV1dUwbbHfb9qsoFm/w06+vraSsQmaMp5+xUoAdknppt8N1xP/hv1ce QP7Q== X-Gm-Message-State: APuU4Z/FeEXxQjIByVxHuwEV0JljQjSJMO+teDhHQ/tP/9FkZlXmNznQ 0S+EUyy0P71pcLTvpF+mBrhyspaxRxHUH6KzfIcYFEIR9o1SBsLgL44w8JB3GuvvVDWj2b7XWJM 4HYd6Eo6nPg0hkws2sneaY3ksoPpvicjCvWKXHLat0LEjOVDGwJM0eVNqry8AwYOHmg== X-Gm-Gg: AYBFou1Ak6IFm1RPbzanZQyB6JGsU9pm0ubd3uQORBxlEmwfPNuKoafqAYSXwcNAA15 ovU9MRn3XDRsuxumMFNvCLLuXwBKJTyLXiEL6qrWA/tHqCBAlEUNS7ZdQNgtQZiBkV3kcBjeOZw 4+gDrfnYdbNQ2+klzL9ZJJabFID2Wq8kBjs5WmG8q87ycjNW501h+xVTDcStXGQBL+pfKdfIf37 PrPZRe9aGsDV/+RDJ0sW9oYiDmZxx87Sgaf1Ddm5ijj3DJx+SmcGb2/H8s+hKPc0+9dAP2eYep3 4ZCaCN+4Aqm+L1WqEl7AUkWhKbYJ319EUN9hHTUGrlFQihlXUZ3uBIX0PEtSlHyqy4z2ARDlrtf X5PhxdU5bkG6ME3aUzaov/LIeaCBwIoaD2S1lqTfptMdfARXynsNNSbpFQRARM+2QeAzQw6nMYg CZXX1lEYv8X83s7EXLoATv3YELs8x2uMwL7Tt2LnwieFhUvBYifaaJZF3Ox9vM4Xu4Pecqzyx7+ LD38ts= X-Received: by 2002:a05:693c:83cf:20b0:376:6ba5:6090 with SMTP id 5a478bee46e88-37964e03109mr2915700eec.1.1794556800035; Fri, 13 Nov 2026 00:00:00 -0800 (PST) X-Received: by 2002:a05:693c:83cf:20b0:376:6ba5:6090 with SMTP id 5a478bee46e88-37964e03109mr2915659eec.1.1794556799265; Thu, 12 Nov 2026 23:59:59 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v16 09/10] tests/qtest: cover initial RISC-V RPMI services Date: Fri, 13 Nov 2026 13:29:04 +0530 Message-ID: <20261113075906.715870-10-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=S+5MU4sP c=1 sm=1 tr=0 ts=6af6c381 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=aNGTY8cIad57_OF_GeEA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfXw/+1f7ogoY4n eYcujbKAkJLJyVIwSmLVS5siBUDDzhHmmvWCKVPGZ+3OccH4bQ+LxpeLdA3SZ602Dx/3p5yUHDG z6HH/9QNjWbB1Z11zV5R0RjBc1mK7VaT8RLDbA2jHA0EhFuupwzT/nzQnVQaY59FvG04ONaDvd1 /Ume4zynSmNyCHQeEfPWRsh6hnGIu9sDjQ+tHMhlGLtBgJzB8MhsysHTuOh1yB+vPSo1RBGnNEU PtudElHPkC6uXBGXhPRwFU7qSkZHPPP3L7RSPzOw92g8z/NGTvY43AweLs//MCTmTGkcRNNqbNh qYkX1L3ZMMCRMrEdOrnwfNcHPup4aR25o3U4fGlcKBDCvUOgR8CkScrFpQ+CxQ8VJbw7h6xD2fA IfHlCJqNySAPHhRzORQ7aqhTPx5py3rkcn3IdqXm3II4dsuJsexRC20V0laWZty2rrkIVEtrTnR oRDdG35OxDyK7YHlHnQ== X-Proofpoint-ORIG-GUID: 3AV6ukh1KK6qNfD2bApcXVGrB9dmSJmV X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX0wvAyfl199JV 3VzC+fbd9GlA5aGl0zvi0RwfdCtlkssqn8Ar2dKtS8wbFOmLx6G7lzxr+fgdmnHEnLT5UpSyIXV eB8a491AbcDvUCVlYEtnAYOBwS/CVJ4= X-Proofpoint-GUID: 3AV6ukh1KK6qNfD2bApcXVGrB9dmSJmV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 clxscore=1015 phishscore=0 malwarescore=0 adultscore=0 spamscore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.168.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0a-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556859370158500 Content-Type: text/plain; charset="utf-8" Add qtests for the RPMI transport plus Base, system reset, HSM, and system suspend service groups. The qtest accelerator does not execute a target hart to WFI, so check that stop and suspend remain pending rather than treating the request as immediately complete. Verify that HART_START is denied while stop is pending and that machine reset returns pending HSM state to STARTED before accepting fresh stop and suspend requests. Check System Suspend resume-address rejection without a suspend event or runstate change. Cover instruction alignment with and without compressed instructions, MMIO and unmapped addresses, RAM-backed addresses, RV32 width rejection for mapped RAM above 4 GiB, and recovery after rejection/reset. Check that an invalid System Suspend hart ID is rejected without a suspend event. Check the enlarged virt queue ranges in the DT and exercise queue-boundary rejection and wraparound at the last data slot. Clear active MISA.C through the qtest CSR interface and check resume-address alignment. Remove dumped DTBs before QEMU exit status checks or content assertions can abort the test. Signed-off-by: Subrahmanya Lingappa --- MAINTAINERS | 1 + tests/qtest/meson.build | 3 + tests/qtest/riscv-rpmi-test.c | 816 ++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 820 insertions(+) create mode 100644 tests/qtest/riscv-rpmi-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 7f7764b03b..5e56f4eec5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -381,6 +381,7 @@ F: hw/riscv/ F: hw/intc/riscv* F: hw/misc/riscv_rpmi* F: include/hw/misc/riscv_rpmi.h +F: tests/qtest/riscv-rpmi-test.c F: include/hw/char/riscv_htif.h F: include/hw/riscv/ F: common-user/host/riscv* diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index ff4bf9528a..207766bcf6 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -317,6 +317,8 @@ qtests_riscv32 =3D \ =20 qtests_riscv64 =3D ['riscv-csr-test'] + \ (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RISCV_RPMI') ? + ['riscv-rpmi-test'] : []) + \ (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and config_all_devices.has_key('CONFIG_RISCV_IOMMU') ? ['iommu-riscv-test'] : []) + \ @@ -442,6 +444,7 @@ qtests =3D { 'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c', 'pnv-xive2-nvpg_bar.c'), 'qos-test': [chardev, io, qos_test_ss.apply({}).sources()], + 'riscv-rpmi-test': [files('riscv-rpmi-test.c'), fdt], 'tpm-crb-swtpm-test': [io, tpmemu_files], 'tpm-crb-test': [io, tpmemu_files], 'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'], diff --git a/tests/qtest/riscv-rpmi-test.c b/tests/qtest/riscv-rpmi-test.c new file mode 100644 index 0000000000..0831322e24 --- /dev/null +++ b/tests/qtest/riscv-rpmi-test.c @@ -0,0 +1,816 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * QTests for RISC-V RPMI devices. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include +#include +#include "libqtest.h" +#include "qobject/qdict.h" + +#define RPMI_SHMEM_BASE 0x10200000ULL +#define RPMI_DOORBELL_BASE 0x10230000ULL +#define RPMI_SLOT_SIZE 64 +#define RPMI_QUEUE_SIZE 0x7800 +#define RPMI_QUEUE_DATA_SLOTS (RPMI_QUEUE_SIZE / RPMI_SLOT_SIZE - 2) + +#define RPMI_A2P_HEAD RPMI_SHMEM_BASE +#define RPMI_A2P_TAIL (RPMI_SHMEM_BASE + RPMI_SLOT_SIZE) +#define RPMI_A2P_SLOT0 (RPMI_SHMEM_BASE + 2 * RPMI_SLOT_SIZE) + +#define RPMI_SRVGRP_BASE 0x0001 +#define RPMI_SRVGRP_SYSTEM_RESET 0x0003 +#define RPMI_SRVGRP_SYSTEM_SUSPEND 0x0004 +#define RPMI_SRVGRP_HSM 0x0005 +#define RPMI_BASE_SRV_GET_PLATFORM_INFO 0x05 +#define RPMI_BASE_SRV_PROBE_SERVICE_GROUP 0x06 +#define RPMI_SYSRST_SRV_GET_ATTRIBUTES 0x02 +#define RPMI_SYSRST_SRV_SYSTEM_RESET 0x03 +#define RPMI_HSM_SRV_GET_HART_STATUS 0x02 +#define RPMI_HSM_SRV_GET_HART_LIST 0x03 +#define RPMI_HSM_SRV_GET_SUSPEND_TYPES 0x04 +#define RPMI_HSM_SRV_GET_SUSPEND_INFO 0x05 +#define RPMI_HSM_SRV_HART_START 0x06 +#define RPMI_HSM_SRV_HART_STOP 0x07 +#define RPMI_HSM_SRV_HART_SUSPEND 0x08 +#define RPMI_SYSSUSP_SRV_GET_ATTRIBUTES 0x02 +#define RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND 0x03 +#define RPMI_MSG_NORMAL_REQUEST 0x00 +#define RPMI_MSG_POSTED_REQUEST 0x01 +#define RPMI_MSG_ACKNOWLEDGEMENT 0x02 +#define RPMI_SYSRST_TYPE_SHUTDOWN 0x00 +#define RPMI_SYSRST_TYPE_COLD_REBOOT 0x01 +#define RPMI_SYSRST_TYPE_INVALID 0x03 +#define RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE 1 +#define RPMI_TOKEN 0x55aa +#define RPMI_ERR_NOTSUPP 0xfffffffeU +#define RPMI_ERR_INVALID_PARAM 0xfffffffdU +#define RPMI_ERR_INVALID_ADDR 0xfffffffbU +#define RPMI_ERR_DENIED 0xfffffffcU +#define RPMI_HSM_HART_STATE_STARTED 0x00 +#define RPMI_HSM_HART_STATE_STOPPED 0x01 +#define RPMI_HSM_HART_STATE_STOP_PENDING 0x03 +#define RPMI_HSM_HART_STATE_SUSPENDED 0x04 +#define RPMI_HSM_HART_STATE_SUSPEND_PENDING 0x05 +#define RPMI_HSM_TEST_START_ADDR 0x80000000ULL +#define RPMI_HSM_TEST_RESUME_ADDR 0x80001000ULL + +#define RPMI_P2A_ACK_BASE (RPMI_SHMEM_BASE + RPMI_QUEUE_SIZE) +#define RPMI_P2A_ACK_HEAD RPMI_P2A_ACK_BASE +#define RPMI_P2A_ACK_TAIL (RPMI_P2A_ACK_BASE + RPMI_SLOT_SIZE) + +static uint64_t rpmi_response_base; + +static uint64_t rpmi_queue_slot(uint64_t queue_base, uint32_t index) +{ + return queue_base + (index + 2) * RPMI_SLOT_SIZE; +} + +static void rpmi_send_request(QTestState *qts, uint16_t service_group, + uint8_t service_id, uint8_t request_type, + const uint32_t *data, size_t data_words) +{ + uint32_t tail =3D qtest_readl(qts, RPMI_A2P_TAIL); + uint64_t slot =3D rpmi_queue_slot(RPMI_SHMEM_BASE, tail); + size_t i; + + qtest_writew(qts, slot, service_group); + qtest_writeb(qts, slot + 2, service_id); + qtest_writeb(qts, slot + 3, request_type); + qtest_writew(qts, slot + 4, data_words * sizeof(*data)); + qtest_writew(qts, slot + 6, RPMI_TOKEN); + + for (i =3D 0; i < data_words; i++) { + qtest_writel(qts, slot + 8 + i * sizeof(*data), data[i]); + } + + g_test_message( + "RPMI_A2P_REQ shmem=3D0x%016" PRIx64 " doorbell=3D0x%016" PRIx64 + " group=3D0x%04x service=3D0x%02x type=3D0x%02x data_len=3D%zu" + " token=3D0x%04x a2p_tail=3D%u slot=3D0x%016" PRIx64, + (uint64_t)RPMI_SHMEM_BASE, (uint64_t)RPMI_DOORBELL_BASE, + service_group, service_id, request_type, data_words * sizeof(*data= ), + RPMI_TOKEN, tail, slot); + + qtest_writel(qts, RPMI_A2P_TAIL, (tail + 1) % RPMI_QUEUE_DATA_SLOTS); + qtest_writel(qts, RPMI_DOORBELL_BASE, 1); +} + +static uint32_t rpmi_response_word(QTestState *qts, unsigned int word) +{ + return qtest_readl(qts, rpmi_response_base + 8 + word * sizeof(uint32_= t)); +} + +static void test_rpmi_virt_fdt_service_nodes(void) +{ + static const struct { + const char *name; + uint32_t service_group; + } services[] =3D { + { "sysreset", RPMI_SRVGRP_SYSTEM_RESET }, + { "hsm", RPMI_SRVGRP_HSM }, + { "suspend", RPMI_SRVGRP_SYSTEM_SUSPEND }, + }; + g_autofree char *dtb_path =3D NULL; + g_autofree char *dtb =3D NULL; + gsize dtb_size; + const fdt32_t *prop; + int mailbox_offset; + int phandle_len; + uint32_t mailbox_phandle; + QDict *response; + bool read_ok; + int remove_result; + QTestState *qts; + + dtb_path =3D g_strdup_printf("%s/riscv-rpmi-fdt-%u.dtb", + g_get_tmp_dir(), (unsigned)getpid()); + qts =3D qtest_init("-machine virt,rpmi=3Don -display none -S"); + response =3D qtest_qmp(qts, "{ 'execute': 'dumpdtb', 'arguments': " + "{ 'filename': %s } }", dtb_path); + + read_ok =3D g_file_get_contents(dtb_path, &dtb, &dtb_size, NULL); + remove_result =3D g_remove(dtb_path); + qtest_quit(qts); + g_assert_true(qdict_haskey(response, "return")); + qobject_unref(response); + g_assert_true(read_ok); + g_assert_cmpint(remove_result, =3D=3D, 0); + g_assert_cmpint(fdt_check_header(dtb), =3D=3D, 0); + + mailbox_offset =3D fdt_path_offset(dtb, "/soc/mailbox@10200000"); + g_assert_cmpint(mailbox_offset, >=3D, 0); + prop =3D fdt_getprop(dtb, mailbox_offset, "reg", &phandle_len); + g_assert_nonnull(prop); + g_assert_cmpint(phandle_len, >=3D, 8 * sizeof(*prop)); + for (unsigned int queue =3D 0; queue < 2; queue++) { + g_assert_cmphex(fdt32_to_cpu(prop[4 * queue + 1]), =3D=3D, + RPMI_SHMEM_BASE + queue * RPMI_QUEUE_SIZE); + g_assert_cmphex(fdt32_to_cpu(prop[4 * queue + 3]), =3D=3D, RPMI_QU= EUE_SIZE); + } + prop =3D fdt_getprop(dtb, mailbox_offset, "phandle", &phandle_len); + g_assert_nonnull(prop); + g_assert_cmpint(phandle_len, =3D=3D, sizeof(*prop)); + mailbox_phandle =3D fdt32_to_cpu(*prop); + + for (size_t i =3D 0; i < ARRAY_SIZE(services); i++) { + g_autofree char *service_path =3D + g_strdup_printf("/soc/%s", services[i].name); + int service_offset =3D fdt_path_offset(dtb, service_path); + int child_offset =3D fdt_subnode_offset(dtb, mailbox_offset, + services[i].name); + int mboxes_len; + + g_assert_cmpint(service_offset, >=3D, 0); + g_assert_cmpint(child_offset, =3D=3D, -FDT_ERR_NOTFOUND); + prop =3D fdt_getprop(dtb, service_offset, "mboxes", &mboxes_len); + g_assert_nonnull(prop); + g_assert_cmpint(mboxes_len, =3D=3D, 2 * sizeof(*prop)); + g_assert_cmphex(fdt32_to_cpu(prop[0]), =3D=3D, mailbox_phandle); + g_assert_cmphex(fdt32_to_cpu(prop[1]), =3D=3D, + services[i].service_group); + } + +} + +static void test_rpmi_doorbell_unsupported_values(void) +{ + const uint32_t values[] =3D { 0, 2, UINT32_MAX }; + QTestState *qts =3D qtest_init("-machine virt,rpmi=3Don"); + + qtest_writew(qts, RPMI_A2P_SLOT0, RPMI_SRVGRP_BASE); + qtest_writeb(qts, RPMI_A2P_SLOT0 + 2, RPMI_BASE_SRV_GET_PLATFORM_INFO); + qtest_writew(qts, RPMI_A2P_SLOT0 + 6, RPMI_TOKEN); + qtest_writel(qts, RPMI_A2P_TAIL, 1); + for (size_t i =3D 0; i < ARRAY_SIZE(values); i++) { + qtest_writel(qts, RPMI_DOORBELL_BASE, values[i]); + g_assert_cmphex(qtest_readl(qts, RPMI_DOORBELL_BASE), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + } + qtest_writel(qts, RPMI_DOORBELL_BASE, 1); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_HEAD), =3D=3D, 1); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 1); + qtest_system_reset(qts); + g_assert_cmphex(qtest_readl(qts, RPMI_DOORBELL_BASE), =3D=3D, 0); + qtest_quit(qts); +} + +static void rpmi_expect_ack(QTestState *qts, uint16_t service_group, + uint8_t service_id, uint16_t data_len) +{ + uint32_t head =3D qtest_readl(qts, RPMI_P2A_ACK_HEAD); + uint32_t tail =3D qtest_readl(qts, RPMI_P2A_ACK_TAIL); + + g_assert_cmphex(tail, !=3D, head); + rpmi_response_base =3D rpmi_queue_slot(RPMI_P2A_ACK_BASE, head); + g_assert_cmphex(qtest_readw(qts, rpmi_response_base), =3D=3D, service_= group); + g_assert_cmphex(qtest_readb(qts, rpmi_response_base + 2), =3D=3D, + service_id); + g_assert_cmphex(qtest_readb(qts, rpmi_response_base + 3), =3D=3D, + RPMI_MSG_ACKNOWLEDGEMENT); + g_assert_cmphex(qtest_readw(qts, rpmi_response_base + 4), =3D=3D, data= _len); + g_assert_cmphex(qtest_readw(qts, rpmi_response_base + 6), =3D=3D, + RPMI_TOKEN); + g_test_message( + "RPMI_P2A_ACK shmem=3D0x%016" PRIx64 + " group=3D0x%04x service=3D0x%02x type=3D0x%02x data_len=3D%u" + " token=3D0x%04x p2a_head=3D%u slot=3D0x%016" PRIx64 + " status=3D0x%08x", + (uint64_t)RPMI_SHMEM_BASE, service_group, service_id, + RPMI_MSG_ACKNOWLEDGEMENT, data_len, RPMI_TOKEN, head, + rpmi_response_base, + data_len >=3D sizeof(uint32_t) ? rpmi_response_word(qts, 0) : 0); + qtest_writel(qts, RPMI_P2A_ACK_HEAD, (head + 1) % RPMI_QUEUE_DATA_SLOT= S); +} + +static void rpmi_send_sysreset(QTestState *qts, uint32_t reset_type, + uint8_t request_type) +{ + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_SYSTEM_RESET, request_type, + &reset_type, 1); +} + +static void rpmi_expect_qemu_failure(const char *extra_args, + const char *stderr_needle) +{ + g_autoptr(GError) error =3D NULL; + g_auto(GStrv) split_args =3D NULL; + g_autoptr(GPtrArray) argv =3D g_ptr_array_new(); + g_autofree char *stderr_data =3D NULL; + gint wait_status; + gboolean spawned; + + g_assert_true(g_shell_parse_argv(extra_args, NULL, &split_args, &error= )); + g_assert_no_error(error); + + g_ptr_array_add(argv, (gpointer)qtest_qemu_binary(NULL)); + for (char **arg =3D split_args; *arg; arg++) { + g_ptr_array_add(argv, *arg); + } + g_ptr_array_add(argv, NULL); + + spawned =3D g_spawn_sync(NULL, (char **)argv->pdata, NULL, + G_SPAWN_STDOUT_TO_DEV_NULL, + NULL, NULL, NULL, &stderr_data, + &wait_status, &error); + g_assert_true(spawned); + g_assert_no_error(error); + g_assert_true(!WIFEXITED(wait_status) || + WEXITSTATUS(wait_status) !=3D EXIT_SUCCESS); + g_assert_nonnull(stderr_data); + g_assert_nonnull(strstr(stderr_data, stderr_needle)); +} + +static void test_rpmi_machine_realize_off(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Doff"); + qtest_quit(qts); +} + +static void test_rpmi_machine_rejects_too_many_harts(void) +{ + rpmi_expect_qemu_failure( + "-machine virt,rpmi=3Don -smp 513 -display none -S", + "max CPUs supported by machine 'virt' is 512"); +} + +static void test_rpmi_base_platform_info(void) +{ + static const char expected[] =3D "QEMU RISC-V virt RPMI"; + QTestState *qts; + size_t i; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_request(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_GET_PLATFORM_INFO, + RPMI_MSG_NORMAL_REQUEST, NULL, 0); + + rpmi_expect_ack(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_GET_PLATFORM_INFO, + 2 * sizeof(uint32_t) + sizeof(expected)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, sizeof(expected)); + for (i =3D 0; i < sizeof(expected); i++) { + g_assert_cmphex(qtest_readb(qts, rpmi_response_base + 16 + i), =3D= =3D, + expected[i]); + } + + qtest_quit(qts); +} + +static void rpmi_probe_group(QTestState *qts, uint32_t service_group, + bool present) +{ + rpmi_send_request(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_PROBE_SERVICE_GROUP, + RPMI_MSG_NORMAL_REQUEST, &service_group, 1); + + rpmi_expect_ack(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_PROBE_SERVICE_GROUP, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + if (present) { + g_assert_cmphex(rpmi_response_word(qts, 1), !=3D, 0); + } else { + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 0); + } +} + +static void test_rpmi_base_probe_service_groups(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don,aia=3Daplic-imsic"); + rpmi_probe_group(qts, RPMI_SRVGRP_BASE, true); + qtest_system_reset(qts); + rpmi_probe_group(qts, RPMI_SRVGRP_SYSTEM_RESET, true); + qtest_system_reset(qts); + rpmi_probe_group(qts, RPMI_SRVGRP_HSM, true); + qtest_system_reset(qts); + rpmi_probe_group(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, true); + + qtest_quit(qts); +} + +static void test_rpmi_sysreset_attrs(void) +{ + static const struct { + uint32_t reset_type; + uint32_t expected_attrs; + } cases[] =3D { + { RPMI_SYSRST_TYPE_SHUTDOWN, RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE }, + { RPMI_SYSRST_TYPE_COLD_REBOOT, RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE = }, + { RPMI_SYSRST_TYPE_INVALID, 0 }, + }; + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + for (size_t i =3D 0; i < ARRAY_SIZE(cases); i++) { + if (i) { + qtest_system_reset(qts); + } + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + RPMI_MSG_NORMAL_REQUEST, &cases[i].reset_type, 1= ); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, + cases[i].expected_attrs); + } + + qtest_quit(qts); +} + +static void test_rpmi_sysreset_shutdown(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_SHUTDOWN, + RPMI_MSG_POSTED_REQUEST); + qtest_qmp_eventwait(qts, "SHUTDOWN"); + qtest_quit(qts); +} + +static void test_rpmi_sysreset_cold_reboot(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don -no-reboot"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_COLD_REBOOT, + RPMI_MSG_POSTED_REQUEST); + qtest_qmp_eventwait(qts, "SHUTDOWN"); + qtest_quit(qts); +} + +static void test_rpmi_sysreset_invalid_type(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_INVALID, + RPMI_MSG_NORMAL_REQUEST); + + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_SYSTEM_RESET, sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, + RPMI_ERR_INVALID_PARAM); + + qtest_quit(qts); +} + +static void test_rpmi_repeated_reset_after_traffic(void) +{ + QTestState *qts; + uint32_t reset_type =3D RPMI_SYSRST_TYPE_SHUTDOWN; + + qts =3D qtest_init("-machine virt,rpmi=3Don,aia=3Daplic-imsic"); + for (uint32_t i =3D 0; i < 5; i++) { + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + RPMI_MSG_NORMAL_REQUEST, + &reset_type, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + qtest_system_reset(qts); + } + qtest_quit(qts); +} + +static void test_rpmi_reset_clears_transport(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_INVALID, + RPMI_MSG_NORMAL_REQUEST); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_SYSTEM_RESET, sizeof(uint32_t)); + + qtest_system_reset(qts); + + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_TAIL), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_DOORBELL_BASE), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_rpmi_doorbell_invalid_access(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + qtest_writeb(qts, RPMI_DOORBELL_BASE, 1); + qtest_writel(qts, RPMI_DOORBELL_BASE + 4, 1); + g_assert_cmphex(qtest_readl(qts, RPMI_DOORBELL_BASE), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_rpmi_queue_bounds(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + qtest_writel(qts, RPMI_A2P_TAIL, RPMI_QUEUE_DATA_SLOTS); + qtest_writel(qts, RPMI_DOORBELL_BASE, 1); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + + qtest_system_reset(qts); + qtest_writel(qts, RPMI_A2P_HEAD, RPMI_QUEUE_DATA_SLOTS - 1); + qtest_writel(qts, RPMI_A2P_TAIL, RPMI_QUEUE_DATA_SLOTS - 1); + qtest_writel(qts, RPMI_P2A_ACK_HEAD, RPMI_QUEUE_DATA_SLOTS - 1); + qtest_writel(qts, RPMI_P2A_ACK_TAIL, RPMI_QUEUE_DATA_SLOTS - 1); + rpmi_probe_group(qts, RPMI_SRVGRP_BASE, true); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_TAIL), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_rpmi_migration_blocked(void) +{ + QTestState *qts; + QDict *error; + const char *desc; + + qts =3D qtest_init("-machine virt,rpmi=3Don -S"); + error =3D qtest_qmp_assert_failure_ref(qts, + "{ 'execute': 'migrate'," + " 'arguments': { 'uri': 'exec:cat > /dev/null' } }"); + desc =3D qdict_get_try_str(error, "desc"); + + g_assert_nonnull(desc); + g_assert_nonnull(strstr(desc, "non-migratable device")); + g_assert_nonnull(strstr(desc, "riscv-rpmi")); + + qobject_unref(error); + qtest_quit(qts); +} + +static void rpmi_expect_hsm_hart_list(QTestState *qts) +{ + uint32_t start_index =3D 0; + + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_LIST, + RPMI_MSG_NORMAL_REQUEST, &start_index, 1); + + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_LIST, + 7 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 2), =3D=3D, 4); + g_assert_cmphex(rpmi_response_word(qts, 3), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 4), =3D=3D, 1); + g_assert_cmphex(rpmi_response_word(qts, 5), =3D=3D, 2); + g_assert_cmphex(rpmi_response_word(qts, 6), =3D=3D, 3); +} + +static void test_rpmi_hsm_hart_list(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 4"); + rpmi_expect_hsm_hart_list(qts); + + qtest_quit(qts); +} + +static void test_rpmi_hsm_multi_socket_hart_list(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don " + "-smp 4,sockets=3D2,cores=3D2,threads=3D1"); + rpmi_expect_hsm_hart_list(qts); + + qtest_quit(qts); +} + +static void test_rpmi_hsm_hart_status(void) +{ + QTestState *qts; + uint32_t hart_id =3D 3; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 4"); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + RPMI_MSG_NORMAL_REQUEST, &hart_id, 1); + + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, + RPMI_HSM_HART_STATE_STARTED); + + qtest_quit(qts); +} + +static void rpmi_expect_hsm_status(QTestState *qts, uint32_t hart_id, + uint32_t expected_state) +{ + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + RPMI_MSG_NORMAL_REQUEST, &hart_id, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, expected_state); +} + +static void test_rpmi_hsm_hart_control(void) +{ + QTestState *qts; + uint32_t hart_id =3D 1; + uint32_t stop_request[] =3D { hart_id }; + uint32_t start_request[] =3D { hart_id, RPMI_HSM_TEST_START_ADDR, 0 }; + uint32_t suspend_request[] =3D { hart_id, 0, RPMI_HSM_TEST_RESUME_ADDR= , 0 }; + uint32_t start_index =3D 0; + uint32_t suspend_type =3D 0; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 2"); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_TYPES, + RPMI_MSG_NORMAL_REQUEST, &start_index, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_TYPES, + 4 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 2), =3D=3D, 1); + g_assert_cmphex(rpmi_response_word(qts, 3), =3D=3D, 0); + + qtest_system_reset(qts); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_INFO, + RPMI_MSG_NORMAL_REQUEST, &suspend_type, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_INFO, + 6 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + + qtest_system_reset(qts); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + RPMI_MSG_NORMAL_REQUEST, stop_request, + ARRAY_SIZE(stop_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + /* The qtest accelerator never runs the target hart to its next WFI. */ + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STOP_PENDING); + + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_START, + RPMI_MSG_NORMAL_REQUEST, start_request, + ARRAY_SIZE(start_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_START, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, RPMI_ERR_DENIED); + + qtest_system_reset(qts); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STARTED); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + RPMI_MSG_NORMAL_REQUEST, stop_request, + ARRAY_SIZE(stop_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STOP_PENDING); + + qtest_quit(qts); + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 2"); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, suspend_request, + ARRAY_SIZE(suspend_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + /* The qtest accelerator does not execute the target hart to WFI. */ + rpmi_expect_hsm_status(qts, hart_id, + RPMI_HSM_HART_STATE_SUSPEND_PENDING); + + qtest_system_reset(qts); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STARTED); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, suspend_request, + ARRAY_SIZE(suspend_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + rpmi_expect_hsm_status(qts, hart_id, + RPMI_HSM_HART_STATE_SUSPEND_PENDING); + + qtest_quit(qts); +} + +static void test_rpmi_syssusp_attrs_and_suspend(void) +{ + QTestState *qts; + uint32_t suspend_type =3D 0; + uint32_t suspend_request[] =3D { 0, 0, 0x80000000, 0 }; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 1"); + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_GET_ATTRIBUTES, + RPMI_MSG_NORMAL_REQUEST, &suspend_type, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_GET_ATTRIBUTES, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 3); + + qtest_system_reset(qts); + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, suspend_request, + ARRAY_SIZE(suspend_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + qtest_qmp_eventwait(qts, "SUSPEND"); + qtest_qmp_assert_success(qts, "{ 'execute': 'system_wakeup' }"); + qtest_qmp_eventwait(qts, "WAKEUP"); + + qtest_quit(qts); +} + +static void rpmi_expect_syssusp_request(QTestState *qts, uint32_t hart_id, + uint64_t address, uint32_t status) +{ + uint32_t request[] =3D { hart_id, 0, address, address >> 32 }; + QDict *response; + + g_test_message("System Suspend hart %" PRIu32 " resume address: 0x%016" + PRIx64, hart_id, address); + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, request, ARRAY_SIZE(request= )); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, status); + if (status =3D=3D 0) { + qtest_qmp_eventwait(qts, "SUSPEND"); + qtest_qmp_assert_success(qts, "{ 'execute': 'system_wakeup' }"); + qtest_qmp_eventwait(qts, "WAKEUP"); + } else { + /* query-status drains earlier events before checking for SUSPEND.= */ + response =3D qtest_qmp(qts, "{ 'execute': 'query-status' }"); + g_assert_cmpstr(qdict_get_str(qdict_get_qdict(response, "return"), + "status"), =3D=3D, "running"); + qobject_unref(response); + response =3D qtest_qmp_event_ref(qts, "SUSPEND"); + g_assert_null(response); + } +} + +static void test_rpmi_syssusp_resume_address(void) +{ + const uint64_t high_ram_addr =3D 0x100000000ULL; + QTestState *qts =3D qtest_init("-machine virt,rpmi=3Don -smp 1 -m 128M= " + "-cpu sifive-u54"); + + rpmi_expect_syssusp_request(qts, 1, 0x80000000, RPMI_ERR_INVALID_PARAM= ); + rpmi_expect_syssusp_request(qts, 0, 0x80000001, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_request(qts, 0, 0x10000000, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_request(qts, 0, 0x88000000, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_request(qts, 0, 0x80000002, 0); + qtest_system_reset(qts); + rpmi_expect_syssusp_request(qts, 0, 0x80000000, 0); + qtest_quit(qts); + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 1 -m 3G -cpu rv32i"); + qtest_writeb(qts, high_ram_addr, 0x5a); + g_assert_cmphex(qtest_readb(qts, high_ram_addr), =3D=3D, 0x5a); + rpmi_expect_syssusp_request(qts, 0, 0x80000002, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_request(qts, 0, high_ram_addr, + RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_request(qts, 0, 0x80000000, 0); + qtest_quit(qts); +} + +static void test_rpmi_syssusp_active_isa_alignment(void) +{ + const int csr_misa =3D 0x301; + const uint64_t misa_c =3D 1U << 2; + uint64_t misa =3D 0; + QTestState *qts =3D qtest_init("-machine virt,rpmi=3Don -smp 1 -m 128M= " + "-cpu sifive-u54,x-misa-w=3Don"); + + qtest_csr_call(qts, "get_csr", 0, csr_misa, &misa); + g_assert_cmphex(misa & misa_c, =3D=3D, misa_c); + misa &=3D ~misa_c; + qtest_csr_call(qts, "set_csr", 0, csr_misa, &misa); + qtest_csr_call(qts, "get_csr", 0, csr_misa, &misa); + g_assert_cmphex(misa & misa_c, =3D=3D, 0); + rpmi_expect_syssusp_request(qts, 0, 0x80000002, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_request(qts, 0, 0x80000000, 0); + qtest_quit(qts); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + if (qtest_has_machine("virt")) { + if (qtest_has_accel("tcg")) { + qtest_add_func("/riscv/rpmi/syssusp/active-isa-alignment", + test_rpmi_syssusp_active_isa_alignment); + } + qtest_add_func("/riscv/rpmi/syssusp/resume-address", + test_rpmi_syssusp_resume_address); + qtest_add_func("/riscv/rpmi/fdt/service-nodes", + test_rpmi_virt_fdt_service_nodes); + qtest_add_func("/riscv/rpmi/machine/realize-off", + test_rpmi_machine_realize_off); + qtest_add_func("/riscv/rpmi/machine/rejects-too-many-harts", + test_rpmi_machine_rejects_too_many_harts); + qtest_add_func("/riscv/rpmi/base/platform-info", + test_rpmi_base_platform_info); + qtest_add_func("/riscv/rpmi/base/probe-service-groups", + test_rpmi_base_probe_service_groups); + qtest_add_func("/riscv/rpmi/sysreset/attrs", + test_rpmi_sysreset_attrs); + qtest_add_func("/riscv/rpmi/sysreset/shutdown", + test_rpmi_sysreset_shutdown); + qtest_add_func("/riscv/rpmi/sysreset/cold-reboot", + test_rpmi_sysreset_cold_reboot); + qtest_add_func("/riscv/rpmi/sysreset/invalid-type", + test_rpmi_sysreset_invalid_type); + qtest_add_func("/riscv/rpmi/reset/clears-transport", + test_rpmi_reset_clears_transport); + qtest_add_func("/riscv/rpmi/negative/doorbell-invalid-access", + test_rpmi_doorbell_invalid_access); + qtest_add_func("/riscv/rpmi/negative/doorbell-unsupported-values", + test_rpmi_doorbell_unsupported_values); + qtest_add_func("/riscv/rpmi/negative/queue-bounds", + test_rpmi_queue_bounds); + qtest_add_func("/riscv/rpmi/reset/repeated-after-traffic", + test_rpmi_repeated_reset_after_traffic); + qtest_add_func("/riscv/rpmi/migration/blocked", + test_rpmi_migration_blocked); + qtest_add_func("/riscv/rpmi/hsm/hart-list", + test_rpmi_hsm_hart_list); + qtest_add_func("/riscv/rpmi/hsm/multi-socket-hart-list", + test_rpmi_hsm_multi_socket_hart_list); + qtest_add_func("/riscv/rpmi/hsm/hart-status", + test_rpmi_hsm_hart_status); + qtest_add_func("/riscv/rpmi/hsm/hart-control", + test_rpmi_hsm_hart_control); + qtest_add_func("/riscv/rpmi/syssusp/attrs-and-suspend", + test_rpmi_syssusp_attrs_and_suspend); + } + + return g_test_run(); +} From nobody Mon Nov 23 04:28:06 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1794556893; cv=none; d=zohomail.com; s=zohoarc; b=bfvG60s+IcdKwjhzVEfj/mvA8bU9s4bQ7zht8daS5C6dp7HpRwjAGtZY5iF9XWoIPXNP3GbSZH5RIdx1kVV1pZtHRa5OwT8I/msPBdTZLCi8x1412u/PIoIF/enMdO1A3s8/xhH5ZeDqTqLyYmgHAS73shvoibpU8wv4IuJsoxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794556893; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U8CqxUR8zSSM2sdXuf4vUBTBhl40+ZbSvhj1c1hLA7k=; b=H4pK+Nzs0tKEPFU5kVFHBbQkhKa4tqTOBbK4Pc3FiGZHYGOWWe8Hyh1JEp3G1AB6cBsGzRegws1Me1TCgc2sc/4xZy43Qgk7brtAj8+J5YLgebEJHh/+v7EJn0BtPVd/TqXASMw9rgbu1aDk7NaC0NcmFdo5wLD+9QBSB+cfDHM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794556893510544.2112465033736; Fri, 13 Nov 2026 00:01:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRmD2-0003cZ-PC; Fri, 13 Nov 2026 03:00:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCj-0003OC-6w for qemu-devel@nongnu.org; Fri, 13 Nov 2026 03:00:16 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRmCd-0000IK-WF for qemu-devel@nongnu.org; Fri, 13 Nov 2026 03:00:12 -0500 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AD576D03119860 for ; Fri, 13 Nov 2026 08:00:07 GMT Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hwkgwa3er-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Fri, 13 Nov 2026 08:00:05 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-33bf1d17dfeso93295eec.2 for ; Fri, 13 Nov 2026 00:00:05 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3795378c2fesm5213376eec.1.2026.11.12.23.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 00:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=U8CqxUR8zSS M2sdXuf4vUBTBhl40+ZbSvhj1c1hLA7k=; b=SAAt+OmyU/jr5vFyga4Ankq105E X1pMe4xKFEcJKQTQBvh93oebN2PH9bOd9/BGfCxNuIB5UiO0xAFcBG7TKo+04MBe rYX4UAmHs6yE6LLk16X7hEaHJBvGg5BwJLRWv1yGBVkh8O0tuP4gpmn0gFtkChuV kEMTqF81erptmCfXsSkpddEc9fNKCIRELCbrKXCoKz+CyVDo9FUGDkG786LnPUXV 6Z54h5iW90rOp3ZQvKYyGwSG6boz+xyJqYCMwOXSL76UJ7Xj+qz9kNkaphJ3BoP9 cnNbGlfKUfr1qSk9LQ4RAScRtwY3OdMZ81MmHH3Tjq58RLBj9xjZqLZco2g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1794556805; x=1795161605; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=U8CqxUR8zSSM2sdXuf4vUBTBhl40+ZbSvhj1c1hLA7k=; b=Gf7bH6jfOy7nKrEJeZ/HJE4cbxm1eDB/w6xPfwsOCpqTBgBbkJUsZdx23JRPyZXHCG tMDdJsgL8ju1Kchbx+OL53T70KNMbcm1LEIRqYsfqlmikO255Q11Ym4YhKl2wTNbPUEH qjb2Y3HWP43Ba//k8EsAK3WPqiOG4VwjdjKZZLQXuR6hR7UsSmoCUgVWLY4dr/q3H9sh B0GD1dg96W1TewOD6Zz8V/BypNyuuxe32kkVpo7m762yKixmHq8p8UbWK3dECDTWopcy gbGLwciHtOFyrDFDn6rJSU2D2wECONcflqWQp5z31diORW61RtQNIplgqaXx/WwgWCe0 V6Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794556805; x=1795161605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=U8CqxUR8zSSM2sdXuf4vUBTBhl40+ZbSvhj1c1hLA7k=; b=b6IQyyUkTOqLmCFogVlebS2644Z3rTddPXECBNyIpT2ZlShZkn+7KpQgrVUZudEFeM nfPLCMA7dozGOZzo1I6OsRA+j1ehNZz8pCipPwkLkKsWTW8bDigyuea2bdAosA1dpFVB bjW9WCYi5MoFSL2ZTLy+oLkhxq0wTelOFoor6eeDQ186Rnj+syTRkKlKl6cMiWqirVIc nyKnPYIyJz/+XNhklFnOx0duX/sOm62hELLxfyKCSPg8YXefjeEqsdrMGEpDV6HJU1QM 0rBIT/CTXFJNdqEzZ+aejFbyEGcUgsBTDyQDCbDdtHDML0fIgBainNwWxA6lA9rLcTsI ayyw== X-Gm-Message-State: APuU4Z/hzgGJ7ghiYpU4hrirxQzx9FZ7fE1l7NgEoGk96bxM0QsFoEzg hEGXWU0huIbC47Cn1If3+yHLsYWGIoam8RsldaHY5t6mFf4pn14N+/i15u6BlfckHooCsBnI2eE QOU/+4PeSj5HNKMekywUcbRxlCQHAoNqiyyEBcorXwYgeRPtFWCD6dgpmrCV+uV09+A== X-Gm-Gg: AYBFou0hA/TwQriXXnM1IPNrlu74uRiYV5DEf/2SgKrtyZ9FSkwPhLnXndrztr5jJE7 kYo02H9O4TEGCu2Ypz1RJxdwUnZBnxLspFUqGDaQzgXZNuCde28fql5ryTUl2/pAu8LPvCQtwgp U5aeRISPb7LNDniXlzOb9j4LhtSXRNhles7B5IzB1PqLquNVidBM0xKyBIlBK0lxhDfysMAFHpC euvvfXc8ab/KUb0mAD75NzIBwpGu7F2QsFmsDOZA/QhYkK2ovGgmdkqyyoKfVIparZ2sL6A7WUu QX+Yk7kI+Re5oHZT8OaI5Ov5sTxxGMVoOyu6Jz8xQUDt1DdeiPiSH2E5u7OinzDXgKBHlSaHwWh a7WbZz2y/Mh7pOtMe2zNmXFt+H170yMiVcXmLkgrZ4ZVmdJKE+70Be8vuHp29opn3QWIN6zmhOV 7UJXTZX8YaexPnaelR60LthwoFt+bnBUhv5ptkgbQbbUo9IIfkGJEe2oFJZbx3EaBF8/O5ujrh7 uM+c4s= X-Received: by 2002:a05:7301:a0a:b0:36c:a1bc:6114 with SMTP id 5a478bee46e88-3796038259fmr2345822eec.0.1794556804244; Fri, 13 Nov 2026 00:00:04 -0800 (PST) X-Received: by 2002:a05:7301:a0a:b0:36c:a1bc:6114 with SMTP id 5a478bee46e88-3796038259fmr2345775eec.0.1794556803519; Fri, 13 Nov 2026 00:00:03 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v16 10/10] tests/functional: add initial RPMI virt guest smoke Date: Fri, 13 Nov 2026 13:29:05 +0530 Message-ID: <20261113075906.715870-11-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261113075906.715870-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=DNgacCNb c=1 sm=1 tr=0 ts=6af6c385 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=NEAV23lmAAAA:8 a=tZD6s3AVAAAA:8 a=EUspDBNiAAAA:8 a=90goSig_s_BKn4pKddUA:9 a=O8hF6Hzn-FEA:10 a=bBxd6f-gb0O0v-kibOvt:22 a=DklORoM8RNzucgFJxVk_:22 X-Proofpoint-ORIG-GUID: aPPXiisvrdpPvJciZom3AGDIR7NE4hdu X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX/03m4SestG+X 45Fob72kSdcQAzHWuT4VNDETRf5CutqGJKmd8S+T+XmRZDGAhiVm2bl4zJAREoTK9bA643CQWLk q1CpbXFRzwwPTq1lSmMYOV85kCc4DlgwTcLzyk5t8VNy7BpUHrUjEs9u/FnMmyJLS5fvT9Sz56G 8lzuhZLni0UrsBADp/tawjRO0cUAte0BbYwiU2Nw8kLQ0dbWJE8TSOzxDIhakKcJefB31j8J0/c i3EkI/Vu6wk++t255+MxyPjD5xFxwEyBVJURe/gNuFmDc05laj9JUhU4F/pI+aquvliw6Qp3T7z pcj6bIrzEL8T24Kn5QxPxa2xNelAW7ZD735NuVxXFOduNutS3wp9XPyb+Rhef6qG9B4ysmf0KXF LnhL4D387fwOLUfAe0uey+eWKQJY+CDKGB+atrNbl+3n4cN24Yc0LKGd6qgHwtcANtFDaVcQLRY OpAYwMvIIqvLqoS25UQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEzMDAzMSBTYWx0ZWRfX/z3YJfmflr+o 8rJeThOv7LcPhItiA3138V8qhA0bYXkCG0dP/SN8x9f771HfIyzgOPfilb/Hqy8ExwZBWUDykcR HKistpYdFj1oPtQJZiWM/H5F5KkraQg= X-Proofpoint-GUID: aPPXiisvrdpPvJciZom3AGDIR7NE4hdu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-13_02,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611130031 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1794556895680158500 Content-Type: text/plain; charset="utf-8" Boot an RPMI-enabled RISC-V virt guest and exercise the initial HSM, system suspend, and system reset paths. Require completed CPU offline and online transitions for HSM stop/start, repeat the cycle, and stop a hart running a busy workload. Reboot while a secondary hart remains stopped, verify the next boot restores both harts, and repeat HSM control afterward. Also cover HSM stop/start immediately after suspend/wakeup and a fresh suspend cycle after reboot. Reject definitive OpenSBI HSM failure diagnostics instead of accepting a shell marker that only appeared in the echoed command. Linux can report CPU death before firmware reaches STOPPED. Bound retries of the subsequent online request, retain transient errors in the console, and require a completed online transition rather than assuming that an offline sysfs mask proves immediate firmware stop completion. Allow transient RPMI_ERR_DENIED diagnostics after a successful stop when the subsequent start completes. Keep stop-only checks and fatal stop diagnostics strict. Keep the suite bounded by Meson's 420-second timeout. Fail immediately on the suspend failure marker, and split that marker in the shell command so echoed input cannot trigger it. Use pinned kernel/rootfs assets with optional local overrides, clean up setup failures, and escape commas in overlay filenames. The pinned rootfs has Python but no taskset; pin the busy worker with Python's sched_setaffinity and require liveness and CPU1 affinity before stopping the hart. Provision pinned librpmi and RPMI-capable OpenSBI firmware in CI. Build QEMU with RPMI explicitly enabled and require all six guest cases to pass without skips. Signed-off-by: Subrahmanya Lingappa --- .gitlab-ci.d/buildtest.yml | 58 ++++ scripts/ci/build-rpmi-deps.sh | 49 ++++ scripts/ci/check-rpmi-guests.py | 36 +++ tests/functional/riscv64/meson.build | 2 + tests/functional/riscv64/test_rpmi_virt.py | 310 +++++++++++++++++++++ 5 files changed, 455 insertions(+) create mode 100644 scripts/ci/build-rpmi-deps.sh create mode 100644 scripts/ci/check-rpmi-guests.py create mode 100644 tests/functional/riscv64/test_rpmi_virt.py diff --git a/.gitlab-ci.d/buildtest.yml b/.gitlab-ci.d/buildtest.yml index b1e95395d0..7ed7b9a19c 100644 --- a/.gitlab-ci.d/buildtest.yml +++ b/.gitlab-ci.d/buildtest.yml @@ -92,6 +92,64 @@ functional-system-debian: IMAGE: debian MAKE_CHECK_ARGS: check-functional =20 +build-rpmi-opensbi: + extends: .base_job_template + stage: build + image: $CI_REGISTRY_IMAGE/qemu/debian-riscv64-cross:$QEMU_CI_CONTAINER_T= AG + needs: + - job: riscv64-debian-cross-container + script: + - sh scripts/ci/build-rpmi-deps.sh opensbi "$CI_PROJECT_DIR/rpmi-deps" + artifacts: + expire_in: 2 days + paths: + - rpmi-deps/opensbi-build/platform/generic/firmware/fw_jump.bin + +build-system-rpmi: + extends: + - .native_build_job_template + - .native_build_artifact_template + needs: + - job: amd64-debian-container + variables: + IMAGE: debian + TARGETS: riscv64-softmmu + CONFIGURE_ARGS: --enable-librpmi + MAKE_CHECK_ARGS: check-build + before_script: + - !reference [.base_meson_job_template, before_script] + - sh scripts/ci/build-rpmi-deps.sh librpmi "$CI_PROJECT_DIR/rpmi-deps" + - export PKG_CONFIG_PATH=3D"$CI_PROJECT_DIR/rpmi-deps/librpmi-install/= lib/pkgconfig" + - export LD_LIBRARY_PATH=3D"$CI_PROJECT_DIR/rpmi-deps/librpmi-install/= lib" + artifacts: + paths: + - build + - rpmi-deps/librpmi-install + - .git-submodule-status + - ci-runner-env + +functional-system-rpmi: + extends: .functional_test_job_template + needs: + - job: build-system-rpmi + artifacts: true + - job: build-rpmi-opensbi + artifacts: true + variables: + IMAGE: debian + before_script: + - !reference [.functional_test_job_template, before_script] + - export QEMU_TEST_RPMI_OPENSBI=3D"$CI_PROJECT_DIR/rpmi-deps/opensbi-b= uild/platform/generic/firmware/fw_jump.bin" + - export LD_LIBRARY_PATH=3D"$CI_PROJECT_DIR/rpmi-deps/librpmi-install/= lib" + script: + - cd build + - pyvenv/bin/meson test --no-rebuild --print-errorlogs + --logbase rpmi-qtest qemu:qtest-riscv64/riscv-rpmi-test + - pyvenv/bin/meson test --no-rebuild --print-errorlogs + --logbase rpmi-guests --suite qemu:func-riscv64-thorough + qemu:func-riscv64-rpmi_virt + - python3 ../scripts/ci/check-rpmi-guests.py meson-logs/rpmi-guests.js= on + crash-test-debian: extends: .native_test_job_template needs: diff --git a/scripts/ci/build-rpmi-deps.sh b/scripts/ci/build-rpmi-deps.sh new file mode 100644 index 0000000000..dcf76b7523 --- /dev/null +++ b/scripts/ci/build-rpmi-deps.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later + +set -eu + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 opensbi|librpmi OUTPUT_DIRECTORY" >&2 + exit 1 +fi + +dependency=3D$1 +output=3D$(realpath -m "$2") +case "$dependency" in + opensbi) + repository=3Dhttps://github.com/riscv-software-src/opensbi.git + revision=3D2aed4ec24f5d85312e528d2a40d7009800d55aeb + ;; + librpmi) + repository=3Dhttps://github.com/riscv-software-src/librpmi.git + revision=3Dfbe6f0594925d304147638d943228bea3e91bd62 + ;; + *) + echo "Unknown RPMI dependency: $dependency" >&2 + exit 1 + ;; +esac + +source=3D$output/$dependency +if [ ! -e "$source/.git" ]; then + git init "$source" + git -C "$source" fetch --depth 1 "$repository" "$revision" + git -C "$source" checkout --detach FETCH_HEAD +fi +test "$(git -C "$source" rev-parse HEAD)" =3D "$revision" +git -C "$source" diff --quiet HEAD + +if [ "$dependency" =3D opensbi ]; then + make -C "$source" -j"${JOBS:-2}" PLATFORM=3Dgeneric \ + CROSS_COMPILE=3Driscv64-linux-gnu- O=3D"$output/opensbi-build" + firmware=3D$output/opensbi-build/platform/generic/firmware/fw_jump.bin + test -s "$firmware" + sha256sum "$firmware" +else + make -C "$source" -j"${JOBS:-2}" CROSS_COMPILE=3D CC=3Dcc \ + O=3D"$output/librpmi-build" I=3D"$output/librpmi-install" install + # The pinned library emits /usr even with a separate installation root. + sed -i "s|^prefix=3D/usr$|prefix=3D$output/librpmi-install|" \ + "$output/librpmi-install/lib/pkgconfig/librpmi.pc" +fi diff --git a/scripts/ci/check-rpmi-guests.py b/scripts/ci/check-rpmi-guests= .py new file mode 100644 index 0000000000..0f87f0e9e1 --- /dev/null +++ b/scripts/ci/check-rpmi-guests.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +"""Require the RPMI functional suite to execute six guests without skips."= "" + +import json +from pathlib import Path +import re +import sys + + +def check_results(path): + records =3D [json.loads(line) for line in path.read_text().splitlines() + if line.strip()] + if len(records) !=3D 1: + raise ValueError('expected one RPMI guest suite result') + result =3D records[0] + output =3D result['stdout'] + passed =3D re.findall(r'^ok ([0-9]+) ', output, re.MULTILINE) + if ('qemu:func-riscv64-rpmi_virt' not in result['name'] or + result['result'] !=3D 'OK' or result['returncode'] !=3D 0 or + passed !=3D [str(number) for number in range(1, 7)] or + re.findall(r'^1\.\.([0-9]+)$', output, re.MULTILINE) !=3D ['6'= ] or + re.search(r'#\s*skip\b|^not ok ', output, + re.IGNORECASE | re.MULTILINE)): + raise ValueError('RPMI guest suite must pass six tests without ski= ps') + + +if __name__ =3D=3D '__main__': + if len(sys.argv) !=3D 2: + sys.exit('Usage: check-rpmi-guests.py MESON_RESULT_JSON') + try: + check_results(Path(sys.argv[1])) + except (OSError, ValueError, KeyError, TypeError) as error: + sys.exit(str(error)) + print('RPMI guest suite: six passes, zero skips') diff --git a/tests/functional/riscv64/meson.build b/tests/functional/riscv6= 4/meson.build index 211ea9acfc..b7c2a29ead 100644 --- a/tests/functional/riscv64/meson.build +++ b/tests/functional/riscv64/meson.build @@ -5,6 +5,7 @@ test_riscv64_timeouts =3D { 'k230' : 120, 'server_ref' : 120, 'tuxrun' : 120, + 'rpmi_virt' : 420, } =20 tests_riscv64_system_quick =3D [ @@ -21,4 +22,5 @@ tests_riscv64_system_thorough =3D [ 'tt_atlantis', 'tuxrun', 'milkv_duo', + 'rpmi_virt', ] diff --git a/tests/functional/riscv64/test_rpmi_virt.py b/tests/functional/= riscv64/test_rpmi_virt.py new file mode 100644 index 0000000000..0b349a1803 --- /dev/null +++ b/tests/functional/riscv64/test_rpmi_virt.py @@ -0,0 +1,310 @@ +#!/usr/bin/env python3 +# +# RISC-V virt RPMI Linux guest integration tests +# +# Copyright (c) 2026 Qualcomm Technologies, Inc. +# +# Author: +# Subrahmanya Lingappa +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +from pathlib import Path +import subprocess + +from qemu_test import Asset, QemuBaseTest, QemuSystemTest +from qemu_test import exec_command +from qemu_test import exec_command_and_wait_for_pattern +from qemu_test import get_qemu_img +from qemu_test import wait_for_console_pattern + + +class RiscvVirtRpmiGuestTest(QemuSystemTest): + """Boot Linux and exercise RPMI-backed services through guest APIs. + + Supply RPMI-capable OpenSBI firmware. Kernel and rootfs overrides are + optional; otherwise the pinned TuxRun assets are downloaded. Set: + + QEMU_TEST_RPMI_OPENSBI=3D/path/to/fw_jump.bin + QEMU_TEST_RPMI_KERNEL=3D/path/to/Image + QEMU_TEST_RPMI_ROOTFS=3D/path/to/rootfs.ext4 + + Exact RPMI packet command-ID coverage remains in riscv-rpmi qtests. Th= is + functional test verifies Linux/OpenSBI integration paths visible from a + real guest without adding probe hooks to production RPMI sources. + """ + + ASSET_KERNEL =3D Asset( + 'https://storage.tuxboot.com/kernels/6.11.9/riscv64/Image', + '174f8bb87f08961e54fa3fcd954a8e31f4645f6d6af4dd43983d5e9841490fb0') + ASSET_ROOTFS =3D Asset( + 'https://storage.tuxboot.com/buildroot/20241119/riscv64/rootfs.ext= 4.zst', + 'aa4736a9872651dfc0d95e709465eedf1134fd19d42b8cb305bfd776f9801004') + PROMPT =3D 'root@tuxtest:~#' + + def _require_path(self, env_name, required=3DTrue): + value =3D os.getenv(env_name) + if not value: + if not required: + return None + self.skipTest(f'{env_name} is required') + path =3D Path(value) + if not path.is_file(): + self.skipTest(f'{env_name} does not exist: {path}') + return path + + def assets_available(self): + return ((self.kernel is not None or self.ASSET_KERNEL.available())= and + (self.rootfs is not None or self.ASSET_ROOTFS.available())) + + def setUp(self): + self.opensbi =3D self._require_path('QEMU_TEST_RPMI_OPENSBI') + self.kernel =3D self._require_path('QEMU_TEST_RPMI_KERNEL', + required=3DFalse) + self.rootfs =3D self._require_path('QEMU_TEST_RPMI_ROOTFS', + required=3DFalse) + try: + super().setUp() + self.qemu_img =3D get_qemu_img(self) + if self.kernel is None: + self.kernel =3D self.ASSET_KERNEL.fetch() + if self.rootfs is None: + self.rootfs =3D self.uncompress(self.ASSET_ROOTFS) + except BaseException: + if hasattr(self, '_console_log_fh'): + super().tearDown() + elif hasattr(self, '_log_fh'): + QemuBaseTest.tearDown(self) + raise + + def _create_rootfs_overlay(self): + overlay =3D Path(self.scratch_file('rootfs.qcow2')) + subprocess.run([ + self.qemu_img, 'create', '-q', '-f', 'qcow2', '-F', 'raw', + '-b', str(self.rootfs), str(overlay), + ], check=3DTrue) + return overlay + + def _boot_guest(self, smp=3D4): + self.set_machine('virt') + self.machine =3D 'virt,rpmi=3Don,aia=3Daplic-imsic' + rootfs_overlay =3D self._create_rootfs_overlay() + rootfs_filename =3D str(rootfs_overlay).replace(",", ",,") + + self.vm.set_console() + self.vm.add_args( + '-cpu', 'rv64', + '-smp', str(smp), + '-m', '1G', + '-bios', str(self.opensbi), + '-kernel', str(self.kernel), + '-append', 'printk.time=3D0 root=3D/dev/vda rw console=3DttyS0= ' + 'earlycon=3Dsbi loglevel=3D8 no_console_suspend', + '-blockdev', 'driver=3Dqcow2,file.driver=3Dfile,' + f'file.filename=3D{rootfs_filename}' + ',node-name=3Dhd0', + '-device', 'virtio-blk-device,drive=3Dhd0', + ) + self.vm.launch() + + def _expect_rpmi_firmware_and_linux(self): + patterns =3D [ + 'Platform HSM Device : rpmi-hsm', + 'Platform Reboot Device : rpmi-system-reset', + 'Platform Shutdown Device : rpmi-system-reset', + 'Platform Suspend Device : rpmi-system-suspend', + 'Standard SBI Extensions', + 'susp', + 'tuxtest login:', + ] + for pattern in patterns: + wait_for_console_pattern(self, pattern) + exec_command_and_wait_for_pattern(self, 'root', self.PROMPT) + + def _run_marker_command(self, command, marker, failure_marker=3DNone): + out =3D exec_command_and_wait_for_pattern(self, command, marker, + failure_message=3Dfailure_= marker) + self.assertIn(marker.encode(), out) + return out + + @staticmethod + def _marker(marker): + """Build a marker without putting the complete token in echoed inp= ut.""" + prefix, suffix =3D marker.rsplit('_', 1) + return "printf '%%s_%%s\\n' %s %s" % (prefix, suffix) + + def _assert_no_hsm_stop_failure(self, output, start_retry=3DFalse): + # OpenSBI may report STOP_PENDING before its state reaches STOPPED. + # CPU offline and a successful later HART_START prove the cycle. + for diagnostic in ('ERR: Failed stop hart', 'Unable to stop the cp= u'): + self.assertNotIn(diagnostic.encode(), output, + 'OpenSBI reported an HSM stop failure: ' + f'{diagnostic}') + if start_retry: + # Only start retries after a successful stop may report DENIED. + output =3D output.partition(b'RPMI_LINUX_HSM_STOP_PASS')[0] + self.assertNotIn(b'RPMI_ERR_DENIED', output) + + def _validate_hsm_boot_start(self, online_cpus): + self._run_marker_command( + 'echo RPMI_LINUX_HSM_START_BEGIN; ' + 'cat /sys/devices/system/cpu/present; ' + 'online=3D$(cat /sys/devices/system/cpu/online); ' + 'echo "$online"; ' + f'if [ "$online" =3D "{online_cpus}" ]; ' + f'then {self._marker("RPMI_LINUX_HSM_START_PASS")}; ' + f'else {self._marker("RPMI_LINUX_HSM_START_FAIL")}; fi', + 'RPMI_LINUX_HSM_START_PASS', 'RPMI_LINUX_HSM_START_FAIL') + + def _validate_fdt_service_layout(self): + self._run_marker_command( + 'base=3D/sys/firmware/devicetree/base/soc; ' + 'if [ -d "$base/sysreset" ] && ' + '[ -d "$base/hsm" ] && [ -d "$base/suspend" ] && ' + '[ ! -d "$base/mailbox@10200000/sysreset" ] && ' + '[ ! -d "$base/mailbox@10200000/hsm" ] && ' + '[ ! -d "$base/mailbox@10200000/suspend" ]; then ' + f'{self._marker("RPMI_FDT_SERVICE_SIBLINGS_PASS")}; ' + f'else {self._marker("RPMI_FDT_SERVICE_SIBLINGS_FAIL")}; fi', + 'RPMI_FDT_SERVICE_SIBLINGS_PASS', + 'RPMI_FDT_SERVICE_SIBLINGS_FAIL') + + def _validate_hsm_stop_start(self): + command =3D ( + 'echo RPMI_LINUX_HSM_STOP_BEGIN; ' + 'if [ -w /sys/devices/system/cpu/cpu1/online ]; then ' + 'echo 0 > /sys/devices/system/cpu/cpu1/online && ' + '[ "$(cat /sys/devices/system/cpu/online)" =3D 0 ] && ' + f'{self._marker("RPMI_LINUX_HSM_STOP_PASS")} && ' + # Linux reports CPU death before firmware has necessarily stop= ped + # the hart. Preserve transient start errors, but bound the wai= t. + '(attempt=3D0; until echo 1 > /sys/devices/system/cpu/cpu1/onl= ine; ' + 'do attempt=3D$((attempt + 1)); ' + 'printf "HSM start retry %s\\n" "$attempt"; ' + '[ "$attempt" -lt 50 ] || exit 1; sleep 0.1; done) && ' + '[ "$(cat /sys/devices/system/cpu/online)" =3D 0-1 ] && ' + f'{self._marker("RPMI_LINUX_HSM_START_PASS")} || ' + f'{self._marker("RPMI_LINUX_HSM_STOP_FAIL")}; ' + f'else {self._marker("RPMI_LINUX_HSM_STOP_FAIL")}; fi; ' + 'sleep 1; ' + f'{self._marker("RPMI_LINUX_HSM_STOP_DONE")}') + out =3D exec_command_and_wait_for_pattern( + self, command, 'RPMI_LINUX_HSM_STOP_DONE', + failure_message=3D'RPMI_LINUX_HSM_STOP_FAIL') + self.assertIn(b'RPMI_LINUX_HSM_STOP_PASS', out) + self.assertIn(b'RPMI_LINUX_HSM_START_PASS', out) + self._assert_no_hsm_stop_failure(out, start_retry=3DTrue) + + def _validate_hsm_stop(self): + command =3D ( + 'echo RPMI_LINUX_HSM_STOP_BEGIN; ' + 'if [ -w /sys/devices/system/cpu/cpu1/online ] && ' + 'echo 0 > /sys/devices/system/cpu/cpu1/online && ' + 'sleep 1 && ' + '[ "$(cat /sys/devices/system/cpu/online)" =3D 0 ]; then ' + f'{self._marker("RPMI_LINUX_HSM_STOP_PASS")}; ' + f'else {self._marker("RPMI_LINUX_HSM_STOP_FAIL")}; fi') + out =3D exec_command_and_wait_for_pattern( + self, command, 'RPMI_LINUX_HSM_STOP_PASS', + failure_message=3D'RPMI_LINUX_HSM_STOP_FAIL') + self._assert_no_hsm_stop_failure(out) + + def _validate_system_suspend(self): + exec_command( + self, + 'echo RPMI_LINUX_SUSPEND_BEGIN; ' + 'if grep -qw mem /sys/power/state; then ' + 'echo mem > /sys/power/state; ' + f'else {self._marker("RPMI_LINUX_SUSPEND_FAIL")}; fi') + wait_for_console_pattern(self, 'RPMI_LINUX_SUSPEND_BEGIN') + wait_for_console_pattern( + self, 'PM: suspend entry', 'RPMI_LINUX_SUSPEND_FAIL') + self.vm.event_wait('SUSPEND', 10) + self.vm.qmp('system_wakeup') + self.vm.event_wait('WAKEUP', 10) + wait_for_console_pattern(self, 'PM: suspend exit') + # The resumed shell prompt and suspend-exit message can share a li= ne. + # Send an empty command so the console always produces a fresh pro= mpt. + exec_command_and_wait_for_pattern(self, '', self.PROMPT) + self._run_marker_command( + 'marker=3DRPMI_LINUX_WAKEUP; echo ${marker}_PASS', + 'RPMI_LINUX_WAKEUP_PASS') + + def _validate_reset_poweroff(self): + exec_command(self, 'echo RPMI_LINUX_RESET_POWEROFF_BEGIN; poweroff= -f') + wait_for_console_pattern(self, 'RPMI_LINUX_RESET_POWEROFF_BEGIN') + wait_for_console_pattern(self, 'reboot: Power down') + self.vm.wait() + + def _validate_reset_reboot(self): + exec_command(self, 'echo RPMI_LINUX_RESET_REBOOT_BEGIN; reboot -f') + wait_for_console_pattern(self, 'RPMI_LINUX_RESET_REBOOT_BEGIN') + wait_for_console_pattern(self, 'reboot: Restarting system') + wait_for_console_pattern(self, 'OpenSBI') + + def test_linux_guest_service_enumeration(self): + self._boot_guest(smp=3D4) + self._expect_rpmi_firmware_and_linux() + self._validate_fdt_service_layout() + self._validate_hsm_boot_start('0-3') + + def test_linux_guest_hsm_stop(self): + self._boot_guest(smp=3D2) + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0-1') + for _ in range(3): + self._validate_hsm_stop_start() + # The pinned rootfs provides Python, but not taskset. + self._run_marker_command( + "python3 -c 'import os; os.sched_setaffinity(0, {1}); " + 'exec("while True: pass")' + "' & echo $! > " + "/tmp/rpmi-hsm-worker; " + 'worker=3D$(cat /tmp/rpmi-hsm-worker); ' + 'attempt=3D0; while kill -0 "$worker" && ' + '[ "$(awk \'/Cpus_allowed_list:/ {print $2}\' ' + '/proc/"$worker"/status)" !=3D 1 ] && ' + '[ "$attempt" -lt 50 ]; do ' + 'attempt=3D$((attempt + 1)); sleep 0.1; done; ' + 'if kill -0 "$worker" && ' + '[ "$(awk \'/Cpus_allowed_list:/ {print $2}\' ' + '/proc/"$worker"/status)" =3D 1 ]; then ' + f'{self._marker("RPMI_HSM_WORKER_PASS")}; ' + f'else {self._marker("RPMI_HSM_WORKER_FAIL")}; fi', + 'RPMI_HSM_WORKER_PASS', 'RPMI_HSM_WORKER_FAIL') + self._validate_hsm_stop_start() + exec_command(self, 'kill $(cat /tmp/rpmi-hsm-worker) 2>/dev/null |= | :') + + def test_linux_guest_hsm_stopped_reset(self): + self._boot_guest(smp=3D2) + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0-1') + self._validate_hsm_stop() + self._validate_reset_reboot() + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0-1') + self._validate_hsm_stop_start() + + def test_linux_guest_suspend(self): + self._boot_guest(smp=3D2) + self._expect_rpmi_firmware_and_linux() + self._validate_system_suspend() + self._validate_hsm_stop_start() + + def test_linux_guest_reset_poweroff(self): + self._boot_guest(smp=3D1) + self._expect_rpmi_firmware_and_linux() + self._validate_reset_poweroff() + + def test_linux_guest_reset_reboot(self): + self._boot_guest(smp=3D1) + self._expect_rpmi_firmware_and_linux() + self._validate_reset_reboot() + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0') + self._validate_system_suspend() + + +if __name__ =3D=3D '__main__': + QemuSystemTest.main()