Skip to contentSkip to conversation

ufs queue

GIT PULL Applied Jeuk Kim 2 participants 4 messages Aug 24 – Aug 25 Arm/Amlogic Meson SoC support

lore
Share & tools
lore

Jeuk Kim

author
#0 lore raw

From: Jeuk Kim <[email protected]>

The following changes since commit eea8fe61b8be8f3016e522e6af24924a0266ca95:

Merge tag 'igvm-20260821-pull-request' of https://gitlab.com/kraxel/qemu into staging (2026-08-21 10:39:31 -0700)

are available in the Git repository at:

https://gitlab.com/jeuk20.kim/qemu.git tags/pull-ufs-20260824

for you to fetch changes up to 6ed05d5e65208a5ee23a02667d5df0dc6491c156:

hw/ufs: Add a generic SysBus frontend (2026-08-24 14:17:29 +0900)

----------------------------------------------------------------
ufs queue

- Separate the UFS controller core from the PCI frontend

----------------------------------------------------------------
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 |  80 +++++++++++++++++++++++++++++++++++++
 hw/ufs/ufs-sysbus.h |  22 +++++++++++
 hw/ufs/ufs.c        | 109 +++++++++++---------------------------------------
 hw/ufs/ufs.h        |  14 ++++---
 9 files changed, 260 insertions(+), 96 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
author
#1 lore raw

[PULL 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        | 109 +++++++++---------------------------------
 hw/ufs/ufs.h        |  14 ++++--
 7 files changed, 153 insertions(+), 96 deletions(-)
 create mode 100644 hw/ufs/ufs-pci.c
hw/ufs/Kconfig +5 -0
index b7b3392e85..47e28a30ea 100644
@@ -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
index 13f4a90145..eeca865eb5 100644
@@ -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
index 6e68328b93..880fc52c05 100644
@@ -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
index 662d9afee3..0cd3ba9b02 100644
@@ -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 +22 -87

213 lines not on this page · raw message

hw/ufs/ufs.h +9 -5
index feb47f460d..aa8361d93d 100644
@@ -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
author
#2 lore raw

[PULL 2/2] hw/ufs: Add a generic SysBus frontend

In reply to Jeuk Kim

Add 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 | 80 +++++++++++++++++++++++++++++++++++++++++++++
 hw/ufs/ufs-sysbus.h | 22 +++++++++++++
 4 files changed, 107 insertions(+)
 create mode 100644 hw/ufs/ufs-sysbus.c
 create mode 100644 hw/ufs/ufs-sysbus.h
hw/ufs/Kconfig +4 -0
index 47e28a30ea..0e40f08a41 100644
@@ -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
index 880fc52c05..a84627b96a 100644
@@ -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 +80 -0

80 lines not on this page · raw message

hw/ufs/ufs-sysbus.h new file +22 -0
new file mode 100644
index 0000000000..71b6787d3a
@@ -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
#3 lore raw
In reply to Jeuk Kim
Quoted 10 lines · Jeuk Kim

From: Jeuk Kim<[email protected]>

The following changes since commit eea8fe61b8be8f3016e522e6af24924a0266ca95:

   Merge tag 'igvm-20260821-pull-request' ofhttps://gitlab.com/kraxel/qemu into staging (2026-08-21 10:39:31 -0700)

are available in the Git repository at:

   https://gitlab.com/jeuk20.kim/qemu.git tags/pull-ufs-20260824
Quoted 8 lines

for you to fetch changes up to 6ed05d5e65208a5ee23a02667d5df0dc6491c156:

   hw/ufs: Add a generic SysBus frontend (2026-08-24 14:17:29 +0900)

----------------------------------------------------------------
ufs queue

- Separate the UFS controller core from the PCI frontend

Applied, thanks.

r~