From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768903; cv=none; d=zohomail.com; s=zohoarc; b=iy3eXavC0M2rvBu/ecVKzDxC3Pm3ScbdnpYeYLR0MHwJCFXxze0h7PVTA3Ozu2GXQhyduAEz4CBcCRTOFCs8ABhBy1rtQRt4p2li7qiTXkLzOj811+t62pYNkMLSjtFJm+ESqQj220VsL5qi7ziHpFQ0PB4ZICP++6tK6QuLFBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768903; 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=+Q4wZP/ShiuYZUn1lGH7YdU9moBHfpBcSJIBbthl4oA=; b=grgpI1ONhedb3/lFSbVr+E9Hq3SAK7mQXOuEUvh01USGOHlM9Xd/zC8NOrEvENzHUMnXcePrXw2csIPI1xEJQIv9WJQ6fum88Y4IwusWCKUrBeuPgszZAFJ2hT1NOA0biAr7WSNuV7w+XSFrLidGQENYQSVFASWfye2w2AZNq/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768903090967.2787703697619; Tue, 3 Nov 2026 21:08:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTCK-0004Ur-8q; Wed, 04 Nov 2026 00:06:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCI-0004Tt-Sa for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:06 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCH-0002B9-0s for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:06 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40R7sC1191178 for ; Wed, 4 Nov 2026 05:06:03 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 4hqm2pjbfj-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:03 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-36c98e5ad40so49435eec.0 for ; Tue, 03 Nov 2026 21:06:03 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:01 -0800 (PST) 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= +Q4wZP/ShiuYZUn1lGH7YdU9moBHfpBcSJIBbthl4oA=; b=Qyau1z3tayqjnPSf K18JZPljmfFpWB4eqfhZ59ea2UtJGtg/t6Ka2AlXHuXVcdsSzsJVVL1lFZsrnhfA WFb5sTuhz2ulf23+FfCz6cAlVm9JLkhxQTM3bpY+MI2B7VNn2U6VgL5cx9zaXYq1 fB0r6WKcxF8pXhUVnz/YFdG+RTXLXLFqj13GhENtEGM4K9GqUyyon+kRCOSbgJ/k oC6M6wubF09vCxSIEM7lcVE3oJvbVjNJ25Cm0htO52FUPzPRW7zhAoUAXJjCWjyY LFmnRAfE1guY1PGX8EhR8w+bmZzTg8ufiN2iYYkNCNpsK4E58LweFu3QUKGdvQ6i hj1kiw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768762; x=1794373562; 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=+Q4wZP/ShiuYZUn1lGH7YdU9moBHfpBcSJIBbthl4oA=; b=NfWheHIsAH6aK2JHgawPCbcDMMLTS0qTpFiDPaqrsq10MGiOyBge4klzz+Fe8oqsex OmhAUs8UQ78JHNL7L/8LtQWe2MIlpRwmr4AacfUMrmmoEICdgNH79ZrKj7qan2+JBzLh q6Btiv7WTf9Cj7BelS9mJglna6JoFAhiby356EN9eLyb7BK5a/LF1oiXeBXczfrLMLMT RpmOWMxz77bHprlt4l/mv0rgLW8R2rdG2iZPzwJmqerP7/0FHc2m392faXBhc6Z2Vkx1 rQ6y/riEtWZs80I5NQAigRA260DIb6yn9Wch2acqmpT3A0cMIGkJiw8oUNFQb6fbI2/h +sog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768762; x=1794373562; 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=+Q4wZP/ShiuYZUn1lGH7YdU9moBHfpBcSJIBbthl4oA=; b=Q36BmJO52Eee4hx0GTxAZEICfaCOYiBZay5lTR6vV0fLo+7IO9alnqW++IWrY67uPe yXhl1kWR3SgmbqoympS0wa/x+l7jBs3U+mHD+BAOF+o7QUIQ4FJjgFT+LMK+Z7YCMv0M SCWZV9rIIybVvUMIibC8uGE1RkP8X+eHaGIX7oZk9r+a6Tsu+bAGSYd2IzFvvNrp98Xz 887fxYYD2VkTIFoJu8JhpaVXi5+hAewKL8SQT0oe1pBJ6XvrBhyKrLnyD5fK1BmXfu0D U/QuIsyBmAdq5oOXbS/jaXD4TGC7rC3rySNU0/zR/3y7m0DxZgNEfS8yLpubTKzHFQTf zdiQ== X-Gm-Message-State: APuU4Z8IcXFvR43HSbl6nHeeW0NNEmmuJIkqJ0+bH8peNEY194n31I01 ZVr6Fapl4H+UMXDUjQAbTOdnlsP67wPyvJYYVqgAwkHvPMjgOuyGRWsQ4suqOIxxVC9fKpGdjMC BSTPlLG6ABKxi7Nmuons+MSkWcPfYV8ORPY3nWSwdus/E6yNgtBjOInlS0+KE7h44jQ== X-Gm-Gg: AYBFou2rsJwZ0PiDBht6YSftRLvrGIyG3dLs9D0kRfNPZfi7SoKMmPwNDmlUrXwQGdR tg5F9FzooZWoSuBQHERz1sT6UG9u7DtZUNbyb/eLfIP8u+aRLow3wCeIqkq16/OqwSPuTr61zQZ 9GG+jfnqFhV3e+45pmXAMZQ6JZGxFlECqw0CTKgkE2b1Boo2JsDk4KHpOIlLEi6Wo7SnZXnGAZb cC6wol9acWg5pZedd/Bj7u9pXMC5lE9BBKJFThEeVDXMr9rkxrFl2xMAdUrOC51qnok5VlnADTF rEucNJEx5Rcg8w3eJ8J+GVzTek3Ua5WNbIhkE4uLWFp3UHf3idzLGCjTK53o3hxNY0Zai8dcOhX N4PgGeG8GzXMOqpUW0HqqaPtzsHWMWdZMsJT2srco7wEE4XPZhen5ihmUzEUzpH9cmiyX0P4MaB hhBsqYD8lIV0Je+o7Y2PDAFMRXQ89/DRdvt5EdVpSSPfv6WI+nEMA4tLtRNaUwQbGeP6IbDEPm4 FK/X6+s X-Received: by 2002:a05:7300:d082:b0:369:ffc5:6767 with SMTP id 5a478bee46e88-36a4236a643mr29516969eec.2.1793768762213; Tue, 03 Nov 2026 21:06:02 -0800 (PST) X-Received: by 2002:a05:7300:d082:b0:369:ffc5:6767 with SMTP id 5a478bee46e88-36a4236a643mr29516914eec.2.1793768761386; Tue, 03 Nov 2026 21:06:01 -0800 (PST) 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?= , Pierrick Bouvier , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v14 01/10] build: add optional librpmi dependency Date: Wed, 4 Nov 2026 10:33:14 +0530 Message-ID: <20261104050324.733555-2-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-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: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfXy2YumpCpJ1J9 +aZASTz9PrQHGhCxzXqTCbWKuwg1kINlUSUw46Yh5GKs3YIXHS9SUHgCvDVhowmc+pq5Oo4aNAa BtGsQeBcp4LR6RYhPovwCR2MmFHUmAsTkVC++hTOKmsO3wfCyQ5cusV6OYGNO8ZYpEjPXo2tsvm Rt6SzC97Ip85voyiWn3jZgdedmByntmhzSrFXkejFVRm2pVAcUTX4floPG1qoTROLCOa0SuRPMU FNJTPwCF00O+Y9/HtuAeNPXTqFfMYSVNcd8fXZZupDlPtEi94vGwj+y0yElPUt4hrZQmsshFXMa hNtjO+Ral8h5SzxdjhB1iTbb0ThsPtFurF1HmpZS9QeL71dNUxv7KyDgBW605xlzWgtPLGOI/L9 SI7hzWeeBMG1CWq68nrp0zIjQDYGixKAwiXwdbs3BwzEZn1fYhlR9/urpWLWHYGolZwQLQT0THi RLJ0g8xenqLfW3q59ng== X-Proofpoint-GUID: TBtBVjnu_AZZ4tM80KDDcG53DPguQTMs X-Proofpoint-ORIG-GUID: TBtBVjnu_AZZ4tM80KDDcG53DPguQTMs X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX3HG7p6qi/mth L0tl67gZNu8JSkchoRe7Y1xtZ0HeVe3V0+KbaLaWL6cWzDsZkYVK0L9pDsgutpClgb6AR8/eVbO u9A64Y3HO7W1WcjeE4RiophqtWZj2NU= X-Authority-Analysis: v=2.4 cv=c64+0h9l c=1 sm=1 tr=0 ts=6aeabd3b cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=JF9118EUAAAA:8 a=1s-lSuUWbzXNuijj7TYA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt: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-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768904340158500 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 71f135f053..434a193efe 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() @@ -3286,6 +3298,7 @@ host_kconfig =3D \ (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=3Dy'] : []) + \ (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=3Dy'] : []= ) + \ (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=3Dy'] : []) + \ + (librpmi.found() ? ['CONFIG_LIBRPMI=3Dy'] : []) + \ (have_rust ? ['CONFIG_HAVE_RUST=3Dy'] : []) =20 ignored =3D [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR' ] @@ -5036,6 +5049,7 @@ summary_info +=3D {'TPM support': have_tpm} summary_info +=3D {'IGVM support': igvm} summary_info +=3D {'libssh support': libssh} summary_info +=3D {'lzo support': lzo} +summary_info +=3D {'RPMI support': librpmi} summary_info +=3D {'snappy support': snappy} summary_info +=3D {'bzip2 support': libbzip2} summary_info +=3D {'lzfse support': liblzfse} diff --git a/meson_options.txt b/meson_options.txt index 9ae8e44ab5..62c9eaa20b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -208,6 +208,8 @@ option('lzfse', type : 'feature', value : 'auto', description: 'lzfse support for DMG images') option('lzo', type : 'feature', value : 'auto', description: 'lzo compression support') +option('librpmi', type : 'feature', value : 'auto', + description: 'RPMI support') option('pvg', type: 'feature', value: 'auto', description: 'macOS paravirtualized graphics support') option('rbd', type : 'feature', value : 'auto', diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 0f8b56bd7f..1c2ad8f0f4 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -147,6 +147,7 @@ meson_options_help() { printf "%s\n" ' libkeyutils Linux keyutils support' printf "%s\n" ' libnfs libnfs block device driver' printf "%s\n" ' libpmem libpmem support' + printf "%s\n" ' librpmi RPMI support' printf "%s\n" ' libssh ssh block device support' printf "%s\n" ' libudev Use libudev to enumerate host devices' printf "%s\n" ' libusb libusb support for USB passthrough' @@ -390,6 +391,8 @@ _meson_option_parse() { --disable-libnfs) printf "%s" -Dlibnfs=3Ddisabled ;; --enable-libpmem) printf "%s" -Dlibpmem=3Denabled ;; --disable-libpmem) printf "%s" -Dlibpmem=3Ddisabled ;; + --enable-librpmi) printf "%s" -Dlibrpmi=3Denabled ;; + --disable-librpmi) printf "%s" -Dlibrpmi=3Ddisabled ;; --enable-libssh) printf "%s" -Dlibssh=3Denabled ;; --disable-libssh) printf "%s" -Dlibssh=3Ddisabled ;; --enable-libudev) printf "%s" -Dlibudev=3Denabled ;; From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768814; cv=none; d=zohomail.com; s=zohoarc; b=aRYBhvU6H0GVFmU79x6/KEirTHIvOoxWPKnz3yhGFV/xG7dqVgkhMV6yAz9R92vrflNjJCJ9p9xnWzr9wCHgd58JKBjS3CrqHTn2892eirlwnUcJDaWYhjbtyw66hlQ51E7+CqwiY68B6WuOR1TeyOKEB1e6ZamOAgIwF1bcqdQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768814; 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=KmOhbnslAFhRa9K4Vc9LKcI8NgfxY4HbVrgEeVNErsc=; b=YoNWdO691qak0K7QIMK/ApbMUcRXk9/JtP3RZ/5jNVTiT+65HWJUtDF4yspL7Df0bdfGO+kYvGbnBO9AHck63d0Yf5oUftP33GWO0+ItWaoDrfMbqOBjVtNgTK/lABqEwPXangA/B3cnhPqo0StWnWlX+iaydeILY/kpYngegxc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768814110901.9780248310796; Tue, 3 Nov 2026 21:06:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTCQ-0004Ye-6W; Wed, 04 Nov 2026 00:06:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCO-0004Vs-69 for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:12 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCL-0002Bh-4v for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:11 -0500 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40RbOV3867680 for ; Wed, 4 Nov 2026 05:06:07 GMT Received: from mail-dl1-f71.google.com (mail-dl1-f71.google.com [74.125.82.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hqn8y203y-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:07 +0000 (GMT) Received: by mail-dl1-f71.google.com with SMTP id a92af1059eb24-14f0e9c6404so13034c88.3 for ; Tue, 03 Nov 2026 21:06:07 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=KmOhbnslAFh Ra9K4Vc9LKcI8NgfxY4HbVrgEeVNErsc=; b=UxHlvWw1Z3KKdZcVmlAtvou6AjF laNfjSrNReU3eaz6BcCth/sZdifkROWH7JDHR1f+h+PkKgwK2uzJm8uMGj5jSI6u melNMxnuhISjMSzTBEAdzQFZOITJLFNxdsqTdOOV1KYbzG2jaAmaOHC4dhJs1Pfd dJ3eAP/BXMl6pqJ01p3BYVlwd3Nhd0D7UfNR1LzuClNc7vApiV9NuqVaKuRJT6F1 yXZJAbMjg8QAvuPe/YiYyGSYl9jCq81Tk4uI4CWVoVa4re+n1+V0Qko41OY6+mh5 dYzx4+LODAy/VA/LGBwJmpXfABcozrOCea6wS9J5IIlt0jdMFn5jP/G9eNQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768767; x=1794373567; 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=KmOhbnslAFhRa9K4Vc9LKcI8NgfxY4HbVrgEeVNErsc=; b=TLkjdQBH9kgro6/3WS7lSxKVpkcONTKzWarpyrjGNhyXpMnnz4d1D2DwVJivj34UGL elwxzqg/3LooIA+vejXOh3l2f4AGsKTlWo4jcmHMtDTjqUWvmz/rvSd8HqUz3T4b1DxC RqM+S6I3wj7k1+vaaIRu1Ao3Y1qieJbV7cuc+1PPjR7NZ+YG6M+H633QzeuMNk6llowq u53eoOhYRe6isEstE3c/kzjLUjEbPXzkAIOeAWmWps2E+f2ne/WFVHSmnMfzWScO/d7W mpbCsuLl5+KS2XDrfAEdqKXt+4L2yg321TjxeIzkxfhsQLTHW5mf/xylPFRgM1O0O++j PSHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768767; x=1794373567; 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=KmOhbnslAFhRa9K4Vc9LKcI8NgfxY4HbVrgEeVNErsc=; b=Knhssvkgmc/i2HxAMlT52i1JDADhmGhAP3flMpxplZkcXps1VThy9EL7DWiRYJ/BW1 /QH5UC2Qkxl8vZgKVgmDCvcdUeS5BZO0A/HGuMPX8MOqtPZ8dimF2GTEed2ofFjVNJnY c1rgDCxvewRvCzF+vByz1cmd8WywHJSwh32DbW4SMd2OPV62czmkol6a7x/J8g3KJB1j 1WKuG9cw7mkp/qYdX3j5oc1gRQx6FmuNzTIoiVV0/21fXvVwGjTsWet+olil1r/okYs9 P6jeYBVki6o4dhSfi5uJxInE4s5nOruqAXckTNosdqOfIXDzxeq223o+h2XtY0iDgBDu pWBQ== X-Gm-Message-State: APuU4Z/7FfadlgSCK4TDi2/3Qc45V20O1JShyL9ugYUJg2y0cnv19qDu UlAfq+cAOPcNA7Y19IypJsnV9ifnetrLagth9NtA4nSiwZjlONy24m3bKtSP1kTaN4tPgO7nqra w3cr0O2SzZ2SfFsZHJbV0luwGCF5IXCL9rK6/Pk3frMNrTeiy0PVhZB9cHIl2SPK9ng== X-Gm-Gg: AYBFou3YvFD1JINXXLtwLARahvyuN/yP7vMhAPZ3ZYVRlVKQK9my9Z8Zjnx00pehvNs /uqQxJjXVd3femksSq7q7MOT8TB/NmPZFwmfetMEtQ5cYXlryWoyajlIEzlmisUGiTiExL8aYxR i7e7gk5YHYU+7BCRchWePeaUT7QQ78WtFmhcNC3PtjT1cOEG0N3OiiN/emJZ5Se+iS/QkMKKOaI OrHyd3e/NV3MlNNL8C1LA8zxT2PrvIiQat2K67arwT4bYxbU46eOl/48iYJMEr/y7pWCR4jsYso ghv9WSHJ5x0hS0gVOlmU5Hets4g0LtZ0Rz+tE3VnWpRCtZGhe4nnwekllFIZV8Rq+lSdCqgeryB P0NZ1g0TT/KWs8VqNlv7p2BWjno3ZQXs6tGzFabYCfE5TIxi8EzI/YrJ4o9BcQS+VuDHAfcg/JW l8JX73zXikTTEMt1nHYF9F9B43/bX77zu2xdvNwkxeD7nNlslMbXfaEFnud0z0jvqXPeQRnJ9d/ IGBGdkf X-Received: by 2002:a05:7300:d090:b0:36a:e7a:e89 with SMTP id 5a478bee46e88-36a4239cc86mr33459667eec.2.1793768766477; Tue, 03 Nov 2026 21:06:06 -0800 (PST) X-Received: by 2002:a05:7300:d090:b0:36a:e7a:e89 with SMTP id 5a478bee46e88-36a4239cc86mr33459615eec.2.1793768765484; Tue, 03 Nov 2026 21:06:05 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Paolo Bonzini , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v14 02/10] hw/misc: add RISC-V RPMI transport and Base support Date: Wed, 4 Nov 2026 10:33:15 +0530 Message-ID: <20261104050324.733555-3-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: IILV82vBIya0HXZo-qYIP7_wiPlolwqi X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX48Jsndkm6n/G GvKcEThCqk75g1HMJ3aWWmxtKtanUwt4Yk7j7SMnu3xfzzuaSWtVILTC1ZecADdnczDmDd/KQCK REVvx9YdaUlzQUTkmwgiqYOLcpCGbrlrc9KD6vCvWIqPZI30zZKFQPSwoiAqLi+YWrqe42F7G6d cY8Ck1xuq7h3VGJPnHaxqTbvBBx8y22amvDRnRCYgTovYEWKlsycC7/cYxteXihAqNFDGTSMotH mA8vGu6a9T76v6u+/4FJPwLs5QIcoHPxcTSceRZCJ6/gULMeNJmm3Lu95CKUoGelqqNiah5VR6k oxG5aIdylLQcWYKZpokGCNiZknYUgy2Oj0lcJ4sj8G52NtaN+0sjgdrao8W7+uhGTNrZNWoqmaL k4WUKOS7o47eQ7uOoFQYdtz+GUba84RRrf0sXeKRvTTFHhZB2y7BC7rjfpG1/y5Jmq20cTSqGx9 s/pp04fSdyS/UQ7qCJw== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX2SA+VX8o5KDq +bJ5Zp+1T2g95MdlJqYxsKetF1aq678Y0ecW/NTpnd45R9CoFU8Km6QfwSfOfy1e0/1jBiv/rDo 9nYrfmJ2zll3m8NWIjKOC7LY90nA+qo= X-Proofpoint-ORIG-GUID: IILV82vBIya0HXZo-qYIP7_wiPlolwqi X-Authority-Analysis: v=2.4 cv=NP5AaE6g c=1 sm=1 tr=0 ts=6aeabd3f cx=c_pps a=JYo30EpNSr/tUYqK9jHPoA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=V1jnuoLLAAAA:20 a=NEAV23lmAAAA:8 a=hwM_GrIuAAAA:20 a=EUspDBNiAAAA:8 a=bDgSmJffVkpEkReGgNYA:9 a=Fk4IpSoW4aLDllm1B1p-: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-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768814671158500 Content-Type: text/plain; charset="utf-8" RPMI (RISC-V Platform Management Interface) is the RISC-V non-ISA platform management specification. It defines a shared-memory transport, message protocol, and service groups for platform management. Add the QEMU transport backend and Base service plumbing for virt using librpmi. Keep context lifecycle, service-group changes, and request dispatch under the existing device paths' BQL ownership. Document that the librpmi environment lock hooks are no-ops because QEMU provides synchronization at the call sites that need it. This implementation targets the RISC-V Platform Management Interface (RPMI) Specification v1.0 Ratified: https://github.com/riscv-non-isa/riscv-rpmi/releases/download/v1.0/riscv-rp= mi.pdf The librpmi backend is maintained at: https://github.com/riscv-software-src/librpmi Signed-off-by: Subrahmanya Lingappa --- MAINTAINERS | 2 + hw/misc/Kconfig | 4 + hw/misc/meson.build | 4 + hw/misc/riscv_rpmi-stub.c | 16 ++ hw/misc/riscv_rpmi.c | 514 ++++++++++++++++++++++++++++++++++ hw/misc/riscv_rpmi_internal.h | 25 ++ include/hw/misc/riscv_rpmi.h | 92 ++++++ 7 files changed, 657 insertions(+) create mode 100644 hw/misc/riscv_rpmi-stub.c create mode 100644 hw/misc/riscv_rpmi.c create mode 100644 hw/misc/riscv_rpmi_internal.h create mode 100644 include/hw/misc/riscv_rpmi.h diff --git a/MAINTAINERS b/MAINTAINERS index 55463103ff..7f7764b03b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -379,6 +379,8 @@ F: gdbstub/gdb-xml/riscv*.xml F: hw/char/riscv_htif.c F: hw/riscv/ F: hw/intc/riscv* +F: hw/misc/riscv_rpmi* +F: include/hw/misc/riscv_rpmi.h F: include/hw/char/riscv_htif.h F: include/hw/riscv/ F: common-user/host/riscv* diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 685b7ff1e7..cabdf3473c 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -303,3 +303,7 @@ source macio/Kconfig =20 config QCOM_QDSP6SS_CLK bool + +config RISCV_RPMI + bool + depends on LIBRPMI diff --git a/hw/misc/meson.build b/hw/misc/meson.build index fc3800baec..b755796170 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -182,3 +182,7 @@ system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files= ('axiado_clk.c')) =20 # Qualcomm Hexagon DSP subsystems system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true: files('qcom-qdsp6s= s-clk.c')) + +system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( + 'riscv_rpmi.c', +), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi-stub.c b/hw/misc/riscv_rpmi-stub.c new file mode 100644 index 0000000000..dc32b43227 --- /dev/null +++ b/hw/misc/riscv_rpmi-stub.c @@ -0,0 +1,16 @@ +/* + * RISC-V RPMI stubs. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/misc/riscv_rpmi.h" + +DeviceState *riscv_rpmi_create(const RiscvRpmiConfig *cfg G_GNUC_UNUSED, + Error **errp) +{ + error_setg(errp, "RISC-V RPMI support is not compiled in"); + return NULL; +} diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c new file mode 100644 index 0000000000..3a30d879aa --- /dev/null +++ b/hw/misc/riscv_rpmi.c @@ -0,0 +1,514 @@ +/* + * 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)) { + riscv_rpmi_context_process_a2p_request(s); + } + s->doorbell =3D 0; + } +} + +static const MemoryRegionOps riscv_rpmi_ops =3D { + .read =3D riscv_rpmi_read, + .write =3D riscv_rpmi_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + }, +}; + +static bool riscv_rpmi_queue_indices_valid(RiscvRpmiState *s, + uint64_t queue_base, + uint32_t queue_size) +{ + uint8_t *shmem =3D memory_region_get_ram_ptr(&s->shmem); + uint32_t data_slots =3D queue_size / RPMI_QUEUE_SLOT_SIZE - 2; + uint32_t head; + uint32_t tail; + + head =3D ldl_le_p(shmem + queue_base); + tail =3D ldl_le_p(shmem + queue_base + RPMI_QUEUE_SLOT_SIZE); + if (head >=3D data_slots || tail >=3D data_slots) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid queue indices head %u tail %u slots %u\= n", + __func__, head, tail, data_slots); + return false; + } + + return true; +} + +static bool riscv_rpmi_transport_indices_valid(RiscvRpmiState *s) +{ + if (!s->has_shmem || !s->a2p_req_size) { + return false; + } + + if (!riscv_rpmi_queue_indices_valid(s, 0, s->a2p_req_size)) { + return false; + } + + return riscv_rpmi_queue_indices_valid(s, s->a2p_req_size, + s->a2p_req_size); +} + +static void riscv_rpmi_configure_base(RiscvRpmiState *s, + const RiscvRpmiConfig *cfg) +{ + s->platform_info =3D g_strdup(cfg->platform_info); + s->services =3D cfg->services; + s->service_count =3D cfg->service_count; + + s->hart_count =3D cfg->hart_count; + if (cfg->hart_ids) { + s->hart_ids =3D g_memdup2(cfg->hart_ids, + cfg->hart_count * sizeof(*cfg->hart_ids)); + } +} + +static void riscv_rpmi_init(Object *obj) +{ + RiscvRpmiState *s =3D RISCV_RPMI(obj); + + memory_region_init_io(&s->mmio, obj, &riscv_rpmi_ops, s, + TYPE_RISCV_RPMI, RPMI_DBREG_SIZE); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static void riscv_rpmi_reset_hold(Object *obj, ResetType type) +{ + RiscvRpmiState *s =3D RISCV_RPMI(obj); + + s->doorbell =3D 0; + + if (s->has_shmem) { + memset(memory_region_get_ram_ptr(&s->shmem), 0, s->shmem_size); + memory_region_set_dirty(&s->shmem, 0, s->shmem_size); + } +} + +static void riscv_rpmi_cleanup(RiscvRpmiState *s) +{ + if (s->context) { + rpmi_context_destroy(s->context); + s->context =3D NULL; + } + + if (s->transport) { + rpmi_transport_shmem_destroy(s->transport); + s->transport =3D NULL; + } + + if (s->rpmi_shmem) { + rpmi_shmem_destroy(s->rpmi_shmem); + s->rpmi_shmem =3D NULL; + } + + if (s->has_shmem) { + memory_region_del_subregion(get_system_memory(), &s->shmem); + s->has_shmem =3D false; + } +} + +bool riscv_rpmi_service_enabled(RiscvRpmiState *s, + enum rpmi_servicegroup_id service_group) +{ + uint32_t i; + + for (i =3D 0; i < s->service_count; i++) { + if (s->services[i].service_group =3D=3D service_group) { + return true; + } + } + + return false; +} + +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s) +{ + if (s->context) { + rpmi_context_process_a2p_request(s->context); + } +} + +static bool riscv_rpmi_validate_config(RiscvRpmiState *s, Error **errp) +{ + uint64_t queue_bytes; + + if (!s->shmem_size) { + error_setg(errp, "RPMI shared memory size must be non-zero"); + return false; + } + + if (s->shmem_base & (RPMI_QUEUE_SLOT_SIZE - 1)) { + error_setg(errp, "RPMI shared memory base must be %u-byte aligned", + RPMI_QUEUE_SLOT_SIZE); + return false; + } + + if (s->a2p_req_size < RPMI_DATA_SLOT_SIZE) { + error_setg(errp, + "RPMI A2P request queue needs at least one data slot"); + return false; + } + + if (!s->hart_count || !s->hart_ids) { + error_setg(errp, "RPMI transport requires hart IDs"); + return false; + } + + for (uint32_t i =3D 0; i < s->hart_count; i++) { + for (uint32_t j =3D i + 1; j < s->hart_count; j++) { + if (s->hart_ids[i] =3D=3D s->hart_ids[j]) { + error_setg(errp, "RPMI hart ID %u is duplicated", + s->hart_ids[i]); + return false; + } + } + } + + if (s->service_count && !s->services) { + error_setg(errp, "RPMI service count requires service descriptors"= ); + return false; + } + + if (s->a2p_req_size % RPMI_QUEUE_SLOT_SIZE) { + error_setg(errp, + "RPMI A2P request queue size must be a multiple of %u", + RPMI_QUEUE_SLOT_SIZE); + return false; + } + + if (s->p2a_req_size && + s->p2a_req_size < RPMI_DATA_SLOT_SIZE) { + error_setg(errp, + "RPMI P2A request queue needs at least one data slot"); + return false; + } + + if (s->p2a_req_size % RPMI_QUEUE_SLOT_SIZE) { + error_setg(errp, + "RPMI P2A request queue size must be a multiple of %u", + RPMI_QUEUE_SLOT_SIZE); + return false; + } + + queue_bytes =3D 2 * (uint64_t)s->a2p_req_size + + 2 * (uint64_t)s->p2a_req_size; + if (queue_bytes > s->shmem_size) { + error_setg(errp, + "RPMI shared memory size 0x%" PRIx64 + " is too small for queues 0x%" PRIx64, + s->shmem_size, queue_bytes); + return false; + } + + return true; +} + +static bool riscv_rpmi_add_service_group(RiscvRpmiState *s, + const RiscvRpmiServiceConfig *ser= vice, + Error **errp) +{ + error_setg(errp, "unsupported RPMI service group %u", + service->service_group); + return false; +} + +static bool riscv_rpmi_init_services(RiscvRpmiState *s, Error **errp) +{ + uint32_t i; + + for (i =3D 0; i < s->service_count; i++) { + if (!riscv_rpmi_add_service_group(s, &s->services[i], errp)) { + return false; + } + } + + return true; +} + +static bool riscv_rpmi_init_context(RiscvRpmiState *s, Error **errp) +{ + const char *platform_info =3D s->platform_info ?: RPMI_PLAT_INFO; + + s->rpmi_shmem =3D rpmi_shmem_create("rpmi-shmem", s->shmem_base, + s->shmem_size, + &rpmi_shmem_qemu_ops, s); + if (!s->rpmi_shmem) { + error_setg(errp, "failed to create RPMI shared memory backend"); + return false; + } + + s->transport =3D rpmi_transport_shmem_create("rpmi-shmem-transport", + RPMI_QUEUE_SLOT_SIZE, + s->a2p_req_size, + s->p2a_req_size, + s->rpmi_shmem); + if (!s->transport) { + error_setg(errp, "failed to create RPMI shared memory transport"); + return false; + } + + s->context =3D rpmi_context_create("rpmi-virt", s->transport, + RPMI_SRVGRP_ID_MAX_COUNT, + RPMI_PRIVILEGE_M_MODE, + strlen(platform_info) + 1, + platform_info); + if (!s->context) { + error_setg(errp, "failed to create RPMI context"); + return false; + } + + return riscv_rpmi_init_services(s, errp); +} + +static void riscv_rpmi_realize(DeviceState *dev, Error **errp) +{ + RiscvRpmiState *s =3D RISCV_RPMI(dev); + g_autofree char *name =3D NULL; + + if (!riscv_rpmi_validate_config(s, errp)) { + return; + } + + name =3D g_strdup_printf("rpmi-shmem@%" PRIx64, s->shmem_base); + if (!memory_region_init_ram(&s->shmem, OBJECT(dev), name, s->shmem_siz= e, + errp)) { + return; + } + + memory_region_add_subregion(get_system_memory(), s->shmem_base, &s->sh= mem); + s->has_shmem =3D true; + + if (!riscv_rpmi_init_context(s, errp)) { + riscv_rpmi_cleanup(s); + } +} + +static void riscv_rpmi_unrealize(DeviceState *dev) +{ + riscv_rpmi_cleanup(RISCV_RPMI(dev)); +} + +static const VMStateDescription riscv_rpmi_vmstate =3D { + .name =3D TYPE_RISCV_RPMI, + .unmigratable =3D 1, +}; + +static const Property riscv_rpmi_properties[] =3D { + DEFINE_PROP_UINT64("shmem-base", RiscvRpmiState, shmem_base, 0), + DEFINE_PROP_UINT64("shmem-size", RiscvRpmiState, shmem_size, 0), + DEFINE_PROP_UINT32("a2p-req-size", RiscvRpmiState, a2p_req_size, 0), + DEFINE_PROP_UINT32("p2a-req-size", RiscvRpmiState, p2a_req_size, 0), +}; + +static void riscv_rpmi_finalize(Object *obj) +{ + RiscvRpmiState *s =3D RISCV_RPMI(obj); + + g_free(s->platform_info); + g_free(s->hart_ids); +} + +static void riscv_rpmi_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + dc->realize =3D riscv_rpmi_realize; + dc->unrealize =3D riscv_rpmi_unrealize; + dc->vmsd =3D &riscv_rpmi_vmstate; + rc->phases.hold =3D riscv_rpmi_reset_hold; + device_class_set_props(dc, riscv_rpmi_properties); +} + +static const TypeInfo riscv_rpmi_info =3D { + .name =3D TYPE_RISCV_RPMI, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RiscvRpmiState), + .instance_init =3D riscv_rpmi_init, + .instance_finalize =3D riscv_rpmi_finalize, + .class_init =3D riscv_rpmi_class_init, +}; + +static void riscv_rpmi_register_types(void) +{ + type_register_static(&riscv_rpmi_info); +} + +type_init(riscv_rpmi_register_types) + +DeviceState *riscv_rpmi_create(const RiscvRpmiConfig *cfg, Error **errp) +{ + DeviceState *dev; + RiscvRpmiState *s; + + if (!cfg) { + error_setg(errp, "missing RPMI configuration"); + return NULL; + } + + dev =3D qdev_new(TYPE_RISCV_RPMI); + qdev_prop_set_uint64(dev, "shmem-base", cfg->shmem_base); + qdev_prop_set_uint64(dev, "shmem-size", cfg->shmem_size); + qdev_prop_set_uint32(dev, "a2p-req-size", cfg->a2p_req_size); + qdev_prop_set_uint32(dev, "p2a-req-size", cfg->p2a_req_size); + + s =3D RISCV_RPMI(dev); + riscv_rpmi_configure_base(s, cfg); + + if (!sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp)) { + return NULL; + } + + sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, cfg->doorbell_base); + return dev; +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h new file mode 100644 index 0000000000..95aa8dec14 --- /dev/null +++ b/hw/misc/riscv_rpmi_internal.h @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI internal service helpers. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#ifndef HW_MISC_RISCV_RPMI_INTERNAL_H +#define HW_MISC_RISCV_RPMI_INTERNAL_H + +#include "qapi/error.h" +#include "hw/misc/riscv_rpmi.h" +#include "librpmi.h" + +#define RPMI_PLAT_INFO "QEMU RISC-V RPMI" + +extern const struct rpmi_shmem_platform_ops rpmi_shmem_qemu_ops; +bool riscv_rpmi_service_enabled(RiscvRpmiState *s, + enum rpmi_servicegroup_id service_group); +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); + +#endif diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h new file mode 100644 index 0000000000..c207501405 --- /dev/null +++ b/include/hw/misc/riscv_rpmi.h @@ -0,0 +1,92 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI definitions shared by RPMI transport and FDT helpers. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#ifndef HW_MISC_RISCV_RPMI_H +#define HW_MISC_RISCV_RPMI_H + +#include "exec/hwaddr.h" +#include "hw/core/sysbus.h" +#include "qom/object.h" + +#ifdef CONFIG_LIBRPMI +#include "librpmi.h" +#else +enum rpmi_servicegroup_id { + RPMI_SRVGRP_SYSTEM_RESET =3D 0x0003, + RPMI_SRVGRP_SYSTEM_SUSPEND =3D 0x0004, + RPMI_SRVGRP_HSM =3D 0x0005, +}; +#endif + +#define RPMI_QUEUE_SLOT_SIZE 64 +/* Minimum queue size: head, tail, and one data slot. */ +#define RPMI_DATA_SLOT_SIZE (3 * RPMI_QUEUE_SLOT_SIZE) +#define RPMI_DBREG_SIZE 0x1000 + +#define RPMI_ALL_NUM_QUEUES 4 +#define RPMI_A2P_NUM_QUEUES 2 +#define RPMI_ALL_NUM_REGS (RPMI_ALL_NUM_QUEUES + 1) +#define RPMI_A2P_NUM_REGS (RPMI_A2P_NUM_QUEUES + 1) + +#define TYPE_RISCV_RPMI "riscv-rpmi" +OBJECT_DECLARE_SIMPLE_TYPE(RiscvRpmiState, RISCV_RPMI) + +struct rpmi_context; +struct rpmi_service_group; +struct rpmi_shmem; +struct rpmi_transport; + +typedef struct RiscvRpmiServiceConfig { + const char *node_name; + const char *compatible; + enum rpmi_servicegroup_id service_group; + bool has_mpxy_channel; + uint32_t mpxy_channel; +} RiscvRpmiServiceConfig; + +typedef struct RiscvRpmiConfig { + hwaddr doorbell_base; + hwaddr shmem_base; + hwaddr shmem_size; + uint32_t a2p_req_size; + uint32_t p2a_req_size; + const char *platform_info; + + const uint32_t *hart_ids; + uint32_t hart_count; + const RiscvRpmiServiceConfig *services; + uint32_t service_count; +} RiscvRpmiConfig; + +struct RiscvRpmiState { + SysBusDevice parent_obj; + + MemoryRegion mmio; + MemoryRegion shmem; + uint64_t shmem_base; + uint64_t shmem_size; + uint32_t a2p_req_size; + uint32_t p2a_req_size; + char *platform_info; + + uint32_t *hart_ids; + uint32_t hart_count; + const RiscvRpmiServiceConfig *services; + uint32_t service_count; + uint32_t doorbell; + struct rpmi_shmem *rpmi_shmem; + struct rpmi_transport *transport; + struct rpmi_context *context; + bool has_shmem; +}; + +DeviceState *riscv_rpmi_create(const RiscvRpmiConfig *cfg, Error **errp); + +#endif From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768828; cv=none; d=zohomail.com; s=zohoarc; b=D460j96K1oemUqkN3n+QePdPvOus+8NftCChoRyxTE6sgPx+qvIYjaoZ6/IhCN3eVPYym5otNPTa8kV5Utl/cEu3fOBwFldsIr3R7HaGqTop9lHz5UA2LcgN/1I0v08RGMukrPJVaT/uShGbDG4MpqqQjBqjkvvuET/VGFlpC14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768828; 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=u2Qed8bktRKllKwFEC/Yl+Whk92hbfUNGOlH2d3s+ck=; b=lMy6JmR6MvgfgpE/gf2388lX4yDn9I1rgQtOZzH9bQ8N9bLxjsVXcAg+lkddTNoyDIZrYJGkl0Winpz39gXqx4OZXhjmBGyhT6hTF8Oilgadz9Z+aul654p4qq8f8PiZrXbbdEGUs6gxulHf21ssc/lOHHfiW1/VrlxYxU2lauU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768828768585.5941920633591; Tue, 3 Nov 2026 21:07:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTCT-0004fR-Et; Wed, 04 Nov 2026 00:06:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCQ-0004ZE-Gj for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:14 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCO-0002Bt-Fc for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:14 -0500 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40R25r1248035 for ; Wed, 4 Nov 2026 05:06:11 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 4hqpuv9kw0-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:10 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-36a6f57c066so47118eec.2 for ; Tue, 03 Nov 2026 21:06:10 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=u2Qed8bktRK llKwFEC/Yl+Whk92hbfUNGOlH2d3s+ck=; b=e3Xj4Z/GwrSIi2G6JFVfE6VCiTy jgRMOaa6JttTtyJZxVl9bvqzzILbFTb/W6dcTzVME2nrG3Is5hiOMoNaH5vHHezp TBSv/KEanpDL7BiujG+zMLGqMsrRk0ev0moyC9a1Rp8WTcC3u5De21/wyKHvK/SA dXq+rVCkTHgAgCr1cx2LylB8UowmPhVxNyNY9r1J7rJuP0Y/x7Mj7xTQr5/+PN4M U3DafMpOK2bS9/Xo6Jt5CY+jxHrBQVuaW/Bwq1v7mWBPIrex/FziiIJAxUrqQlXT dkxsvXpbwABQzSeC6DwSAhsz4VAPvUcv1pDB2mWiWeew6FxW8+mc4vx5sbA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768770; x=1794373570; 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=u2Qed8bktRKllKwFEC/Yl+Whk92hbfUNGOlH2d3s+ck=; b=QJKiNCgJz4ul8cMKT/x41iE2iO2lB7rGz5jcx69dCeGMOJL7lhklIYrYI5yuIIWAwg BMyLjbnTWj4FuSPkkXBiQmXNE0X3z6/BUhaw/QWcvOv9aWbG/q15MBCSO6jvG+kRaI0U 6b08G+vCFaaabNY6uT7vMZOa8Z5YzaJblZmh7YIH9WdDE0VqjIbd9L97HBm9EFbbo7cN 2E4Qm+Qk6UArhaDdh52QQpCEMhcMKXRJ6N5A6miqcndGULhRrdyTRHDbGWEwwo0c4Uxm A8HO3f/r2rpEFsCJdtmFajFutEZT/jov3iE2vUTdOnNX/KiyGtLzIRAnmizozRGwt0kW 3ZZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768770; x=1794373570; 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=u2Qed8bktRKllKwFEC/Yl+Whk92hbfUNGOlH2d3s+ck=; b=tsGCCv+S7IigA74RcdfOVipKDFsI5GsSBLTiB8RdWrZdtwqsZlMRlEj7Rwa+asVQcR XOGDyPEwnwJhfu7Vi7KpZp0tFhxZSIPg5qtHgXNoV+Btjnw18WYb5pRAiFdXguFcB4i8 8PWXwchDl8laSosRgowcJDgDOz7rWkPcUYAhUDjd32yM4tFqKhbigexrHsf3iP0Y40gw K4fkIiLOoA3WGgKcKSTLd8ritz7DnAEIYXTiIT2s8v2OSl9jH6U0xmbJdLA4j/LxmWDd ppCxe1XbsMuSzPphpewqHUJl9cy2Z36Z4XSyxx+TW937mexzLOg0r7U2OhFF17qBHfI1 Jgzw== X-Gm-Message-State: APuU4Z+4YGaUSSByrwdD1MuHW4t84efyYd6IMkNkdbF4FYIKRdDsS7Dv ZT0J5nG1tM2WAhaeu26Hgyi5u5py67ZgGUQOEK0auQ03pXKux4Lbn+leNAAu1EMkYPmcO5/jw0M 1rwVbHgSSk52Y1I8TUU1V6pQRKrh5Im6LWBJUaXFoUnEu5NcK6IQJpebp9kr7eeqC0g== X-Gm-Gg: AYBFou0JpPXtycfktegOpSiV1fE8yuCgoMSoIoJO5s4/AJq9Gl5gPHSxIf/JeKKpEyu m4GnnzeFMfAAOI1JqmJ04pUQS41IBU4XE7x715wimt96tFy3peBFT+FcHgEBVSblBrV7leguXJp S+nhdRhjW/33bBGPdKRaEwhTJTFLOjmJl65HfKrmyctO+AIl2VDJRjxSv5dlm4ScBB+aC5AxxKF s98vIvrLUtevnzPIM5Tp5Se068+9wK9CDaAJkpTCVrCETThr+X6Ta4jklsIzloN8anbe8U3SacL tZ9GclViUijSFd+pqGkbrGQ7NnXYrB02A01B/I3XuQ908YK4ud3Of7cqAYdggwXmiAa5y2oJ683 M+Vg9BMbd/hbduoQmfwV000X17xdp4v+qFVpFHiYizTe0JT5inmXDb97VD446MbIMqKu0IUoIPI t6A3fzz58o7gaZfgNoXe8P8iltbB5CuQ54B+7Y2Z/leACBNyG1FncavLAe4esrxl4n8cKlSUUmY U/qAWON X-Received: by 2002:a05:7300:cb88:b0:36c:a1bc:6115 with SMTP id 5a478bee46e88-36ca1bc6a73mr4486859eec.0.1793768770001; Tue, 03 Nov 2026 21:06:10 -0800 (PST) X-Received: by 2002:a05:7300:cb88:b0:36c:a1bc:6115 with SMTP id 5a478bee46e88-36ca1bc6a73mr4486793eec.0.1793768769177; Tue, 03 Nov 2026 21:06:09 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu Subject: [PATCH v14 03/10] hw/riscv: add RPMI FDT helpers Date: Wed, 4 Nov 2026 10:33:16 +0530 Message-ID: <20261104050324.733555-4-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=O6SsLx9W c=1 sm=1 tr=0 ts=6aeabd42 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22 a=EUspDBNiAAAA:8 a=WNJofZAcfibaGo0vQRIA:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-ORIG-GUID: 1jWjzEnRoTAp6wn5AZqRJjNIdlI4OwH_ X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX6fs9t+a1Kfxb /txjGOrtT/L7qzVZGiuNyirAMLOGquVsn3a87aAickG6Rs7Z2G84AANS+SaRHmz6ZVXoLsWNbF3 /Kq/Gf7eJ+wBEFI9pLBllas8LH+4q5w= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX68JX2ArLTL82 DeMAgfgXciNlOUhjFCRk2Rah4zAIoWLKbDdWqjqVpSKJY+pRciy5HH75C4WluCt7+igmEyQF4Ev VngTPT+B20QtEeJKYdmx97h6anNH95HIxtXzWbRZ4kZBMmMuvvwOZTqY/Fr3pCZIspkShuKDN4W ZGjihocGKHlVmIViIbQbyWj9WJfx5KmP47JVsl+F4aAQKZbMpLs9vELfLCkUc/ucxwSBkcJpbz1 clJFlu7mJ//DgpOZCReIlvhZ+rqwDjMNAEmp9W0sYEjv2loOd+UFowbCxh11mVBLTid6aS2/LNS lLvp8NxzYZ1QMwYbFX0plnf4WIPuYLRHiJTana9bWO/tDAyvlo9wI3geqfeX2E2bI0gK6cd1ERP 4c5tKXud0hvTVEJZqAD6vGmJ7wHQyzneDyaTQbWvHBmZ5nfcvZnSCu1ZEEgd1TXDVPwYbCjzPI3 NlwsMMsl/Du/qHLFSug== X-Proofpoint-GUID: 1jWjzEnRoTAp6wn5AZqRJjNIdlI4OwH_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 clxscore=1015 spamscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768830879158500 Content-Type: text/plain; charset="utf-8" Add helper routines for describing RPMI shared-memory mailbox transports and sibling service nodes in the RISC-V virt device tree. The helpers keep RPMI node construction in one place so the virt machine can add service groups without open-coding compatible strings, channel IDs, interrupts, and shared-memory references at each call site. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- hw/riscv/meson.build | 3 ++ hw/riscv/rpmi-fdt-stub.c | 24 ++++++++++ hw/riscv/rpmi-fdt.c | 92 +++++++++++++++++++++++++++++++++++++ include/hw/riscv/rpmi-fdt.h | 34 ++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 hw/riscv/rpmi-fdt-stub.c create mode 100644 hw/riscv/rpmi-fdt.c create mode 100644 include/hw/riscv/rpmi-fdt.h diff --git a/hw/riscv/meson.build b/hw/riscv/meson.build index 6bdabb9544..806ba41e42 100644 --- a/hw/riscv/meson.build +++ b/hw/riscv/meson.build @@ -5,6 +5,9 @@ riscv_ss.add(files('device-common.c')) riscv_ss.add(files('fdt-common.c')) riscv_ss.add(when: 'CONFIG_RISCV_NUMA', if_true: files('numa.c')) riscv_ss.add(files('riscv_hart.c')) +riscv_ss.add(when: 'CONFIG_RISCV_RPMI', + if_true: files('rpmi-fdt.c'), + if_false: files('rpmi-fdt-stub.c')) riscv_ss.add(when: 'CONFIG_OPENTITAN', if_true: files('opentitan.c')) riscv_ss.add(when: 'CONFIG_RISCV_VIRT', if_true: files('virt.c')) riscv_ss.add(when: 'CONFIG_RISCV_SERVER_PLATFORM_REF', if_true: files('ser= ver_platform_ref.c')) diff --git a/hw/riscv/rpmi-fdt-stub.c b/hw/riscv/rpmi-fdt-stub.c new file mode 100644 index 0000000000..0de006bd47 --- /dev/null +++ b/hw/riscv/rpmi-fdt-stub.c @@ -0,0 +1,24 @@ +/* + * RISC-V RPMI device-tree helper stubs. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/riscv/rpmi-fdt.h" + +void riscv_rpmi_fdt_add_mbox(void *fdt G_GNUC_UNUSED, + const RiscvRpmiFdtMboxConfig *cfg G_GNUC_UNUS= ED, + uint32_t *phandle G_GNUC_UNUSED, + uint32_t *mbox_handle G_GNUC_UNUSED) +{ + g_assert_not_reached(); +} + +void riscv_rpmi_fdt_add_service_node(void *fdt G_GNUC_UNUSED, + const RiscvRpmiServiceConfig *service + G_GNUC_UNUSED, + uint32_t mbox_handle G_GNUC_UNUSED) +{ + g_assert_not_reached(); +} diff --git a/hw/riscv/rpmi-fdt.c b/hw/riscv/rpmi-fdt.c new file mode 100644 index 0000000000..0ca1f69546 --- /dev/null +++ b/hw/riscv/rpmi-fdt.c @@ -0,0 +1,92 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI device-tree helpers + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "hw/riscv/rpmi-fdt.h" +#include "hw/misc/riscv_rpmi.h" +#include "system/device_tree.h" + +void riscv_rpmi_fdt_add_mbox(void *fdt, + const RiscvRpmiFdtMboxConfig *cfg, + uint32_t *phandle, + uint32_t *mbox_handle) +{ + g_autofree char *name =3D NULL; + hwaddr a2p_req_base, p2a_ack_base, p2a_req_base, a2p_ack_base; + uint32_t handle; + static const char * const regnames_all[RPMI_ALL_NUM_REGS] =3D { + "a2p-req", "p2a-ack", "p2a-req", "a2p-ack", "a2p-doorbell" + }; + static const char * const regnames_a2p[RPMI_A2P_NUM_REGS] =3D { + "a2p-req", "p2a-ack", "a2p-doorbell" + }; + + a2p_req_base =3D cfg->shmem_base; + p2a_ack_base =3D a2p_req_base + cfg->a2p_req_size; + p2a_req_base =3D p2a_ack_base + cfg->a2p_req_size; + a2p_ack_base =3D p2a_req_base + cfg->p2a_req_size; + + handle =3D (*phandle)++; + + if (mbox_handle) { + *mbox_handle =3D handle; + } + name =3D g_strdup_printf("/soc/mailbox@%" HWADDR_PRIx, cfg->shmem_base= ); + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", "riscv,rpmi-shmem-mbo= x"); + qemu_fdt_setprop_cell(fdt, name, "riscv,slot-size", RPMI_QUEUE_SLOT_SI= ZE); + qemu_fdt_setprop_cell(fdt, name, "#mbox-cells", 1); + + if (cfg->p2a_req_size) { + qemu_fdt_setprop_string_array(fdt, name, "reg-names", + (char **)®names_all, + ARRAY_SIZE(regnames_all)); + qemu_fdt_setprop_cells(fdt, name, "reg", + (uint32_t)(a2p_req_base >> 32), (uint32_t)a2p_req_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(p2a_ack_base >> 32), (uint32_t)p2a_ack_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(p2a_req_base >> 32), (uint32_t)p2a_req_base, + 0x0, cfg->p2a_req_size, + (uint32_t)(a2p_ack_base >> 32), (uint32_t)a2p_ack_base, + 0x0, cfg->p2a_req_size, + (uint32_t)(cfg->doorbell_base >> 32), (uint32_t)cfg->doorbell_= base, + 0x0, cfg->doorbell_size); + } else { + qemu_fdt_setprop_string_array(fdt, name, "reg-names", + (char **)®names_a2p, + ARRAY_SIZE(regnames_a2p)); + qemu_fdt_setprop_cells(fdt, name, "reg", + (uint32_t)(a2p_req_base >> 32), (uint32_t)a2p_req_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(p2a_ack_base >> 32), (uint32_t)p2a_ack_base, + 0x0, cfg->a2p_req_size, + (uint32_t)(cfg->doorbell_base >> 32), (uint32_t)cfg->doorbell_= base, + 0x0, cfg->doorbell_size); + } + + qemu_fdt_setprop_cells(fdt, name, "phandle", handle); +} + +void riscv_rpmi_fdt_add_service_node(void *fdt, + const RiscvRpmiServiceConfig *service, + uint32_t mbox_handle) +{ + g_autofree char *name =3D g_strdup_printf("/soc/%s", service->node_nam= e); + + qemu_fdt_add_subnode(fdt, name); + qemu_fdt_setprop_string(fdt, name, "compatible", service->compatible); + qemu_fdt_setprop_cells(fdt, name, "mboxes", mbox_handle, + service->service_group); + if (service->has_mpxy_channel) { + qemu_fdt_setprop_cell(fdt, name, "riscv,sbi-mpxy-channel-id", + service->mpxy_channel); + } +} diff --git a/include/hw/riscv/rpmi-fdt.h b/include/hw/riscv/rpmi-fdt.h new file mode 100644 index 0000000000..e74115108e --- /dev/null +++ b/include/hw/riscv/rpmi-fdt.h @@ -0,0 +1,34 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI device-tree helpers + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#ifndef HW_RISCV_RPMI_FDT_H +#define HW_RISCV_RPMI_FDT_H + +#include "exec/hwaddr.h" + +typedef struct RiscvRpmiServiceConfig RiscvRpmiServiceConfig; + +typedef struct RiscvRpmiFdtMboxConfig { + hwaddr shmem_base; + hwaddr doorbell_base; + uint32_t a2p_req_size; + uint32_t p2a_req_size; + uint32_t doorbell_size; +} RiscvRpmiFdtMboxConfig; + +void riscv_rpmi_fdt_add_mbox(void *fdt, + const RiscvRpmiFdtMboxConfig *cfg, + uint32_t *phandle, + uint32_t *mbox_handle); +void riscv_rpmi_fdt_add_service_node(void *fdt, + const RiscvRpmiServiceConfig *service, + uint32_t mbox_handle); + +#endif From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768798; cv=none; d=zohomail.com; s=zohoarc; b=YiPjp7AvUgk8sCyHAAYnbuPPwBsqYFSTqSPjOKx/0KQ89zE5A+mwLTC7AMKKWJUwAWQyeCC0KkrF/Fq4c5akj5L9PWo4Mk8KPCZ58g/bLwBgR5kD8eHvu+XHVNFK9OzFBJTHKOtE0/TLUvaoLMhdEhlASD0U+HXIl47Nc7ZSPBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768798; 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=WIoo5ELzUL+vFgYLKtvV6sBmfMdz6DfJgI0tbx2TvS4=; b=G94rVr1wxAs8j7LetlFU/2URm8Ytv8dNahkKQzOpAxe6Bn3MA5iGOUNUKMt9w3SS25+rR5RX8KCoUJOGnm6ubYQZGuV9CDfMlqSCxMFHnWn/ounWVIPgTNY6kt/RlIOZY4+ab9A/+UE/bSBSPHpQi/V4nFELGE5KwTKs7yCWeEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768798706371.9107447766645; Tue, 3 Nov 2026 21:06:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTCY-0004lv-QT; Wed, 04 Nov 2026 00:06:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCU-0004h1-Ob for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:18 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCS-0002CZ-OH for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:18 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40RKDY1191425 for ; Wed, 4 Nov 2026 05:06:15 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 4hqm2pjbgq-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:14 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-36ca34c12a6so23180eec.1 for ; Tue, 03 Nov 2026 21:06:14 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=WIoo5ELzUL+ vFgYLKtvV6sBmfMdz6DfJgI0tbx2TvS4=; b=OMXNqaH4kRTwXk5z4w+R7T1+ucC az9UcNNKCnqoOs1fnfVNW5v6WX2w3mBUaoxHR5KSjO9y+mPCuxqEtJcvR50zo52G 2WyZwy8v0E3bEKVm0Y0LHAJL70ddq2ZtHrQnGzPcwLomTrN8depsN2bjekckRc9G DjCbjX4WQoMclm2AjdVF91MmKuzZw9ma7NUWwrzq8inMfsrE87Ym8lqipaHC3gNK +9OPQortapwLk7xKGkdPHrv0I93gM0sLaCfj9ezA1JZGAtX2JVAX+MnstojKVUJ5 6yLnRlV8JdFiKCW50Ow47UohmqxHHdYf2vsrhYPs0MAk9sMf1h3SZ5hNSBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768774; x=1794373574; 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=WIoo5ELzUL+vFgYLKtvV6sBmfMdz6DfJgI0tbx2TvS4=; b=DVct3qcXAP0/5sAc1Utb86wtZFRqdQ6OqHHlYiAoYOa8QXo5mM4Be0z9gWj4Dc3Wjo HgPx0nHr2mw756sVXvumN5Urg9tRdDSM1cYcwVspr40LYlmSz34EjkiHJInSAKucNrIG 8A9ymCgvqsBQ2x+6HE9P8VXEmBlU9sRxUmKK6/qHhvASmjtt9sDgvvxBycWptnM9O9J+ S+HjF1+0R6fDOtTRDF33g3duVwj4wUQTBaKoQkrRh55BTeP1IOZrJn7gshojSGH8tQNd AZqngfqajSw8eMHaY2P7UY2eebQAMF2OazVuUaDzm6bepqiLM9XMGxY23uZzt8Z76txh 5SSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768774; x=1794373574; 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=WIoo5ELzUL+vFgYLKtvV6sBmfMdz6DfJgI0tbx2TvS4=; b=q9jqxRiDBiRzeBJyOGZHiXXhXtbkrL779APFEqd2hZFhiPev4m1jybQd1x+T0Y8Uz1 KhCwOX+3BBz0SY9LmzfkmwktABbx8q5Uvs/Xrs3WVx1jnja8sEf9au1Csbk93AJ4UvSR ciflMguubRCeAbFZObGIhbHRRT2Q3htlM0E0c/jHdq61KOawT10vI8IcIDWPhopRRJkj xAzzPgCs6yGh5TcUExYJkq+ATyYZIYqLkf/crQx/XCIUm0EcCoqNLe08E2Hlqyhrufbs 1+hRfNH66NfjnQxyEKp+9ST4D6QuX+tdAS0GoKpta5hQ9DdUv8MqFl2IaxBv533JrAur sANw== X-Gm-Message-State: APuU4Z8ubcyRFZ7GymBDsO0c+yMu/3769FMxJUBd8oaC3affrYbR3Wz7 2jzGubT483uneKzn3FeI5O+lc5y3KrPLsZwscydKGTgzpxOUyhcqOrrFf2Uh7D6jQoFh3H39ZNP QVK9K8wNS5znRkNJC16oSHkfoxGP8TvJi+sSjgt87wCLjF3nESRDWPTMvE7fxF3mUdw== X-Gm-Gg: AYBFou1ty6EBnkHM7R31PNNxiyef8QnohcvF4S1dKp9QblzWlYfAhqA+Y/6tN6NwOUh nhPcr2HuiuP1xlZmm9HE1jj1uKBNqIM7ztT0nZLkcw0yJO/pJqz8xjfnP4tleK8aItiO2qL7sAc VXlgY71n7kxa+P5SM6iRJdBwYQn8ydb8iWT4zHb3HzAbGfeN5X773yFnLhF9EQGcO5HGGeeZCca WxIzXOXMOEHbG2TYWeHmUFNUErGUbzp1OCqZeMxh9OpzlNBASi0H0krtNW3Z+t1a4oPxQinD8hF +EvJyKrk1Eyn4M7BbNgD5H+GP1mzu/H180IqhixWugbZxINILaiK2iIGE6xwIrKnZ1RIW5w2hzq L/3vJNSm22cfGxujG8fLI8KXE4HSGK1F1KpyPZ9ngswTWpIHEaGyeESqVN2G7cuZjbJxqVSS9EI MNFnkQVquRaZy9FvKNE3Fz+btLHA+dDkKufKS5O0pSh2lcVGdhdVQ0SaLPzae/cFCcau8Mm+9A9 Amy2cP+ X-Received: by 2002:a05:693c:8099:b0:35f:ea17:d171 with SMTP id 5a478bee46e88-36a42236aa1mr33976094eec.2.1793768773812; Tue, 03 Nov 2026 21:06:13 -0800 (PST) X-Received: by 2002:a05:693c:8099:b0:35f:ea17:d171 with SMTP id 5a478bee46e88-36a42236aa1mr33976003eec.2.1793768773101; Tue, 03 Nov 2026 21:06:13 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Paolo Bonzini , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v14 04/10] hw/riscv/virt: add opt-in RPMI base support Date: Wed, 4 Nov 2026 10:33:17 +0530 Message-ID: <20261104050324.733555-5-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX3bb60B2wBI8Q skdfPuD8PJAgjnpeepR4HpPXKE2jkdb1eXC7c3LSl2DzC6erSREF40xNXUcHEp+bVZmHufuvs9C zTnRo7wv+4fCDNI0ORVkPFpU5pBG7h8VEcNNlBBxYTk0HZMw5Z5lYEJkbw93K7jfR0+exyG7eIg 5zcUotfIs5IkYEINwmVss2MCJGyzaE6xho8rEl5hiygH+o+OLwxUTiBgQTJI9VZlYPF6PuvYe/W +Zj2K32lJB4kepDdRplBmZWC6dwNc+DedpKiM94OaVntD/+nb46pRXT1X573uLX4IbUk5xTu8Fz OLtZ2v4QaG4LnCeMmbZFloOmqNow6axRABuT41PJH6Qsgdf+HNYudeL/C7WYbJZ8cNSAcjWzfQz IvWzdlKgIYRUJ9QXZB3pFsuUYhd+RIUQ2828SOcPrMcU2FrVcUndde/UZlsdJ7bZutNaKZiDtQV E4LwfWeFoGDaFr8HkUg== X-Proofpoint-GUID: 0TFk1PFzl4afGHupAWLeNSu0bYReEm0Y X-Proofpoint-ORIG-GUID: 0TFk1PFzl4afGHupAWLeNSu0bYReEm0Y X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX/NYTIwis0NUN fTqGeLmyuy+ZcWT5S5BxNUIhY3KTco/TlGkF1vaYGT1H8vAAEg1TFMzQyyn8SRXfcN8+8rgzeC3 Q/a9/kNDLkL1Si0ch9i9xOMOSvEnw40= X-Authority-Analysis: v=2.4 cv=c64+0h9l c=1 sm=1 tr=0 ts=6aeabd46 cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=HmRiOy3tFSfIY13RnpAA: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-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768800393158500 Content-Type: text/plain; charset="utf-8" Add the virt machine rpmi=3Don/off option and wire the initial RPMI Base transport into machine realization for firmware clients that use RPMI platform management. The option remains disabled by default. Enabling it requires a librpmi-enabled TCG build; KVM and builds without librpmi reject the configuration. The RPMI mailbox node is emitted when enabled, while the legacy reset and poweroff nodes remain available until the later service patches select the RPMI reset path. Size each A2P queue from one quarter of shared memory after reserving 8 KiB: 30 KiB per queue on virt. Signed-off-by: Subrahmanya Lingappa --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 90 +++++++++++++++++++++++++++++++++++++++++ include/hw/riscv/virt.h | 3 ++ 3 files changed, 94 insertions(+) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index d89fdfcc86..28d108faf8 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -49,6 +49,7 @@ config RISCV_VIRT imply VIRTIO_VGA imply TEST_DEVICES imply TPM_TIS_SYSBUS + imply RISCV_RPMI select DEVICE_TREE select RISCV_NUMA select GOLDFISH_RTC diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index de1c92463a..8a2ed43029 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -46,6 +46,8 @@ #include "hw/intc/riscv_aplic.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_test.h" +#include "hw/misc/riscv_rpmi.h" +#include "hw/riscv/rpmi-fdt.h" #include "hw/core/platform-bus.h" #include "chardev/char.h" #include "system/device_tree.h" @@ -107,6 +109,8 @@ static const MemMapEntry virt_memmap[] =3D { /* UART1 supports page isolation from UART0 */ [VIRT_UART1] =3D { 0x1000a000, 0x100 }, [VIRT_FW_CFG] =3D { 0x10100000, 0x18 }, + [VIRT_RPMI_SHMEM] =3D { 0x10200000, 0x20000 }, + [VIRT_RPMI_DOORBELL] =3D { 0x10230000, 0x1000 }, [VIRT_FLASH] =3D { 0x20000000, 0x4000000 }, [VIRT_IMSIC_M] =3D { 0x24000000, VIRT_IMSIC_MAX_SIZE }, [VIRT_IMSIC_S] =3D { 0x28000000, VIRT_IMSIC_MAX_SIZE }, @@ -115,6 +119,10 @@ static const MemMapEntry virt_memmap[] =3D { [VIRT_DRAM] =3D { 0x80000000, 0x0 }, }; =20 +#define VIRT_RPMI_A2P_REQ_SIZE \ + ((virt_memmap[VIRT_RPMI_SHMEM].size - 0x2000) / 4) +#define VIRT_RPMI_P2A_REQ_SIZE 0 + /* PCIe high mmio is fixed for RV32 */ #define VIRT32_HIGH_PCIE_MMIO_BASE 0x300000000ULL #define VIRT32_HIGH_PCIE_MMIO_SIZE (4 * GiB) @@ -470,6 +478,35 @@ static void create_fdt_iommu(RISCVVirtState *s, uint16= _t bdf) s->pci_iommu_bdf =3D bdf; } =20 +static RiscvRpmiConfig virt_rpmi_config(RISCVVirtState *s, + const uint32_t *hart_ids, + uint32_t hart_count) +{ + return (RiscvRpmiConfig) { + .doorbell_base =3D s->memmap[VIRT_RPMI_DOORBELL].base, + .shmem_base =3D s->memmap[VIRT_RPMI_SHMEM].base, + .shmem_size =3D s->memmap[VIRT_RPMI_SHMEM].size, + .a2p_req_size =3D VIRT_RPMI_A2P_REQ_SIZE, + .p2a_req_size =3D VIRT_RPMI_P2A_REQ_SIZE, + .platform_info =3D "QEMU RISC-V virt RPMI", + .hart_ids =3D hart_ids, + .hart_count =3D hart_count, + }; +} + +static void create_fdt_rpmi(RISCVVirtState *s, uint32_t *phandle) +{ + RiscvRpmiFdtMboxConfig cfg =3D { + .shmem_base =3D s->memmap[VIRT_RPMI_SHMEM].base, + .doorbell_base =3D s->memmap[VIRT_RPMI_DOORBELL].base, + .a2p_req_size =3D VIRT_RPMI_A2P_REQ_SIZE, + .p2a_req_size =3D VIRT_RPMI_P2A_REQ_SIZE, + .doorbell_size =3D s->memmap[VIRT_RPMI_DOORBELL].size, + }; + + riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, NULL); +} + static void finalize_fdt(RISCVVirtState *s) { uint32_t phandle =3D 1, irq_mmio_phandle =3D 1, msi_pcie_phandle =3D 1; @@ -506,6 +543,9 @@ static void finalize_fdt(RISCVVirtState *s) s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, FINISHER_RESET, FINISHER_PASS, true); + if (s->have_rpmi) { + create_fdt_rpmi(s, &phandle); + } =20 create_fdt_uarts(s, irq_mmio_phandle); =20 @@ -739,6 +779,18 @@ static void virt_machine_init(MachineState *machine) exit(1); } =20 + if (s->have_rpmi) { +#ifndef CONFIG_LIBRPMI + error_report("RISC-V RPMI support is not compiled in"); + exit(1); +#else + if (kvm_enabled()) { + error_report("RISC-V RPMI support is not available with KVM"); + exit(1); + } +#endif + } + /* Initialize sockets */ mmio_irqchip =3D virtio_irqchip =3D pcie_irqchip =3D NULL; for (i =3D 0; i < socket_count; i++) { @@ -897,6 +949,21 @@ static void virt_machine_init(MachineState *machine) /* SiFive Test MMIO device */ sifive_test_create(s->memmap[VIRT_TEST].base); =20 + if (s->have_rpmi) { + MachineClass *mc =3D MACHINE_GET_CLASS(machine); + const CPUArchIdList *possible_cpus =3D mc->possible_cpu_arch_ids(m= achine); + g_autofree uint32_t *rpmi_hart_ids =3D + g_new0(uint32_t, machine->smp.cpus); + RiscvRpmiConfig rpmi_cfg; + + for (i =3D 0; i < machine->smp.cpus; i++) { + rpmi_hart_ids[i] =3D possible_cpus->cpus[i].arch_id; + } + + rpmi_cfg =3D virt_rpmi_config(s, rpmi_hart_ids, machine->smp.cpus); + riscv_rpmi_create(&rpmi_cfg, &error_fatal); + } + /* VirtIO MMIO devices */ for (i =3D 0; i < VIRTIO_COUNT; i++) { sysbus_create_simple("virtio-mmio", @@ -1050,6 +1117,20 @@ static void virt_set_aclint(Object *obj, bool value,= Error **errp) s->have_aclint =3D value; } =20 +static bool virt_get_rpmi(Object *obj, Error **errp) +{ + RISCVVirtState *s =3D RISCV_VIRT_MACHINE(obj); + + return s->have_rpmi; +} + +static void virt_set_rpmi(Object *obj, bool value, Error **errp) +{ + RISCVVirtState *s =3D RISCV_VIRT_MACHINE(obj); + + s->have_rpmi =3D value; +} + bool virt_is_iommu_sys_enabled(RISCVVirtState *s) { return s->iommu_sys =3D=3D ON_OFF_AUTO_ON; @@ -1166,6 +1247,15 @@ static void virt_machine_class_init(ObjectClass *oc,= const void *data) "enable/disable emulating " "ACLINT devices"); =20 + + object_class_property_add_bool(oc, "rpmi", virt_get_rpmi, + virt_set_rpmi); + object_class_property_set_description(oc, "rpmi", + "Set on/off to enable/disable " + "RISC-V RPMI devices; requires " + "librpmi and is unavailable with= " + "KVM"); + object_class_property_add_str(oc, "aia", virt_get_aia, virt_set_aia); object_class_property_set_description(oc, "aia", diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 6e4fbf4b64..c9fb118fc8 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -55,6 +55,7 @@ struct RISCVVirtState { =20 int fdt_size; bool have_aclint; + bool have_rpmi; RISCVVirtAIAType aia_type; int aia_guests; char *oem_id; @@ -82,6 +83,8 @@ enum { VIRT_VIRTIO, VIRT_UART1, VIRT_FW_CFG, + VIRT_RPMI_SHMEM, + VIRT_RPMI_DOORBELL, VIRT_IMSIC_M, VIRT_IMSIC_S, VIRT_FLASH, From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768835; cv=none; d=zohomail.com; s=zohoarc; b=OGqi1EQ11Dui179mJGHxW3wMIckxhklA+ZsGc7cdrrxDOaUUVJFNJQNcIGyNi4A7g3q58lVPPt/+EdMkkBgSoXML3KIZ6eAfuw4P9mSZC+b2g1HQdnubRTDghQ3pUTHZkX+TgRdwcCG1dIoGnrGRYmtxMzmVEXI6a7coOFke1zI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768835; 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=vPDz0xyXCYAWTwQ75srl+Okui8f5Y7xXM2D854TzN5c=; b=V5WOtjCdpjUY59IGROJ4XkiIwsnSAt39MImqkwRfPGTBzyVgyzYC21bfAaAcopwUUwKaGN4jxA83+3+fSKydJA1jCVCNI8DGrOSAueIx0A5d19hOHE2aSkIZWm6B1ev4+Cq/LCeRZfO66PWRztrwkWRiAtdGuuRXFUHep5egv+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768835164501.0704507341261; Tue, 3 Nov 2026 21:07:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTCe-0004pN-GB; Wed, 04 Nov 2026 00:06:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCa-0004mt-3Q for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:24 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCW-0002D6-LX for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:23 -0500 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40R1Ie3458487 for ; Wed, 4 Nov 2026 05:06:19 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 4hqh2bubnw-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:18 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-36a19435aeeso31926eec.1 for ; Tue, 03 Nov 2026 21:06:18 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=vPDz0xyXCYA WTwQ75srl+Okui8f5Y7xXM2D854TzN5c=; b=K2gT4eVfonZtUJDF2p63hNGEZWT 6+9yFHMuCui5ALpFhqs4jqkv8h32B/8UjDXp78KSQi1bSs++bUgF43LIEcWZ2bKv KHbn5QefuxQSZ0Sl2IOuiPg3ub6RXCnP0PELHNSvayOEmmcI5LvcvmXmyC5pwzXQ LQZdYj8SHiBq7DUFfLRk/C4+wWP846/DWp87iewsgsgN/a7TH+7Fe6pQrjLAfnVv A2OiuPDF6qGeZn072u4da19cxSjV0dmHcl8zLzbrANw1wS1L7nOrA1DEmGmhY6I/ xonM0RMlho8qkkrIXmSLD9ZYdzNpuZD7lqU1pibsnv0Goo2G8PlrxMkNIUA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768778; x=1794373578; 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=vPDz0xyXCYAWTwQ75srl+Okui8f5Y7xXM2D854TzN5c=; b=LXvzTCSG3BnTZsDascpr5mfHxdDS7enj+1xs6Y6c0CxGU1axPDB6dhJB62qOVWSCY8 BOqjRnD7r+jVW+n/35M7QOdUMwYjuXDFQximxfrB48aeaSCB1c0AO/G62T4zaXE49lLH riCXUULkfPntx7Rz1MYQ+N7+h7Nn9lAW66peep3NaR37Ln4phowi2EP3aRMVtePMqU+C q3yf6ek8wZ4BBfeWQ40D7UFV+03pJjSmB1at/vng/ndHgIIis/fpMjUeVA8ov8IegR+8 QI0ZKi3+mBt6ZpI4HQ+1SgkB9Vn3Ng2UkSP+HRNJ9os+3PSyIAut0uzaIYFyFlCAr2pH UzzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768778; x=1794373578; 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=vPDz0xyXCYAWTwQ75srl+Okui8f5Y7xXM2D854TzN5c=; b=oju33mlNCXuH4lOQelzIZk4LlEri0DLOrqfX9g61uvY/qikd6Hqh4sqECK64Qs1wsM HElCRA7YBf3UjNmZcoVngMe9z4a8Y5OABuAZAvsCxjKmbIiZWIJIKjpSYdoy1u3rwPRs YAnjIF53n0LcGng7JyDJb7ntMLw4avBFABCDsq5Ud58OM88IZWO3zxe9VR9j0KvawoEJ sDdRB6VmuAdK9X/aKCNUUBisO9+DN8sHfBLvq8RmD8L8dqMxk2mT3I02RL7IK4DDxwrT BFfydJCrufYpy4h/YTRYcThmLAx5NDphl9i/Xsp1AdyNTgySEHoE813o9+FVjd3x42xy tQtg== X-Gm-Message-State: APuU4Z+aN65Aj6YebAY7MyilaLWS1mq8RN3y9klFIDfWSHY6JmitVfrm qTZQ3k34wa98BS6+xh03fUB6EAPbqzMj4SIO+JrpvCyU1QkK2ZC8Bsc4Rs1uySiDpMuIcaQ0jjr Fp8mHbO9OrTmH2NoVBwFoRthFkXj927MDB+OFL8hQj+qILqgITN5AlMqUMvLfMXBTWQ== X-Gm-Gg: AYBFou3fN/OTggXrY5Ah2dUXE3+ULKVnXgTOZQR72XvrD2U5CtaiKImEImBK5D4OZpI emsBCJXH/JqoeX2uHqiUV1E06VNn/USRW6zh5vRNyC3H7adzijBVZG029pOYNHyzF7c/QhsYIX2 o7TT1fjO7vukLOo5QEUftzL9rNX0oG69wERKq69erGDkmvGp56oaafwX1rYn60Kqn1gEIWl0FxS QQH4LAmLun2/obKqNuemkWwKnXnlyqMILwlhR29bKbWrygkjD1KxcurUSkxIyXgFeYhc17EpIP1 hpi/M9jYnFa0+N5ECZuAhoo46cGSVESqCCpnn0FDoMv+Kbrmx58FP/J2Uk8eD8oQZCGmm3lhE6J RnN2ndFZ0OX21XYTD1ZxFg3CxiBP8NuXwttrlULRgc+qW+AeXxNPs7DJu1rHnU/zOQlkiHrlHoT N6KNEqC5roVo4I7Iet6KJiuH0NzUpDakQxQs0G61Z9AevyPu5/2YM3tabW9OazhiMxYXBHdgVVE Wv8pbwX X-Received: by 2002:a05:7300:d082:b0:369:ffc5:6767 with SMTP id 5a478bee46e88-36a4236a643mr29517925eec.2.1793768777632; Tue, 03 Nov 2026 21:06:17 -0800 (PST) X-Received: by 2002:a05:7300:d082:b0:369:ffc5:6767 with SMTP id 5a478bee46e88-36a4236a643mr29517860eec.2.1793768776917; Tue, 03 Nov 2026 21:06:16 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Palmer Dabbelt , Alistair Francis , Weiwei Li , Liu Zhiwei , Chao Liu Subject: [PATCH v14 05/10] riscv: add RPMI system reset service Date: Wed, 4 Nov 2026 10:33:18 +0530 Message-ID: <20261104050324.733555-6-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfXz1HiQzNqexit D2xfUGAEF0ez21A1BU2ezGLxAMAzfFEkVuZK37GvE1rSSKnF6L5JrvWYFU8sk32GmyrMcaWt/vo wiUp1lP86h2rVn/R9R86d/E04oBHl9g= X-Authority-Analysis: v=2.4 cv=AKV9GsJK c=1 sm=1 tr=0 ts=6aeabd4a cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=EUspDBNiAAAA:8 a=HwIue_3DUM2RCVtF5-MA:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-ORIG-GUID: tNVeUjBk745qF2IolpTRHklOB3S07XUw X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX00LK6dp8hPmw boCME9zyWNmC2SHx/9qUfHJ/j1TSq48PWT5FzUj2/BJSksGAo6rGKPrzeR/xK97CSQJKr7xLgRJ NwPvP0Mk16cQxmI2do3zVtYHag1Cx3iLpafaCnvkaEMla6Nd6y8vLdnBBqmm+fIkm14+KoFnDcm TBJEEiAE8YuHhFSMjmP2Es128bmvczEkfylIP6yCydtExTT9WIcV28zVoELCswYvBbN7gZGoLC1 a66KSCN5wFmvXLqaAwbQkyaQtdq0S6P/5gItypAqllzHqCQAsAiQub7CZdZTzGdG4wBtVs22INK W3G2obbZa/LHGmgr54IBqEp8ROq/QAS/cBCYYpcDT9WgodJrHVIzjg9INSXWaeC4lZ2XFS9DvIt A8dOmXPUTuh7HGbVde8ysACGJKiNg8jqyZLNB4NU5VkTdI0IWPYtMp/9x6xL3zf6tmuKw25grJr WAsIfvC71wVSqrjlVdQ== X-Proofpoint-GUID: tNVeUjBk745qF2IolpTRHklOB3S07XUw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768837016158500 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 gues= t requests, and dispatches accepted requests through machine reset and shut= down callbacks. This lets firmware use RPMI reset commands while keeping bo= ard-specific reset policy in the RISC-V machine. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza --- hw/misc/meson.build | 1 + hw/misc/riscv_rpmi.c | 68 +++++++++++- hw/misc/riscv_rpmi_internal.h | 9 ++ hw/misc/riscv_rpmi_sysreset.c | 185 +++++++++++++++++++++++++++++++++ hw/riscv/fdt-common.c | 8 +- hw/riscv/server_platform_ref.c | 2 +- hw/riscv/virt.c | 46 +++++++- include/hw/misc/riscv_rpmi.h | 10 +- include/hw/riscv/fdt-common.h | 3 +- 9 files changed, 322 insertions(+), 10 deletions(-) create mode 100644 hw/misc/riscv_rpmi_sysreset.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index b755796170..a091d393a3 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -185,4 +185,5 @@ system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true:= files('qcom-qdsp6ss-clk. =20 system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( 'riscv_rpmi.c', + 'riscv_rpmi_sysreset.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 3a30d879aa..82a457241c 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -199,10 +199,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 @@ -236,6 +263,10 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTy= pe type) =20 static void riscv_rpmi_cleanup(RiscvRpmiState *s) { + for (uint32_t i =3D ARRAY_SIZE(riscv_rpmi_service_ops); i > 0; i--) { + riscv_rpmi_service_ops[i - 1].remove(s); + } + if (s->context) { rpmi_context_destroy(s->context); s->context =3D NULL; @@ -278,6 +309,30 @@ void riscv_rpmi_context_process_a2p_request(RiscvRpmiS= tate *s) } } =20 +bool riscv_rpmi_context_add_group(RiscvRpmiState *s, + struct rpmi_service_group *group, + const char *name, + Error **errp) +{ + enum rpmi_error rc; + + rc =3D rpmi_context_add_group(s->context, group); + if (rc !=3D RPMI_SUCCESS) { + error_setg(errp, "failed to add RPMI %s service group: %d", name, = rc); + return false; + } + + return true; +} + +void riscv_rpmi_context_remove_group(RiscvRpmiState *s, + struct rpmi_service_group *group) +{ + if (s->context && group) { + rpmi_context_remove_group(s->context, group); + } +} + static bool riscv_rpmi_validate_config(RiscvRpmiState *s, Error **errp) { uint64_t queue_bytes; @@ -357,9 +412,16 @@ static bool riscv_rpmi_add_service_group(RiscvRpmiStat= e *s, const RiscvRpmiServiceConfig *ser= vice, Error **errp) { - error_setg(errp, "unsupported RPMI service group %u", - service->service_group); - return false; + const RiscvRpmiServiceOps *ops; + + ops =3D riscv_rpmi_service_ops_by_group(service->service_group); + if (!ops) { + error_setg(errp, "unsupported RPMI service group %u", + service->service_group); + return false; + } + + return ops->add(s, errp); } =20 static bool riscv_rpmi_init_services(RiscvRpmiState *s, Error **errp) diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index 95aa8dec14..e5880aebe2 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -21,5 +21,14 @@ extern const struct rpmi_shmem_platform_ops rpmi_shmem_q= emu_ops; bool riscv_rpmi_service_enabled(RiscvRpmiState *s, enum rpmi_servicegroup_id service_group); void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); +bool riscv_rpmi_context_add_group(RiscvRpmiState *s, + struct rpmi_service_group *group, + const char *name, + Error **errp); +void riscv_rpmi_context_remove_group(RiscvRpmiState *s, + struct rpmi_service_group *group); + +bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_sysreset_remove(RiscvRpmiState *s); =20 #endif diff --git a/hw/misc/riscv_rpmi_sysreset.c b/hw/misc/riscv_rpmi_sysreset.c new file mode 100644 index 0000000000..825a74b2d9 --- /dev/null +++ b/hw/misc/riscv_rpmi_sysreset.c @@ -0,0 +1,185 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI System Reset service. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "riscv_rpmi_internal.h" +#include "librpmi_env.h" + +typedef struct RiscvRpmiSysresetType { + uint32_t type; + void (*action)(RiscvRpmiState *s); +} RiscvRpmiSysresetType; + +typedef struct RiscvRpmiSysresetGroup { + struct rpmi_service_group group; + struct rpmi_service services[RPMI_SYSRST_SRV_ID_MAX]; + RiscvRpmiState *rpmi; +} RiscvRpmiSysresetGroup; + +static void riscv_rpmi_sysreset_reboot(RiscvRpmiState *s) +{ + const RiscvRpmiMachineOps *ops =3D s->machine_ops; + + if (ops && ops->system_reset) { + ops->system_reset(); + } +} + +static void riscv_rpmi_sysreset_shutdown(RiscvRpmiState *s) +{ + const RiscvRpmiMachineOps *ops =3D s->machine_ops; + + if (ops && ops->system_shutdown) { + ops->system_shutdown(); + } +} + +static const RiscvRpmiSysresetType riscv_rpmi_sysreset_types[] =3D { + { + .type =3D RPMI_SYSRST_TYPE_SHUTDOWN, + .action =3D riscv_rpmi_sysreset_shutdown, + }, { + .type =3D RPMI_SYSRST_TYPE_COLD_REBOOT, + .action =3D riscv_rpmi_sysreset_reboot, + }, +}; + +static const RiscvRpmiSysresetType *riscv_rpmi_sysreset_type_by_id( + uint32_t reset_type) +{ + for (uint32_t index =3D 0; index < ARRAY_SIZE(riscv_rpmi_sysreset_type= s); + index++) { + if (riscv_rpmi_sysreset_types[index].type =3D=3D reset_type) { + return &riscv_rpmi_sysreset_types[index]; + } + } + + return NULL; +} + +static enum rpmi_error riscv_rpmi_sysreset_get_attributes( + struct rpmi_service_group *group, struct rpmi_service *service, + struct rpmi_transport *trans, rpmi_uint16_t request_data_len, + const rpmi_uint8_t *request_data, rpmi_uint16_t *response_data_len, + rpmi_uint8_t *response_data) +{ + uint32_t reset_type =3D ldl_le_p(request_data); + *response_data_len =3D 2 * sizeof(uint32_t); + stl_le_p(response_data, RPMI_SUCCESS); + stl_le_p(response_data + sizeof(uint32_t), + riscv_rpmi_sysreset_type_by_id(reset_type) ? + RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE : 0); + + return RPMI_SUCCESS; +} + +static enum rpmi_error riscv_rpmi_sysreset_do_reset( + struct rpmi_service_group *group, struct rpmi_service *service, + struct rpmi_transport *trans, rpmi_uint16_t request_data_len, + const rpmi_uint8_t *request_data, rpmi_uint16_t *response_data_len, + rpmi_uint8_t *response_data) +{ + RiscvRpmiSysresetGroup *sysreset =3D group->priv; + const RiscvRpmiSysresetType *type; + uint32_t reset_type =3D ldl_le_p(request_data); + + *response_data_len =3D sizeof(uint32_t); + type =3D riscv_rpmi_sysreset_type_by_id(reset_type); + + if (!type) { + stl_le_p(response_data, (uint32_t)RPMI_ERR_INVALID_PARAM); + return RPMI_SUCCESS; + } + + stl_le_p(response_data, RPMI_SUCCESS); + type->action(sysreset->rpmi); + return RPMI_SUCCESS; +} + +static const struct rpmi_service riscv_rpmi_sysreset_services[] =3D { + [RPMI_SYSRST_SRV_ENABLE_NOTIFICATION] =3D { + .service_id =3D RPMI_SYSRST_SRV_ENABLE_NOTIFICATION, + .min_a2p_request_datalen =3D 8, + }, + [RPMI_SYSRST_SRV_GET_ATTRIBUTES] =3D { + .service_id =3D RPMI_SYSRST_SRV_GET_ATTRIBUTES, + .min_a2p_request_datalen =3D 4, + .process_a2p_request =3D riscv_rpmi_sysreset_get_attributes, + }, + [RPMI_SYSRST_SRV_SYSTEM_RESET] =3D { + .service_id =3D RPMI_SYSRST_SRV_SYSTEM_RESET, + .min_a2p_request_datalen =3D 4, + .process_a2p_request =3D riscv_rpmi_sysreset_do_reset, + }, +}; + +static struct rpmi_service_group *riscv_rpmi_sysreset_create(RiscvRpmiStat= e *s) +{ + RiscvRpmiSysresetGroup *sysreset; + struct rpmi_service_group *group; + + sysreset =3D g_new0(RiscvRpmiSysresetGroup, 1); + sysreset->rpmi =3D s; + memcpy(sysreset->services, riscv_rpmi_sysreset_services, + sizeof(riscv_rpmi_sysreset_services)); + + group =3D &sysreset->group; + group->name =3D "sysreset"; + group->servicegroup_id =3D RPMI_SRVGRP_SYSTEM_RESET; + group->max_service_id =3D RPMI_SYSRST_SRV_ID_MAX; + group->servicegroup_version =3D + RPMI_BASE_VERSION(RPMI_SPEC_VERSION_MAJOR, RPMI_SPEC_VERSION_MINOR= ); + group->privilege_level_bitmap =3D RPMI_PRIVILEGE_M_MODE_MASK; + group->services =3D sysreset->services; + group->lock =3D rpmi_env_alloc_lock(); + group->priv =3D sysreset; + + return group; +} + +static void riscv_rpmi_sysreset_destroy(struct rpmi_service_group *group) +{ + if (!group) { + return; + } + + rpmi_env_free_lock(group->lock); + g_free(group->priv); +} + +bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group; + + if (s->sysreset_group) { + error_setg(errp, "duplicate RPMI sysreset service descriptor"); + return false; + } + + group =3D riscv_rpmi_sysreset_create(s); + if (!riscv_rpmi_context_add_group(s, group, "sysreset", errp)) { + riscv_rpmi_sysreset_destroy(group); + return false; + } + + s->sysreset_group =3D group; + return true; +} + +void riscv_rpmi_sysreset_remove(RiscvRpmiState *s) +{ + if (!s->sysreset_group) { + return; + } + + riscv_rpmi_context_remove_group(s, s->sysreset_group); + riscv_rpmi_sysreset_destroy(s->sysreset_group); + s->sysreset_group =3D NULL; +} diff --git a/hw/riscv/fdt-common.c b/hw/riscv/fdt-common.c index ce2dcb43b4..8a378458da 100644 --- a/hw/riscv/fdt-common.c +++ b/hw/riscv/fdt-common.c @@ -315,7 +315,8 @@ void riscv_create_fdt_flash(void *fdt, hwaddr flashbase= , hwaddr flashsize) void riscv_create_fdt_syscon(void *fdt, uint32_t *next_phandle, hwaddr addr, hwaddr size, uint32_t reboot, uint32_t poweroff, - bool sifive_test_compat) + bool sifive_test_compat, + bool create_reset_nodes) { uint32_t syscon_phandle; char *name; @@ -343,6 +344,11 @@ void riscv_create_fdt_syscon(void *fdt, uint32_t *next= _phandle, =20 g_free(name); =20 + /* Some machines route reset and shutdown through another interface. */ + if (!create_reset_nodes) { + return; + } + name =3D g_strdup_printf("/reboot"); qemu_fdt_add_subnode(fdt, name); qemu_fdt_setprop_string(fdt, name, "compatible", "syscon-reboot"); diff --git a/hw/riscv/server_platform_ref.c b/hw/riscv/server_platform_ref.c index 5f485b1c79..d18550b48d 100644 --- a/hw/riscv/server_platform_ref.c +++ b/hw/riscv/server_platform_ref.c @@ -310,7 +310,7 @@ static void finalize_fdt(RISCVServerRefMachineState *s) riscv_create_fdt_syscon(ms->fdt, &phandle, rvserver_ref_memmap[RVSERVER_RESET_SYSCON].bas= e, rvserver_ref_memmap[RVSERVER_RESET_SYSCON].siz= e, - SYSCON_RESET, SYSCON_POWEROFF, false); + SYSCON_RESET, SYSCON_POWEROFF, false, true); =20 riscv_create_fdt_uart(ms->fdt, &rvserver_ref_memmap[RVSERVER_UART0], RVSERVER_UART0_IRQ, AIA_TYPE_APLIC_IMSIC, diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 8a2ed43029..1e313e078e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -52,6 +52,7 @@ #include "chardev/char.h" #include "system/device_tree.h" #include "system/system.h" +#include "system/runstate.h" #include "system/tcg.h" #include "system/kvm.h" #include "system/tpm.h" @@ -478,6 +479,34 @@ static void create_fdt_iommu(RISCVVirtState *s, uint16= _t bdf) s->pci_iommu_bdf =3D bdf; } =20 +static const RiscvRpmiServiceConfig virt_rpmi_services[] =3D { + { + .node_name =3D "sysreset", + .compatible =3D "riscv,rpmi-system-reset", + .service_group =3D RPMI_SRVGRP_SYSTEM_RESET, + }, +}; + +static uint32_t virt_rpmi_service_count(void) +{ + return ARRAY_SIZE(virt_rpmi_services); +} + +static void virt_rpmi_system_reset(void) +{ + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); +} + +static void virt_rpmi_system_shutdown(void) +{ + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); +} + +static const RiscvRpmiMachineOps virt_rpmi_machine_ops =3D { + .system_reset =3D virt_rpmi_system_reset, + .system_shutdown =3D virt_rpmi_system_shutdown, +}; + static RiscvRpmiConfig virt_rpmi_config(RISCVVirtState *s, const uint32_t *hart_ids, uint32_t hart_count) @@ -489,13 +518,18 @@ static RiscvRpmiConfig virt_rpmi_config(RISCVVirtStat= e *s, .a2p_req_size =3D VIRT_RPMI_A2P_REQ_SIZE, .p2a_req_size =3D VIRT_RPMI_P2A_REQ_SIZE, .platform_info =3D "QEMU RISC-V virt RPMI", + .machine_ops =3D &virt_rpmi_machine_ops, .hart_ids =3D hart_ids, .hart_count =3D hart_count, + .services =3D virt_rpmi_services, + .service_count =3D virt_rpmi_service_count(), }; } =20 static void create_fdt_rpmi(RISCVVirtState *s, uint32_t *phandle) { + uint32_t rpmi_mbox_handle; + uint32_t i; RiscvRpmiFdtMboxConfig cfg =3D { .shmem_base =3D s->memmap[VIRT_RPMI_SHMEM].base, .doorbell_base =3D s->memmap[VIRT_RPMI_DOORBELL].base, @@ -504,7 +538,14 @@ static void create_fdt_rpmi(RISCVVirtState *s, uint32_= t *phandle) .doorbell_size =3D s->memmap[VIRT_RPMI_DOORBELL].size, }; =20 - riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, NULL); + riscv_rpmi_fdt_add_mbox(MACHINE(s)->fdt, &cfg, phandle, + &rpmi_mbox_handle); + + for (i =3D 0; i < virt_rpmi_service_count(); i++) { + riscv_rpmi_fdt_add_service_node(MACHINE(s)->fdt, + &virt_rpmi_services[i], + rpmi_mbox_handle); + } } =20 static void finalize_fdt(RISCVVirtState *s) @@ -542,7 +583,8 @@ static void finalize_fdt(RISCVVirtState *s) riscv_create_fdt_syscon(MACHINE(s)->fdt, &phandle, s->memmap[VIRT_TEST].base, s->memmap[VIRT_TEST].size, - FINISHER_RESET, FINISHER_PASS, true); + FINISHER_RESET, FINISHER_PASS, true, + !s->have_rpmi); if (s->have_rpmi) { create_fdt_rpmi(s, &phandle); } diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index c207501405..1ab648359d 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -43,6 +43,11 @@ struct rpmi_service_group; struct rpmi_shmem; struct rpmi_transport; =20 +typedef struct RiscvRpmiMachineOps { + void (*system_reset)(void); + void (*system_shutdown)(void); +} RiscvRpmiMachineOps; + typedef struct RiscvRpmiServiceConfig { const char *node_name; const char *compatible; @@ -58,7 +63,7 @@ typedef struct RiscvRpmiConfig { uint32_t a2p_req_size; uint32_t p2a_req_size; const char *platform_info; - + const RiscvRpmiMachineOps *machine_ops; const uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; @@ -75,7 +80,8 @@ struct RiscvRpmiState { uint32_t a2p_req_size; uint32_t p2a_req_size; char *platform_info; - + const RiscvRpmiMachineOps *machine_ops; + struct rpmi_service_group *sysreset_group; uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; diff --git a/include/hw/riscv/fdt-common.h b/include/hw/riscv/fdt-common.h index eb9db8278d..4d2b8a8059 100644 --- a/include/hw/riscv/fdt-common.h +++ b/include/hw/riscv/fdt-common.h @@ -103,7 +103,8 @@ void riscv_create_fdt_flash(void *fdt, hwaddr flashbase= , hwaddr flashsize); void riscv_create_fdt_syscon(void *fdt, uint32_t *next_phandle, hwaddr addr, hwaddr size, uint32_t reboot, uint32_t poweroff, - bool sifive_test_compat); + bool sifive_test_compat, + bool create_reset_nodes); uint32_t riscv_create_fdt_riscv_iommu_sys(void *fdt, hwaddr addr, hwaddr s= ize, uint32_t *next_phandle, uint32_t irq_chip, From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768816; cv=none; d=zohomail.com; s=zohoarc; b=BdjRbS9Nf1E8myWNfyqga5BgxCZQ9KhkUcE4BXNdExPi6NvvNWC06LEMC9mePBUW2pbDyfBc6rZfxtXbgfNDTARwyAlGhspvP2pcWbh4Y6WXmuvjaE8IzXTum2Q0XcZ9O2CUCQp+hX3HGHtqGvUaquRpuFNcLXUqivvVVS9xfgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768816; 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=Dmfk2gM+Tl7KAfXw/DcWh4xkvdptq2iisCNJWTAyzO0=; b=MsIwakVC3c8WjCHIBsmX7vyDBybAdqRyO/ELpX6lO8D+hhqFJCx9y3mnLt+iE3V+M0Z2+4RAVAW7tOiZdKPnwTdLjckI+Gruu2Bz0r4kMfTT4/YZK2mFxhSFZe3xtO2lLfIm3EbkfUrI0ukXFCp3ygGqKGUbzrgU6DIzuTB3N0k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768816898562.1270708540789; Tue, 3 Nov 2026 21:06:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTCo-0005BN-Pj; Wed, 04 Nov 2026 00:06:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCn-00057T-Bq for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:37 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCj-0002DT-UD for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:37 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40R0bl1191067 for ; Wed, 4 Nov 2026 05:06:22 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 4hqm2pjbj5-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:22 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-36d01525afeso13912eec.3 for ; Tue, 03 Nov 2026 21:06:22 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=Dmfk2gM+Tl7 KAfXw/DcWh4xkvdptq2iisCNJWTAyzO0=; b=E+Lgs/r1Yxd1an5mdcd9Wg9RWJ/ cL1Dvj1zNacv2KfUd2CrHAGrohm4MpZ7m5DgtlY746RT1mpmh3F18qbM9esYuqxh dZdwkKlXpusRV0RKfNgnh8xAx19/d0Fmdl0WK6jzG4Wg9w2g6agbH+OHoKSsdHjJ 8fwxa+3SavtnUSnqHW8OhDHohbagZft2Iov0k+EbniGbnSOJNcC4Wsu0iASLjMrS f3G0MjFOLLSOE6ie832qJ87zaJaUgbgaYocTiSf/r0/kKrrooqhPpG1jQ5FlUqGu esXr4cGosifwQf2ydORWrly7qryzFWEf8KBvLSow8u/sLJuYcXPPj3RyyfA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768782; x=1794373582; 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=Dmfk2gM+Tl7KAfXw/DcWh4xkvdptq2iisCNJWTAyzO0=; b=iWpN4Tzq+q2n54zSxd1dKHQJf5OSB/BgA4dK9rT84GB+Ur5AdtNWztJ8ZogpP6omKv XMMB3XZJalD2Djwu2pULDEGza304dsz/UDpIIfkObODFeqyruh0Thc5cTzXcd5ulvy5C 9nyr929GIEC36wOZmstbZgiRmVajEQWoS+SfRYPMZvjcl3EgzrLvFDmIzP0T1YctMr7s hVBdBk1H19dz7v3HiMWLL9yOfBwX6J+23KtJwM1H2pBkaV/Vdm4xgkKfs5vDQ4QFL467 ZGljBwRrv8Av6E12DdKMJG4q1dkqN/0r3IS8mxp8CrADrFk9n+JKmA39uF29yAeFvcnd VO7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768782; x=1794373582; 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=Dmfk2gM+Tl7KAfXw/DcWh4xkvdptq2iisCNJWTAyzO0=; b=wLH6JQ9zIsJUr3BlPmTS8uXPUOFeasriK6mTlDxFWMXr+6Pjlfx1WjvTtuPMWIyTdS eCzfBmcmzpDMP6u1b0B6Axp0v1XXtgQr5bFfQMst1MYt2BZy7L4uvTW2EZOQhB+rV8AE g350Cjej6v1tvPHzd+BCQ2+HVWeZhOkC6sl2nRaXcEsjeyjV4p3//QPO8Jqo1E1w+CwS Gjo79iM4QG/1JWsIzDfcl4vTIa3hubMiU3sPg12iWrJxtoA/Oo6ttTl3W6iQGrhQIpGs zuTNWBR7zf/DfeBAF17C0qmfWTRLIwGWl01JlZpVo18qTeYMYu47oVjg28lLviVbPZ5q jEfg== X-Gm-Message-State: APuU4Z/oHnzEytTpnzYjkm1m4P8wi1Qcxh4G9uxNUkdj8KnwheyFbNhO /FhO1Vpi+vHCakuG4uFjFtkJubEQQ1OhrxeFGC876piOCepqdI5Nh8taSih4+bME6t071YG0zsq uq6mqBB7SzT0R6d5APxf9hFeEq9E2vB9c64VFcoJHTpl3M8TW25mH8bXfN9poPaNCeQ== X-Gm-Gg: AYBFou279jrvgUhLbC8DAvKcpU7OQVODosM1IVrvqzFXB9g3/No1g1DeZSk3UoKCG4i clqo10kqoxEqUkHVv8UyCFTzW9Xbfmx4pzuYrF8EPKEEqIZMFY1unVeOGG5MjM4giIZiZF3Tlzv P9qBc2AkDYP5MadsFnZq7aMUSLdx1VXhy38w48ISeLskGaDXtUn3EzDE2AyWbQlL1bSYwTnWPMV /9PSekG6d8bK/AIlxCnoo/NIX+VhZKDYdRG7dcmXHBAh5oSncXa+5PIXMN5XAEFEZB/enn5Bdgi tM7PLEAFVCeqJldWNHjAkh74x+i2ulaAkcyEaXN5bx5n4VbEgWLnsRvGw2BCOcKZIcaTuEWaEfM 9HeZJJXMKPrKbrSLwXpeM0ai+7NtrTnIGIiSE7dpFJTokbwBU4Xg+a/zqYs8RMWhqtxDuCY+Y97 Ek/QzfsdATU6zWt0IkeQ+Ph8hHKdFpmVZOYBd7nHCYWLnZx2Dth7Q+smeqadPPd7f5DZ4AuC4Lu Z6tsVAN X-Received: by 2002:a05:7300:cb88:b0:36c:a1bc:6115 with SMTP id 5a478bee46e88-36ca1bc6a73mr4487869eec.0.1793768781463; Tue, 03 Nov 2026 21:06:21 -0800 (PST) X-Received: by 2002:a05:7300:cb88:b0:36c:a1bc:6115 with SMTP id 5a478bee46e88-36ca1bc6a73mr4487790eec.0.1793768780768; Tue, 03 Nov 2026 21:06:20 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v14 06/10] riscv: add RPMI HSM service Date: Wed, 4 Nov 2026 10:33:19 +0530 Message-ID: <20261104050324.733555-7-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX/RXZMDzDCvUw 3bcqDMt9VAbLf9lS5f4KLShhLi5SMe4XRH81bWn1KC7xksLGqG6juESSiSDNc6HGIuR06nnRUxT FK86kjYCvNkx97i6VnTpgILN8ODOfHdIJxnHHPGfG80tQOWEhqQTLVWcIlsT+8lVjaVvX3hvqvG EtyLv8UbBLMkEPvBPd6VJOr0ulTHeoZv5Xeok8TNiCVSD9K6RRrzu/HU32pPwH/1WKJZSLskKnu PwZUEQfrzZTU4edgDVJWFewYES9b2Yf3QzWY6q/V1AzChzfB3skkJ+J2jnph/ETMDcZRxFUSjZQ mnfz1RhIzkiAP9hBYszMUQbNgmCW9qXaCB7nGUn03fzLzqG5w/ogAu9GseFqIWGmTYqNI7V35qn G2oqq2h2svdhwX1LJ5NL5yk2CzwftpPGGqG1he2ISlj51EVbVbBaGLDETPrbhjocuPM8Sycaio2 pvd5mMG0HE2aaYJuvLQ== X-Proofpoint-GUID: n71wAvHNHcuyfMkH7Of05zJDzV-5_AhG X-Proofpoint-ORIG-GUID: n71wAvHNHcuyfMkH7Of05zJDzV-5_AhG X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX90+y14LmqcYX P6HPfMF/z/Tj32wJOo6jZ4dffH6RkQZ4KungC5I8TzsV1EYJTBN2sSI22UHbyFJwpxRhaWTCQdw uMdHc2ruHEakQzRbccaij1gA12C1AQQ= X-Authority-Analysis: v=2.4 cv=c64+0h9l c=1 sm=1 tr=0 ts=6aeabd4e cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=cGHwFTRIVs7s_0MWZt0A: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-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768818677158500 Content-Type: text/plain; charset="utf-8" Add the RPMI Hart State Management service group for RISC-V virt. The service exposes configured hart IDs to librpmi and keeps stable per-har= t state in the RPMI device. A persistent observer on each target CPU makes = actual WFI entry authoritative for stop and suspend completion, while CPU w= ork handles starts and requests received after a hart has already entered W= FI. Keep RPMI-stopped harts off despite pending interrupts, timer events, kicks= , or generic resume attempts. HART_START is the normal path that restores t= he hart power state and execution address. Serialize librpmi state publication under the BQL, drain target-CPU work du= ring teardown, and reconstruct the external librpmi HSM object during machi= ne reset so pending operations return to the STARTED baseline. Signed-off-by: Subrahmanya Lingappa --- hw/misc/meson.build | 1 + hw/misc/riscv_rpmi.c | 7 + hw/misc/riscv_rpmi_hsm.c | 344 ++++++++++++++++++++++++++++++++++ hw/misc/riscv_rpmi_internal.h | 5 +- hw/riscv/virt.c | 5 + include/hw/misc/riscv_rpmi.h | 5 + target/riscv/cpu-qom.h | 16 ++ target/riscv/cpu.c | 61 ++++++ target/riscv/cpu.h | 7 + target/riscv/tcg/op_helper.c | 4 + target/riscv/tcg/tcg-cpu.c | 1 + 11 files changed, 455 insertions(+), 1 deletion(-) create mode 100644 hw/misc/riscv_rpmi_hsm.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index a091d393a3..6d93cd4ab0 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -186,4 +186,5 @@ system_ss.add(when: 'CONFIG_QCOM_QDSP6SS_CLK', if_true:= files('qcom-qdsp6ss-clk. system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( 'riscv_rpmi.c', 'riscv_rpmi_sysreset.c', + 'riscv_rpmi_hsm.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 82a457241c..1bf9d77b04 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -210,6 +210,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 @@ -259,6 +263,9 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTyp= e type) memset(memory_region_get_ram_ptr(&s->shmem), 0, s->shmem_size); memory_region_set_dirty(&s->shmem, 0, s->shmem_size); } + if (!riscv_rpmi_hsm_reset(s, &error_abort)) { + return; + } } =20 static void riscv_rpmi_cleanup(RiscvRpmiState *s) diff --git a/hw/misc/riscv_rpmi_hsm.c b/hw/misc/riscv_rpmi_hsm.c new file mode 100644 index 0000000000..42a4f3b096 --- /dev/null +++ b/hw/misc/riscv_rpmi_hsm.c @@ -0,0 +1,344 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI HSM service. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "riscv_rpmi_internal.h" +#include "hw/core/cpu.h" +#include "qemu/main-loop.h" +#include "system/cpus.h" +#include "target/riscv/cpu-qom.h" +#include "librpmi_env.h" + +static const struct rpmi_hsm_suspend_type riscv_rpmi_hsm_suspend_types[] = =3D { + { .type =3D 0 }, +}; + +struct RiscvRpmiHsmHart { + RiscvRpmiState *rpmi; + CPUState *cpu; + enum rpmi_hart_hw_state state; + enum rpmi_hart_hw_state wfi_state; + uint64_t start_addr; +}; + +/* + * RPMI requests and queued CPU work hold BQL. Natural WFI transitions use= an + * atomic armed-state check and take BQL only when a transition is pending. + */ +static RiscvRpmiHsmHart *riscv_rpmi_hsm_hart(RiscvRpmiState *s, + uint32_t hart_index) +{ + if (!s->hsm_harts || hart_index >=3D s->hart_count || + !s->hsm_harts[hart_index].cpu) { + return NULL; + } + + return &s->hsm_harts[hart_index]; +} +static void riscv_rpmi_hsm_wfi(CPUState *cpu, bool entering, void *opaque) +{ + RiscvRpmiHsmHart *hart =3D opaque; + enum rpmi_hart_hw_state wfi_state; + bool need_bql =3D !bql_locked(); + bool changed =3D false; + + wfi_state =3D qatomic_read(&hart->wfi_state); + if (wfi_state =3D=3D RPMI_HART_HW_STATE_MAX) { + return; + } + if (need_bql) { + bql_lock(); + } + + wfi_state =3D qatomic_read(&hart->wfi_state); + if (entering && wfi_state =3D=3D RPMI_HART_HW_STATE_STOPPED) { + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + riscv_cpu_set_powered_off(cpu, true); + hart->state =3D RPMI_HART_HW_STATE_STOPPED; + changed =3D true; + } else if (wfi_state =3D=3D RPMI_HART_HW_STATE_SUSPENDED) { + hart->state =3D entering ? RPMI_HART_HW_STATE_SUSPENDED : + RPMI_HART_HW_STATE_STARTED; + if (!entering) { + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + } + changed =3D true; + } + + if (changed) { + rpmi_hsm_process_state_changes(hart->rpmi->hsm); + } + if (need_bql) { + bql_unlock(); + } +} + +static void riscv_rpmi_hsm_set_observer(CPUState *cpu, run_on_cpu_data dat= a) +{ + riscv_cpu_set_wfi_observer(cpu, riscv_rpmi_hsm_wfi, data.host_ptr); +} + +static void riscv_rpmi_hsm_clear_observer(CPUState *cpu, run_on_cpu_data d= ata) +{ + riscv_cpu_set_wfi_observer(cpu, NULL, NULL); + riscv_cpu_set_powered_off(cpu, false); + cpu->halted =3D false; + cpu_resume(cpu); +} + +static void riscv_rpmi_hsm_start_cpu(CPUState *cpu, run_on_cpu_data data) +{ + RiscvRpmiHsmHart *hart =3D data.host_ptr; + + g_assert(bql_locked()); + riscv_cpu_handle_wfi_resume(cpu); + cpu_set_pc(cpu, hart->start_addr); + riscv_cpu_set_powered_off(cpu, false); + cpu->halted =3D false; + cpu_resume(cpu); + hart->state =3D RPMI_HART_HW_STATE_STARTED; + rpmi_hsm_process_state_changes(hart->rpmi->hsm); +} + +static void riscv_rpmi_hsm_replay_wfi(CPUState *cpu, run_on_cpu_data data) +{ + riscv_cpu_replay_wfi_observer(cpu); +} + +static enum rpmi_error riscv_rpmi_hsm_start_prepare( + void *priv, rpmi_uint32_t hart_index, rpmi_uint64_t start_addr) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(priv, hart_index); + + g_assert(bql_locked()); + if (!hart) { + return RPMI_ERR_INVALID_PARAM; + } + + hart->start_addr =3D start_addr; + async_run_on_cpu(hart->cpu, riscv_rpmi_hsm_start_cpu, + RUN_ON_CPU_HOST_PTR(hart)); + return RPMI_SUCCESS; +} + +/* librpmi requires finalize hooks even when QEMU has no second phase. */ +static void riscv_rpmi_hsm_start_finalize(void *priv, + rpmi_uint32_t hart_index, + rpmi_uint64_t start_addr) +{ +} + +static enum rpmi_error riscv_rpmi_hsm_arm_wfi( + RiscvRpmiState *s, uint32_t hart_index, enum rpmi_hart_hw_state state) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(s, hart_index); + + g_assert(bql_locked()); + if (!hart) { + return RPMI_ERR_INVALID_PARAM; + } + + qatomic_set(&hart->wfi_state, state); + async_run_on_cpu(hart->cpu, riscv_rpmi_hsm_replay_wfi, + RUN_ON_CPU_NULL); + return RPMI_SUCCESS; +} + +static enum rpmi_error riscv_rpmi_hsm_stop_prepare(void *priv, + rpmi_uint32_t hart_ind= ex) +{ + return riscv_rpmi_hsm_arm_wfi(priv, hart_index, + RPMI_HART_HW_STATE_STOPPED); +} + +static void riscv_rpmi_hsm_stop_finalize(void *priv, + rpmi_uint32_t hart_index) +{ +} + +static enum rpmi_error riscv_rpmi_hsm_suspend_prepare( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_hsm_suspend_type *suspend_type, + rpmi_uint64_t resume_addr) +{ + if (!suspend_type) { + return RPMI_ERR_INVALID_PARAM; + } + + return riscv_rpmi_hsm_arm_wfi(priv, hart_index, + RPMI_HART_HW_STATE_SUSPENDED); +} + +static void riscv_rpmi_hsm_suspend_finalize( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_hsm_suspend_type *suspend_type, + rpmi_uint64_t resume_addr) +{ +} + +static enum rpmi_hart_hw_state riscv_rpmi_hsm_get_hw_state( + void *priv, rpmi_uint32_t hart_index) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(priv, hart_index); + + g_assert(bql_locked()); + return hart ? hart->state : RPMI_HART_HW_STATE_STOPPED; +} + +static const struct rpmi_hsm_platform_ops riscv_rpmi_hsm_ops =3D { + .hart_get_hw_state =3D riscv_rpmi_hsm_get_hw_state, + .hart_start_prepare =3D riscv_rpmi_hsm_start_prepare, + .hart_start_finalize =3D riscv_rpmi_hsm_start_finalize, + .hart_stop_prepare =3D riscv_rpmi_hsm_stop_prepare, + .hart_stop_finalize =3D riscv_rpmi_hsm_stop_finalize, + .hart_suspend_prepare =3D riscv_rpmi_hsm_suspend_prepare, + .hart_suspend_finalize =3D riscv_rpmi_hsm_suspend_finalize, +}; + +static bool riscv_rpmi_hsm_create_external( + RiscvRpmiState *s, struct rpmi_service_group **group, Error **errp) +{ + s->hsm =3D rpmi_hsm_create(s->hart_count, s->hart_ids, + ARRAY_SIZE(riscv_rpmi_hsm_suspend_types), + riscv_rpmi_hsm_suspend_types, + &riscv_rpmi_hsm_ops, s); + if (!s->hsm) { + error_setg(errp, "failed to create RPMI HSM context"); + return false; + } + + *group =3D rpmi_service_group_hsm_create(s->hsm); + if (!*group) { + rpmi_hsm_destroy(s->hsm); + s->hsm =3D NULL; + error_setg(errp, "failed to create RPMI HSM service group"); + return false; + } + + return true; +} + +static void riscv_rpmi_hsm_destroy_external(RiscvRpmiState *s) +{ + if (s->hsm_group) { + rpmi_env_free_lock(s->hsm_group->lock); + s->hsm_group->lock =3D NULL; + rpmi_service_group_hsm_destroy(s->hsm_group); + s->hsm_group =3D NULL; + } + if (s->hsm) { + rpmi_hsm_destroy(s->hsm); + s->hsm =3D NULL; + } +} + +static void riscv_rpmi_hsm_reset_cpu(CPUState *cpu, run_on_cpu_data data) +{ + riscv_cpu_handle_wfi_resume(cpu); + riscv_cpu_set_powered_off(cpu, false); + cpu->halted =3D false; +} + +bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group; + + if (s->hsm_group) { + error_setg(errp, "duplicate RPMI HSM service descriptor"); + return false; + } + if (!s->hart_count || !s->hart_ids) { + error_setg(errp, "RPMI HSM service requires hart IDs"); + return false; + } + + s->hsm_harts =3D g_new0(RiscvRpmiHsmHart, s->hart_count); + for (uint32_t i =3D 0; i < s->hart_count; i++) { + RiscvRpmiHsmHart *hart =3D &s->hsm_harts[i]; + + hart->rpmi =3D s; + hart->cpu =3D cpu_by_arch_id(s->hart_ids[i]); + hart->state =3D RPMI_HART_HW_STATE_STARTED; + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + } + + if (!riscv_rpmi_hsm_create_external(s, &group, errp)) { + g_clear_pointer(&s->hsm_harts, g_free); + return false; + } + if (!riscv_rpmi_context_add_group(s, group, "HSM", errp)) { + s->hsm_group =3D group; + riscv_rpmi_hsm_destroy_external(s); + g_clear_pointer(&s->hsm_harts, g_free); + return false; + } + + s->hsm_group =3D group; + for (uint32_t i =3D 0; i < s->hart_count; i++) { + RiscvRpmiHsmHart *hart =3D &s->hsm_harts[i]; + + if (hart->cpu) { + run_on_cpu(hart->cpu, riscv_rpmi_hsm_set_observer, + RUN_ON_CPU_HOST_PTR(hart)); + } + } + return true; +} + +void riscv_rpmi_hsm_remove(RiscvRpmiState *s) +{ + if (!s->hsm_harts) { + return; + } + + for (uint32_t i =3D 0; i < s->hart_count; i++) { + CPUState *cpu =3D s->hsm_harts[i].cpu; + + if (cpu) { + run_on_cpu(cpu, riscv_rpmi_hsm_clear_observer, RUN_ON_CPU_NULL= ); + } + } + riscv_rpmi_context_remove_group(s, s->hsm_group); + riscv_rpmi_hsm_destroy_external(s); + g_clear_pointer(&s->hsm_harts, g_free); +} + +bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group =3D NULL; + + if (!s->hsm_harts) { + return true; + } + + for (uint32_t i =3D 0; i < s->hart_count; i++) { + RiscvRpmiHsmHart *hart =3D &s->hsm_harts[i]; + + if (hart->cpu) { + run_on_cpu(hart->cpu, riscv_rpmi_hsm_reset_cpu, + RUN_ON_CPU_NULL); + } + hart->state =3D RPMI_HART_HW_STATE_STARTED; + qatomic_set(&hart->wfi_state, RPMI_HART_HW_STATE_MAX); + } + + riscv_rpmi_context_remove_group(s, s->hsm_group); + riscv_rpmi_hsm_destroy_external(s); + if (!riscv_rpmi_hsm_create_external(s, &group, errp)) { + return false; + } + if (!riscv_rpmi_context_add_group(s, group, "HSM", errp)) { + s->hsm_group =3D group; + riscv_rpmi_hsm_destroy_external(s); + return false; + } + s->hsm_group =3D group; + return true; +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index e5880aebe2..e56dba5b1a 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -27,8 +27,11 @@ bool riscv_rpmi_context_add_group(RiscvRpmiState *s, Error **errp); void riscv_rpmi_context_remove_group(RiscvRpmiState *s, struct rpmi_service_group *group); - bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp); void riscv_rpmi_sysreset_remove(RiscvRpmiState *s); =20 +bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_hsm_remove(RiscvRpmiState *s); +bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **errp); + #endif diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 1e313e078e..32aa13325e 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -485,6 +485,11 @@ static const RiscvRpmiServiceConfig virt_rpmi_services= [] =3D { .compatible =3D "riscv,rpmi-system-reset", .service_group =3D RPMI_SRVGRP_SYSTEM_RESET, }, + { + .node_name =3D "hsm", + .compatible =3D "riscv,rpmi-hsm", + .service_group =3D RPMI_SRVGRP_HSM, + }, }; =20 static uint32_t virt_rpmi_service_count(void) diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index 1ab648359d..3a240941cd 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -42,6 +42,8 @@ struct rpmi_context; struct rpmi_service_group; struct rpmi_shmem; struct rpmi_transport; +struct rpmi_hsm; +typedef struct RiscvRpmiHsmHart RiscvRpmiHsmHart; =20 typedef struct RiscvRpmiMachineOps { void (*system_reset)(void); @@ -82,6 +84,9 @@ struct RiscvRpmiState { char *platform_info; const RiscvRpmiMachineOps *machine_ops; struct rpmi_service_group *sysreset_group; + struct rpmi_hsm *hsm; + struct rpmi_service_group *hsm_group; + RiscvRpmiHsmHart *hsm_harts; uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h index 61234842e3..f6b6023835 100644 --- a/target/riscv/cpu-qom.h +++ b/target/riscv/cpu-qom.h @@ -64,4 +64,20 @@ =20 OBJECT_DECLARE_CPU_TYPE(RISCVCPU, RISCVCPUClass, RISCV_CPU) =20 +#ifndef CONFIG_USER_ONLY +/* + * WFI observers persist across entries and exits. Access observers and WFI + * state only on the target CPU thread; use run_on_cpu() to register or re= move + * an observer and drain earlier CPU work before freeing its opaque state. + */ +void riscv_cpu_set_wfi_observer( + CPUState *cpu, + void (*observer)(CPUState *cpu, bool entering, void *opaque), + void *opaque); +void riscv_cpu_handle_wfi(CPUState *cpu); +void riscv_cpu_handle_wfi_resume(CPUState *cpu); +void riscv_cpu_replay_wfi_observer(CPUState *cpu); +void riscv_cpu_set_powered_off(CPUState *cpu, bool powered_off); +#endif + #endif /* RISCV_CPU_QOM_H */ diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 5a0529fbda..e516a6b98f 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -58,6 +58,61 @@ const uint32_t misa_bits[] =3D {RVI, RVE, RVM, RVA, RVF,= RVD, RVV, */ #define RISCV_CPU_MARCHID 42 =20 +#ifndef CONFIG_USER_ONLY +void riscv_cpu_set_wfi_observer(CPUState *cpu, + void (*observer)(CPUState *, bool, void *), + void *opaque) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + rcpu->wfi_observer =3D observer; + rcpu->wfi_observer_opaque =3D opaque; +} + +void riscv_cpu_handle_wfi(CPUState *cpu) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + rcpu->wfi_active =3D true; + if (rcpu->wfi_observer) { + rcpu->wfi_observer(cpu, true, rcpu->wfi_observer_opaque); + } +} + +void riscv_cpu_handle_wfi_resume(CPUState *cpu) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + if (!rcpu->wfi_active) { + return; + } + rcpu->wfi_active =3D false; + if (rcpu->wfi_observer) { + rcpu->wfi_observer(cpu, false, rcpu->wfi_observer_opaque); + } +} + +void riscv_cpu_replay_wfi_observer(CPUState *cpu) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + g_assert(qemu_cpu_is_self(cpu)); + if (rcpu->wfi_active && rcpu->wfi_observer) { + rcpu->wfi_observer(cpu, true, rcpu->wfi_observer_opaque); + } +} + +void riscv_cpu_set_powered_off(CPUState *cpu, bool powered_off) +{ + RISCVCPU *rcpu =3D RISCV_CPU(cpu); + + qatomic_set(&rcpu->powered_off, powered_off); +} +#endif + /* * From vector_helper.c * Note that vector data is stored in host-endian 64-bit chunks, @@ -967,6 +1022,10 @@ static bool riscv_cpu_has_work(CPUState *cs) { RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; + + if (qatomic_read(&cpu->powered_off)) { + return false; + } /* * Definition of the WFI instruction requires it to ignore the privile= ge * mode and delegation registers, but respect individual enables @@ -988,6 +1047,8 @@ static void riscv_cpu_reset_hold(Object *obj, ResetTyp= e type) mcc->parent_phases.hold(obj, type); } #ifndef CONFIG_USER_ONLY + riscv_cpu_set_powered_off(cs, false); + cpu->wfi_active =3D false; env->misa_mxl =3D mcc->def->misa_mxl_max; env->priv =3D PRV_M; env->mstatus &=3D ~(MSTATUS_MIE | MSTATUS_MPRV); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 49a1186bdb..ac79397858 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -577,6 +577,13 @@ struct ArchCPU { =20 CPURISCVState env; =20 +#ifndef CONFIG_USER_ONLY + void (*wfi_observer)(CPUState *, bool, void *); + void *wfi_observer_opaque; + bool wfi_active; + bool powered_off; +#endif + GDBFeature dyn_csr_feature; GDBFeature dyn_vreg_feature; =20 diff --git a/target/riscv/tcg/op_helper.c b/target/riscv/tcg/op_helper.c index f9c79fe6b9..b0fb3c2cf8 100644 --- a/target/riscv/tcg/op_helper.c +++ b/target/riscv/tcg/op_helper.c @@ -644,6 +644,10 @@ void HELPER(wfi)(CPURISCVState *env) return; } cs->halted =3D 1; +#ifndef CONFIG_USER_ONLY + /* Publish WFI only after QEMU has entered the halted state. */ + riscv_cpu_handle_wfi(cs); +#endif cs->exception_index =3D EXCP_HLT; cpu_loop_exit(cs); } diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index 2a7796c382..2bd198c016 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -305,6 +305,7 @@ const TCGCPUOps riscv_tcg_ops =3D { .tlb_fill =3D riscv_cpu_tlb_fill, .pointer_wrap =3D riscv_pointer_wrap, .cpu_exec_enter =3D riscv_cpu_exec_enter, + .leaving_halt =3D riscv_cpu_handle_wfi_resume, .cpu_exec_interrupt =3D riscv_cpu_exec_interrupt, .cpu_exec_reset =3D cpu_reset, .do_interrupt =3D riscv_cpu_do_interrupt, From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768850; cv=none; d=zohomail.com; s=zohoarc; b=I1jxsWOnZvEBsXxcN+Ugx6KHVT6TWgNPNJD8aNto90aVUHARA8vftHN968Ty5tybMenCzxpNfqJ2HOunnXEXcZUhKkF+p756QLzxCSyexJd5vV36KkyLP221k5KZPRwOHxGK+yg+x/8iWbuZmvdjh1w2UKrj6x59TfSFnIT4F4M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768850; 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=d+pDUawxAXtCoCyAp3yiWcSw5cwf6H6rCMMVnTzmx6E=; b=GiWCnWsJbHoTgczh/ekHhcjpLp6ciPUFvqwLnnOiWncjrr0M+tszZgobngfYAzav5rJojcHpmsT0K2k1iqgm75jdpUvRGV8iA6nqdsOXZUF3hUM4MZN+JBafN6+qfUg4lmiXuJY23l6H1tQKesWbPZsEPRunifnWKEswR5l16HE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768850305500.22797023621854; Tue, 3 Nov 2026 21:07:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTCx-0005K1-IB; Wed, 04 Nov 2026 00:06:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCr-0005Hw-64 for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:41 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCn-0002Dv-Ot for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:40 -0500 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40R3HK1191107 for ; Wed, 4 Nov 2026 05:06:26 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 4hqm2pjbja-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:26 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-36c98e5ad40so49506eec.0 for ; Tue, 03 Nov 2026 21:06:26 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=d+pDUawxAXt CoCyAp3yiWcSw5cwf6H6rCMMVnTzmx6E=; b=WX7rQBy/W+I47wReU4etZU3KMGl bAPExMvnrQYyMoUcevs/P38kBW4JkxA73jN0TKQQp/nkuT8NzK9oOPbbM6ANmC8D g5eeEGAm1NB08GxbnCeI4bVo93rdT0QZ9uDjPvYkQY6lAG8QKgNOsh3ZUveAaiwa Q6BuXPxJd5Qm6/6+UxZQncWKV1Bkwl1lnxZMf3UaH2aMCVmEKt8zV/BKHAaA/8xd 9HE8RxqqH+V7pHVPWMdMi1CXQmgjkqMr0tfOVChZyFO4cdzQy9JHI5FP+sIj+n0k wkuE+O9JT92ijwTi6dpbN8bqhZ3gF/OZJqHs790Z3nvbsiq4YgcDFO0ph8A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768786; x=1794373586; 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=d+pDUawxAXtCoCyAp3yiWcSw5cwf6H6rCMMVnTzmx6E=; b=frBWnXeIuuw14p0QIb0TrCLr13EoFHQgyyJgf5a/TJWRpdjnSbXHM2en3akJzFV6Yx 3XmSi5vh2PzfmoD4aRYRTXP6bR1L4xFgo2Eua9d7d8AQU01yKRq7jcFofawIdbPIQGP+ j2wjP3x+Hs9A435eY8yv3aY2UvYoSUdNtrgbLxldGQvc2G05EZmd1sarcVFT9NTOwQF2 vh0VbWgKYU2B0V14ruxJy+k0hUQoZdIjyDSKOvU/OsJSPyLYOG/GgTzQHDyP94whaOcP 9tanW2YElGpwtli9q6wIywwjpbVQ4ZCtmiEJUWTa3sGHO0IHrCBRm/xP4kKqHmSS0Yjw XfFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768786; x=1794373586; 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=d+pDUawxAXtCoCyAp3yiWcSw5cwf6H6rCMMVnTzmx6E=; b=CPQS9SKimemFeUMHxAd6UhjIVBZPgPzIK+Q/Q4/L+qcovbRXD6C+bcGGfAtpHm/nqg u5Q0HBSdI4RAWjwzUeh3++Uwj1o+MfKZvqbT7sp4eCaTgLJ5qYi1Gd2dv4ORcwsDMEii 1AIZWGy+o7kQAXrp5/Hf5nzwO115MMRuVUWz8LWXnrJeomzoItTieN+Ow7gDVOvgOn/W lw3gJiMMbYDxRTG1dYpw1F4if5dNzzuVjfrTar/CsX5o1bzE0rGFk5jIz5UA+GZH+0Ek W/jkubiFLOcAL3EEixctb/3i6pQJoGUgEwtxwo8Jjf7B1LaYu//TieFwAt/BbaVg/Ho3 Oz+Q== X-Gm-Message-State: APuU4Z/20JXpDtamMqJNPCGaXPnOm1S9Grv7ACxTgpOWghvtmQCGN6NO bIMzFoiHCdXykRcaIPGjiyJwN5IrqtwRsUwf9rtMs0TcgNWYN0Q6XKRJ0CtY2A3fNwuwdcpjaJD i57ZmJ9sD17o0xBjWDY6M9MiUpN53x9sZdqY7dkayegM2Y6xgzWn3yXggR2jDrdXNjg== X-Gm-Gg: AYBFou0giUlj3lCWtDVHt011r4s1s8yPfB/091GA3y788lVQWhjwoY0OObewVBkcfKR mACdBprtl2mf7RjntrXbTD2uM5WHX8xu+w96V/eheqocpcLn1mhB5zCUie4MEKzXJFdLiZO9UfD IRomtt1IpeeYCbsn7vGOGYSkqGIHDA/hTAPRLoZzVEU7Vx8VGGMdPwJVgAvkhhbQXCaAeAQN2q8 jh1gs30+GSgtwoKoicTXUL8hJOg/1J8U4SMqVhq4grLBLcEB8uMJ+jj3BZC11auF7yXdP9AZ80B T7BDFTljvHpiUBFqKM8E0mvvQiOfO33V1K1Uc10FcVkGO9Ya+bClm1lfTFrRB3+J0FoS5dwy/4M FEMO5bpvCOcXXf6TjLjNz/KkqbLxDmFsPlf5X2652ZDxFVjPox9Xa0ZxRZ/MwY6KYrnrDW+37z1 B7zud2feyDsM9SuLYuHMrJodwC/zmajPYovlbjOiP79EfOtpKEPWDekcmSV2gAIV8eEGh/e4yXm p5hm4k/ X-Received: by 2002:a05:7301:fa6:b0:369:f195:a5ff with SMTP id 5a478bee46e88-36a4231f8e3mr34526488eec.1.1793768785215; Tue, 03 Nov 2026 21:06:25 -0800 (PST) X-Received: by 2002:a05:7301:fa6:b0:369:f195:a5ff with SMTP id 5a478bee46e88-36a4231f8e3mr34526445eec.1.1793768784515; Tue, 03 Nov 2026 21:06:24 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v14 07/10] riscv: add RPMI system suspend service Date: Wed, 4 Nov 2026 10:33:20 +0530 Message-ID: <20261104050324.733555-8-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX7p2/bCN2WGh2 rm5ieiDa+O6DvcbnEsvUrJsNXMDRQsnXprR5fs8+O26Nqgu7zxs6V1FkpyEgMUGRYMy1T8/XrT+ DAI3rSpxR7QFrqbv4arQtWpH2D9dZhdU1Vuj1jgIQWMl4R3VENjpgO2NG/lBWRzMN4DO2Pkjjcb qYZb+CrD3JseA4FT/pHIsp9akWODqTn7sSuRiqYHMPf1QuO73VDd0zrszhHbcBbzMdA4NALBdmn 3uD+gPOK0rbp0QlbFSpQ0nNDau2wFaQKIoLuWdSeMIm5hPqnCr7ScL0pyeQeyOdH+ReDTfgnMSf afwnXA+YMhjOIdPUb3+WJEHQy31x0Him7UaVSyYt4Z6rsygjuawSe3vn/Oygq44uLi1B6GdIajI YGeD3PmrO6YYbvl1EdHPxKkBCV7adqINAG42k7QDas9yOdV380RgYu5ceJNqIwUi+WFd88/iNsY tCy01t3vy9Ljh+DJGrQ== X-Proofpoint-GUID: UAOXQitXyYRe2kSu2xj-7aV3y7g3_pRR X-Proofpoint-ORIG-GUID: UAOXQitXyYRe2kSu2xj-7aV3y7g3_pRR X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX1tj7sACs5l42 ySfX4MZlV8L7VHMYLMF1x67CJEmyq1CayoyzXNGGAB53grBT0PWCSibS0VOG3OlF+YmFCI9jeN3 AiHMad5Gd5fs8H9loWd5v96fCY+a09w= X-Authority-Analysis: v=2.4 cv=c64+0h9l c=1 sm=1 tr=0 ts=6aeabd52 cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=Mh6PCMENURz3S0C0lcMA:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 adultscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768851311158500 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 QE= MU wakeup support, and routes the finalize callback to the generic system s= uspend path. Process only the accepted System Suspend event instead of poll= ing every RPMI service group from an unrelated doorbell request. On wakeup, publish the suspend event under the BQL and defer the HSM hart r= esume until vCPUs are ready to run. Cancel stale wakeup work during teardow= n. Machine reset removes and recreates System Suspend around HSM reconstruc= tion so the service always references the current HSM object. Reject malformed resume addresses before accepting suspend. Require the target hart's configured instruction alignment and address width, and verify that the resume PC is backed by RAM in the active system-memory map. Signed-off-by: Subrahmanya Lingappa --- hw/misc/meson.build | 2 + hw/misc/riscv_rpmi.c | 30 ++++-- hw/misc/riscv_rpmi_hsm.c | 15 +++ hw/misc/riscv_rpmi_internal.h | 8 +- hw/misc/riscv_rpmi_syssusp.c | 198 ++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 5 + include/hw/misc/riscv_rpmi.h | 9 ++ 7 files changed, 259 insertions(+), 8 deletions(-) create mode 100644 hw/misc/riscv_rpmi_syssusp.c diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 6d93cd4ab0..1dc7aa7c67 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -188,3 +188,5 @@ system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [file= s( 'riscv_rpmi_sysreset.c', 'riscv_rpmi_hsm.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) +specific_ss.add(when: 'CONFIG_RISCV_RPMI', + if_true: [files('riscv_rpmi_syssusp.c'), librpmi]) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 1bf9d77b04..56a092e49e 100644 --- a/hw/misc/riscv_rpmi.c +++ b/hw/misc/riscv_rpmi.c @@ -214,6 +214,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 @@ -256,6 +260,7 @@ static void riscv_rpmi_init(Object *obj) static void riscv_rpmi_reset_hold(Object *obj, ResetType type) { RiscvRpmiState *s =3D RISCV_RPMI(obj); + bool reset_syssusp =3D s->syssusp_group !=3D NULL; =20 s->doorbell =3D 0; =20 @@ -263,9 +268,15 @@ static void riscv_rpmi_reset_hold(Object *obj, ResetTy= pe type) memset(memory_region_get_ram_ptr(&s->shmem), 0, s->shmem_size); memory_region_set_dirty(&s->shmem, 0, s->shmem_size); } + if (reset_syssusp) { + riscv_rpmi_syssusp_remove(s); + } if (!riscv_rpmi_hsm_reset(s, &error_abort)) { return; } + if (reset_syssusp && !riscv_rpmi_syssusp_add(s, &error_abort)) { + return; + } } =20 static void riscv_rpmi_cleanup(RiscvRpmiState *s) @@ -309,13 +320,6 @@ bool riscv_rpmi_service_enabled(RiscvRpmiState *s, return false; } =20 -void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s) -{ - if (s->context) { - rpmi_context_process_a2p_request(s->context); - } -} - bool riscv_rpmi_context_add_group(RiscvRpmiState *s, struct rpmi_service_group *group, const char *name, @@ -340,6 +344,18 @@ void riscv_rpmi_context_remove_group(RiscvRpmiState *s, } } =20 +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s) +{ + if (s->context) { + rpmi_context_process_a2p_request(s->context); + if (s->syssusp_event_pending && s->syssusp_group) { + s->syssusp_event_pending =3D false; + rpmi_context_process_group_events(s->context, + RPMI_SRVGRP_SYSTEM_SUSPEND); + } + } +} + static bool riscv_rpmi_validate_config(RiscvRpmiState *s, Error **errp) { uint64_t queue_bytes; diff --git a/hw/misc/riscv_rpmi_hsm.c b/hw/misc/riscv_rpmi_hsm.c index 42a4f3b096..08e78e1ee7 100644 --- a/hw/misc/riscv_rpmi_hsm.c +++ b/hw/misc/riscv_rpmi_hsm.c @@ -42,6 +42,7 @@ static RiscvRpmiHsmHart *riscv_rpmi_hsm_hart(RiscvRpmiSta= te *s, =20 return &s->hsm_harts[hart_index]; } + static void riscv_rpmi_hsm_wfi(CPUState *cpu, bool entering, void *opaque) { RiscvRpmiHsmHart *hart =3D opaque; @@ -342,3 +343,17 @@ bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **e= rrp) s->hsm_group =3D group; return true; } + +void riscv_rpmi_hsm_resume(RiscvRpmiState *s, uint32_t hart_index, + uint64_t resume_addr) +{ + RiscvRpmiHsmHart *hart =3D riscv_rpmi_hsm_hart(s, hart_index); + + if (!hart) { + return; + } + + hart->start_addr =3D resume_addr; + run_on_cpu(hart->cpu, riscv_rpmi_hsm_start_cpu, + RUN_ON_CPU_HOST_PTR(hart)); +} diff --git a/hw/misc/riscv_rpmi_internal.h b/hw/misc/riscv_rpmi_internal.h index e56dba5b1a..8739c3f041 100644 --- a/hw/misc/riscv_rpmi_internal.h +++ b/hw/misc/riscv_rpmi_internal.h @@ -20,18 +20,24 @@ extern const struct rpmi_shmem_platform_ops rpmi_shmem_qemu_ops; bool riscv_rpmi_service_enabled(RiscvRpmiState *s, enum rpmi_servicegroup_id service_group); -void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); bool riscv_rpmi_context_add_group(RiscvRpmiState *s, struct rpmi_service_group *group, const char *name, Error **errp); void riscv_rpmi_context_remove_group(RiscvRpmiState *s, struct rpmi_service_group *group); +void riscv_rpmi_context_process_a2p_request(RiscvRpmiState *s); + bool riscv_rpmi_sysreset_add(RiscvRpmiState *s, Error **errp); void riscv_rpmi_sysreset_remove(RiscvRpmiState *s); =20 bool riscv_rpmi_hsm_add(RiscvRpmiState *s, Error **errp); void riscv_rpmi_hsm_remove(RiscvRpmiState *s); bool riscv_rpmi_hsm_reset(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_hsm_resume(RiscvRpmiState *s, uint32_t hart_index, + uint64_t resume_addr); + +bool riscv_rpmi_syssusp_add(RiscvRpmiState *s, Error **errp); +void riscv_rpmi_syssusp_remove(RiscvRpmiState *s); =20 #endif diff --git a/hw/misc/riscv_rpmi_syssusp.c b/hw/misc/riscv_rpmi_syssusp.c new file mode 100644 index 0000000000..d70536a27a --- /dev/null +++ b/hw/misc/riscv_rpmi_syssusp.c @@ -0,0 +1,198 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI System Suspend service. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "riscv_rpmi_internal.h" +#include "system/address-spaces.h" +#include "system/memory.h" +#include "qemu/timer.h" +#include "system/cpus.h" +#include "system/runstate.h" +#include "target/riscv/cpu.h" + +static const struct rpmi_system_suspend_type riscv_rpmi_syssusp_types[] = =3D { + { + .type =3D RPMI_SYSSUSP_TYPE_SUSPEND_TO_RAM, + .attr =3D RPMI_SYSSUSP_ATTRS_FLAGS_RESUMEADDR, + }, +}; + +static enum rpmi_error riscv_rpmi_syssusp_prepare( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_system_suspend_type *syssusp_type, + rpmi_uint64_t resume_addr) +{ + RiscvRpmiState *s =3D priv; + RISCVCPU *cpu =3D RISCV_CPU(cpu_by_arch_id(s->hart_ids[hart_index])); + unsigned int alignment =3D ((cpu->env.misa_ext_mask & RVC) || + cpu->cfg.ext_zca) ? 2 : 4; + MemoryRegionSection section; + + if ((resume_addr & (alignment - 1)) || + (cpu->env.misa_mxl =3D=3D MXL_RV32 && resume_addr > UINT32_MAX)) { + return RPMI_ERR_INVALID_ADDR; + } + + section =3D memory_region_find(get_system_memory(), resume_addr, 1); + if (!section.mr || !memory_region_is_ram(section.mr) || + memory_region_is_rom(section.mr)) { + if (section.mr) { + memory_region_unref(section.mr); + } + return RPMI_ERR_INVALID_ADDR; + } + memory_region_unref(section.mr); + + /* The accepted request needs one targeted event pass to finalize it. = */ + s->syssusp_event_pending =3D true; + return RPMI_SUCCESS; +} + +static rpmi_bool_t riscv_rpmi_syssusp_ready(void *priv, + rpmi_uint32_t hart_index) +{ + return true; +} + +static void riscv_rpmi_syssusp_finalize( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_system_suspend_type *syssusp_type, + rpmi_uint64_t resume_addr) +{ + qemu_system_suspend_request(); +} + +static rpmi_bool_t riscv_rpmi_syssusp_can_resume(void *priv, + rpmi_uint32_t hart_index) +{ + return runstate_check(RUN_STATE_RUNNING); +} + +static enum rpmi_error riscv_rpmi_syssusp_resume( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_system_suspend_type *syssusp_type, + rpmi_uint64_t resume_addr) +{ + RiscvRpmiState *s =3D priv; + + s->syssusp_resume_hart_index =3D hart_index; + s->syssusp_resume_addr =3D resume_addr; + s->syssusp_resume_pending =3D true; + return RPMI_SUCCESS; +} + +static const struct rpmi_syssusp_platform_ops riscv_rpmi_syssusp_ops =3D { + .system_suspend_prepare =3D riscv_rpmi_syssusp_prepare, + .system_suspend_ready =3D riscv_rpmi_syssusp_ready, + .system_suspend_finalize =3D riscv_rpmi_syssusp_finalize, + .system_suspend_can_resume =3D riscv_rpmi_syssusp_can_resume, + .system_suspend_resume =3D riscv_rpmi_syssusp_resume, +}; + +static void riscv_rpmi_wakeup_timer(void *opaque) +{ + RiscvRpmiState *s =3D opaque; + + if (s->syssusp_resume_pending) { + riscv_rpmi_hsm_resume(s, s->syssusp_resume_hart_index, + s->syssusp_resume_addr); + s->syssusp_resume_pending =3D false; + s->syssusp_resume_addr =3D 0; + } +} + +static void riscv_rpmi_wakeup_notify(Notifier *notifier, void *data) +{ + RiscvRpmiState *s =3D container_of(notifier, RiscvRpmiState, + wakeup_notifier); + + rpmi_context_process_group_events(s->context, + RPMI_SRVGRP_SYSTEM_SUSPEND); + /* + * Wakeup notifiers run before vCPUs resume. Defer the HSM kick so + * OpenSBI can leave WFI after QEMU restarts execution. + */ + timer_mod(s->wakeup_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 10= ); +} + +static bool riscv_rpmi_syssusp_create(RiscvRpmiState *s, + struct rpmi_service_group **group, + Error **errp) +{ + if (!s->hsm) { + error_setg(errp, "RPMI system suspend service requires HSM service= "); + return false; + } + + *group =3D rpmi_service_group_syssusp_create( + s->hsm, ARRAY_SIZE(riscv_rpmi_syssusp_types), + riscv_rpmi_syssusp_types, &riscv_rpmi_syssusp_ops, s); + if (!*group) { + error_setg(errp, "failed to create RPMI system suspend service gro= up"); + return false; + } + + qemu_register_wakeup_support(); + s->wakeup_timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, + riscv_rpmi_wakeup_timer, s); + s->wakeup_notifier.notify =3D riscv_rpmi_wakeup_notify; + qemu_register_wakeup_notifier(&s->wakeup_notifier); + return true; +} + +static void riscv_rpmi_syssusp_destroy(RiscvRpmiState *s) +{ + notifier_remove(&s->wakeup_notifier); + timer_free(s->wakeup_timer); + s->wakeup_timer =3D NULL; + + s->syssusp_event_pending =3D false; + s->syssusp_resume_pending =3D false; + s->syssusp_resume_hart_index =3D 0; + s->syssusp_resume_addr =3D 0; + + if (s->syssusp_group) { + rpmi_service_group_syssusp_destroy(s->syssusp_group); + s->syssusp_group =3D NULL; + } +} + +bool riscv_rpmi_syssusp_add(RiscvRpmiState *s, Error **errp) +{ + struct rpmi_service_group *group; + + if (s->syssusp_group) { + error_setg(errp, "duplicate RPMI system suspend descriptor"); + return false; + } + + if (!riscv_rpmi_syssusp_create(s, &group, errp)) { + return false; + } + + if (!riscv_rpmi_context_add_group(s, group, "system suspend", errp)) { + s->syssusp_group =3D group; + riscv_rpmi_syssusp_destroy(s); + return false; + } + + s->syssusp_group =3D group; + return true; +} + +void riscv_rpmi_syssusp_remove(RiscvRpmiState *s) +{ + if (!s->syssusp_group) { + return; + } + + riscv_rpmi_context_remove_group(s, s->syssusp_group); + riscv_rpmi_syssusp_destroy(s); +} diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 32aa13325e..53a31d1abd 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -490,6 +490,11 @@ static const RiscvRpmiServiceConfig virt_rpmi_services= [] =3D { .compatible =3D "riscv,rpmi-hsm", .service_group =3D RPMI_SRVGRP_HSM, }, + { + .node_name =3D "suspend", + .compatible =3D "riscv,rpmi-system-suspend", + .service_group =3D RPMI_SRVGRP_SYSTEM_SUSPEND, + }, }; =20 static uint32_t virt_rpmi_service_count(void) diff --git a/include/hw/misc/riscv_rpmi.h b/include/hw/misc/riscv_rpmi.h index 3a240941cd..3aaaaf68ae 100644 --- a/include/hw/misc/riscv_rpmi.h +++ b/include/hw/misc/riscv_rpmi.h @@ -13,6 +13,8 @@ =20 #include "exec/hwaddr.h" #include "hw/core/sysbus.h" +#include "qemu/notify.h" +#include "qemu/timer.h" #include "qom/object.h" =20 #ifdef CONFIG_LIBRPMI @@ -84,9 +86,16 @@ struct RiscvRpmiState { char *platform_info; const RiscvRpmiMachineOps *machine_ops; struct rpmi_service_group *sysreset_group; + struct rpmi_service_group *syssusp_group; struct rpmi_hsm *hsm; struct rpmi_service_group *hsm_group; RiscvRpmiHsmHart *hsm_harts; + bool syssusp_event_pending; + Notifier wakeup_notifier; + QEMUTimer *wakeup_timer; + bool syssusp_resume_pending; + uint32_t syssusp_resume_hart_index; + uint64_t syssusp_resume_addr; uint32_t *hart_ids; uint32_t hart_count; const RiscvRpmiServiceConfig *services; From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768849; cv=none; d=zohomail.com; s=zohoarc; b=OmCBRXZn9LwiDrrNQ5M/KkXDUULqL2RI8Z3mkgjUZSJzfcStbgep72hlhIL+cQoAW5oNGE/gjmAfsGok/L9qLZBLOAMedOU44h3AivXySPUL/gmolxYBsWyDA8pprIlPp5b3K1Y/MckYZPEmRf4ynQsy/DXkqpIplVo+EKJjspY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768849; 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=a0vBc4PLM8JtpS9+9S5hjW80mO0/TB0W4hbgh1tAwX0=; b=HExJgjFUrJkk2u27kVlS909tZpUIjNVYlLfbjQbvAekOEDXKBbW1DpcYacoZoarN6ZPnGuB/mT8MBb3isoKO6i7wly7my84GeT6s3BDII76cgOeBFdSE6Va8GGUHaWLAm3jE3TgkTzjLYT/VaTurXR6Az507VmtYLHZw4UyRM9w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179376884958760.00421556364347; Tue, 3 Nov 2026 21:07:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTD3-0005Q5-FP; Wed, 04 Nov 2026 00:06:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCt-0005KP-VZ for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:47 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCq-0002ES-CM for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:42 -0500 Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40RIUo3460027 for ; Wed, 4 Nov 2026 05:06:29 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 4hqh2bubpc-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:28 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-36c98e5ad40so49512eec.0 for ; Tue, 03 Nov 2026 21:06:28 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=a0vBc4PLM8J tpS9+9S5hjW80mO0/TB0W4hbgh1tAwX0=; b=R39xx0n4QkJCwrCHYuOEeS2XIiZ HwltcuZlxJ82qMUUIWFmq2olm1WWTwMv216SA79PNDfvfDK5JHeYP4rpwd+2M8pG qW/yKN0xyxwRt1kCpUU1htx1182cGvhRyfyM/l3pey2bNILpQoCvv5hU5UoSNnhs uMWAO4nl+vjf8ct78a76WoSaCSJY1uZ2RwHnn70IO23L6x67ygSM8o62nN/3PvBX Zdfjh36JnO5RjIYF2k1C00+SqAIiXL9NpzWugnyidlone4Zxgq/peqV/bmZtQIJQ oTJO5DsFGO2kWx05Eh31cq4XNlNcsDgNUEpOoRZDI3aL98yhPF+DQ9DYOHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768788; x=1794373588; 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=a0vBc4PLM8JtpS9+9S5hjW80mO0/TB0W4hbgh1tAwX0=; b=gIi2dfz5z/216iVQQRR7oJIRycvh+GxGHRM0ZHsKfYTpvdpl/puLvhZLm2LN5A+LCx z3aKtxE71q8/zNZakxncqwZ3ssy1P8HwYB1VhR05ewBuFzPGyfpps2cP67VTqg1PyTq9 qbdih8zkSizazUHGolbXbIof363UbLMSjSZzjt0SD9aMp8dD2RGdDfkwgkSdP0/NbpGo oJu+etG0pgUhiXCMFLvCwsAbo9JD6heTqgJF1zt5PmUm+YEe3cZAXaT+Tcke1EWVXomE 84S7jP0Qn+fH5paTImUi5onAo0o9tcV5yXD/ZFKJHEsCvvCnBijmrP389GgrdBp5qdn4 zTBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768788; x=1794373588; 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=a0vBc4PLM8JtpS9+9S5hjW80mO0/TB0W4hbgh1tAwX0=; b=XDhUi69VsM7lqtlqsHPmcwVl7ZaQbnX6x0nwF1rNS9iIdgrI0gQO9J025JQrAqwAjg bcIacmb1v2ogC1jLz5lkKou3OUmo3UsKFH5fCBiYBuSqGG0tvlpmnyO1+IhM6EWDhUvI e3+5ANhswCOjSVXSGcM2QMVvc4ORyJI/B1S1/lubDD63VciNOzZKFb6J7x3y3HsoQrov G9OG0fkHYRm46zWmXcQFmvfr7yanREBXGvGVpGM8bmiGQ6rwaVtYnzwRdj/SjA4dBCGl +B8NXzW02oO6zTyux1zexfucxiLZs6UtvuojkU0lFaUNwdTksa1aNjUYOLGV9FpOqv5a g3Ww== X-Gm-Message-State: APuU4Z97teRYOqk7caqd/i3FnJ19SFVybZNKT6y7riM8e0AkuO1Z9yji aPAENt7ygaogQO5KLMhydkdqHqx7HjGi7rg9NAYuKn6dvUdlCK796d1UkFRcb9L+6kfxbgxHsTq G30TutQEO9UuJP07OHMyl7CSN+YX9no8V6b21UmX4DLshYbENjiEMyZrf7qbjB6deDg== X-Gm-Gg: AYBFou2TuZItCguXhOGuqm+hEroO4d54393jd5L4IrVUfcuKow/yjlJSL8evR5SAwZO e9jSD5iUidWq38LNbB1N65zlIpXEJJQuGmgvQsNxh4QrvxGahrMS59jMFjtAosrrzE3NlroCk0S VCVOjaMFuuEzv/x4zVoSKNfWtLlbMnQdsS2FrL6q5VempjkKRLqVWUlP6BD8vxJKAmTIDfZ3oYd iInLNDBskDvF+Pl9SxiSvYlAgjkp5UcGocFkziNUVKygk2jcp4Aq2iJHqzqNM7PZb1jkVQt5bEQ cmc7s35VtURoeFFYMtuypxhXcWAMXAQS7uGjfbBuau4ds3FJv2GRAEyWt0hgdJwE5eL6uChobWv Ik/kqv3d5OOAEAEO2BMHYxk70aVu24mHrHxsjDvGQysKyT+RMgxDORVaGS0sDvPRX/vjp5q/pyG z1MmYb4rvN1lNeSdM1Kfvx7IZcx77ijBklVPaNjLwtdzM4MXJDYMuJBzIrHmZOsB5sG+WLhrbOl egHNkT+ X-Received: by 2002:a05:7300:d082:b0:369:ffc5:6767 with SMTP id 5a478bee46e88-36a4236a643mr29518563eec.2.1793768787885; Tue, 03 Nov 2026 21:06:27 -0800 (PST) X-Received: by 2002:a05:7300:d082:b0:369:ffc5:6767 with SMTP id 5a478bee46e88-36a4236a643mr29518526eec.2.1793768787247; Tue, 03 Nov 2026 21:06:27 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Pierrick Bouvier Subject: [PATCH v14 08/10] docs/system/riscv: document initial virt RPMI support Date: Wed, 4 Nov 2026 10:33:21 +0530 Message-ID: <20261104050324.733555-9-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX5GEkVA4b9OOK 5l1MDVc+vZRuxg75pUGc1rkgP05wPQrh95ucr+f6C5Ooq00JUdZsBuw2eAHE3pirezXFTXeruY4 MOACIusb0plhsqg62VpH4Nar3FJv6Ls= X-Authority-Analysis: v=2.4 cv=AKV9GsJK c=1 sm=1 tr=0 ts=6aeabd54 cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=YMgV9FUhrdKAYTUUvYB2:22 a=NEAV23lmAAAA:8 a=V1jnuoLLAAAA:20 a=EUspDBNiAAAA:8 a=bNRx8rSjxjkR0t5bZ0UA:9 a=bBxd6f-gb0O0v-kibOvt:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-ORIG-GUID: gXfNjbtIUM4eFYzllHYKTS2heJ2X6sar X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX4XtZlAgYD+51 mjTtV5Q+WN+o1Ys0dDPBHyGIUJGW0qMSgpN0+ezxcR9eLbrHVljcCa7P+drFXdT6kHK4uU2u+vO TPo2bf9V3jNMRNPLA5lYb67T2GEOYunWerDbAFAIY24C2bQ3NKX+T3sv1zIoBcWLlt7vW84byLC GBOOyVYAPt5WMh7q3JarTzuyiqM1qUzCnoe/+5DNFWjSjWqZFC+oFu6ZNBVq5bHU9kvjlAooHaQ ZpqTrMz3qPYU6QKeq0M/ooprKcfJTRJWu8coq3clbU/Oyf97nER7oTkBF55Qm+ynzbxBi8pxL/n T+QORyn2oyLzSpL66XCSElnxABYvuNOtaTd33biG4bEn5f3tZ2YtSWa3+SZulVbCkpvDWiUh+yN sTQCaPlJQ2L4psyR5ci3ZhtAlo441Ym2YJHbRXav8tnemBrRBhUxqxijGhriSnzPvwi9Rf1lhGs Q0ATVhcniR/cQT78u1w== X-Proofpoint-GUID: gXfNjbtIUM4eFYzllHYKTS2heJ2X6sar X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0 impostorscore=0 phishscore=0 spamscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768851247158500 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 | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst index 3c87246891..7835913e16 100644 --- a/docs/system/riscv/virt.rst +++ b/docs/system/riscv/virt.rst @@ -149,6 +149,85 @@ 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. + Running Linux kernel -------------------- From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768850; cv=none; d=zohomail.com; s=zohoarc; b=Q1ohuNZk1EpTX02QtrbxS6MWti4qKf/Qqz1ICUHQzo22dB2Z6PKvNmmaEfrfzoKtWKlrmeVZyN1bO+az/BmAvZapCaILh0UvDhTGydiRIwB+CZItiS2fC70dBv01uBAS29d6u1U6BQVUpCbZZrJGBTvE1bcw7IydJ8AQgHZBEv4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768850; 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=EXE9Tm7D9EMHmyZuVKtxKJ9b4ApRm+QuTNL4BU9W/Nk=; b=I4vbxZlqG23DEayOtflhQevm+XoZ8hKA97klPTrixqITS5x89IOq36NmVMVQTpizpjGB8Xvnptf+RfSongm8DYIY5L3x1vReW7zz1Xv8us2xP21440OmLFQvG48vFWQYfMOY4eJ9rRHohOCbcYq9I3cFs2ral0tVNqE0o90UErk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768850324290.4606680848101; Tue, 3 Nov 2026 21:07:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTDC-0005pJ-P8; Wed, 04 Nov 2026 00:07:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTD3-0005T6-NX for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:54 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCv-0002Ey-PV for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:50 -0500 Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40RFQa1248584 for ; Wed, 4 Nov 2026 05:06:34 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 4hqpuv9kxx-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:34 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-313c7315becso40038eec.2 for ; Tue, 03 Nov 2026 21:06:34 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=EXE9Tm7D9EM HmyZuVKtxKJ9b4ApRm+QuTNL4BU9W/Nk=; b=VSaie74bflQrGp1uKzIFy/kWmdt s3f36mua8F3tIEzOzLuE0VKP4yKSsipSFDsPVcBSoq4xgkhxWVrQ7a0h5U91SQ2F /wn9LX6xo+MHEX2FnK+eYOBEzy6pvsNOMAuMe2OpymNY7IqESxu1DXhzULiwVfZx KUbMpqPx386eShg9/98xHRk/cnaegWjAZ/GpF3CwItJ8d3+/hh3XXA9Nd0f2cM33 rXCUxfY5FicPCYbIsxRuoQ8c+CMbPfij1hmOsUpHg3r/9P3ry+IoptFa7PMJ41a0 fLyaRvtmxsgzp1l1tu9HQ/xVFwjvbny9ej5l2qdUeRM4tmQq6KucuRHiTpA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768794; x=1794373594; 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=EXE9Tm7D9EMHmyZuVKtxKJ9b4ApRm+QuTNL4BU9W/Nk=; b=juhB06hZEgWT4N05wiZ+Da/STY/LRM208LAppY4ryMdGNAwZSI2CXA2fs1yMIhfsEj +rN2Cb9S/OpdK+T95vMlxCALr3oT9ZRAdkccj7RaW1KpR/NuaUQGzKDKSbNTZcYmLNa0 ZgI9wzBwSD2ImoCbAhbBQ/pAfWgJkaFlX+gbc8b1NmPCPJ30lq6YHCwRNusr6kGUkaoS tFmgaMMZq4EM5aQ8CRFmkbj/AkbD4fo+u1MbMgSCGfcEdIm9pHwIgbM25nF+7+dOaH+O rLhrGqjFXTSkTULjOv3SMfUv/k9L7VvhLJZNf9VYrmcvRFskW0UfYkJu3cmeVNkaFjBP f9tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768794; x=1794373594; 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=EXE9Tm7D9EMHmyZuVKtxKJ9b4ApRm+QuTNL4BU9W/Nk=; b=t6DfwD1hT6F3kPA/6HoIDSS9FZMAhFZ0N/reux+CAwizl0CuWlKx+uGAw0p13e5rkX xvoiaNKrJl5gUznaegFYdB8HlwHGSkvw9qt/yb6dSLdQxa5wpObM3N8wxIPvEijfNO+3 gkGOG4smAByUFxjD5s/PU0bcVzWhOS6Fy7NDC+V2RIw4BssCptcuey1VSXnn0+V5mpih ONPQSopsjbfdknHr1cuuk2Eina2FDnrhtyVMyqbpG/uCYnlURVS7rCwat4gG4HIRzOJl apfxnTMxfg4gcm681RyEBwqDWGR2j5VUAFE+f0HNAvdBSvkXRijwEsES8rb2QYhJL9SL 787Q== X-Gm-Message-State: APuU4Z/7cbIaa7T1Uc8KiOK0F8Xgnwfriif+e4hVbMhdFZtg9fonz7s8 hhKA39JxkpyjJUM1Js5aPd1jiIYy++CtPNX7X4eoKoWcE1WdgfyhwlzHQvSJgV08ifshStZdp3x gxy2wujTpkdRju4B1I9OxFNVNya7DpnH6UVS5CFhvxnA4n1zRNtgc4hsdIzsarNZLbA== X-Gm-Gg: AYBFou0JF+vOAK3B1fqVriUp+7b4H0+1MUKCkyWPjDLZ1DYQWMwuyp5/MTuazQvuxWF D5XrkgjJFY2Dt8jYSqH3lyrZDdXumFWU5ylFZXWPI7IiaRMYfM/LJFZoFEe/tUdBetbuKphoGme HFPo9WDHZ98K6e4K3zHdVekjZJ1aRYzkDIUdEecK+HHEfCJgFk7nGY5HQviCitZlkOhQ9MZgfaQ OFR87++Ca8PvMR+N3anFGhU482RF574FvIxmebGbl4xeCRpPEw1NESPAJc441MKXZfu8LxuI16F H7onZLz/BOgEJ+0sFnbDtHT/r6OOjbLueQgEMG9/DWPba6kBqoKfR5E41JaZqtmWsZDNgrSAcss zleJhX9EAEnGb/fuwedkBHvJT6XbUQXHs+Z4jyS4RiS3dyxZ5tM0e+aVcC2UVggK9TbfX6ZxY63 sqz2ch0j62ey8w5YwO/faDgJ5mUsK0krMQQmXtMErFtTs6j2+S1fPzxN1Luh5f6lwu7Vth1fDVn arDihRu X-Received: by 2002:a05:7300:fb14:b0:351:7883:bf47 with SMTP id 5a478bee46e88-36a41daec1emr31162541eec.0.1793768792814; Tue, 03 Nov 2026 21:06:32 -0800 (PST) X-Received: by 2002:a05:7300:fb14:b0:351:7883:bf47 with SMTP id 5a478bee46e88-36a41daec1emr31162457eec.0.1793768791809; Tue, 03 Nov 2026 21:06:31 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Fabiano Rosas , Laurent Vivier , Paolo Bonzini , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v14 09/10] tests/qtest: cover initial RISC-V RPMI services Date: Wed, 4 Nov 2026 10:33:22 +0530 Message-ID: <20261104050324.733555-10-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=O6SsLx9W c=1 sm=1 tr=0 ts=6aeabd5a cx=c_pps a=Uww141gWH0fZj/3QKPojxA==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=Um2Pa8k9VHT-vaBCBUpS:22 a=EUspDBNiAAAA:8 a=tDkw8OHjEmLI60v_eaAA:9 a=PxkB5W3o20Ba91AHUih5:22 X-Proofpoint-ORIG-GUID: HxRMuNBasBicxGBi_nxvjic_BA8ALbmq X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX5JtW9ghEPdWK XMD9r7yUrVJla1yiF2FmWBmSrAbFguh4EKweuyjhDYFgJG0H15LnK/MZ5jo5XPYbyhLyichxzlT 1/IygmyPNd1b3QXWZ86duTl02jsTiNk= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX5ulY2HK9+7Hc zYGnOdc2X31GLY3UBQX3rLSymci315wF3JYbwN/MwpXbai6XWEPScn3lPviteifJ1gERJrVx3oR DcET8Y0rdZQwUbwaj9PEPsf/Cqmb1nY2qb7BbAQRHsR/m6zfDZ74NO9XHlEUaH6cZJCttsFTdbJ HSUrQZNR+1O56W9FLuRqkd7SEbpVin5Dc2pqoZDjrSI1CHiPRWs0kcFRfH2MzabdN6pBnzWskdD wvVsOVqkFKqUsz9lWSiwyYil5CrZeYIW11OcUvP5NOvD5WuEWhmdnU0xldOkqfxzyyEYr2oBRxy BFFkvd0CjoVDtjUyUDdhbS6rIRCjONw8UdQy2XFEB4sKbJM6TsFMEAF3XKLDvFXRro1b4fOflKJ sOAX7XMpfdCbl5l84gHo4KVwrFks6pB84l8GNKO97C+Y9KiNKoskzdXhfSTirRR66382i04Yh57 3F+VW5oQ39gxh5hWuGA== X-Proofpoint-GUID: HxRMuNBasBicxGBi_nxvjic_BA8ALbmq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 impostorscore=0 clxscore=1015 spamscore=0 suspectscore=0 priorityscore=1501 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768851208158500 Content-Type: text/plain; charset="utf-8" Add qtests for the RPMI transport plus Base, system reset, HSM, and system suspend service groups. The qtest accelerator does not execute a target hart to WFI, so check that stop and suspend remain pending rather than treating the request as immediately complete. Verify that HART_START is denied while stop is pending and that machine reset returns pending HSM state to STARTED before accepting fresh stop and suspend requests. Check System Suspend resume-address rejection without a suspend event or runstate change. Cover instruction alignment with and without compressed instructions, MMIO and unmapped addresses, RAM-backed addresses, RV32 width rejection for mapped RAM above 4 GiB, and recovery after rejection/reset. Check the enlarged virt queue ranges in the DT and exercise queue-boundary rejection and wraparound at the last data slot. Signed-off-by: Subrahmanya Lingappa --- MAINTAINERS | 1 + tests/qtest/meson.build | 3 + tests/qtest/riscv-rpmi-test.c | 759 ++++++++++++++++++++++++++++++++++ 3 files changed, 763 insertions(+) create mode 100644 tests/qtest/riscv-rpmi-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 7f7764b03b..5e56f4eec5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -381,6 +381,7 @@ F: hw/riscv/ F: hw/intc/riscv* F: hw/misc/riscv_rpmi* F: include/hw/misc/riscv_rpmi.h +F: tests/qtest/riscv-rpmi-test.c F: include/hw/char/riscv_htif.h F: include/hw/riscv/ F: common-user/host/riscv* diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index ff4bf9528a..207766bcf6 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -317,6 +317,8 @@ qtests_riscv32 =3D \ =20 qtests_riscv64 =3D ['riscv-csr-test'] + \ (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RISCV_RPMI') ? + ['riscv-rpmi-test'] : []) + \ (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and config_all_devices.has_key('CONFIG_RISCV_IOMMU') ? ['iommu-riscv-test'] : []) + \ @@ -442,6 +444,7 @@ qtests =3D { 'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c', 'pnv-xive2-nvpg_bar.c'), 'qos-test': [chardev, io, qos_test_ss.apply({}).sources()], + 'riscv-rpmi-test': [files('riscv-rpmi-test.c'), fdt], 'tpm-crb-swtpm-test': [io, tpmemu_files], 'tpm-crb-test': [io, tpmemu_files], 'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'], diff --git a/tests/qtest/riscv-rpmi-test.c b/tests/qtest/riscv-rpmi-test.c new file mode 100644 index 0000000000..318c66b426 --- /dev/null +++ b/tests/qtest/riscv-rpmi-test.c @@ -0,0 +1,759 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * QTests for RISC-V RPMI devices. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include +#include +#include "libqtest.h" +#include "qobject/qdict.h" + +#define RPMI_SHMEM_BASE 0x10200000ULL +#define RPMI_DOORBELL_BASE 0x10230000ULL +#define RPMI_SLOT_SIZE 64 +#define RPMI_QUEUE_SIZE 0x7800 +#define RPMI_QUEUE_DATA_SLOTS (RPMI_QUEUE_SIZE / RPMI_SLOT_SIZE - 2) + +#define RPMI_A2P_HEAD RPMI_SHMEM_BASE +#define RPMI_A2P_TAIL (RPMI_SHMEM_BASE + RPMI_SLOT_SIZE) +#define RPMI_A2P_SLOT0 (RPMI_SHMEM_BASE + 2 * RPMI_SLOT_SIZE) + +#define RPMI_SRVGRP_BASE 0x0001 +#define RPMI_SRVGRP_SYSTEM_RESET 0x0003 +#define RPMI_SRVGRP_SYSTEM_SUSPEND 0x0004 +#define RPMI_SRVGRP_HSM 0x0005 +#define RPMI_BASE_SRV_GET_PLATFORM_INFO 0x05 +#define RPMI_BASE_SRV_PROBE_SERVICE_GROUP 0x06 +#define RPMI_SYSRST_SRV_GET_ATTRIBUTES 0x02 +#define RPMI_SYSRST_SRV_SYSTEM_RESET 0x03 +#define RPMI_HSM_SRV_GET_HART_STATUS 0x02 +#define RPMI_HSM_SRV_GET_HART_LIST 0x03 +#define RPMI_HSM_SRV_GET_SUSPEND_TYPES 0x04 +#define RPMI_HSM_SRV_GET_SUSPEND_INFO 0x05 +#define RPMI_HSM_SRV_HART_START 0x06 +#define RPMI_HSM_SRV_HART_STOP 0x07 +#define RPMI_HSM_SRV_HART_SUSPEND 0x08 +#define RPMI_SYSSUSP_SRV_GET_ATTRIBUTES 0x02 +#define RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND 0x03 +#define RPMI_MSG_NORMAL_REQUEST 0x00 +#define RPMI_MSG_POSTED_REQUEST 0x01 +#define RPMI_MSG_ACKNOWLEDGEMENT 0x02 +#define RPMI_SYSRST_TYPE_SHUTDOWN 0x00 +#define RPMI_SYSRST_TYPE_COLD_REBOOT 0x01 +#define RPMI_SYSRST_TYPE_INVALID 0x03 +#define RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE 1 +#define RPMI_TOKEN 0x55aa +#define RPMI_ERR_NOTSUPP 0xfffffffeU +#define RPMI_ERR_INVALID_PARAM 0xfffffffdU +#define RPMI_ERR_INVALID_ADDR 0xfffffffbU +#define RPMI_ERR_DENIED 0xfffffffcU +#define RPMI_HSM_HART_STATE_STARTED 0x00 +#define RPMI_HSM_HART_STATE_STOPPED 0x01 +#define RPMI_HSM_HART_STATE_STOP_PENDING 0x03 +#define RPMI_HSM_HART_STATE_SUSPENDED 0x04 +#define RPMI_HSM_HART_STATE_SUSPEND_PENDING 0x05 +#define RPMI_HSM_TEST_START_ADDR 0x80000000ULL +#define RPMI_HSM_TEST_RESUME_ADDR 0x80001000ULL + +#define RPMI_P2A_ACK_BASE (RPMI_SHMEM_BASE + RPMI_QUEUE_SIZE) +#define RPMI_P2A_ACK_HEAD RPMI_P2A_ACK_BASE +#define RPMI_P2A_ACK_TAIL (RPMI_P2A_ACK_BASE + RPMI_SLOT_SIZE) + +static uint64_t rpmi_response_base; + +static uint64_t rpmi_queue_slot(uint64_t queue_base, uint32_t index) +{ + return queue_base + (index + 2) * RPMI_SLOT_SIZE; +} + +static void rpmi_send_request(QTestState *qts, uint16_t service_group, + uint8_t service_id, uint8_t request_type, + const uint32_t *data, size_t data_words) +{ + uint32_t tail =3D qtest_readl(qts, RPMI_A2P_TAIL); + uint64_t slot =3D rpmi_queue_slot(RPMI_SHMEM_BASE, tail); + size_t i; + + qtest_writew(qts, slot, service_group); + qtest_writeb(qts, slot + 2, service_id); + qtest_writeb(qts, slot + 3, request_type); + qtest_writew(qts, slot + 4, data_words * sizeof(*data)); + qtest_writew(qts, slot + 6, RPMI_TOKEN); + + for (i =3D 0; i < data_words; i++) { + qtest_writel(qts, slot + 8 + i * sizeof(*data), data[i]); + } + + g_test_message( + "RPMI_A2P_REQ shmem=3D0x%016" PRIx64 " doorbell=3D0x%016" PRIx64 + " group=3D0x%04x service=3D0x%02x type=3D0x%02x data_len=3D%zu" + " token=3D0x%04x a2p_tail=3D%u slot=3D0x%016" PRIx64, + (uint64_t)RPMI_SHMEM_BASE, (uint64_t)RPMI_DOORBELL_BASE, + service_group, service_id, request_type, data_words * sizeof(*data= ), + RPMI_TOKEN, tail, slot); + + qtest_writel(qts, RPMI_A2P_TAIL, (tail + 1) % RPMI_QUEUE_DATA_SLOTS); + qtest_writel(qts, RPMI_DOORBELL_BASE, 1); +} + +static uint32_t rpmi_response_word(QTestState *qts, unsigned int word) +{ + return qtest_readl(qts, rpmi_response_base + 8 + word * sizeof(uint32_= t)); +} + +static void test_rpmi_virt_fdt_service_nodes(void) +{ + static const struct { + const char *name; + uint32_t service_group; + } services[] =3D { + { "sysreset", RPMI_SRVGRP_SYSTEM_RESET }, + { "hsm", RPMI_SRVGRP_HSM }, + { "suspend", RPMI_SRVGRP_SYSTEM_SUSPEND }, + }; + g_autofree char *dtb_path =3D NULL; + g_autofree char *dtb =3D NULL; + gsize dtb_size; + const fdt32_t *prop; + int mailbox_offset; + int phandle_len; + uint32_t mailbox_phandle; + 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, "reg", &phandle_len); + g_assert_nonnull(prop); + g_assert_cmpint(phandle_len, >=3D, 8 * sizeof(*prop)); + for (unsigned int queue =3D 0; queue < 2; queue++) { + g_assert_cmphex(fdt32_to_cpu(prop[4 * queue + 1]), =3D=3D, + RPMI_SHMEM_BASE + queue * RPMI_QUEUE_SIZE); + g_assert_cmphex(fdt32_to_cpu(prop[4 * queue + 3]), =3D=3D, RPMI_QU= EUE_SIZE); + } + prop =3D fdt_getprop(dtb, mailbox_offset, "phandle", &phandle_len); + g_assert_nonnull(prop); + g_assert_cmpint(phandle_len, =3D=3D, sizeof(*prop)); + mailbox_phandle =3D fdt32_to_cpu(*prop); + + for (size_t i =3D 0; i < ARRAY_SIZE(services); i++) { + g_autofree char *service_path =3D + g_strdup_printf("/soc/%s", services[i].name); + int service_offset =3D fdt_path_offset(dtb, service_path); + int child_offset =3D fdt_subnode_offset(dtb, mailbox_offset, + services[i].name); + int mboxes_len; + + g_assert_cmpint(service_offset, >=3D, 0); + g_assert_cmpint(child_offset, =3D=3D, -FDT_ERR_NOTFOUND); + prop =3D fdt_getprop(dtb, service_offset, "mboxes", &mboxes_len); + g_assert_nonnull(prop); + g_assert_cmpint(mboxes_len, =3D=3D, 2 * sizeof(*prop)); + g_assert_cmphex(fdt32_to_cpu(prop[0]), =3D=3D, mailbox_phandle); + g_assert_cmphex(fdt32_to_cpu(prop[1]), =3D=3D, + services[i].service_group); + } + + 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) % RPMI_QUEUE_DATA_SLOT= S); +} + +static void rpmi_send_sysreset(QTestState *qts, uint32_t reset_type, + uint8_t request_type) +{ + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_SYSTEM_RESET, request_type, + &reset_type, 1); +} + +static void rpmi_expect_qemu_failure(const char *extra_args, + const char *stderr_needle) +{ + g_autoptr(GError) error =3D NULL; + g_auto(GStrv) split_args =3D NULL; + g_autoptr(GPtrArray) argv =3D g_ptr_array_new(); + g_autofree char *stderr_data =3D NULL; + gint wait_status; + gboolean spawned; + + g_assert_true(g_shell_parse_argv(extra_args, NULL, &split_args, &error= )); + g_assert_no_error(error); + + g_ptr_array_add(argv, (gpointer)qtest_qemu_binary(NULL)); + for (char **arg =3D split_args; *arg; arg++) { + g_ptr_array_add(argv, *arg); + } + g_ptr_array_add(argv, NULL); + + spawned =3D g_spawn_sync(NULL, (char **)argv->pdata, NULL, + G_SPAWN_STDOUT_TO_DEV_NULL, + NULL, NULL, NULL, &stderr_data, + &wait_status, &error); + g_assert_true(spawned); + g_assert_no_error(error); + g_assert_true(!WIFEXITED(wait_status) || + WEXITSTATUS(wait_status) !=3D EXIT_SUCCESS); + g_assert_nonnull(stderr_data); + g_assert_nonnull(strstr(stderr_data, stderr_needle)); +} + +static void test_rpmi_machine_realize_off(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Doff"); + qtest_quit(qts); +} + +static void test_rpmi_machine_rejects_too_many_harts(void) +{ + rpmi_expect_qemu_failure( + "-machine virt,rpmi=3Don -smp 513 -display none -S", + "max CPUs supported by machine 'virt' is 512"); +} + +static void test_rpmi_base_platform_info(void) +{ + static const char expected[] =3D "QEMU RISC-V virt RPMI"; + QTestState *qts; + size_t i; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_request(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_GET_PLATFORM_INFO, + RPMI_MSG_NORMAL_REQUEST, NULL, 0); + + rpmi_expect_ack(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_GET_PLATFORM_INFO, + 2 * sizeof(uint32_t) + sizeof(expected)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, sizeof(expected)); + for (i =3D 0; i < sizeof(expected); i++) { + g_assert_cmphex(qtest_readb(qts, rpmi_response_base + 16 + i), =3D= =3D, + expected[i]); + } + + qtest_quit(qts); +} + +static void rpmi_probe_group(QTestState *qts, uint32_t service_group, + bool present) +{ + rpmi_send_request(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_PROBE_SERVICE_GROUP, + RPMI_MSG_NORMAL_REQUEST, &service_group, 1); + + rpmi_expect_ack(qts, RPMI_SRVGRP_BASE, + RPMI_BASE_SRV_PROBE_SERVICE_GROUP, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + if (present) { + g_assert_cmphex(rpmi_response_word(qts, 1), !=3D, 0); + } else { + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 0); + } +} + +static void test_rpmi_base_probe_service_groups(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don,aia=3Daplic-imsic"); + rpmi_probe_group(qts, RPMI_SRVGRP_BASE, true); + qtest_system_reset(qts); + rpmi_probe_group(qts, RPMI_SRVGRP_SYSTEM_RESET, true); + qtest_system_reset(qts); + rpmi_probe_group(qts, RPMI_SRVGRP_HSM, true); + qtest_system_reset(qts); + rpmi_probe_group(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, true); + + qtest_quit(qts); +} + +static void test_rpmi_sysreset_attrs(void) +{ + static const struct { + uint32_t reset_type; + uint32_t expected_attrs; + } cases[] =3D { + { RPMI_SYSRST_TYPE_SHUTDOWN, RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE }, + { RPMI_SYSRST_TYPE_COLD_REBOOT, RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE = }, + { RPMI_SYSRST_TYPE_INVALID, 0 }, + }; + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + for (size_t i =3D 0; i < ARRAY_SIZE(cases); i++) { + if (i) { + qtest_system_reset(qts); + } + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + RPMI_MSG_NORMAL_REQUEST, &cases[i].reset_type, 1= ); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, + cases[i].expected_attrs); + } + + qtest_quit(qts); +} + +static void test_rpmi_sysreset_shutdown(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_SHUTDOWN, + RPMI_MSG_POSTED_REQUEST); + qtest_qmp_eventwait(qts, "SHUTDOWN"); + qtest_quit(qts); +} + +static void test_rpmi_sysreset_cold_reboot(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don -no-reboot"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_COLD_REBOOT, + RPMI_MSG_POSTED_REQUEST); + qtest_qmp_eventwait(qts, "SHUTDOWN"); + qtest_quit(qts); +} + +static void test_rpmi_sysreset_invalid_type(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_INVALID, + RPMI_MSG_NORMAL_REQUEST); + + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_SYSTEM_RESET, sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, + RPMI_ERR_INVALID_PARAM); + + qtest_quit(qts); +} + +static void test_rpmi_repeated_reset_after_traffic(void) +{ + QTestState *qts; + uint32_t reset_type =3D RPMI_SYSRST_TYPE_SHUTDOWN; + + qts =3D qtest_init("-machine virt,rpmi=3Don,aia=3Daplic-imsic"); + for (uint32_t i =3D 0; i < 5; i++) { + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + RPMI_MSG_NORMAL_REQUEST, + &reset_type, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_GET_ATTRIBUTES, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + qtest_system_reset(qts); + } + qtest_quit(qts); +} + +static void test_rpmi_reset_clears_transport(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + rpmi_send_sysreset(qts, RPMI_SYSRST_TYPE_INVALID, + RPMI_MSG_NORMAL_REQUEST); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_SYSTEM_RESET, sizeof(uint32_t)); + + qtest_system_reset(qts); + + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_TAIL), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_DOORBELL_BASE), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_rpmi_doorbell_invalid_access(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + qtest_writeb(qts, RPMI_DOORBELL_BASE, 1); + qtest_writel(qts, RPMI_DOORBELL_BASE + 4, 1); + g_assert_cmphex(qtest_readl(qts, RPMI_DOORBELL_BASE), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_rpmi_queue_bounds(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don"); + qtest_writel(qts, RPMI_A2P_TAIL, RPMI_QUEUE_DATA_SLOTS); + qtest_writel(qts, RPMI_DOORBELL_BASE, 1); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + + qtest_system_reset(qts); + qtest_writel(qts, RPMI_A2P_HEAD, RPMI_QUEUE_DATA_SLOTS - 1); + qtest_writel(qts, RPMI_A2P_TAIL, RPMI_QUEUE_DATA_SLOTS - 1); + qtest_writel(qts, RPMI_P2A_ACK_HEAD, RPMI_QUEUE_DATA_SLOTS - 1); + qtest_writel(qts, RPMI_P2A_ACK_TAIL, RPMI_QUEUE_DATA_SLOTS - 1); + rpmi_probe_group(qts, RPMI_SRVGRP_BASE, true); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_TAIL), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_rpmi_migration_blocked(void) +{ + QTestState *qts; + QDict *error; + const char *desc; + + qts =3D qtest_init("-machine virt,rpmi=3Don -S"); + error =3D qtest_qmp_assert_failure_ref(qts, + "{ 'execute': 'migrate'," + " 'arguments': { 'uri': 'exec:cat > /dev/null' } }"); + desc =3D qdict_get_try_str(error, "desc"); + + g_assert_nonnull(desc); + g_assert_nonnull(strstr(desc, "non-migratable device")); + g_assert_nonnull(strstr(desc, "riscv-rpmi")); + + qobject_unref(error); + qtest_quit(qts); +} + +static void rpmi_expect_hsm_hart_list(QTestState *qts) +{ + uint32_t start_index =3D 0; + + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_LIST, + RPMI_MSG_NORMAL_REQUEST, &start_index, 1); + + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_LIST, + 7 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 2), =3D=3D, 4); + g_assert_cmphex(rpmi_response_word(qts, 3), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 4), =3D=3D, 1); + g_assert_cmphex(rpmi_response_word(qts, 5), =3D=3D, 2); + g_assert_cmphex(rpmi_response_word(qts, 6), =3D=3D, 3); +} + +static void test_rpmi_hsm_hart_list(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 4"); + rpmi_expect_hsm_hart_list(qts); + + qtest_quit(qts); +} + +static void test_rpmi_hsm_multi_socket_hart_list(void) +{ + QTestState *qts; + + qts =3D qtest_init("-machine virt,rpmi=3Don " + "-smp 4,sockets=3D2,cores=3D2,threads=3D1"); + rpmi_expect_hsm_hart_list(qts); + + qtest_quit(qts); +} + +static void test_rpmi_hsm_hart_status(void) +{ + QTestState *qts; + uint32_t hart_id =3D 3; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 4"); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + RPMI_MSG_NORMAL_REQUEST, &hart_id, 1); + + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, + RPMI_HSM_HART_STATE_STARTED); + + qtest_quit(qts); +} + +static void rpmi_expect_hsm_status(QTestState *qts, uint32_t hart_id, + uint32_t expected_state) +{ + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + RPMI_MSG_NORMAL_REQUEST, &hart_id, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_HART_STATUS, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, expected_state); +} + +static void test_rpmi_hsm_hart_control(void) +{ + QTestState *qts; + uint32_t hart_id =3D 1; + uint32_t stop_request[] =3D { hart_id }; + uint32_t start_request[] =3D { hart_id, RPMI_HSM_TEST_START_ADDR, 0 }; + uint32_t suspend_request[] =3D { hart_id, 0, RPMI_HSM_TEST_RESUME_ADDR= , 0 }; + uint32_t start_index =3D 0; + uint32_t suspend_type =3D 0; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 2"); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_TYPES, + RPMI_MSG_NORMAL_REQUEST, &start_index, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_TYPES, + 4 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 2), =3D=3D, 1); + g_assert_cmphex(rpmi_response_word(qts, 3), =3D=3D, 0); + + qtest_system_reset(qts); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_INFO, + RPMI_MSG_NORMAL_REQUEST, &suspend_type, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_GET_SUSPEND_INFO, + 6 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + + qtest_system_reset(qts); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + RPMI_MSG_NORMAL_REQUEST, stop_request, + ARRAY_SIZE(stop_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + /* The qtest accelerator never runs the target hart to its next WFI. */ + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STOP_PENDING); + + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_START, + RPMI_MSG_NORMAL_REQUEST, start_request, + ARRAY_SIZE(start_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_START, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, RPMI_ERR_DENIED); + + qtest_system_reset(qts); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STARTED); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + RPMI_MSG_NORMAL_REQUEST, stop_request, + ARRAY_SIZE(stop_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_STOP, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STOP_PENDING); + + qtest_quit(qts); + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 2"); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, suspend_request, + ARRAY_SIZE(suspend_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + /* The qtest accelerator does not execute the target hart to WFI. */ + rpmi_expect_hsm_status(qts, hart_id, + RPMI_HSM_HART_STATE_SUSPEND_PENDING); + + qtest_system_reset(qts); + rpmi_expect_hsm_status(qts, hart_id, RPMI_HSM_HART_STATE_STARTED); + rpmi_send_request(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, suspend_request, + ARRAY_SIZE(suspend_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_HSM, RPMI_HSM_SRV_HART_SUSPEND, + sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + rpmi_expect_hsm_status(qts, hart_id, + RPMI_HSM_HART_STATE_SUSPEND_PENDING); + + qtest_quit(qts); +} + +static void test_rpmi_syssusp_attrs_and_suspend(void) +{ + QTestState *qts; + uint32_t suspend_type =3D 0; + uint32_t suspend_request[] =3D { 0, 0, 0x80000000, 0 }; + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 1"); + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_GET_ATTRIBUTES, + RPMI_MSG_NORMAL_REQUEST, &suspend_type, 1); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_GET_ATTRIBUTES, + 2 * sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + g_assert_cmphex(rpmi_response_word(qts, 1), =3D=3D, 3); + + qtest_system_reset(qts); + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, suspend_request, + ARRAY_SIZE(suspend_request)); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, 0); + qtest_qmp_eventwait(qts, "SUSPEND"); + qtest_qmp_assert_success(qts, "{ 'execute': 'system_wakeup' }"); + qtest_qmp_eventwait(qts, "WAKEUP"); + + qtest_quit(qts); +} + +static void rpmi_expect_syssusp_address(QTestState *qts, uint64_t address, + uint32_t status) +{ + uint32_t request[] =3D { 0, 0, address, address >> 32 }; + QDict *response; + + g_test_message("System Suspend resume address: 0x%016" PRIx64, address= ); + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, + RPMI_MSG_NORMAL_REQUEST, request, ARRAY_SIZE(request= )); + rpmi_expect_ack(qts, RPMI_SRVGRP_SYSTEM_SUSPEND, + RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND, sizeof(uint32_t)); + g_assert_cmphex(rpmi_response_word(qts, 0), =3D=3D, status); + if (status =3D=3D 0) { + qtest_qmp_eventwait(qts, "SUSPEND"); + qtest_qmp_assert_success(qts, "{ 'execute': 'system_wakeup' }"); + qtest_qmp_eventwait(qts, "WAKEUP"); + } else { + /* query-status drains earlier events before checking for SUSPEND.= */ + response =3D qtest_qmp(qts, "{ 'execute': 'query-status' }"); + g_assert_cmpstr(qdict_get_str(qdict_get_qdict(response, "return"), + "status"), =3D=3D, "running"); + qobject_unref(response); + response =3D qtest_qmp_event_ref(qts, "SUSPEND"); + g_assert_null(response); + } +} + +static void test_rpmi_syssusp_resume_address(void) +{ + const uint64_t high_ram_addr =3D 0x100000000ULL; + QTestState *qts =3D qtest_init("-machine virt,rpmi=3Don -smp 1 -m 128M= " + "-cpu sifive-u54"); + + rpmi_expect_syssusp_address(qts, 0x80000001, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_address(qts, 0x10000000, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_address(qts, 0x88000000, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_address(qts, 0x80000002, 0); + qtest_system_reset(qts); + rpmi_expect_syssusp_address(qts, 0x80000000, 0); + qtest_quit(qts); + + qts =3D qtest_init("-machine virt,rpmi=3Don -smp 1 -m 3G -cpu rv32i"); + qtest_writeb(qts, high_ram_addr, 0x5a); + g_assert_cmphex(qtest_readb(qts, high_ram_addr), =3D=3D, 0x5a); + rpmi_expect_syssusp_address(qts, 0x80000002, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_address(qts, high_ram_addr, RPMI_ERR_INVALID_ADDR); + rpmi_expect_syssusp_address(qts, 0x80000000, 0); + 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/syssusp/resume-address", + test_rpmi_syssusp_resume_address); + qtest_add_func("/riscv/rpmi/fdt/service-nodes", + test_rpmi_virt_fdt_service_nodes); + qtest_add_func("/riscv/rpmi/machine/realize-off", + test_rpmi_machine_realize_off); + qtest_add_func("/riscv/rpmi/machine/rejects-too-many-harts", + test_rpmi_machine_rejects_too_many_harts); + qtest_add_func("/riscv/rpmi/base/platform-info", + test_rpmi_base_platform_info); + qtest_add_func("/riscv/rpmi/base/probe-service-groups", + test_rpmi_base_probe_service_groups); + qtest_add_func("/riscv/rpmi/sysreset/attrs", + test_rpmi_sysreset_attrs); + qtest_add_func("/riscv/rpmi/sysreset/shutdown", + test_rpmi_sysreset_shutdown); + qtest_add_func("/riscv/rpmi/sysreset/cold-reboot", + test_rpmi_sysreset_cold_reboot); + qtest_add_func("/riscv/rpmi/sysreset/invalid-type", + test_rpmi_sysreset_invalid_type); + qtest_add_func("/riscv/rpmi/reset/clears-transport", + test_rpmi_reset_clears_transport); + qtest_add_func("/riscv/rpmi/negative/doorbell-invalid-access", + test_rpmi_doorbell_invalid_access); + qtest_add_func("/riscv/rpmi/negative/queue-bounds", + test_rpmi_queue_bounds); + qtest_add_func("/riscv/rpmi/reset/repeated-after-traffic", + test_rpmi_repeated_reset_after_traffic); + qtest_add_func("/riscv/rpmi/migration/blocked", + test_rpmi_migration_blocked); + qtest_add_func("/riscv/rpmi/hsm/hart-list", + test_rpmi_hsm_hart_list); + qtest_add_func("/riscv/rpmi/hsm/multi-socket-hart-list", + test_rpmi_hsm_multi_socket_hart_list); + qtest_add_func("/riscv/rpmi/hsm/hart-status", + test_rpmi_hsm_hart_status); + qtest_add_func("/riscv/rpmi/hsm/hart-control", + test_rpmi_hsm_hart_control); + qtest_add_func("/riscv/rpmi/syssusp/attrs-and-suspend", + test_rpmi_syssusp_attrs_and_suspend); + } + + return g_test_run(); +} From nobody Mon Nov 23 04:28:01 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793768953; cv=none; d=zohomail.com; s=zohoarc; b=M0qTKjbL2Spkd6USbxeuW9fnVnCKECF+FtGND5LRzsKCadRyCz3JnNlw6kUgsjYZSExBA636FPJnd6jRrjX9sjPF2XXmY37iG4Lckhr7Zn2KReMvff8HwMum0RS+fjqdF9N0hC6cTdsuvM4vIbkxWztYbyNAs4cbCC5cfO0VhzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793768953; 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=dSL6nfK1EWQYD69SBse0aWzzU/cjJiK6qtAlh0W5j0c=; b=W3pUaxKsV/kBkd+X9v2mRtIyvScGnwjWjh+ClnMmVtzfk7lpxWZQzZqJOoq0pUdGiekrrgihtJlfDDDJioMXo0luEOXKd4YxZI/EQ60rplC1d8WEaA4JDtzqLGXh8dW17rAFF+udFLol3/MlcC0fVbfD3d8a1GbmHEMTGWSEAaE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793768953545828.5015233314202; Tue, 3 Nov 2026 21:09:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xOTDA-0005et-KF; Wed, 04 Nov 2026 00:07:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTD3-0005T7-NN for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:54 -0500 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xOTCy-0002Fb-Nb for qemu-devel@nongnu.org; Wed, 04 Nov 2026 00:06:51 -0500 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A40Rlf83867864 for ; Wed, 4 Nov 2026 05:06:37 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 4hqn8y206j-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 04 Nov 2026 05:06:37 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-35d7e79abedso25143eec.3 for ; Tue, 03 Nov 2026 21:06:37 -0800 (PST) Received: from hu-slingapp-blr.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com. [103.229.18.19]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-36ca390df28sm3925036eec.18.2026.11.03.21.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2026 21:06:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=dSL6nfK1EWQ YD69SBse0aWzzU/cjJiK6qtAlh0W5j0c=; b=IbxOi1Q/Sytu1JMLZ7uWU/G8G67 ig5XAhH6chG0YPPoMSyORUhcHQ9hHPqujpsL43H8H1JzPAsh8BW5JJbBXP8fd2dF Xzv+EQftoSwC7SkvInfMDDtDHJF98fl8p6aAhiCfngMZoi7P42hCiTa7P3d05s1d VweT7NPNf5+ICSPTIuAgTzQcyJY8ZxWGl7SFwhsEG1QaFgk8CZYEABxwRPLbxe9r n0pqa0Y0WwpcJ7ScC5q2BtTtH3PoIiAjM9vg4Cs+0i3NK9P5hd0MhLSPlzk1Q1vz pCO9Xe+IeqtxLG0G/SYUooqFWoTeZgaDymGlS7T+BGwa/KKhn64+LQwIRfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793768796; x=1794373596; 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=dSL6nfK1EWQYD69SBse0aWzzU/cjJiK6qtAlh0W5j0c=; b=fugmv1RVsKjHAlavjT1t5Apf139gKkiqtGk2Ssl+YxdbGhLTdRjStZhWq2NFbohdhh gTcOirTrFWnUzEAIrU6wrnX08yboOUF+eStNogTrxbDe1fVGvGeUF2/tlXAB1eWGTIEr w+4zXYs0NG7g0ArRzR3q5ZFz/FXBGwN7d3wb+GXEFQrKOUqVVndlQwcEpcPsmtCUG1c7 +/eOCXS9GC6kCQqycCgKDLjW6InxW836tg91g+FavDtn7udJ7TYO7FBkii/l88b7OK/r TNIUvvw2DU4mQhTlXxvwY+tWTKIEyGWxEjdcwjw80SUdjJ1TK+Dmetgv7KhYAzANnlVK wy4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793768796; x=1794373596; 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=dSL6nfK1EWQYD69SBse0aWzzU/cjJiK6qtAlh0W5j0c=; b=f2zkWRY3+Y1bItXwiFcDTuMFKvBX0PlNYxtd7YaEgb8LZawTuBOYEW2Az3VKKGpj2v Yn5AizUiPBRG3OpOIencw7uP1KHxKZSBek6Jic52uwkQmWEMramXuaYlQGeDdqXEyYbm /P/vXxnmPUxQ7N7r/mS/wo0vpe+sIZbTwHaRiE5jGWmiO+I5CFmdb6nUu/prMOQ5GaNQ Wz4iMILfba+MDWNXsKsasnZaAAUh12aGyWePVVPkrnEC2MOo+s9Okdr5GZDtDKkhFqit JcBoUZZXl0g5X/zzYywTQkVBLifffs7hZ2/dHeQ1x9CEd4D5qhvq17KslxdIJz0WFL/a Zvag== X-Gm-Message-State: APuU4Z8Mwt7EQQeajyE1gDZ1RhzirBe7V20unBYcNVXQXw5tqyLS6i8d gyUfeekO5T9tu62VRVVPRKk1Iia/RY6sc4h+SgG2Ui9Y/XSYrid2OL5cy1HX5F+H9++PDUn4lyQ pfRcHo++pKg+gF1LnDBosW+sf1mw77p3PjZ0Lkpc3oqkkgJi/4TbzNR5vCyHCAfXhZw== X-Gm-Gg: AYBFou3o2sRUh6brN8qOpjo+LNlMmHJo0wHl9XZaYFmXFOTiuwvYJ1xx99kzhJZFIcz 6vZFpHxEWNFmILL1bGrBNvU6natdXvnHhT7civRY06/nEBgkPiZC5EG6v1RKOPQH7a2AclDVdpj 1GX0OX9so9MxGYTzoZjeUM6dz7DbtUG2nXQlsrdQdMDzOYTDOfqjACHPLDtmpbeqDvsP2VyQxvY WbgKxDg6FY8vgx+ViPfNd0fAvajAi7PaXsRE0lNxG8LmRrOQkWx420vpStG/oCBMjLui2DYMpqa i4yShaRHoZ3hbc6gJ/0yvGYkW2QmKH1k3JWvAmPgnoslGNiyCSa0EY/nB3cRcIr+dP6CgY3A0jp j9ncE9oy4oVqDP0fg5ORJ87YY5CyZsbXqwKNW1DcYREFnN0P0xnZe7Qdy5whawIgP96hrvnkDaq hZf0gLwPywCamp93ipYTDMX2ccllG8fh+0+oXrt8oYnZU1fixOq8u3HDEJQpW9EywLDrw3VZJVi 5MriDay X-Received: by 2002:a05:7300:ae18:b0:36a:13fd:b5c with SMTP id 5a478bee46e88-36a4235ceddmr31093778eec.2.1793768796156; Tue, 03 Nov 2026 21:06:36 -0800 (PST) X-Received: by 2002:a05:7300:ae18:b0:36a:13fd:b5c with SMTP id 5a478bee46e88-36a4235ceddmr31093732eec.2.1793768795525; Tue, 03 Nov 2026 21:06:35 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v14 10/10] tests/functional: add initial RPMI virt guest smoke Date: Wed, 4 Nov 2026 10:33:23 +0530 Message-ID: <20261104050324.733555-11-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261104050324.733555-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: 5bmJ3XPZDLHD_TlJuuXmdW-XTHt-2Ae6 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfXw6jTyI0N579W iyuCRCvmsT8yclzDLEGuVulOhCLDME1YihKvzf1Em9MInWyQYaPx1xtUDz4K3UU46tnB//S511i zhWZu5t/LIe7XTbUrVzLZl6+i7axDoO0zBXpXhFUdHIIH9gO5MAEtGiXgajJ//Z7QkwC70UNlR7 c08GW+CoQ1N2V//SkIo9lBquUpAvBPV3saqkRhLacLkfyeIpjsmSLpn1uq3VdL6356YeI2hxUoN sH6MIgMPKs+mnboj7awbfVPJuE8M2kOD35/ohQlXGktBLZnh0xBNbjiG+nXRBsFDZKpLowP2tCU kbEFUSNVQROKNGW+tVxFFnnC1SYsHxivmJ0vFaQUBkB/NF0UKg298SrzpfvbN8us+8EjUSOlDrV ZkKCNmXdhxswHO1i26F20jmAnK3mrRIWaztT+mP22ocdGg3ir5VLHzJC+8+WY53iaPgE2V6sKqz 2NDQZmdQPm9eZeI58AQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTA0MDAyMCBTYWx0ZWRfX5jaXjXpiQoWs IFlnV5Wds8YxeRhivskl0ZW6eLG7+fCbUG1h3aAp1deaCkO/jWyO5Cwd9f0zk6EYN8Xnv/R41Lm 9U5uWAep6DZvG9u+H3J/JKRuGlOPJAg= X-Proofpoint-ORIG-GUID: 5bmJ3XPZDLHD_TlJuuXmdW-XTHt-2Ae6 X-Authority-Analysis: v=2.4 cv=NP5AaE6g c=1 sm=1 tr=0 ts=6aeabd5d cx=c_pps a=PfFC4Oe2JQzmKTvty2cRDw==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_K5XuSEh1TEqbUxoQ0s3:22 a=EUspDBNiAAAA:8 a=lsuYGQq57gzD3Ej6WjEA:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-04_01,2026-11-03_04,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 lowpriorityscore=0 malwarescore=0 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611040020 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: 1793768955423158500 Content-Type: text/plain; charset="utf-8" Boot an RPMI-enabled RISC-V virt guest and exercise the initial HSM, system suspend, and system reset paths. Require completed CPU offline and online transitions for HSM stop/start, repeat the cycle, and stop a hart running a busy workload. Reboot while a secondary hart remains stopped, verify the next boot restores both harts, and repeat HSM control afterward. Also cover HSM stop/start immediately after suspend/wakeup and a fresh suspend cycle after reboot. Reject definitive OpenSBI HSM failure diagnostics instead of accepting a shell marker that only appeared in the echoed command. Linux can report CPU death before firmware reaches STOPPED. Bound retries of the subsequent online request, retain transient errors in the console, and require a completed online transition rather than assuming that an offline sysfs mask proves immediate firmware stop completion. Signed-off-by: Subrahmanya Lingappa --- tests/functional/riscv64/meson.build | 2 + tests/functional/riscv64/test_rpmi_virt.py | 268 +++++++++++++++++++++ 2 files changed, 270 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..1e098e8b33 --- /dev/null +++ b/tests/functional/riscv64/test_rpmi_virt.py @@ -0,0 +1,268 @@ +#!/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 + + @staticmethod + def _marker(marker): + """Build a marker without putting the complete token in echoed inp= ut.""" + prefix, suffix =3D marker.rsplit('_', 1) + return "printf '%%s_%%s\\n' %s %s" % (prefix, suffix) + + def _assert_no_hsm_stop_failure(self, output): + # OpenSBI may report STOP_PENDING before its state reaches STOPPED. + # CPU offline and a successful later HART_START prove the cycle. + for diagnostic in ( + 'ERR: Failed stop hart', 'Unable to stop the cpu', + 'RPMI_ERR_DENIED'): + self.assertNotIn(diagnostic.encode(), output, + 'OpenSBI reported an HSM stop failure: ' + f'{diagnostic}') + + def _validate_hsm_boot_start(self, online_cpus): + self._run_marker_command( + 'echo RPMI_LINUX_HSM_START_BEGIN; ' + 'cat /sys/devices/system/cpu/present; ' + 'online=3D$(cat /sys/devices/system/cpu/online); ' + 'echo "$online"; ' + f'if [ "$online" =3D "{online_cpus}" ]; ' + f'then {self._marker("RPMI_LINUX_HSM_START_PASS")}; ' + f'else {self._marker("RPMI_LINUX_HSM_START_FAIL")}; fi', + 'RPMI_LINUX_HSM_START_PASS', 'RPMI_LINUX_HSM_START_FAIL') + + def _validate_fdt_service_layout(self): + self._run_marker_command( + 'base=3D/sys/firmware/devicetree/base/soc; ' + 'if [ -d "$base/sysreset" ] && ' + '[ -d "$base/hsm" ] && [ -d "$base/suspend" ] && ' + '[ ! -d "$base/mailbox@10200000/sysreset" ] && ' + '[ ! -d "$base/mailbox@10200000/hsm" ] && ' + '[ ! -d "$base/mailbox@10200000/suspend" ]; then ' + f'{self._marker("RPMI_FDT_SERVICE_SIBLINGS_PASS")}; ' + f'else {self._marker("RPMI_FDT_SERVICE_SIBLINGS_FAIL")}; fi', + 'RPMI_FDT_SERVICE_SIBLINGS_PASS', + 'RPMI_FDT_SERVICE_SIBLINGS_FAIL') + + def _validate_hsm_stop_start(self): + command =3D ( + 'echo RPMI_LINUX_HSM_STOP_BEGIN; ' + 'if [ -w /sys/devices/system/cpu/cpu1/online ]; then ' + 'echo 0 > /sys/devices/system/cpu/cpu1/online && ' + '[ "$(cat /sys/devices/system/cpu/online)" =3D 0 ] && ' + f'{self._marker("RPMI_LINUX_HSM_STOP_PASS")} && ' + # Linux reports CPU death before firmware has necessarily stop= ped + # the hart. Preserve transient start errors, but bound the wai= t. + '(attempt=3D0; until echo 1 > /sys/devices/system/cpu/cpu1/onl= ine; ' + 'do attempt=3D$((attempt + 1)); ' + 'printf "HSM start retry %s\\n" "$attempt"; ' + '[ "$attempt" -lt 50 ] || exit 1; sleep 0.1; done) && ' + '[ "$(cat /sys/devices/system/cpu/online)" =3D 0-1 ] && ' + f'{self._marker("RPMI_LINUX_HSM_START_PASS")} || ' + f'{self._marker("RPMI_LINUX_HSM_STOP_FAIL")}; ' + f'else {self._marker("RPMI_LINUX_HSM_STOP_FAIL")}; fi; ' + 'sleep 1; ' + f'{self._marker("RPMI_LINUX_HSM_STOP_DONE")}') + out =3D exec_command_and_wait_for_pattern( + self, command, 'RPMI_LINUX_HSM_STOP_DONE', + failure_message=3D'RPMI_LINUX_HSM_STOP_FAIL') + self.assertIn(b'RPMI_LINUX_HSM_STOP_PASS', out) + self.assertIn(b'RPMI_LINUX_HSM_START_PASS', out) + self._assert_no_hsm_stop_failure(out) + + def _validate_hsm_stop(self): + command =3D ( + 'echo RPMI_LINUX_HSM_STOP_BEGIN; ' + 'if [ -w /sys/devices/system/cpu/cpu1/online ] && ' + 'echo 0 > /sys/devices/system/cpu/cpu1/online && ' + 'sleep 1 && ' + '[ "$(cat /sys/devices/system/cpu/online)" =3D 0 ]; then ' + f'{self._marker("RPMI_LINUX_HSM_STOP_PASS")}; ' + f'else {self._marker("RPMI_LINUX_HSM_STOP_FAIL")}; fi') + out =3D exec_command_and_wait_for_pattern( + self, command, 'RPMI_LINUX_HSM_STOP_PASS', + failure_message=3D'RPMI_LINUX_HSM_STOP_FAIL') + self._assert_no_hsm_stop_failure(out) + + def _validate_system_suspend(self): + exec_command( + self, + 'echo RPMI_LINUX_SUSPEND_BEGIN; ' + 'if grep -qw mem /sys/power/state; then ' + 'echo mem > /sys/power/state; ' + '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') + # The resumed shell prompt and suspend-exit message can share a li= ne. + # Send an empty command so the console always produces a fresh pro= mpt. + exec_command_and_wait_for_pattern(self, '', self.PROMPT) + self._run_marker_command( + 'marker=3DRPMI_LINUX_WAKEUP; echo ${marker}_PASS', + 'RPMI_LINUX_WAKEUP_PASS') + + def _validate_reset_poweroff(self): + exec_command(self, 'echo RPMI_LINUX_RESET_POWEROFF_BEGIN; poweroff= -f') + wait_for_console_pattern(self, 'RPMI_LINUX_RESET_POWEROFF_BEGIN') + wait_for_console_pattern(self, 'reboot: Power down') + self.vm.wait() + + def _validate_reset_reboot(self): + exec_command(self, 'echo RPMI_LINUX_RESET_REBOOT_BEGIN; reboot -f') + wait_for_console_pattern(self, 'RPMI_LINUX_RESET_REBOOT_BEGIN') + wait_for_console_pattern(self, 'reboot: Restarting system') + wait_for_console_pattern(self, 'OpenSBI') + + def test_linux_guest_service_enumeration(self): + self._boot_guest(smp=3D4) + self._expect_rpmi_firmware_and_linux() + self._validate_fdt_service_layout() + self._validate_hsm_boot_start('0-3') + + def test_linux_guest_hsm_stop(self): + self._boot_guest(smp=3D2) + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0-1') + for _ in range(3): + self._validate_hsm_stop_start() + exec_command( + self, + "taskset -c 1 sh -c 'while :; do :; done' & echo $! > " + "/tmp/rpmi-hsm-worker") + time.sleep(0.1) + self._validate_hsm_stop_start() + exec_command(self, 'kill $(cat /tmp/rpmi-hsm-worker) 2>/dev/null |= | :') + + def test_linux_guest_hsm_stopped_reset(self): + self._boot_guest(smp=3D2) + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0-1') + self._validate_hsm_stop() + self._validate_reset_reboot() + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0-1') + self._validate_hsm_stop_start() + + def test_linux_guest_suspend(self): + self._boot_guest(smp=3D2) + self._expect_rpmi_firmware_and_linux() + self._validate_system_suspend() + self._validate_hsm_stop_start() + + def test_linux_guest_reset_poweroff(self): + self._boot_guest(smp=3D1) + self._expect_rpmi_firmware_and_linux() + self._validate_reset_poweroff() + + def test_linux_guest_reset_reboot(self): + self._boot_guest(smp=3D1) + self._expect_rpmi_firmware_and_linux() + self._validate_reset_reboot() + self._expect_rpmi_firmware_and_linux() + self._validate_hsm_boot_start('0') + self._validate_system_suspend() + + +if __name__ =3D=3D '__main__': + QemuSystemTest.main()