The Linux qcom_geni_serial driver expects a GENI UART to be a child of
a QUP wrapper.

Signed-off-by: Brian Cain <[email protected]>
---
 MAINTAINERS                   |  2 +
 include/hw/misc/qup-wrapper.h | 27 +++++++++++
 hw/misc/qup-wrapper.c         | 90 +++++++++++++++++++++++++++++++++++
 hw/misc/Kconfig               |  3 ++
 hw/misc/meson.build           |  3 ++
 5 files changed, 125 insertions(+)
 create mode 100644 include/hw/misc/qup-wrapper.h
 create mode 100644 hw/misc/qup-wrapper.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 4ca1751e30f..064d9531d3e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1383,7 +1383,9 @@ M: Brian Cain <[email protected]>
 R: Pierrick Bouvier <[email protected]>
 S: Supported
 F: hw/hexagon/
+F: hw/misc/qup-wrapper.c
 F: include/hw/hexagon/
+F: include/hw/misc/qup-wrapper.h
 F: configs/devices/hexagon-softmmu/default.mak
 F: docs/system/hexagon/
 F: tests/functional/hexagon/
diff --git a/include/hw/misc/qup-wrapper.h b/include/hw/misc/qup-wrapper.h
new file mode 100644
index 00000000000..6180092b799
--- /dev/null
+++ b/include/hw/misc/qup-wrapper.h
@@ -0,0 +1,27 @@
+/*
+ * QUP wrapper (GENI SE QUP) device
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_MISC_QUP_WRAPPER_H
+#define HW_MISC_QUP_WRAPPER_H
+
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+
+#define TYPE_QUP_WRAPPER "qup-wrapper"
+OBJECT_DECLARE_SIMPLE_TYPE(QupWrapperState, QUP_WRAPPER)
+
+#define QUP_WRAPPER_MMIO_SIZE 0x6000
+
+struct QupWrapperState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion iomem;
+
+    uint32_t hw_version;
+};
+
+#endif /* HW_MISC_QUP_WRAPPER_H */
diff --git a/hw/misc/qup-wrapper.c b/hw/misc/qup-wrapper.c
new file mode 100644
index 00000000000..40c79dc66e6
--- /dev/null
+++ b/hw/misc/qup-wrapper.c
@@ -0,0 +1,90 @@
+/*
+ * QUP wrapper device
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/core/sysbus.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/misc/qup-wrapper.h"
+#include "qemu/log.h"
+
+#define REG_QUPV3_HW_VER 0x4
+
+static uint64_t qup_wrapper_read(void *opaque, hwaddr offset, unsigned size)
+{
+    QupWrapperState *s = QUP_WRAPPER(opaque);
+    uint64_t value = 0;
+
+    switch (offset) {
+    case REG_QUPV3_HW_VER:
+        value = s->hw_version;
+        break;
+    default:
+        qemu_log_mask(LOG_UNIMP, "qup-wrapper: read from unknown offset 0x%"
+                      HWADDR_PRIx "\n", offset);
+        break;
+    }
+
+    return value;
+}
+
+static void qup_wrapper_write(void *opaque, hwaddr offset, uint64_t value,
+                              unsigned size)
+{
+    qemu_log_mask(LOG_UNIMP, "qup-wrapper: write to offset 0x%"
+                  HWADDR_PRIx " value 0x%" PRIx64 "\n", offset, value);
+}
+
+static const MemoryRegionOps qup_wrapper_ops = {
+    .read = qup_wrapper_read,
+    .write = qup_wrapper_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 4,
+    },
+    .impl = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    },
+};
+
+static void qup_wrapper_init(Object *obj)
+{
+    QupWrapperState *s = QUP_WRAPPER(obj);
+
+    memory_region_init_io(&s->iomem, obj, &qup_wrapper_ops, s,
+                          TYPE_QUP_WRAPPER, QUP_WRAPPER_MMIO_SIZE);
+    sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
+}
+
+static const Property qup_wrapper_properties[] = {
+    DEFINE_PROP_UINT32("hw-version", QupWrapperState, hw_version,
+                       0x30100000),
+};
+
+static void qup_wrapper_class_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    device_class_set_props(dc, qup_wrapper_properties);
+    dc->desc = "Qualcomm QUP wrapper";
+}
+
+static const TypeInfo qup_wrapper_info = {
+    .name          = TYPE_QUP_WRAPPER,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(QupWrapperState),
+    .instance_init = qup_wrapper_init,
+    .class_init    = qup_wrapper_class_init,
+};
+
+static void qup_wrapper_register_types(void)
+{
+    type_register_static(&qup_wrapper_info);
+}
+
+type_init(qup_wrapper_register_types)
diff --git a/hw/misc/Kconfig b/hw/misc/Kconfig
index 7abd22869a4..aa76a2398a9 100644
--- a/hw/misc/Kconfig
+++ b/hw/misc/Kconfig
@@ -266,4 +266,7 @@ config K230_DECOMP_GZIP
 config SOPHGO_CV1800B_CLK
     bool
 
+config QUP_WRAPPER
+    bool
+
 source macio/Kconfig
diff --git a/hw/misc/meson.build b/hw/misc/meson.build
index 90f3f89de70..9cf897abc76 100644
--- a/hw/misc/meson.build
+++ b/hw/misc/meson.build
@@ -181,3 +181,6 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: 
files('sbsa_ec.c'))
 system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c'))
 
 system_ss.add(when: 'CONFIG_AXIADO_CLK', if_true: files('axiado_clk.c'))
+
+# Qualcomm QUP devices
+system_ss.add(when: 'CONFIG_QUP_WRAPPER', if_true: files('qup-wrapper.c'))
-- 
2.34.1

Reply via email to