From nobody Sun Dec 6 20:46:09 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=1796218553; cv=none; d=zohomail.com; s=zohoarc; b=lfT2QFyLm9zv+Sh5hBttgXsvJSB11ZBEAg7ytW2P+KNnhrmYdlulOXCH/iaurZ2RXNeoFWwDBR3sCRSCq7zyM+Tas98bHC82ZDWwEm7qqVd93ZwEJ6PU61NDs4cLK6177l1ygMqdi6Cf55OrqzL6lroclSoD75LP4Fx2CiV15TQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796218553; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From: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=Ycpicf9kURmpYOE9h/Xi/+NmwQ6BJ5qD4ad7+zAl7Aw=; b=l+1MLh40Xj/8e2l6RBOfuAWVrtDJIW5svaU79genjMZWVSc3gF/8zFPvlNYLcAYdCckW61Ueqigvjf28jc9n01VOWm0NCmzgEWwq6sv2bHDaoCzyMmPoUWu1UU8lXugM9Q+sxnj5Hp5J1+22Sst3kIoLNuS/4WVyzHoEUIzqgo8= 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 1796218553400283.1041089041121; Wed, 2 Dec 2026 05:35:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xYkUb-0005yY-Lx; Wed, 02 Dec 2026 08:35:29 -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 1xYjgx-0000FY-N5 for qemu-devel@nongnu.org; Wed, 02 Dec 2026 07:44:11 -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 1xYjgu-0003J9-Sa for qemu-devel@nongnu.org; Wed, 02 Dec 2026 07:44:11 -0500 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2CC5iI3684826 for ; Wed, 2 Dec 2026 12:44:06 GMT Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ja4k1bm1v-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 02 Dec 2026 12:44:06 +0000 (GMT) Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-1b58804285aso139964c88.2 for ; Wed, 02 Dec 2026 04:44:06 -0800 (PST) Received: from bhaskar-desktop.localdomain ([106.222.234.87]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b556847fdasm103635675c88.13.2026.12.02.04.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 04:44:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=Ycpicf9kURmpYOE9h/Xi/+ NmwQ6BJ5qD4ad7+zAl7Aw=; b=i6iyTREd8JoMffHLg7BemqtzMRlKf0+DOqAcXT xM0cn4IZ87MdhOaNClcBHZ0lBGM3V6fqT4R77SbZIQcqXSELkxHxTns/Vj3CzWbr TdiKXgIKFmgiF17dYmQqmk6DLe0FHhgBdf3Y3PdUI7Xq4VJB+R0uitAAbZE9dQ/8 nUu0mwQHk2ES+PriV5uHg5Hg7alY0ppk1uzUJe/aXHtLcgMdb+/koHw84Rl3E+UZ LESrTmatJi5e65Y+lkE0I728av0ilD3lI7M1ClPZp5to7Oev8b24T9SW1d0CHmSM 4wV0uIIkRjBDe6CqraJy8vZv9D8n9tAmKKCNX/9BW5ZLPQGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796215445; x=1796820245; darn=nongnu.org; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=Ycpicf9kURmpYOE9h/Xi/+NmwQ6BJ5qD4ad7+zAl7Aw=; b=L6on9SIDetcUi93pRQjr2G4od9m9/G48tAVE64r8lwa9tQqAXDlC7EMr6bvqnc7U11 VU6H+aGKcqs9S4G31ivZp3mTZWD4N7cWkCElweZH4aYvWH5qLZpmgnSFrRXW0r8/KJGh RPGRfZI02fwIieNIBr7jAjn+KvJmVrhJ+AZhxEUR0uPehnAE3LrXhZWsFAYPBZoa4UUo qBEqQpHPz1yJLPyY/taiioDS/7fNJLj9e6iQpmTlBfNnhgo2w+A7PnCHMfoZ/waI21l9 SC6S0o4ip8qFEPByl3wqeh2oWEeEv0E7bpzXGI09HkJ5pXDXyfj2kuXLCR+W5NkOJhf0 JbYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796215445; x=1796820245; h=cc:to:message-id:content-transfer-encoding:content-type :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=Ycpicf9kURmpYOE9h/Xi/+NmwQ6BJ5qD4ad7+zAl7Aw=; b=UXgON0uzadxWXYbgJSjSiu87Iz9wrneerQ4n3EfjfxZEf4/TM7IGj5slI49vL/hNos OtGTY7aigpfQRgdFCgfU6O04epVxEJDG7fwhtZTW0KhDN5iigqt4BivG1/KvkSyd4l1u Js7iWo1oHMmDQm7KGr95CnCMv3evLkpvL3Xw2Y+du/SyJ2Q+HKHOVI1P4qtjJdgGDsR7 bAwyXO6GVXSjbcHNHQjfitSUACh/gldFwicIaV7kl9JyRxFwx+o0SxE4s/4FSxgw0FGi /7PAJC+UuPzOh8hr43H71xm8HWplpPv9hVhGmkNdDrg4MAplWnOQsKz/re/jbfedhyJc aSyA== X-Gm-Message-State: APuU4Z98nxvfQc4Y7aEQw1lVldzyXh0lLK8ij8sHKHs5qRczusWaFzgw kgvcy995ydaPrVEZ1xL21RloQWNX1XLbloddIAJsoLP8WonzXFow02RN+tIIw0lABX+kmyD3j5f eAOZ4/iDg748GAYsIfext5nYkq2HKbBp7xBj1cNzXcmdJTKAC/o75V5Jv7w== X-Gm-Gg: AZFdTZfMUfPNoVx2uDNivNItSr2I8pYmyX/mzBtKxeGBiPfSjZheR1O1kcLq3IB61fb YZangs43J6BeD+WlT2+pUGyzC7yWKAHkCFk9Z21mkGxSeQQRJE6mDpLwQ6at2DFPVjgN7IZebhS TOTgeXJ9oqOrH9iEyJdcbhIasqiH97R/BoywJOqHzbntaBZPwQr0uMZeuuqm9k1SIJnR7cR4vjE EDthji0SGcpaZu7a6V642bbWvJNzyBelFbRmNez4fJU7QH4okzh2vankWIqKgMnORz6SJg3hu/y CNrnGBT3dqT+P4lpsdHW590gwZV8r0F5rM/SIuNqBj2MWDNypf8x+G04Ri9uWWmuRtRjGOluNvv gSyFiPiRkW7gp+pC+CG+DSdyzQj+6w3DLFvhuEE1PebVJjfTwP2QmAyMV83D3UwpHR+hsPElnqd rGYAraZ8KrnKE= X-Received: by 2002:a05:701b:450e:20b0:1b5:b37f:4934 with SMTP id a92af1059eb24-1b5b37f4b87mr13845433c88.0.1796215444598; Wed, 02 Dec 2026 04:44:04 -0800 (PST) X-Received: by 2002:a05:701b:450e:20b0:1b5:b37f:4934 with SMTP id a92af1059eb24-1b5b37f4b87mr13845379c88.0.1796215443807; Wed, 02 Dec 2026 04:44:03 -0800 (PST) From: Bhaskar Valaboju Date: Wed, 02 Dec 2026 12:43:56 +0000 Subject: [PATCH] hw/arm/virt: Add optional secure PL022 SPI controller with SPI NOR flash MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261202-virt-secure-spi-v1-1-7c714084359a@oss.qualcomm.com> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/yXMQQqDQBBE0atIr22IBjTxKuJinCmTzkKlWwdBv HtG3RS8Rf2dDCowarKdFFFMpjGhyDPyXzd+wBKSqXyUVZGGo+jCBr8q2GZhF15v/+zrMMBRes2 KQbar2Ha3be1/8MuZoeP4A/2BgMZzAAAA X-Change-ID: 20261202-virt-secure-spi-ad89c3b7dfea To: qemu-devel@nongnu.org Cc: Sumit Garg , Jens Wiklander , Peter Maydell , Pierrick Bouvier , Paolo Bonzini , qemu-arm@nongnu.org, Bhaskar Valaboju X-Mailer: b4 0.16.0 X-Proofpoint-GUID: ZpcAV-6eiw7mMlp0z2n-g6PJxBVbObU- X-Proofpoint-ORIG-GUID: ZpcAV-6eiw7mMlp0z2n-g6PJxBVbObU- X-Authority-Analysis: v=2.4 cv=F5DC5ahN c=1 sm=1 tr=0 ts=6b101296 cx=c_pps a=SvEPeNj+VMjHSW//kvnxuw==:117 a=rhAvW2LpFdk2y8TNhmGq6w==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=NEAV23lmAAAA:8 a=EUspDBNiAAAA:8 a=YM1gp4wz5HpfFbPPkT0A:9 a=QEXdDO2ut3YA:10 a=Kq8ClHjjuc5pcCNDwlU0:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDA1MCBTYWx0ZWRfX02oaS3oSmtJS E4Jj9CW1HvoIB0cTlvhl99h/x0QEeaOubcD023l7eiO2pBk6WPz5pJIOs4Md8xdjLl64FygQN1A VXx8MwbM58eUGxmCC1ZANnQx5sWHEqautMV5GYoCicpT0S+hdg3sTNasm0YeMdMXeeDQU7nPADz 5BGbHE+5p1V0bnG1CbnLILveAYh4JjH2cipmoskv2TuVXsCoBAZeUdwOYyfbrjApTO701pKlE4z RmMWvRVThXgosMUE9lZux7TYXhvKtWvVZyQwLj3J29/70jdig6nzdaE89xr4BQpKtlgCaxjKFBV 5wUBorjV3dKbsaRH2kQh+sZzg9a4htkBqTbDFb6udL9rg331gcvO5FUlAPE65Ao8bpS3P1Uy9xa /Ma2nax2ljEF0JdGb/o7GFus0hzR8ejyMNSzzSEvAqD8SfJggVtcqzyLUPlpz5Lom5dhTmj92Kf buXqPLTM8TaPiGKdwPQ== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDA1MCBTYWx0ZWRfX008WmfvYxlv/ lRhHx3gIu+Rxfc+JMXyp/kpfwJip0T9v6ZBgnKJj2eTMr1q6TXHSIuZrkNR3/BhepjFdiq0/xwb 5HM5jvUzjmPla5+GU5Oa107aDwjxYUA= 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-12-02_02,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 priorityscore=1501 adultscore=0 clxscore=1011 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020050 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=bhaskar.valaboju@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-Mailman-Approved-At: Wed, 02 Dec 2026 08:35:26 -0500 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: 1796218554855158500 Secure-World firmware on virt has no flash it can own: the secure flash is a CFI pflash bank holding the boot firmware. Firmware such as OP-TEE that keeps its data in a SPI NOR flash cannot be tested on virt with a real SPI controller and flash model. Add a "secure-spi" machine property (default off) that gives the Secure World a PL022 SPI controller with a 32MB Winbond W25Q256 SPI NOR flash on chip select 0. The PL022 has no chip select output, so the flash CS# is driven by line 0 of a dedicated PL061 GPIO controller. Like the secure UART and GPIO, both devices are mapped in the secure address space only, and their DT nodes are marked status =3D "disabled" and secure-status =3D "okay". The flash contents are backed by "-drive if=3Dmtd,index=3D0". secure-spi=3Don requires secure=3Don. With the default of off, the machine is unchanged. Signed-off-by: Bhaskar Valaboju --- This adds a SPI controller with a SPI NOR flash to the virt machine, for Secure-World firmware, so SPI NOR flash drivers can be developed and tested against a real controller and flash model. Tested on qemu-system-arm with OP-TEE (vexpress-qemu_virt) and -machine virt,secure=3Don,secure-spi=3Don, using OP-TEE's existing PL022 and PL061 drivers and its SPI NOR secure storage, under review at https://github.com/OP-TEE/optee_os/pull/8318: the flash is probed through the PL022 with the PL061 chip select (JEDEC ID ef 40 19, SFDP), OP-TEE secure storage on the flash passes xtest, and the contents persist across reboots with -drive if=3Dmtd,index=3D0,format=3Draw,file=3Dflash.img. secure-spi=3Don wi= thout secure=3Don is rejected. --- docs/system/arm/virt.rst | 11 ++++ hw/arm/Kconfig | 2 + hw/arm/virt.c | 140 +++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/arm/virt.h | 3 + 4 files changed, 156 insertions(+) diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst index 5f6dd17978..1f28b37496 100644 --- a/docs/system/arm/virt.rst +++ b/docs/system/arm/virt.rst @@ -56,6 +56,8 @@ The virt board supports: - A second PL061 GPIO controller, with GPIO lines for triggering a system reset or system poweroff - A secure flash memory + - An optional PL022 SPI controller with a SPI NOR flash + (see ``secure-spi``) - 16MB of secure RAM =20 The second NonSecure UART only exists if a backend is configured @@ -112,6 +114,15 @@ secure Set ``on``/``off`` to enable/disable emulating a guest CPU which impleme= nts the Arm Security Extensions (TrustZone). The default is ``off``. =20 +secure-spi + Set ``on``/``off`` to enable/disable a Secure-World-only PL022 SPI + controller with a 32MB Winbond W25Q256 SPI NOR flash. The PL022 has no + chip select output, so a dedicated Secure-World-only PL061 GPIO + controller drives the flash chip select on its line 0. The flash + contents are backed by ``-drive if=3Dmtd,index=3D0``; without it the fla= sh + starts erased and its contents are lost at exit. Requires ``secure=3Don`= `. + The default is ``off``. + virtualization Set ``on``/``off`` to enable/disable emulating a guest CPU which impleme= nts the Arm Virtualization Extensions. The default is ``off``. diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index e9f796f718..4f4bfdaf42 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -21,6 +21,8 @@ config ARM_VIRT select PL011 # UART select PL031 # RTC select PL061 # GPIO + select PL022 # SPI + select SSI_M25P80 select GPIO_PWR select PLATFORM_BUS select SMBIOS diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 0b11f7e328..204726c06a 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -62,6 +62,10 @@ #include "hw/core/sysbus-fdt.h" #include "hw/core/platform-bus.h" #include "hw/core/qdev-properties.h" +#include "hw/core/qdev-properties-system.h" +#include "hw/ssi/ssi.h" +#include "system/blockdev.h" +#include "system/block-backend.h" #include "hw/arm/fdt.h" #include "hw/intc/arm_gic.h" #include "hw/intc/arm_gicv3_common.h" @@ -210,6 +214,8 @@ static const MemMapEntry base_memmap[] =3D { [VIRT_PVTIME] =3D { 0x090a0000, 0x00010000 }, [VIRT_SECURE_GPIO] =3D { 0x090b0000, 0x00001000 }, [VIRT_ACPI_PCIHP] =3D { 0x090c0000, ACPI_PCIHP_SIZE }, + [VIRT_SECURE_SPI] =3D { 0x090d0000, 0x00001000 }, + [VIRT_SECURE_SPI_GPIO] =3D { 0x090e0000, 0x00001000 }, [VIRT_MMIO] =3D { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that siz= e */ [VIRT_PLATFORM_BUS] =3D { 0x0c000000, 0x02000000 }, @@ -267,6 +273,8 @@ static const int a15irqmap[] =3D { [VIRT_UART1] =3D 8, [VIRT_ACPI_GED] =3D 9, [VIRT_GWDT_WS0] =3D 10, + [VIRT_SECURE_SPI] =3D 11, + [VIRT_SECURE_SPI_GPIO] =3D 12, [VIRT_MMIO] =3D 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] =3D 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ [VIRT_SMMU] =3D 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */ @@ -1718,6 +1726,109 @@ static void create_gpio_devices(const VirtMachineSt= ate *vms, int gpio, } } =20 +/* Line of the secure SPI PL061 that drives the flash CS# */ +#define SECURE_SPI_GPIO_CS 0 + +/* + * Secure-World-only PL022 SPI controller with a SPI NOR flash, for + * firmware such as OP-TEE that keeps its data in flash. The PL022 has + * no chip select output, so the flash CS# is driven by a dedicated PL061 + * GPIO controller. The flash contents come from "-drive if=3Dmtd,index=3D= 0". + */ +static void create_secure_spi(const VirtMachineState *vms, MemoryRegion *m= em) +{ + hwaddr base =3D vms->memmap[VIRT_SECURE_SPI].base; + hwaddr size =3D vms->memmap[VIRT_SECURE_SPI].size; + hwaddr gpio_base =3D vms->memmap[VIRT_SECURE_SPI_GPIO].base; + hwaddr gpio_size =3D vms->memmap[VIRT_SECURE_SPI_GPIO].size; + int irq =3D vms->irqmap[VIRT_SECURE_SPI]; + int gpio_irq =3D vms->irqmap[VIRT_SECURE_SPI_GPIO]; + const char gpio_compat[] =3D "arm,pl061\0arm,primecell"; + const char spi_compat[] =3D "arm,pl022\0arm,primecell"; + const char spi_clocknames[] =3D "sspclk\0apb_pclk"; + MachineState *ms =3D MACHINE(vms); + DeviceState *pl022, *pl061, *flash; + DriveInfo *dinfo; + SysBusDevice *s; + SSIBus *bus; + uint32_t gpio_phandle; + char *gpio_node, *spi_node, *flash_node; + + pl061 =3D qdev_new("pl061"); + /* Keep CS# deasserted until the guest drives it */ + qdev_prop_set_uint8(pl061, "pullups", BIT(SECURE_SPI_GPIO_CS)); + qdev_prop_set_uint8(pl061, "pulldowns", 0xff & ~BIT(SECURE_SPI_GPIO_CS= )); + s =3D SYS_BUS_DEVICE(pl061); + sysbus_realize_and_unref(s, &error_fatal); + memory_region_add_subregion(mem, gpio_base, sysbus_mmio_get_region(s, = 0)); + sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, gpio_irq)); + + pl022 =3D qdev_new("pl022"); + s =3D SYS_BUS_DEVICE(pl022); + sysbus_realize_and_unref(s, &error_fatal); + memory_region_add_subregion(mem, base, sysbus_mmio_get_region(s, 0)); + sysbus_connect_irq(s, 0, qdev_get_gpio_in(vms->gic, irq)); + bus =3D (SSIBus *)qdev_get_child_bus(pl022, "ssi"); + + flash =3D qdev_new("w25q256"); + dinfo =3D drive_get(IF_MTD, 0, 0); + if (dinfo) { + qdev_prop_set_drive_err(flash, "drive", blk_by_legacy_dinfo(dinfo), + &error_fatal); + } + ssi_realize_and_unref(flash, bus, &error_fatal); + qdev_connect_gpio_out(pl061, SECURE_SPI_GPIO_CS, + qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0)); + + gpio_phandle =3D qemu_fdt_alloc_phandle(ms->fdt); + gpio_node =3D g_strdup_printf("/pl061@%" PRIx64, gpio_base); + qemu_fdt_add_subnode(ms->fdt, gpio_node); + qemu_fdt_setprop_sized_cells(ms->fdt, gpio_node, "reg", + 2, gpio_base, 2, gpio_size); + qemu_fdt_setprop(ms->fdt, gpio_node, "compatible", + gpio_compat, sizeof(gpio_compat)); + qemu_fdt_setprop_cell(ms->fdt, gpio_node, "#gpio-cells", 2); + qemu_fdt_setprop(ms->fdt, gpio_node, "gpio-controller", NULL, 0); + qemu_fdt_setprop_cells(ms->fdt, gpio_node, "interrupts", + gic_fdt_irq_type_spi(vms), gpio_irq, + GIC_FDT_IRQ_FLAGS_LEVEL_HI); + qemu_fdt_setprop_cell(ms->fdt, gpio_node, "clocks", vms->clock_phandle= ); + qemu_fdt_setprop_string(ms->fdt, gpio_node, "clock-names", "apb_pclk"); + qemu_fdt_setprop_cell(ms->fdt, gpio_node, "phandle", gpio_phandle); + qemu_fdt_setprop_string(ms->fdt, gpio_node, "status", "disabled"); + qemu_fdt_setprop_string(ms->fdt, gpio_node, "secure-status", "okay"); + + spi_node =3D g_strdup_printf("/spi@%" PRIx64, base); + qemu_fdt_add_subnode(ms->fdt, spi_node); + qemu_fdt_setprop_sized_cells(ms->fdt, spi_node, "reg", 2, base, 2, siz= e); + qemu_fdt_setprop(ms->fdt, spi_node, "compatible", + spi_compat, sizeof(spi_compat)); + qemu_fdt_setprop_cells(ms->fdt, spi_node, "interrupts", + gic_fdt_irq_type_spi(vms), irq, + GIC_FDT_IRQ_FLAGS_LEVEL_HI); + qemu_fdt_setprop_cells(ms->fdt, spi_node, "clocks", + vms->clock_phandle, vms->clock_phandle); + qemu_fdt_setprop(ms->fdt, spi_node, "clock-names", + spi_clocknames, sizeof(spi_clocknames)); + qemu_fdt_setprop_cell(ms->fdt, spi_node, "#address-cells", 1); + qemu_fdt_setprop_cell(ms->fdt, spi_node, "#size-cells", 0); + /* CS# is active low */ + qemu_fdt_setprop_cells(ms->fdt, spi_node, "cs-gpios", + gpio_phandle, SECURE_SPI_GPIO_CS, 1); + qemu_fdt_setprop_string(ms->fdt, spi_node, "status", "disabled"); + qemu_fdt_setprop_string(ms->fdt, spi_node, "secure-status", "okay"); + + flash_node =3D g_strdup_printf("%s/flash@0", spi_node); + qemu_fdt_add_subnode(ms->fdt, flash_node); + qemu_fdt_setprop_string(ms->fdt, flash_node, "compatible", "jedec,spi-= nor"); + qemu_fdt_setprop_cell(ms->fdt, flash_node, "reg", 0); + qemu_fdt_setprop_cell(ms->fdt, flash_node, "spi-max-frequency", 120000= 00); + + g_free(flash_node); + g_free(spi_node); + g_free(gpio_node); +} + static void create_virtio_devices(const VirtMachineState *vms) { int i; @@ -3235,6 +3346,14 @@ static void machvirt_init(MachineState *machine) create_gpio_devices(vms, VIRT_SECURE_GPIO, secure_sysmem); } =20 + if (vms->secure_spi) { + if (!vms->secure) { + error_report("mach-virt: secure-spi=3Don requires secure=3Don"= ); + exit(1); + } + create_secure_spi(vms, secure_sysmem); + } + /* connect powerdown request */ vms->powerdown_notifier.notify =3D virt_powerdown_req; qemu_register_powerdown_notifier(&vms->powerdown_notifier); @@ -3289,6 +3408,20 @@ static void virt_set_secure(Object *obj, bool value,= Error **errp) vms->secure =3D value; } =20 +static bool virt_get_secure_spi(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->secure_spi; +} + +static void virt_set_secure_spi(Object *obj, bool value, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + vms->secure_spi =3D value; +} + static bool virt_get_virt(Object *obj, Error **errp) { VirtMachineState *vms =3D VIRT_MACHINE(obj); @@ -4228,6 +4361,13 @@ static void virt_machine_class_init(ObjectClass *oc,= const void *data) "Set on/off to enable/disa= ble the ARM " "Security Extensions (Trus= tZone)"); =20 + object_class_property_add_bool(oc, "secure-spi", virt_get_secure_spi, + virt_set_secure_spi); + object_class_property_set_description(oc, "secure-spi", + "Set on/off to add a Secure-Worl= d-only " + "PL022 SPI controller with a SPI= NOR " + "flash (requires secure=3Don)"); + object_class_property_add_bool(oc, "virtualization", virt_get_virt, virt_set_virt); object_class_property_set_description(oc, "virtualization", diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 22e66d1a11..94cf7c44c8 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -100,6 +100,8 @@ enum { VIRT_GWDT_WS0, VIRT_GWDT_REFRESH, VIRT_GWDT_CONTROL, + VIRT_SECURE_SPI, + VIRT_SECURE_SPI_GPIO, VIRT_LOWMEMMAP_LAST, }; =20 @@ -166,6 +168,7 @@ struct VirtMachineState { FWCfgState *fw_cfg; PFlashCFI01 *flash[2]; bool secure; + bool secure_spi; bool highmem; bool highmem_compact; bool highmem_cxl; --- base-commit: 3c061218fcf37a98c944ecb88cff56f94f5c0a43 change-id: 20261202-virt-secure-spi-ad89c3b7dfea Best regards, -- =20 Bhaskar Valaboju