From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021105; cv=none; d=zohomail.com; s=zohoarc; b=QwYL4TQNmSYnc05RYuiYu/MtpioQ0IUHTN1RRFUIr4JgUU/74zEuh2aj5LDnjNu5RQFbQlci4HsoMDYgw0kWdevQnu2xFokALWudbSRsxQx8HvRp5FL2TVFjzbbqjdbl+iVJWkFQZCLZ6tkJfnt2pFvBaTqK79x6tW4sCogOQ7Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021105; h=Content-Type: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=c7Apu//vZJzbInnGD9i0yt6UetOB1zhCDAWsiR8yYUY=; b=itjs1Ugr11CK/FCfA79JYESfLLiZo4vLX7rOvJnPCXQejTNFNckyf4CFdQM7/tLnYAxhxQg8TzwqK8LFB7BQfhagsnYLaisxpdzeOTTi0rhlroh0tbwF2cN7e20NwPz7gYs4GeObZHxzlCIDifBvi8Ez0JBmYvfkaTykQ4rHqIs= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021105005963.2672013347583; Mon, 26 Oct 2026 06:25:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKfn-0001RU-O7; Mon, 26 Oct 2026 09:23:35 -0400 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 1xLKfl-0001Qs-CR for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:33 -0400 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 1xLKfd-0005Dd-9q for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:27 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69QAt1VV2732889 for ; Mon, 26 Oct 2026 13:23:23 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 4hj4cp8uhx-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:23 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-35d7e79abedso276363eec.3 for ; Mon, 26 Oct 2026 06:23:23 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= c7Apu//vZJzbInnGD9i0yt6UetOB1zhCDAWsiR8yYUY=; b=NdtK6cIJia0HO/iF JnpOfVI65hiQb23kV1DTUmyU9R7zzxQdCUxnDPwXa2dTRvVa2SSBe2UpaWyWIcOb sWCwUJohM7duR5Zmf4ZYGW5XzPPUR1LUm054E3mwwyG4lieCxLSSp6AzJXukbuSV chzxZVttxJCNwQAnvEDH/N2aMQ0yRRPgjmlnRNv+bz1P6rLADp1tM0+q4ZS5EFWq GRPeZL9ImQb+4rorXWmIbSAIal5eVJGbndnvtw4GX4jpTABjPHtZuTYpU64aYBgg qO38Lj5XB1WTU6hKDBBPXgZmLx9ytuQtWCmRqsQrCv3rfed2/CUwkpALQuMtmCvH p3fJpg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021002; x=1793625802; darn=nongnu.org; h=content-transfer-encoding:content-type: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=c7Apu//vZJzbInnGD9i0yt6UetOB1zhCDAWsiR8yYUY=; b=T8vPoVMumeeVxyEBTUipi6q3T6kXRz8Ln0GrEqeDD0s9g/AGO6uJp2zWWM70DWGXU1 cSXDD9FxbLCHuko+QHOocaX+2W2c2VLLbmB2kxrDkXzhV00Ellxz85e9zG2ADHSgJeqZ XFliw3pas0m5oKGGiI6VQUxWiNdbMxropGWBS4kckCI1T/M6TcQxDMx49b7XCOtnwtXH Kq2Ex+Lr4dctdnPVwxU8RxHsxjyfhT987hXPlei3K19FJSPYzuBpamxzT4oKQYIdGTYF HbTxF7IGEQg9nZ6xCYrFPf0+DyM+N9kE8yMn7uCU5FCqKkBW/K4An1XAiHzU/O1dil/Y 2o2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021002; x=1793625802; h=content-transfer-encoding:content-type: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=c7Apu//vZJzbInnGD9i0yt6UetOB1zhCDAWsiR8yYUY=; b=oMLZ3WJnlY0elyT2X62pHW8TW8qDRvSCSPkkyHtthFKrXye8ZsZcEkrZ6VtgW77N/P ssGIV9DLtUKOp7hGzJ6glCwRHsuYod4+NqftEvCN5usCUH1H/X2EagOs1MQxbOnBYG6h LclCm7e4Gx5wJa7KrWQKst0W6fVPNnEQLTaSP1eUUX4L/ZOhfLFB4/G3+OL119ggv66N esEsYrM1DtV3On77C+GLw6bE0ksnzgtl9Y3gJeQmU8PczjfLWdND4PRQow3ECX4o39Yp 7srNNC6rlMLPjul+/uJMaFm6UULZv1pw0PvvHdtiq99CmkqMxQ2IIGPUwaMvVrSpB7PZ zTow== X-Gm-Message-State: AFq9FYI1uYIc2C82AvxpF3UcFDDxToEN7GrJsgMO5BH7uheaZanvKP7G KFtJ0Fk7W8eMOwxNR3UJZ5pmKQ1BHGYllotH8u1uD1OjiQqcoehmZmgDkyG8vUVZEE4n+lfC3Ij RJuWakeQ+Ya1p68M6gopSckbaVXHhQv6QjyGh6ydscx0kcAZ1zNS4GJscR50nCDLOXg== X-Gm-Gg: AYBFou33vrNpBsXofqls0CReC8SDIkOXIOVGItWH+aKmMelC1jWA/zx7DQkaPbzlNPG iGjf0rbAfsstnvDf4ICPgr8FPP3NyvHJjY1AlS0enSkHc35IebABgmC6VAdoQRrolMNIwFAYoc1 vSsf2iT4jMzSLVzRCM1j+PMe7Ttl1jopPVqtNCPwYspzmJ86qEgD90QGa9pNvM5uEa49iF42/um pU8hSAZ2JmB7oJfuLAeE7V+0MXMtcMOPR7HhrL2aVIHJwrZ2pcswrSs9zWQBypaF4Z00h7UzStI UZKfvi5BAdyQJcvQrTSgO9Jok2Jx5VEqmiVtICT3MUPkQ68PZglnHUHdCpIgmrf+8Dg1q9uc7+V kKwX+hJX596vHnxKafqZsUqgE3r8ZvtMJwd1mD4gKbdikug4cFVI8jzbMN2h+jUFbCgHF0/mQz3 um43C5g6s48OFB9KCg3R2lxgka0ZVfPYQ= X-Received: by 2002:a05:7022:7f05:b0:17f:641e:7f6b with SMTP id a92af1059eb24-199345c5ecamr16603888c88.1.1793021001722; Mon, 26 Oct 2026 06:23:21 -0700 (PDT) X-Received: by 2002:a05:7022:7f05:b0:17f:641e:7f6b with SMTP id a92af1059eb24-199345c5ecamr16603815c88.1.1793021000898; Mon, 26 Oct 2026 06:23:20 -0700 (PDT) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alistair Francis , Sunil V L , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v12 01/10] build: add optional librpmi dependency Date: Mon, 26 Oct 2026 18:52:44 +0530 Message-ID: <20261026132254.2652399-2-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX6yMk6d9bjSaF VlKbdOfsM4kNOrqt2G60IbmpSo9KRwKX20DIunAkw0gsw+/zIdJ7Zrks/6En4UE0CU4AjrX3chS trPFYnmohD7s/gIhuBGUsnK4Tdh4LQuiCXaaAIJDE2XbkgyxSRwbdP7tkcRe6n0+pTVFdTBto8v q/698lWlmGPzdqIL1LM5QPDp0CWEvWn/DSQaxwEEBCJwlizHJbIWPxzfr7HiWP8m8sUXpYas19Q X24FZMeubqaqs/WN2+gASqZPa3YhWQCHs8iFgvNq5QT4xOLlHH7mBs/4pxXNXL7RaBy8FhgZPkI mrQRJgiOJahfoOA9LINwDDfFM4fZCIrkMnXhEYHuxS7bQN6xzt+FU1xBZVu4IULd8gYeWredmH4 ubaEYI4D5XComhyCGSu02sNPQd5WWyOQrR7nFw12emZZambZeegjHepby+Dhzu1EZ57ChnCWQoM 12r7BBme478/1SqIxng== X-Proofpoint-GUID: oM0eIeT5Z0-w_c2yS2LrRpxV-lhBqN2a X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX2PW+MBKniIsm fYJ7POcCHwLP3vlLPrS8xx2goVcOdKEuBYNhPF4rTiHpGPA0+/FLoYkFWqNileGKI+QEcdc/tr9 8xIiYpWy9bW/AViQu+v6RqG/l+x5zSk= X-Proofpoint-ORIG-GUID: oM0eIeT5Z0-w_c2yS2LrRpxV-lhBqN2a X-Authority-Analysis: v=2.4 cv=TboDJhQh c=1 sm=1 tr=0 ts=6adf544b cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=EUspDBNiAAAA:8 a=JF9118EUAAAA:8 a=ZLPlHWeyiUGg96gsXukA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=6Ab_bkdmUrQuMsNx7PHu:22 a=xVlTc564ipvMDusKsbsT: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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 adultscore=0 malwarescore=0 suspectscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021107025158500 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. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Reviewed-by: Sunil V L --- Kconfig.host | 3 +++ meson.build | 14 ++++++++++++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 +++ 4 files changed, 22 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 4f29bc6cc3..9c4d501687 100644 --- a/meson.build +++ b/meson.build @@ -2026,6 +2026,17 @@ 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) + error('librpmi support requires the RPMI system suspend service group = API') + 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 +2460,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() @@ -3280,6 +3292,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' ] @@ -5009,6 +5022,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 895c6e63c2..ca54c6e731 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 14990966d3..0b78ea6fb1 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 ;; --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021091; cv=none; d=zohomail.com; s=zohoarc; b=KvTaR7w31Kt1k5feOKYsxl4R9A+fxygcWenXEtpjAT28Gd1tae5ymMyCkw1QdgKlbYT6ixIYa6xr0bwn/AmrxOZSxie1UEIgQQDG12pjmovY5BZMx2SZXcE6IZOtGNCiIDHxcCpR26ly82CSJYHK1+w0qkG6wUitK9CxBDhpb1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021091; 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=Kl1hhSbvwiAPKCrR/dOh413ogUAiab0E20vuyNAe1kM=; b=IocMBAV7AIc5wHitkq81PS9KeagI4f9v5spXHrFAemJXMrBBgnqZqbTvAdM1EYr5Xg/dIrJSPHMT2C2hlrJNvB2u5zI8Ma02kqJTgBvfyzdwY00yU4DDhUfWk4DhU+nxVIM8T6Y1C3hutbBlUB5zDhSma0USPF9VmQq8rqOckRk= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021091400223.6949180837945; Mon, 26 Oct 2026 06:24:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKfs-0001Ts-20; Mon, 26 Oct 2026 09:23:40 -0400 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 1xLKfq-0001Sk-1m for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:38 -0400 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 1xLKfl-0005EA-4t for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:37 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69QAt2tm2733255 for ; Mon, 26 Oct 2026 13:23:27 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 4hj4cp8uj6-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:27 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-34edae32c04so433792eec.3 for ; Mon, 26 Oct 2026 06:23:27 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:24 -0700 (PDT) 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=Kl1hhSbvwiA PKCrR/dOh413ogUAiab0E20vuyNAe1kM=; b=jOqpZSIMJhXon29AHro14BQdtU4 +mbugXWVTaBDx7G8EtjF4T7ajLuePg63VnKr2sSRnA7uJvG12w6Cuvhh3n2syo6L pRo6+c1xDP8WEDdnOOzO9AGyWF06F4XFS5lMaHJBi1UM+edPCri6Vo6DIlCncQLv FTqHDq3NFfMM40/oCImmrWN7ed30uoruJuQ+48sNut+0U6MwxBUMVpbiD0+FsX8Y 7iYsujj2V0MCQkt0fBM33tnZXEeEJyrAhqxfsYZu9al1etufMDksu4XZaRC7cea2 UnXIvvTWgW18M96oBDa2kkT+bYjQN4omMkPITNwHuoI7/QAAarL8TdhqXkA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021007; x=1793625807; 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=Kl1hhSbvwiAPKCrR/dOh413ogUAiab0E20vuyNAe1kM=; b=XP8peFTFDxPbAecwphc0wF9QDRIY46Yj9aix7Q2tFFpNuWCR3Ymu6+e9AtMIi+76ZA OznLYfb5EbSVcDcmNzffrvm+47wbR9iiAugMTK6iIiv3g2FQ4g0aYxzlNq4TtUQXSyJ2 3z8hPCsJLf33tWi5a+8O6q/5Hgn1HtxriiV/la2bzTBxMmqVz1Beu8T4E6r2KLqS5yDw ImUlscwCygnB4zYETPO0qtEMj6ee9AEQl1ZpDQJZvYwiOJ940EkzHsw9nQGexzI+pyE0 p7J5vDtwt54W0D0U6gsXSCO0UVoTUJ0aJJkoJp41T/GGGMDJbrr0jKGL/FYIJxjIWAgB 4LCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021007; x=1793625807; 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=Kl1hhSbvwiAPKCrR/dOh413ogUAiab0E20vuyNAe1kM=; b=SkUBlEp6kxihJxuF9nSQvzK0waF4tZGfSE9FZQWw88dDknRe76r3MwldlhLk69T1Mk IwoZAkxg507OHbil58x3tmCJScSL1jdErJCw7I2ZNkhCJH82T7r8szL+isfAjuBaZug2 59gys5Txmmg0KnE7P7R4E+onjlgjiLx4tu9T8uTmCStN2a7clLD99lnoG6ApwrGtQhjo pk8rG0kULAasd7u4vyZDcEVueMXHQySvF4Wjcf0iymOzUVekvTv0MPgEukPktabI5OdO 9+3MyGEpIC7nGeOAqpHZpls9rKHBn9Z/nRis5AQ5kto1mnJ7jzd9yoASm1L8PSXe3mAV lYAw== X-Gm-Message-State: AFq9FYJ4n9+XrSvBTDXWOOoRcm1b3IK0ReE1Rr0jTM6Gomz3ow7SB7ap ah8Bu1IapqAg5/zxO/47lLsyuZrgfHRpx+SmuFqwMhcCHRzN4YGFLCiUkQWvPtkjt7XOSs8MGgz 3okncMYzNWz1wGExSNIzPw10pm1FkWUiUbr8sX6YG+KKrU791Jgzlof1AzVQKFV6fBg== X-Gm-Gg: AYBFou2ipbWjSXZrTdx3pJ1KAnfdP7f+vZqEzCEp5FJl7xrz9QB2ATO65bo1jf2kKPI lWTW+7BZ5/peJNXwr40gWNpBpQFugyaplY5lwfh5hn+tDMK6XEwthENcD58F5bI16ikPPGR9oSp wWl3fOHEd4UHcaPHEVWathzMxwOWmdw2ddlBZKp8gTpJmPvDNhsYo+rFzqPBSvLj1C65WWS9BB7 7/BJ33WMxjyrAX31+ApAe6A04Bv5DlrfuZaFz3c4dOYl0I4eFzlX741CQuGr0QoXvuL+QTkLZ9A 0S2Juz3/o0qsco7q5wwjSe26KtCHL0ntLmzuwUg4EOS0QS0JDVcJIBS9YJiyp29kd7XBYmT4rsi 8MTYJmzyD87kOsT1WpB7S6yTkchs3cgoVES6+hlcDp9k4Puyi1BBSCEOOWySo3qSS5FpMK8RPgZ f3fUmx2UbWOruNUdv62WbLz59rWp36/XM= X-Received: by 2002:a05:7023:a46:b0:14b:edb2:c3bc with SMTP id a92af1059eb24-1991b9e5d7bmr15737068c88.0.1793021006017; Mon, 26 Oct 2026 06:23:26 -0700 (PDT) X-Received: by 2002:a05:7023:a46:b0:14b:edb2:c3bc with SMTP id a92af1059eb24-1991b9e5d7bmr15736986c88.0.1793021005105; Mon, 26 Oct 2026 06:23:25 -0700 (PDT) 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 v12 02/10] hw/misc: add RISC-V RPMI transport and Base support Date: Mon, 26 Oct 2026 18:52:45 +0530 Message-ID: <20261026132254.2652399-3-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX0yHAjOCt1vM7 ksXpDdGsiWNJ6kJfmJDBfvJ9fUa0FpoWKb0YTTDjUi0qS00APS8WRJ2mxPHrAI0hikRNNgum+tL fq8iOUElXR55w71n18QgwLjVrQurBnQrEWejkkvQpnTfS5P+W4L+J9a/lB6IqTSs/DZCPOleDZe WJAScqIb11ZJLlHgMC2C+p6OdlK3Us0y8BjOwDnyH17+m4CbisU8kNWLk5DZ/RtRGig8Lu/6XZx 0Rq00xKi0Qwtu5Zm7QhG93F6QfQ5l2+nl4xBOrYfIQiCYe2EIyyMRm/0rUnVMJddnbypPpjc3CE miJY2ithRhtHkMGffbSSnpQcyS5Tt5ACOwjkZ7PJxPzoiUvakbvdxfKeaetpyxMkgvCwFe7AJFv sexCJL8QQFGu250YbjVl6oIYeBip3QhoLgq7XES0pQyArMTrTmlROfn/p5yCWah/KSrpMgyP39m oMaAh2fWNBy22O5IGSA== X-Proofpoint-GUID: OaxjpxptXVmegDpLgQiisBJM3tb2KLmq X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfXyxVgBOATGUJ4 WaDFHnBOyZ+/AnWB7lpOXg/yWN4IolD2TSqvnMqggXs2u4POHUOZgA4FT8zkmDtCs7b6COPCgMu vBPxXl4hhDnyDtxcvVrv5tUh/ZkowEw= X-Proofpoint-ORIG-GUID: OaxjpxptXVmegDpLgQiisBJM3tb2KLmq X-Authority-Analysis: v=2.4 cv=TboDJhQh c=1 sm=1 tr=0 ts=6adf544f cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=V1jnuoLLAAAA:20 a=NEAV23lmAAAA:8 a=hwM_GrIuAAAA:20 a=EUspDBNiAAAA:8 a=wBPrJzG_k3pUc5KpXHEA:9 a=scEy_gLbYbu1JhEsrz4S:22 a=bA3UWDv6hWIuX7UZL3qL: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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 adultscore=0 malwarescore=0 suspectscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021092482158500 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. 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 | 3 + hw/misc/riscv_rpmi-stub.c | 16 ++ hw/misc/riscv_rpmi.c | 505 ++++++++++++++++++++++++++++++++++ hw/misc/riscv_rpmi_internal.h | 24 ++ include/hw/misc/riscv_rpmi.h | 95 +++++++ 7 files changed, 649 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 4ca1751e30..b0afe3fe0e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -376,6 +376,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 7abd22869a..0b8e28f72c 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -267,3 +267,7 @@ config SOPHGO_CV1800B_CLK bool =20 source macio/Kconfig + +config RISCV_RPMI + bool + depends on LIBRPMI diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 90f3f89de7..3e298a74c8 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -181,3 +181,6 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('= sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) =20 system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_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..c73408714a --- /dev/null +++ b/hw/misc/riscv_rpmi.c @@ -0,0 +1,505 @@ +/* + * 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. + * 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)) { + rpmi_context_process_a2p_request(s->context); + rpmi_context_process_all_events(s->context); + } + 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; + + if (cfg->hart_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_id= s)); + } + } +} + +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; +} + +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_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) { + error_setg(errp, "RPMI A2P request queue size must be non-zero"); + 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 % 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..c0cb1b64e6 --- /dev/null +++ b/hw/misc/riscv_rpmi_internal.h @@ -0,0 +1,24 @@ +/* + * 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); + +#endif diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h new file mode 100644 index 0000000000..93d128f2e2 --- /dev/null +++ b/include/hw/misc/riscv_rpmi.h @@ -0,0 +1,95 @@ +/* + * 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" +#include "qemu/notify.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 +#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 VIRT_RPMI_A2P_REQ_SIZE (16 * RPMI_QUEUE_SLOT_SIZE) +#define VIRT_RPMI_P2A_REQ_SIZE 0 + + +#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 --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021108; cv=none; d=zohomail.com; s=zohoarc; b=BXCvutgnyrdf6dx3K1MJViajmyYeKEyxQDe8iW+tkGG5HB4qFAZ4XL8jHGd9blBdXCf2Ms6dwZc35ONb6abfASGu+RbJ6j5lcJFjIi6iEhPCBq4eiYLzzVVWpBawJVb86epa85B3DyQXDdgEQkI9OnrAHinHkLHMSQTGhAKSCIQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021108; 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=zf8SXWPwTle7JSE8aHa6ven2gctQeVgaW9MEcdAKbxE=; b=NkbpD3eeKf/n2Cqwso+LPEiH2gkVNl1HWrp/Ic5ukFkM9jz0WmIdncSg+mZlkfY62BeYiSfGJ5DmS3aH5u4wrXf8D5KBhwk1IjmXfezi5reUokS8owOgtbyX07X0nAB0t23LwYLDVYiN3m9wNpXvfEbhVDzfoJARJLSw0TzDz6I= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179302110881638.74873042436104; Mon, 26 Oct 2026 06:25:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKfp-0001SL-SJ; Mon, 26 Oct 2026 09:23:37 -0400 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 1xLKfn-0001RQ-9m for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:35 -0400 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 1xLKfl-0005EI-4G for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:35 -0400 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 69QAt42Q3633158 for ; Mon, 26 Oct 2026 13:23:31 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 4hj4sf0qbf-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:30 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-313c7315becso550446eec.2 for ; Mon, 26 Oct 2026 06:23:30 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:28 -0700 (PDT) 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=zf8SXWPwTle 7JSE8aHa6ven2gctQeVgaW9MEcdAKbxE=; b=ngE0zPegl50D+ymev/GzeC23rlR pIqD0R51xLs5j7Uwn4Ja6o7iHm4w+VlrZR0QtT4qR2szk9rB5cIGLZBh5MXxXEU7 taPFHD+4njPn6cKSF2ymeFARuNEiHnYYcFvJzYqNl727Txfxu5Q253f1Klb5lZp4 gmhmJmIs2JuMs+PX+ljXk+sAhUqxMVuess2AMjKaFabX975lMhQCXUNLSoCFPhLC TaMemmVuHY6fpB3fUAxgy0KfkSWKIZVVTFCc+omko3qmhIdA1KUgv31G70FfSzcS dYIehDS15Fmmc7qX/kGjbKGiAW/eocssYWMIuM3Pxm+hA8yB0QECh5nkwDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021010; x=1793625810; 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=zf8SXWPwTle7JSE8aHa6ven2gctQeVgaW9MEcdAKbxE=; b=cxCrSwjngy+Y+AtDTrEx56NDRokVsXEC6TgaLCh0CqQeRVggHi0k/JdLmmqYIDRO2u Qpf6c+1yVMMyOXMVfztodAB18Q3RFW6gL+auSas7547xJtEpBsojsfSKxE0oJ0nHTz8K 8+fepwQgh6ChHRd6CafGL0Ar7XWNwhpsiHTofMY2+1dViSXw1i4cG2+DykMY4vrRPMDY harBUpY1+lDGA7Zd9/ZLS+yeE26TiOHIogq9d9eI3rfXfj5vFTmWX/h6MnjEhgIp4sx/ zNOfjKHEKew4Tjqv4aj0m3ts0dGuytCGfI9BlG/nHyay4KXNLSO/1P0T7wNzRTBTZW52 dmqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021010; x=1793625810; 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=zf8SXWPwTle7JSE8aHa6ven2gctQeVgaW9MEcdAKbxE=; b=aC/7Hway7G4Iw+xsdq9ANNkAyU6E4AL+nZDNTkYGL/sqdtcdT3vk6ZgN5sht1ENCzf uXwR1vq3z5GI4HlFA6yUfCgLzR9W9/P5nmE7gDuIKMaRqFdp3qBase/yWeazUOvqN/Ll s4oAsVSk9KA2xPptzzS8uit3SPHR0w1Jr6w++4WNKBXmQF7V9SxsLis9pxkpcKFO0FLO mr+6MMr27SR570Zc4MOXYfiKONgaANIV1Q3Ef2KYmiU0N8/lmRTpX89uAE7HuOo15gto THhA2L3m43GD2DlBWzyM+AWmmQ/SM/mxRZMfeIKgyYsnI9HTutI5HwjkgEj1fwYyzuan 5YjA== X-Gm-Message-State: AFq9FYLEkfJFCOGrz8hzAwYayucFDTPR1Y5I/vzvkK8ji1s0ioGUBTw+ IoP1Mhqqmxjt4hTyhkU++6onUgSJnVijaNGC+wfnbJ7UDMcPMZs7IVZMu0xFz2bmQBStcFz3U+F ZckDwpXoLpdSjt46icozASwdHHxDG9di7Bdkji8EOM2Tu5a+CILcFfKYxxsu5e7VDKw== X-Gm-Gg: AYBFou1SiqoiG8B4+7lxRWRUdcMxNEUifFUtAUAXfI+BwrrJC3YDgCGSAhPdzR/pj3f qBV19NUTwyMes1INw7DBK+ULWepb8RedyLdV0UKwNUy1OnrT/J/U/Hu8dR/arD8SX1MPzpb8S6Z dtwt/u7haRTqAimiPOi8PbhaO9JXp1kjOZYaQ1fZQpDDD1egaEQGFWnTgWnv2uDxG3wByDOqp2h HLqLiWCvXAoM2Ua4lqm9otuBuaNWZvhVhAQyj4VJ9HczLd5/IKYwAe6F6rue8uxpgISS51L0EqY javb5GeASfiL1gksp4FGu767VUk4aGWK5QDroJjyugmaidkCfh1rB8bfXDyrFYzq86eSw9spQiB PeoAQrO/pMz3CRI1pZ1dgDJZycrENK0mTG1qe1oduS+fl/NwUsZPVHImuKPfgGB6O52iyyNdjWH 1XosYwH/EdyPjI9lUvvxlPlKVlwQhjQqY= X-Received: by 2002:a05:7022:7e0e:b0:183:d275:cf76 with SMTP id a92af1059eb24-19934a9266cmr17464661c88.2.1793021009685; Mon, 26 Oct 2026 06:23:29 -0700 (PDT) X-Received: by 2002:a05:7022:7e0e:b0:183:d275:cf76 with SMTP id a92af1059eb24-19934a9266cmr17464595c88.2.1793021009074; Mon, 26 Oct 2026 06:23:29 -0700 (PDT) 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 v12 03/10] hw/riscv: add RPMI FDT helpers Date: Mon, 26 Oct 2026 18:52:46 +0530 Message-ID: <20261026132254.2652399-4-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX88GLPK1Dat3X Jh1TQ1Blx1mTJOhG6LCyl3LnEGGUcxvDcTb/eyKP/2lqQRDvJ/j4a3Ee2yEN3AkTo1xtH4UGcVr 6UJ/1tutlYAIE5MBxSs7Iwi75xVnP5g= X-Authority-Analysis: v=2.4 cv=ZOdCCn7b c=1 sm=1 tr=0 ts=6adf5453 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=3WHJM1ZQz_JShphwDgj5:22 a=EUspDBNiAAAA:8 a=A4YYoHtc6PVOd8TWIokA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-GUID: SgDXlYSPEqAiOK1nOhCcuXE4N8HtrKRx X-Proofpoint-ORIG-GUID: SgDXlYSPEqAiOK1nOhCcuXE4N8HtrKRx X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX6LIUKGuhlw+7 0ZpXs8botsQt9Ha8jWdVBaXIrdRgLZpRafD5Ngn6o29kNtglAJc8F3AkBiSWGKFzwP7blTMb/hb 6Wt3NTgKP9B8lZCwhcpZjcu2P1Aby8f/oLYqFLdH5ZuuUVVH1YgThb026OZ6ATOJcMaAwegK0lF iB/RAuF7MjpUTuWS3SneGgeGC3N/zrkJX8yI3NrfKJ+rhE2+dYBdqHH74b007EaGjNOyGbUe7/k JEF8aEoxc5q6DMbME38Qm3HEJam79og1baHQ4eENobXL9P5VVoOwHx9nyDEx+YQJ682y0C+J8DF eEpLMxCl2eY6Jk+FLXqwMOUjxZE3UvUivpqYovynJbiC5wCXDvwwcpdodUg0yH+rQdzSRQq01r7 9CtpZEI+PEwcKthxJhJWmqerFIkq8PnjWmIQaqjqjt2XOmDXj0E1P95XoTBqYMmt8HPqwXnSZBY TXzBiHqRsb+2RhXtxlg== 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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 lowpriorityscore=0 priorityscore=1501 malwarescore=0 adultscore=0 spamscore=0 bulkscore=0 impostorscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021110769158500 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 | 36 +++++++++++++ hw/riscv/rpmi-fdt.c | 101 ++++++++++++++++++++++++++++++++++++ include/hw/riscv/rpmi-fdt.h | 40 ++++++++++++++ 4 files changed, 180 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..77995f88ea --- /dev/null +++ b/hw/riscv/rpmi-fdt-stub.c @@ -0,0 +1,36 @@ +/* + * 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(void *fdt G_GNUC_UNUSED, + const char *node_name G_GNUC_UNUSED, + const char *compatible G_GNUC_UNUSED, + uint32_t mbox_handle G_GNUC_UNUSED, + enum rpmi_servicegroup_id service_group + G_GNUC_UNUSED, + bool has_mpxy_channel G_GNUC_UNUSED, + uint32_t mpxy_channel 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..2110d4457e --- /dev/null +++ b/hw/riscv/rpmi-fdt.c @@ -0,0 +1,101 @@ +/* + * 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 "qemu/bswap.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; + 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; + + *mbox_handle =3D (*phandle)++; + 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", *mbox_handle); +} + +void riscv_rpmi_fdt_add_service(void *fdt, const char *node_name, + const char *compatible, + uint32_t mbox_handle, + uint32_t service_group, + bool has_mpxy_channel, + uint32_t mpxy_channel) +{ + g_autofree char *name =3D g_strdup_printf("/soc/%s", node_name); + + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", compatible); + qemu_fdt_setprop_cells(fdt, name, "mboxes", mbox_handle, service_group= ); + if (has_mpxy_channel) { + qemu_fdt_setprop_cell(fdt, name, "riscv,sbi-mpxy-channel-id", + mpxy_channel); + } +} + +void riscv_rpmi_fdt_add_service_node(void *fdt, + const RiscvRpmiServiceConfig *service, + uint32_t mbox_handle) +{ + riscv_rpmi_fdt_add_service(fdt, service->node_name, + service->compatible, mbox_handle, + service->service_group, + service->has_mpxy_channel, + 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..5b8c44ad20 --- /dev/null +++ b/include/hw/riscv/rpmi-fdt.h @@ -0,0 +1,40 @@ +/* + * 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" +#include "hw/misc/riscv_rpmi.h" + +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(void *fdt, const char *node_name, + const char *compatible, + uint32_t mbox_handle, + enum rpmi_servicegroup_id service_group, + bool has_mpxy_channel, + uint32_t mpxy_channel); + +void riscv_rpmi_fdt_add_service_node(void *fdt, + const RiscvRpmiServiceConfig *service, + uint32_t mbox_handle); + +#endif --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021077; cv=none; d=zohomail.com; s=zohoarc; b=lyr/iLcTyycng+1s4YGdZakgDlYRMQTVAsxkaH0DoOQr94k/uRZXrFh07pEkHyLqBpfhNcR9WTP8iijut/HK6OJEdoRkUyl2Fnmv2drSejepG/eK3Dx3F1kk54QVkcdM+jfwg3kLAA4DQKIqOeWSGdVqJqDfI7hAJMmeIsHcEFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021077; 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=JY6PW36Ycz6PF6cSIf5XDLnEYJidKUv3EsSSHn5rJqw=; b=lzzLCkrmO4/lU7nEII1/JPjDibxg0Sei51QRGPbqxeBuNMUvvEW2mh9z0hUiUHN6zlgCC6Rd4jYp4jOpZnlsRx1dbcFXxrwmP/6np5t+OnNX0UOoURHTFpABFGRHaEDMUlIMFo2qHKOUBTf/1op/WrwDrSq7VOoEAXtpmVAIkFw= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021077636413.9982368362864; Mon, 26 Oct 2026 06:24:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKfx-0001Up-8F; Mon, 26 Oct 2026 09:23:46 -0400 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 1xLKfq-0001T5-F3 for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:38 -0400 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 1xLKfo-0005Eu-A1 for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:38 -0400 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 69QAt5NH3034427 for ; Mon, 26 Oct 2026 13:23:35 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 4hj56y0knu-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:35 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-34edae32c04so433813eec.3 for ; Mon, 26 Oct 2026 06:23:35 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:32 -0700 (PDT) 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=JY6PW36Ycz6 PF6cSIf5XDLnEYJidKUv3EsSSHn5rJqw=; b=N6iUjz05aQngnswcnFEHfaPRSks 0zxIUfbC4n14sjXpXcviyPQpDsFCosq/WK+n1ermCwIbtmXLbPwuAbQGBm1KjqJT D3LjCCjiuEoo2CQ69GQGLbBmpYx2BeES+ayBUtKGb9KaZMQrRRQz7JBmxeInHzZF VWNLiCmXYQoLhohrCyi/uXOmPFPHYSBCBoqskzF7tBh9Z/Sfp3XQzrxVYMqiDqAf 5QziLwJQ20mFNCaE8e0qTuk6yu3P6DhDA2y9wufXqsrVCY/FlDv4CMNbyxr0z0VG SjGY17N6mHiHRfH2SZG9UeYf/2ZhyoNAydHjiWkZJmVz4b3GOj89fD/v6WQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021014; x=1793625814; 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=JY6PW36Ycz6PF6cSIf5XDLnEYJidKUv3EsSSHn5rJqw=; b=iZvPWgMtbc3E5Eazz+9CeGEWnr/TNqfuRPfEeqBFXRIAVt/MW9xrDCXeBs6f1blbJA kQ0d8Y9qa0nM+LyIaI12aM0atWK/jAKHkP4BZqphHPxWjiwKY/cLG6TAzIJyY/B6q14V yKjADtXkPxUG9F0p45q5TdB1INbzxUW9nPcnL2x1Xq5b99Cb3vlWOJ/PJ30Fo51yqYP8 Y495BDxUUW78Z3NVqR9+7cBiIIAwvZ/ScPvBeW88peoioPuRLPkE54Aewe6WgSl6SQuX S3C8Dx4PMMFUUB+3aAujBL7EAb+vYmoZA2Zh9e4Gs49ITrpsrJFATc2COzfzqYplndMv GBhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021014; x=1793625814; 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=JY6PW36Ycz6PF6cSIf5XDLnEYJidKUv3EsSSHn5rJqw=; b=YtpQ1xKXbpRU7mvyV0tlS8ObmBdkBEZnsR4e5rZbF7Uq8p+/2xX35uWYOk5mxtZy8i ZdjqqNzvXpso6QdeuI46QwU9h3f2z4DhKgyrGCvLLZWXVmO5Y+tlgiwkSg/bKWVqf4BZ Q4w/4+3XAoUi4F3sIVMgbHOIdgzlahw3kLvwDE1FWpEiDkwm/58X1+z45T+3Dlp1axLg R4at2JLiXfszH8bpnuTP3O5wz+6/pQblPTIlQwr8nYd3065HKOzcS4rykCTxLe7WLnja NaW8STK0TIOKl1/9o4kYwqVZ3lxzhrjwORjWua0pFjXsbKbK8rJj9/7tbUOeS2iqmNw+ NrMA== X-Gm-Message-State: AFq9FYJWME2/q9Mc+v64hFmHiWGwicmu03OAVcyKq5N9vz3LZ9tc09Fp Wc5+bvKB6fN9FP3GbhR+JZbZdYhSa5na+i4kHpAk/Q14p5s5GRCasZ9ActB95lf+WqUGQHj8hBO /Wen+f1LbGeCLrFn0HP8eDv4vp3/paGsu4bgrsgXWPf0f2snXjh9CK14kzNuEmTzFEw== X-Gm-Gg: AYBFou2gEj8yGqOoe9xIaQrypvWxQTFiA1SkvzpOM2SHjTFG2lK4mKc0wN8ykjEhq/w weu74c1pCUI2tgnVXvSpuIb488DCgmQsZ9Mwondlf3OsAHIqhZjbZ3zY0e5dfxZ0G/Fmwok9+bc +kmH6Hu3oLnbo9X1M1I9BFpiqzH53doB2syhQvenVqKMsv7Ea6fD3HAQ7pyfbvYNfRoFRQhpNZj qz9LdTjD7xpjdfj3CrpyQOgavDAPZxbEEMBQtkqhuZ6ZwKxw1jhJWGmKofKqCWp1a34VySRt0e9 HmVxXiuj/bstcJFg0tPC9JfwS6oGSqeGphjE6NkR43/U4OMfNH1t/JvEe8WR1xjkA2zy31WGJug UMYvBaSckGh2tZH7FmBLtO0e/+IaXh3XLhcjgLW52fAg5n7DKKL433k9LrDeg72h7GMKT3aYaOj 87+LZEhyadsdbhyjuAsKNUlzv5oIVLG8g= X-Received: by 2002:a05:7022:5f07:b0:146:ffa9:2117 with SMTP id a92af1059eb24-1993639e5f7mr14995238c88.1.1793021013971; Mon, 26 Oct 2026 06:23:33 -0700 (PDT) X-Received: by 2002:a05:7022:5f07:b0:146:ffa9:2117 with SMTP id a92af1059eb24-1993639e5f7mr14995180c88.1.1793021013251; Mon, 26 Oct 2026 06:23:33 -0700 (PDT) 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 v12 04/10] hw/riscv/virt: add opt-in RPMI base support Date: Mon, 26 Oct 2026 18:52:47 +0530 Message-ID: <20261026132254.2652399-5-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX/HzfW7SAjcDX DQUq5ZG5P6kmqbq9CTIZxpq/k5UuXFFneKcwkHUNV3H9UCAd+FgFtVfjapgr9VOK65cd7DduoGo heL3scg5eBWLOISh4+x1pvgfyd4UROY= X-Authority-Analysis: v=2.4 cv=eMeGH3p1 c=1 sm=1 tr=0 ts=6adf5457 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=UqCFv9FlzdzCN5i-bQEA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX813TEoKTwfHX P7KtQVBNgZO2zlW7Eu/yedcAjWrry3bzUSVYNrV/oFNIfpYZzfc7xGBZr+CK6wCgXmzBlwbcJgr zomw+u/UGWbAcCZ05OHhqeDZbS1dbbDa4Fb/ic54sbVhWC+M+oqEOOUfMQo+QGhW/jguYCNP9S4 pRFYT1laCIp9/FwucaYOkNU/UgHsrQwJebqqEo7Y3nPedAoWijyQ7lVT1yQvFZTGl461Zq147rK SVWWW8lJyY5Js9Il05hG160GTR2n9CUNDq0Q92A8Ap6+Q/2Q3uz4W/yu0yZVVo+aMj83MbCHgcM sC+deaTbu1KDPxVtE80IHhsABxOSw7DGuAs2ukxiuo6AUIGdSE9plagJ5fp+5pp1QpdTcJCrJ1p URPrAVYw396fI685iPiIkcT0cAWpFHt/sK0S5E3rIYcwjuADm2vJYQ4kGACKwWZRw8amQA6LEYJ Ad4VRzy9xjF4I1gatqg== X-Proofpoint-GUID: MwZVtwRAPUK88bo3aeepO0OTDpLnvE1S X-Proofpoint-ORIG-GUID: MwZVtwRAPUK88bo3aeepO0OTDpLnvE1S 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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 spamscore=0 phishscore=0 priorityscore=1501 adultscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021080558158500 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. The option remains disabled by default and requires TCG plus librpmi. Invalid accelerator/build combinations fail during machine initialization. When enabled, virt allocates the RPMI shared-memory transport, creates the RPMI device, configures Base service metadata, and emits the corresponding device-tree nodes for firmware discovery. Signed-off-by: Subrahmanya Lingappa --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 97 +++++++++++++++++++++++++++++++++++++++++ include/hw/riscv/virt.h | 3 ++ 3 files changed, 101 insertions(+) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index fb05031228..dfdbc6dfe1 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 d4b501802f..3209e09e00 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -45,6 +45,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" @@ -101,6 +103,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 }, @@ -464,6 +468,40 @@ 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, + uint32_t msi_phandle) +{ + RiscvRpmiConfig rpmi_cfg =3D virt_rpmi_config(s, NULL, 0); + uint32_t rpmi_mbox_handle; + RiscvRpmiFdtMboxConfig cfg =3D { + .shmem_base =3D rpmi_cfg.shmem_base, + .doorbell_base =3D rpmi_cfg.doorbell_base, + .a2p_req_size =3D rpmi_cfg.a2p_req_size, + .p2a_req_size =3D rpmi_cfg.p2a_req_size, + .doorbell_size =3D s->memmap[VIRT_RPMI_DOORBELL].size, + }; + + riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, + &rpmi_mbox_handle); +} + static void finalize_fdt(RISCVVirtState *s) { uint32_t phandle =3D 1, irq_mmio_phandle =3D 1, msi_pcie_phandle =3D 1; @@ -500,6 +538,11 @@ 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, msi_pcie_phandle); + } else { + create_fdt_reset(s, &phandle); + } =20 create_fdt_uarts(s, irq_mmio_phandle); =20 @@ -733,6 +776,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++) { @@ -891,6 +946,25 @@ 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; + Error *local_err =3D NULL; + + 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); + if (!riscv_rpmi_create(&rpmi_cfg, &local_err)) { + error_report_err(local_err); + exit(1); + } + } + /* VirtIO MMIO devices */ for (i =3D 0; i < VIRTIO_COUNT; i++) { sysbus_create_simple("virtio-mmio", @@ -969,6 +1043,7 @@ static void virt_machine_instance_init(Object *obj) =20 s->oem_id =3D g_strndup(ACPI_BUILD_APPNAME6, 6); s->oem_table_id =3D g_strndup(ACPI_BUILD_APPNAME8, 8); + s->have_rpmi =3D false; s->acpi =3D ON_OFF_AUTO_AUTO; s->iommu_sys =3D ON_OFF_AUTO_AUTO; s->num_sources =3D VIRT_IRQCHIP_NUM_SOURCES; @@ -1044,6 +1119,21 @@ 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; @@ -1165,6 +1255,13 @@ 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"); + 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 e516898f9a..919a664bc2 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, --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021138; cv=none; d=zohomail.com; s=zohoarc; b=PF45Rq2whyyBe1TH9Vma4vO2yjvD6WET0drJnS2Q1fGaJsElnXCUMTuMQMXAFCTtAvwor5gQ9B2LIRR78WbbBEdytbUIJhn33jpg1QBz8NOgDnDGBn3cRuJ7LBNYwQnR0rX2/8WkhAtfMW+hRLFiPkdmXYfyCtMwCqqNFljaevk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021138; 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=8gBI37r+YwKT1ipjpv7BdiLSDymv5LJMOQBb8QmlPpA=; b=KjceNExvwfhP7/BIWhhdXbji1FoZGTGjICE2Jw66Hpi51BdvwTOBpvBV9QWHiudvCdcDXO7VC5YmGf+sFJRev1qpKVwN7n5cDPzFRy90kUYbkPpT4YH1gYmMVwWJUY8nGGV4b3pvRVu3t9RZx/L2imuaQ5/s2iSEo+7T6/ypDc4= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021138233922.3508424876443; Mon, 26 Oct 2026 06:25:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKg1-0001Wi-0P; Mon, 26 Oct 2026 09:23:49 -0400 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 1xLKfx-0001Vd-Mt for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:46 -0400 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 1xLKft-0005Ff-GA for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:45 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69QAt1VY2732889 for ; Mon, 26 Oct 2026 13:23:40 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 4hj4cp8uk2-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:39 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-3663d3547a0so329970eec.1 for ; Mon, 26 Oct 2026 06:23:39 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:36 -0700 (PDT) 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=8gBI37r+YwK T1ipjpv7BdiLSDymv5LJMOQBb8QmlPpA=; b=a8H9fFR0Y1KuIjmMZjjVTCdyXHw aYl3MeKU4Diz4rJJSnphyHNz6YUAXYDh5rNgeAEZfoA5qIMFf68AY5He9aIHDH4u K1WHW0pYB+bhczFEgn9Gj9n1p7uf0BtXZuvN0rSDaFe+a3VqTd3ZCrJCxr2lSFrP W1iA9ICQLKLS2ZMJrXhaOOR5Iv25bO33vaJ65cpguSac6NWPZBC3RoPWMckWZogh 0lyWx2kWkCTEl0p8N6FuRsgD0CkKqtkgYnNsi7LCaAHblzu1DN3YjB9ELosLw4O3 gtbZSp5wP+36rcLwX1APtSuVMsMY2fN5zMN+VLG3iWrg7EXV3VvOfCAh0dg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021019; x=1793625819; 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=8gBI37r+YwKT1ipjpv7BdiLSDymv5LJMOQBb8QmlPpA=; b=GjKvQe+w5TBbLPUz2oubu1T+x0Z3CJZmEDbjDzXxzp4ndhYB5SAx3vPVK96daLzrFS bdMzXoPlV7c9Kxd+jSoiksp27L17klEdsiiucZyoNC7v1h79jgWx47TLNV66KIrZD1OW LlGh+XKMRBStRnwvEaEntD6mj33zqsSTo/mmPlS0TfuYxZ884Fs4KRE44c3tkM59IbNf CTP40dIXTRBu2F5jv8AEgMhztRLKuzG2WOvorCKDUyjFrZueZ9n2J5/xasAbLAvXm/YY gE9J0Qd6nfctEbznFvVLE4loTs9dgfZaNu53QsDJELr/dL/o9Y/1LIa19+UUgkgJTqLU rpwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021019; x=1793625819; 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=8gBI37r+YwKT1ipjpv7BdiLSDymv5LJMOQBb8QmlPpA=; b=iIJCmlWwYMPKA6u6dpk9cOY3vt2lbe+aWcPj/Jg8WeZtyPATL7bmuwyc48ybSQalAq JrOExHValJ4QUB3eQxv1SWeSzIHN+RhdCwa3k3P/FCNSbqZYZPXI7JK1BWLLdTmsiTK5 k2jgKjgaoULpuqJ1CNm/HXDCnmegeEjq3mBQy0MwocGJ7IS4Xj3HpxJX3/ayAZtYEOBM h3XhAquktonYcFI8g1+NjtmUlFhCg0HrFYLxzSAWSU089WAbzF4XZkfzXitk2NatqD3i 6D/b97QdJjDDaR+Aplid2jULtb/zTcVJvlYvLYQ81N8d+p4wLRlkP6tQ4Rhx49AC5a82 51Kg== X-Gm-Message-State: AFq9FYIaLyvj9QXOUxXtpcAYEozF2bDNQxnHNsWsNV6aZZCkR26N1xD2 kQfvtCKZWE9QFiGudF+4sGoaqpfIjwjmDf9eAPDDoJC9rCUYuEn0oKiiX+O64XRpteR27Qk9Scr wBn0osr0z430+KnrRty1MQv1PZpwGDw34KYlquhWDDBJ9w37y2jMTMnIV3n9qNzqO4w== X-Gm-Gg: AYBFou1gLuJPs2Kfw6aYZ518N2Obn88/N6TugdcUGPOJvFVqvbhHsItE6kM7ppebvu/ WkNnYWwAQ8QlFToCXCEpos0E09zP66X7Jw5jZ6LuwWlMYJbbSJhkvG4m8q6Nr+PYuJl+EQGN+an VWENWWIOzr+QE2honHqi8AIS2VQ8OJ18KIQIlgEq5W27+WuAMSOn/qy6+AFpBe/x8VaC1o++L4/ jUEFY8hLmJF9tBNtP2QM2mJZVc4PFoJiA9VEGPLcnQEfPYCpZsQx22tmyJcscxo38+qyF0U4Vxj LfC2nbrjNdYXrtplyfDnG2+fMmzDHJv5FLsyDZo6uQ8WImYIBlg/dORjxtjflK0M878FTKFQzfm gR89JXwD+zCepLUpdauehgnvPwvQQ/JzAqaBjGk4TH9BSkd+POE/wTBcWcXqImGebUzo8PKW6jZ 71vRz+mSeKXHMYlBf5UXBDREadTz2svw4= X-Received: by 2002:a05:7022:488:b0:127:def:dd72 with SMTP id a92af1059eb24-19933f05929mr20569052c88.2.1793021018162; Mon, 26 Oct 2026 06:23:38 -0700 (PDT) X-Received: by 2002:a05:7022:488:b0:127:def:dd72 with SMTP id a92af1059eb24-19933f05929mr20568959c88.2.1793021017390; Mon, 26 Oct 2026 06:23:37 -0700 (PDT) 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 v12 05/10] riscv: add RPMI system reset service Date: Mon, 26 Oct 2026 18:52:48 +0530 Message-ID: <20261026132254.2652399-6-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX4YDSMt5Nk31a dIUOMu38iK1aJQ2fZ1TrIGZFcatQUWou9zW0hHBYZ5uMi1/5eilmhpO6Ybh0pSKNIROUgNMhawd 6MXS6eq+Ml5LztnoqcwroaYtAg2PMlwL5c8aXJ5UiHumQzcJZ2siaNFfVnTvBMW7KrFfwp2V3+h VsDwgI/JoqYDIE/weaDKncasAXrmRe7K7mfrYsNYJRnhYR/up+gbiGZcpdUp15qmYGjAV9VfMKE hSDeM8m+6O9QCAa4Rnrv725ENArO7KhA73yalw8Z1+CyCvJoHJNDuJ47vebkk7Yq/x0UyS6mwcQ ZXkVhj8GHHORY9zhGie0L1pm5Ojm/V+gCFTdOj1E406gNIvLbzU8NwbzALai05QkZTaEJ44LwCC 8daV0UIK+2/nChBuxKwpuZkldTLdinlgTUtJeoHF7P8T9+Vs6UYDzvRyMD2PgNkPekJxHAoV6JC qUPbUG66gpwwHn6TbeA== X-Proofpoint-GUID: Kj_9E_le56hX-p1HJ6NtWqoyfNnJkafA X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX81L4oTMbIHbS 4mhoWUB3JjwwLIf+dw5uHIckLh0vwTgcAfnAQ5dg5E/9URmzF+pS/VcJUhFuX1mc+3Gm6AO87i/ LLAFrCoiJHH32Zc4Pw1HDVJxFgkqkn4= X-Proofpoint-ORIG-GUID: Kj_9E_le56hX-p1HJ6NtWqoyfNnJkafA X-Authority-Analysis: v=2.4 cv=TboDJhQh c=1 sm=1 tr=0 ts=6adf545b cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=EUspDBNiAAAA:8 a=arUmSIHHDxOh6OzMZbEA:9 a=PxkB5W3o20Ba91AHUih5: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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 adultscore=0 malwarescore=0 suspectscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021139092158500 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 the machine reset and shutdown callbacks. This lets firmware use RPMI reset commands while keeping the board-specific reset policy in the RISC-V virt 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 | 206 +++++++++++++++++++++++++++++++++ hw/riscv/fdt-common.c | 8 +- hw/riscv/rpmi-fdt.c | 2 +- hw/riscv/server_platform_ref.c | 2 +- hw/riscv/virt.c | 42 ++++++- include/hw/misc/riscv_rpmi.h | 11 +- include/hw/riscv/fdt-common.h | 3 +- 10 files changed, 338 insertions(+), 14 deletions(-) create mode 100644 hw/misc/riscv_rpmi_sysreset.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 3e298a74c8..87ea363199 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -183,4 +183,5 @@ system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi= .c')) system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_clk.c')) 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 c73408714a..7d55215fa0 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -200,10 +200,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 @@ -240,7 +267,9 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTyp= e 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); + } =20 if (s->context) { rpmi_context_destroy(s->context); @@ -277,6 +306,30 @@ bool riscv_rpmi_service_enabled(RiscvRpmiState *s, return false; } =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; @@ -348,9 +401,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 c0cb1b64e6..1d7445b2d1 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -20,5 +20,14 @@ extern const struct rpmi_shmem_platform_ops rpmi_shmem_qemu_ops; bool riscv_rpmi_service_enabled(RiscvRpmiState *s, enum rpmi_servicegroup_id service_group); +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..775eb5483f --- /dev/null +++ b/hw/misc/riscv_rpmi_sysreset.c @@ -0,0 +1,206 @@ +/* + * 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 "qemu/log.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 void riscv_rpmi_do_system_reset(RiscvRpmiState *s, + rpmi_uint32_t reset_type) +{ + const RiscvRpmiSysresetType *type; + + type =3D riscv_rpmi_sysreset_type_by_id(reset_type); + if (type) { + type->action(s); + return; + } + + qemu_log_mask(LOG_GUEST_ERROR, "%s: unsupported reset type %u\n", + __func__, reset_type); +} + +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); + uint32_t *resp =3D (uint32_t *)response_data; + + *response_data_len =3D 2 * sizeof(*resp); + stl_le_p(&resp[0], RPMI_SUCCESS); + stl_le_p(&resp[1], 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; + uint32_t reset_type =3D ldl_le_p(request_data); + uint32_t *resp =3D (uint32_t *)response_data; + + *response_data_len =3D sizeof(*resp); + + if (!riscv_rpmi_sysreset_type_by_id(reset_type)) { + stl_le_p(resp, (uint32_t)RPMI_ERR_INVALID_PARAM); + return RPMI_SUCCESS; + } + + stl_le_p(resp, RPMI_SUCCESS); + riscv_rpmi_do_system_reset(sysreset->rpmi, reset_type); + 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 (!group) { + error_setg(errp, "failed to create RPMI sysreset service group"); + return false; + } + + 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/rpmi-fdt.c b/hw/riscv/rpmi-fdt.c index 2110d4457e..c9cd3cad68 100644 --- a/hw/riscv/rpmi-fdt.c +++ b/hw/riscv/rpmi-fdt.c @@ -74,7 +74,7 @@ void riscv_rpmi_fdt_add_mbox(void *fdt, void riscv_rpmi_fdt_add_service(void *fdt, const char *node_name, const char *compatible, uint32_t mbox_handle, - uint32_t service_group, + enum rpmi_servicegroup_id service_group, bool has_mpxy_channel, uint32_t mpxy_channel) { 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 3209e09e00..6e3d143a0b 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -469,6 +469,34 @@ static void create_fdt_iommu(RISCVVirtState *s, uint16= _t bdf) } =20 =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(RISCVVirtState *s) +{ + 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) @@ -480,8 +508,11 @@ static RiscvRpmiConfig virt_rpmi_config(RISCVVirtState= *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(s), }; } =20 @@ -490,6 +521,7 @@ static void create_fdt_rpmi(RISCVVirtState *s, uint32_t= *phandle, { RiscvRpmiConfig rpmi_cfg =3D virt_rpmi_config(s, NULL, 0); uint32_t rpmi_mbox_handle; + uint32_t i; RiscvRpmiFdtMboxConfig cfg =3D { .shmem_base =3D rpmi_cfg.shmem_base, .doorbell_base =3D rpmi_cfg.doorbell_base, @@ -500,6 +532,11 @@ static void create_fdt_rpmi(RISCVVirtState *s, uint32_= t *phandle, =20 riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, &rpmi_mbox_handle); + + for (i =3D 0; i < rpmi_cfg.service_count; i++) { + riscv_rpmi_fdt_add_service_node(MACHINE(s)->fdt, &rpmi_cfg.service= s[i], + rpmi_mbox_handle); + } } =20 static void finalize_fdt(RISCVVirtState *s) @@ -537,11 +574,10 @@ 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, msi_pcie_phandle); - } else { - create_fdt_reset(s, &phandle); } =20 create_fdt_uarts(s, irq_mmio_phandle); diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index 93d128f2e2..1500ff1b8b 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -37,7 +37,6 @@ enum rpmi_servicegroup_id { #define VIRT_RPMI_A2P_REQ_SIZE (16 * RPMI_QUEUE_SLOT_SIZE) #define VIRT_RPMI_P2A_REQ_SIZE 0 =20 - #define TYPE_RISCV_RPMI "riscv-rpmi" OBJECT_DECLARE_SIMPLE_TYPE(RiscvRpmiState, RISCV_RPMI) =20 @@ -46,6 +45,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; @@ -61,7 +65,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; @@ -78,7 +82,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, --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021124; cv=none; d=zohomail.com; s=zohoarc; b=QgvAN6cqTp+BN1hvG6xfuzoaMX+NP1mUWXiMX8JaeU6qcXua/kJ8w9lrkxqfq5ZYlflgiVwdELosFVMWKDha+lEj7nNLT7JD2A8of2/pRpvOtIQd510x+7Esxj6NaHR8T32Z4OuZgVxtqf1FDMnT3II18WLvE0k16/EmUYAS7Dw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021124; 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=hmunNE+gojes745y3xLjTV9YHlCeEzKNm7XlWICxDoY=; b=LQU+BlwcstuYlJSWgSXuc3JtSyxsNFwFfDzl9mN3h95Tte4G3qnyaukh7gIHJ3+UL285gFgfzUGy8A+85KVvIFl89Zd9jcxM07UHXZl0hh7MVshrtfvOT55DsVwcU6q1YLgtsK60jKdlvOyOsjqss/Tyd0oqRcjRwVLSGOpk33Y= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021124504395.5678491849702; Mon, 26 Oct 2026 06:25:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKgC-0001YN-0O; Mon, 26 Oct 2026 09:24:00 -0400 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 1xLKg5-0001XW-GG for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:53 -0400 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 1xLKg3-0005Gc-73 for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:53 -0400 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69QAtNTu3050893 for ; Mon, 26 Oct 2026 13:23:50 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 4hhvddaafq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:50 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-34e650cff93so409921eec.2 for ; Mon, 26 Oct 2026 06:23:50 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:41 -0700 (PDT) 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=hmunNE+goje s745y3xLjTV9YHlCeEzKNm7XlWICxDoY=; b=jDz2KbSfFcNZVrHp0zIkED4+SpK xqFx4vOJsiD0AjlOSGljZzqKHDrR20MKZFpv989OHbSdQn3RZxyXbeCJOCNcrcmA OKPo2F0rAUgIQSVAdAeivMTpWeXKrXGgT+EA6tuQqMr+k/Pu8A5k4xhyd+A9aLhf CQjS1LZghNnC5ZKZHZK+2PNbFgrENBISEAHC3+3tAdSVIplGwgBvTd6T7ZAp+Q0a pDwRUMR67joSUUKTipGre37zk4qqYYHlnciFhpcGAbMSUR1hfh7MQdGS6MteABqQ 8hLjwV1WJrBNxNxU6sKMgSM8Zq+/CyXaiX8ckSB4AtvibqgHKfPG7Xm2Pqg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021029; x=1793625829; 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=hmunNE+gojes745y3xLjTV9YHlCeEzKNm7XlWICxDoY=; b=D/sDStuZl8npAxUwRJiW5hTHiLx9lVsNGTp1gapaDFgZS/qoPUuQ8xc8kEdM+Rubvy ilaG3Ixwpsdd8WRD0VlRtFwUC9FAHeLhGvYTLb8ZNm7MJ8+Vr0qcN98g1fa41ObjB9ha gQLr5T50aIzPEo2yQGIK9rzsABgLZKQj/YmU3ml9xTuMsikQbQnOam/jD4vItS6ByyuZ M7bQ5m/9428r9kcCNEMM4aX7l2VhtmKG4LeV/AAy1PMFO0ovqzY1ae4YwKiewqqybjNB dmlZfUCocXdA5sR2ZQ9x/Lfz85Imo8tusS+EPuHr4MLw0foDrnM7jg/lWHHpRSOM4NeY kXBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021029; x=1793625829; 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=hmunNE+gojes745y3xLjTV9YHlCeEzKNm7XlWICxDoY=; b=QJchrQSSWKMCsFzUNMoViwoUuFbt2HBDaqozbpK3BuaUSKiIRGmy+Fq4WyteEekwhm 5cvIrJjSZV8A5T3z8cL93thJ99Oocm7tvTQUKD+G35O8X98yVrymHtfWi8r68x5dQKb1 FjugiRXe2UvQvFJGgOc30m1GhtRWYzAWMkzENhnlmfkk2hyP29bN6+KMDnIjrRdMilid 9ZawCny9OX1486TjlsQBBKPnWfl61MhxViUXydnVa4FLYnQYfAhXo27wo8eIClg4CniQ hP1Najj0prDKd5CV5j/iscjt+xn4h4gdYqzt4cBA2TtSULXIYpOKo//hQcNxlvFgqVQx kR+Q== X-Gm-Message-State: AFq9FYKRtszrgviVd6YcBGSjiAyA85jX6u+3lpFk779JwWJcbkpdxeez Nl1ekLsAaFUYwL47CXWxR6av+MsLaOsB4uKy0wSv41JmxsNXqc8D0p9TALE0rE38neBWdUUhMZF wozZjCmSO57q4yTre6nJ+/YNnHLfsI57Opcyau4JOBSIObBHwWhoV4PnQfPUaAOSmpw== X-Gm-Gg: AYBFou1LiZM62SHeXPDR/Mn09PXKzjIj7X8YUv1GbabJNG3p5qVWhfJp75LC+SEUzaU PUGEM+goz45LDs6wn6VJTeS33ewihElbBXuT/6LfV7qyrwXS7Of1VQOh54UUUVVM+x42Y8YWd1L zV8W14nKPXfDBTZE0kMwgK1euwVXL4CYf6TBR66FOw4OLkMu2SN0qDEvrJNpY+6tGPLcDCD+HN0 ZWQqvrh52NFdXyXLXKMpBkctjTvZsr9KuSHAL4t1bqbPR8S00cvbVfqDfMS1BrbsgO5+H0mON03 a8L+Vx+V2ANTY4ugZWLPFPNP+b1n7ZqrRA6cuOySkjCUYmId/mai5PwZjhDXkN90JAYGTwQSTr+ yp2ImMb4rLKXsha8kS5otp8hN1yUhF6gLAUJtd4ZzQaNKG1B9vC6udJVjW+oVVSaJ4AmTygIgar c033xZF3IrBtYiqEwOkaYs5yJ/7brHj8M= X-Received: by 2002:a05:701b:454d:20b0:147:d430:7322 with SMTP id a92af1059eb24-1993329074bmr14561308c88.1.1793021028943; Mon, 26 Oct 2026 06:23:48 -0700 (PDT) X-Received: by 2002:a05:701b:454d:20b0:147:d430:7322 with SMTP id a92af1059eb24-1993329074bmr14561240c88.1.1793021028269; Mon, 26 Oct 2026 06:23:48 -0700 (PDT) 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 v12 06/10] riscv: add RPMI HSM service Date: Mon, 26 Oct 2026 18:52:49 +0530 Message-ID: <20261026132254.2652399-7-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: mmaZjVaBVlKWaz0pbaFNtZsDZJvtl2Ig X-Proofpoint-GUID: mmaZjVaBVlKWaz0pbaFNtZsDZJvtl2Ig X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfXywo0q0/Q8QB+ 4eLbT5O0U2QLVLMCe/v1F8AjUJs0cPvNSZQEzzufK75RGk6itP+yE5U4hdLK25eEsidQeqflJ0q iI2OXXEUOuzIYwxMSn/8vJO7GswwHaqk/YwXJ2mEjwgziPKQH2kgQ+0xzT1jIQBI5XmA+QIIJzv 3mHzTYM8CX1RV9vM/IgoLmphayzYoza+xIYQFv/Hxe3/DLX7LINt1jK6XfKeQm33X059V0NBnx1 GzZlRb+RazALJC32m7eq/ulbeF5cpu4iUW6F7F6xajbVnGMUlz01dcHxO0+M8N8G0hgpSPU0+1n SkR6Wt+IRebMCwWwCjwuCwnd5aSltnR7XrZqd9iynVVYDNv/dykIVvd09BqEA7J+dEBnhXGlCof 8vNffHd3GizcEixXj6qg7Sh7uQgbqSM52u0AkgGIVK+W09FfRF/PTdDHxFCZUTi8zfqrtCT8CnJ t9o8QnkK+uKIghkHhaQ== X-Authority-Analysis: v=2.4 cv=N8+8hG9B c=1 sm=1 tr=0 ts=6adf5466 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=itn9ZVZVmevHaGIKV1oA:9 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX47O8d/YicLtN Nex6ANYFIT1akRN38eUVZHe0Uej5Tbej61C7O7LDphTnATJm1kxaW2mZh8RWFIQDZN1cchQKBP5 3fOiOIfFJLKhLoF8qfu0pvOSt1snyRA= 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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 priorityscore=1501 adultscore=0 bulkscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021124882158500 Content-Type: text/plain; charset="utf-8" Add the RPMI Hart State Management service group for RISC-V virt. The service exposes the configured virt hart IDs to librpmi and keeps per-hart RPMI hardware state in the RPMI device. Start, stop, and suspend requests update QEMU CPU halted state and resume/kick vCPUs as needed so firmware can exercise RPMI HSM operations against the emulated topology. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- hw/misc/meson.build | 1 + hw/misc/riscv_rpmi.c | 5 + hw/misc/riscv_rpmi_hsm.c | 281 ++++++++++++++++++++++++++++++++++ hw/misc/riscv_rpmi_internal.h | 4 + hw/riscv/virt.c | 5 + include/hw/misc/riscv_rpmi.h | 4 + 6 files changed, 300 insertions(+) create mode 100644 hw/misc/riscv_rpmi_hsm.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 87ea363199..00ae6f1b41 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -184,4 +184,5 @@ system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files= ('axiado_clk.c')) 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 7d55215fa0..b3b9a202a5 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -211,6 +211,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 @@ -263,6 +267,7 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTyp= e type) memory_region_set_dirty(&s->shmem, 0, s->shmem_size); } =20 + riscv_rpmi_hsm_reset(s); } =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..08a985cb30 --- /dev/null +++ b/hw/misc/riscv_rpmi_hsm.c @@ -0,0 +1,281 @@ +/* + * 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 "librpmi_env.h" + +static const struct rpmi_hsm_suspend_type riscv_rpmi_hsm_suspend_types[] = =3D { + { + .type =3D 0, + .info =3D { + .flags =3D 0, + .entry_latency_us =3D 0, + .exit_latency_us =3D 0, + .wakeup_latency_us =3D 0, + .min_residency_us =3D 0, + }, + }, +}; + +typedef struct RiscvRpmiHsmStateTransition { + enum rpmi_hart_hw_state state; + bool halted; + bool resume; +} RiscvRpmiHsmStateTransition; + +static const RiscvRpmiHsmStateTransition riscv_rpmi_hsm_state_transitions[= ] =3D { + { + .state =3D RPMI_HART_HW_STATE_STARTED, + .halted =3D false, + .resume =3D true, + }, { + .state =3D RPMI_HART_HW_STATE_STOPPED, + .halted =3D true, + .resume =3D false, + }, { + .state =3D RPMI_HART_HW_STATE_SUSPENDED, + .halted =3D true, + .resume =3D false, + }, +}; + +static const RiscvRpmiHsmStateTransition *riscv_rpmi_hsm_state_transition( + enum rpmi_hart_hw_state state) +{ + for (uint32_t index =3D 0; + index < ARRAY_SIZE(riscv_rpmi_hsm_state_transitions); index++) { + if (riscv_rpmi_hsm_state_transitions[index].state =3D=3D state) { + return &riscv_rpmi_hsm_state_transitions[index]; + } + } + + return NULL; +} + +static CPUState *riscv_rpmi_hart_cpu(RiscvRpmiState *s, uint32_t hart_inde= x) +{ + if (hart_index >=3D s->hart_count || !s->hart_ids) { + return NULL; + } + + return cpu_by_arch_id(s->hart_ids[hart_index]); +} + +static void riscv_rpmi_hsm_set_hw_state(RiscvRpmiState *s, + uint32_t hart_index, + enum rpmi_hart_hw_state state) +{ + CPUState *cpu =3D riscv_rpmi_hart_cpu(s, hart_index); + const RiscvRpmiHsmStateTransition *transition; + + if (hart_index >=3D s->hart_count || !s->hsm_hw_states) { + return; + } + + s->hsm_hw_states[hart_index] =3D state; + if (!cpu) { + return; + } + + transition =3D riscv_rpmi_hsm_state_transition(state); + if (!transition) { + return; + } + + cpu->halted =3D transition->halted; + if (transition->resume) { + cpu_resume(cpu); + } else { + qemu_cpu_kick(cpu); + } +} + +static enum rpmi_error riscv_rpmi_hsm_start_prepare( + void *priv, rpmi_uint32_t hart_index, rpmi_uint64_t start_addr) +{ + RiscvRpmiState *s =3D priv; + CPUState *cpu =3D riscv_rpmi_hart_cpu(s, hart_index); + + if (!cpu) { + return RPMI_ERR_INVALID_PARAM; + } + + cpu_set_pc(cpu, start_addr); + riscv_rpmi_hsm_set_hw_state(s, hart_index, RPMI_HART_HW_STATE_STARTED); + return RPMI_SUCCESS; +} + +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_stop_prepare(void *priv, + rpmi_uint32_t hart_inde= x) +{ + RiscvRpmiState *s =3D priv; + + if (!riscv_rpmi_hart_cpu(s, hart_index)) { + return RPMI_ERR_INVALID_PARAM; + } + + riscv_rpmi_hsm_set_hw_state(s, hart_index, RPMI_HART_HW_STATE_STOPPED); + return RPMI_SUCCESS; +} + +static void riscv_rpmi_hsm_stop_finalize(void *priv, rpmi_uint32_t hart_in= dex) +{ +} + +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) +{ + RiscvRpmiState *s =3D priv; + + if (!suspend_type || !riscv_rpmi_hart_cpu(s, hart_index)) { + return RPMI_ERR_INVALID_PARAM; + } + + riscv_rpmi_hsm_set_hw_state(s, hart_index, RPMI_HART_HW_STATE_SUSPENDE= D); + return RPMI_SUCCESS; +} + +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) +{ + RiscvRpmiState *s =3D priv; + + if (hart_index >=3D s->hart_count || !s->hsm_hw_states) { + return RPMI_HART_HW_STATE_STOPPED; + } + + return s->hsm_hw_states[hart_index]; +} + +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(RiscvRpmiState *s, + struct rpmi_service_group **group, + Error **errp) +{ + struct rpmi_hsm *hsm; + + if (!s->hart_count || !s->hart_ids) { + error_setg(errp, "RPMI HSM service requires hart IDs"); + return false; + } + + s->hsm_hw_states =3D g_new0(uint32_t, s->hart_count); + for (uint32_t i =3D 0; i < s->hart_count; i++) { + s->hsm_hw_states[i] =3D RPMI_HART_HW_STATE_STARTED; + } + + 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 (!hsm) { + g_clear_pointer(&s->hsm_hw_states, g_free); + error_setg(errp, "failed to create RPMI HSM context"); + return false; + } + + *group =3D rpmi_service_group_hsm_create(hsm); + if (!*group) { + rpmi_hsm_destroy(hsm); + g_clear_pointer(&s->hsm_hw_states, g_free); + error_setg(errp, "failed to create RPMI HSM service group"); + return false; + } + + s->hsm =3D hsm; + return true; +} + +static void riscv_rpmi_hsm_destroy(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; + } + + g_clear_pointer(&s->hsm_hw_states, g_free); +} + + +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 (!riscv_rpmi_hsm_create(s, &group, errp)) { + return false; + } + + if (!riscv_rpmi_context_add_group(s, group, "HSM", errp)) { + s->hsm_group =3D group; + riscv_rpmi_hsm_destroy(s); + return false; + } + + s->hsm_group =3D group; + return true; +} + +void riscv_rpmi_hsm_remove(RiscvRpmiState *s) +{ + riscv_rpmi_context_remove_group(s, s->hsm_group); + riscv_rpmi_hsm_destroy(s); +} + +void riscv_rpmi_hsm_reset(RiscvRpmiState *s) +{ + if (!s->hsm_hw_states) { + return; + } + + for (uint32_t i =3D 0; i < s->hart_count; i++) { + s->hsm_hw_states[i] =3D RPMI_HART_HW_STATE_STARTED; + } + if (s->hsm) { + rpmi_hsm_process_state_changes(s->hsm); + } +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index 1d7445b2d1..7f9d110776 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -30,4 +30,8 @@ void riscv_rpmi_context_remove_group(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); +void riscv_rpmi_hsm_reset(RiscvRpmiState *s); + #endif diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 6e3d143a0b..ef81ba761e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -475,6 +475,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(RISCVVirtState *s) diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index 1500ff1b8b..9f7aa9f6ef 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -44,6 +44,7 @@ struct rpmi_context; struct rpmi_service_group; struct rpmi_shmem; struct rpmi_transport; +struct rpmi_hsm; =20 typedef struct RiscvRpmiMachineOps { void (*system_reset)(void); @@ -84,6 +85,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; + uint32_t *hsm_hw_states; uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021109; cv=none; d=zohomail.com; s=zohoarc; b=OfNg5iIC7XqV5y5H1Agp2WHY1FrkCxRqGfA0hlpMeR0ry7Bw6jvSYpsEN60ZRky1PJ+hIs020PXDZnZKxFpQ+gLdQTKf0P1uxeCS3276VRWXgzmrCbJFpbxO+49jmK6QsC6SOxERB0eyi2cn3mNAhIfFgZQ/MOebM91z0pW3IcU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021109; 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=0u9GymWvgpH0GPnAN9I9PgeXSywcOrQqFDiDN4mMbgk=; b=j15FI2SoxLmcfF0j7k0JdO7rdN+1N46XiK3fsu3UFngKZ3ZIyQ/4zhBZMoBLsqxXlhZyuQhvnaiJPnSHQzBIX7mNIffqh3VHKBmiIVbCte+AE6HXMhsyhOMnPeeEZ9/8fk0NlPIoFa/xWgtjCQdXva5V3WQvZehR0f62L8Hw8Fg= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179302110951045.49042739043364; Mon, 26 Oct 2026 06:25:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKgK-0001ZJ-H5; Mon, 26 Oct 2026 09:24:10 -0400 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 1xLKgA-0001YT-Fl for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:59 -0400 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 1xLKg8-0005HA-4Q for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:23:58 -0400 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 69QAtMeY2541984 for ; Mon, 26 Oct 2026 13:23: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 4hhsjdam0k-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:54 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-313c7315becso550526eec.2 for ; Mon, 26 Oct 2026 06:23:54 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:51 -0700 (PDT) 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=0u9GymWvgpH 0GPnAN9I9PgeXSywcOrQqFDiDN4mMbgk=; b=E2MtUnKYaPkOOotl1tWnr6djc34 rPUBDcW5zwSB00id2XyOZKPB+myxD50HKUnsVlw9y3cLjtxbKWtd2sbjB2IIOfI4 UC+oAmdyE/4jlwFkJSH3Trc/0uwS4NdxNSA5dTvt6dhta6R0qd3iecnrJ0PepiGb 2qjwOk8AZGXPr0DI3NBqauDnr4qk40OUF3gPl8cvWC1Jz0staa37JYNHG3PLFF0W iVLhO09D5/wHG491ViTI4b1qP/MB18gzspMJIYAM1F9j9JC+ebXEd5jZ1gOC63KC BHAgbGfsQ+1LOwrhh+kWP0zVy0PXuJox1wU0uMoPOgczRZA+8eIwr+gL41g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021033; x=1793625833; 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=0u9GymWvgpH0GPnAN9I9PgeXSywcOrQqFDiDN4mMbgk=; b=eI4M3ca/F2vmSnKllU//4+zUXKxhwX+KDuzxOXWJ0btDduB/9QARIrsU4sy8OpPKQx UcToY9T+nXWSwH92HyORXz6lUvzJVPl8iGIWXW3Tgs7KMb5yW7cS7rb4WV0C5iyukI1x spLxyp6N51eKSwXhL+ifj63Uonr3ASTOj1GfhnPyf8iqcx9v2SNKzx4jGYFf5MRisTDy 1Uh0FQfgYF6KmqPXD5XdHzffJlWg8Zy5CreEIbh2xGBogVCP9oqxCCxnhiHq/2y/WhXO hPsILBZA7EtNTcWDyUwhFVXK0w1G/N+X2g5OYJoOjrA9KKhXdjEz0cVH/FndGwy+Hg2I LolQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021033; x=1793625833; 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=0u9GymWvgpH0GPnAN9I9PgeXSywcOrQqFDiDN4mMbgk=; b=OKGdUfXNyqDTZMP0NHUB07g1FhqhaIHibmnRO214TBjHAmUfIpcT54msn3TbNR1KZo noBFL6hlcINfCMXx3CETwSu3X7WxnLX1heelKzwm/C4pQO55hI+FATzRcb5P8bQk0JPW fiD+QIWHOkEWXIq87dOelcDKRISQkk1ZWBxGrXuj1UhowokelJncP8lQVWXI/9XtJl23 GsYtaAt5EG3AXEXWv+tJKuLXJB7Fi01gnTCIlzsfVT7Pgo76x4F5JHwEKcEw6PEa69sY GHRedXHrR7hdqVMAbbOTRV+XAAY0MrltJl2+GP0meY/cXuSxEsvoSCl22xqoypv/2u/x FvWg== X-Gm-Message-State: AFq9FYIzoEMiw/G0C9fPcytrmp8PFlW1uKapP/EpNtyh2KxRlvG+cDni zYrZKEMJO0XGd8GDl7GsqNOJJitpdAWQNxBs6vw4UuIAoQb4Y5jsqvLNaPyotVFUuhNqPtFOZGX eNtefyCQuFhrsCosOrPFE0lRWMNI+IGWoGpcj+yE3+KCryvzc9O54VmwG5xQE8YzrcQ== X-Gm-Gg: AYBFou1O/bhYlXCIDRedu0G2UszBdd6hnjKKCxzve48SmmHE7FI7HofYoiK2VbLkxQH tVjDgz8Fx3jcO37GXnG4PU9FIenSdZNLHrZLqUuUlsLRkGxFV4xCnk9VbFKqETfyYMlmbnffStk 308pQJYKSKVEDu9kkdTvDrYx4ttUsVwrBz9tKldP8Di4uLAni0P2ngWAQ4pp0xDn1ZxLej1hfIZ jZWrsKy6mmdouqI6rEbLSG85UIImRjFGn8S2ulnRfqAstZsH0NSiGvwXJVa7RTEaS6uq4w9EUay /HE9iZQIAIhKlNd2FhZk7CJgbTHCHoOUwxLNc5Zh7cPE3H+LEQcn+wWIVvRbuoJhmGjghKIWaDJ TJSkil4xFodyQr8bUP9WnmJmdzigU+VBzzqAOZsfgrz6+MwxFzUDH/2V5KDLBv0nw9sbn4rL1b8 SSt0H/+B7f6WKDJrWO1DFIrsEIW603Y0E= X-Received: by 2002:a05:701b:430a:b0:16b:4f52:a08 with SMTP id a92af1059eb24-1991b142105mr14500690c88.0.1793021033122; Mon, 26 Oct 2026 06:23:53 -0700 (PDT) X-Received: by 2002:a05:701b:430a:b0:16b:4f52:a08 with SMTP id a92af1059eb24-1991b142105mr14500619c88.0.1793021032371; Mon, 26 Oct 2026 06:23:52 -0700 (PDT) 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 v12 07/10] riscv: add RPMI system suspend service Date: Mon, 26 Oct 2026 18:52:50 +0530 Message-ID: <20261026132254.2652399-8-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: vc1vy0Unt8_a7hwVPowqgfQ7vNMVNwIa X-Proofpoint-GUID: vc1vy0Unt8_a7hwVPowqgfQ7vNMVNwIa X-Authority-Analysis: v=2.4 cv=a4elZkSF c=1 sm=1 tr=0 ts=6adf546a cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=U8RMtI3d1EX5IS3VA7UA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX02S9bwYwMNG2 TrIqDWF78VJFBhdymIm7t0Ik7LdFDpn/zeqaGP1LNiMADXrMvmGHXQLzxO0E7P6jweWEqMItAHM ktkTb0bvEYz2cUaNsRFRS4mTZ4xezh4= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX1Lq26ZWbhh49 nLy+Wruv3IAJhDrxzDThJsqLnEOn7aEMhIyAN1KOL6zfWtfZ1M4EnPlL5tE3qLFmQO0RWCG8sRI s04hvylR1FFGdjY8AwCPCGEJVv23OxGFl/1d8mUVmbEiEouEb9Wml9DMkT3W73Hp5u2MvrlNilq xvSuIcDwOC8CSO5LzBXsrZLvlQT9Ddtk86rQnxafeCfku5PYswanE9nzrN9m6ftl0X4gqBhAUL5 XdKYWAC5ecsciDwwpaZ3xYuS35mX9x3w+kdgcZIqgPu7ncI52Ekyu2Zn3LdCS5Y3D3sUsiXsISL BnXSZOVMb4Ys1gC0XqGpv29iTG9x1BThaHLm0zpZRM1iO3Bm6bYBJngia8IA1LR/F7G8bk+NM1S sH2I4Z17EK8mdepqG6sDvfmn9HLXgJK3Ob+q1IgEoZ+1TWbJNDQU86Q/vI9bYp4kGuXPDaWETW0 /Y/gbRTqyqsk+1OKc5w== 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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 spamscore=0 clxscore=1015 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021110774158500 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 suspend finalize callback to the machine suspend path. On wakeup it processes RPMI group events and defers the HSM hart resume until vCPUs are ready to run again. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- hw/misc/meson.build | 1 + hw/misc/riscv_rpmi.c | 4 + hw/misc/riscv_rpmi_hsm.c | 10 +- hw/misc/riscv_rpmi_internal.h | 6 ++ hw/misc/riscv_rpmi_syssusp.c | 194 ++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 24 +++++ include/hw/misc/riscv_rpmi.h | 10 ++ 7 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 hw/misc/riscv_rpmi_syssusp.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 00ae6f1b41..b619452df3 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -185,4 +185,5 @@ system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [file= s( 'riscv_rpmi.c', 'riscv_rpmi_sysreset.c', 'riscv_rpmi_hsm.c', + 'riscv_rpmi_syssusp.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index b3b9a202a5..83a41cb71c 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -215,6 +215,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 diff --git a/hw/misc/riscv_rpmi_hsm.c b/hw/misc/riscv_rpmi_hsm.c index 08a985cb30..928fe3e52e 100644 --- a/hw/misc/riscv_rpmi_hsm.c +++ b/hw/misc/riscv_rpmi_hsm.c @@ -236,7 +236,6 @@ static void riscv_rpmi_hsm_destroy(RiscvRpmiState *s) g_clear_pointer(&s->hsm_hw_states, g_free); } =20 - bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp) { struct rpmi_service_group *group; @@ -279,3 +278,12 @@ void riscv_rpmi_hsm_reset(RiscvRpmiState *s) rpmi_hsm_process_state_changes(s->hsm); } } + +void riscv_rpmi_hsm_resume(RiscvRpmiState *s, uint32_t hart_index, + uint64_t resume_addr) +{ + riscv_rpmi_hsm_set_hw_state(s, hart_index, RPMI_HART_HW_STATE_STARTED); + if (s->hsm) { + rpmi_hsm_process_state_changes(s->hsm); + } +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index 7f9d110776..2c4723ad6b 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -33,5 +33,11 @@ void riscv_rpmi_sysreset_remove(RiscvRpmiState *s); bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp); void riscv_rpmi_hsm_remove(RiscvRpmiState *s); void riscv_rpmi_hsm_reset(RiscvRpmiState *s); +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..f4a9bbdaf4 --- /dev/null +++ b/hw/misc/riscv_rpmi_syssusp.c @@ -0,0 +1,194 @@ +/* + * 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 "qemu/timer.h" +#include "system/runstate.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; + + if (s->machine_ops && s->machine_ops->register_wakeup_support) { + s->machine_ops->register_wakeup_support(); + } + 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) +{ + RiscvRpmiState *s =3D priv; + + if (s->machine_ops && s->machine_ops->system_suspend) { + s->machine_ops->system_suspend(); + } +} + +static rpmi_bool_t riscv_rpmi_syssusp_can_resume(void *priv, + rpmi_uint32_t hart_index) +{ + RiscvRpmiState *s =3D priv; + + if (s->machine_ops && s->machine_ops->system_can_resume) { + return s->machine_ops->system_can_resume(); + } + + return true; +} + +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); + + if (s->context) { + rpmi_context_process_group_events(s->context, + RPMI_SRVGRP_SYSTEM_SUSPEND); + } + if (s->wakeup_timer) { + /* + * 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; + } + + if (s->machine_ops && s->machine_ops->register_wakeup_support) { + s->machine_ops->register_wakeup_support(); + } + if (!s->wakeup_timer) { + s->wakeup_timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, + riscv_rpmi_wakeup_timer, s); + } + if (!s->wakeup_notifier_registered) { + s->wakeup_notifier.notify =3D riscv_rpmi_wakeup_notify; + qemu_register_wakeup_notifier(&s->wakeup_notifier); + s->wakeup_notifier_registered =3D true; + } + + *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; + } + + return true; +} + +static void riscv_rpmi_syssusp_destroy(RiscvRpmiState *s) +{ + if (s->wakeup_notifier_registered) { + notifier_remove(&s->wakeup_notifier); + s->wakeup_notifier_registered =3D false; + } + if (s->wakeup_timer) { + timer_free(s->wakeup_timer); + s->wakeup_timer =3D NULL; + } + + 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) +{ + 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 ef81ba761e..c17c03c524 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -51,6 +51,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" @@ -480,6 +481,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(RISCVVirtState *s) @@ -497,9 +503,27 @@ static void virt_rpmi_system_shutdown(void) qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); } =20 +static void virt_rpmi_system_suspend(void) +{ + qemu_system_suspend_request(); +} + +static void virt_rpmi_register_wakeup_support(void) +{ + qemu_register_wakeup_support(); +} + +static bool virt_rpmi_system_can_resume(void) +{ + return runstate_check(RUN_STATE_RUNNING); +} + static const RiscvRpmiMachineOps virt_rpmi_machine_ops =3D { .system_reset =3D virt_rpmi_system_reset, .system_shutdown =3D virt_rpmi_system_shutdown, + .system_suspend =3D virt_rpmi_system_suspend, + .register_wakeup_support =3D virt_rpmi_register_wakeup_support, + .system_can_resume =3D virt_rpmi_system_can_resume, }; =20 static RiscvRpmiConfig virt_rpmi_config(RISCVVirtState *s, diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index 9f7aa9f6ef..a0381e31d7 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -49,6 +49,9 @@ struct rpmi_hsm; typedef struct RiscvRpmiMachineOps { void (*system_reset)(void); void (*system_shutdown)(void); + void (*system_suspend)(void); + void (*register_wakeup_support)(void); + bool (*system_can_resume)(void); } RiscvRpmiMachineOps; =20 typedef struct RiscvRpmiServiceConfig { @@ -85,9 +88,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; uint32_t *hsm_hw_states; + Notifier wakeup_notifier; + bool wakeup_notifier_registered; + 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; --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021089; cv=none; d=zohomail.com; s=zohoarc; b=I03PSpnYu2bE9loOEgzHiFlE7vbWvxb6B0fSWefJjdn3PbnuL4FgeFeVe4A1kazL5XzzmXi4lZSTQD0IYcbI9DOROePOCYHhUvIHJKQmt9hbKDLfJeIJFs/Yu9GnlcDfi2EbzWFtyCsPbbq9iXPz4udYDqPpUYP3pFgpJ+m9lnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021089; 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=NJrJBfSD91dLhA24xgIqTZOoBu7hAZgyfhwlbuYfSZI=; b=aJ1tL5HC7jshCPb6kVM8Pdt9WI+xvQX25AGeU4NFD5ZAdOtIlJNjVppnV8FrRYRIH46RGdhMj+HeT39WRXK0NMqBZ3vjci3YhFke3O9kcsga8psJDl/C6jZex+2KsxkaswJc33wva0qA9CkHIk1wXL2+m4aix8e2qBxpm0+nntc= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021089757963.7581687848033; Mon, 26 Oct 2026 06:24:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKgO-0001Zh-5Q; Mon, 26 Oct 2026 09:24:12 -0400 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 1xLKgD-0001Z2-Ao for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:24:01 -0400 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 1xLKgB-0005HN-DF for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:24:01 -0400 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 69QAtNj92542049 for ; Mon, 26 Oct 2026 13:23:57 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 4hhsjdam0r-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:23:56 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-313c7315becso550533eec.2 for ; Mon, 26 Oct 2026 06:23:56 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:54 -0700 (PDT) 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=NJrJBfSD91d LhA24xgIqTZOoBu7hAZgyfhwlbuYfSZI=; b=jIGGtng/1Oj+ar8ePNRk1JYp1S7 ejBYDmnaohUVMs/EuR8P1mFKCLkLkdJythw234Jnf5a0bo3R8Py54n9SegVM0kYt alswbkDasxO9+xleWz/pSvlavMAmmDnN8d2vIcvFBztA6+FBu9vO5rNdA1R3YVPd uXoxjCbrSGzs4k5skK6KUAagOw/wg1JYwRWaRAC/s9Vd9Dat8fsW9yLkFPrE7Mph nDwFr49gtgxLH6WKD47Arbscg83q7GzO/FNYbGtX7LyM4F/C1gByr5gaE6DEapRG WsvN+ncvjkfF5JipdGOIfzNTYixO5VCXUvWBG05+ALkY4HDDycb/TK7fPTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021036; x=1793625836; 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=NJrJBfSD91dLhA24xgIqTZOoBu7hAZgyfhwlbuYfSZI=; b=CFHZY6NyyiIu9eQF8l0qJD6FzCw5f4GVwDQCCxikKB5HUi6RjkIUS5fx1O+djVYS0e xuxmMwImA6NOyMFMpbRIVtlfeiNcvhERlkMQ43Ywhp4qq2l+PHJFqU/ASayHHwwf+1pz nI0g/g/YtdwYgmpoxeQg0BDCH0sPcCBGcL0BgoUzcxuIYW0ZEh3T5fh+K6UHeb6DYMYC LRSuoQ+mPQfoMyUzebRNlk3T3ahAUyZR3KAK5LMNA8KzNGdTEu17tYUlgqzq8ztNlUD3 8nUx3A+iRa4mbM+z8z0cdXUrQr2CGzkShIsZ0o/CCJ8cPO45upt1/AvK0d7QuXEaFuJq dxNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021036; x=1793625836; 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=NJrJBfSD91dLhA24xgIqTZOoBu7hAZgyfhwlbuYfSZI=; b=qoDabbOvR2kXpBUOnw0Ixb8LUjLdS7oL6cQEXnGKtJsrnT/IbA5cEzVkm6U2Mz7YhE uVmYTXQmafegLWZ43f3rUvWKc3Z0od7IkXM22/TcfVtqgVQ011IPb4L0MdhESQSTAwmE dy119KcuVhvoxl4k4yxhZxeKCEw8QKbNHnPL1XsdiI9g6f2Hx2bQW7zgDxb775uF7Tlk 9uJgSxHwu4u2bP4UhDlA2O5k4aSWGWSmH+o2zPf4Yno58qLjIUZoORe8kWbArUM845z3 EJm7Ewqf15eRb4jYtQ6hffn/ugOBlrfcJtZnbZvGB5xE5e8RLZpUjDAlcgmIJfuOhVeX w8eQ== X-Gm-Message-State: AFq9FYKA+JZ3pGEq6DXnDBDwSLbcCJhrPgNvdiUoI8CQYcZ8kOqrZOb1 H1XBRBY8VSL0/Ba4tG9AtOzZC+eY1WGvLr4Kpr3tKHe7ZSEVo2C9xrQTDSa89aq64etl2FibfD3 yK2tB8j2voBG5R/Knl+I7PNkaTSPna0Kmiz5IsMCBYEUpXIU2u3b0xxtM753/JruB9g== X-Gm-Gg: AYBFou2aO8g+3+YeL7BM9NvfQ+UXHGJAY8GpPru6RgAbu2CXs2gIGSL175le6OXprMG DMgrIqC2bUsZcHJZ0KAMj52svYgjt+uPdOdheQFrMn5+kSaB3TxtDNOMJ6QD8NPKu3vYlbc86cA Y6yUdpMsKNFxkUOVHfQnpcoYGoxg5uklTS3AXJLou70hV+zpP984HqFYpENTuqD0fPO0Sp6NsV6 quFQg8sfKhFjkaPbZpqbO6wbGaJdVReBnx3SCokdpt5y7J+0QNvQIbDbWEwgF7IPxhmiN7gILiR Fo2UMuWCer6MxqFNye0wjwYc1R4iGCZj0eITpweDLcmfimK6XVB7zc7z0/2rBq+3FL+14sQqCN1 aT+DRYVoueLRGweqc35cY/cZAFmgIeLMAtdyRG7gor4a2CvXyeUOj+Rdv8BjNXdSipGsEzpbMwZ +VCDoXscg+5//KScLm95Vm0khejf+/kN8= X-Received: by 2002:a05:7022:7e0e:b0:183:d275:cf76 with SMTP id a92af1059eb24-19934a9266cmr17467288c88.2.1793021035940; Mon, 26 Oct 2026 06:23:55 -0700 (PDT) X-Received: by 2002:a05:7022:7e0e:b0:183:d275:cf76 with SMTP id a92af1059eb24-19934a9266cmr17467222c88.2.1793021035212; Mon, 26 Oct 2026 06:23:55 -0700 (PDT) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Pierrick Bouvier Subject: [PATCH v12 08/10] docs/system/riscv: document initial virt RPMI support Date: Mon, 26 Oct 2026 18:52:51 +0530 Message-ID: <20261026132254.2652399-9-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: D1FRrselYJpcYBuKW-ckgdNz8Owt5H7c X-Proofpoint-GUID: D1FRrselYJpcYBuKW-ckgdNz8Owt5H7c X-Authority-Analysis: v=2.4 cv=a4elZkSF c=1 sm=1 tr=0 ts=6adf546c cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=NEAV23lmAAAA:8 a=V1jnuoLLAAAA:20 a=EUspDBNiAAAA:8 a=bNRx8rSjxjkR0t5bZ0UA:9 a=scEy_gLbYbu1JhEsrz4S:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX6X43N4bc6vXJ k88rWepQUKQLOKK3hjIeqVkasTmgLYvxgmUH66eTXwWOM4u13qGIgZP8MpLD9XwmW5rFoDrUZ9x Cy69yQhn81ZfB1x64yssYUf/ntXBJgA= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX1x+BALA/ci2s Dhts/bSQT2DVzFfL6d4QnUpWHu/rQuEv17qGl4aW22orecQ+oA8WCn8dshCgJP7seCdpd0gs2vp zHxa9hPfWMWI7fNpcEvlxa166YtB6oHv645B4XSCjePgdAYLoUNxeZU3+DA1g+aQWp4YoVcVcxA x0euQbVh1F0jvGDzrQ2yW+sJuYRlZjXPg3kNRmRen6tDFKSPhhx7oOQufRWPSgjW9b3NatbKIFY KrWEIlVAyL15NCX6j5KgacBMVHYccLUw3TMNkAoY8bK4EAdXdNirqhJT7kuzRqbnPNGt8+w+5ZS fuRR6n0EPH9JcZKYVFO3qON1DEDNu2blDh//ktsnXhTHy1gKz5JxJJ8FhoSqlERhA5Q0ysKgz3N O64Wsk5IHHBD1sXVmS2qljTAEcy2vmk9qdZ64y5UvSXTT7E8ZKETPM1s+KeNNr25e0Zr9bq6eDw As75MeJWA5r9rQeX/aQ== 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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 spamscore=0 clxscore=1015 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021092434158500 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. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- docs/system/riscv/virt.rst | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index 3c87246891..a3647efe1b 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -149,6 +149,87 @@ 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. + +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. +These binding names are part of the RPMI RFC surface and may be revised if= the +RISC-V RPMI bindings change during review. + Running Linux kernel -------------------- =20 --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021142; cv=none; d=zohomail.com; s=zohoarc; b=GjZo7fMrC2u8I5lfof/a6tz4JiHB9FPevuFAq0S/FM5w20YN3j2LS35TZS4uSrSwvAdpV8lfzNs01ivg3/zKxNKSJJNLLc9HAYp66691oXh3qqkDoqKIpGFyuv/9AlTqF1sc1Sg/HBBdFgk+gcNUPjamFjwPEI/sKxoIx68jfwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021142; 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=5ulk6XjkgH0e+2wC/uqh30VwHtLlb31J3vXz5/nMi2M=; b=ha27Vl7/z+rpkkYyEsLqag0uo0x2fM6/s8yZyZ8vvBQPw80mhaoBcZMsH/vkulEOb/2nXJ8ew2Xfqk5aHMt2+cP/p8vQfUK2V0Armpj0tvUdeTMMopoT/1r7edbnD75sFOTNLcHEjv+2P5Dq7koyee1L7JXEf0Qo0IvrQIF7Zg8= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021142587355.09205673127803; Mon, 26 Oct 2026 06:25:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKh2-0002FI-Td; Mon, 26 Oct 2026 09:24:53 -0400 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 1xLKgL-0001Zw-2b for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:24:10 -0400 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 1xLKgH-0005IE-0M for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:24:08 -0400 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 69QAtF0G4126973 for ; Mon, 26 Oct 2026 13:24:02 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 4hhshptjcb-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:24:02 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-36a0e07082dso884eec.0 for ; Mon, 26 Oct 2026 06:24:02 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:23:59 -0700 (PDT) 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=5ulk6XjkgH0 e+2wC/uqh30VwHtLlb31J3vXz5/nMi2M=; b=ka5TILgBxzt1PIn0/CNU785W3RR Jf1wHErWLRm3T1DUYKBBLVaAkpqvpG+A3CvlNNfTLM7JhjpjWpXqRh/eE0coW1yO 5sUp8L/11UL6K0simdQNNCsZxvT9ySgNVkNAtGWC3vZp4Cgj/tpDLAXfN3090Fjl uet61WFzUHmWLA2wBcppdpLkjWfSaGhOebrx7bwDNKMHbrHm6s4Y59hUXHy8meIW KWqyJH1ULUMsg2yNSo5XqCFdz3C9x80RJKwfrs/ZUK7V52YvoZKDwRxI147FbpVv YLPlUJg4a3FO0NzyIlbXnjaF6T3go/tvxGoR/Mc0E/8D9NUeY9eV9g2+OOg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021042; x=1793625842; 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=5ulk6XjkgH0e+2wC/uqh30VwHtLlb31J3vXz5/nMi2M=; b=B/2ymriBv+x+XeFF5pBwicPtUIeQVCQ/zatx2mZCDt68aFgeWh3VkbsogJrhHxsQuO VEoSUmfj9rzhYclpUtRtrgcU4Ap9UjQkFgDATUK5Ohdz1S/jNTVa1Xnkc2U4hNrQbKLn KfK9RIbM6+dKZVMpLapQ/F/NhkU9BswUQyl8A0gejYXKR3ze3IspJFJd7yHH6qOUpY91 9NyMwHEgAB9d2UZXu91sgG6QLv8bb2fm5gcT9ITvW+5iXlY63sAQ+IwOrc8orNWOsJBm iiKJj4MJoX4UGi1yxy5xtet33TA0tYhXKAl2toA6xfZjyWpBWDpbiyKKp4n2uLC17+Mt sMnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021042; x=1793625842; 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=5ulk6XjkgH0e+2wC/uqh30VwHtLlb31J3vXz5/nMi2M=; b=X70YKgXMydE2EthJfDuqbU93F0JS6dQTvv84oVfxqu6eaTarG/Dxl7WdTY+R2Wg8O1 03R8TeA7vhcqR3n52zg+pfxrQ2OlZMPNVrPIZurio1OvEDFxtyjg0WluM8oJCYx2fDtC ASOIJjuJ7MnMhFrxkLzZ/HhvjDz4spb9h67XTdbzarjrxTjVsA6CAs2sVSSEzCLk64gt nY4MnT/23YSrElN9YsksHC8IcO6CnHqlcZkZTjaB0W7SjDkWwjEqG47h+jU/GjrFoKU3 9kJwAXo2Mv7S64fmrWPZe4zInbzj1hzMxFfeqKTXyVrc4YpJ0v5U1HMWzr2DeJPbX5rJ 72Xg== X-Gm-Message-State: AFq9FYIe6f8JGZ69XAujxC7Aj5SIynMrn5Cf/hzURAXHnR/+h711Z3Nr ZY5KiRyYUXHIUE2UeQTZUG+TQXuZov7QOMBnp4qBQ82T3FS71cnalYEVxZOjE5fxikXu8aszJW0 qf/8JJ1JSwWDLgY1VUSI28L20keSXIz55rkzpC4BPuP4gSX/0c62M5RZUxl25ETh/sA== X-Gm-Gg: AYBFou3a+4CW5V0mGlpSQ0qNnaxjwiOMXMEODKD/rrBGu1zIhBsgJIaEJKsqDQy+vgv Dwjb+4EMOFwi8w7PIJwqd+TxJMbDAf56XseI3yypDB/g6Hl0mkffnZHK4/NvpRDM3InQYXjwpyd J+BIMvvvDhQ6g23qrP9hYHQr4WlpfEzyTevAztqKRG9yiNg/DoAcyWSvCbadgYPv8LcJHM8r7Ha rmUeVXnzSPMe/ZlmCd63BpMvy6edQLIZzNHLB0ypv1hO+tCX5iiolK12e9YBowUIEC7kHGuATtQ 9VjgDvea1Qw7tXNBCi8DUNqEXq37v6Wm/kwgWF9ygRM+VNdu8sgFCcpni+rY6BSvVyiKtTKW5A/ 490VE7tFdaEjdY0xObKowGaxyRmas8TosX/BIfbEIVduqFuVQzzMPlN/ILax5Egjh9yEJmlDmat aMSRmsNAD4l5aGkVgX9RVNxIavi/CaP3M= X-Received: by 2002:a05:7022:488:b0:127:def:dd72 with SMTP id a92af1059eb24-19933f05929mr20572226c88.2.1793021041127; Mon, 26 Oct 2026 06:24:01 -0700 (PDT) X-Received: by 2002:a05:7022:488:b0:127:def:dd72 with SMTP id a92af1059eb24-19933f05929mr20572098c88.2.1793021040301; Mon, 26 Oct 2026 06:24:00 -0700 (PDT) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu Subject: [PATCH v12 09/10] tests/qtest: cover initial RISC-V RPMI services Date: Mon, 26 Oct 2026 18:52:52 +0530 Message-ID: <20261026132254.2652399-10-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX+rt7jb3NNG83 ylX5k1dt+peY9hoyD0APNoafzIlcG/q0gMEpzsKfQuifVh43WGH21a9TGWb0DZ778xF71/LzLlm cXhU3b+P/1Oq/Aek37YLeNK9nIaSdGE= X-Proofpoint-GUID: ZHROepCQxO3MUVwfKa93pxu2npLH5R-A X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX0pE55QtIbHD6 VfANxXEM9dmSFTIrBQ3fT9YJDN8ijgglle6HfhxME0CM2lir78eDVsENfMvr4UCIjKZejCvzw7/ 8A0pKZQy8D0KqeC61G/r6Jbpy1mC5USqtwtmmdsP016b27dD2sBy0Cx9y44RbDPQqKJ50xGkE3c WFMG6o7rTOd4FD5c4UpnBIDKaOqF/24VSmqpyitdjTGlo3k2AnD/jEOtqB2/ouip96fhMZLLi2Q Oi2YKORAkZPyNPkQVFywD/zz9jsLyswbBdZUBI6GYr5byBUhfE3Pj/HrF1I47CLAmh++HldrI0P AIz42YnNhL2WFm2wLtoDu4r6fKudUmBGR7UJsIkIUJRpMZ2kWNdptKXESCKCqpOQwNLEh2CgC82 1kBUgHBrOzTBGUzKLG1iIGdtGd36QaK8fSvOzlTKdEYNzIdbL3a4rLuRhQ71Umsegs0kQdhsqDo AWmXfFbKruwPp5X+Wsw== X-Authority-Analysis: v=2.4 cv=HZWB3SE8 c=1 sm=1 tr=0 ts=6adf5472 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=CgxbgbrB4M1EZRPeLE4A:9 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-ORIG-GUID: ZHROepCQxO3MUVwfKa93pxu2npLH5R-A 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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 clxscore=1015 adultscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021143221158500 Content-Type: text/plain; charset="utf-8" Add qtests for the RPMI transport plus Base, system reset, HSM, and system suspend service groups. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- MAINTAINERS | 1 + tests/qtest/meson.build | 3 + tests/qtest/riscv-rpmi-test.c | 686 ++++++++++++++++++++++++++++++++++ 3 files changed, 690 insertions(+) create mode 100644 tests/qtest/riscv-rpmi-test.c diff --git a/MAINTAINERS b/MAINTAINERS index b0afe3fe0e..cc71369b7a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -378,6 +378,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 46685d6d46..0a2ece0bed 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -314,6 +314,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'] : []) + \ @@ -436,6 +438,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..fe9bb3e919 --- /dev/null +++ b/tests/qtest/riscv-rpmi-test.c @@ -0,0 +1,686 @@ +/* + * 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_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_SUSPENDED 0x04 +#define RPMI_HSM_TEST_START_ADDR 0x80000000ULL +#define RPMI_HSM_TEST_RESUME_ADDR 0x80001000ULL + +#define RPMI_P2A_ACK_BASE (RPMI_SHMEM_BASE + 16 * RPMI_SLOT_SIZE) +#define RPMI_P2A_ACK_HEAD RPMI_P2A_ACK_BASE +#define RPMI_P2A_ACK_TAIL (RPMI_P2A_ACK_BASE + RPMI_SLOT_SIZE) +#define RPMI_P2A_ACK_SLOT0 (RPMI_P2A_ACK_BASE + 2 * 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) % 16); + 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; + 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"); + qtest_qmp_assert_success(qts, + "{ 'execute': 'dumpdtb', 'arguments': " + "{ 'filename': %s } }", dtb_path); + qtest_quit(qts); + + g_assert_true(g_file_get_contents(dtb_path, &dtb, &dtb_size, NULL)); + 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, "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); + } + + g_assert_cmpint(g_remove(dtb_path), =3D=3D, 0); +} + +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) % 16); +} + +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_false(g_spawn_check_exit_status(wait_status, NULL)); + 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_P2A_ACK_SLOT0 + 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) +{ + QTestState *qts; + uint32_t reset_type =3D RPMI_SYSRST_TYPE_SHUTDOWN; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + 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); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, + RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE); + + qtest_system_reset(qts); + reset_type =3D RPMI_SYSRST_TYPE_COLD_REBOOT; + 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); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, + RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE); + + qtest_system_reset(qts); + reset_type =3D RPMI_SYSRST_TYPE_INVALID; + 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); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 0); + + 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, 0x1000); + 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_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 test_rpmi_hsm_hart_list(void) +{ + QTestState *qts; + uint32_t start_index =3D 0; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 4"); + 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); + + qtest_quit(qts); +} + +static void test_rpmi_hsm_multi_socket_hart_list(void) +{ + QTestState *qts; + uint32_t start_index =3D 0; + + qts =3D qtest_init("-machine virt,rpmi=3Don " + "-smp 4,sockets=3D2,cores=3D2,threads=3D1"); + 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); + + 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 uint64_t rpmi_hart_pc(QTestState *qts, uint32_t cpu_index) +{ + g_autofree char *registers =3D qtest_hmp(qts, "info registers %u", + cpu_index); + const char *pc_line; + uint64_t pc; + + pc_line =3D strstr(registers, "\n pc"); + g_assert_nonnull(pc_line); + g_assert_cmpint(sscanf(pc_line, "\n pc %" SCNx64, &pc), =3D=3D, 1); + + return pc; +} + +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); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STOPPED); + + 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, 0); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STARTED); + g_assert_cmphex(rpmi_hart_pc(qts, hart_id), =3D=3D, RPMI_HSM_TEST_STAR= T_ADDR); + + 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_SUSPENDED); + + 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); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + if (qtest_has_machine("virt")) { + 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/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(); +} --=20 2.43.0 From nobody Mon Nov 23 04:36:03 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793021115; cv=none; d=zohomail.com; s=zohoarc; b=FtsuhEuNnWpxvbBhw1viJzCHvlI13Ua97nzfxUYJsGyRMESOvMBaabLkIZEZKsY0fv9vdo5DOtrJEfDM4zuFK6hQu26d1xwfrOcsz2VaMphTwseTRFcOs1sdyPmx4b02naiMN/UlLNW8YLw2pNnxPIZAXnIcqqjKuuqIQp/o/Ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793021115; 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=jjimakbRNf3sibYKXqGYuHPGisMTQj40lpsh+tSmlKw=; b=NeSwnOPxmg5LuZOHUFDdu3HRgSVLVB9Vc4t70nxoelY/5+ZsAPTBR/+i/jVAHfw8y2rxIJhCJQHWu+uiJnUvYmx5jrP13crZLVINtOjxUIg6ryCEuo8dvBm7KtFCVPJuifpEzSDE23Lpz2oOBc0UJJLCquTgi/PB+PuOpUGYsUM= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793021115548685.6955996728134; Mon, 26 Oct 2026 06:25:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLKhA-0002cL-PY; Mon, 26 Oct 2026 09:25:00 -0400 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 1xLKgN-0001a3-PH for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:24:12 -0400 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 1xLKgK-0005IU-RZ for qemu-devel@nongnu.org; Mon, 26 Oct 2026 09:24:10 -0400 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 69QAsm3i2168530 for ; Mon, 26 Oct 2026 13:24:06 GMT Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hj3u60xvg-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 26 Oct 2026 13:24:05 +0000 (GMT) Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-1501de3f7a6so29901c88.2 for ; Mon, 26 Oct 2026 06:24:05 -0700 (PDT) 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 a92af1059eb24-198a21bc6cbsm24360931c88.16.2026.10.26.06.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 06:24:03 -0700 (PDT) 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=jjimakbRNf3 sibYKXqGYuHPGisMTQj40lpsh+tSmlKw=; b=g3RcIQs8CnxqZSHMr+3srjmnhl/ cLjyn9Xs54bCXPxCBxetWInOUjTkzT4k8I6IGLq8YTQZpQQAlsgp/e8vjlUWZwkO bCWsrycwpXy5TGtUU4jKJg3isiyornWykWQgaJEbZ1Qooz4YVa3GKaZ5e9ZQFPET ehF7ts3VhKTfaW2rF7H1p0rAfoxiH0XJIVeWY9b33wEhJy3U/dsJPOBz3WnJuYf0 oasec88wlG//p4hSX4ktS/nnuA0o20wqdMDvc7xh871urbnDUMPIUbOZyNOrv+aZ sAYldHOFCm4kXj25Wwgtw3CTXpuj6n9tHy0WIVKskJtAyg8gsoaBJkT9qQw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793021045; x=1793625845; 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=jjimakbRNf3sibYKXqGYuHPGisMTQj40lpsh+tSmlKw=; b=V8C4Z2WHy4+3okQo72zNKXASOxB1GBoD6dTbfpP9ep8+lUK7Sr+028WiMm5SzRQK45 z1IpDnuie9HVTKDgaBygpQ54A1bvPG59UufcIrddCm2colaqC+azJJrKH0pqm2Fj4+3x TRNkFwhQQugOPx02FIpvm0pdFOsMCqdsxwFsmVJhHq13qL/rg9e81ld07GBMxgH9BSQf sfReKmCZfXz9eEHN3kisiXkYb8s9QhrQK21h9y2CsF1BC+jLQESKdEDz9Vs8zgll6aw0 cjfyx+HuCzGPCPOfmKEG/plZUZOC2zd+ZI63IMcDIbrQiJOSn9iedCRJgo7IwFh85tPa WyyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793021045; x=1793625845; 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=jjimakbRNf3sibYKXqGYuHPGisMTQj40lpsh+tSmlKw=; b=t5dnNl7PMJWeqdiGprcg/gNNyImSU1zVHT+aE6hWxeJTGsuipBxGraFcZM7TPjB188 Uk9rjOx47i391+aF9c8jI2bUESfJEC8oVFdIHjBYw4GMEoDb17WmG5XuQtPTsMvSIC2p 5rjRcct8uBHb/9lPJchCak2qvLYNaD4AzD72RUtSvwJ0WFameTVkVmLj1b79XFaIYPYE qE9YHSu/VSxLq/R4rvdPdiT06O/SiFn3qmscTWiKeRQ++YLO/p5F1G+p+t8/wuKhsyeO Lia1YnIymL5XlxZETVDhSpR/bMD7Va2cJGpts6iDDh9ftCxQ5nl7HFu+qd9MgmO39T8i y5ng== X-Gm-Message-State: AFq9FYJ/K6jEwvaPbpG2YfDKTxbNnkN1hLoYJU6eJXxe4FvJtbPkdPbn d5IgCYOgCZuODbCzi4SIljrwCj6aUslCP5EAwomPJ55Df2Y/kLO7sWRvtRaM7pbA+pdhU7hsO90 MeQGv90sFjhJVgHFNcINz96ToZqg3SzRag7JBAvfe7847OtNjRuiVzpiSXvsMLpzLsA== X-Gm-Gg: AYBFou1T6BNrl5zaazInpUrBfWfEJA0rKFzpCa9FC3+qTMRxQ5sNPL+cubf1pSy7ksU kK6eUXNzumcdmL1osTMfmz0rqjKXegX18DqTnPNlRaDnf2A+y6sx3UUfdujeH8JISeg6F9lJWc7 MfQbK0E6ez3LBdTk+zcD27YbZ47XVVXjnjMV7XvGH7S48iUc4BHpdwh2nvZBebbRkxrWHHzV8Av TZKFx42WHItoeko/CB2A7H7TzyMiXWOAfMdb1HxSla9e3XcyLwiwLN79kSCtcnsZHpxpqtKRiMZ ECcIJOYKHpbBeL2jcp4NaIfsJKZYPEgkXWSBgYB0ao1WgMaGgNdBh1+XWyqQhDYS/X/kRvQqTpL Pi4lns82satp9aHEjnQ+3Vr0HFtL4l2LV2GLiPGaDdtvsp0mdehk4dBLQ1sGtS/5tXMpk+nD9oh PVNa/i4UAyMwzw0fe1EOS+8sd4mySMp8s= X-Received: by 2002:a05:701b:454d:20b0:147:d430:7322 with SMTP id a92af1059eb24-1993329074bmr14562944c88.1.1793021045003; Mon, 26 Oct 2026 06:24:05 -0700 (PDT) X-Received: by 2002:a05:701b:454d:20b0:147:d430:7322 with SMTP id a92af1059eb24-1993329074bmr14562865c88.1.1793021044174; Mon, 26 Oct 2026 06:24:04 -0700 (PDT) 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 v12 10/10] tests/functional: add initial RPMI virt guest smoke Date: Mon, 26 Oct 2026 18:52:53 +0530 Message-ID: <20261026132254.2652399-11-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261026132254.2652399-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: x3rgoKPtvF2k76-ZgyhF9_cby1QjPWKU X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfXyFOZCKoOHhbu 8Y95wf6SKsGPdZQ+Ar/9HjgH4/4ndOYMi1+WjbDFKSDKZBwl/Ynv0n2A61iwtPSFfOwyCnwKHxG nz0gvNtb+AjEb3mvm4m8EtFf76iATNAxoVgsbBr0XpX2Fuqrto3yLuyPdHRttz18s0znbP7cRsL HlkEGlD9N53HgOhySnvwajlmbiXrgII1vBEwp3kaOg6yi0NmI0/ESxT+xZbriWBTBmxQejkSiF8 djafMSFuag5Z9HuYPPt9SM3An/ohSlnl0FqjLpIuS7DJxv343ECCg6G9mprWY8jepgyatrQCEXS Sp9zzgXQ94u83M8bkikt7dGxPqnzWOl0Krc1SdmO2769Z7nUYKgcPQAuoScoKMuscJHdhVC+E9Y pXwhhPt/DMWi6d+/hVvxduOLOfIKtprbKNBaWNeYs4+VM1wnvJ8BXmIYWTI5qcZzQMsfT9V2i5v 8U9KckHUlSUdpP6PLGA== X-Proofpoint-ORIG-GUID: x3rgoKPtvF2k76-ZgyhF9_cby1QjPWKU X-Authority-Analysis: v=2.4 cv=K823jCWI c=1 sm=1 tr=0 ts=6adf5475 cx=c_pps a=SvEPeNj+VMjHSW//kvnxuw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=660iZSQnnn4A:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=qwN9Sapu9sPqXycc-XcA:9 a=Kq8ClHjjuc5pcCNDwlU0:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI2MDA1MyBTYWx0ZWRfX9d4CPaVX4jMV cw821HiE6Rtc5vWtT3h26Jj2Ra/pWUTAwVQ0b3d5F1iAt8s+l6FxaHDS0ArZZpaGGnuRAW3i7Q0 obroAHgphqGpL/ZniiKn/7NzZsGKQRM= 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-10-26_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 spamscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610260053 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: 1793021116972158500 Content-Type: text/plain; charset="utf-8" From: Subrahmanya Lingappa Boot an RPMI-enabled RISC-V virt guest and exercise the initial HSM, system suspend, and system reset paths. Signed-off-by: Subrahmanya Lingappa --- tests/functional/riscv64/meson.build | 2 + tests/functional/riscv64/test_rpmi_virt.py | 198 +++++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 tests/functional/riscv64/test_rpmi_virt.py diff --git a/tests/functional/riscv64/meson.build b/tests/functional/riscv6= 4/meson.build index 211ea9acfc..565f4a9dd8 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' : 300, } =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..cf15705d06 --- /dev/null +++ b/tests/functional/riscv64/test_rpmi_virt.py @@ -0,0 +1,198 @@ +#!/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 +import time + +from qemu_test import 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. + + This test intentionally keeps guest artifacts external. 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. + """ + + timeout =3D 360 + PROMPT =3D 'root@tuxtest:~#' + + def _require_path(self, env_name): + value =3D os.getenv(env_name) + if not value: + self.skipTest(f'{env_name} is required') + path =3D Path(value) + if not path.exists(): + self.skipTest(f'{env_name} does not exist: {path}') + return path + + def setUp(self): + super().setUp() + self.opensbi =3D self._require_path('QEMU_TEST_RPMI_OPENSBI') + self.kernel =3D self._require_path('QEMU_TEST_RPMI_KERNEL') + self.rootfs =3D self._require_path('QEMU_TEST_RPMI_ROOTFS') + self.qemu_img =3D get_qemu_img(self) + + 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() + + 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_overlay},node-name=3Dhd= 0', + '-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 + + 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}" ]; ' + 'then echo RPMI_LINUX_HSM_START_PASS; ' + 'else echo 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 ' + 'echo RPMI_FDT_SERVICE_SIBLINGS_PASS; ' + 'else echo RPMI_FDT_SERVICE_SIBLINGS_FAIL; fi', + 'RPMI_FDT_SERVICE_SIBLINGS_PASS', + 'RPMI_FDT_SERVICE_SIBLINGS_FAIL') + + def _validate_hsm_stop(self): + self._run_marker_command( + '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 ] && ' + 'echo RPMI_LINUX_HSM_STOP_PASS || echo RPMI_LINUX_HSM_STOP_FAI= L; ' + 'else echo RPMI_LINUX_HSM_STOP_FAIL; fi', + 'RPMI_LINUX_HSM_STOP_PASS', 'RPMI_LINUX_HSM_STOP_FAIL') + + 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; ' + 'else echo RPMI_LINUX_SUSPEND_FAIL; fi') + wait_for_console_pattern(self, 'RPMI_LINUX_SUSPEND_BEGIN') + wait_for_console_pattern(self, 'PM: suspend entry') + 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') + wait_for_console_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') + self._validate_hsm_stop() + + def test_linux_guest_suspend(self): + self._boot_guest(smp=3D1) + self._expect_rpmi_firmware_and_linux() + self._validate_system_suspend() + + 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() + + +if __name__ =3D=3D '__main__': + QemuSystemTest.main() --=20 2.43.0