From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608399; cv=none; d=zohomail.com; s=zohoarc; b=VBm0JZQbFJ8tniLQPvwyqfZueyFXzdk7Bu+umeb5qbyVayXAvWCHVKfLsKeipiV8Xg6G0bMXv7BLpk8m5CuP0Hc9hMb9QVpcLbhIr9n3OefrHzyGH/yK8OCqGYujyBKPSsJsfcRsnRb9aAa8avC+JftNpBRbYG2GiR/um8ZlHcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608399; 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=yduADB2OpVCwll9flVD3mKkXGUD6xulVEqJm2BB22+E=; b=PqjXxcAgC3bfYPiDo2vEbaubYDf9jerJTQfyZrJYrpVQnx2nnTBdX/TxBBl04V5zDRD4Rr0+jLxooDMqbW44oymgfWb2lyWMhdc12OumbxeUllDSXpb+rrhbBcKMEFjZbfRV8toKKscpD5ymYBc97rXzG4D8B83FsQqXNft6YHA= 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 1793608399214356.4434215678565; Mon, 2 Nov 2026 00:33:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnTT-0002tk-BW; Mon, 02 Nov 2026 03:33: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 1xNnSm-0002m3-Kd for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:22 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNnSi-0004nc-M4 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:20 -0500 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A23vFpP2753354 for ; Mon, 2 Nov 2026 08:32:14 GMT Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hpg201djc-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:14 +0000 (GMT) Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-7cc081f3066so101502137.1 for ; Mon, 02 Nov 2026 00:32: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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:11 -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= yduADB2OpVCwll9flVD3mKkXGUD6xulVEqJm2BB22+E=; b=b6KUZmvp6+ekfFfH Sl5MV2WkTbYWsC2Fn934OffPjHOhLYspiVlq7iYYWXHDK6oPSOhlYFkxKF1XoQfv B9VptfhUkxeDbEUAOKD3Rec863unOU+iCwJVVZHbS31MOvCBkXCF+pGWC5eGjyyo vkTLNsyc5kqSbYbZlgyzAkyEOkFr0f4qKlBObzQ73tqoqGIbvy0jeaXa9BlwGcJL qi0K91XF/sEDLY5OFJuJiaQOVx988adhwffRbAqCLCAfjwGhlvpxPhCX1j94t++0 yNAPCLWtIdoNdfaxPWCDKv+QGqdGAy1cEimT6o/Oc0RYKjSwFi0AlYzSMQTOJBLu d8/r0A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608332; x=1794213132; 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=yduADB2OpVCwll9flVD3mKkXGUD6xulVEqJm2BB22+E=; b=CrmX4g4aikxs4oFfDyi4LC+9hPhgVWYt45o6FXYBMKeQ//FuWoeFmikEHDGxlBTurr ZZiM0Nq75jAGz7H6TAH/O7m+ktAhCIRZ+7vpAZN5t/8U77h0gQGuJ/4hxcLlibWtclYp MwAgIY+2HJM/v9+KXlcUbvX3AqU/XCju/1dvX2LLFH2E1kkWVmfB2KsB31Aj3A46wMFo rctt1zHtRIluRAhKXYBpbbcmmjkMMTkYi/00yFKemgpJlvdqXAjRgFvvqgfaixioO1GJ xjIUqLvNwLTV6XkHr8inGTsvfKc1k78C6LFNbvN1IW8McwybxrX/0PDk/75tUDBGk9GB lBBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608332; x=1794213132; 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=yduADB2OpVCwll9flVD3mKkXGUD6xulVEqJm2BB22+E=; b=Xz/MmXO/8aD+JkJ1nwZxXsm9u1CIZZjNIfhtf1kJpcpYhVnvLKT0JXaB6EOXIpCAC3 FwNTN0GNGKLhNJ5UOUj6kGUd4DthUPk9AzRiyPnadUhBs74KzGsZXPrypjb5YeKVb2yM 4iUB62yqiXVUN7h0rQ3Yj/D4q5wSZfgpWsRYP0jfCDxd3UVqVQWRo6PM+zEL6EgwisRm yXpIzhHbJu9otFHvdhobuK2IzgkQ3ZGFZc9rEpnU0W40q4Oum+6WERu/qVgZy87MHflB cNFrRmMBFKejg2jiiM3WwZXAt7gZcnwL37j95tx98d+BWHkUe9Bh9ba4H1oqmxDidX/D zJhQ== X-Gm-Message-State: APuU4Z/TwkJIQZaBYYUlqykE4C4oyyHjA8AuWb7NOTSFT22dX3oHSXnv b0uQLEQyk2BesU6sXXPfcm3QZoJL7JX+YbWDf2LqgyMUMn6S6waZTJmyJU5Ig0D7zgIPk/v20PC BSbqd6NM3uwG6QOh1Xef0vLx/TvcsuMKdfydExgmG2MX9ptrP9uoRVfjgLSlnQry24g== X-Gm-Gg: AYBFou0YKYmJMzivW9LVUWg+OQ2IvczBaDp+XhoBRblG57kXBB18yTWeV9fP63XFFvQ jYZkMjTHgbfQfVtLyjDSGaTryfvkz0QPcM0PkaEVwnt51+OctY4GEjxYQdr2bqKLpMa+kXEAs+W izhTlTkuN7xyzFH8vHz3wPl+JSkA4rMsmPmefLreDT1b0Hejg5jXFrr5VhmFThceF1bRm2Q7kgj v+XDW4fwM5bCVHRwvMCsfFC30LJeFshQzI9j9qep7AzTHRJKq9Ot+WGE7xjauoPBq2hqKVnzT0U 5AxGX9JhNWFMIJ+SAiudF/ognAR1bC9+MkAaqijWoQPv/jcOsTUBINzwP98KEMztGq5Y//gnTM0 7WXFtEg0wcsVpbffWLyvuDuCPHY5u8nJQGOY9sNIXCfz/fdf4Z6QKFz5i77Hz1STfBdP6fhWN9X ZSGzyHQ1Ba/vC9knIKk3nUEc0Gf2Ynq/JDjSVW5FHBIhabfLlgkkQdXAJHFN26Xxk30xfU61+Ti hxhdes5 X-Received: by 2002:a05:6102:8346:20b0:7cc:174b:f7b7 with SMTP id ada2fe7eead31-7d07239e743mr3998413137.0.1793608332033; Mon, 02 Nov 2026 00:32:12 -0800 (PST) X-Received: by 2002:a05:6102:8346:20b0:7cc:174b:f7b7 with SMTP id ada2fe7eead31-7d07239e743mr3998389137.0.1793608331486; Mon, 02 Nov 2026 00:32:11 -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 v13 01/10] build: add optional librpmi dependency Date: Mon, 2 Nov 2026 14:01:49 +0530 Message-ID: <20261102083159.3383468-2-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: asHFboqr-JlEw-gNKyN-I3egwv0D4rz_ X-Authority-Analysis: v=2.4 cv=fZY4WEQF c=1 sm=1 tr=0 ts=6ae84a8e cx=c_pps a=N1BjEkVkxJi3uNfLdpvX3g==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=JF9118EUAAAA:8 a=ZLPlHWeyiUGg96gsXukA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=crWF4MFLhNY0qMRaF8an:22 a=xVlTc564ipvMDusKsbsT:22 X-Proofpoint-ORIG-GUID: asHFboqr-JlEw-gNKyN-I3egwv0D4rz_ X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXzxWBIaypIDCa CVWNLLu7qkBX2RLkpFPaXRbE6xzRWHTeOUtQchXfZAnzVsGmjj33ePAYkHlL+7hbOTA3gXxnda8 9OlLPKkYgzfOkyFn/grn2+VF0s+HKLFUDqUOhmCFJ50z6hnKHv/ouYhUO1prGq1NLBYKq/0FnKu FLKN74umT8d9+kIy/zhCLUGxsKpcD9KceVM9melOo15M216DqlTRRnxBME0VI2YrC3jQozn6E3I 7UNSXYM2NulM69R7/xIKf4FHk1y1fGHXZFq1m/Xz20f61VtSiC8TjTwXsziOc6vBbtoMkWyMBPV OOpS2DoUPf+H9hLUNAPOyz6K+1Jj6T2OQ4V2BREOB27IWSMDFXshWMM51JmBMx3y/zdbQ0sLlgG UbT5ule1ocVbAXn9bWf1PszHMJRNlDLNl1G6oyniubDVgb9d3Sfm3SJGitIqt1gA5ycFHU2JWZa Ho016OTBWPV5ZbHbpwg== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXxuqYBJxxsAkY UZm/gu2dLNhsRWhoiQ3/lmFvV7eyIxLfAe9PaPWD3k+w7wC14LaEUYyXubUKfnd+croZFx0qg80 fh0FhZhccmZDG/tDty74NqOL3Ty6ClQ= 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 impostorscore=0 adultscore=0 phishscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1793608400050158500 Add a meson option and config probe for librpmi so RISC-V machines can opt into RPMI support when the library is available. Keep the dependency optional so default builds without librpmi continue to work. Signed-off-by: Subrahmanya Lingappa Reviewed-by: Daniel Henrique Barboza Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis Reviewed-by: Sunil V L --- Kconfig.host | 3 +++ meson.build | 14 ++++++++++++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 +++ 4 files changed, 22 insertions(+) diff --git a/Kconfig.host b/Kconfig.host index 933425c74b..6f98dadb2e 100644 --- a/Kconfig.host +++ b/Kconfig.host @@ -8,6 +8,9 @@ config LINUX config LIBCBOR bool =20 +config LIBRPMI + bool + config GNUTLS bool =20 diff --git a/meson.build b/meson.build index 4f29bc6cc3..9c4d501687 100644 --- a/meson.build +++ b/meson.build @@ -2026,6 +2026,17 @@ if lzo.found() and not cc.links(''' endif endif =20 +librpmi =3D not_found +if not get_option('librpmi').auto() or have_system + librpmi =3D dependency('librpmi', required: get_option('librpmi'), + method: 'pkg-config') + if librpmi.found() and not cc.has_header_symbol('librpmi.h', + 'rpmi_service_group_syss= usp_create', + dependencies: librpmi) + error('librpmi support requires the RPMI system suspend service group = API') + endif +endif + numa =3D not_found if not get_option('numa').auto() or have_system or have_tools numa =3D cc.find_library('numa', has_headers: ['numa.h'], @@ -2449,6 +2460,7 @@ config_host_data.set('CONFIG_LINUX', host_os =3D=3D '= linux') config_host_data.set('CONFIG_POSIX', host_os !=3D 'windows') config_host_data.set('CONFIG_WIN32', host_os =3D=3D 'windows') config_host_data.set('CONFIG_LZO', lzo.found()) +config_host_data.set('CONFIG_LIBRPMI', librpmi.found()) config_host_data.set('CONFIG_MPATH', mpathpersist.found()) config_host_data.set('CONFIG_BLKIO', blkio.found()) if blkio.found() @@ -3280,6 +3292,7 @@ host_kconfig =3D \ (multiprocess_allowed ? ['CONFIG_MULTIPROCESS_ALLOWED=3Dy'] : []) + \ (vfio_user_server_allowed ? ['CONFIG_VFIO_USER_SERVER_ALLOWED=3Dy'] : []= ) + \ (hv_balloon ? ['CONFIG_HV_BALLOON_POSSIBLE=3Dy'] : []) + \ + (librpmi.found() ? ['CONFIG_LIBRPMI=3Dy'] : []) + \ (have_rust ? ['CONFIG_HAVE_RUST=3Dy'] : []) =20 ignored =3D [ 'TARGET_XML_FILES', 'TARGET_ABI_DIR' ] @@ -5009,6 +5022,7 @@ summary_info +=3D {'TPM support': have_tpm} summary_info +=3D {'IGVM support': igvm} summary_info +=3D {'libssh support': libssh} summary_info +=3D {'lzo support': lzo} +summary_info +=3D {'RPMI support': librpmi} summary_info +=3D {'snappy support': snappy} summary_info +=3D {'bzip2 support': libbzip2} summary_info +=3D {'lzfse support': liblzfse} diff --git a/meson_options.txt b/meson_options.txt index 895c6e63c2..ca54c6e731 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -208,6 +208,8 @@ option('lzfse', type : 'feature', value : 'auto', description: 'lzfse support for DMG images') option('lzo', type : 'feature', value : 'auto', description: 'lzo compression support') +option('librpmi', type : 'feature', value : 'auto', + description: 'RPMI support') option('pvg', type: 'feature', value: 'auto', description: 'macOS paravirtualized graphics support') option('rbd', type : 'feature', value : 'auto', diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 14990966d3..0b78ea6fb1 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -147,6 +147,7 @@ meson_options_help() { printf "%s\n" ' libkeyutils Linux keyutils support' printf "%s\n" ' libnfs libnfs block device driver' printf "%s\n" ' libpmem libpmem support' + printf "%s\n" ' librpmi RPMI support' printf "%s\n" ' libssh ssh block device support' printf "%s\n" ' libudev Use libudev to enumerate host devices' printf "%s\n" ' libusb libusb support for USB passthrough' @@ -390,6 +391,8 @@ _meson_option_parse() { --disable-libnfs) printf "%s" -Dlibnfs=3Ddisabled ;; --enable-libpmem) printf "%s" -Dlibpmem=3Denabled ;; --disable-libpmem) printf "%s" -Dlibpmem=3Ddisabled ;; + --enable-librpmi) printf "%s" -Dlibrpmi=3Denabled ;; + --disable-librpmi) printf "%s" -Dlibrpmi=3Ddisabled ;; --enable-libssh) printf "%s" -Dlibssh=3Denabled ;; --disable-libssh) printf "%s" -Dlibssh=3Ddisabled ;; --enable-libudev) printf "%s" -Dlibudev=3Denabled ;; base-commit: d73149283205645625bfa9fe029cfb68e4c4a9ae --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608473; cv=none; d=zohomail.com; s=zohoarc; b=VbXPWg7fEYNcvmCJG22plWBZlg+leULkQxGEHdoY9Agf4ui96yOrDoteewmTJJzpnVgX32HqLIo5GpSBuU1Mb7OfEJQO34QRCb3FtTxFRoWu61Pnse6wvG4/SynVsd4M4YnQwJdTcTwf8CSRglDRlVIZkwii405Vnd+Axw327Wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608473; 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=1X/ze9k3aiHqDH6qiOAi8eRWkFsQIxB5ABwsvz0DQgw=; b=Rs5p+Bk9hCpJ/e9MXq92MvtR1pOgJqbJpwqBzd+2EmoV/mBM1riPSbVlXR8EVf3Hrwt24KdEzJQFnBFvVI5pKxeQKuo3z4oBvPRPuCP2mZ0ZKyj7Uh3ee515ksv12dGvy2D0buC1uZANyV9PmJ8EywlsPS163kRDSE+lux93IME= 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 1793608473707572.0767256341386; Mon, 2 Nov 2026 00:34:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnTT-0002ta-9V; Mon, 02 Nov 2026 03:33: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 1xNnSq-0002nL-GC for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:38 -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 1xNnSk-0004nm-VS for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:23 -0500 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A24w3P71262061 for ; Mon, 2 Nov 2026 08:32:17 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hpky4gqq0-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:17 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-33bf1d17dfeso393896eec.2 for ; Mon, 02 Nov 2026 00:32:17 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:15 -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=1X/ze9k3aiH qDH6qiOAi8eRWkFsQIxB5ABwsvz0DQgw=; b=mcxVvYBzQ/Nrxm+mMVgNaFcOfCS jr5J0Xn0lHR6dcVzbX/645bN7E9enR8VynZ2OfkVlcwCvl3JBbBtxMPorqDA18sw d4l8tX+DmVqK1VQmjG0LKg9NJuJo6IPL456hFSOyXN/kz3GABNFq+fj3RzzKUHJ9 EecsFdqEiULbPlHomSOtghnFYM5cRV7+XxmfvWG7pUqogQLMtNnGeg2JYFOgkFZn 0geRU0mwlK6CHNmuXNoKFX65QBFUGqjM6VbjwLx0FydYRPZOv4vmSvgRvh82tbY1 oR+vk9klqWKhg2T06Ch0pP5zqow+LDgJcT7zFb5+ixXiL9WCXYhKC4Ee/nw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608337; x=1794213137; 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=1X/ze9k3aiHqDH6qiOAi8eRWkFsQIxB5ABwsvz0DQgw=; b=UTpyBNSNrGSzJ09qYeDwM99Uy/k+iclRohP8OtBpxd25gWd9+I8QdwUh20AeAkZz4g c1B6dkdH2B/9ROu2vUbdx6GzMjVoDZOMfz1INPix4hsYdMUt9FYXP4cd0cXm0PQkeLzg 7yr17pwkFCqk7dyMU9oIpbJzoKqs1o0LzaAy+Hdzi6IUECsGv6s0OsK+LhYbCsnSHOWJ XVp8J/qe/XVUUqz/oosAf6wWF1eO069cCAH+doJQPGznJJ86Guu019WPZdjCq7U6eABx eeL0hlB58pAWPk8+TSqE/YyfhBySwqr75ptIy6ztOaUJAvuT6YmpDxqOi+TSqqgLvxYd kz0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608337; x=1794213137; 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=1X/ze9k3aiHqDH6qiOAi8eRWkFsQIxB5ABwsvz0DQgw=; b=yDvKetAn/lq374lhqkeTP9Rd9StT9nAfv1pbs5QDPxMxwUGbF1CEt1+BbR7/D6N/nQ 4myfxgkFnFdoTmWYahvgvOBRsvNW1vrOEbfHxdCvFcObt+BRWWWY4qOX7Ouc+zv99aFn uML4Bk0aUw3yYenv2GrYglOnoLBzip5El+e/4AaI/T3UtgiGozfn6rDrZbmc37rpYP59 Iv0Hsl7aPkDqrduQWHtYlcGSvKMit6+BnJPoca/nYVIJa9+kmYr1USJMzl7oeqfY3DX+ kXknU7Tf9DTA4iJwpkGbKxGifuPp3sR2O2PfqQTe9MOspppLbwU83gacECSqjUYYtLp1 xhpA== X-Gm-Message-State: AFq9FYIcBPPPj6ysxs5pWCgiFd64lvshsnYeC27dHBmFcG4CRfYB45XL 56YqDK0SPAIFMiO7Ofws0dwGdRwdmOV9feyGRkL2IDWRPqpdvGDCRiVsPk2e5Z/nN4/tP+xHxXs TFcD/ssv6j+J8ltqyXMwHiw5xN6HVpkzocmZWkWbUDF3qHABqq4A3tH54xqdVNycRlA== X-Gm-Gg: AYBFou2tCZQf3CohFwJy9Djy0w0BaTTbnW2JhaRZ1GAfv1Twxfk3nElnMa8SXvD0pTC rGkAIG93p84p1/L6hPICRqUBkVAwxFa5V5ueZBbWcsAVxCgLT7rXILICAfJt1smaddjObvZlxq4 Q5zllqDM67D+KWSsu/R9oa2G/2OfpM6+SKBMIr4vEFzarpgVcHLTYLfJwW7ueOgz5/MHqpVDWtA uTLPBEKiYv5kWniJaugDAbd+FJvc2SGVeJF1lDB/Ip2ESfO4oCThJ+mRjOZAwzfXXNDC8t2TbDv ayuArKBQT56Ng2VgG7z3/EVLtq9jUJlfhevEuXBfTbqYf9tAhpcJXM/I9Nx/4OQhVQvxuv+oG+0 HLLkg0vccbsyrhOPWoc9oC60TOebIH6cXz7BhEFu+Ci9gVqg50VMzb1wG7+FEH1bsGOeLntrCnK n7QfJtAfpliXTCG3tWtSViEH44oZqnEiRgjJD/LGK9j2s+k4qx9GdZxtMFrrAswM2KvKhCX17/N yPWYlKO X-Received: by 2002:a05:7022:b053:20b0:144:fd17:3b21 with SMTP id a92af1059eb24-1ac500d67e6mr24100188c88.0.1793608336377; Mon, 02 Nov 2026 00:32:16 -0800 (PST) X-Received: by 2002:a05:7022:b053:20b0:144:fd17:3b21 with SMTP id a92af1059eb24-1ac500d67e6mr24100111c88.0.1793608335624; Mon, 02 Nov 2026 00:32:15 -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 v13 02/10] hw/misc: add RISC-V RPMI transport and Base support Date: Mon, 2 Nov 2026 14:01:50 +0530 Message-ID: <20261102083159.3383468-3-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: SsuBcFJ9fatBhfZj7aPMel6K1EFF_hWQ X-Proofpoint-GUID: SsuBcFJ9fatBhfZj7aPMel6K1EFF_hWQ X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX8eZDkHXaEQLy 61Q+siH6beFv2toHsPYP0DkQ6+PFZscNIIszATCqHZCTYTV4Rcmahdq9n0AYvi5TghtKVO3SVJ5 MFe/GdhkHzyOmWmyh0YJPh92EPVZ+vE= X-Authority-Analysis: v=2.4 cv=QoHLTlyd c=1 sm=1 tr=0 ts=6ae84a91 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=DJpcGTmdVt4CTyJn9g5Z:22 a=V1jnuoLLAAAA:20 a=NEAV23lmAAAA:8 a=hwM_GrIuAAAA:20 a=EUspDBNiAAAA:8 a=bDgSmJffVkpEkReGgNYA:9 a=scEy_gLbYbu1JhEsrz4S:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXxvCN8ROxcYiX n39zVQVevcJVSploMJK2smlFGktH2CqpEsJ+nd42ryK0n8je8+5S0GZ1Ev/mjlYDQB4eMIrqAY7 vLxnasLphfJM6gvRmIaZ2fuXJKbT9bggik0P/DPg1D7Zdj9ztgXdRjkLwsgOIXMU6ySoBJ1JFqC qUDuIY43WYbQVS/aWGhMTIRHu8cirxDCbr6a72QoBrch2qTSy7/XMy2tAAArcYKzw4qPIyYujrR 3c1InAK0oSAPI4AXR22RqEi1kdw8n+bUrLePOuPZvd8/bNPiECK6egdNUMvbcd/7NyJPn3ZYVpO 3CuFuvCJwfyrdAqifeM2SJz/aS3T72M/a/WL8dB0eESHWGG3n3r5nlqZ4PeoxnZpVDra54wGyis o1dXRUpTlIpD4IVr1SrThF1vIW7aljQ4Y1yU/dZO4p53Hxkk+sjSS6FKzHW5thv5WyFwTNJ7yjx JnI0/lALAn+FH1uwNYw== 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 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: 1793608477041154100 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 | 3 + 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, 656 insertions(+) create mode 100644 hw/misc/riscv_rpmi-stub.c create mode 100644 hw/misc/riscv_rpmi.c create mode 100644 hw/misc/riscv_rpmi_internal.h create mode 100644 include/hw/misc/riscv_rpmi.h diff --git a/MAINTAINERS b/MAINTAINERS index 4ca1751e30..b0afe3fe0e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -376,6 +376,8 @@ F: gdbstub/gdb-xml/riscv*.xml F: hw/char/riscv_htif.c F: hw/riscv/ F: hw/intc/riscv* +F: hw/misc/riscv_rpmi* +F: include/hw/misc/riscv_rpmi.h F: include/hw/char/riscv_htif.h F: include/hw/riscv/ F: common-user/host/riscv* diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig index 7abd22869a..0b8e28f72c 100644 --- a/hw/misc/Kconfig +++ b/hw/misc/Kconfig @@ -267,3 +267,7 @@ config SOPHGO_CV1800B_CLK bool =20 source macio/Kconfig + +config RISCV_RPMI + bool + depends on LIBRPMI diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 90f3f89de7..3e298a74c8 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -181,3 +181,6 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('= sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) =20 system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_clk.c')) +system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( + 'riscv_rpmi.c', +), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi-stub.c b/hw/misc/riscv_rpmi-stub.c new file mode 100644 index 0000000000..dc32b43227 --- /dev/null +++ b/hw/misc/riscv_rpmi-stub.c @@ -0,0 +1,16 @@ +/* + * RISC-V RPMI stubs. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/misc/riscv_rpmi.h" + +DeviceState *riscv_rpmi_create(const RiscvRpmiConfig *cfg G_GNUC_UNUSED, + Error **errp) +{ + error_setg(errp, "RISC-V RPMI support is not compiled in"); + return NULL; +} diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c new file mode 100644 index 0000000000..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 --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608606; cv=none; d=zohomail.com; s=zohoarc; b=EUTP8geipth1mXGpzd4t/rKQw3IblvZBEtKQG49DkOLbtgUhhQ5B/0ADx5JqNLF2DSb/KMEOyUXXiKfUjIoNmLkKcwTwzxvGKxlyWZ4eUoSCJ7lmG0dSopMZTWKTCGBEc7KyHbEAyHaifW1emUm2ZWzGAGZ+luHN37ZqkGznCYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608606; 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=Cxwm6Ecqik9o6SuCY9NmVjL+EPNRNsiAAv5UIqXeAkk=; b=DzpbKoVMQYfLLlZoGMxf/R9F/HoSJLxgb8lS4qe+roP+dSrobJLRsBrPtYjxmgNRh291uyD+8R8x4K+9zuV43n3VzN44dA0jxt5kPiiPkQx1q+WVT1HQ2NaI6U5vWXcz2HCau2xR1VTKeCfXu2WtP0cdEuL2y/2KjU4dbGkEh0c= 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 1793608606100256.5225779587878; Mon, 2 Nov 2026 00:36:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnWz-0005a6-Kr; Mon, 02 Nov 2026 03:36:41 -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 1xNnSu-0002oT-CA for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:38 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNnSp-0004oF-49 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:25 -0500 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A24DHsa2433620 for ; Mon, 2 Nov 2026 08:32:21 GMT Received: from mail-dy1-f199.google.com (mail-dy1-f199.google.com [74.125.82.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hpka60v1x-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:21 +0000 (GMT) Received: by mail-dy1-f199.google.com with SMTP id 5a478bee46e88-339628f2bbaso317428eec.1 for ; Mon, 02 Nov 2026 00:32:21 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:19 -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=Cxwm6Ecqik9 o6SuCY9NmVjL+EPNRNsiAAv5UIqXeAkk=; b=EW3OPL25+jwT3e/wdjJdsJ8sSTi SyuuPjoAie4oWmLJWYXXdxkBOd5q024DfV/4bAE0DXibkH1v37SYFbsEzMUJZARU YrNYTThxtKksYpUXNQcvaCIss+fZDQdD0csSl7wIJYhJOcoCoME1RBfObssZCSDh RXbc4gQGpr04rbDvj8RvVGbuXJa/EMjmu8idQhAOkKK1Lc5l36GY0ohLKBj4Le57 kJ9jxKWE8qk+aEXqUXLSB4sPbpzfY16Wr716Cbd+Cbkaz3vAWr+k5fOsElGRhel+ r1whHunmB4ebSDQFAPlr5sHi39Zz4QBLg/8blkDccGw4c4aTEK+0HCK1Yow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608340; x=1794213140; 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=Cxwm6Ecqik9o6SuCY9NmVjL+EPNRNsiAAv5UIqXeAkk=; b=YFQQ7dQwkmKQypDxAVAQkpUXpLeodTu51yPV7PKgcAwRADDIgcrr18VRHTFHnSEew7 c1QVDfClVBo6YPjlnFDrVCUf3UVUyjZMJJ5/w+T3WtSDjdRvNlK2JgjPhgzE1DXA0ZlD Uo+RLpRDdz0iy4YA2J2yIOp+hSDrROx1JSms7Oae8Fh/C1IgHrdEFmynd/nA+gkzhmSq Ge+PSPadX6+23kAyr2U7IfFTFEDsWnjgpDAoNXPog7GPjw5wt9e6+W5REAJqTbWav25K kir0IYULXPRqf/V9B2X/1zHTtbg2lH6qmlIDj2qkvT8n7C9glsgzJe+EZBPNPl3rkIiv +1Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608340; x=1794213140; 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=Cxwm6Ecqik9o6SuCY9NmVjL+EPNRNsiAAv5UIqXeAkk=; b=N6sSK9YO8++l7nNJHOOLqL61Nbc+fW4zNcjVsczzAqQbi+tHtdTfBBgaEOlQPzj24S YW1mS1a72Zf08qMBxcSp9ZSDGZOzI26TXenvxu7YZg0DKOHlzTRaORdPCYT3X9sOsyjP AupEe2wDmNArE+dY2aKn9pm0XT0GgnsvUJQJ5TqdNaVBQ7HR+K8Amf+6a62e45dMTuF4 NyG8nYoH4YU71UjtJz78V4xmmGcEX6nsZoClyKJdq3IhUb24HbpA55E9UJU8gNiSS0Nc j9VGTUmiF7a5SRrCWN923Gtgej0beCXNaKj/ws3kZzbMHtM8f8jqF+oJOKvdSHk7yNWF H2ow== X-Gm-Message-State: AFq9FYIBr2zSF5mD0fd+FrZpA6tkTDzcgw5OLaarCxzNcpMkjC8QDg1w Ta3D3/5uV/xzjaiQVoh/O9F84X+jUXXuVQh7QDZ337FRRXkuZFEB1lar0T0UZFQv+GdQi9v7l6L 4T/+bb8tLyWt+7gJzcByVN9cjH3S3sIOoPhPgp5RD9i+I7ERhTIGcZUtSfrE4uxFUMA== X-Gm-Gg: AYBFou0IsuQTyAq6UQvOp8+sG2x8eGm02RXs5QKwJ9wgEA0B7wqZ7qwnOvvRl8hRcxL IiD03QaFZI0qkQG5wEnxqrQkiJzlhm8yvh27/d0GrdGk85VR2sfE8pXUfuW1B6v/GmXIpdqB3Vk nZKJisXfIQFQezPv7SJc8TzEneM2lXi6o+DNR2t1I+7wLE674NjoQFNIFVqL5b6AUdo/nG0RjFL xRYmGknnkB+qBtaWmPKBR7h7VMT4/FAJ24OiXHjW8lW0xFhnrVzJGhnWbRAs4CHoNZDasA1I5xD aAxNfBf4AZIZ0YWuqJY9Qm7etUwcOgMw84hqjv2U1IxEWeI3hJkE/QgW1tzH8sceBJIODCMfMLR h8vWgsUCAv7D+/GK47GQ7nT4T/ymJexYh3bkEBhNiIFNUXEWoFG9+AIns4qpBIzeIrv2BtE//Ue bWhgWtrN2Uy0zc0uCjn85+31uJny7Q9AMUoX5Iihwt3iplMg6bbrgl2vQeJStB88jT75GkwVnWY dy+pdjj X-Received: by 2002:a05:701b:2515:b0:17f:641e:7f6b with SMTP id a92af1059eb24-1ac5904ae73mr20881879c88.1.1793608340011; Mon, 02 Nov 2026 00:32:20 -0800 (PST) X-Received: by 2002:a05:701b:2515:b0:17f:641e:7f6b with SMTP id a92af1059eb24-1ac5904ae73mr20881823c88.1.1793608339358; Mon, 02 Nov 2026 00:32:19 -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 v13 03/10] hw/riscv: add RPMI FDT helpers Date: Mon, 2 Nov 2026 14:01:51 +0530 Message-ID: <20261102083159.3383468-4-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: e6XQ2_dK2VrKhlxjkLr9TFoVUJabmIe- X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX7sUiAUh8dvgr F7szmjebbvR/5ppLibWDTPMJgW42Fj9iJYbtvzMlNGyjf6q/8jO4vb0MGWKj00CU13+QgGfGGLs owYSmlLB9jw50UFt4GzCiE5NXNdmNKk= X-Authority-Analysis: v=2.4 cv=ZbyIpcVA c=1 sm=1 tr=0 ts=6ae84a95 cx=c_pps a=cFYjgdjTJScbgFmBucgdfQ==:117 a=Ou0eQOY4+eZoSc0qltEV5Q==:17 a=zJRp6_cAMcgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=EUspDBNiAAAA:8 a=WNJofZAcfibaGo0vQRIA:9 a=scEy_gLbYbu1JhEsrz4S:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX5+fDnJLe9kzJ pphFg+NEubkXIrjKhIVXPv+O2Xr0hTqCGvclcC0HSMnNOJMWzXxO0hI30wXXsUU4+XFvL6biT/u 6tBMygbuyyUwSqmxgF125CKfA7zbFElwN8Ylyk0ojG+B+rUNnFqx+RY/7Wn/1w3s+j/nMGjEtjr KZ20RorpRKEONgX/2bP3ZZOPlCyQEAabHbneV1pjRkl79tI8+l25/3WzixzwlVCWkLSmbi28urc K239K7V65qO6bfUWhSeJoN3DyF8HoGFkJWigmGfHHaxgxOxKQYLlMc587aGPUD1GxhPk21qv81m p45E4Zec36/nV+s7RR1p5T2EMpmXT18vlm8o+Fzcxtbm6xt+QPR7R1ijS3HxiDAvlBUZMzuAg38 T8h65dJiUVJLOD94njWslzMmXbeky9HpaTIXoKIKptvDhQcfVI4d5gGXjLc0GJe43/sHM+OjU+D ttfSKl+x4uadH/AMtBQ== X-Proofpoint-GUID: e6XQ2_dK2VrKhlxjkLr9TFoVUJabmIe- 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 clxscore=1015 bulkscore=0 impostorscore=0 spamscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1793608608973154100 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 --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608667; cv=none; d=zohomail.com; s=zohoarc; b=asd68XPX8c0DlfrpECmJWhoU5rKPicLAhSx0783eSSJcUncjLWtkf+rhVmaA68spMDRmOwBu5qe1+6V1uXGJOAE/mHohS7EXi6674SQVpJXn2g4s6kX+AK5e6+k/Ds8zNG951lb545di/MZK/SzOJCE0JkeL0tKQ8N3SDReqwgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608667; 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=rmFrDc0KgPNHHa0ffKf08DOspV7JwzgSvvDggzxccNY=; b=a+xnc5n1j6L1j2wyeyBFXKaoHSHo28GhvtCZezQA2Hhbfl0p3CJK1xJnXij9JS9384AxxKggZ8xoXd0dTHRi3uyCjmbpXlTY5w7A6Qi5vSY0JsePt93AfIdLrUyMyajnti1esASyN2uicZdcPdatZrpyMa0tHJERtFCohcHfQSA= 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 1793608667520892.3823422286506; Mon, 2 Nov 2026 00:37:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnTX-0002vn-Is; Mon, 02 Nov 2026 03:33: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 1xNnSx-0002oa-LI for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:38 -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 1xNnSt-0004om-Kn for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:29 -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 6A25Vxug3924268 for ; Mon, 2 Nov 2026 08:32:25 GMT Received: from mail-vs1-f70.google.com (mail-vs1-f70.google.com [209.85.217.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hpmf1rmrh-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:25 +0000 (GMT) Received: by mail-vs1-f70.google.com with SMTP id ada2fe7eead31-7c2b7a15cedso86082137.0 for ; Mon, 02 Nov 2026 00:32:25 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:23 -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=rmFrDc0KgPN HHa0ffKf08DOspV7JwzgSvvDggzxccNY=; b=RG4Wv2kYl9yrqLvEgcBpXwd8b/J xn33FG+9PItzwGkPS2Odzo6i3Zdbo53vpSUVMRJ0v7XbCzb8jFtewSgwtnuP9RZO Hd7SxhXHqdWLUJ9C1Jo23v+uBY6Vezx7MyDF9cRdRHLLpmg/2XnJSCKTnQicrMnC p3Pcvf6PXs8HB4Y0Onz0ZAH16khPq5bgpzVFrGp/nfeFk+5UxKBtSMqAwmx8QnSR lan9InonGpUQNXGizIsfiBHuyzDhEyLyLMJa/tgm1pjVpW13GiNt6t6jBlNS2ORO +AFma0Z71oH4/KfFEaHXLqzKFU9HDofkhcAz/hjeppWMz7cRXa/P99Kbw6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608344; x=1794213144; 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=rmFrDc0KgPNHHa0ffKf08DOspV7JwzgSvvDggzxccNY=; b=JcAvsZWt78q16jvXwr6Pm+QxuKm3cIQ0YI47I9VZ3rVFCQ3TrM+YYG7k2G/RGPRHh1 CfT5HTiLdnqZEmszkH9C3jJBYoft4qVkjLzUajHr7krGPEGN2w37/vyJCpKtw3k3ZbR5 V35kqVGgpBlRp05mHGRBMEDYFjgkzWapgJRODbchM1Iw1IAtJH/Rp5BGLx/mt7VOKlSr KU5797IwumrQd/UsmVrgmcQGYJyPgCgKuCstIGdMT1elfT1cxFLoRXiZAuwLQgnUjI0E UryzeHEV3YCneU2xJRmRgvEhcN6twQpoYKadsGduinU2yJwgjNQwmb4PxrB9DDdtClIK zEtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608344; x=1794213144; 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=rmFrDc0KgPNHHa0ffKf08DOspV7JwzgSvvDggzxccNY=; b=cxrLwP4ukZX05CDc/tfnu4O7tkU5w6cKX3P2ND78K7ykZ6IrsGzpcSA+kNEWzcS2QN /g5jYlJFeB8Ih3uMpyctv5DnuRihTlpSyvt9Iwt2TkyvR3GGKcuw60oBLrXrt9YL6xEf ghj8EiEWC/E/AoRcTK1rE8Bl4EyHznr4Iii5MC52b5rmLIzjteHgeLYKBJJJrVUmWRFz R66YulF0Ki6vUU8ZtcsCMB1VApWUc6sDz/a6M0vV7iTO8vgnCpi7DeB9g4FPUOl2eEcE QHgQjJ14I59zK9efv1wyMx0w1osgr74J2p3sRqtraR4T76fWkjsMOsloPNxV0FNV8iH5 6OlA== X-Gm-Message-State: APuU4Z/klEBP0j0ZWU7NFuMCoUeT1p1b8lu6991UGp7aXZqQB3GiKhiS MXc5rU6sPOW7CcnU3BNnJZ4HOKhQqrPh6ID9/V90/jUq04AorFG0qV/Z1t0rTaZ/Pbi6egs4oGb gqSFdeZQaFmEiZ60q6CSQ9kfjr4FmXlgBr4yvWcJK78hOtZ/Quj/XrYWbC45kpsMJgA== X-Gm-Gg: AYBFou1sK3cg8wFOV5oIzxK9kCLp2O44RNUGBe0aIk0sflCdQzwPbgu3/qa0Jij2KnG IPPTj6583YPyLS6cPT/FycCuno417MRg7H83DbninPqtGhx5SAryxtaZUQ7xHVk8cOfg1UlE7HT Rru42C/Q3UqTdzKysflzTzeeJhzvWxOlC8wPUdSjW7B54HghRCuFQQa6eEn1V04+xU3KoOEBj6P QBmcnJ1U+HHLiKl2Rc8F5zFSRs9p1MX4voqm5D5f2fo5dX4VCGMn/ZzsjNFeHtSkZYph1/qmO90 nMUlVfx8qls91/B3v0VZomvbdfFC0tmfy1lstHX4r7CejrHUPJ6PFcceePVNsA1uxPl+YvJl+Pc 0qe1LgSU52jSt4TTv9uxIL/4MX4u2PVO0uwYs7QlBIGVSJsAJvMRHdmwc4GIC9f+bM7R02vDT// M9CAH76ZIuQ9PuX1ral/9jyFQ9ngv3BhJ7S17ZjFQoc5KGyKZoznfcnau98jqaopDVAsqMWA6cb dZrlOOA X-Received: by 2002:a05:6102:868f:20b0:7b4:f1cd:80dd with SMTP id ada2fe7eead31-7d0727a54dbmr3088635137.1.1793608344193; Mon, 02 Nov 2026 00:32:24 -0800 (PST) X-Received: by 2002:a05:6102:868f:20b0:7b4:f1cd:80dd with SMTP id ada2fe7eead31-7d0727a54dbmr3088622137.1.1793608343710; Mon, 02 Nov 2026 00:32:23 -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 v13 04/10] hw/riscv/virt: add opt-in RPMI base support Date: Mon, 2 Nov 2026 14:01:52 +0530 Message-ID: <20261102083159.3383468-5-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: SWSNnH6M3Ax7dhypfpPaMF_nJ2iijsa0 X-Authority-Analysis: v=2.4 cv=bNaDs/+Z c=1 sm=1 tr=0 ts=6ae84a99 cx=c_pps a=N1BjEkVkxJi3uNfLdpvX3g==: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=DxKkKmlP5ys5yIFZ1rYA:9 a=crWF4MFLhNY0qMRaF8an:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX6sD8zPhSoahr FYspAH1pF2DnH64CEScbtOm5sjqsYWGf2TEA3CDf9DyFOQhNytTsWL7jbwuM8AsgcftLteRZcqR 6LlHkzaCfk8PgfqkteWqvw2twm6w484uCFyRnGuVGEV2n8pc7lhfa/n2cFW1ZJ4VGprQ8uvgIa7 yGA0MgjMQKIq+Y6lsBADzkcuGYir2FUzu08GW6J/OdyJvgChAb+/6Llyjill3zCBMzvGrvFhM9e 4GGcL6EWorbYRMaevdKugaAN/LdvFZ+NslEO0WgMLSVs/Er80Zt8h5DnmEAsUZE0kTrNOj+xlDW HD9B49JXImEnJi40BTLUulg5vpFxDdqFhaKpKXzVN+zU5ZKtT0ewnnGPwBOqbsVlJKmg4CphC2N YvQlsscN0ox5ijJxASozgTxTTCC2LSYwkR7159tLPJCAzPN+Pr1WX0H3vNMU8wd0MdI7TkxeFWu qwk/uX/ODloRvV7NtdA== X-Proofpoint-GUID: SWSNnH6M3Ax7dhypfpPaMF_nJ2iijsa0 X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXzi6u9oNbZNBM q0R/C4eT8yZ8Q8YpPyGdJvyVWCkvh4yAZtgLpZVMYxkt04YCIN+PWVGsov/uBpRG/v9wgL+/voj Ghpl5vPE7yVgkaXqtplsS3Jvh5VcSu8= 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 adultscore=0 suspectscore=0 clxscore=1015 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 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: 1793608669833154100 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. Signed-off-by: Subrahmanya Lingappa --- hw/riscv/Kconfig | 1 + hw/riscv/virt.c | 89 +++++++++++++++++++++++++++++++++++++++++ include/hw/riscv/virt.h | 3 ++ 3 files changed, 93 insertions(+) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index fb05031228..dfdbc6dfe1 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -49,6 +49,7 @@ config RISCV_VIRT imply VIRTIO_VGA imply TEST_DEVICES imply TPM_TIS_SYSBUS + imply RISCV_RPMI select DEVICE_TREE select RISCV_NUMA select GOLDFISH_RTC diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index d4b501802f..c564b5be45 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -45,6 +45,8 @@ #include "hw/intc/riscv_aplic.h" #include "hw/intc/sifive_plic.h" #include "hw/misc/sifive_test.h" +#include "hw/misc/riscv_rpmi.h" +#include "hw/riscv/rpmi-fdt.h" #include "hw/core/platform-bus.h" #include "chardev/char.h" #include "system/device_tree.h" @@ -101,6 +103,8 @@ static const MemMapEntry virt_memmap[] =3D { /* UART1 supports page isolation from UART0 */ [VIRT_UART1] =3D { 0x1000a000, 0x100 }, [VIRT_FW_CFG] =3D { 0x10100000, 0x18 }, + [VIRT_RPMI_SHMEM] =3D { 0x10200000, 0x20000 }, + [VIRT_RPMI_DOORBELL] =3D { 0x10230000, 0x1000 }, [VIRT_FLASH] =3D { 0x20000000, 0x4000000 }, [VIRT_IMSIC_M] =3D { 0x24000000, VIRT_IMSIC_MAX_SIZE }, [VIRT_IMSIC_S] =3D { 0x28000000, VIRT_IMSIC_MAX_SIZE }, @@ -109,6 +113,9 @@ static const MemMapEntry virt_memmap[] =3D { [VIRT_DRAM] =3D { 0x80000000, 0x0 }, }; =20 +#define VIRT_RPMI_A2P_REQ_SIZE (16 * RPMI_QUEUE_SLOT_SIZE) +#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) @@ -464,6 +471,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; @@ -500,6 +536,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 @@ -733,6 +772,18 @@ static void virt_machine_init(MachineState *machine) exit(1); } =20 + if (s->have_rpmi) { +#ifndef CONFIG_LIBRPMI + error_report("RISC-V RPMI support is not compiled in"); + exit(1); +#else + if (kvm_enabled()) { + error_report("RISC-V RPMI support is not available with KVM"); + exit(1); + } +#endif + } + /* Initialize sockets */ mmio_irqchip =3D virtio_irqchip =3D pcie_irqchip =3D NULL; for (i =3D 0; i < socket_count; i++) { @@ -891,6 +942,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", @@ -1044,6 +1110,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; @@ -1165,6 +1245,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 e516898f9a..919a664bc2 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -55,6 +55,7 @@ struct RISCVVirtState { =20 int fdt_size; bool have_aclint; + bool have_rpmi; RISCVVirtAIAType aia_type; int aia_guests; char *oem_id; @@ -82,6 +83,8 @@ enum { VIRT_VIRTIO, VIRT_UART1, VIRT_FW_CFG, + VIRT_RPMI_SHMEM, + VIRT_RPMI_DOORBELL, VIRT_IMSIC_M, VIRT_IMSIC_S, VIRT_FLASH, --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608502; cv=none; d=zohomail.com; s=zohoarc; b=P7+pCle9rroMQxy16iI3rHn5yjaJPwdOO3dYMv0h3ZaxspXL5D9TL33483xD69IcRvTWHv8htVvEYNM8Q+1m+FeEEb10W2GstkNFKJt/py3ydVglKyq0bLoQM2/fctFOdIA9ikKB10/Lx2tsdqD/Pvba/WYbHzx7zIClO+gw2p4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608502; 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=nv4ajAxDTmJl6B7+mslCNwwEfxrAEmwYqwXM/yTwO1Y=; b=FQAzr2PY1WxI8TISlmMZ+Ic/0ky8MA7nCEy0h44xrYjjwfsZv+rcQ0KQfGbvnGlfAHhvGPAufedhEFYdGcv4GyjTppKvEQZgnpTKQmnvmm8m7T4tV4FC6v32xFEhv1WPj/DPkHZA4WBmMBKghr8at2RHaKbqhEw4NHNEFzc3OGg= 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 1793608502146946.4171461183579; Mon, 2 Nov 2026 00:35:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnV4-0003e9-Gl; Mon, 02 Nov 2026 03:34:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNnT5-0002pS-6H for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:40 -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 1xNnSx-0004pE-Eg for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:38 -0500 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A24w5021262130 for ; Mon, 2 Nov 2026 08:32: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 4hpky4gqqx-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:29 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-36a0e07082dso334153eec.0 for ; Mon, 02 Nov 2026 00:32:29 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:27 -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=nv4ajAxDTmJ l6B7+mslCNwwEfxrAEmwYqwXM/yTwO1Y=; b=HRw90g5u+PgS8AAvUTbVt08jqKK 3hWESbaHkPqmkRA3Nx90KrU+zliivzdCJuqBk9OwS57IAgU3GMSgMdkC29OjjL5g 6ufHs/95RXTR5owFQAoW7GTLDC3xVV7jY7PrzoxpVphiTp0CeqXgLHcxAOQTHu3W DkOWv9HapUM+ARpM7uQKJR7Ko2xhf4ijYfR/aSaamASLN0AtY+1VLI9Pk7kBbY2o bnyWx+/YeduL5UH1z1Np1NFOaoO8xA75Vt8YJc7Ni3eyivrOSDu2B7PFGWEI21VN AZ6FoVL2bgayzuO2TpvmsUC+usZUX6yXHE3ZDVvRzx6dMmxePnEX03LPIsw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608349; x=1794213149; 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=nv4ajAxDTmJl6B7+mslCNwwEfxrAEmwYqwXM/yTwO1Y=; b=Tpa5KfciO9lma6pjrpEUWqbjV385cXFf21pnzdl+0fjAu+Hte65SPRC/lVJDVGi/Jr x0TCts1SuFt3LIK5PKb0SWeDoVgJFpmYS/n9E5ZthLxm2tiyvXIZGrGpyqa6Z/p+CYtT QDXLsBUEeYhcl5fGoKDdlXLTzOCGypHLFlzc30mef1YS46MaNw9iBwXgS8C+dN7YfTKs v6qUqRWnNTApDNxYi5YXy4XR0L1uN2SbUqXPh3JVM0z2zDMX84jG4Eu+d07CdREtVBfG LzBbwm8d6wuXPI8PdzXNmE5td02Vv1/tNy8QQ6FbnKUXg8Q6k/YHk3TNrAtU9tN1FIzc BLyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608349; x=1794213149; 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=nv4ajAxDTmJl6B7+mslCNwwEfxrAEmwYqwXM/yTwO1Y=; b=Tc83tyGm6IoIVjA4VV9nodGK8vxGkw20dEM+Uu4i7EdN5WIuVw/1PKk273kuYTnE6J 5YnyuOwofyx3MZmXWn10Sw1OZArHkUqcmFB/SE0nkXiOOrYS8SCPhGAGqNCt1Pc7cKh+ RWvakWpCuIIeEZavmExqIVycT3aea8Xfv1y6UY91G9sOGpkTHVFIu3+atIPtTAMYww09 99WjGwGrAIU0KwVr2ZY2VFzInDU9O242DxUffro/597lF8nKbdAZq3vJT2vTuks7UXt8 x7GS802WUdSfi9RrcBDcYqigjXlwyGcNIHLF4LWgb8sK2msoM2sGcYYgSGgY6AXd3HvP EkzQ== X-Gm-Message-State: AFq9FYIToaQqeMK2CVDUzda90zxHtRVc0wSRGhA69YsLjSwhprNpSEi1 qWS/ieX7Xl4RFmMEXUioBcB9w7CE1FZ7B2rT/uAR9aHVF+dMzRQo/QjWITEvQ0K+5DnnYBG2ypU dlTlqi/SoMvnijDTaLp1VU/fTrMxxGiY5KyboJhLvEgvKER5qRk/+ao4Z50l7VBLEKA== X-Gm-Gg: AYBFou27Ez8j0B+zx1v/Vh+WELGgRzcrDMGhA6UUWl3W0ZWqVf2GMASXCNaPKvR4WWn w4hsqEOxv77lDaCQsMMKzDa6tPlWX6sfUg/7sYjjP1Tr6vEef40w8L73ztVroaYpQxBj3prD79I U9XHk/6msESKqZK64XiReHPOYUO1UUJwn1fgG/8cza29uFIYzGgMQJGicD5Nm87reO4x6Z9jQdV bYORtFi6Pmb0uDE2FXgAx4ByroJO/2xiSlhteGW9Y/DDcp2H1NzorOjPccqB+FvIa2FG679zWU6 0mNJwEhgtb2ImrF92VHtBA2hXoHp7OP90z3qspvAOmR1ZJbd91cWoFCEGoxRTc9wcR6URLqGICc B0vW3NTdWn834Ra366K01OxIUcZToK1oMRmpZF5WaZvjLYSSzTU98j6SD1Rla07pPt76qchkO3A yVM2KBQ9TKFIwlmgPuAuYgPv/5AiIgkBdB6CxLCBa43cH+0XGJ4hgP3uixzj+7PivB3GisbJuAH rJNSU1v X-Received: by 2002:a05:701b:428f:10b0:143:5c2a:e45f with SMTP id a92af1059eb24-1ac4f91ef0emr24390188c88.0.1793608348247; Mon, 02 Nov 2026 00:32:28 -0800 (PST) X-Received: by 2002:a05:701b:428f:10b0:143:5c2a:e45f with SMTP id a92af1059eb24-1ac4f91ef0emr24390130c88.0.1793608347522; Mon, 02 Nov 2026 00:32:27 -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 v13 05/10] riscv: add RPMI system reset service Date: Mon, 2 Nov 2026 14:01:53 +0530 Message-ID: <20261102083159.3383468-6-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: XQgHJDmE3m32FGxt9M77-S_OryVfwimk X-Proofpoint-GUID: XQgHJDmE3m32FGxt9M77-S_OryVfwimk X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXzoVaJCy2+Bof VSVPH5fTTkBtE0XUj31YSpCrp4/AMkYxMLKGbt5TPl1TKgekJ6qXM7L8+HUcMjSeCVRAWAlysYg PC4jNcR6xbf3J+K5UsveD0hgenmU/94= X-Authority-Analysis: v=2.4 cv=QoHLTlyd c=1 sm=1 tr=0 ts=6ae84a9d 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=DJpcGTmdVt4CTyJn9g5Z:22 a=EUspDBNiAAAA:8 a=HwIue_3DUM2RCVtF5-MA:9 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX2Wkew8/c65uL yxq4OC2eLQ+GEEySuG4ywTIXk7VMBDo+/xkv/VhJqJoNzDJq3dnpl5xnwwTK9FqCClz8zIqFQwI T0geakkN+tbzOCg7jAEQ9OMcTxdbAKxnAlIek+P8rlwtcWMw4le9/0e8QYTK1/JevkgEjyvD8kT F3F7DLZtOzVAkyhfEn64QmcWN8JzlroP53ALXx+Ja3ppJ+yaC7m5Gr2zRzBK4s3qPlVoEBN1Tf1 0r/o2tbnk8IBVSQcjg/qMCBpPvrgmHeT73zfGBu5I5phvw0hInOBDqRlOVM3IB0E0zgwHzjC90D GikYy8tv28xnDVT/UZdb6ihFSN7Fnnwh4tAK5JvxMxKLvkhZ0AoWEpsCONgcB2mwg1gYLQAy/yc uBaWlQyGynekCb27Chil4hqX/x6bZLzlmqeGRosS2zY1Yd7KQPsXSpLEvTWoFqOsR/ynqLeFfzt Ed+0moJGkDrC2LMck/w== 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 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: 1793608505684154100 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 3e298a74c8..87ea363199 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -183,4 +183,5 @@ system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi= .c')) system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_clk.c')) system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( 'riscv_rpmi.c', + 'riscv_rpmi_sysreset.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 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 c564b5be45..84c9d9a4a3 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -51,6 +51,7 @@ #include "chardev/char.h" #include "system/device_tree.h" #include "system/system.h" +#include "system/runstate.h" #include "system/tcg.h" #include "system/kvm.h" #include "system/tpm.h" @@ -471,6 +472,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) @@ -482,13 +511,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, @@ -497,7 +531,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) @@ -535,7 +576,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, --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608669; cv=none; d=zohomail.com; s=zohoarc; b=C/9Q8GjblnIDgXTo2NuSTRJtOGPfrJG9Jm74VHB0rqxAL2YHAN2KrQ70fT5xzczGhOKSqwB+AFjZQ8mgpQTmMxUuB6YhYYV22WKbgfcam0Q22sd7IX69w58aJR8xUUPHTM3k0ZRhm1j05jpmkV1T/3UL6CgEUu2nCwjYYXzPHa0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608669; 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=AcrWqNMJ7EZ7HOR618MRa0KbI+LD8WOUCw1m3zDdHbU=; b=NZB2E1Q3Q9GQkF2+4ymwVL2tIXzXTMe8Wo9aZ/okPdRiNg7YE+bDlGxyEFe7ewnGtYi6Ij8rLfUlpCaRk4T5YrkrprJep1oZNrqBiXt04GIqFJGop4u88jU4eAXxsJUBAuqJqGQrApmrHJRlllkq1EF0KsBW75tknVvzn9ahago= 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 1793608669405296.55586302449285; Mon, 2 Nov 2026 00:37:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnTV-0002v0-7V; Mon, 02 Nov 2026 03:33:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNnT5-0002pT-6u for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:40 -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 1xNnT0-0004pY-Jm for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:38 -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 6A25Vxuj3924268 for ; Mon, 2 Nov 2026 08:32:33 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 4hpmf1rmsh-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:33 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-36a6f57c066so79544eec.2 for ; Mon, 02 Nov 2026 00:32:33 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32: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=AcrWqNMJ7EZ 7HOR618MRa0KbI+LD8WOUCw1m3zDdHbU=; b=NFQRTnrxxrRZ/uGx1tcJbBL4qFa nUNsSMIdul0kerOGMhgxoQucOrNhxy8v+xMG0n1vATweHRTa2UV9NSK/ImSZyV1p Qki9bmTAyLmgEYGduplLN4rhywC3SrNudbaY0ioJGtfUY5mJF4pLyRdb0CVbix6j 9lMeZnTSeR4YEHgM6jFPdlMvRa4fBe+hIhmJuLvzYBfddeFtyMjNpozflwKoHwxC wizEvcECQ3HEMc9R+wLUcMMbw4gXzrBrYbzLKF7BFsfDi5VdFe4pXyDg9Ee7gFIe BSx7cEjmBCAlpVLE52BcKxJB8GjkilQ0MXQHWfDlWoT97OrPLZdO9mr0xZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608352; x=1794213152; 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=AcrWqNMJ7EZ7HOR618MRa0KbI+LD8WOUCw1m3zDdHbU=; b=NvE65rBe0agGhcxKr/GPl9XvUMjl2yPZEO8ppxaIc/FUMgO1eI/+t3DJcHWp+ylXS5 iUwW+0kW61TgtcUT267xWjEdE/swX28sS795jUKaW9fFxA3vKgOZNtQD2ihKpuLs8+79 3RZtOis0m3rv1UK3swOGNsoi8bgIhitOkc7/8BqExQhD8a7GDj7FFtt6ngRBAfIdQ5k/ uMVEG9bgSFdrdkO5wPCzf/XS3algOqopCl+B7z5K1ZasiFkfT8UZqdQ8KbOXhKCnYNI8 FmrBusa28Y+m8vUhtr817ajH+apLTuc541KuBEL1p+cDf5wmgQTwVnwXlOcC6aks/6U1 wE2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608352; x=1794213152; 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=AcrWqNMJ7EZ7HOR618MRa0KbI+LD8WOUCw1m3zDdHbU=; b=LZM33KLO15P19It9U1qzrOPLW+fHObybMJoc7akBidgHb+vv0kczZ1F+gMSNtpB9yN 93B6rftBo9ScoGXjouAHIIeTzbh5kE9VcpHUHt18BXzEGF4LBK+JW9EFerLqV1B96HYb MFUMahKLyNqaPRiBDerd3LI6CQx75GAbUcEU3Grnm3YjTYg4N9ENOvOudjdKksNKdqSE 4YLE4DeQWi7w4isA/zT432ONJUiCrKZuSLdUeL7i0imzWI4T6rskKjf42uS/cNr9El9E WVyvIPVeas14Fl/7Z0eEBgnPt0o5Db6ifGd1rUaGyOXRM4Plq4aEAv6v/LOeTqmp3Yis GSrg== X-Gm-Message-State: AFq9FYK4S1Eo376qLQc6J14O1JDJEOnB1j7m+VEzOwYys+5fDZLvAi43 upDQzeLWDI3irXhu7Q27vgcRsXY1L/c8QGo0wyXP/w403nl/te1mIqcPCBf5yGNaHmXZ8/GLnSc 25Z4bSfXK8DbP7QXmbPfRqJQvdD9CEIWBxKh8oHSORdlmAufdhvY6X0lgX8HU2fqhkg== X-Gm-Gg: AYBFou2NA0stTxl9qIVzGCK5KBjIBgtZ1yZbWeeCnQZs6Q7w2zq28aaB9rClkihFmG8 H+qQgEVT9H/S5UwgrLj+0UCyWCQuKBp99Tk1iM8fwXIKWq7vhZE+fci2+m9EchIobLLAcJN7kzR a3cU96Ys5/K70fH/geavPfEKkbUSZvyx2rgPm9GhY4gCuPaZDdIR9+NgACJEryT84imc6GiFINl /89pRpG36CzKeoi6vQGkS+bPBGDjR0ZN5uyg+/QBidIwyCkvoTk5vYFCkfxAtm4CXR7BbLQnlG2 GeR42fi3GtR1S9zH8r1j1HsxRg3LB+gJxkvY6eIl+Pp/r2XHc4do4C5cmydlmMtTQto8kaHCaAh 8NpCeyd3JJVO6FwLhq9OguM+u3oBxi93jVqVQmlVFRKcrNQQ4IGgJhgkee7F5HGTidulVNOy+qn HV8pm4EopneIkU9RiIUVf+Fi3d09Xo49QeZtbc8E47fd/xR5xXhAp22OIS4T/jpU1kWiSM3L1IR 0IM0a4V X-Received: by 2002:a05:701b:418d:20b0:147:d430:7322 with SMTP id a92af1059eb24-1ac585a6abemr23334241c88.1.1793608352166; Mon, 02 Nov 2026 00:32:32 -0800 (PST) X-Received: by 2002:a05:701b:418d:20b0:147:d430:7322 with SMTP id a92af1059eb24-1ac585a6abemr23334152c88.1.1793608351447; Mon, 02 Nov 2026 00:32:31 -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 v13 06/10] riscv: add RPMI HSM service Date: Mon, 2 Nov 2026 14:01:54 +0530 Message-ID: <20261102083159.3383468-7-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: PHre2FtPPL_t5unAWbM2oP_F5Amq2pF- X-Authority-Analysis: v=2.4 cv=bNaDs/+Z c=1 sm=1 tr=0 ts=6ae84aa1 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-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX4Vg2ofFkMIcz se1Xgoc8ccj3ua2Gnsj6kGxzsdXNYHAxB0Gz4Peq42d8UJprCDAH1Z3tZ5ze3BF9Kee29AqMsLN q8ZkPrvcbnlEa9Sx7+tlwTZ1+G049qObVK3wRDLqDMi8B+Yyi+Px+Wj12xpydUFA6BdDs+Vfux/ pehhviPU7Ws4eUw+3wxToz/h8a1aM0y4RDLKaeDk6UdsBia58YOZV8jpxpoOaXscot4u067ChRV yNOZeMN0QmjkwMe7tLV1qJtNfa2YpFNX29vcpN8MkUu0ItiZxgaGoWfLWMByOLQ4jP/Smag7G9R fzo5dHPWZxL9lEoagsNuQ14CntWVYZBvehT29xBPbOGst4xBWMHehfJ7GZsTH520NUou2ovvt2M GAryahxfD09TnJp0LJYIioZTOOsbocxaEFFM3zOUOZ+YquSiz2IO9ZmA8KhX94xLY/PDHi69qPo +mFrsIx9eVoGBFnIC6w== X-Proofpoint-GUID: PHre2FtPPL_t5unAWbM2oP_F5Amq2pF- X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXymVx0hn0VEZy aVOlWM/O3u6JuBZ2YSvBAJHNye0mSNxFozc65JBc+sEUU3WPrJhQXiiCHW/7IkhKgu1XRLAF7zG rr6oQLtcL3Jc3wllBptuGl93QaRzGkY= 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 adultscore=0 suspectscore=0 clxscore=1015 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 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: 1793608670884158500 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 87ea363199..00ae6f1b41 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -184,4 +184,5 @@ system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files= ('axiado_clk.c')) system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [files( 'riscv_rpmi.c', 'riscv_rpmi_sysreset.c', + 'riscv_rpmi_hsm.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 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 84c9d9a4a3..876dd450f7 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -478,6 +478,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 ae750f85c6..6cd70a67d7 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, @@ -966,6 +1021,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 @@ -987,6 +1046,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 80c0463617..1af25466ef 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, --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608398; cv=none; d=zohomail.com; s=zohoarc; b=MI5Y0Lr2y1RyWma0MCkFxcXYMBr5VYVsS7gqPGjpPimvAiHVSBer85SXdZfKymjMvZtJWAKh6Hmhwb4boqj+fQKX8Gyg0/zJFdxBl0+sZDPYtSVDv3omdd3zhaEmdr0FUWjb6T/t4CJURP5JvARFrAlS3PzuNy1Lykwf4EzWGUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608398; 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=o2WTlMn45svydn72LQlriq+X1SEu1otNlNrqtX8iKUs=; b=QWJ96gdW/wEuT2DmlaR0jxRdCnArBgz0DF6LegPXsD/cFbexTbtBk8X0iAKGYV7DT2t8UoxUrimjfgN1gcBnd3U9FFRX2j17Z5Uhke87EZriNhhQ4ftK9Jxhl9KvGGYVR9TMo4iupkmjZdFe3IQKg7TEtri/RKimzEeBaq4cGcU= 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 179360839894789.03259424452222; Mon, 2 Nov 2026 00:33:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnTV-0002v2-8H; Mon, 02 Nov 2026 03:33:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNnT6-0002pd-MK for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:41 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNnT4-0004pq-4v for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:40 -0500 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A23vJVA3324695 for ; Mon, 2 Nov 2026 08:32: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 4hn7b6p329-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:37 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-33bf1d17dfeso393925eec.2 for ; Mon, 02 Nov 2026 00:32:36 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:34 -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=o2WTlMn45sv ydn72LQlriq+X1SEu1otNlNrqtX8iKUs=; b=a6V6Avu7hTWJY38sTn3pRQquwk4 w5B6o4hAwXUPn4vLbroECIetw5n+Gp1PPo58wEU3FVYPdIMPWmbnvpaf7nixSj4T 8Ucm7VOy25yHzRM1uZ7c1iUDiM2m/zaDE/TIYw5vfCu4peUjh+JVMrhPwh9qaWqU +yYAZVuoLQe9L2b9u6dBrgR/7xoRAxqKTQhn4zZ5vglyX8QrUkeuS+6lWPMhjYlS M3X5BpyIURFfAT8ggngn5lVLd8XfctPylIZJGT7pZIA3FAEkhu/LStmT1n0TpCN/ tWlz/j/ruASaCWnmwMfSGwXEvKIq/G93zNyCrkQdE5tP8MhuhillrUcvhug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608356; x=1794213156; 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=o2WTlMn45svydn72LQlriq+X1SEu1otNlNrqtX8iKUs=; b=ExlMcHx/5ysEpx75hwYk9Id0GbaZz7uGAygqR/leO8Rg2Fd6H+wNelpV3ptCw+j4+w EIs8hdZzqjtwqSRvP9GW9Ef3ohd/EnRMXBIJ/i5K64edICcRYxCjkCFj8/rPxUb5PCVr d0Vt5VAY04TTukbhsq76k3eaCWz2vrC0DA6qrQspRrVkNVqJrJF/2A8muTczU6NvbhLF WjhhnYI6TGP9wtNiVqw7Ej57LtMJCO5bazQ7MHMFbQ17FUZYazEYYeigy7QkyNV8wJ7n PwZr8E4IBuO0S0mBs7XuB6VGMRzPqAu+ij2x1IxjqbGOVhf2emTFFjJ0QZkwBH+MbCAo eZWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608356; x=1794213156; 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=o2WTlMn45svydn72LQlriq+X1SEu1otNlNrqtX8iKUs=; b=iWW5tynvgIIjCsu5aiq3KAtYqXkB3qXtAhJXjL/wplmYINVoJIGOicfoH9n1U9rlpV T69r67lv/iIbog+tMFu507RhGNGagVrJ4p505cEjdpkZmlZ6F+L+DuRx6ZL2vqbekr92 BWMKHDtnm1XovEBO3xxytx3EpBrDVxNyokuIYQlEmeeo8yQ5b++J9T8Q4FOfAnaBWcLq Z1wlkml7siW1CeI4UL9XURynLHB8BqB2pXi5tz97BFGT0eiGMB9l5EbLcr3l+ZLPI38L HaH6avKXbn+Olfnu6+T5iR+jBSPJFANn7GKk+5zuFzcVu+oem6nI1DxfUYReXeFAwbyj v7OA== X-Gm-Message-State: AFq9FYKD3Nkda6JIg/HoxupoWOd7SbBLCt3KXNZtk5J6SbrEb73VZv1A i59DMs2rqCV9oaq13g5reKd+ypKLBUuuo9/xoL6arnxb9EtNEDIFr0YkfDWJPdWwlHYDKsjSCX1 jM+ElQTkEPDhZvmwtToJ5ZvU9hCNfyTyK50PD7mv7JXofbNNTT4DUp3v5vQfH0gNQjw== X-Gm-Gg: AYBFou3GtHF/jqRcMzAjqXEaqArU+C+NSIvciLAeWECoJp8AULJcPi2fGF8MvkBr+/2 EBb5JFXhzI0FV2pMpxIa/NQY1w2odjzCuAJBuG3Kf/8qoJcasGj1lb9EdrmrDNcbK8A3Y1g6AkM g4onv1fNPwhk8dcLWEjXo9xonFznX6il+R1ZLjXr3Zj2AtxyIUvDxNZaGXzGhhDkWHeKUVHHUNM 1UrJouw7n28U7GTKjbBp2pb/HapTd12Xr6pca0sPW5Q7xggP+OzL7a6t2R7X4lkwg18hHPkKUop hKUQZSB1mhOuEHM6w/7j8ZqTjyXtueIG51I7jD831RZDWuZrtToYtikLwmYXsK0Y+WQ6qDs7Lg5 fH2sKpXGh61Lue0Om2ef8rsFhRqm5AxPx9NEBKHZSDCUtaG9sPSNNHXTXDDY9hLalBbFGeMcC9x jn507+TWDFdiApk5PPL312QK/RbBeeQsiV6JP73H+06OlX2ZpWuYJHRALjD1pNWuVRNxBNwz3Qj HQSPgik X-Received: by 2002:a05:7022:c46:b0:1a1:9106:cfff with SMTP id a92af1059eb24-1ac5c45fd28mr20482673c88.2.1793608355909; Mon, 02 Nov 2026 00:32:35 -0800 (PST) X-Received: by 2002:a05:7022:c46:b0:1a1:9106:cfff with SMTP id a92af1059eb24-1ac5c45fd28mr20482636c88.2.1793608355245; Mon, 02 Nov 2026 00:32: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 v13 07/10] riscv: add RPMI system suspend service Date: Mon, 2 Nov 2026 14:01:55 +0530 Message-ID: <20261102083159.3383468-8-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: vfJpnHWPmchMxVBdTpGOuV5mMfIoBH7k X-Authority-Analysis: v=2.4 cv=QuvLTlyd c=1 sm=1 tr=0 ts=6ae84aa5 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=_glEPmIy2e8OvE2BGh3C:22 a=EUspDBNiAAAA:8 a=6a6dvNLtoisV_qPEzFoA:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-GUID: vfJpnHWPmchMxVBdTpGOuV5mMfIoBH7k X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX1nVqBU2OtNJJ +eWTZwzM5uNr7us0k4KrUejuMLMbevj2gL0GsoF9BNMKzJn9BVZjEbSntzRdXuv8maBe3BBNrSk yxc9J2V/+nNnU1vEcru6MIBvGZgE2+o= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX0SXKIx+9Ecj+ WPPmNLkeawfZ+eyBlo18skJTLPw4r64lUoKknXlYTb+RnsbsNXpf9G+lx2ZfJoO/fPtf47PjBIG MtooUDcfWbF3CBwrplEWgHNeBcEtUvuPTUOYN3UxZS1XSYX4bYd6XDUW1Ng4Mi8swP5SoTtA75U vjTuR9URIpYuFL/XeCweTx1uhJusXDaOx6eyJoJFgRmHN/MBFiy36AvZoz0b0696nlUFP0BolKH nZlE0+8SNZ/gzE+u/LR+Zr4VlcaBhk/rzXyv2716HBUj0T0KF5kAVdl31kJWc4E0+rpvvVI3UKx nkNCDsQDXgd50vBq+PNd3i5kLZCHfalUu2rQDY4UedZvNn2BbiQXOmprhFrcXCUE++9KfDcRT4o 7yUkWcJXvzdyl9ElWukCvXJSp7FByiZzhTsrBqyyf6x6033KxP3LVBFj1N/UT4azCUYm8F8BNa8 wNR8ykjOIjlCrm4YGHw== 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1793608400105158500 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. Signed-off-by: Subrahmanya Lingappa --- hw/misc/meson.build | 1 + 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 | 175 ++++++++++++++++++++++++++++++++++ hw/riscv/virt.c | 5 + include/hw/misc/riscv_rpmi.h | 9 ++ 7 files changed, 235 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 00ae6f1b41..b619452df3 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -185,4 +185,5 @@ system_ss.add(when: 'CONFIG_RISCV_RPMI', if_true: [file= s( 'riscv_rpmi.c', 'riscv_rpmi_sysreset.c', 'riscv_rpmi_hsm.c', + 'riscv_rpmi_syssusp.c', ), librpmi], if_false: files('riscv_rpmi-stub.c')) diff --git a/hw/misc/riscv_rpmi.c b/hw/misc/riscv_rpmi.c index 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..e614322330 --- /dev/null +++ b/hw/misc/riscv_rpmi_syssusp.c @@ -0,0 +1,175 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * RISC-V RPMI System Suspend service. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include "riscv_rpmi_internal.h" +#include "qemu/timer.h" +#include "system/runstate.h" + +static const struct rpmi_system_suspend_type riscv_rpmi_syssusp_types[] = =3D { + { + .type =3D RPMI_SYSSUSP_TYPE_SUSPEND_TO_RAM, + .attr =3D RPMI_SYSSUSP_ATTRS_FLAGS_RESUMEADDR, + }, +}; + +static enum rpmi_error riscv_rpmi_syssusp_prepare( + void *priv, rpmi_uint32_t hart_index, + const struct rpmi_system_suspend_type *syssusp_type, + rpmi_uint64_t resume_addr) +{ + RiscvRpmiState *s =3D priv; + + /* 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 876dd450f7..132387c740 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -483,6 +483,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; --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608414; cv=none; d=zohomail.com; s=zohoarc; b=TVzgoxMu3Xa1tqAdCeIsYcc7Wz2RLqNvVj9bQqVV3cmy2GtNFxF0uouLAOeWdedzANtKVLQVY+NeUSfwzzXp+pWLI9PXgLazSWRwiShtMtIEugxqtvInStSUHuRJ2/TdE76uJ8UA62XU82+tNpc6HbW0e7Z0rXKpIlYSKda94qs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608414; 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=TWBnGbwuz+qDPVFESpXXqRRCe0rhy78MEhLbH1dXTfI=; b=bPaSwcqrQf9bxXeuUAbNDj0dLltQiBV7aH7ikMSVJEH0myxNYtkJm6Tyl+ljfKQWE52j508EOAixhV7fu0/YNfwuvsA1tReiskZshpw5sV3itFd9Q4FCVLLVT1l489YQL2E6gePBrN74VozJhny+GYjhVPYOeNpBqRL5lq0FG8c= 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 1793608414212753.5676025344817; Mon, 2 Nov 2026 00:33:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnTf-0002xi-94; Mon, 02 Nov 2026 03:33:15 -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 1xNnTA-0002r0-CP for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:49 -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 1xNnT6-0004qK-O7 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:42 -0500 Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A24w2JF1262028 for ; Mon, 2 Nov 2026 08:32:39 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 4hpky4gqrk-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:39 +0000 (GMT) Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-313b1501a0aso400833eec.0 for ; Mon, 02 Nov 2026 00:32:39 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:37 -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=TWBnGbwuz+q DPVFESpXXqRRCe0rhy78MEhLbH1dXTfI=; b=XBPxHrwey+cdapik/ZE4JDX4WyT +pExIWAFjdA7qN9R4y5qTmTSK8HKJQMasv3fBulTT8tVQ3EhRqiDx5GQ+LWU+O6q 05giUGcYJhkO/OBcbus5vWXoAjrOEpLiquBrpkHW5qRVd39XpynA/PP6N8e3cqdi dXsO6tCFObKSrVopAFK6V3EqoLPlKF0VFsY03YPnPjnf8v2mIaKwhlgGklClW6cE nM3QB4czKR47KmJaj5lHgrUJ4s28wVhSFOfnG/EQNohlcnt+G9DaOm1aak71gg6O SmMh4j9eAAVusdLKpAQ3TFfgaeN1dDKrc7CXdROF5V08pQQf6946NGg2Q/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608359; x=1794213159; 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=TWBnGbwuz+qDPVFESpXXqRRCe0rhy78MEhLbH1dXTfI=; b=HkiCYTMCN97Jfzjx8wgeQ+urhfNp6ckRtcOLWQolIi3BMPvnaCBm0LY1CgPcaF+iAJ NB2aum3abbAEye3gDGvRijWbll91IsRixNV95WIFb486kM/WYbYL4OI0OnonWLig/Hy5 NVEfAWlfAj/FH80bCOzrstXdBhkfWDzGSWCnYlQrHhTUWoIgqeYZXM/9y7T2Bv9TBPLW NzcRXYa/VAu16cCczMLqbZNSQ13GaMFvQsx10Uw28Vm7FLWi+pMWC5SUR3UHBmIIJI3M ib+M0VRMdNNXPU7TmB93cLuM2fi1OBEXELPRKd3P9TV1jsWrZHv9T0CS0larelhq34PO EoQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608359; x=1794213159; 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=TWBnGbwuz+qDPVFESpXXqRRCe0rhy78MEhLbH1dXTfI=; b=wX07SfRWBGMs3KmlFwqUIYy3ACBZ+T7GLX3/d/lxYnHTLVfadOgplVXqDR1HctAdp2 DmPrV1yixMqEeXE3tR3igsihLFVd+EkfYX8w+hXFlPtJoo/YeEUUsPMq1kfc0Ly4bUdS V/p5zCxl3ifs+W5luWZ1cOhzVo6ZbI6vGqgjOze4LT/nSyTKVQhBlKPWhzdIQb0N+or4 6P50HpFwIzpnXpTfnSKSO3TGQbUTI/40xuZcJsI4tjkqx89uUeKOeyoWP359a607zkrJ eRSSOJaAwXcQgZghrEpKNCeoBEGF4KWHnVlZx2hc8Bt0pHJ0nHJ5XWSTKy7ZzkKY7qFm 8RwA== X-Gm-Message-State: AFq9FYLwqw5Ti1bv50r2VEGFYH5p8IRd+H60AvUjzodZ/vz17mauO3eL tgn6j5EB54vPvwayEzvbHaMGU/uBazwhwiIot1Opb7SEVn5E2gkmyKPQ/i7g1+QGbVehM1VfksJ mZW/iI+lYCMWpV3QMUqj4BXugKsg8g3GjmDXa4bM5XyX424nlst5bzCp5bd4hdvqd0Q== X-Gm-Gg: AYBFou1vh4uc9MIh46FcIZT85sSpAQaZPUSDP4JqUJEM0WmzVHI0hCLbCaG/oYiuMX0 8QOzo9mTFR7ausPgpE/WZPFdHPLKd4mRvh5EDgt3TxHuU+21uAmRyEjPNrPxjYvnMGLBg1wMxCF /bly+EuVhG3FfAUcleMTKWh9mYMMny1LiPke6bUNAyMqunPEyYCXXnIafU5dE0WQX7Fn6I7N552 9YuCA5AKRq+d1usolLqmD5ku6aTfkhvdWoZJd972O88TyhGcgP9TT8tZSzAaWAHfro23BJH2Tk6 4VQtbIulMPjMpbTpI80fpG0jekXKytjK1R/lKK1/dXn446yZP/DiUo6a+xAros+Og4ZSD8tYCle 2g68S4CJFeXB4FJi0sbSnKDRCfH2xL45BLvMLF6742AXV9dk/C/9JSe9rFzXubKMyIgXld9G4eH uLdWFUSEyWmeakISQ6y3VlGz1OEBgP1sJ1IVMkHHBY/PrEZVNIWiYA/ijFp/0zqmoQx7OaFSZ9F HdE7u6P X-Received: by 2002:a05:7022:b053:20b0:144:fd17:3b21 with SMTP id a92af1059eb24-1ac500d67e6mr24101767c88.0.1793608358498; Mon, 02 Nov 2026 00:32:38 -0800 (PST) X-Received: by 2002:a05:7022:b053:20b0:144:fd17:3b21 with SMTP id a92af1059eb24-1ac500d67e6mr24101720c88.0.1793608357888; Mon, 02 Nov 2026 00:32:37 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Daniel Henrique Barboza , Pierrick Bouvier Subject: [PATCH v13 08/10] docs/system/riscv: document initial virt RPMI support Date: Mon, 2 Nov 2026 14:01:56 +0530 Message-ID: <20261102083159.3383468-9-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: fLEJcYOl1cpJSpmATinBph4KAySXddMV X-Proofpoint-GUID: fLEJcYOl1cpJSpmATinBph4KAySXddMV X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXyRqju1CqBxeP RjKH45fI0BABeYM9u7TfkCX/XQn+7ven+7/tfaGr3aGJ3+NzY9mcvPtO7I+l2At3qmdDiXpM/20 MJs5j5CIJM5Ir2pnx5QLaw2wVpICFLQ= X-Authority-Analysis: v=2.4 cv=QoHLTlyd c=1 sm=1 tr=0 ts=6ae84aa7 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=DJpcGTmdVt4CTyJn9g5Z:22 a=NEAV23lmAAAA:8 a=V1jnuoLLAAAA:20 a=EUspDBNiAAAA:8 a=bNRx8rSjxjkR0t5bZ0UA:9 a=PxkB5W3o20Ba91AHUih5:22 a=bA3UWDv6hWIuX7UZL3qL:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfXyB/sZ9cxfnyT cG/VNMQJfX7Si1KSdOpOdN2i4hAPqY8xqzhOGrL/H871ce6MeBRZ66Q1VP9fM4NC55f1TEddiyi rXMgkWBeMC63mFokh2kD6kcbQ7goLfsXWaethqAP0oxl7UqegaMzPzcD7B9grNa3PMJYuRIGnyn 2oM95UfqprEfMSmBlvbyDeF/QEKkVuFE6T+i92VStuc1pGqVmTjBW5WfRGvmRyQxUB0EYj7d4Tp ro+Wxs1Fv8lxrneQsFg6Glw8LzrjwxXOM/D+Jc7Pz8p0fkdaKlcK9ej42xiv9Da1/odsJb5GOQw h2FQf70atwKjSnz8lhRuSmfPSXFEh4mqrFPrVxJG38rEq5OM1YxSNeDwTvwW5q+jIng3CfuJxPe obvLb/EDNxLrbjeFHm0qlaR6EDus5E2+jAmcwO+Frr5USnzLKB+TjL221ayrbaVvkuv13JDiPI0 SuW+BMEsUU0I7u1sLhQ== 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 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: 1793608416114154100 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 -------------------- =20 --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608718; cv=none; d=zohomail.com; s=zohoarc; b=RAfuFO4/jAd1/xSr5w6L1CIjS1PLOnunTtQO28vaNibTaqvCkfkmJ7hx04Oi3pqUl/W6Gu5+qaqZeJyZTSqSuWPrlzCJJ2Kg5RXhajT6Hjyj4PZIJPtdzdS+MP2G/m19oW1MVRBghAqWonmMXUOABZGkP7TG8kOOOHBbF7rKyi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608718; 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=RYDbxZ8ZHfKHq/QCPqCoHjkFq8hZ0UAyJnbjKIKsNb8=; b=D/RErdaApZqOlqA+Fg4oevI+09YYAqJiLAI3AwjAFWrOanq6Uv9oLtdQQqXFMYl72Li7++YzH+Ad16lMrgiR+GYxsydaGHhXi8MRS1uenceFdkfSf8MmbqffNXpDV4Xd609GaKbfeeHe02WbzFOAxw20xUJP/W/asKkBNWpspI0= 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 1793608718253255.13072114509907; Mon, 2 Nov 2026 00:38:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnXF-0005u8-W0; Mon, 02 Nov 2026 03:37: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 1xNnTI-0002sz-Jd for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:56 -0500 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xNnTC-0004r3-MP for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:51 -0500 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6A23vHNZ3324639 for ; Mon, 2 Nov 2026 08:32:44 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 4hn7b6p32t-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:44 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-36a6f57c066so79558eec.2 for ; Mon, 02 Nov 2026 00:32:44 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:42 -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=RYDbxZ8ZHfK Hq/QCPqCoHjkFq8hZ0UAyJnbjKIKsNb8=; b=QEacVqZlwdodB+R1/aZDud1tlyk rEMTJkPE7xdxCvWgHVg7nIOBff81wHC2r3/9093rS3wgw83EEZybiJ0H7J6oqGsh OgEZhh/B6NYj/7ZSfEBbAb7lQ+Duq7cRBu3XX77/CXRHlf2nnKVcjnA+qpty4bjn /vifz4Luf9Zb6hMyfn4m8ouZsIJR9xRxrIPpUTeL1Aj6ZREad9qgxio6QopXqDy+ PcNlqmogjpZ/QoFR9HE8z87oc/VpTV7AQwdNehOGQdFzEp3So28/qRpVNLxVzdYS xyqO9kz+/ina65Ob2wVE5a97yfekwR7dfTymcDrOAkrvVZaarEfJPdchGWA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608363; x=1794213163; 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=RYDbxZ8ZHfKHq/QCPqCoHjkFq8hZ0UAyJnbjKIKsNb8=; b=f/I4xV0/GsBUL4eu83NgpA6XbQDF6+0kyW2nYkWp4NH6fYx+hrIFMCJHHlVkRAEp6j wFtuCliCZSArZpqvGikygspNwLKOBv5cqqZVoYW17yBPcqkZM2RkafoC7Lx2WXRvxsVM aMlXfP3G3PVjjCcV8jXy0MC4ZNHcFbUOQXC3a5gk3JrJNgzwBjf2KZAEWYWdqkSisb+U VIpZWPoV3mPEkKLE3ACEqfJJLLNlrDlD7kY5RtjIewx5qqBJqunAr7xANz/wL/30aYXV kX8Thzbr2aSfneZl5BGzdNL1evrNnOLSj4GYCkClsgCwoyE6bC3DooD9XW2sfhSDHSTY Yhig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608363; x=1794213163; 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=RYDbxZ8ZHfKHq/QCPqCoHjkFq8hZ0UAyJnbjKIKsNb8=; b=aIoj7orJqzmpr6q1izBJYp6iohy+dSOyeqFGmmjn+ZYznUo6fBLZA+ap5QRG1vg6NO 3MYnRDwhbk7B3EsuQ+FL+H3HIgPrg6a3yts+27FB8O9faIzevo7tIW/Z1U7x6TT5GN/D B0Aj8YdwutgCZOWFQV6lvarBWN3rkqABoSoNPcUf1hnput+ZHPgs7h4KRBogzuSoPcTv QHXzSd38Jzyy/tXVt6TKfZ5jfZ0EctFG4wOjA9O0ZY8NwUS8YeuZoO/8tw/tDI1eI08h LDSc/RjTagY09ZniMD5AXc/wqz0MpAVJ62ZJXN/spyL68xyx2fqjM8jIoTaD4JhVtD0V WA7w== X-Gm-Message-State: AFq9FYIwvxh9g5mk9TjhmnCVB1Ta8f95GmTkckrL3Hqpt+pJwnVHfADA YVK7+cjRL7KawA9R/e17hjm/+RAxgRVU7zcXpnyyUcG0ZmGLjGWD0ipiDoLF3XYI7VAtRE8pS8N AV7Uz+sI50QheWyL/KTyVxQLaB8NZfQeJTkJwVJRneDndXlT6njM7aWPA1TS8rZ9uYw== X-Gm-Gg: AYBFou334MLe/G5oI6KwbZUC+JrXRBEnI6dF2A5caWaYJOGjCW2KkZB2XwaCbVdf/ir 5fRmwJ4zOFDqj3YCdxDV78uGDPwiO7zVYkikbvfKITVa/eC5g71kJV+gHmV0UgnfvJwOcRAuM7H ZsplU12ONMPdlR2qcLqLiDESpzqNQj+OOdOcLApXcKBzCFBIgGEYw6IlG1OpTaKjhKFMWRtp6JI R0rcq83jbCG1Jh+YrmO5wJZMXAVnUe2MNDynZKB1vGOv79UywnPnDGbQrZ1Al2LESyZGVMg8d1u opp9INAfGl8/kip944/GmD+Bs0qjC/W4apOS8G7UGZcdwSnqxtNVPxVCaZE0MajUyv/OCqJSbl2 xevmu4gdUlXy94dzZd3VnqcKHHfiNkQ6Epb1I80fTE4DRxxqpqgRhE3epa5GceXXeUfD0LSzSZi tNbjOAJKzUQzxy1klILb7lECKXUs5iJf5CTjo9eWjaDYH5PKFRSAwdoH/KYfqTB/e1jp/y/Ta4v vjmBlzi X-Received: by 2002:a05:7022:c90:b0:127:def:dd72 with SMTP id a92af1059eb24-1ac5914348dmr19777142c88.2.1793608363120; Mon, 02 Nov 2026 00:32:43 -0800 (PST) X-Received: by 2002:a05:7022:c90:b0:127:def:dd72 with SMTP id a92af1059eb24-1ac5914348dmr19777097c88.2.1793608362371; Mon, 02 Nov 2026 00:32:42 -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 v13 09/10] tests/qtest: cover initial RISC-V RPMI services Date: Mon, 2 Nov 2026 14:01:57 +0530 Message-ID: <20261102083159.3383468-10-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: Tdajfqy7ZIm7iREvVXB44N6orILjeoCU X-Authority-Analysis: v=2.4 cv=QuvLTlyd c=1 sm=1 tr=0 ts=6ae84aac 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=_glEPmIy2e8OvE2BGh3C:22 a=EUspDBNiAAAA:8 a=CgxbgbrB4M1EZRPeLE4A:9 a=6Ab_bkdmUrQuMsNx7PHu:22 X-Proofpoint-GUID: Tdajfqy7ZIm7iREvVXB44N6orILjeoCU X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX4BpCET3BGF/w fZ/8vLgaeD/EP8NHRXB6ZFsicv/RbMjRhokfukYY+Uim0CMmITT+H/benba8NG96we5uXUEupK5 NvneWCWibEatx4qViMnnptjqARRAdlM= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX+aHzqzqyNq2Y h0YLIUYqcZSxm55h5C9X3C+JetUQK+JUzKeJB3Zbxut8yPsE0hTnoCfBwaPS77KP0pHdlmvHdWt Iv7DK4tET/bBCEmCYgK4+DKYIs6q16ker95JA8QSQBEplPRtsuSGachmGLHR+iYaTn6lYmept52 Gw7RdcqZO42tln1eJnk1bI1FcDyLTG9ed7wjrW1poI66Ypfo5To81C/bzKdohoJnAgbD0Pfu8dJ 5LafL9cZz8/51ZTLWSgEOy8N2Bqmk0DAPfVi7dZxnfvCVdHAuJ47kGMAfWQzsYt0wmNa3LHVQvs d9rpiHLnUfLHQ3KjE7wcDRMmrd0Dwt7HqLnqPB1rfCifMhTupoKvnRIIkpF71/hCH6Yy+vRlNDM MNnpkxTQjELJRSBNkkXNAma/yojHsYPRbuSHgEoe0HwOCGx7jNrmUNZsEPsfiTKfEB7jKbP2qMT 3z/TuYnM5jwmhzfFF6Q== 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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 malwarescore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=subrahmanya.lingappa@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1793608719933158500 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. Signed-off-by: Subrahmanya Lingappa --- MAINTAINERS | 1 + tests/qtest/meson.build | 3 + tests/qtest/riscv-rpmi-test.c | 685 ++++++++++++++++++++++++++++++++++ 3 files changed, 689 insertions(+) create mode 100644 tests/qtest/riscv-rpmi-test.c diff --git a/MAINTAINERS b/MAINTAINERS index b0afe3fe0e..cc71369b7a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -378,6 +378,7 @@ F: hw/riscv/ F: hw/intc/riscv* F: hw/misc/riscv_rpmi* F: include/hw/misc/riscv_rpmi.h +F: tests/qtest/riscv-rpmi-test.c F: include/hw/char/riscv_htif.h F: include/hw/riscv/ F: common-user/host/riscv* diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 46685d6d46..0a2ece0bed 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -314,6 +314,8 @@ qtests_riscv32 =3D \ =20 qtests_riscv64 =3D ['riscv-csr-test'] + \ (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RISCV_RPMI') ? + ['riscv-rpmi-test'] : []) + \ (config_all_devices.has_key('CONFIG_IOMMU_TESTDEV') and config_all_devices.has_key('CONFIG_RISCV_IOMMU') ? ['iommu-riscv-test'] : []) + \ @@ -436,6 +438,7 @@ qtests =3D { 'pnv-xive2-test': files('pnv-xive2-common.c', 'pnv-xive2-flush-sync.c', 'pnv-xive2-nvpg_bar.c'), 'qos-test': [chardev, io, qos_test_ss.apply({}).sources()], + 'riscv-rpmi-test': [files('riscv-rpmi-test.c'), fdt], 'tpm-crb-swtpm-test': [io, tpmemu_files], 'tpm-crb-test': [io, tpmemu_files], 'tpm-tis-swtpm-test': [io, tpmemu_files, 'tpm-tis-util.c'], diff --git a/tests/qtest/riscv-rpmi-test.c b/tests/qtest/riscv-rpmi-test.c new file mode 100644 index 0000000000..16b4be2320 --- /dev/null +++ b/tests/qtest/riscv-rpmi-test.c @@ -0,0 +1,685 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * QTests for RISC-V RPMI devices. + * + * Copyright (c) 2026 Qualcomm Technologies, Inc. + * Author: + * Subrahmanya Lingappa + */ + +#include "qemu/osdep.h" +#include +#include +#include "libqtest.h" +#include "qobject/qdict.h" + +#define RPMI_SHMEM_BASE 0x10200000ULL +#define RPMI_DOORBELL_BASE 0x10230000ULL +#define RPMI_SLOT_SIZE 64 + +#define RPMI_A2P_HEAD RPMI_SHMEM_BASE +#define RPMI_A2P_TAIL (RPMI_SHMEM_BASE + RPMI_SLOT_SIZE) +#define RPMI_A2P_SLOT0 (RPMI_SHMEM_BASE + 2 * RPMI_SLOT_SIZE) + +#define RPMI_SRVGRP_BASE 0x0001 +#define RPMI_SRVGRP_SYSTEM_RESET 0x0003 +#define RPMI_SRVGRP_SYSTEM_SUSPEND 0x0004 +#define RPMI_SRVGRP_HSM 0x0005 +#define RPMI_BASE_SRV_GET_PLATFORM_INFO 0x05 +#define RPMI_BASE_SRV_PROBE_SERVICE_GROUP 0x06 +#define RPMI_SYSRST_SRV_GET_ATTRIBUTES 0x02 +#define RPMI_SYSRST_SRV_SYSTEM_RESET 0x03 +#define RPMI_HSM_SRV_GET_HART_STATUS 0x02 +#define RPMI_HSM_SRV_GET_HART_LIST 0x03 +#define RPMI_HSM_SRV_GET_SUSPEND_TYPES 0x04 +#define RPMI_HSM_SRV_GET_SUSPEND_INFO 0x05 +#define RPMI_HSM_SRV_HART_START 0x06 +#define RPMI_HSM_SRV_HART_STOP 0x07 +#define RPMI_HSM_SRV_HART_SUSPEND 0x08 +#define RPMI_SYSSUSP_SRV_GET_ATTRIBUTES 0x02 +#define RPMI_SYSSUSP_SRV_SYSTEM_SUSPEND 0x03 +#define RPMI_MSG_NORMAL_REQUEST 0x00 +#define RPMI_MSG_POSTED_REQUEST 0x01 +#define RPMI_MSG_ACKNOWLEDGEMENT 0x02 +#define RPMI_SYSRST_TYPE_SHUTDOWN 0x00 +#define RPMI_SYSRST_TYPE_COLD_REBOOT 0x01 +#define RPMI_SYSRST_TYPE_INVALID 0x03 +#define RPMI_SYSRST_ATTRS_FLAGS_RESETTYPE 1 +#define RPMI_TOKEN 0x55aa +#define RPMI_ERR_NOTSUPP 0xfffffffeU +#define RPMI_ERR_INVALID_PARAM 0xfffffffdU +#define RPMI_ERR_INVALID_ADDR 0xfffffffbU +#define RPMI_ERR_DENIED 0xfffffffcU +#define RPMI_HSM_HART_STATE_STARTED 0x00 +#define RPMI_HSM_HART_STATE_STOPPED 0x01 +#define RPMI_HSM_HART_STATE_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 + 16 * RPMI_SLOT_SIZE) +#define RPMI_P2A_ACK_HEAD RPMI_P2A_ACK_BASE +#define RPMI_P2A_ACK_TAIL (RPMI_P2A_ACK_BASE + RPMI_SLOT_SIZE) + +static uint64_t rpmi_response_base; + +static uint64_t rpmi_queue_slot(uint64_t queue_base, uint32_t index) +{ + return queue_base + (index + 2) * RPMI_SLOT_SIZE; +} + +static void rpmi_send_request(QTestState *qts, uint16_t service_group, + uint8_t service_id, uint8_t request_type, + const uint32_t *data, size_t data_words) +{ + uint32_t tail =3D qtest_readl(qts, RPMI_A2P_TAIL); + uint64_t slot =3D rpmi_queue_slot(RPMI_SHMEM_BASE, tail); + size_t i; + + qtest_writew(qts, slot, service_group); + qtest_writeb(qts, slot + 2, service_id); + qtest_writeb(qts, slot + 3, request_type); + qtest_writew(qts, slot + 4, data_words * sizeof(*data)); + qtest_writew(qts, slot + 6, RPMI_TOKEN); + + for (i =3D 0; i < data_words; i++) { + qtest_writel(qts, slot + 8 + i * sizeof(*data), data[i]); + } + + g_test_message( + "RPMI_A2P_REQ shmem=3D0x%016" PRIx64 " doorbell=3D0x%016" PRIx64 + " group=3D0x%04x service=3D0x%02x type=3D0x%02x data_len=3D%zu" + " token=3D0x%04x a2p_tail=3D%u slot=3D0x%016" PRIx64, + (uint64_t)RPMI_SHMEM_BASE, (uint64_t)RPMI_DOORBELL_BASE, + service_group, service_id, request_type, data_words * sizeof(*data= ), + RPMI_TOKEN, tail, slot); + + qtest_writel(qts, RPMI_A2P_TAIL, (tail + 1) % 16); + qtest_writel(qts, RPMI_DOORBELL_BASE, 1); +} + +static uint32_t rpmi_response_word(QTestState *qts, unsigned int word) +{ + return qtest_readl(qts, rpmi_response_base + 8 + word * sizeof(uint32_= t)); +} + +static void test_rpmi_virt_fdt_service_nodes(void) +{ + static const struct { + const char *name; + uint32_t service_group; + } services[] =3D { + { "sysreset", RPMI_SRVGRP_SYSTEM_RESET }, + { "hsm", RPMI_SRVGRP_HSM }, + { "suspend", RPMI_SRVGRP_SYSTEM_SUSPEND }, + }; + g_autofree char *dtb_path =3D NULL; + g_autofree char *dtb =3D NULL; + gsize dtb_size; + const fdt32_t *prop; + int mailbox_offset; + int phandle_len; + uint32_t mailbox_phandle; + QTestState *qts; + + dtb_path =3D g_strdup_printf("%s/riscv-rpmi-fdt-%u.dtb", + g_get_tmp_dir(), (unsigned)getpid()); + qts =3D qtest_init("-machine virt,rpmi=3Don -display none -S"); + qtest_qmp_assert_success(qts, + "{ 'execute': 'dumpdtb', 'arguments': " + "{ 'filename': %s } }", dtb_path); + qtest_quit(qts); + + g_assert_true(g_file_get_contents(dtb_path, &dtb, &dtb_size, NULL)); + g_assert_cmpint(fdt_check_header(dtb), =3D=3D, 0); + + mailbox_offset =3D fdt_path_offset(dtb, "/soc/mailbox@10200000"); + g_assert_cmpint(mailbox_offset, >=3D, 0); + prop =3D fdt_getprop(dtb, mailbox_offset, "phandle", &phandle_len); + g_assert_nonnull(prop); + g_assert_cmpint(phandle_len, =3D=3D, sizeof(*prop)); + mailbox_phandle =3D fdt32_to_cpu(*prop); + + for (size_t i =3D 0; i < ARRAY_SIZE(services); i++) { + g_autofree char *service_path =3D + g_strdup_printf("/soc/%s", services[i].name); + int service_offset =3D fdt_path_offset(dtb, service_path); + int child_offset =3D fdt_subnode_offset(dtb, mailbox_offset, + services[i].name); + int mboxes_len; + + g_assert_cmpint(service_offset, >=3D, 0); + g_assert_cmpint(child_offset, =3D=3D, -FDT_ERR_NOTFOUND); + prop =3D fdt_getprop(dtb, service_offset, "mboxes", &mboxes_len); + g_assert_nonnull(prop); + g_assert_cmpint(mboxes_len, =3D=3D, 2 * sizeof(*prop)); + g_assert_cmphex(fdt32_to_cpu(prop[0]), =3D=3D, mailbox_phandle); + g_assert_cmphex(fdt32_to_cpu(prop[1]), =3D=3D, + services[i].service_group); + } + + g_assert_cmpint(g_remove(dtb_path), =3D=3D, 0); +} + +static void rpmi_expect_ack(QTestState *qts, uint16_t service_group, + uint8_t service_id, uint16_t data_len) +{ + uint32_t head =3D qtest_readl(qts, RPMI_P2A_ACK_HEAD); + uint32_t tail =3D qtest_readl(qts, RPMI_P2A_ACK_TAIL); + + g_assert_cmphex(tail, !=3D, head); + rpmi_response_base =3D rpmi_queue_slot(RPMI_P2A_ACK_BASE, head); + g_assert_cmphex(qtest_readw(qts, rpmi_response_base), =3D=3D, service_= group); + g_assert_cmphex(qtest_readb(qts, rpmi_response_base + 2), =3D=3D, + service_id); + g_assert_cmphex(qtest_readb(qts, rpmi_response_base + 3), =3D=3D, + RPMI_MSG_ACKNOWLEDGEMENT); + g_assert_cmphex(qtest_readw(qts, rpmi_response_base + 4), =3D=3D, data= _len); + g_assert_cmphex(qtest_readw(qts, rpmi_response_base + 6), =3D=3D, + RPMI_TOKEN); + g_test_message( + "RPMI_P2A_ACK shmem=3D0x%016" PRIx64 + " group=3D0x%04x service=3D0x%02x type=3D0x%02x data_len=3D%u" + " token=3D0x%04x p2a_head=3D%u slot=3D0x%016" PRIx64 + " status=3D0x%08x", + (uint64_t)RPMI_SHMEM_BASE, service_group, service_id, + RPMI_MSG_ACKNOWLEDGEMENT, data_len, RPMI_TOKEN, head, + rpmi_response_base, + data_len >=3D sizeof(uint32_t) ? rpmi_response_word(qts, 0) : 0); + qtest_writel(qts, RPMI_P2A_ACK_HEAD, (head + 1) % 16); +} + +static void rpmi_send_sysreset(QTestState *qts, uint32_t reset_type, + uint8_t request_type) +{ + rpmi_send_request(qts, RPMI_SRVGRP_SYSTEM_RESET, + RPMI_SYSRST_SRV_SYSTEM_RESET, request_type, + &reset_type, 1); +} + +static void rpmi_expect_qemu_failure(const char *extra_args, + const char *stderr_needle) +{ + g_autoptr(GError) error =3D NULL; + g_auto(GStrv) split_args =3D NULL; + g_autoptr(GPtrArray) argv =3D g_ptr_array_new(); + g_autofree char *stderr_data =3D NULL; + gint wait_status; + gboolean spawned; + + g_assert_true(g_shell_parse_argv(extra_args, NULL, &split_args, &error= )); + g_assert_no_error(error); + + g_ptr_array_add(argv, (gpointer)qtest_qemu_binary(NULL)); + for (char **arg =3D split_args; *arg; arg++) { + g_ptr_array_add(argv, *arg); + } + g_ptr_array_add(argv, NULL); + + spawned =3D g_spawn_sync(NULL, (char **)argv->pdata, NULL, + G_SPAWN_STDOUT_TO_DEV_NULL, + NULL, NULL, NULL, &stderr_data, + &wait_status, &error); + g_assert_true(spawned); + g_assert_no_error(error); + g_assert_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, 0x1000); + qtest_writel(qts, RPMI_DOORBELL_BASE, 1); + g_assert_cmphex(qtest_readl(qts, RPMI_A2P_HEAD), =3D=3D, 0); + g_assert_cmphex(qtest_readl(qts, RPMI_P2A_ACK_TAIL), =3D=3D, 0); + + qtest_quit(qts); +} + +static void test_rpmi_migration_blocked(void) +{ + QTestState *qts; + QDict *error; + const char *desc; + + qts =3D qtest_init("-machine virt,rpmi=3Don -S"); + error =3D qtest_qmp_assert_failure_ref(qts, + "{ 'execute': 'migrate'," + " 'arguments': { 'uri': 'exec:cat > /dev/null' } }"); + desc =3D qdict_get_try_str(error, "desc"); + + g_assert_nonnull(desc); + g_assert_nonnull(strstr(desc, "non-migratable device")); + g_assert_nonnull(strstr(desc, "riscv-rpmi")); + + qobject_unref(error); + qtest_quit(qts); +} + +static void 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); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + if (qtest_has_machine("virt")) { + qtest_add_func("/riscv/rpmi/fdt/service-nodes", + test_rpmi_virt_fdt_service_nodes); + qtest_add_func("/riscv/rpmi/machine/realize-off", + test_rpmi_machine_realize_off); + qtest_add_func("/riscv/rpmi/machine/rejects-too-many-harts", + test_rpmi_machine_rejects_too_many_harts); + qtest_add_func("/riscv/rpmi/base/platform-info", + test_rpmi_base_platform_info); + qtest_add_func("/riscv/rpmi/base/probe-service-groups", + test_rpmi_base_probe_service_groups); + qtest_add_func("/riscv/rpmi/sysreset/attrs", + test_rpmi_sysreset_attrs); + qtest_add_func("/riscv/rpmi/sysreset/shutdown", + test_rpmi_sysreset_shutdown); + qtest_add_func("/riscv/rpmi/sysreset/cold-reboot", + test_rpmi_sysreset_cold_reboot); + qtest_add_func("/riscv/rpmi/sysreset/invalid-type", + test_rpmi_sysreset_invalid_type); + qtest_add_func("/riscv/rpmi/reset/clears-transport", + test_rpmi_reset_clears_transport); + qtest_add_func("/riscv/rpmi/negative/doorbell-invalid-access", + test_rpmi_doorbell_invalid_access); + qtest_add_func("/riscv/rpmi/negative/queue-bounds", + test_rpmi_queue_bounds); + qtest_add_func("/riscv/rpmi/reset/repeated-after-traffic", + test_rpmi_repeated_reset_after_traffic); + qtest_add_func("/riscv/rpmi/migration/blocked", + test_rpmi_migration_blocked); + qtest_add_func("/riscv/rpmi/hsm/hart-list", + test_rpmi_hsm_hart_list); + qtest_add_func("/riscv/rpmi/hsm/multi-socket-hart-list", + test_rpmi_hsm_multi_socket_hart_list); + qtest_add_func("/riscv/rpmi/hsm/hart-status", + test_rpmi_hsm_hart_status); + qtest_add_func("/riscv/rpmi/hsm/hart-control", + test_rpmi_hsm_hart_control); + qtest_add_func("/riscv/rpmi/syssusp/attrs-and-suspend", + test_rpmi_syssusp_attrs_and_suspend); + } + + return g_test_run(); +} --=20 2.43.0 From nobody Mon Nov 23 04:28:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793608487; cv=none; d=zohomail.com; s=zohoarc; b=RL6DojUPo/myA7IOGHYGf6pymfGj6hof/7W4JUsdrbzwV2ItFwEqvKlGGEmU4Io6Cb2ByxGCpV70Hnew/tk7UmehT5IKscHuBTwk/NZoSV7geJU8+6iJYRXsdGj4Ni9N2QQpGL21VN8xdV88xkTUwjZc67glmOaXB1tsPlZbY7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793608487; 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=ri0ajYQs99J8UGNO5ccZsqsRjx8awDzcrCveS/lI9yc=; b=Iu408lZ8EClwxjCJX2Eb0Kr27YsISvWdNzdfqMM3MLMcRvwizgGZolhQuncJTpud3cxzx5eyiBGnhyKl8LV5HSFim2P7L0rQW9PSvtPPNWmk/LnEuscqAiESUNqRHhbxbOSUZOnW83qgq22rI1Nsdvil4PYpHxqC6ftkdip32Xk= 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 1793608487747246.54929894676673; Mon, 2 Nov 2026 00:34:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xNnTv-00034v-1n; Mon, 02 Nov 2026 03:33:33 -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 1xNnTM-0002tP-Bt for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:33:00 -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 1xNnTG-0004rQ-E0 for qemu-devel@nongnu.org; Mon, 02 Nov 2026 03:32:55 -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 6A24CcBh1811538 for ; Mon, 2 Nov 2026 08:32:48 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 4hpk9rguge-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 02 Nov 2026 08:32:48 +0000 (GMT) Received: by mail-dy1-f200.google.com with SMTP id 5a478bee46e88-36a137058c5so395385eec.1 for ; Mon, 02 Nov 2026 00:32:47 -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 a92af1059eb24-1b106edc7f8sm15083213c88.9.2026.11.02.00.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2026 00:32:46 -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=ri0ajYQs99J 8UGNO5ccZsqsRjx8awDzcrCveS/lI9yc=; b=EOJMafBvXfngAKW/Mk0YpXq1lnC mzkijYcF5NGHXGQkPrudJBWNE8O8SQgDGoMkKhi/1yv8KXmxvG6cRGO0ORPhh+Kr g7E8q+TjkiRd4kjlPwCaNkpQS6PWpvuK5mhuJwaN/+TUgdqttqUkz/vhTqMyZLrE nl4Ki3hMR0V1WwyjXBgqMOEpG5yDaPXhcScvw4kFBP5tkPlYnsewBGDPa+N9Ee5W SN+39yIm9djw5t3MWM/B0YNMaIP4ucQ0A7P2vCbYOwDL1tLEcOdE2iRpDpzw2gxw sRuzgdBnkZq0CiZR3zW2X5/q3g3jNy0m9RoS7z5s1jFkpb75v6ucmJ0eeVw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793608367; x=1794213167; 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=ri0ajYQs99J8UGNO5ccZsqsRjx8awDzcrCveS/lI9yc=; b=Vjtm8xlnzDV6gZJb0W1dWHG/CXQudceGl4SXvUBHA3sGQB6jBTMGzWvmoAWovMFJ7H QRdKT1Ke9uaT6hURBfiaR1Au74Bz+cb1cd7g8TS8d+X4Dfgt+Qk3WGz5/7WtJq17ljTj tAQc1SziYDOkmnv4Ywdks43z0OsPCXO8UFSu18ms3XKNB7zG8vnDbvMAGcix7jFMfYZh uSEG9O4IzWXIYZkvDZYkUHiPJLYigeicnKTmW1Sq9z2FOnRurGfjozsGjgAeKhjx0daU WMpjQ/9tnlqAGoJP/SbWkIHh6L6X5Nc1otSDnckJCqpiIVpqA+0dfGnjFee4Z6mkYaxr eUdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793608367; x=1794213167; 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=ri0ajYQs99J8UGNO5ccZsqsRjx8awDzcrCveS/lI9yc=; b=kW0Jmg32xgwZ2KphN6YMtPIlpg1S4QtlNm/0NdFnCVmRMSuuJypzciw/0DZUqPMSHl BXLqb8RZKyZ93I8UrLnwR2GciTpiczp1tJa8BUOOA7+ohFFwPos7Bg37+V8PW/RAsDr7 qBUtZY0Lli14NC0zKoSYTcPIpm8zEtczbCjdMyQgRlT8R6fOBAD3ndOIIhmEAGGi3t6T 591An4vgaiNhqvP1xbP4ysiLQTE4kabocq889xWBeq9dM2UFsBYzNUKjlwebzj+fNVtK N636FIYF14c9Ap1QyXSleoc1e7CJjpH0VflcN8Ln5HgrHxUNMz5SglLtpCvdC2eHp7DH dA1A== X-Gm-Message-State: AFq9FYLydtqZfs2ia1dKIH9+/v7bajjpwHVf1MpCRKTAjuwk1SmZl7tR 65M4+i2NuVZvK1uqOyrTeVvkkESbTBjUa7Qd03onOwV69xTWsGVQm38/lzm/pV40zApw+UhtlO1 qTg+DIJQYecu5xnnkGz9TVkqkes5QCv79WhzP9HLXbNpz1mRwQ3tEPrDc/UhhbhR9OA== X-Gm-Gg: AYBFou2rvGkwSseEh4n4XZlXcCKNPtEbNAkctN/a3XZ2Krkng5BZYCJuzKFX/ZWI8Da IuBdP0z9/OHPym06L6m8vAC2XCy8BrPE9MwUFqrpO7FcZCKY4njL5vF4s5ozWupfGvZ2LWV9XNl Af/e+ae9LKRoZkjNG6PEaWJ35eJBUr+FC9zkas6vykz0QO7/zls4p4PtwcYTWgZ7MXwCgTI5W4i GVx6czGowuZLbaobeWuQBrs1vTbVsYMKXJBeAoWpYWuho3cRzkJQNo1UagEzdjEGK3las5ewEk2 UzgyM5gXr3MFZauA4qE78dJUqb+EMzSdC2KDufcX8ekqXwBORhmLDvdXXgjJo1mZ+PC1Z42ggA9 8uRmgz9LcvkGzLojVBdPp6JmYbPnt9pIAKloMGbdtqs/fPd9lKTygf8ADZYGiABNx7BPeceP4az fGkCNhsBnoeUpseZ3O4XB6eAY+yrwSCJi8vKMHBrW204DuwYghxt7UzH1w8g/kWE6WlvaWI9r48 ljNsOBZ X-Received: by 2002:a05:701b:2302:b0:183:d275:cf76 with SMTP id a92af1059eb24-1ac59dd0e2emr21253692c88.2.1793608367023; Mon, 02 Nov 2026 00:32:47 -0800 (PST) X-Received: by 2002:a05:701b:2302:b0:183:d275:cf76 with SMTP id a92af1059eb24-1ac59dd0e2emr21253647c88.2.1793608366295; Mon, 02 Nov 2026 00:32:46 -0800 (PST) From: Subrahmanya Lingappa To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Subrahmanya Lingappa , Subrahmanya Lingappa , Palmer Dabbelt , Alistair Francis , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Chao Liu Subject: [PATCH v13 10/10] tests/functional: add initial RPMI virt guest smoke Date: Mon, 2 Nov 2026 14:01:58 +0530 Message-ID: <20261102083159.3383468-11-subrahmanya.lingappa@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> References: <20261102083159.3383468-1-subrahmanya.lingappa@oss.qualcomm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: 7H5E8Hcl_TDOo9HtNrGsbWIPHfETO7Ph X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX+bVDYVH23SYh s/Xs4zohPsHXnJvRnYIaR6uYOxWkatusrPeVKvXfvW3MNjkGgRHBqBSlRtut7iUiFPPMj+6+qjE 20yS9pklyb91HfeRxR0wJgWcXZLZjPqzPrDzwGqAdNAaZVId12HIaqF0rhwmhCoSWB/Iaj+LDR9 b0f6sCjwD4TZlS3T6+CnTIm6CHYaOnNb1O5U/FX1DrRMI4oYMjsDAiwfo55DpA0iqhhFFIr9cU2 4dqTKnSI1Z55K69LCn/+0YuUUKx7ZFyBAUST400awaFti7XAYYQeLbCHbSB59CXzdtZ2UtbWHfE Rjc3gM5tGIIGEoRoVxcIR/ADHAJkEY+7LagIZAXYh1SdYbFdZawJAkZ3/+h0iNGvjgOGgsfnbR4 SU7vaXjjMyTijI6xRLN9UCyy/7+UQdGcVEB0mNGhwEvyrPrlhm8qxNez5AJuMbemEudfTY8j0fA tZyftH7vC/H646ZIavw== X-Proofpoint-GUID: 7H5E8Hcl_TDOo9HtNrGsbWIPHfETO7Ph X-Proofpoint-Spam-Info: AW1haW4tMjYxMTAyMDAzMyBTYWx0ZWRfX31lfTmYPh2sV 7XAnq1XWeW1/WcRqQS5r4YRRLi1dfWPHpZkEG22SDJV/6VZSWtn7kxzA+vdjn1K4fiUafhe5a2D SrWNp1d62hb4AGLJgjj/420vNd9bX/s= X-Authority-Analysis: v=2.4 cv=LvwHWXdc c=1 sm=1 tr=0 ts=6ae84ab0 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=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-02_02,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 adultscore=0 suspectscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610300000 definitions=main-2611020033 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: 1793608491215154100 Content-Type: text/plain; charset="utf-8" From: Subrahmanya Lingappa Boot an RPMI-enabled RISC-V virt guest and exercise the initial HSM, system suspend, and system reset paths. 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() --=20 2.43.0