[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 3/4] hw/misc/pvpanic: Add the MMIO interface
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-devel] [PATCH v3 3/4] hw/misc/pvpanic: Add the MMIO interface |
Date: |
Thu, 18 Oct 2018 15:04:33 +0200 |
Signed-off-by: Peng Hao <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
[PMD: Use TYPE_PVPANIC definition, split in 2 patches]
---
Peng: I hope this is now more obvious how you could reuse the pvpanic device.
hw/misc/pvpanic.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/hw/misc/pvpanic.c b/hw/misc/pvpanic.c
index 4f552e1533..b81c5fa633 100644
--- a/hw/misc/pvpanic.c
+++ b/hw/misc/pvpanic.c
@@ -2,10 +2,12 @@
* QEMU simulated pvpanic device.
*
* Copyright Fujitsu, Corp. 2013
+ * Copyright (c) 2018 ZTE Ltd.
*
* Authors:
* Wen Congyang <address@hidden>
* Hu Tao <address@hidden>
+ * Peng Hao <address@hidden>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
@@ -47,7 +49,10 @@ static void handle_event(int event)
typedef struct PVPanicState {
/*< private >*/
- ISADevice isadev;
+ union {
+ ISADevice isadev;
+ SysBusDevice busdev;
+ };
/*< public >*/
MemoryRegion mr;
@@ -123,9 +128,54 @@ static TypeInfo pvpanic_isa_info = {
.class_init = pvpanic_isa_class_init,
};
+static uint64_t pvpanic_mmio_read(void *opaque, hwaddr addr, unsigned size)
+{
+ return -1;
+}
+
+static void pvpanic_mmio_write(void *opaque, hwaddr addr, uint64_t value,
+ unsigned size)
+{
+ handle_event(value);
+}
+
+static const MemoryRegionOps pvpanic_mmio_ops = {
+ .read = pvpanic_mmio_read,
+ .write = pvpanic_mmio_write,
+ .impl = {
+ .max_access_size = 1,
+ },
+};
+
+static void pvpanic_mmio_initfn(Object *obj)
+{
+ PVPanicState *s = PVPANIC(obj);
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+
+ memory_region_init_io(&s->mr, OBJECT(s), &pvpanic_mmio_ops, s,
+ TYPE_PVPANIC, 2);
+ sysbus_init_mmio(sbd, &s->mr);
+}
+
+static void pvpanic_mmio_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+}
+
+static TypeInfo pvpanic_mmio_info = {
+ .name = TYPE_PVPANIC,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(PVPanicState),
+ .instance_init = pvpanic_mmio_initfn,
+ .class_init = pvpanic_mmio_class_init,
+};
+
static void pvpanic_register_types(void)
{
type_register_static(&pvpanic_isa_info);
+ type_register_static(&pvpanic_mmio_info);
}
type_init(pvpanic_register_types)
--
2.17.2