aspeed queue
Subsystems (2)
The following changes since commit 4975b64efb5aa4248cbc3760312bbe08d6e71638:
Merge tag 'pull-loongarch-20250928' of https://github.com/bibo-mao/qemu into staging (2025-09-28 09:01:35 -0700)
are available in the Git repository at:
https://github.com/legoater/qemu/ tags/pull-aspeed-20250929
for you to fetch changes up to 9ec30a07483640ecb8417fce3dfa9273f7a036c9:
hw/arm/aspeed_ast27x0-fc: Make sub-init functions return bool with errp (2025-09-29 18:00:20 +0200)
----------------------------------------------------------------
aspeed queue:
* Introduce a new ASPEED OTP memory device model integrated with the Secure Boot Controller. It includes a new block device backend ('drive' property), is enabled for AST2600 SoCs and AST1030 SoCs. Functional tests are included
* Changed "ast2700-evb" alias to point to the "ast2700a1-evb" machine
* Introduce support for Aspeed PCIe host controller, including models for the PCIe Root Complex, Root Port, and PHY. Enabled for the AST2600 and AST2700 SoCs, and functional tests are included
* Refactor Boot ROM support to improve code reuse across the different Aspeed machine. This is in preparation of vbootrom support in the ast2700fc machine
* Improved Error Handling in the AST27x0-fc machine init functions
----------------------------------------------------------------
Jamin Lin (20):
hw/arm/aspeed Move ast2700-evb alias to ast2700a1-evb hw/pci/pci_ids: Add PCI vendor ID for ASPEED
hw/pci-host/aspeed: Add AST2600 PCIe PHY model
hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge hw/pci-host/aspeed: Add AST2600 PCIe Root Device support hw/pci-host/aspeed: Add AST2600 PCIe Root Port and make address configurable hw/pci-host/aspeed: Add MSI support and per-RC IOMMU address space hw/arm/aspeed: Wire up PCIe devices in SoC model hw/arm/aspeed_ast2600: Add PCIe RC support (RC_H only) hw/pci-host/aspeed: Add AST2700 PCIe PHY
hw/pci-host/aspeed: Add AST2700 PCIe config with dedicated H2X blocks hw/pci-host/aspeed: Disable Root Device and place Root Port at 00:00.0 to AST2700 hw/arm/aspeed_ast27x0: Introduce 3 PCIe RCs for AST2700 tests/functional/arm/test_aspeed_ast2600: Add PCIe and network test hw/arm/aspeed: Move aspeed_board_init_flashes() to common SoC code hw/arm/aspeed: Move write_boot_rom to common SoC code hw/arm/aspeed: Move aspeed_install_boot_rom to common SoC code hw/arm/aspeed: Move aspeed_load_vbootrom to common SoC code hw/arm/aspeed_ast27x0-fc: Drop dead return checks hw/arm/aspeed_ast27x0-fc: Make sub-init functions return bool with errp
Kane-Chen-AS (12):
hw/nvram/aspeed_otp: Add ASPEED OTP memory device model hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC hw/arm: Integrate ASPEED OTP memory support into AST2600 SoCs hw/nvram/aspeed_otp: Add 'drive' property to support block backend hw/nvram/aspeed_otp: Add OTP programming semantics and tracing hw/arm: Integrate ASPEED OTP memory support into AST1030 SoCs hw/misc/aspeed_sbc: Add CAMP2 support for OTP data reads hw/misc/aspeed_sbc: Handle OTP write command for voltage mode registers docs/system/arm/aspeed: Document OTP memory options tests/functional/arm: Add helper to generate OTP images tests/functional/arm: Add AST1030 boot test with generated OTP image tests/functional/arm: Add AST2600 boot test with generated OTP image
docs/system/arm/aspeed.rst | 31 + include/hw/arm/aspeed_soc.h | 23 + include/hw/misc/aspeed_sbc.h | 6 + include/hw/nvram/aspeed_otp.h | 33 + include/hw/pci-host/aspeed_pcie.h | 137 +++ include/hw/pci/pci_ids.h | 2 + hw/arm/aspeed.c | 107 +-- hw/arm/aspeed_ast10x0.c | 2 +- hw/arm/aspeed_ast2600.c | 76 +- hw/arm/aspeed_ast27x0-fc.c | 77 +- hw/arm/aspeed_ast27x0.c | 74 ++ hw/arm/aspeed_soc_common.c | 96 +++ hw/misc/aspeed_sbc.c | 197 +++++ hw/nvram/aspeed_otp.c | 190 +++++ hw/pci-host/aspeed_pcie.c | 1015 +++++++++++++++++++++++ hw/arm/Kconfig | 3 + hw/misc/trace-events | 6 + hw/nvram/meson.build | 4 + hw/nvram/trace-events | 5 + hw/pci-host/Kconfig | 4 + hw/pci-host/meson.build | 1 + hw/pci-host/trace-events | 11 + tests/functional/aarch64/test_aspeed_ast2700.py | 4 +- tests/functional/arm/test_aspeed_ast1030.py | 24 +- tests/functional/arm/test_aspeed_ast2600.py | 36 + tests/functional/aspeed.py | 8 + 26 files changed, 2019 insertions(+), 153 deletions(-) create mode 100644 include/hw/nvram/aspeed_otp.h create mode 100644 include/hw/pci-host/aspeed_pcie.h create mode 100644 hw/nvram/aspeed_otp.c create mode 100644 hw/pci-host/aspeed_pcie.c
[PULL 01/32] hw/nvram/aspeed_otp: Add ASPEED OTP memory device model
From: Kane-Chen-AS <[email protected]>
Introduce a QEMU device model for ASPEED's One-Time Programmable (OTP) memory.
This model simulates a word-addressable OTP region used for secure fuse storage. The OTP memory can operate with an internal memory buffer.
The OTP model provides a memory-like interface through a dedicated AddressSpace, allowing other device models (e.g., SBC) to issue transactions as if accessing a memory-mapped region.
--- include/hw/nvram/aspeed_otp.h | 33 ++++++++++++ hw/nvram/aspeed_otp.c | 99 +++++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 4 ++ 3 files changed, 136 insertions(+) create mode 100644 include/hw/nvram/aspeed_otp.h create mode 100644 hw/nvram/aspeed_otp.c
include/hw/nvram/aspeed_otp.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* ASPEED OTP (One-Time Programmable) memory +* +* Copyright (C) 2025 Aspeed +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef ASPEED_OTP_H +#define ASPEED_OTP_H + +#include "system/memory.h" +#include "hw/block/block.h" +#include "system/address-spaces.h" + +#define TYPE_ASPEED_OTP "aspeed-otp" +OBJECT_DECLARE_SIMPLE_TYPE(AspeedOTPState, ASPEED_OTP) + +typedef struct AspeedOTPState { +DeviceState parent_obj; + +BlockBackend *blk; + +uint64_t size; + +AddressSpace as; + +MemoryRegion mmio; + +uint8_t *storage; +}AspeedOTPState ; + +#endif /* ASPEED_OTP_H */
hw/nvram/aspeed_otp.c new file +99 -0
99 lines not on this page · raw message
hw/nvram/meson.build +4 -0
@@ -19,3 +19,7 @@ system_ss.add(when: 'CONFIG_XLNX_BBRAM', if_true: files('xlnx-bbram.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c')) specific_ss.add(when: 'CONFIG_ACPI', if_true: files('fw_cfg-acpi.c')) + +system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( + 'aspeed_otp.c', + ))
Signature · 1 line
2.51.0
[PULL 07/32] hw/misc/aspeed_sbc: Add CAMP2 support for OTP data reads
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
The OTP space contains three types of entries: data, conf, and strap. Data entries consist of two DWORDs, while the other types contain only one DWORD. This change adds the R_CAMP2 register (0x024 / 4) to store the second DWORD when reading from the OTP data region.
With this enhancement, OTP reads now correctly return both DWORDs for data entries via the CAMP registers, along with improved address validation and error handling.
--- hw/misc/aspeed_sbc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
hw/misc/aspeed_sbc.c +27 -0
@@ -22,6 +22,7 @@#define R_ADDR (0x010 / 4)#define R_STATUS (0x014 / 4)#define R_CAMP1 (0x020 / 4) +#define R_CAMP2 (0x024 / 4)#define R_QSR (0x040 / 4)/* R_STATUS */
@@ -50,6 +51,8 @@#define SBC_OTP_CMD_READ 0x23b1e361#define SBC_OTP_CMD_PROG 0x23b1e364 +#define OTP_DATA_DWORD_COUNT (0x800) +#define OTP_TOTAL_DWORD_COUNT (0x1000)static uint64_t aspeed_sbc_read (void *opaque,hwaddr addr,unsigned int size) {AspeedSBCState *s =ASPEED_SBC (opaque);
@@ -72,6 +75,16 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,MemTxResult ret;AspeedOTPState *otp = &s->otp;uint32_t value, otp_offset; +bool is_data = false; + +if (otp_addr <OTP_DATA_DWORD_COUNT ) { + is_data = true; + }else if (otp_addr >=OTP_TOTAL_DWORD_COUNT ) { +qemu_log_mask (LOG_GUEST_ERROR , +"Invalid OTP addr 0x%x\n" , + otp_addr); +return false; + } otp_offset = otp_addr <<2 ; ret = address_space_read(&otp->as, otp_offset, MEMTXATTRS_UNSPECIFIED,
@@ -85,6 +98,20 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s, s->regs[R_CAMP1 ] = value;trace_aspeed_sbc_otp_read (otp_addr, value); +if (is_data) { + ret =address_space_read (&otp->as, otp_offset +4 , +MEMTXATTRS_UNSPECIFIED , + &value,sizeof (value)); +if (ret !=MEMTX_OK ) { +qemu_log_mask (LOG_GUEST_ERROR , +"Failed to read OTP memory, addr = %x\n" , + otp_addr); +return false; + } + s->regs[R_CAMP2 ] = value; +trace_aspeed_sbc_otp_read (otp_addr +1 , value); + } +return true; }
Signature · 1 line
2.51.0
[PULL 05/32] hw/nvram/aspeed_otp: Add OTP programming semantics and tracing
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
Implement correct OTP programming behavior for Aspeed OTP:
- Support read-modify-write flow with one-way bit programming:
* prog_bit uses 0s as the "to-be-programmed" mask.
* Even-indexed words: 0->1, odd-indexed words: 1->0.
* Reject non-programmable requests and log conflicts.
- Enable unaligned accesses in MemoryRegionOps.
Since each OTP address maps to a 1DW (4B) or 2DW (8B) block in the backing store, upper-layer accesses may be unaligned to block boundaries.
This matches the irreversible, word-parity-dependent programming rules of Aspeed SoCs and exposes changes via QEMU trace events.
--- hw/nvram/aspeed_otp.c | 80 ++++++++++++++++++++++++++++++++++++++++++- hw/nvram/trace-events | 5 +++ 2 files changed, 84 insertions(+), 1 deletion(-)
hw/nvram/aspeed_otp.c +79 -1
@@ -12,6 +12,7 @@#include "system/block-backend.h" #include "hw/qdev-properties.h" #include "hw/nvram/aspeed_otp.h" +#include "hw/nvram/trace.h" static uint64_t aspeed_otp_read (void *opaque,hwaddr offset,unsigned size) {
@@ -23,12 +24,87 @@ static uint64_t aspeed_otp_read(void *opaque, hwaddr offset, unsigned size)return val; } +static bool valid_program_data (uint32_t otp_addr, +uint32_t value,uint32_t prog_bit) +{ +uint32_t programmed_bits, has_programmable_bits; +bool is_odd = otp_addr &1 ; + +/* +* prog_bit uses 0s to indicate target bits to program: +* - if OTP word is even-indexed, programmed bits flip 0->1 +* - if odd, bits flip 1->0 +* Bit programming is one-way only and irreversible. +*/ +if (is_odd) { + programmed_bits = ~value & prog_bit; + }else { + programmed_bits = value & (~prog_bit); + } + +/* If any bit can be programmed, accept the request */ + has_programmable_bits = value ^ (~prog_bit); + +if (programmed_bits) { +trace_aspeed_otp_prog_conflict (otp_addr, programmed_bits); +for (int i =0 ; i <32 ; ++i) { +if (programmed_bits & (1U << i)) { +trace_aspeed_otp_prog_bit (i); + } + } + } + +return has_programmable_bits !=0 ; +} + +static bool program_otpmem_data (void *opaque,uint32_t otp_addr, +uint32_t prog_bit,uint32_t *value) +{ +AspeedOTPState *s = opaque; +bool is_odd = otp_addr &1 ; +uint32_t otp_offset = otp_addr <<2 ; + +memcpy (value, s->storage + otp_offset,sizeof (uint32_t )); + +if (!valid_program_data (otp_addr, *value, prog_bit)) { +return false; + } + +if (is_odd) { + *value &= ~prog_bit; + }else { + *value |= ~prog_bit; + } + +return true; +} +static void aspeed_otp_write (void *opaque,hwaddr otp_addr,uint64_t val,unsigned size) {AspeedOTPState *s = opaque; +uint32_t otp_offset, value; -memcpy (s->storage + otp_addr, &val, size); +if (!program_otpmem_data (s, otp_addr, val, &value)) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Failed to program data, value = %x, bit = %" PRIx64"\n" , + __func__, value, val); +return ; + } + + otp_offset = otp_addr <<2 ; +memcpy (s->storage + otp_offset, &value, size); + +if (s->blk) { +if (blk_pwrite (s->blk, otp_offset, size, &value,0 ) <0 ) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: Failed to write %x to %x\n" , + __func__, value, otp_offset); + +return ; + } + } +trace_aspeed_otp_prog (otp_offset, val, value); }static bool aspeed_otp_init_storage (AspeedOTPState *s,Error **errp)
@@ -63,6 +139,8 @@ static const MemoryRegionOps aspeed_otp_ops = { .endianness = DEVICE_LITTLE_ENDIAN, .valid.min_access_size = 1, .valid.max_access_size = 4, + .valid.unaligned = true, + .impl.unaligned = true };static void aspeed_otp_realize (DeviceState *dev,Error **errp)
hw/nvram/trace-events +5 -0
@@ -1,5 +1,10 @@ # See docs/devel/tracing.rst for syntax documentation. +# aspeed_otp.c +aspeed_otp_prog(uint32_t addr, uint32_t prog_value, uint32_t value) "OTP Memory program: addr 0x%" PRIx32 " prog_value 0x%" PRIx32 " value 0x%" PRIx32 +aspeed_otp_prog_conflict(uint32_t addr, uint32_t bits) "Conflict at addr=0x%x, bits=0x%08x" +aspeed_otp_prog_bit(int bit) "Programmed bit %d" + # ds1225y.c nvram_read(uint32_t addr, uint32_t ret) "read addr %d: 0x%02x" nvram_write(uint32_t addr, uint32_t old, uint32_t val) "write addr %d: 0x%02x -> 0x%02x"
Signature · 1 line
2.51.0
[PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
This patch connects the aspeed.otp device to the ASPEED Secure Boot Controller (SBC) model. It implements OTP memory access via the SBC's command interface and enables emulation of secure fuse programming flows.
The following OTP commands are supported:
- READ: reads a 32-bit word from OTP memory into internal registers
- PROG: programs a 32-bit word value to the specified OTP address
Trace events are added to observe read/program operations and command handling flow.
--- include/hw/misc/aspeed_sbc.h | 5 ++ hw/misc/aspeed_sbc.c | 111 +++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 5 ++ 3 files changed, 121 insertions(+)
include/hw/misc/aspeed_sbc.h +5 -0
@@ -10,6 +10,7 @@#define ASPEED_SBC_H #include "hw/sysbus.h" +#include "hw/nvram/aspeed_otp.h" #define TYPE_ASPEED_SBC "aspeed.sbc"#define TYPE_ASPEED_AST2600_SBC TYPE_ASPEED_SBC "-ast2600"
@@ -36,10 +37,14 @@ struct AspeedSBCState {MemoryRegion iomem;uint32_t regs[ASPEED_SBC_NR_REGS ]; + + AspeedOTPState otp; };struct AspeedSBCClass {SysBusDeviceClass parent_class; + +bool has_otp; };#endif /* ASPEED_SBC_H */
hw/misc/aspeed_sbc.c +111 -0
154 lines not on this page · raw message
hw/misc/trace-events +5 -0
@@ -90,6 +90,11 @@ slavio_sysctrl_mem_readl(uint32_t ret) "Read system control 0x%08x" slavio_led_mem_writew(uint32_t val) "Write diagnostic LED 0x%04x" slavio_led_mem_readw(uint32_t ret) "Read diagnostic LED 0x%04x" +# aspeed_sbc.c +aspeed_sbc_handle_cmd(uint32_t cmd, uint32_t addr, bool ret) "Handling command 0x%" PRIx32 " for OTP addr 0x%" PRIx32 " Result: %d" +aspeed_sbc_otp_read(uint32_t addr, uint32_t value) "OTP Memory read: addr 0x%" PRIx32 " value 0x%" PRIx32 +aspeed_sbc_otp_prog(uint32_t addr, uint32_t value) "OTP Memory write: addr 0x%" PRIx32 " value 0x%" PRIx32 + # aspeed_scu.c aspeed_scu_write(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_scu_read(uint64_t offset, unsigned size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32
Signature · 1 line
2.51.0
Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 8 lines · Cédric Le Goater
From: Kane-Chen-AS <[email protected]>
This patch connects the aspeed.otp device to the ASPEED Secure Boot Controller (SBC) model. It implements OTP memory access via the SBC's command interface and enables emulation of secure fuse programming flows.
Quoted 6 lines
The following OTP commands are supported:
- READ: reads a 32-bit word from OTP memory into internal registers
- PROG: programs a 32-bit word value to the specified OTP addressTrace events are added to observe read/program operations and command handling flow.
Hi Cédric -- I was just looking at this SBC OTP code for reasons related to unaligned access handling, and I noticed something odd:
hw/misc/aspeed_sbc.c static uint64_t aspeed_sbc_read(void *opaque, hwaddr addr, unsigned int size) · line 78
Quoted 10 lines
hw/misc/aspeed_sbc.c +10
-0+static bool aspeed_sbc_otp_read (AspeedSBCState *s, +uint32_t otp_addr) +{ +MemTxResult ret; +AspeedOTPState *otp = &s->otp; +uint32_t value, otp_offset; + + otp_offset = otp_addr <<2 ; + ret =address_space_read (&otp->as, otp_offset,MEMTXATTRS_UNSPECIFIED , + &value,sizeof (value));
In the read path, we take the address from the guest (in the R_ADDR register) and shift it right by 2 before using it as the address to address_space_read(). This means that:
* the address is always 4-aligned
* the address the MemoryRegion on the other end sees is a byte offset which matches the size of its memory region
Quoted 11 lines
hw/misc/aspeed_sbc.c +11
-0+if (ret !=MEMTX_OK ) { +qemu_log_mask (LOG_GUEST_ERROR , +"Failed to read OTP memory, addr = %x\n" , + otp_addr); +return false; + } + s->regs[R_CAMP1 ] = value; +trace_aspeed_sbc_otp_read (otp_addr, value); + +return true; +}
hw/misc/aspeed_sbc.c static uint64_t aspeed_sbc_read(void *opaque, hwaddr addr, unsigned int size) · line 99
Quoted 10 lines
hw/misc/aspeed_sbc.c +10
-0+ +static bool aspeed_sbc_otp_prog (AspeedSBCState *s, +uint32_t otp_addr) +{ +MemTxResult ret; +AspeedOTPState *otp = &s->otp; +uint32_t value = s->regs[R_CAMP1 ]; + + ret =address_space_write (&otp->as, otp_addr,MEMTXATTRS_UNSPECIFIED , + &value,sizeof (value));
But here in the prog path, we use the address from the guest directly in the call to address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily 4 aligned, and that it can have values that exceed the valid size of the OTP.
The OTP device on the other end seems to try to account for this difference: its read function uses the offset it is passed as-is, whereas its write function uses "otp_offset = otp_addr << 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.
Is there a reason it was done this way, or could we make the write path also do the conversion to a byte-offset in the SBC and validation of the range, so it matches the read path? (That would let us mark the OTP device's MemoryRegion as not needing to deal with unaligned accesses, because then it would always get 4-aligned 4-byte accesses.)
thanks
-- PMM
Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 6 lines · Peter Maydell
But here in the prog path, we use the address from the guest directly in the call to
address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily 4 aligned, and that it can have values that exceed the valid size of the OTP.
Quoted 7 lines
The OTP device on the other end seems to try to account for this difference: its read function uses the offset it is passed as-is, whereas its write function uses "
otp_offset=otp_addr<< 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.
I found a repro which triggers a clang asan failure, so I filed a bug:
https://gitlab.com/qemu-project/qemu/-/work_items/3436
Would you mind having a look at it?
thanks
-- PMM
RE: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 23 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, April 24, 2026 11:58 PM
To: Cédric Le Goater <[email protected]>
Cc: [email protected]; [email protected]; Kane Chen <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCQuoted 6 lines · Peter Maydell
But here in the prog path, we use the address from the guest directly in the call to
address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily
4 aligned, and that it can have values that exceed the valid size of the OTP.Quoted 6 lines
The OTP device on the other end seems to try to account for this
difference: its read function uses the offset it is passed as-is, whereas its write function uses "otp_offset=otp_addr<< 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.
Quoted 6 lines
I found a repro which triggers a clang asan failure, so I filed a bug:
https://gitlab.com/qemu-project/qemu/-/work_items/3436
Would you mind having a look at it?
Hi Peter,
Sorry for the confusion. I plan to move the address conversion
otp_offset = otp_addr << 2;
from aspeed_otp_write to the upper layer (aspeed_sbc_otp_prog) to ensure consistent behavior between the read and write paths. This should help reduce confusion and align the implementation more clearly.
If there are no concerns with this change, I will proceed with submitting a patch shortly.
Quoted 2 lines
thanks
-- PMM
Best Regards,
Kane
Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 23 lines · Kane Chen
Quoted 23 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, April 24, 2026 11:58 PM
To: Cédric Le Goater <[email protected]>
Cc: [email protected]; [email protected]; Kane Chen <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCQuoted 12 lines · Peter Maydell
But here in the prog path, we use the address from the guest directly in the call to
address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily
4 aligned, and that it can have values that exceed the valid size of the OTP.The OTP device on the other end seems to try to account for this
difference: its read function uses the offset it is passed as-is, whereas its write function uses "otp_offset=otp_addr<< 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.
Quoted 5 lines
Quoted 5 lines
I found a repro which triggers a clang asan failure, so I filed a bug:
https://gitlab.com/qemu-project/qemu/-/work_items/3436
Would you mind having a look at it?
Thanks Peter. I really appreciate the simplicity of the test case.
Quoted 6 lines
Quoted 1 line
Hi Peter,
Sorry for the confusion. I plan to move the address conversion
Quoted 8 lines
otp_offset=otp_addr<< 2;from
aspeed_otp_writeto the upper layer (aspeed_sbc_otp_prog) to ensure consistent behavior between the read and write paths. This should help reduce confusion and align the implementation more clearly.If there are no concerns with this change, I will proceed with submitting a patch shortly.
Hello Kane,
See below.
https://github.com/legoater/qemu/commit/f2967c5bb6084903db178c08afe2b410dd98d3ff
However, the functional tests are broken. These tests should be using real HW values preferably and not values expected by QEMU.
Can you please fix the tests and send the patch below ?
Thanks,
C.
From f2967c5bb6084903db178c08afe2b410dd98d3ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <[email protected]>
Date: Mon, 27 Apr 2026 10:50:21 +0200
Subject: [PATCH] hw/misc/aspeed_sbc: Add bounds checking for OTP write
operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
There is a mismatch between the Aspeed OTP model and the Aspeed SBC model in how the guest-provided address is handled. aspeed_sbc_otp_prog() passes a word-indexed address directly to address_space_write() without converting it to a byte offset, whereas aspeed_otp_write() expects a byte offset and applies an additional shift (otp_addr << 2). This double-shift confusion means that an out-of-range word address can lead to a write beyond the allocated storage.
Fix this by adding bounds checking on the word offset before converting to byte offset and passing to address_space_write(). This matches the existing bounds check in aspeed_sbc_otp_read().
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3436
--- hw/misc/aspeed_sbc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
hw/misc/aspeed_sbc.c +9 -2
@@ -159,9 +159,16 @@ static bool aspeed_sbc_otp_prog(AspeedSBCState *s,MemTxResult ret;AspeedOTPState *otp = &s->otp;uint32_t value = s->regs[R_CAMP1 ]; +uint32_t otp_offset; - ret =address_space_write (&otp->as, otp_addr,MEMTXATTRS_UNSPECIFIED , - &value,sizeof (value)); +if (otp_addr >=OTP_TOTAL_DWORD_COUNT ) { +qemu_log_mask (LOG_GUEST_ERROR ,"Invalid OTP addr 0x%x\n" , otp_addr); +return false; + } + + otp_offset = otp_addr <<2 ; + ret =address_space_write (&otp->as, otp_offset,MEMTXATTRS_UNSPECIFIED , + &value,sizeof (value));if (ret !=MEMTX_OK ) { qemu_log_mask(LOG_GUEST_ERROR, "Failed to write OTP memory, addr = %x\n",
Signature · 1 line
2.53.0
Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 44 lines · Cédric Le Goater
Quoted 23 lines · Kane Chen
Quoted 23 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, April 24, 2026 11:58 PM
To: Cédric Le Goater <[email protected]>
Cc: [email protected]; [email protected]; Kane Chen <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCQuoted 12 lines · Peter Maydell
But here in the prog path, we use the address from the guest directly in the call to
address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily
4 aligned, and that it can have values that exceed the valid size of the OTP.The OTP device on the other end seems to try to account for this
difference: its read function uses the offset it is passed as-is, whereas its write function uses "otp_offset=otp_addr<< 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.Quoted 5 lines
Quoted 5 lines
I found a repro which triggers a clang asan failure, so I filed a bug:
https://gitlab.com/qemu-project/qemu/-/work_items/3436
Would you mind having a look at it?
Thanks Peter. I really appreciate the simplicity of the test case.
Quoted 12 lines
Quoted 1 line
Hi Peter,
Sorry for the confusion. I plan to move the address conversion
otp_offset=otp_addr<< 2;from
aspeed_otp_writeto the upper layer (aspeed_sbc_otp_prog) to ensure consistent behavior between the read and write paths. This should help reduce confusion and align the implementation more clearly.
Quoted 8 lines
Quoted 2 lines
If there are no concerns with this change, I will proceed with submitting a patch shortly.
Hello Kane,
See below.
https://github.com/legoater/qemu/commit/f2967c5bb6084903db178c08afe2b410dd98d3ff
There is more to it. The additional shift in Aspeed OTP model should be removed too. With that, the memory transactions on the OTP storage should be safe. I think.
I pushed a new version on branch aspeed-11.1
Thanks,
C.
Quoted 64 lines
However, the functional tests are broken. These tests should be using real HW values preferably and not values expected by QEMU. Can you please fix the tests and send the patch below ?
Thanks,
C.
From
f2967c5bb6084903db178c08afe2b410dd98d3ffMon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <[email protected]>
Date: Mon, 27 Apr 2026 10:50:21 +0200
Subject: [PATCH] hw/misc/aspeed_sbc: Add bounds checking for OTP write
operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitThere is a mismatch between the Aspeed OTP model and the Aspeed SBC model in how the guest-provided address is handled.
aspeed_sbc_otp_prog()passes a word-indexed address directly toaddress_space_write()without converting it to a byte offset, whereasaspeed_otp_write()expects a byte offset and applies an additional shift (otp_addr<< 2). This double-shift confusion means that an out-of-range word address can lead to a write beyond the allocated storage.Fix this by adding bounds checking on the word offset before converting to byte offset and passing to
address_space_write(). This matches the existing bounds check inaspeed_sbc_otp_read().Cc Kane-Chen-AS <[email protected]>Fixes 1a00754ccf15 ("hw/misc: Add Aspeed Secure Boot Controller model")Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3436
Reported-by Peter Maydell <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- hw/misc/aspeed_sbc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)hw/misc/aspeed_sbc.c +9
-2@@ -159,9 +159,16 @@ static bool aspeed_sbc_otp_prog(AspeedSBCState *s, MemTxResult ret; AspeedOTPState *otp = &s->otp; uint32_t value = s->regs[R_CAMP1]; + uint32_t otp_offset; - ret = address_space_write(&otp->as, otp_addr, MEMTXATTRS_UNSPECIFIED, - &value, sizeof(value)); + if (otp_addr >= OTP_TOTAL_DWORD_COUNT) { + qemu_log_mask(LOG_GUEST_ERROR, "Invalid OTP addr 0x%x\n", otp_addr); + return false; + } + + otp_offset = otp_addr << 2; + ret = address_space_write(&otp->as, otp_offset, MEMTXATTRS_UNSPECIFIED, + &value, sizeof(value)); if (ret != MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "Failed to write OTP memory, addr = %x\n",
RE: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 72 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, April 27, 2026 5:25 PM
To: Kane Chen <[email protected]>; Peter Maydell <[email protected]>
Cc: [email protected]; [email protected]; Troy Lee <[email protected]>; Jamin Lin <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCQuoted 11 lines · Cédric Le Goater
Quoted 10 lines · Kane Chen
Quoted 10 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, April 24, 2026 11:58 PM
To: Cédric Le Goater <[email protected]>
Cc: [email protected]; [email protected]; Kane Chen <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCOn Fri, 24 Apr 2026 at 16:46, Peter Maydell <[email protected]>
Quoted 33 lines · wrote:
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
But here in the prog path, we use the address from the guest directly in the call to
address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily 4 aligned, and that it can have values that exceed the valid size of the OTP.The OTP device on the other end seems to try to account for this
difference: its read function uses the offset it is passed as-is, whereas its write function uses "otp_offset=otp_addr<< 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.Quoted 5 lines
Quoted 5 lines
I found a repro which triggers a clang asan failure, so I filed a bug:
https://gitlab.com/qemu-project/qemu/-/work_items/3436
Would you mind having a look at it?
Thanks Peter. I really appreciate the simplicity of the test case.
Quoted 12 lines
Quoted 1 line
Hi Peter,
Sorry for the confusion. I plan to move the address conversion
otp_offset=otp_addr<< 2;from
aspeed_otp_writeto the upper layer (aspeed_sbc_otp_prog) to ensure consistent behavior between the read and write paths. This should help reduce confusion and align the implementation more clearly.Quoted 8 lines
Quoted 2 lines
If there are no concerns with this change, I will proceed with submitting a patch shortly.
Hello Kane,
See below.
https://github.com/legoater/qemu/commit/f2967c5bb6084903db178c08afe2b
4Quoted 1 line
10dd98d3ffThere is more to it. The additional shift in Aspeed OTP model should be removed too. With that, the memory transactions on the OTP storage should be safe. I think.
Quoted 6 lines
I pushed a new version on branch aspeed-11.1
Thanks,
C.
Hi Cédric,
I have modified the code and am currently running functional tests. Once the tests are completed without any errors, I'll go ahead and send out the patch.
Best Regards,
Kane
Quoted 72 lines
Quoted 49 lines
However, the functional tests are broken. These tests should be using real HW values preferably and not values expected by QEMU. Can you please fix the tests and send the patch below ?
Thanks,
C.
From
f2967c5bb6084903db178c08afe2b410dd98d3ffMon Sep 17 00:00:00
2001
From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <[email protected]>
Date: Mon, 27 Apr 2026 10:50:21 +0200
Subject: [PATCH] hw/misc/aspeed_sbc: Add bounds checking for OTP write
operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitThere is a mismatch between the Aspeed OTP model and the Aspeed SBC model in how the guest-provided address is handled.
aspeed_sbc_otp_prog()passes a word-indexed address directly toaddress_space_write()without converting it to a byte offset, whereasaspeed_otp_write()expects a byte offset and applies an additional shift (otp_addr<< 2). This double-shift confusion means that an out-of-range word address can lead to a write beyond the allocated storage.Fix this by adding bounds checking on the word offset before converting to byte offset and passing to
address_space_write(). This matches the existing bounds check inaspeed_sbc_otp_read().Cc Kane-Chen-AS <[email protected]>Fixes 1a00754ccf15 ("hw/misc: Add Aspeed Secure Boot Controllermodel")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3436Reported-by Peter Maydell <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- hw/misc/aspeed_sbc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)hw/misc/aspeed_sbc.c index renamed from hw/misc/aspeed_sbc.c +0
-0
065e822e70d9..50d499f924dc100644hw/misc/aspeed_sbc.c +0
-0@@ -159,9 +159,16 @@ static bool aspeed_sbc_otp_prog(AspeedSBCState *s,hw/misc/aspeed_sbc.c static bool aspeed_sbc_otp_prog(AspeedSBCState · line 167
Quoted 10 lines
hw/misc/aspeed_sbc.c +3
-2MemTxResult ret; AspeedOTPState *otp = &s->otp; uint32_t value = s->regs[R_CAMP1]; + uint32_t otp_offset; - ret = address_space_write(&otp->as, otp_addr, MEMTXATTRS_UNSPECIFIED, - &value, sizeof(value)); + if (otp_addr >= OTP_TOTAL_DWORD_COUNT) { + qemu_log_mask(LOG_GUEST_ERROR, "Invalid OTP addr0x%x\n",
hw/misc/aspeed_sbc.c static bool aspeed_sbc_otp_prog(AspeedSBCState *s,
Quoted 11 lines
hw/misc/aspeed_sbc.c +8
-0+otp_addr); + return false; + } + + otp_offset = otp_addr << 2; + ret = address_space_write(&otp->as, otp_offset, +MEMTXATTRS_UNSPECIFIED , + &value, sizeof(value)); if (ret != MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "Failed to write OTP memory, addr =%x\n",
Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 74 lines · Kane Chen
Quoted 74 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, April 27, 2026 5:25 PM
To: Kane Chen <[email protected]>; Peter Maydell <[email protected]>
Cc: [email protected]; [email protected]; Troy Lee <[email protected]>; Jamin Lin <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCQuoted 11 lines · Cédric Le Goater
Quoted 10 lines · Kane Chen
Quoted 10 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, April 24, 2026 11:58 PM
To: Cédric Le Goater <[email protected]>
Cc: [email protected]; [email protected]; Kane Chen <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCOn Fri, 24 Apr 2026 at 16:46, Peter Maydell <[email protected]>
Quoted 33 lines · wrote:
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
But here in the prog path, we use the address from the guest directly in the call to
address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily 4 aligned, and that it can have values that exceed the valid size of the OTP.The OTP device on the other end seems to try to account for this
difference: its read function uses the offset it is passed as-is, whereas its write function uses "otp_offset=otp_addr<< 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.Quoted 5 lines
Quoted 5 lines
I found a repro which triggers a clang asan failure, so I filed a bug:
https://gitlab.com/qemu-project/qemu/-/work_items/3436
Would you mind having a look at it?
Thanks Peter. I really appreciate the simplicity of the test case.
Quoted 12 lines
Quoted 1 line
Hi Peter,
Sorry for the confusion. I plan to move the address conversion
otp_offset=otp_addr<< 2;from
aspeed_otp_writeto the upper layer (aspeed_sbc_otp_prog) to ensure consistent behavior between the read and write paths. This should help reduce confusion and align the implementation more clearly.Quoted 8 lines
Quoted 2 lines
If there are no concerns with this change, I will proceed with submitting a patch shortly.
Hello Kane,
See below.
https://github.com/legoater/qemu/commit/f2967c5bb6084903db178c08afe2b
4Quoted 1 line
10dd98d3ffThere is more to it. The additional shift in Aspeed OTP model should be removed too. With that, the memory transactions on the OTP storage should be safe. I think.
I pushed a new version on branch aspeed-11.1
Quoted 8 lines
Quoted 4 lines
Thanks,
C.
Hi Cédric,
I have modified the code and am currently running functional tests. Once the tests are completed without any errors, I'll go ahead and send out the patch.
Thanks a lot. Peter's test is quite nice too.
build :
$ ./configure --cc=clang --disable-docs --enable-asan --target-list=arm-softmmu,aarch64-softmmu
and run :
$ cat > aspeed-otp.txt # set SBC R_ADDR writel 0x1E6F2010 0x1000 # set SBC R_CMD to CMD_READ writel 0x1E6F2004 0x23b1e364
$ ASAN_OPTIONS="fast_unwind_on_malloc=0" ./build/qemu-system-arm -M ast2600-evb -accel qtest -qtest chardev:repro -chardev file,id=repro,path=/dev/null,input-path=aspeed-otp.txt -display none
Something we should do more often.
Thanks,
Quoted 77 lines
Best Regards,
KaneQuoted 72 lines
Quoted 49 lines
However, the functional tests are broken. These tests should be using real HW values preferably and not values expected by QEMU. Can you please fix the tests and send the patch below ?
Thanks,
C.
From
f2967c5bb6084903db178c08afe2b410dd98d3ffMon Sep 17 00:00:00
2001
From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <[email protected]>
Date: Mon, 27 Apr 2026 10:50:21 +0200
Subject: [PATCH] hw/misc/aspeed_sbc: Add bounds checking for OTP write
operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitThere is a mismatch between the Aspeed OTP model and the Aspeed SBC model in how the guest-provided address is handled.
aspeed_sbc_otp_prog()passes a word-indexed address directly toaddress_space_write()without converting it to a byte offset, whereasaspeed_otp_write()expects a byte offset and applies an additional shift (otp_addr<< 2). This double-shift confusion means that an out-of-range word address can lead to a write beyond the allocated storage.Fix this by adding bounds checking on the word offset before converting to byte offset and passing to
address_space_write(). This matches the existing bounds check inaspeed_sbc_otp_read().Cc Kane-Chen-AS <[email protected]>Fixes 1a00754ccf15 ("hw/misc: Add Aspeed Secure Boot Controllermodel")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3436Reported-by Peter Maydell <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- hw/misc/aspeed_sbc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)hw/misc/aspeed_sbc.c index renamed from hw/misc/aspeed_sbc.c +0
-0
065e822e70d9..50d499f924dc100644hw/misc/aspeed_sbc.c +0
-0@@ -159,9 +159,16 @@ static bool aspeed_sbc_otp_prog(AspeedSBCState *s,hw/misc/aspeed_sbc.c static bool aspeed_sbc_otp_prog(AspeedSBCState · line 167
Quoted 10 lines
hw/misc/aspeed_sbc.c +3
-2MemTxResult ret; AspeedOTPState *otp = &s->otp; uint32_t value = s->regs[R_CAMP1]; + uint32_t otp_offset; - ret = address_space_write(&otp->as, otp_addr, MEMTXATTRS_UNSPECIFIED, - &value, sizeof(value)); + if (otp_addr >= OTP_TOTAL_DWORD_COUNT) { + qemu_log_mask(LOG_GUEST_ERROR, "Invalid OTP addr0x%x\n",
hw/misc/aspeed_sbc.c static bool aspeed_sbc_otp_prog(AspeedSBCState *s,
Quoted 11 lines
hw/misc/aspeed_sbc.c +8
-0+otp_addr); + return false; + } + + otp_offset = otp_addr << 2; + ret = address_space_write(&otp->as, otp_offset, +MEMTXATTRS_UNSPECIFIED , + &value, sizeof(value)); if (ret != MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "Failed to write OTP memory, addr =%x\n",
Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
Quoted 14 lines · Cédric Le Goater
Thanks a lot. Peter's test is quite nice too.
build :
$ ./configure --cc=clang --disable-docs --enable-asan --target-list=arm-softmmu,aarch64-softmmuand run :
$ cat > aspeed-otp.txt # set SBC R_ADDR writel 0x1E6F2010 0x1000 # set SBC R_CMD to CMD_READ writel 0x1E6F2004 0x23b1e364
Quoted 3 lines
$ ASAN_OPTIONS="fast_unwind_on_malloc=0" ./build/qemu-system-arm -M ast2600-evb -accel qtest -qtest chardev:repro -chardev file,id=repro,path=/dev/null,input-path=aspeed-otp.txt -display noneSomething we should do more often.
I would quite like to get a sanitizer build/test run into our CI; I worked through a lot of the existing failures in the runup to the 11.0 release, but need to get the last few fixes in (and sort out the actual "run in the CI" part, including figuring out what split between CI jobs and what timeouts to use).
thanks
-- PMM
RE: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBC
In reply to Cédric Le GoaterQuoted 113 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, April 27, 2026 6:54 PM
To: Kane Chen <[email protected]>; Peter Maydell <[email protected]>
Cc: [email protected]; [email protected]; Troy Lee <[email protected]>; Jamin Lin <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCQuoted 61 lines · Kane Chen
Quoted 61 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Monday, April 27, 2026 5:25 PM
To: Kane Chen <[email protected]>; Peter Maydell <[email protected]>
Cc: [email protected]; [email protected]; Troy Lee <[email protected]>; Jamin Lin <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCQuoted 12 lines · Cédric Le Goater
Quoted 11 lines · Kane Chen
Quoted 11 lines
-----Original Message-----
From: Peter Maydell <[email protected]>
Sent: Friday, April 24, 2026 11:58 PM
To: Cédric Le Goater <[email protected]>
Cc: [email protected]; [email protected]; Kane Chen <[email protected]>
Subject: Re: [PULL 02/32] hw/misc/aspeed_sbc: Connect ASPEED OTP memory device to SBCOn Fri, 24 Apr 2026 at 16:46, Peter Maydell
<[email protected]>Quoted 37 lines · wrote:
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
But here in the prog path, we use the address from the guest directly in the call to
address_space_write. This means that the address the MemoryRegion in the OTP device sees is not necessarily
4 aligned, and that it can have values that exceed the valid size of the OTP.The OTP device on the other end seems to try to account for this
difference: its read function uses the offset it is passed as-is, whereas its write function uses "otp_offset=otp_addr<< 2" to convert the offset into a byte offset before using it as an array index etc. But the write function doesn't check whether it's got an overlarge value, so I think it can write off the end of the storage.Quoted 5 lines
Quoted 5 lines
I found a repro which triggers a clang asan failure, so I filed a bug:
https://gitlab.com/qemu-project/qemu/-/work_items/3436
Would you mind having a look at it?
Thanks Peter. I really appreciate the simplicity of the test case.
Quoted 14 lines
Quoted 1 line
Hi Peter,
Sorry for the confusion. I plan to move the address conversion
otp_offset=otp_addr<< 2;from
aspeed_otp_writeto the upper layer (aspeed_sbc_otp_prog) to ensure consistent behavior between the read and write paths. This should help reduce confusion and align the implementation more clearly.If there are no concerns with this change, I will proceed with submitting a patch shortly.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Hello Kane,
See below.
https://github.com/legoater/qemu/commit/f2967c5bb6084903db178c08afe2b
Quoted 9 lines
Quoted 9 lines
4
Quoted 1 line
10dd98d3ffThere is more to it. The additional shift in Aspeed OTP model should be removed too. With that, the memory transactions on the OTP storage should be safe. I think.
I pushed a new version on branch aspeed-11.1
Quoted 8 lines
Quoted 4 lines
Thanks,
C.
Hi Cédric,
I have modified the code and am currently running functional tests. Once the tests are completed without any errors, I'll go ahead and send out
the patch.
Thanks a lot. Peter's test is quite nice too.
build :
$ ./configure --cc=clang --disable-docs --enable-asan --target-list=arm-softmmu,aarch64-softmmuand run :
$ cat > aspeed-otp.txt # set SBC R_ADDR writel 0x1E6F2010 0x1000 # set SBC R_CMD to CMD_READ writel 0x1E6F2004 0x23b1e364
Quoted 10 lines
$ ASAN_OPTIONS="fast_unwind_on_malloc=0" ./build/qemu-system-arm -M ast2600-evb -accel qtest -qtest chardev:repro -chardev file,id=repro,path=/dev/null,input-path=aspeed-otp.txt -display noneSomething we should do more often.
Thanks,
Hi Cédric,
Thank you for the information. After following the steps above, I was able to reproduce the bug mentioned by Peter and verify that it is resolved with the modified code.
The test results are shown below:
[I 0.000000] OPENED
[R +0.865696] # set SBC R_ADDR
[R +0.865757] writel 0x1E6F2010 0x1000
[S +0.865774] OK
[R +0.865833] # set SBC R_CMD to CMD_READ
[R +0.865888] writel 0x1E6F2004 0x23b1e364
[S +0.865895] OK
[R +0.865927]
[I +0.865970] CLOSED
I submit the patch series for further review. If you have any comment or suggestion regarding the code change, please let me know.
Best Regards,
Kane
Quoted 81 lines
Quoted 14 lines
Best Regards,
KaneQuoted 10 lines
Quoted 10 lines
However, the functional tests are broken. These tests should be using real HW values preferably and not values expected by QEMU. Can you please fix the tests and send the patch below ?
Thanks,
C.
From
f2967c5bb6084903db178c08afe2b410dd98d3ffMon Sep 1700:00:00
Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
2001
From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= <[email protected]>
Date: Mon, 27 Apr 2026 10:50:21 +0200
Subject: [PATCH] hw/misc/aspeed_sbc: Add bounds checking for OTP write
operations
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitThere is a mismatch between the Aspeed OTP model and the Aspeed SBC model in how the guest-provided address is handled.
aspeed_sbc_otp_prog()passes a word-indexed address directly toaddress_space_write()without converting it to a byte offset, whereasaspeed_otp_write()expects a byte offset and applies an additional shift (otp_addr<< 2). This double-shift confusion means that an out-of-range word address can lead to a write beyond the allocated storage.Fix this by adding bounds checking on the word offset before converting to byte offset and passing to
address_space_write(). This matches the existing bounds check inaspeed_sbc_otp_read().Cc Kane-Chen-AS <[email protected]>Fixes 1a00754ccf15 ("hw/misc: Add Aspeed Secure Boot Controllermodel")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3436Reported-by Peter Maydell <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>--- hw/misc/aspeed_sbc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)Quoted 5 lines
Quoted 5 lines
hw/misc/aspeed_sbc.c static bool
Quoted 5 lines
hw/misc/aspeed_sbc.c index renamed from hw/misc/aspeed_sbc.c +0
-0
065e822e70d9..50d499f924dc100644hw/misc/aspeed_sbc.c +0
-0@@ -159,9 +159,16 @@ static boolaspeed_sbc_otp_prog(AspeedSBCState
Quoted 12 lines
Quoted 12 lines
hw/misc/aspeed_sbc.c static bool aspeed_sbc_otp_prog(AspeedSBCState *s,
Quoted 11 lines
hw/misc/aspeed_sbc.c +3
-2*s, MemTxResult ret; AspeedOTPState *otp = &s->otp; uint32_t value = s->regs[R_CAMP1]; + uint32_t otp_offset; - ret = address_space_write(&otp->as, otp_addr, MEMTXATTRS_UNSPECIFIED, - &value, sizeof(value)); + if (otp_addr >= OTP_TOTAL_DWORD_COUNT) { + qemu_log_mask(LOG_GUEST_ERROR, "Invalid OTP addr0x%x\n",
Quoted 11 lines
Quoted 11 lines
hw/misc/aspeed_sbc.c static bool aspeed_sbc_otp_prog(AspeedSBCState *s,
Quoted 11 lines
hw/misc/aspeed_sbc.c +8
-0+otp_addr); + return false; + } + + otp_offset = otp_addr << 2; + ret = address_space_write(&otp->as, otp_offset, +MEMTXATTRS_UNSPECIFIED , + &value, sizeof(value)); if (ret != MEMTX_OK) { qemu_log_mask(LOG_GUEST_ERROR, "Failed to write OTP memory, addr=
Quoted 2 lines
Quoted 1 line
%x\n",
[PULL 11/32] tests/functional/arm: Add helper to generate OTP images
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
Add a small helper that generates OTP images at test time. This lets multiple test cases create default OTP contents without shipping prebuilt fixtures and keeps the tests self-contained.
--- tests/functional/aspeed.py | 8 ++++++++ 1 file changed, 8 insertions(+)
tests/functional/aspeed.py +8 -0
@@ -61,3 +61,11 @@ def do_test_arm_aspeed_sdk_start(self, image): self.wait_for_console_pattern('U-Boot 2019.04') self.wait_for_console_pattern('## Loading kernel from FIT Image') self.wait_for_console_pattern('Starting kernel ...') + + def generate_otpmem_image(self): + path = self.scratch_file("otpmem.img") + pattern = b'\x00\x00\x00\x00\xff\xff\xff\xff' * (16 * 1024 // 8) + with open(path, "wb") as f: + f.write(pattern) + return path +
Signature · 1 line
2.51.0
[PULL 03/32] hw/arm: Integrate ASPEED OTP memory support into AST2600 SoCs
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
The has_otp attribute is enabled in the SBC subclasses for AST2600 to control the presence of OTP support per SoC type.
--- hw/arm/aspeed_ast2600.c | 2 +- hw/misc/aspeed_sbc.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
hw/arm/aspeed_ast2600.c +1 -1
@@ -261,7 +261,7 @@ static void aspeed_soc_ast2600_init(Object *obj)object_initialize_child (obj,"i3c" , &s->i3c,TYPE_ASPEED_I3C ); -object_initialize_child (obj,"sbc" , &s->sbc,TYPE_ASPEED_SBC ); +object_initialize_child (obj,"sbc" , &s->sbc,TYPE_ASPEED_AST2600_SBC );object_initialize_child (obj,"iomem" , &s->iomem,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"video" , &s->video,TYPE_UNIMPLEMENTED_DEVICE );
hw/misc/aspeed_sbc.c +2 -0
@@ -273,8 +273,10 @@ static const TypeInfo aspeed_sbc_info = {static void aspeed_ast2600_sbc_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass); +AspeedSBCClass *sc =ASPEED_SBC_CLASS (klass); dc->desc ="AST2600 Secure Boot Controller" ; + sc->has_otp = true; }static const TypeInfo aspeed_ast2600_sbc_info = {
Signature · 1 line
2.51.0
[PULL 04/32] hw/nvram/aspeed_otp: Add 'drive' property to support block backend
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
This patch introduces a 'drive' property to the Aspeed OTP device, allowing it to be backed by a block device. Users can now preload OTP data via QEMU CLI using a block backend.
Example usage:
./qemu-system-arm \
-blockdev driver=file,filename=otpmem.img,node-name=otp \
-global aspeed-otp.drive=otp \
...If the drive is provided, its content will be loaded as the initial OTP state. Otherwise, an internal memory buffer will be used.
--- hw/nvram/aspeed_otp.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
hw/nvram/aspeed_otp.c +14 -1
@@ -35,13 +35,25 @@ static bool aspeed_otp_init_storage(AspeedOTPState *s, Error **errp) {uint32_t *p;int i, num; +uint64_t perm; +if (s->blk) { + perm =BLK_PERM_CONSISTENT_READ | + (blk_supports_write_perm (s->blk) ?BLK_PERM_WRITE :0 ); +if (blk_set_perm (s->blk, perm,BLK_PERM_ALL , errp) <0 ) { +return false; + } +if (blk_pread (s->blk,0 , s->size, s->storage,0 ) <0 ) { +error_setg (errp,"Failed to read the initial flash content" ); +return false; + } + }else { num = s->size /sizeof (uint32_t ); p = (uint32_t *)s->storage;for (i =0 ; i < num; i++) { p[i] = (i %2 ==0 ) ?0x00000000 :0xFFFFFFFF ; } - + }return true; }
@@ -75,6 +87,7 @@ static void aspeed_otp_realize(DeviceState *dev, Error **errp)static const Property aspeed_otp_properties[] = {DEFINE_PROP_UINT64 ("size" , AspeedOTPState, size,0 ), +DEFINE_PROP_DRIVE ("drive" , AspeedOTPState, blk), };static void aspeed_otp_class_init (ObjectClass *klass,const void *data)
Signature · 1 line
2.51.0
[PULL 09/32] docs/system/arm/aspeed: Document OTP memory options
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
Add documentation for the OTP memory module used by AST2600 and AST1030 SoCs, and describe options for using a pre-generated image or an internal buffer. Include example commands for configuration and image generation.
--- docs/system/arm/aspeed.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
docs/system/arm/aspeed.rst +31 -0
@@ -243,6 +243,37 @@ under Linux), use : -M ast2500-evb,bmc-console=uart3 +OTP Option +^^^^^^^^^^ + +Both the AST2600 and AST1030 chips use the same One Time Programmable +(OTP) memory module, which is utilized for configuration, key storage, +and storing user-programmable data. This OTP memory module is managed +by the Secure Boot Controller (SBC). The following options can be +specified or omitted based on your needs. + + * When the options are specified, the pre-generated configuration + file will be used as the OTP memory storage. + + * When the options are omitted, an internal memory buffer will be + used to store the OTP memory data. + +.. code-block:: bash + + -blockdev driver=file,filename=otpmem.img,node-name=otp \ + -global aspeed-otp.drive=otp \ + +The following bash command can be used to generate a default +configuration file for OTP memory: + +.. code-block:: bash + + if [ ! -f otpmem.img ]; then + for i in $(seq 1 2048); do + printf '\x00\x00\x00\x00\xff\xff\xff\xff' + done > otpmem.img + fi + Aspeed 2700 family boards (``ast2700-evb``) ==================================================================
Signature · 1 line
2.51.0
[PULL 06/32] hw/arm: Integrate ASPEED OTP memory support into AST1030 SoCs
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
The has_otp attribute is enabled in the SBC subclasses for AST1030 to control the presence of OTP support per SoC type.
--- include/hw/misc/aspeed_sbc.h | 1 + hw/arm/aspeed_ast10x0.c | 2 +- hw/misc/aspeed_sbc.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-)
include/hw/misc/aspeed_sbc.h +1 -0
@@ -14,6 +14,7 @@#define TYPE_ASPEED_SBC "aspeed.sbc"#define TYPE_ASPEED_AST2600_SBC TYPE_ASPEED_SBC "-ast2600" +#define TYPE_ASPEED_AST10X0_SBC TYPE_ASPEED_SBC "-ast10x0" OBJECT_DECLARE_TYPE(AspeedSBCState, AspeedSBCClass, ASPEED_SBC)#define ASPEED_SBC_NR_REGS (0x93c >> 2)
hw/arm/aspeed_ast10x0.c +1 -1
@@ -154,7 +154,7 @@ static void aspeed_soc_ast1030_init(Object *obj)object_initialize_child (obj,"peci" , &s->peci,TYPE_ASPEED_PECI ); -object_initialize_child (obj,"sbc" , &s->sbc,TYPE_ASPEED_SBC ); +object_initialize_child (obj,"sbc" , &s->sbc,TYPE_ASPEED_AST10X0_SBC );for (i =0 ; i < sc->wdts_num; i++) {snprintf (typename,sizeof (typename),"aspeed.wdt-%s" , socname);
hw/misc/aspeed_sbc.c +16 -0
@@ -285,9 +285,25 @@ static const TypeInfo aspeed_ast2600_sbc_info = { .class_init = aspeed_ast2600_sbc_class_init, }; +static void aspeed_ast10x0_sbc_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +AspeedSBCClass *sc =ASPEED_SBC_CLASS (klass); + + dc->desc ="AST10X0 Secure Boot Controller" ; + sc->has_otp = true; +} + +static const TypeInfo aspeed_ast10x0_sbc_info = { + .name =TYPE_ASPEED_AST10X0_SBC , + .parent =TYPE_ASPEED_SBC , + .class_init = aspeed_ast10x0_sbc_class_init, +}; +static void aspeed_sbc_register_types (void ) {type_register_static (&aspeed_ast2600_sbc_info); +type_register_static (&aspeed_ast10x0_sbc_info);type_register_static (&aspeed_sbc_info); }
Signature · 1 line
2.51.0
[PULL 08/32] hw/misc/aspeed_sbc: Handle OTP write command for voltage mode registers
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
Extend OTP command handling to recognize specific voltage mode register addresses and emulate the expected hardware behavior. Without this change, legitimate voltage mode change requests would be incorrectly reported as "Unknown command" and logged as an error.
This implementation does not perform actual mode changes, but ensures that valid requests are accepted and ignored as per hardware behavior.
--- hw/misc/aspeed_sbc.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/misc/trace-events | 1 + 2 files changed, 42 insertions(+)
hw/misc/aspeed_sbc.c +41 -0
@@ -49,10 +49,17 @@#define OTP_MEMORY_SIZE 0x4000/* OTP command */ #define SBC_OTP_CMD_READ 0x23b1e361 +#define SBC_OTP_CMD_WRITE 0x23b1e362#define SBC_OTP_CMD_PROG 0x23b1e364#define OTP_DATA_DWORD_COUNT (0x800)#define OTP_TOTAL_DWORD_COUNT (0x1000) + +/* Voltage mode */ +#define MODE_REGISTER (0x1000) +#define MODE_REGISTER_A (0x3000) +#define MODE_REGISTER_B (0x5000) +static uint64_t aspeed_sbc_read (void *opaque,hwaddr addr,unsigned int size) {AspeedSBCState *s =ASPEED_SBC (opaque);
@@ -115,6 +122,37 @@ static bool aspeed_sbc_otp_read(AspeedSBCState *s,return true; } +static bool mode_handler (uint32_t otp_addr) +{ +switch (otp_addr) { +case MODE_REGISTER : +case MODE_REGISTER_A : +case MODE_REGISTER_B : +/* HW behavior, do nothing here */ +return true; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"Unsupported address 0x%x\n" , + otp_addr); +return false; + } +} + +static bool aspeed_sbc_otp_write (AspeedSBCState *s, +uint32_t otp_addr) +{ +if (otp_addr ==0 ) { +trace_aspeed_sbc_ignore_cmd (otp_addr); +return true; + }else { +if (mode_handler (otp_addr) == false) { +return false; + } + } + +return true; +} +static bool aspeed_sbc_otp_prog (AspeedSBCState *s,uint32_t otp_addr) {
@@ -157,6 +195,9 @@ static void aspeed_sbc_handle_command(void *opaque, uint32_t cmd)case SBC_OTP_CMD_READ : ret =aspeed_sbc_otp_read (s, otp_addr);break ; +case SBC_OTP_CMD_WRITE : + ret =aspeed_sbc_otp_write (s, otp_addr); +break ;case SBC_OTP_CMD_PROG : ret =aspeed_sbc_otp_prog (s, otp_addr);break ;
hw/misc/trace-events +1 -0
@@ -91,6 +91,7 @@ slavio_led_mem_writew(uint32_t val) "Write diagnostic LED 0x%04x" slavio_led_mem_readw(uint32_t ret) "Read diagnostic LED 0x%04x" # aspeed_sbc.c +aspeed_sbc_ignore_cmd(uint32_t cmd) "Ignoring command 0x%" PRIx32 aspeed_sbc_handle_cmd(uint32_t cmd, uint32_t addr, bool ret) "Handling command 0x%" PRIx32 " for OTP addr 0x%" PRIx32 " Result: %d" aspeed_sbc_otp_read(uint32_t addr, uint32_t value) "OTP Memory read: addr 0x%" PRIx32 " value 0x%" PRIx32 aspeed_sbc_otp_prog(uint32_t addr, uint32_t value) "OTP Memory write: addr 0x%" PRIx32 " value 0x%" PRIx32
Signature · 1 line
2.51.0
[PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Introduce PCIe config and host bridge model for the AST2600 platform.
This patch adds support for the H2X (AHB to PCIe Bus Bridge) controller with a 0x100 byte register space. The register layout is shared between two root complexes: 0x00–0x7f is common, 0x80–0xbf for RC_L, and 0xc0–0xff for RC_H. Only RC_H is modeled in this implementation.
The RC_H bus uses bus numbers in the 0x80–0xff range instead of the standard root bus 0x00. To allow the PCI subsystem to discover devices, the host bridge logic remaps the root bus number back to 0x00 whenever the configured bus number matches the "bus-nr" property.
New MMIO callbacks are added for the H2X config space:
- aspeed_pcie_cfg_read() and aspeed_pcie_cfg_write() handle register accesses.
- aspeed_pcie_cfg_readwrite() provides configuration read/write support.
- aspeed_pcie_cfg_translate_write() handles PCIe byte-enable semantics for write operations.
The reset handler initializes the H2X register block with default values as defined in the AST2600 datasheet.
Additional changes:
- Implement ASPEED PCIe root complex (TYPE_ASPEED_PCIE_RC).
- Wire up interrupt propagation via aspeed_pcie_rc_set_irq().
- Add tracepoints for config read/write and INTx handling.
--- include/hw/pci-host/aspeed_pcie.h | 59 +++++ hw/pci-host/aspeed_pcie.c | 421 ++++++++++++++++++++++++++++++ hw/pci-host/trace-events | 4 + 3 files changed, 484 insertions(+)
include/hw/pci-host/aspeed_pcie.h +59 -0
@@ -22,6 +22,65 @@#include "hw/pci/pcie_host.h" #include "qom/object.h" +typedef struct AspeedPCIECfgTxDesc { +uint32_t desc0; +uint32_t desc1; +uint32_t desc2; +uint32_t desc3; +uint32_t wdata; +uint32_t rdata_reg; +}AspeedPCIECfgTxDesc ; + +typedef struct AspeedPCIERcRegs { +uint32_t int_en_reg; +uint32_t int_sts_reg; +}AspeedPCIERcRegs ; + +typedef struct AspeedPCIERegMap { +AspeedPCIERcRegs rc; +}AspeedPCIERegMap ; + +#define TYPE_ASPEED_PCIE_RC "aspeed.pcie-rc" +OBJECT_DECLARE_SIMPLE_TYPE (AspeedPCIERcState,ASPEED_PCIE_RC ); + +struct AspeedPCIERcState { +PCIExpressHost parent_obj; + +MemoryRegion mmio_window; +MemoryRegion io_window; +MemoryRegion mmio; +MemoryRegion io; + +uint32_t bus_nr; +char name[16 ]; +qemu_irq irq; +}; + +/* Bridge between AHB bus and PCIe RC. */ +#define TYPE_ASPEED_PCIE_CFG "aspeed.pcie-cfg" +OBJECT_DECLARE_TYPE (AspeedPCIECfgState, AspeedPCIECfgClass,ASPEED_PCIE_CFG ); + +struct AspeedPCIECfgState { +SysBusDevice parent_obj; + +MemoryRegion mmio; +uint32_t *regs; +uint32_t id; + +const AspeedPCIERcRegs *rc_regs; +AspeedPCIERcState rc; +}; + +struct AspeedPCIECfgClass { +SysBusDeviceClass parent_class; + +const AspeedPCIERegMap *reg_map; +const MemoryRegionOps *reg_ops; + +uint64_t rc_bus_nr; +uint64_t nr_regs; +}; +#define TYPE_ASPEED_PCIE_PHY "aspeed.pcie-phy"OBJECT_DECLARE_TYPE (AspeedPCIEPhyState, AspeedPCIEPhyClass,ASPEED_PCIE_PHY );
hw/pci-host/aspeed_pcie.c +421 -0
433 lines not on this page · raw message
hw/pci-host/trace-events +4 -0
@@ -1,6 +1,10 @@ # See docs/devel/tracing.rst for syntax documentation. # aspeed_pcie.c +aspeed_pcie_rc_intx_set_irq(uint32_t id, int num, int level) "%d: num %d set IRQ leve %d" +aspeed_pcie_cfg_read(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32 +aspeed_pcie_cfg_write(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32 +aspeed_pcie_cfg_rw(uint32_t id, const char *dir, uint8_t bus, uint8_t devfn, uint64_t addr, uint64_t data) "%d: %s bus:0x%x devfn:0x%x addr 0x%" PRIx64 " data 0x%" PRIx64 aspeed_pcie_phy_read(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32 aspeed_pcie_phy_write(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32
Signature · 1 line
2.51.0
Re: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
Quoted 9 lines · Cédric Le Goater
From: Jamin Lin <[email protected]>
Introduce PCIe config and host bridge model for the AST2600 platform.
hw/pci-host/aspeed_pcie.c +4
-0+static void aspeed_pcie_rc_class_init (ObjectClass *klass,const void *data) +{ +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass);
hw/pci-host/aspeed_pcie.c line 128
Quoted 10 lines
hw/pci-host/aspeed_pcie.c +10
-0+ + dc->desc ="ASPEED PCIe RC" ; + dc->realize = aspeed_pcie_rc_realize; + dc->fw_name ="pci" ; +set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); + + hc->root_bus_path = aspeed_pcie_rc_root_bus_path; +device_class_set_props (dc, aspeed_pcie_rc_props); + + msi_nonbroken = true;
This sets the msi_nonbroken global in the class init, which is run for every type compiled into QEMU at startup. That means it's effectively forcing it to 'true' for every machine type, whether it's aspeed or not.
You're supposed to set this in your 'realize' method, so it only takes effect if your interrupt controller/PCI controller/etc is actually being used.
thanks
-- PMM
RE: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
Hi Peter, Marcelo
*
Quoted 28 lines
Subject: Re: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
Quoted 9 lines · Cédric Le Goater
From: Jamin Lin <[email protected]>
Introduce PCIe config and host bridge model for the AST2600 platform.
hw/pci-host/aspeed_pcie.c +4
-0+static void aspeed_pcie_rc_class_init (ObjectClass *klass,const void +*data) { +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass);hw/pci-host/aspeed_pcie.c line 128
Quoted 10 lines
hw/pci-host/aspeed_pcie.c +10
-0+ + dc->desc ="ASPEED PCIe RC" ; + dc->realize = aspeed_pcie_rc_realize; + dc->fw_name ="pci" ; +set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); + + hc->root_bus_path = aspeed_pcie_rc_root_bus_path; +device_class_set_props (dc, aspeed_pcie_rc_props); + + msi_nonbroken = true;This sets the
msi_nonbrokenglobal in the class init, which is run for every type compiled into QEMU at startup. That means it's effectively forcing it to 'true' for every machine type, whether it's aspeed or not.
Quoted 7 lines
You're supposed to set this in your 'realize' method, so it only takes effect if your interrupt controller/PCI controller/etc is actually being used.
Reported-by Marcelo Manzo <[email protected]>thanks
-- PMM
Thanks for report this issue.
Will fix it soon.
Jamin
RE: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
Quoted 39 lines
Subject: RE: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
Hi Peter, Marcelo
*
Quoted 19 lines
Subject: Re: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
Quoted 15 lines · Cédric Le Goater
From: Jamin Lin <[email protected]>
Introduce PCIe config and host bridge model for the AST2600 platform.
hw/pci-host/aspeed_pcie.c +10
-0+static void aspeed_pcie_rc_class_init (ObjectClass *klass,const +void +*data) { +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="ASPEED PCIe RC" ; + dc->realize = aspeed_pcie_rc_realize; + dc->fw_name ="pci" ; +set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories);Quoted 8 lines
hw/pci-host/aspeed_pcie.c line 128
Quoted 5 lines
hw/pci-host/aspeed_pcie.c +5
-0+ + hc->root_bus_path = aspeed_pcie_rc_root_bus_path; +device_class_set_props (dc, aspeed_pcie_rc_props); + + msi_nonbroken = true;This sets the
msi_nonbrokenglobal in the class init, which is run for every type compiled into QEMU at startup. That means it's effectivelyforcing it to 'true'
Quoted 5 lines
for every machine type, whether it's aspeed or not.
You're supposed to set this in your 'realize' method, so it only takes effect if your interrupt controller/PCI controller/etc is actually being used.
Quoted 8 lines
Quoted 4 lines
Reported-by Marcelo Manzo <[email protected]>thanks
-- PMMThanks for report this issue.
Will fix it soon.
Jamin
Please help to review.
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
Thanks,
Jamin
Re: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
In reply to Peter MaydellHi,
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Cédric Le Goater
From: Jamin Lin <[email protected]>
Introduce PCIe config and host bridge model for the AST2600 platform.
hw/pci-host/aspeed_pcie.c +11
-0+static void aspeed_pcie_rc_class_init (ObjectClass *klass,const void *data) +{ +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="ASPEED PCIe RC" ; + dc->realize = aspeed_pcie_rc_realize; + dc->fw_name ="pci" ; +set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); + + hc->root_bus_path = aspeed_pcie_rc_root_bus_path;
Quoted 8 lines
hw/pci-host/aspeed_pcie.c line 128
Quoted 3 lines
hw/pci-host/aspeed_pcie.c +3
-0+device_class_set_props (dc, aspeed_pcie_rc_props); + + msi_nonbroken = true;This sets the
msi_nonbrokenglobal in the class init, which is run for every type compiled into QEMU at startup. That means it's effectively forcing it to 'true' for every machine type, whether it's aspeed or not.
TYPE_S390_PCI_HOST_BRIDGE seems to do that since 2015 in commit 8cba80c3a0 ("s390: Add PCI bus support"); why isn't it an issue there?
1652:static void s390_pcihost_class_init(ObjectClass *klass, ...)
1653-{
1654- DeviceClass *dc = DEVICE_CLASS(klass);
1655- HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
1656-
1657- device_class_set_legacy_reset(dc, s390_pcihost_reset);
1658- dc->realize = s390_pcihost_realize;
1659- dc->unrealize = s390_pcihost_unrealize;
1660- hc->pre_plug = s390_pcihost_pre_plug;
1661- hc->plug = s390_pcihost_plug;
1662- hc->unplug_request = s390_pcihost_unplug_request;
1663- hc->unplug = s390_pcihost_unplug;
1664- msi_nonbroken = true;^^^^^^^^^^^^^^^^^^^^
1665- device_class_set_props(dc, phb_props); 1666-}
1668=static const TypeInfo s390_pcihost_info = {
1669- .name = TYPE_S390_PCI_HOST_BRIDGE,
1670- .parent = TYPE_PCI_HOST_BRIDGE,
1671- .instance_size = sizeof(S390pciState),
1672: .class_init = s390_pcihost_class_init,
1673- .interfaces = (const InterfaceInfo[]) { 1674- { TYPE_HOTPLUG_HANDLER },
1675- { }
1676- }
1677-};
Quoted 8 lines
You're supposed to set this in your 'realize' method, so it only takes effect if your interrupt controller/PCI controller/etc is actually being used.
Reported-by Marcelo Manzo <[email protected]>thanks
-- PMM
Re: [PULL 16/32] hw/pci-host/aspeed: Add AST2600 PCIe config space and host bridge
Quoted 30 lines · Philippe Mathieu-Daudé
Hi,
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Cédric Le Goater
From: Jamin Lin <[email protected]>
Introduce PCIe config and host bridge model for the AST2600 platform.
hw/pci-host/aspeed_pcie.c +11
-0+static void aspeed_pcie_rc_class_init (ObjectClass *klass,const void *data) +{ +PCIHostBridgeClass *hc =PCI_HOST_BRIDGE_CLASS (klass); +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc ="ASPEED PCIe RC" ; + dc->realize = aspeed_pcie_rc_realize; + dc->fw_name ="pci" ; +set_bit (DEVICE_CATEGORY_BRIDGE , dc->categories); + + hc->root_bus_path = aspeed_pcie_rc_root_bus_path;Quoted 8 lines
hw/pci-host/aspeed_pcie.c line 128
Quoted 3 lines
hw/pci-host/aspeed_pcie.c +3
-0+device_class_set_props (dc, aspeed_pcie_rc_props); + + msi_nonbroken = true;This sets the
msi_nonbrokenglobal in the class init, which is run for every type compiled into QEMU at startup. That means it's effectively forcing it to 'true' for every machine type, whether it's aspeed or not.
Quoted 2 lines
TYPE_S390_PCI_HOST_BRIDGEseems to do that since 2015 in commit8cba80c3a0("s390: Add PCI bus support"); why isn't it an issue there?
It is in principle, but doesn't cause a problem in practice because s390 only has one machine type, so there is no situation where you're trying to run some other machine that shouldn't have msi_nonbroken set to true that was compiled into the same binary. We should fix the s390 case too.
thanks
-- PMM
[PULL 18/32] hw/pci-host/aspeed: Add AST2600 PCIe Root Port and make address configurable
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Introduce an ASPEED PCIe Root Port and wire it under the RC. The root port is modeled as TYPE_ASPEED_PCIE_ROOT_PORT (subclass of TYPE_PCIE_ROOT_PORT).
Key changes:
- Add TYPE_ASPEED_PCIE_ROOT_PORT (PCIESlot-based) with vendor/device IDs and AER capability offset.
- Extend AspeedPCIERcState to embed a root_port instance and a configurable rp_addr.
- Add "rp-addr" property to the RC to place the root port at a specific devfn on the root bus.
- Set the root port's "chassis" property to ensure a unique chassis per RC.
- Extend AspeedPCIECfgClass with rc_rp_addr defaulting to PCI_DEVFN(8,0).
Rationale:
- AST2600 places the root port at 80:08.0 (bus 0x80, dev 8, fn 0).
- AST2700 must place the root port at 00:00.0, and it supports three RCs. Each root port must therefore be uniquely identifiable; uses the PCIe "chassis" ID for that.
- Providing a configurable "rp-addr" lets platforms select the correct devfn per SoC family, while the "chassis" property ensures uniqueness across multiple RC instances on AST2700.
--- include/hw/pci-host/aspeed_pcie.h | 11 +++++++ hw/pci-host/aspeed_pcie.c | 50 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
include/hw/pci-host/aspeed_pcie.h +11 -0
@@ -20,6 +20,7 @@#include "hw/sysbus.h" #include "hw/pci/pci_bridge.h" #include "hw/pci/pcie_host.h" +#include "hw/pci/pcie_port.h" #include "qom/object.h" typedef struct AspeedPCIECfgTxDesc {
@@ -40,6 +41,13 @@ typedef struct AspeedPCIERegMap {AspeedPCIERcRegs rc; } AspeedPCIERegMap; +#define TYPE_ASPEED_PCIE_ROOT_PORT "aspeed.pcie-root-port" +OBJECT_DECLARE_SIMPLE_TYPE(AspeedPCIERootPortState, ASPEED_PCIE_ROOT_PORT) + +typedef struct AspeedPCIERootPortState { +PCIESlot parent_obj; +}AspeedPCIERootPortState ; +#define TYPE_ASPEED_PCIE_ROOT_DEVICE "aspeed.pcie-root-device"OBJECT_DECLARE_SIMPLE_TYPE (AspeedPCIERootDeviceState,ASPEED_PCIE_ROOT_DEVICE );
@@ -58,12 +66,14 @@ struct AspeedPCIERcState {MemoryRegion mmio;MemoryRegion io; +uint32_t rp_addr;uint32_t bus_nr;char name[16 ];bool has_rd;qemu_irq irq;AspeedPCIERootDeviceState root_device; +AspeedPCIERootPortState root_port; };/* Bridge between AHB bus and PCIe RC. */
@@ -87,6 +97,7 @@ struct AspeedPCIECfgClass {const AspeedPCIERegMap *reg_map;const MemoryRegionOps *reg_ops; +uint32_t rc_rp_addr;uint64_t rc_bus_nr;uint64_t nr_regs;bool rc_has_rd;
hw/pci-host/aspeed_pcie.c +50 -0
101 lines not on this page · raw message
Signature · 1 line
2.51.0
[PULL 10/32] hw/arm/aspeed Move ast2700-evb alias to ast2700a1-evb
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
This patch moves the "ast2700-evb" alias from the A0 to A1. The A0 machine remains available via its explicit name ("ast2700a0-evb"), while functional tests are updated to target A0 by name instead of relying on the generic alias.
--- hw/arm/aspeed.c | 2 +- tests/functional/aarch64/test_aspeed_ast2700.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
hw/arm/aspeed.c +1 -1
@@ -1995,7 +1995,6 @@ static void aspeed_machine_ast2700a0_evb_class_init(ObjectClass *oc,MachineClass *mc =MACHINE_CLASS (oc);AspeedMachineClass *amc =ASPEED_MACHINE_CLASS (oc); - mc->alias ="ast2700-evb" ; mc->desc ="Aspeed AST2700 A0 EVB (Cortex-A35)" ; amc->soc_name ="ast2700-a0" ; amc->hw_strap1 =AST2700_EVB_HW_STRAP1 ;
@@ -2018,6 +2017,7 @@ static void aspeed_machine_ast2700a1_evb_class_init(ObjectClass *oc,MachineClass *mc =MACHINE_CLASS (oc);AspeedMachineClass *amc =ASPEED_MACHINE_CLASS (oc); + mc->alias ="ast2700-evb" ; mc->desc ="Aspeed AST2700 A1 EVB (Cortex-A35)" ; amc->soc_name ="ast2700-a1" ; amc->hw_strap1 =AST2700_EVB_HW_STRAP1 ;
tests/functional/aarch64/test_aspeed_ast2700.py +2 -2
@@ -115,8 +115,8 @@ def start_ast2700_test_vbootrom(self, name): self.do_test_aarch64_aspeed_sdk_start( self.scratch_file(name, 'image-bmc')) - def test_aarch64_ast2700_evb_sdk_v09_06(self): - self.set_machine('ast2700-evb') + def test_aarch64_ast2700a0_evb_sdk_v09_06(self): + self.set_machine('ast2700a0-evb') self.archive_extract(self.ASSET_SDK_V906_AST2700) self.start_ast2700_test('ast2700-a0-default')
Signature · 1 line
2.51.0
[PULL 26/32] tests/functional/arm/test_aspeed_ast2600: Add PCIe and network test
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Extend the AST2600 functional tests with PCIe and network checks.
This patch introduces a new helper "do_ast2600_pcie_test()" that runs "lspci" on the emulated system and verifies the presence of the expected PCIe devices:
- 80:00.0 Host bridge: ASPEED Technology, Inc. Device 2600
- 80:08.0 PCI bridge: ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge
- 81:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
To exercise the PCIe network device, the test adds:
-device e1000e,netdev=net1,bus=pcie.0
-netdev user,id=net1
and assigns an IP address to the interface, verifying it with ip addr.
--- tests/functional/arm/test_aspeed_ast2600.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tests/functional/arm/test_aspeed_ast2600.py +21 -0
@@ -101,8 +101,26 @@ def test_arm_ast2600_evb_buildroot_tpm(self): 'https://github.com/AspeedTech-BMC/openbmc/releases/download/v09.07/ast2600-default-obmc.tar.gz', 'cb6c08595bcbba1672ce716b068ba4e48eda1ed9abe78a07b30392ba2278feba') + def do_ast2600_pcie_test(self): + exec_command_and_wait_for_pattern(self, + 'lspci -s 80:00.0', + '80:00.0 Host bridge: ' + 'ASPEED Technology, Inc. Device 2600') + exec_command_and_wait_for_pattern(self, + 'lspci -s 80:08.0', + '80:08.0 PCI bridge: ' + 'ASPEED Technology, Inc. AST1150 PCI-to-PCI Bridge') + exec_command_and_wait_for_pattern(self, + 'lspci -s 81:00.0', + '81:00.0 Ethernet controller: ' + 'Intel Corporation 82574L Gigabit Network Connection') + exec_command_and_wait_for_pattern(self, + 'ip addr show dev eth4', + 'inet 10.0.2.15/24') + def test_arm_ast2600_evb_sdk(self): self.set_machine('ast2600-evb') + self.require_netdev('user') self.archive_extract(self.ASSET_SDK_V907_AST2600)
@@ -110,6 +128,8 @@ def test_arm_ast2600_evb_sdk(self): 'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test') self.vm.add_args('-device', 'ds1338,bus=aspeed.i2c.bus.5,address=0x32') + self.vm.add_args('-device', 'e1000e,netdev=net1,bus=pcie.0') + self.vm.add_args('-netdev', 'user,id=net1') self.do_test_arm_aspeed_sdk_start( self.scratch_file("ast2600-default", "image-bmc"))
@@ -135,6 +155,7 @@ def test_arm_ast2600_evb_sdk(self): year = time.strftime("%Y") exec_command_and_wait_for_pattern(self, '/sbin/hwclock -f /dev/rtc1', year) + self.do_ast2600_pcie_test() def test_arm_ast2600_otp_blockdev_device(self): self.vm.set_machine("ast2600-evb")
Signature · 1 line
2.51.0
[PULL 29/32] hw/arm/aspeed: Move aspeed_install_boot_rom to common SoC code
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Move the boot ROM install helper into common SoC code so it can be reused by all ASPEED boards, and decouple the API from AspeedMachineState.
Specifically:
- Move aspeed_install_boot_rom() to hw/arm/aspeed_soc_common.c and declare it in include/hw/arm/aspeed_soc.h.
- Change the helper’s signature to take AspeedSoCState * and a MemoryRegion * provided by the caller, instead of AspeedMachineState *.
- Update aspeed_machine_init() call sites accordingly.
No functional change.
--- include/hw/arm/aspeed_soc.h | 2 ++ hw/arm/aspeed.c | 23 +++-------------------- hw/arm/aspeed_soc_common.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 20 deletions(-)
include/hw/arm/aspeed_soc.h +2 -0
@@ -314,6 +314,8 @@ void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype, unsigned int count, int unit0);void aspeed_write_boot_rom (BlockBackend *blk,hwaddr addr,size_t rom_size,Error **errp); +void aspeed_install_boot_rom (AspeedSoCState *soc,BlockBackend *blk, +MemoryRegion *boot_rom,uint64_t rom_size);static inline int aspeed_uart_index (int uart_dev) {
hw/arm/aspeed.c +3 -20
@@ -263,24 +263,6 @@ static void aspeed_reset_secondary(ARMCPU *cpu,cpu_set_pc (cs, info->smp_loader_start); } -/* -* Create a ROM and copy the flash contents at the expected address -* (0x0). Boots faster than execute-in-place. -*/ -static void aspeed_install_boot_rom (AspeedMachineState *bmc,BlockBackend *blk, -uint64_t rom_size) -{ -AspeedSoCState *soc = bmc->soc; -AspeedSoCClass *sc =ASPEED_SOC_GET_CLASS (soc); - -memory_region_init_rom (&bmc->boot_rom,NULL ,"aspeed.boot_rom" , rom_size, - &error_abort); -memory_region_add_subregion_overlap (&soc->spi_boot_container,0 , - &bmc->boot_rom,1 ); -aspeed_write_boot_rom (blk, sc->memmap[ASPEED_DEV_SPI_BOOT ], rom_size, - &error_abort); -} -#define VBOOTROM_FILE_NAME "ast27x0_bootrom.bin"/*
@@ -460,9 +442,10 @@ static void aspeed_machine_init(MachineState *machine)if (fmc0 && !boot_emmc) {uint64_t rom_size =memory_region_size (&bmc->soc->spi_boot); -aspeed_install_boot_rom (bmc, fmc0, rom_size); +aspeed_install_boot_rom (bmc->soc, fmc0, &bmc->boot_rom, rom_size); }else if (emmc0) { -aspeed_install_boot_rom (bmc,blk_by_legacy_dinfo (emmc0),64 * KiB); +aspeed_install_boot_rom (bmc->soc,blk_by_legacy_dinfo (emmc0), + &bmc->boot_rom,64 * KiB); } }
hw/arm/aspeed_soc_common.c +17 -0
@@ -178,6 +178,23 @@ void aspeed_write_boot_rom(BlockBackend *blk, hwaddr addr, size_t rom_size,rom_add_blob_fixed ("aspeed.boot_rom" , storage, rom_size, addr); } +/* +* Create a ROM and copy the flash contents at the expected address +* (0x0). Boots faster than execute-in-place. +*/ +void aspeed_install_boot_rom (AspeedSoCState *soc,BlockBackend *blk, +MemoryRegion *boot_rom,uint64_t rom_size) +{ +AspeedSoCClass *sc =ASPEED_SOC_GET_CLASS (soc); + +memory_region_init_rom (boot_rom,NULL ,"aspeed.boot_rom" , rom_size, + &error_abort); +memory_region_add_subregion_overlap (&soc->spi_boot_container,0 , + boot_rom,1 ); +aspeed_write_boot_rom (blk, sc->memmap[ASPEED_DEV_SPI_BOOT ], rom_size, + &error_abort); +} +static void aspeed_soc_realize (DeviceState *dev,Error **errp) {AspeedSoCState *s =ASPEED_SOC (dev);
Signature · 1 line
2.51.0
[PULL 30/32] hw/arm/aspeed: Move aspeed_load_vbootrom to common SoC code
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Move the vbootrom loader helper into common SoC code so it can be reused by all ASPEED boards, and decouple the API from AspeedMachineState.
Specifically:
- Move aspeed_load_vbootrom() to hw/arm/aspeed_soc_common.c and declare it in include/hw/arm/aspeed_soc.h.
- Change the helper’s signature to take AspeedSoCState * instead of AspeedMachineState *.
- Update aspeed_machine_init() call sites accordingly.
No functional change.
--- include/hw/arm/aspeed_soc.h | 4 ++++ hw/arm/aspeed.c | 31 +------------------------------ hw/arm/aspeed_soc_common.c | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 30 deletions(-)
include/hw/arm/aspeed_soc.h +4 -0
@@ -43,6 +43,8 @@#include "hw/char/serial-mm.h" #include "hw/intc/arm_gicv3.h" +#define VBOOTROM_FILE_NAME "ast27x0_bootrom.bin" +#define ASPEED_SPIS_NUM 3#define ASPEED_EHCIS_NUM 4#define ASPEED_WDTS_NUM 8
@@ -316,6 +318,8 @@ void aspeed_write_boot_rom(BlockBackend *blk, hwaddr addr, size_t rom_size, Error **errp);void aspeed_install_boot_rom (AspeedSoCState *soc,BlockBackend *blk,MemoryRegion *boot_rom,uint64_t rom_size); +void aspeed_load_vbootrom (AspeedSoCState *soc,const char *bios_name, +Error **errp);static inline int aspeed_uart_index (int uart_dev) {
hw/arm/aspeed.c +1 -30
@@ -26,9 +26,7 @@#include "hw/qdev-properties.h" #include "system/block-backend.h" #include "system/reset.h" -#include "hw/loader.h" #include "qemu/error-report.h" -#include "qemu/datadir.h" #include "qemu/units.h" #include "hw/qdev-clock.h" #include "system/system.h"
@@ -263,33 +261,6 @@ static void aspeed_reset_secondary(ARMCPU *cpu,cpu_set_pc (cs, info->smp_loader_start); } -#define VBOOTROM_FILE_NAME "ast27x0_bootrom.bin" - -/* -* This function locates the vbootrom image file specified via the command line -* using the -bios option. It loads the specified image into the vbootrom -* memory region and handles errors if the file cannot be found or loaded. -*/ -static void aspeed_load_vbootrom (AspeedMachineState *bmc,const char *bios_name, -Error **errp) -{ - g_autofree char *filename = NULL; -AspeedSoCState *soc = bmc->soc; -int ret; - - filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); -if (!filename) { -error_setg (errp,"Could not find vbootrom image '%s'" , bios_name); -return ; - } - - ret =load_image_mr (filename, &soc->vbootrom); -if (ret <0 ) { -error_setg (errp,"Failed to load vbootrom image '%s'" , bios_name); -return ; - } -} -static void sdhci_attach_drive (SDHCIState *sdhci,DriveInfo *dinfo,bool emmc,bool boot_emmc) {
@@ -451,7 +422,7 @@ static void aspeed_machine_init(MachineState *machine)if (amc->vbootrom) { bios_name = machine->firmware ?:VBOOTROM_FILE_NAME ; -aspeed_load_vbootrom (bmc, bios_name, &error_abort); +aspeed_load_vbootrom (bmc->soc, bios_name, &error_abort); }arm_load_kernel (ARM_CPU (first_cpu), machine, &aspeed_board_binfo);
hw/arm/aspeed_soc_common.c +25 -0
@@ -19,6 +19,7 @@#include "system/blockdev.h" #include "system/block-backend.h" #include "hw/loader.h" +#include "qemu/datadir.h" const char *aspeed_soc_cpu_type (AspeedSoCClass *sc)
@@ -195,6 +196,30 @@ void aspeed_install_boot_rom(AspeedSoCState *soc, BlockBackend *blk, &error_abort); } +/* +* This function locates the vbootrom image file specified via the command line +* using the -bios option. It loads the specified image into the vbootrom +* memory region and handles errors if the file cannot be found or loaded. +*/ +void aspeed_load_vbootrom (AspeedSoCState *soc,const char *bios_name, +Error **errp) +{ + g_autofree char *filename = NULL; +int ret; + + filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , bios_name); +if (!filename) { +error_setg (errp,"Could not find vbootrom image '%s'" , bios_name); +return ; + } + + ret =load_image_mr (filename, &soc->vbootrom); +if (ret <0 ) { +error_setg (errp,"Failed to load vbootrom image '%s'" , bios_name); +return ; + } +} +static void aspeed_soc_realize (DeviceState *dev,Error **errp) {AspeedSoCState *s =ASPEED_SOC (dev);
Signature · 1 line
2.51.0
[PULL 22/32] hw/pci-host/aspeed: Add AST2700 PCIe PHY
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Introduce a PCIe Host Controller PHY model for AST2700. This adds an AST2700 specific PHY type (TYPE_ASPEED_2700_PCIE_PHY) with a 0x800 byte register space and link-status bits compatible with the firmware’s expectations.
AST2700 provides three PCIe RCs; PCIe0 and PCIe1 are GEN4, PCIe2 is GEN2. The PHY exposes:PEHR_2700_LINK_GEN2 at 0x344, bit 18 indicates GEN2 link up PEHR_2700_LINK_GEN4 at 0x358, bit 8 indicates GEN4 link up
In real hardware these GEN2/GEN4 link bits are mutually exclusive. QEMU does not model GEN2 vs GEN4 signaling differences, so the reset handler sets both bits to 1. This keeps the model simple and lets firmware see the link as up; firmware will read the appropriate register per RC port to infer the intended mode.
The header gains TYPE_ASPEED_2700_PCIE_PHY; the new class derives from TYPE_ASPEED_PCIE_PHY, sets nr_regs to 0x800 >> 2, and installs an AST2700 reset routine that programs the class code (0x06040011) and the GEN2/GEN4 status bits.
--- include/hw/pci-host/aspeed_pcie.h | 1 + hw/pci-host/aspeed_pcie.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
include/hw/pci-host/aspeed_pcie.h +1 -0
@@ -114,6 +114,7 @@ struct AspeedPCIECfgClass { };#define TYPE_ASPEED_PCIE_PHY "aspeed.pcie-phy" +#define TYPE_ASPEED_2700_PCIE_PHY TYPE_ASPEED_PCIE_PHY "-ast2700"OBJECT_DECLARE_TYPE (AspeedPCIEPhyState, AspeedPCIEPhyClass,ASPEED_PCIE_PHY );struct AspeedPCIEPhyState {
hw/pci-host/aspeed_pcie.c +39 -0
@@ -696,6 +696,12 @@ REG32(PEHR_PROTECT, 0x7C) REG32(PEHR_LINK, 0xC0)FIELD (PEHR_LINK ,STS ,5 ,1 ) +/* AST2700 */ +REG32(PEHR_2700_LINK_GEN2, 0x344) + FIELD(PEHR_2700_LINK_GEN2, STS, 18, 1) +REG32(PEHR_2700_LINK_GEN4, 0x358) + FIELD(PEHR_2700_LINK_GEN4, STS, 8, 1) +#define ASPEED_PCIE_PHY_UNLOCK 0xA8 static uint64_t aspeed_pcie_phy_read(void *opaque, hwaddr addr,
@@ -803,6 +809,38 @@ static const TypeInfo aspeed_pcie_phy_info = { .class_size = sizeof(AspeedPCIEPhyClass), }; +static void aspeed_2700_pcie_phy_reset (DeviceState *dev) +{ +AspeedPCIEPhyState *s =ASPEED_PCIE_PHY (dev); +AspeedPCIEPhyClass *apc =ASPEED_PCIE_PHY_GET_CLASS (s); + +memset (s->regs,0 , apc->nr_regs <<2 ); + + s->regs[R_PEHR_ID ] = + (0x1150 <<R_PEHR_ID_DEV_SHIFT ) |PCI_VENDOR_ID_ASPEED ; + s->regs[R_PEHR_CLASS_CODE ] =0x06040011 ; + s->regs[R_PEHR_2700_LINK_GEN2 ] =R_PEHR_2700_LINK_GEN2_STS_MASK ; + s->regs[R_PEHR_2700_LINK_GEN4 ] =R_PEHR_2700_LINK_GEN4_STS_MASK ; +} + +static void aspeed_2700_pcie_phy_class_init (ObjectClass *klass, +const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +AspeedPCIEPhyClass *apc =ASPEED_PCIE_PHY_CLASS (klass); + + dc->desc ="ASPEED AST2700 PCIe Phy" ; +device_class_set_legacy_reset (dc, aspeed_2700_pcie_phy_reset); + + apc->nr_regs =0x800 >>2 ; +} + +static const TypeInfo aspeed_2700_pcie_phy_info = { + .name =TYPE_ASPEED_2700_PCIE_PHY , + .parent =TYPE_ASPEED_PCIE_PHY , + .class_init = aspeed_2700_pcie_phy_class_init, +}; +static void aspeed_pcie_register_types (void ) {type_register_static (&aspeed_pcie_rc_info);
@@ -810,6 +848,7 @@ static void aspeed_pcie_register_types(void)type_register_static (&aspeed_pcie_root_port_info);type_register_static (&aspeed_pcie_cfg_info);type_register_static (&aspeed_pcie_phy_info); +type_register_static (&aspeed_2700_pcie_phy_info); }type_init (aspeed_pcie_register_types);
Signature · 1 line
2.51.0
[PULL 15/32] hw/pci-host/aspeed: Add AST2600 PCIe PHY model
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
This patch introduces an initial ASPEED PCIe PHY/host controller model to support the AST2600 SoC. It provides a simple register block with MMIO read/write callbacks, integration into the build system, and trace events for debugging.
Key changes:
1. PCIe PHY MMIO read/write callbacks
Implemented aspeed_pcie_phy_read() and aspeed_pcie_phy_write() to handle 32-bit register accesses.
2. Build system and Kconfig integration
Added CONFIG_PCI_EXPRESS_ASPEED in hw/pci-host/Kconfig and meson rules.
Updated ASPEED_SOC in hw/arm/Kconfig to imply PCI_DEVICES and select PCI_EXPRESS_ASPEED.
3. Trace events for debug
New tracepoints aspeed_pcie_phy_read and aspeed_pcie_phy_write allow monitoring MMIO accesses.
4. Register space and defaults (AST2600 reference)
Expose a 0x100 register space, as documented in the AST2600 datasheet. On reset, set default values:
PEHR_ID: Vendor ID = ASPEED, Device ID = 0x1150 PEHR_CLASS_CODE = 0x06040006
PEHR_DATALINK = 0xD7040022
PEHR_LINK: bit[5] set to 1 to indicate link up.
This provides a skeleton device for the AST2600 platform. It enables firmware to detect the PCIe link as up by default and allows future extension.
This commit is the starting point of the series to introduce ASPEED PCIe Root Complex (RC) support. Based on previous work from Cédric Le Goater, the following commits in this series extend and refine the implementation:
- Add a PCIe Root Port so that devices can be attached without requiring an extra bridge.
- Restrict the Root Port device instantiation to the AST2600 platform.
- Integrate aspeed_cfg_translate_write() to support both AST2600 and AST2700.
- Add MSI support and a preliminary RC IOMMU address space.
- Fix issues with MSI interrupt clearing.
- Extend support to the AST2700 SoC.
- Drop the AST2600 RC_L support.
- Introduce PCIe RC functional tests covering both AST2600 and AST2700.
--- include/hw/pci-host/aspeed_pcie.h | 42 ++++++++ hw/pci-host/aspeed_pcie.c | 157 ++++++++++++++++++++++++++++++ hw/arm/Kconfig | 3 + hw/pci-host/Kconfig | 4 + hw/pci-host/meson.build | 1 + hw/pci-host/trace-events | 4 + 6 files changed, 211 insertions(+) create mode 100644 include/hw/pci-host/aspeed_pcie.h create mode 100644 hw/pci-host/aspeed_pcie.c
include/hw/pci-host/aspeed_pcie.h new file +42 -0
@@ -0,0 +1,42 @@ +/* +* ASPEED PCIe Host Controller +* +* Copyright (C) 2025 ASPEED Technology Inc. +* Copyright (c) 2022 Cédric Le Goater <[email protected]> +* +* Authors: +* Cédric Le Goater <[email protected]> +* Jamin Lin <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* Based on previous work from Cédric Le Goater. +* Modifications extend support for the ASPEED AST2600 and AST2700 platforms. +*/ + +#ifndef ASPEED_PCIE_H +#define ASPEED_PCIE_H + +#include "hw/sysbus.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci/pcie_host.h" +#include "qom/object.h" + +#define TYPE_ASPEED_PCIE_PHY "aspeed.pcie-phy" +OBJECT_DECLARE_TYPE (AspeedPCIEPhyState, AspeedPCIEPhyClass,ASPEED_PCIE_PHY ); + +struct AspeedPCIEPhyState { +SysBusDevice parent_obj; + +MemoryRegion mmio; +uint32_t *regs; +uint32_t id; +}; + +struct AspeedPCIEPhyClass { +SysBusDeviceClass parent_class; + +uint64_t nr_regs; +}; + +#endif /* ASPEED_PCIE_H */
hw/pci-host/aspeed_pcie.c new file +157 -0
157 lines not on this page · raw message
hw/arm/Kconfig +3 -0
@@ -541,6 +541,7 @@ config ASPEED_SOC bool default y depends on TCG && ARM + imply PCI_DEVICES select DS1338 select FTGMAC100 select I2C
@@ -561,6 +562,8 @@ config ASPEED_SOC select MAX31785 select FSI_APB2OPB_ASPEED select AT24C + select PCI_EXPRESS + select PCI_EXPRESS_ASPEED config MPS2 bool
hw/pci-host/Kconfig +4 -0
@@ -46,6 +46,10 @@ config PCI_I440FX select PCI select PAM +config PCI_EXPRESS_ASPEED + bool + select PCI_EXPRESS + config PCI_EXPRESS_Q35 bool select PCI_EXPRESS
hw/pci-host/meson.build +1 -0
@@ -2,6 +2,7 @@ pci_ss = ss.source_set() pci_ss.add(when: 'CONFIG_PAM', if_true: files('pam.c')) pci_ss.add(when: 'CONFIG_PCI_BONITO', if_true: files('bonito.c')) pci_ss.add(when: 'CONFIG_GT64120', if_true: files('gt64120.c')) +pci_ss.add(when: 'CONFIG_PCI_EXPRESS_ASPEED', if_true: files('aspeed_pcie.c')) pci_ss.add(when: 'CONFIG_PCI_EXPRESS_DESIGNWARE', if_true: files('designware.c')) pci_ss.add(when: 'CONFIG_PCI_EXPRESS_GENERIC_BRIDGE', if_true: files('gpex.c')) pci_ss.add(when: ['CONFIG_PCI_EXPRESS_GENERIC_BRIDGE', 'CONFIG_ACPI'], if_true: files('gpex-acpi.c'))
hw/pci-host/trace-events +4 -0
@@ -1,5 +1,9 @@ # See docs/devel/tracing.rst for syntax documentation. +# aspeed_pcie.c +aspeed_pcie_phy_read(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32 +aspeed_pcie_phy_write(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32 + # bonito.c bonito_spciconf_small_access(uint64_t addr, unsigned size) "PCI config address is smaller then 32-bit, addr: 0x%"PRIx64", size: %u"
Signature · 1 line
2.51.0
[PULL 24/32] hw/pci-host/aspeed: Disable Root Device and place Root Port at 00:00.0 to AST2700
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
AST2700 does not implement a PCIe Root Device; each RC exposes a single PCIe Root Port at devfn 0:0.0.
--- hw/pci-host/aspeed_pcie.c | 2 ++ 1 file changed, 2 insertions(+)
hw/pci-host/aspeed_pcie.c +2 -0
@@ -829,6 +829,8 @@ static void aspeed_2700_pcie_cfg_class_init(ObjectClass *klass, apc->nr_regs =0x100 >>2 ; apc->rc_msi_addr =0x000000F0 ; apc->rc_bus_nr =0 ; + apc->rc_has_rd = false; + apc->rc_rp_addr =PCI_DEVFN (0 ,0 ); }static const TypeInfo aspeed_2700_pcie_cfg_info = {
Signature · 1 line
2.51.0
[PULL 13/32] tests/functional/arm: Add AST2600 boot test with generated OTP image
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
Add a functional test that boots an AST2600 machine with a generated OTP image. The test verifies that OTP contents are read during early boot and that the system reaches the expected console prompt.
--- tests/functional/arm/test_aspeed_ast2600.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
tests/functional/arm/test_aspeed_ast2600.py +15 -0
@@ -136,5 +136,20 @@ def test_arm_ast2600_evb_sdk(self): exec_command_and_wait_for_pattern(self, '/sbin/hwclock -f /dev/rtc1', year) + def test_arm_ast2600_otp_blockdev_device(self): + self.vm.set_machine("ast2600-evb") + + image_path = self.archive_extract(self.ASSET_SDK_V907_AST2600) + otp_img = self.generate_otpmem_image() + + self.vm.set_console() + self.vm.add_args( + "-blockdev", f"driver=file,filename={otp_img},node-name=otp", + "-global", "aspeed-otp.drive=otp", + ) + self.do_test_arm_aspeed_sdk_start( + self.scratch_file("ast2600-default", "image-bmc")) + self.wait_for_console_pattern("ast2600-default login:") + if __name__ == '__main__': AspeedTest.main()
Signature · 1 line
2.51.0
[PULL 32/32] hw/arm/aspeed_ast27x0-fc: Make sub-init functions return bool with errp
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Refactor ast2700fc_ca35_init(), ast2700fc_ssp_init(), and ast2700fc_tsp_init() to take an Error **errp parameter and return a bool.
Each function now reports failure through the error object and returns false.
--- hw/arm/aspeed_ast27x0-fc.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-)
hw/arm/aspeed_ast27x0-fc.c +20 -14
@@ -56,7 +56,7 @@ struct Ast2700FCState {#define AST2700FC_FMC_MODEL "w25q01jvq"#define AST2700FC_SPI_MODEL "w25q512jv" -static void ast2700fc_ca35_init (MachineState *machine) +static bool ast2700fc_ca35_init (MachineState *machine,Error **errp) {Ast2700FCState *s =AST2700A1FC (machine);AspeedSoCState *soc;
@@ -71,8 +71,8 @@ static void ast2700fc_ca35_init(MachineState *machine)memory_region_add_subregion (get_system_memory (),0 , &s->ca35_memory);if (!memory_region_init_ram (&s->ca35_dram,OBJECT (&s->ca35),"ca35-dram" , -AST2700FC_BMC_RAM_SIZE , &error_abort)) { -return ; +AST2700FC_BMC_RAM_SIZE , errp)) { +return false; }object_property_set_link (OBJECT (&s->ca35),"memory" ,OBJECT (&s->ca35_memory), &error_abort);
@@ -92,8 +92,8 @@ static void ast2700fc_ca35_init(MachineState *machine)object_property_set_int (OBJECT (&s->ca35),"hw-strap2" ,AST2700FC_HW_STRAP2 , &error_abort);aspeed_soc_uart_set_chr (soc,ASPEED_DEV_UART12 ,serial_hd (0 )); -if (!qdev_realize (DEVICE (&s->ca35),NULL , &error_abort)) { -return ; +if (!qdev_realize (DEVICE (&s->ca35),NULL , errp)) { +return false; }/*
@@ -108,9 +108,11 @@ static void ast2700fc_ca35_init(MachineState *machine) ast2700fc_board_info.loader_start = sc->memmap[ASPEED_DEV_SDRAM ];arm_load_kernel (ARM_CPU (first_cpu), machine, &ast2700fc_board_info); + +return true; } -static void ast2700fc_ssp_init (MachineState *machine) +static bool ast2700fc_ssp_init (MachineState *machine,Error **errp) {AspeedSoCState *soc;Ast2700FCState *s =AST2700A1FC (machine);
@@ -127,12 +129,14 @@ static void ast2700fc_ssp_init(MachineState *machine) soc =ASPEED_SOC (&s->ssp);aspeed_soc_uart_set_chr (soc,ASPEED_DEV_UART4 ,serial_hd (1 )); -if (!qdev_realize (DEVICE (&s->ssp),NULL , &error_abort)) { -return ; +if (!qdev_realize (DEVICE (&s->ssp),NULL , errp)) { +return false; } + +return true; } -static void ast2700fc_tsp_init (MachineState *machine) +static bool ast2700fc_tsp_init (MachineState *machine,Error **errp) {AspeedSoCState *soc;Ast2700FCState *s =AST2700A1FC (machine);
@@ -149,16 +153,18 @@ static void ast2700fc_tsp_init(MachineState *machine) soc =ASPEED_SOC (&s->tsp);aspeed_soc_uart_set_chr (soc,ASPEED_DEV_UART7 ,serial_hd (2 )); -if (!qdev_realize (DEVICE (&s->tsp),NULL , &error_abort)) { -return ; +if (!qdev_realize (DEVICE (&s->tsp),NULL , errp)) { +return false; } + +return true; }static void ast2700fc_init (MachineState *machine) { -ast2700fc_ca35_init (machine); -ast2700fc_ssp_init (machine); -ast2700fc_tsp_init (machine); +ast2700fc_ca35_init (machine, &error_abort); +ast2700fc_ssp_init (machine, &error_abort); +ast2700fc_tsp_init (machine, &error_abort); }static void ast2700fc_class_init (ObjectClass *oc,const void *data)
Signature · 1 line
2.51.0
[PULL 17/32] hw/pci-host/aspeed: Add AST2600 PCIe Root Device support
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Introduce a PCIe Root Device for AST2600 platform.
The AST2600 root complex exposes a PCIe root device at bus 80, devfn 0. This root device is implemented as a child of the PCIe RC and modeled as a host bridge PCI function (class_id = PCI_CLASS_BRIDGE_HOST).
Key changes:
- Add a new device type "aspeed.pcie-root-device".
- Instantiate the root device as part of AspeedPCIERcState.
- Initialize it during RC realize() and attach it to the root bus.
- Mark the root device as non-user-creatable.
- Add RC boolean property "has-rd" to control whether the Root Device is created (platforms can enable/disable it as needed).
Note: Only AST2600 implements this PCIe root device. AST2700 does not provide one.
--- include/hw/pci-host/aspeed_pcie.h | 11 ++++++ hw/pci-host/aspeed_pcie.c | 56 +++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
include/hw/pci-host/aspeed_pcie.h +11 -0
@@ -40,6 +40,13 @@ typedef struct AspeedPCIERegMap {AspeedPCIERcRegs rc; } AspeedPCIERegMap; +#define TYPE_ASPEED_PCIE_ROOT_DEVICE "aspeed.pcie-root-device" +OBJECT_DECLARE_SIMPLE_TYPE (AspeedPCIERootDeviceState,ASPEED_PCIE_ROOT_DEVICE ); + +struct AspeedPCIERootDeviceState { +PCIBridge parent_obj; +}; +#define TYPE_ASPEED_PCIE_RC "aspeed.pcie-rc"OBJECT_DECLARE_SIMPLE_TYPE (AspeedPCIERcState,ASPEED_PCIE_RC );
@@ -53,7 +60,10 @@ struct AspeedPCIERcState {uint32_t bus_nr;char name[16 ]; +bool has_rd;qemu_irq irq; + +AspeedPCIERootDeviceState root_device; };/* Bridge between AHB bus and PCIe RC. */
@@ -79,6 +89,7 @@ struct AspeedPCIECfgClass {uint64_t rc_bus_nr;uint64_t nr_regs; +bool rc_has_rd; };#define TYPE_ASPEED_PCIE_PHY "aspeed.pcie-phy"
hw/pci-host/aspeed_pcie.c +56 -0
92 lines not on this page · raw message
Signature · 1 line
2.51.0
[PULL 21/32] hw/arm/aspeed_ast2600: Add PCIe RC support (RC_H only)
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Wire up the PCIe Root Complex in the AST2600 SoC model.
According to the AST2600 firmware driver, only the RC_H controller is supported. RC_H uses PCIe PHY1 at 0x1e6ed200 and the PCIe config (H2X) register block at 0x1e770000. The RC_H MMIO window is mapped at 0x70000000–0x80000000. RC_L is not modeled. The RC_H interrupt is wired to IRQ 168. Only RC_H is realized and connected to the SoC interrupt controller.
The SoC integration initializes PCIe PHY1, instantiates a single RC instance, wires its MMIO regions, and connects its interrupt. An alias region is added to map the RC MMIO space into the guest physical address space.
This provides enough functionality for firmware and guest drivers to discover and use the AST2600 RC_H Root Complex while leaving RC_L unimplemented.
--- include/hw/arm/aspeed_soc.h | 1 + hw/arm/aspeed_ast2600.c | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
include/hw/arm/aspeed_soc.h +1 -0
@@ -62,6 +62,7 @@ struct AspeedSoCState {MemoryRegion spi_boot_container;MemoryRegion spi_boot;MemoryRegion vbootrom; +MemoryRegion pcie_mmio_alias[ASPEED_PCIE_NUM ];AddressSpace dram_as;AspeedRtcState rtc;AspeedTimerCtrlState timerctrl;
hw/arm/aspeed_ast2600.c +74 -0
115 lines not on this page · raw message
Signature · 1 line
2.51.0
[PULL 20/32] hw/arm/aspeed: Wire up PCIe devices in SoC model
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Add PCIe controller and PHY instances to the Aspeed SoC state and device enum. This prepares the SoC model to host PCIe Root Complexes and their associated PHYs.
Although the AST2600 supports only a single Root Complex, the AST2700 provides three Root Complexes. For this reason, the model defines arrays of three PCIe config/PHY objects and enumerates three PCIe device IDs so that both SoCs can be represented consistently.
--- include/hw/arm/aspeed_soc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/hw/arm/aspeed_soc.h +13 -0
@@ -37,6 +37,7 @@#include "qom/object.h" #include "hw/misc/aspeed_lpc.h" #include "hw/misc/unimp.h" +#include "hw/pci-host/aspeed_pcie.h" #include "hw/misc/aspeed_peci.h" #include "hw/fsi/aspeed_apb2opb.h" #include "hw/char/serial-mm.h"
@@ -49,6 +50,7 @@#define ASPEED_MACS_NUM 4#define ASPEED_UARTS_NUM 13#define ASPEED_JTAG_NUM 2 +#define ASPEED_PCIE_NUM 3struct AspeedSoCState {DeviceState parent;
@@ -87,6 +89,8 @@ struct AspeedSoCState {AspeedSDHCIState sdhci;AspeedSDHCIState emmc;AspeedLPCState lpc; +AspeedPCIECfgState pcie[ASPEED_PCIE_NUM ]; +AspeedPCIEPhyState pcie_phy[ASPEED_PCIE_NUM ];AspeedPECIState peci;SerialMM uart[ASPEED_UARTS_NUM ];Clock *sysclk;
@@ -254,6 +258,15 @@ enum {ASPEED_DEV_LPC ,ASPEED_DEV_IBT ,ASPEED_DEV_I2C , +ASPEED_DEV_PCIE0 , +ASPEED_DEV_PCIE1 , +ASPEED_DEV_PCIE2 , +ASPEED_DEV_PCIE_PHY0 , +ASPEED_DEV_PCIE_PHY1 , +ASPEED_DEV_PCIE_PHY2 , +ASPEED_DEV_PCIE_MMIO0 , +ASPEED_DEV_PCIE_MMIO1 , +ASPEED_DEV_PCIE_MMIO2 ,ASPEED_DEV_PECI ,ASPEED_DEV_ETH1 , ASPEED_DEV_ETH2,
Signature · 1 line
2.51.0
[PULL 31/32] hw/arm/aspeed_ast27x0-fc: Drop dead return checks
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
1. object_property_set_link() can return false only when it fails, and it sets an error when it fails. Since passing &error_abort causes an abort, the function never returns false, and the return statement is effectively dead code.
2. object_property_set_int() is considered as a routine which shouldn't fail. So the common practice in models is to pass &error_abort and ignore the returned value.
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/#26540626
No functional change.
--- hw/arm/aspeed_ast27x0-fc.c | 43 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 29 deletions(-)
hw/arm/aspeed_ast27x0-fc.c +14 -29
@@ -74,19 +74,12 @@ static void ast2700fc_ca35_init(MachineState *machine) AST2700FC_BMC_RAM_SIZE, &error_abort)) {return ; } -if (!object_property_set_link (OBJECT (&s->ca35),"memory" , -OBJECT (&s->ca35_memory), - &error_abort)) { -return ; - }; -if (!object_property_set_link (OBJECT (&s->ca35),"dram" , -OBJECT (&s->ca35_dram), &error_abort)) { -return ; - } -if (!object_property_set_int (OBJECT (&s->ca35),"ram-size" , -AST2700FC_BMC_RAM_SIZE , &error_abort)) { -return ; - } +object_property_set_link (OBJECT (&s->ca35),"memory" , +OBJECT (&s->ca35_memory), &error_abort); +object_property_set_link (OBJECT (&s->ca35),"dram" ,OBJECT (&s->ca35_dram), + &error_abort); +object_property_set_int (OBJECT (&s->ca35),"ram-size" , +AST2700FC_BMC_RAM_SIZE , &error_abort); for (int i = 0; i < sc->macs_num; i++) { if (!qemu_configure_nic_device(DEVICE(&soc->ftgmac100[i]),
@@ -94,14 +87,10 @@ static void ast2700fc_ca35_init(MachineState *machine)break ; } } -if (!object_property_set_int (OBJECT (&s->ca35),"hw-strap1" , -AST2700FC_HW_STRAP1 , &error_abort)) { -return ; - } -if (!object_property_set_int (OBJECT (&s->ca35),"hw-strap2" , -AST2700FC_HW_STRAP2 , &error_abort)) { -return ; - } +object_property_set_int (OBJECT (&s->ca35),"hw-strap1" , +AST2700FC_HW_STRAP1 , &error_abort); +object_property_set_int (OBJECT (&s->ca35),"hw-strap2" , +AST2700FC_HW_STRAP2 , &error_abort);aspeed_soc_uart_set_chr (soc,ASPEED_DEV_UART12 ,serial_hd (0 ));if (!qdev_realize (DEVICE (&s->ca35),NULL , &error_abort)) {return ;
@@ -133,10 +122,8 @@ static void ast2700fc_ssp_init(MachineState *machine) UINT64_MAX);qdev_connect_clock_in (DEVICE (&s->ssp),"sysclk" , s->ssp_sysclk); -if (!object_property_set_link (OBJECT (&s->ssp),"memory" , -OBJECT (&s->ssp_memory), &error_abort)) { -return ; - } +object_property_set_link (OBJECT (&s->ssp),"memory" , +OBJECT (&s->ssp_memory), &error_abort); soc =ASPEED_SOC (&s->ssp);aspeed_soc_uart_set_chr (soc,ASPEED_DEV_UART4 ,serial_hd (1 ));
@@ -157,10 +144,8 @@ static void ast2700fc_tsp_init(MachineState *machine) UINT64_MAX);qdev_connect_clock_in (DEVICE (&s->tsp),"sysclk" , s->tsp_sysclk); -if (!object_property_set_link (OBJECT (&s->tsp),"memory" , -OBJECT (&s->tsp_memory), &error_abort)) { -return ; - } +object_property_set_link (OBJECT (&s->tsp),"memory" , +OBJECT (&s->tsp_memory), &error_abort); soc =ASPEED_SOC (&s->tsp);aspeed_soc_uart_set_chr (soc,ASPEED_DEV_UART7 ,serial_hd (2 ));
Signature · 1 line
2.51.0
[PULL 25/32] hw/arm/aspeed_ast27x0: Introduce 3 PCIe RCs for AST2700
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Add PCIe Root Complex support to the AST2700 SoC model.
The AST2700 A1 silicon revision provides three PCIe Root Complexes:
PCIe0 with its PHY at 0x12C15000, config (H2X) block at 0x120E0000, MMIO window at 0x60000000, and GIC IRQ 56.
PCIe1 with its PHY at 0x12C15800, config (H2X) block at 0x120F0000, MMIO window at 0x80000000, and GIC IRQ 57.
PCIe2 with its PHY at 0x14C1C000, config (H2X) block at 0x140D0000, MMIO window at 0xA0000000, and IRQ routed through INTC4 bit 31 mapped to GIC IRQ 196.
Each RC instantiates a PHY device, a PCIe config (H2X) bridge, and an MMIO alias region. The per-RC MMIO alias size is 0x20000000. The AST2700 A0 silicon revision does not support PCIe Root Complexes, so pcie_num is set to 0 in that variant.
--- include/hw/arm/aspeed_soc.h | 1 + hw/arm/aspeed_ast27x0.c | 74 +++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
include/hw/arm/aspeed_soc.h +1 -0
@@ -186,6 +186,7 @@ struct AspeedSoCClass {uint32_t silicon_rev;uint64_t sram_size;uint64_t secsram_size; +int pcie_num;int spis_num;int ehcis_num;int wdts_num;
hw/arm/aspeed_ast27x0.c +74 -0
152 lines not on this page · raw message
Signature · 1 line
2.51.0
[PULL 19/32] hw/pci-host/aspeed: Add MSI support and per-RC IOMMU address space
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Add MSI support to the ASPEED PCIe RC/Config model and introduce a per-RC "IOMMU root" address space to correctly route MSI writes.
On AST2700 all RCs use the same MSI address, and the MSI target is PCI system memory (not normal DRAM). If the MSI window were mapped into real system RAM, an endpoint's write could be observed by other RCs and spuriously trigger their interrupts. To avoid this, each RC now owns an isolated IOMMU root AddressSpace that contains a small MSI window and a DRAM alias region for normal DMA.
The MSI window captures writes and asserts the RC IRQ. MSI status bits are tracked in new H2X RC_H registers (R_H2X_RC_H_MSI_EN{0,1} and R_H2X_RC_H_MSI_STS{0,1}). Clearing all status bits drops the IRQ. The default MSI address is set to 0x1e77005c and can be overridden via the msi-addr property.
This keeps MSI traffic contained within each RC while preserving normal DMA to system DRAM. It enables correct MSI/MSI-X interrupt delivery when multiple RCs use the same MSI target address.
--- include/hw/pci-host/aspeed_pcie.h | 10 +++ hw/pci-host/aspeed_pcie.c | 132 ++++++++++++++++++++++++++++++ hw/pci-host/trace-events | 3 + 3 files changed, 145 insertions(+)
include/hw/pci-host/aspeed_pcie.h +10 -0
@@ -35,6 +35,8 @@ typedef struct AspeedPCIECfgTxDesc {typedef struct AspeedPCIERcRegs {uint32_t int_en_reg;uint32_t int_sts_reg; +uint32_t msi_sts0_reg; +uint32_t msi_sts1_reg; }AspeedPCIERcRegs ; typedef struct AspeedPCIERegMap {
@@ -61,11 +63,18 @@ OBJECT_DECLARE_SIMPLE_TYPE(AspeedPCIERcState, ASPEED_PCIE_RC);struct AspeedPCIERcState {PCIExpressHost parent_obj; +MemoryRegion iommu_root; +AddressSpace iommu_as; +MemoryRegion dram_alias; +MemoryRegion *dram_mr;MemoryRegion mmio_window; +MemoryRegion msi_window;MemoryRegion io_window;MemoryRegion mmio;MemoryRegion io; +uint64_t dram_base; +uint32_t msi_addr;uint32_t rp_addr;uint32_t bus_nr;char name[16 ];
@@ -97,6 +106,7 @@ struct AspeedPCIECfgClass {const AspeedPCIERegMap *reg_map;const MemoryRegionOps *reg_ops; +uint32_t rc_msi_addr;uint32_t rc_rp_addr;uint64_t rc_bus_nr;uint64_t nr_regs;
hw/pci-host/aspeed_pcie.c +132 -0
198 lines not on this page · raw message
hw/pci-host/trace-events +3 -0
@@ -2,6 +2,9 @@ # aspeed_pcie.c aspeed_pcie_rc_intx_set_irq(uint32_t id, int num, int level) "%d: num %d set IRQ leve %d" +aspeed_pcie_rc_msi_notify(uint32_t id, uint64_t addr, uint64_t data) "%d: 0x%" PRIx64 " data 0x%" PRIx64 +aspeed_pcie_rc_msi_set_irq(uint32_t id, uint64_t unm, int level) "%d: num 0x%" PRIx64 " set IRQ level %d" +aspeed_pcie_rc_msi_clear_irq(uint32_t id, int level) "%d: clear IRQ level %d" aspeed_pcie_cfg_read(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32 aspeed_pcie_cfg_write(uint32_t id, uint64_t addr, uint32_t value) "%d: addr 0x%" PRIx64 " value 0x%" PRIx32 aspeed_pcie_cfg_rw(uint32_t id, const char *dir, uint8_t bus, uint8_t devfn, uint64_t addr, uint64_t data) "%d: %s bus:0x%x devfn:0x%x addr 0x%" PRIx64 " data 0x%" PRIx64
Signature · 1 line
2.51.0
[PULL 28/32] hw/arm/aspeed: Move write_boot_rom to common SoC code
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Move the write_boot_rom helper from hw/arm/aspeed.c into hw/arm/aspeed_soc_common.c so it can be reused by all ASPEED machines. Export the API as aspeed_write_boot_rom() in include/hw/arm/aspeed_soc.h and update the existing call site to use the new helper.
No functional change.
--- include/hw/arm/aspeed_soc.h | 2 ++ hw/arm/aspeed.c | 33 ++------------------------------- hw/arm/aspeed_soc_common.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 31 deletions(-)
include/hw/arm/aspeed_soc.h +2 -0
@@ -312,6 +312,8 @@ void aspeed_mmio_map_unimplemented(AspeedSoCState *s, SysBusDevice *dev, uint64_t size);void aspeed_board_init_flashes (AspeedSMCState *s,const char *flashtype,unsigned int count,int unit0); +void aspeed_write_boot_rom (BlockBackend *blk,hwaddr addr,size_t rom_size, +Error **errp);static inline int aspeed_uart_index (int uart_dev) {
hw/arm/aspeed.c +2 -31
@@ -263,35 +263,6 @@ static void aspeed_reset_secondary(ARMCPU *cpu,cpu_set_pc (cs, info->smp_loader_start); } -static void write_boot_rom (BlockBackend *blk,hwaddr addr,size_t rom_size, -Error **errp) -{ - g_autofree void *storage = NULL; -int64_t size; - -/* -* The block backend size should have already been 'validated' by -* the creation of the m25p80 object. -*/ - size =blk_getlength (blk); -if (size <=0 ) { -error_setg (errp,"failed to get flash size" ); -return ; - } - -if (rom_size > size) { - rom_size = size; - } - - storage =g_malloc0 (rom_size); -if (blk_pread (blk,0 , rom_size, storage,0 ) <0 ) { -error_setg (errp,"failed to read the initial flash content" ); -return ; - } - -rom_add_blob_fixed ("aspeed.boot_rom" , storage, rom_size, addr); -} -/* * Create a ROM and copy the flash contents at the expected address * (0x0). Boots faster than execute-in-place.
@@ -306,8 +277,8 @@ static void aspeed_install_boot_rom(AspeedMachineState *bmc, BlockBackend *blk, &error_abort);memory_region_add_subregion_overlap (&soc->spi_boot_container,0 , &bmc->boot_rom,1 ); -write_boot_rom (blk, sc->memmap[ASPEED_DEV_SPI_BOOT ], - rom_size, &error_abort); +aspeed_write_boot_rom (blk, sc->memmap[ASPEED_DEV_SPI_BOOT ], rom_size, + &error_abort); }#define VBOOTROM_FILE_NAME "ast27x0_bootrom.bin"
hw/arm/aspeed_soc_common.c +31 -0
@@ -17,6 +17,8 @@#include "hw/arm/aspeed_soc.h" #include "hw/char/serial-mm.h" #include "system/blockdev.h" +#include "system/block-backend.h" +#include "hw/loader.h" const char *aspeed_soc_cpu_type (AspeedSoCClass *sc)
@@ -147,6 +149,35 @@ void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype, } } +void aspeed_write_boot_rom (BlockBackend *blk,hwaddr addr,size_t rom_size, +Error **errp) +{ + g_autofree void *storage = NULL; +int64_t size; + +/* +* The block backend size should have already been 'validated' by +* the creation of the m25p80 object. +*/ + size =blk_getlength (blk); +if (size <=0 ) { +error_setg (errp,"failed to get flash size" ); +return ; + } + +if (rom_size > size) { + rom_size = size; + } + + storage =g_malloc0 (rom_size); +if (blk_pread (blk,0 , rom_size, storage,0 ) <0 ) { +error_setg (errp,"failed to read the initial flash content" ); +return ; + } + +rom_add_blob_fixed ("aspeed.boot_rom" , storage, rom_size, addr); +} +static void aspeed_soc_realize (DeviceState *dev,Error **errp) {AspeedSoCState *s =ASPEED_SOC (dev);
Signature · 1 line
2.51.0
[PULL 12/32] tests/functional/arm: Add AST1030 boot test with generated OTP image
In reply to Cédric Le GoaterFrom: Kane-Chen-AS <[email protected]>
Add a functional test that boots an AST1030 machine with a generated OTP image. The test verifies that OTP contents are read during early boot and that the system reaches the expected console prompt.
--- tests/functional/arm/test_aspeed_ast1030.py | 24 +++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
tests/functional/arm/test_aspeed_ast1030.py +20 -4
@@ -7,17 +7,18 @@ # SPDX-License-Identifier: GPL-2.0-or-later from qemu_test import LinuxKernelTest, Asset +from aspeed import AspeedTest from qemu_test import exec_command_and_wait_for_pattern -class AST1030Machine(LinuxKernelTest): +class AST1030Machine(AspeedTest): ASSET_ZEPHYR_3_02 = Asset( ('https://github.com/AspeedTech-BMC' '/zephyr/releases/download/v00.03.02/ast1030-evb-demo.zip'), '1ec83caab3ddd5d09481772801be7210e222cb015ce22ec6fffb8a76956dcd4f') - def test_ast1030_zephyros_3_02(self): + def test_arm_ast1030_zephyros_3_02(self): self.set_machine('ast1030-evb') kernel_name = "ast1030-evb-demo-3/zephyr.elf"
@@ -36,7 +37,7 @@ def test_ast1030_zephyros_3_02(self): '/zephyr/releases/download/v00.01.07/ast1030-evb-demo.zip'), 'ad52e27959746988afaed8429bf4e12ab988c05c4d07c9d90e13ec6f7be4574c') - def test_ast1030_zephyros_1_07(self): + def test_arm_ast1030_zephyros_1_07(self): self.set_machine('ast1030-evb') kernel_name = "ast1030-evb-demo/zephyr.bin"
@@ -68,6 +69,21 @@ def test_ast1030_zephyros_1_07(self): 'kernel uptime', ]: exec_command_and_wait_for_pattern(self, shell_cmd, "uart:~$") + def test_arm_ast1030_otp_blockdev_device(self): + self.vm.set_machine("ast1030-evb") + + kernel_name = "ast1030-evb-demo-3/zephyr.elf" + kernel_file = self.archive_extract(self.ASSET_ZEPHYR_3_02, member=kernel_name) + otp_img = self.generate_otpmem_image() + + self.vm.set_console() + self.vm.add_args( + "-kernel", kernel_file, + "-blockdev", f"driver=file,filename={otp_img},node-name=otp", + "-global", "aspeed-otp.drive=otp", + ) + self.vm.launch() + self.wait_for_console_pattern("Booting Zephyr OS") if __name__ == '__main__': - LinuxKernelTest.main() + AspeedTest.main()
Signature · 1 line
2.51.0
[PULL 14/32] hw/pci/pci_ids: Add PCI vendor ID for ASPEED
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
--- include/hw/pci/pci_ids.h | 2 ++ 1 file changed, 2 insertions(+)
include/hw/pci/pci_ids.h +2 -0
@@ -291,4 +291,6 @@#define PCI_VENDOR_ID_NVIDIA 0x10de +#define PCI_VENDOR_ID_ASPEED 0x1A03 +#endif
Signature · 1 line
2.51.0
[PULL 27/32] hw/arm/aspeed: Move aspeed_board_init_flashes() to common SoC code
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Relocate aspeed_board_init_flashes() from hw/arm/aspeed.c into hw/arm/aspeed_soc_common.c so the helper can be reused by all ASPEED machines. The API was already declared in include/hw/arm/aspeed_soc.h; this change moves its implementation out of the machine file to keep aspeed.c cleaner.
No functional change.
--- hw/arm/aspeed.c | 22 ---------------------- hw/arm/aspeed_soc_common.c | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 22 deletions(-)
hw/arm/aspeed.c +0 -22
@@ -337,28 +337,6 @@ static void aspeed_load_vbootrom(AspeedMachineState *bmc, const char *bios_name, } } -void aspeed_board_init_flashes (AspeedSMCState *s,const char *flashtype, -unsigned int count,int unit0) -{ -int i; - -if (!flashtype) { -return ; - } - -for (i =0 ; i < count; ++i) { -DriveInfo *dinfo =drive_get (IF_MTD ,0 , unit0 + i); -DeviceState *dev; - - dev =qdev_new (flashtype); -if (dinfo) { -qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo)); - } -qdev_prop_set_uint8 (dev,"cs" , i); -qdev_realize_and_unref (dev,BUS (s->spi), &error_fatal); - } -} -static void sdhci_attach_drive (SDHCIState *sdhci,DriveInfo *dinfo,bool emmc,bool boot_emmc) {
hw/arm/aspeed_soc_common.c +23 -0
@@ -16,6 +16,7 @@#include "hw/misc/unimp.h" #include "hw/arm/aspeed_soc.h" #include "hw/char/serial-mm.h" +#include "system/blockdev.h" const char *aspeed_soc_cpu_type (AspeedSoCClass *sc)
@@ -124,6 +125,28 @@ void aspeed_mmio_map_unimplemented(AspeedSoCState *s, SysBusDevice *dev, sysbus_mmio_get_region(dev, 0), -1000); } +void aspeed_board_init_flashes (AspeedSMCState *s,const char *flashtype, +unsigned int count,int unit0) +{ +int i; + +if (!flashtype) { +return ; + } + +for (i =0 ; i < count; ++i) { +DriveInfo *dinfo =drive_get (IF_MTD ,0 , unit0 + i); +DeviceState *dev; + + dev =qdev_new (flashtype); +if (dinfo) { +qdev_prop_set_drive (dev,"drive" ,blk_by_legacy_dinfo (dinfo)); + } +qdev_prop_set_uint8 (dev,"cs" , i); +qdev_realize_and_unref (dev,BUS (s->spi), &error_fatal); + } +} +static void aspeed_soc_realize (DeviceState *dev,Error **errp) {AspeedSoCState *s =ASPEED_SOC (dev);
Signature · 1 line
2.51.0
[PULL 23/32] hw/pci-host/aspeed: Add AST2700 PCIe config with dedicated H2X blocks
In reply to Cédric Le GoaterFrom: Jamin Lin <[email protected]>
Introduce PCIe config (H2X) support for the AST2700 SoC.
Unlike the AST2600, the AST2700 provides three independent Root Complexes, each with its own H2X (AHB to PCIe bridge) register block of size 0x100. All RCs use the same MSI address (0x000000F0). The H2X block includes two different access paths:
1. CFGI (internal bridge): used to access the host bridge itself, always with BDF=0. The AST2700 controller simplifies the design by exposing only one register (H2X_CFGI_TLP) with fields for ADDR[15:0], BEN[19:16], and WR[20]. This is not a full TLP descriptor as in the external case. For QEMU readability and code reuse, the model converts H2X_CFGI_TLP into a standard TLP TX descriptor with BDF forced to 0 and then calls the existing helpers aspeed_pcie_cfg_readwrite() and aspeed_pcie_cfg_translate_write().
2. CFGE (external EP access): used to access external endpoints. The AST2700 design provides H2X_CFGE_TLP1 and a small FIFO at H2X_CFGE_TLPN. For reads, TX DESC0 is stored in TLP1 and DESC1/DESC2 in TLPN FIFO slots. For writes, TX DESC0 is stored in TLP1, DESC1/DESC2 in TLPN FIFO[0..1], and TX write data in TLPN FIFO[2].
The implementation extends AspeedPCIECfgState with a small FIFO and index, wires up new register definitions for AST2700, and adds a specific ops table and class (TYPE_ASPEED_2700_PCIE_CFG). The reset handler clears the FIFO state. Interrupt and MSI status registers are also supported.
This provides enough modeling for firmware and drivers to use any of the three PCIe RCs on AST2700 with their own dedicated H2X config window, while reusing existing TLP decode helpers in QEMU.
--- include/hw/pci-host/aspeed_pcie.h | 3 + hw/pci-host/aspeed_pcie.c | 158 ++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+)
include/hw/pci-host/aspeed_pcie.h +3 -0
@@ -87,6 +87,7 @@ struct AspeedPCIERcState {/* Bridge between AHB bus and PCIe RC. */ #define TYPE_ASPEED_PCIE_CFG "aspeed.pcie-cfg" +#define TYPE_ASPEED_2700_PCIE_CFG TYPE_ASPEED_PCIE_CFG "-ast2700"OBJECT_DECLARE_TYPE (AspeedPCIECfgState, AspeedPCIECfgClass,ASPEED_PCIE_CFG );struct AspeedPCIECfgState {
@@ -98,6 +99,8 @@ struct AspeedPCIECfgState {const AspeedPCIERcRegs *rc_regs;AspeedPCIERcState rc; +uint32_t tlpn_fifo[3 ]; +uint32_t tlpn_idx; };struct AspeedPCIECfgClass {
hw/pci-host/aspeed_pcie.c +158 -0
194 lines not on this page · raw message
Signature · 1 line
2.51.0
Richard Henderson
AppliedQuoted 15 lines · Cédric Le Goater
The following changes since commit
4975b64efb5aa4248cbc3760312bbe08d6e71638:Merge tag 'pull-loongarch-20250928' ofhttps://github.com/bibo-mao/qemu into staging (2025-09-28 09:01:35 -0700)are available in the Git repository at:
https://github.com/legoater/qemu/ tags/pull-aspeed-20250929for you to fetch changes up to
9ec30a07483640ecb8417fce3dfa9273f7a036c9:hw/arm/aspeed_ast27x0-fc: Make sub-init functions return bool with errp (2025-09-29 18:00:20 +0200)----------------------------------------------------------------
aspeed queue:
Quoted 12 lines
* Introduce a new ASPEED OTP memory device model integrated with the Secure Boot Controller. It includes a new block device backend ('drive' property), is enabled for AST2600 SoCs and AST1030 SoCs. Functional tests are included
* Changed "ast2700-evb" alias to point to the "ast2700a1-evb" machine
* Introduce support for Aspeed PCIe host controller, including models for the PCIe Root Complex, Root Port, and PHY. Enabled for the AST2600 and AST2700 SoCs, and functional tests are included
* Refactor Boot ROM support to improve code reuse across the different Aspeed machine. This is in preparation of vbootrom support in the ast2700fc machine
* Improved Error Handling in the AST27x0-fc machine init functions
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/10.2 as appropriate.
r~