hw/ufs: Add a generic SysBus frontend
cover hw/ufs: Add a generic SysBus frontend
The UFS controller implementation is currently tied to its PCI QOM device. This series separates the controller core from the PCI frontend and adds a reusable SysBus frontend, following the AHCI model.
The existing "ufs" PCI device and its properties remain unchanged. Platform-specific controllers can derive from TYPE_SYSBUS_UFS and keep only their hardware-specific behavior.
Jeuk Kim (2):
hw/ufs: Separate the controller core from the PCI frontend hw/ufs: Add a generic SysBus frontend
hw/ufs/Kconfig | 9 ++++ hw/ufs/lu.c | 2 +- hw/ufs/meson.build | 4 +- hw/ufs/trace-events | 4 +- hw/ufs/ufs-pci.c | 112 ++++++++++++++++++++++++++++++++++++++++++++ hw/ufs/ufs-sysbus.c | 81 ++++++++++++++++++++++++++++++++ hw/ufs/ufs-sysbus.h | 22 +++++++++ hw/ufs/ufs.c | 108 +++++++++--------------------------------- hw/ufs/ufs.h | 14 ++++-- 9 files changed, 262 insertions(+), 94 deletions(-) create mode 100644 hw/ufs/ufs-pci.c create mode 100644 hw/ufs/ufs-sysbus.c create mode 100644 hw/ufs/ufs-sysbus.h
Signature · 1 line
2.43.0
PATCH 1/2 hw/ufs: Separate the controller core from the PCI frontend
UfsHc is currently also the PCI device instance, tying common code to PCI-specific DMA and IRQ interfaces and preventing reuse by non-PCI frontends.
Make UfsHc transport-independent and embed it in UfsPciState. Move the PCI-specific handling to ufs-pci.c, pass the owning DeviceState and DMA AddressSpace to the core, and record the core explicitly in UfsBus.
Split the common implementation into CONFIG_UFS, selected by CONFIG_UFS_PCI. The user-visible "ufs" device and its properties remain unchanged. No functional change is intended.
--- hw/ufs/Kconfig | 5 ++ hw/ufs/lu.c | 2 +- hw/ufs/meson.build | 3 +- hw/ufs/trace-events | 4 +- hw/ufs/ufs-pci.c | 112 ++++++++++++++++++++++++++++++++++++++++++++ hw/ufs/ufs.c | 108 +++++++++--------------------------------- hw/ufs/ufs.h | 14 ++++-- 7 files changed, 154 insertions(+), 94 deletions(-) create mode 100644 hw/ufs/ufs-pci.c
hw/ufs/Kconfig +5 -0
@@ -1,4 +1,9 @@ +config UFS + bool + select SCSI + config UFS_PCI bool default y if PCI_DEVICES depends on PCI + select UFS
hw/ufs/lu.c +1 -1
@@ -497,7 +497,7 @@ static void ufs_lu_realize(DeviceState *dev, Error **errp) {UfsLu *lu =DO_UPCAST (UfsLu, qdev, dev);BusState *s =qdev_get_parent_bus (dev); -UfsHc *u =UFS (s->parent); +UfsHc *u =UFS_BUS (s)->hc;BlockBackend *blk = lu->conf.blk;if (!ufs_lu_check_constraints (lu, errp)) {
hw/ufs/meson.build +2 -1
@@ -1 +1,2 @@ -system_ss.add(when: 'CONFIG_UFS_PCI', if_true: files('ufs.c', 'lu.c')) +system_ss.add(when: 'CONFIG_UFS', if_true: files('ufs.c', 'lu.c')) +system_ss.add(when: 'CONFIG_UFS_PCI', if_true: files('ufs-pci.c'))
hw/ufs/trace-events +2 -2
@@ -1,6 +1,6 @@ # ufs.c -ufs_irq_raise(void) "INTx" -ufs_irq_lower(void) "INTx" +ufs_irq_raise(void) "IRQ" +ufs_irq_lower(void) "IRQ" ufs_mmio_read(uint64_t addr, uint64_t data, unsigned size) "addr 0x%"PRIx64" data 0x%"PRIx64" size %d" ufs_mmio_write(uint64_t addr, uint64_t data, unsigned size) "addr 0x%"PRIx64" data 0x%"PRIx64" size %d" ufs_process_db(uint32_t slot) "UTRLDBR slot %"PRIu32""
hw/ufs/ufs-pci.c new file +112 -0
112 lines not on this page · raw message
hw/ufs/ufs.c +23 -85
213 lines not on this page · raw message
hw/ufs/ufs.h +9 -5
@@ -11,9 +11,11 @@#ifndef HW_UFS_UFS_H #define HW_UFS_UFS_H -#include "hw/pci/pci_device.h" +#include "hw/core/qdev.h" #include "hw/scsi/scsi.h" #include "block/ufs.h" +#include "scsi/constants.h" +#include "system/dma.h" #define UFS_MAX_LUS 32#define UFS_MAX_MCQ_QNUM 32
@@ -27,6 +29,7 @@ typedef struct UfsBusClass {typedef struct UfsBus {BusState parent_bus; +struct UfsHc *hc; }UfsBus ;#define TYPE_UFS_BUS "ufs-bus"
@@ -141,7 +144,8 @@ typedef struct UfsWb { } UfsWb; typedef struct UfsHc { - PCIDevice parent_obj; + DeviceState *dev; + AddressSpace *dma_as; UfsBus bus; MemoryRegion iomem; UfsReg reg;
@@ -268,9 +272,6 @@ static inline bool ufs_is_write_req(UfsRequest *req)return (cmd ==WRITE_6 ) || (cmd ==WRITE_10 ) || (cmd ==WRITE_16 ); } -#define TYPE_UFS "ufs" -#define UFS (obj) OBJECT_CHECK(UfsHc, (obj), TYPE_UFS) -#define TYPE_UFS_LU "ufs-lu"#define UFSLU (obj) OBJECT_CHECK(UfsLu, (obj), TYPE_UFS_LU)
@@ -302,4 +303,7 @@ void ufs_build_query_response(UfsRequest *req);void ufs_complete_req (UfsRequest *req,UfsReqResult req_result);void ufs_wb_update_avail_buffer (UfsHc *u);void ufs_init_wlu (UfsLu *wlu,uint8_t wlun); +bool ufs_realize (UfsHc *u,DeviceState *dev,AddressSpace *dma_as, +Error **errp); +void ufs_unrealize (UfsHc *u);#endif /* HW_UFS_UFS_H */
Signature · 1 line
2.43.0
PATCH 2/2 hw/ufs: Add a generic SysBus frontend
In reply to Jeuk KimAdd TYPE_SYSBUS_UFS as a reusable frontend for the transport-independent UFS controller core.
Use the system memory address space for DMA, expose the controller MMIO region and IRQ through SysBus, and provide the same properties and migration policy as the PCI frontend. Platform-specific controllers can derive from this type and keep only their hardware-specific behavior.
--- hw/ufs/Kconfig | 4 +++ hw/ufs/meson.build | 1 + hw/ufs/ufs-sysbus.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ hw/ufs/ufs-sysbus.h | 22 ++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 hw/ufs/ufs-sysbus.c create mode 100644 hw/ufs/ufs-sysbus.h
hw/ufs/Kconfig +4 -0
@@ -7,3 +7,7 @@ config UFS_PCI default y if PCI_DEVICES depends on PCI select UFS + +config UFS_SYSBUS + bool + select UFS
hw/ufs/meson.build +1 -0
@@ -1,2 +1,3 @@ system_ss.add(when: 'CONFIG_UFS', if_true: files('ufs.c', 'lu.c')) system_ss.add(when: 'CONFIG_UFS_PCI', if_true: files('ufs-pci.c')) +system_ss.add(when: 'CONFIG_UFS_SYSBUS', if_true: files('ufs-sysbus.c'))
hw/ufs/ufs-sysbus.c new file +81 -0
81 lines not on this page · raw message
hw/ufs/ufs-sysbus.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* QEMU Universal Flash Storage (UFS) sysbus controller +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_UFS_UFS_SYSBUS_H +#define HW_UFS_UFS_SYSBUS_H + +#include "hw/core/sysbus.h" +#include "ufs.h" + +#define TYPE_SYSBUS_UFS "sysbus-ufs" +OBJECT_DECLARE_SIMPLE_TYPE(SysbusUfsState, SYSBUS_UFS) + +struct SysbusUfsState { +SysBusDevice parent_obj; + +UfsHc ufs; +}; + +#endif /* HW_UFS_UFS_SYSBUS_H */
Signature · 1 line
2.43.0