[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 06/10] sysbus: add bus_interface_clock feature to
From: |
damien . hedde |
Subject: |
[Qemu-devel] [PATCH v4 06/10] sysbus: add bus_interface_clock feature to sysbus devices |
Date: |
Mon, 17 Sep 2018 10:40:12 +0200 |
From: Damien Hedde <address@hidden>
Add an optional bus interface clock to sysbus devices.
This clock can be added by the subclasses if required using the
sysbus_init_bus_interface_clock function given the target name of the
clock.
The default behavior of the clock is to enable or disable the mmios in
function of the clock status (mmios are enabled iff the clock is running
and the reset not asserted).
This behavior may be changed by overriding the clock callback using
sysbus_get_bus_interface_clock and clock_set_callback functions.
Signed-off-by: Damien Hedde <address@hidden>
---
include/hw/sysbus.h | 22 ++++++++++++++++++++++
hw/core/sysbus.c | 25 +++++++++++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/include/hw/sysbus.h b/include/hw/sysbus.h
index 0b59a3b8d6..abbeece601 100644
--- a/include/hw/sysbus.h
+++ b/include/hw/sysbus.h
@@ -73,6 +73,7 @@ struct SysBusDevice {
} mmio[QDEV_MAX_MMIO];
int num_pio;
uint32_t pio[QDEV_MAX_PIO];
+ ClockIn *bus_itf_clk;
};
typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
@@ -135,4 +136,25 @@ static inline DeviceState *sysbus_try_create_simple(const
char *name,
return sysbus_try_create_varargs(name, addr, irq, NULL);
}
+/**
+ * sysbus_init_bus_interface_clock:
+ * @dev: the sysbus device
+ * @name: the name of the clock
+ *
+ * Add the bus interface clock to the device. Mmios will be enabled/disabled
+ * according to the clock status. Must not be called more than once on the same
+ * device.
+ *
+ * Note: if this clock remains unconnected, the sysbus device will work as if
+ * the clock was absent (no side-effect).
+ */
+void sysbus_init_bus_interface_clock(SysBusDevice *dev, const char *name);
+
+/**
+ * sysbus_init_get_interface_clock:
+ * @dev: the sysbus device
+ * @retuns: the clock previously added by sysbus_init_bus_interface_clock.
+ */
+ClockIn *sysbus_get_bus_interface_clock(SysBusDevice *dev);
+
#endif /* HW_SYSBUS_H */
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 7ac36ad3e7..8d225263fa 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -324,6 +324,31 @@ MemoryRegion *sysbus_address_space(SysBusDevice *dev)
return get_system_memory();
}
+static void sysbus_device_clock_callback(void *opaque, ClockState *clk)
+{
+ SysBusDevice *dev = opaque;
+ bool enable = clock_state_is_domain_running(clk);
+ int i;
+
+ /* set/clear mmio visible flag on clock change */
+ for (i = 0; i < dev->num_mmio && i < QDEV_MAX_MMIO; i++) {
+ MemoryRegion *mr = sysbus_mmio_get_region(dev, i);
+ memory_region_set_enabled(mr, enable);
+ }
+}
+
+void sysbus_init_bus_interface_clock(SysBusDevice *dev, const char *name)
+{
+ assert(dev->bus_itf_clk == NULL);
+ dev->bus_itf_clk = qdev_init_clock_in(DEVICE(dev), name,
+ sysbus_device_clock_callback, dev);
+}
+
+ClockIn *sysbus_get_bus_interface_clock(SysBusDevice *dev)
+{
+ return dev->bus_itf_clk;
+}
+
static void sysbus_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
--
2.18.0
- [Qemu-devel] [PATCH v4 00/10] Clock framework API., damien . hedde, 2018/09/17
- [Qemu-devel] [PATCH v4 03/10] qdev-monitor: print the device's clock with info qtree, damien . hedde, 2018/09/17
- [Qemu-devel] [PATCH v4 08/10] hw/misc/zynq_slcr: add clock generation for uarts, damien . hedde, 2018/09/17
- [Qemu-devel] [PATCH v4 06/10] sysbus: add bus_interface_clock feature to sysbus devices,
damien . hedde <=
- [Qemu-devel] [PATCH v4 09/10] hw/char/cadence_uart: add clock support, damien . hedde, 2018/09/17
- [Qemu-devel] [PATCH v4 07/10] hw/misc/zynq_slcr: use standard register definition, damien . hedde, 2018/09/17
- [Qemu-devel] [PATCH v4 01/10] hw/core/clock-port: introduce clock port objects, damien . hedde, 2018/09/17
[Qemu-devel] [PATCH v4 02/10] qdev: add clock input&output support to devices., damien . hedde, 2018/09/17
Re: [Qemu-devel] [PATCH v4 00/10] Clock framework API., Peter Maydell, 2018/09/19