[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 30/33] convert cadence_uart to 3-phases reset
From: |
Damien Hedde |
Subject: |
[Qemu-devel] [PATCH v3 30/33] convert cadence_uart to 3-phases reset |
Date: |
Mon, 29 Jul 2019 16:56:51 +0200 |
Split the existing reset procedure into 3 phases.
Test the resetting flag to discard register accesses
and character reception.
Also adds a active high reset io.
Signed-off-by: Damien Hedde <address@hidden>
---
hw/char/cadence_uart.c | 77 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 73 insertions(+), 4 deletions(-)
diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index fa25fe24da..d7bacc44fe 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -39,6 +39,18 @@
#define DB_PRINT(...)
#endif
+#define CADENCE_UART_CLASS(class) \
+ OBJECT_CLASS_CHECK(CadenceUartClass, (class), TYPE_CADENCE_UART)
+#define CADENCE_UART_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(CadenceUartClass, (obj), TYPE_CADENCE_UART)
+
+typedef struct CadenceUartClass {
+ /*< private >*/
+ SysBusDeviceClass parent_class;
+
+ struct ResettablePhases parent_reset_phases;
+} CadenceUartClass;
+
#define UART_SR_INTR_RTRIG 0x00000001
#define UART_SR_INTR_REMPTY 0x00000002
#define UART_SR_INTR_RFUL 0x00000004
@@ -223,6 +235,10 @@ static int uart_can_receive(void *opaque)
int ret = MAX(CADENCE_UART_RX_FIFO_SIZE, CADENCE_UART_TX_FIFO_SIZE);
uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;
+ if (device_is_resetting((DeviceState *) opaque)) {
+ return 0;
+ }
+
if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) {
ret = MIN(ret, CADENCE_UART_RX_FIFO_SIZE - s->rx_count);
}
@@ -338,6 +354,10 @@ static void uart_receive(void *opaque, const uint8_t *buf,
int size)
CadenceUARTState *s = opaque;
uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE;
+ if (device_is_resetting((DeviceState *) opaque)) {
+ return;
+ }
+
if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) {
uart_write_rx_fifo(opaque, buf, size);
}
@@ -351,6 +371,10 @@ static void uart_event(void *opaque, int event)
CadenceUARTState *s = opaque;
uint8_t buf = '\0';
+ if (device_is_resetting((DeviceState *) opaque)) {
+ return;
+ }
+
if (event == CHR_EVENT_BREAK) {
uart_write_rx_fifo(opaque, &buf, 1);
}
@@ -383,6 +407,10 @@ static void uart_write(void *opaque, hwaddr offset,
{
CadenceUARTState *s = opaque;
+ if (device_is_resetting((DeviceState *)opaque)) {
+ return;
+ }
+
DB_PRINT(" offset:%x data:%08x\n", (unsigned)offset, (unsigned)value);
offset >>= 2;
if (offset >= CADENCE_UART_R_MAX) {
@@ -441,6 +469,10 @@ static uint64_t uart_read(void *opaque, hwaddr offset,
CadenceUARTState *s = opaque;
uint32_t c = 0;
+ if (device_is_resetting((DeviceState *)opaque)) {
+ return 0;
+ }
+
offset >>= 2;
if (offset >= CADENCE_UART_R_MAX) {
c = 0;
@@ -460,9 +492,14 @@ static const MemoryRegionOps uart_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
-static void cadence_uart_reset(DeviceState *dev)
+static void cadence_uart_reset_init(Object *obj)
{
- CadenceUARTState *s = CADENCE_UART(dev);
+ CadenceUARTState *s = CADENCE_UART(obj);
+ CadenceUartClass *cc = CADENCE_UART_GET_CLASS(obj);
+
+ if (cc->parent_reset_phases.init) {
+ cc->parent_reset_phases.init(obj);
+ }
s->r[R_CR] = 0x00000128;
s->r[R_IMR] = 0;
@@ -471,6 +508,28 @@ static void cadence_uart_reset(DeviceState *dev)
s->r[R_BRGR] = 0x0000028B;
s->r[R_BDIV] = 0x0000000F;
s->r[R_TTRIG] = 0x00000020;
+}
+
+static void cadence_uart_reset_hold(Object *obj)
+{
+ CadenceUARTState *s = CADENCE_UART(obj);
+ CadenceUartClass *cc = CADENCE_UART_GET_CLASS(obj);
+
+ if (cc->parent_reset_phases.hold) {
+ cc->parent_reset_phases.hold(obj);
+ }
+
+ qemu_set_irq(s->irq, 0);
+}
+
+static void cadence_uart_reset_exit(Object *obj)
+{
+ CadenceUARTState *s = CADENCE_UART(obj);
+ CadenceUartClass *cc = CADENCE_UART_GET_CLASS(obj);
+
+ if (cc->parent_reset_phases.exit) {
+ cc->parent_reset_phases.exit(obj);
+ }
uart_rx_reset(s);
uart_tx_reset(s);
@@ -499,6 +558,8 @@ static void cadence_uart_init(Object *obj)
sysbus_init_irq(sbd, &s->irq);
s->char_tx_time = (NANOSECONDS_PER_SECOND / 9600) * 10;
+
+ qdev_init_warm_reset_gpio(DEVICE(obj), "rst", DEVICE_RESET_ACTIVE_HIGH);
}
static int cadence_uart_post_load(void *opaque, int version_id)
@@ -544,12 +605,19 @@ static Property cadence_uart_properties[] = {
static void cadence_uart_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ ResettableClass *rc = RESETTABLE_CLASS(klass);
+ CadenceUartClass *cc = CADENCE_UART_CLASS(klass);
dc->realize = cadence_uart_realize;
dc->vmsd = &vmstate_cadence_uart;
- dc->reset = cadence_uart_reset;
dc->props = cadence_uart_properties;
- }
+
+ resettable_class_set_parent_reset_phases(rc,
+ cadence_uart_reset_init,
+ cadence_uart_reset_hold,
+ cadence_uart_reset_exit,
+ &cc->parent_reset_phases);
+}
static const TypeInfo cadence_uart_info = {
.name = TYPE_CADENCE_UART,
@@ -557,6 +625,7 @@ static const TypeInfo cadence_uart_info = {
.instance_size = sizeof(CadenceUARTState),
.instance_init = cadence_uart_init,
.class_init = cadence_uart_class_init,
+ .class_size = sizeof(CadenceUartClass),
};
static void cadence_uart_register_types(void)
--
2.22.0
- [Qemu-devel] [PATCH v3 19/33] hw/sd/pl181.c & omap_mmc.c: remove device_legacy_reset call, (continued)
- [Qemu-devel] [PATCH v3 19/33] hw/sd/pl181.c & omap_mmc.c: remove device_legacy_reset call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 17/33] hw/usb/dev-uas.c: remove qdev_reset_all call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 14/33] hw/s390x/s390-virtio-ccw.c: remove qdev_reset_all call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 13/33] hw/scsi/: remove qdev/qbus_reset_all call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 23/33] hw/scsi/vmw_pvscsi.c: remove device_legacy_reset call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 22/33] hw/ppc/pnv_psi.c: remove device_legacy_reset call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 26/33] hw/s390x/s390-pci-inst.c: remove device_legacy_reset call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 25/33] hw/i386/pc.c: remove device_legacy_reset call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 24/33] hw/ppc/spapr: remove device_legacy_reset call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 31/33] Convert zynq's slcr to 3-phases reset, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 30/33] convert cadence_uart to 3-phases reset,
Damien Hedde <=
- [Qemu-devel] [PATCH v3 27/33] hw/ide/microdrive.c: remove device_legacy_reset calls, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 20/33] hw/hyperv/hyperv.c: remove device_legacy_reset call, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 28/33] qdev: Remove unused deprecated reset functions, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 33/33] Connect the uart reset gpios in the zynq platform, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 32/33] Add uart reset support in zynq_slcr, Damien Hedde, 2019/07/29
- [Qemu-devel] [PATCH v3 29/33] hw/misc/zynq_slcr: use standard register definition, Damien Hedde, 2019/07/29
- Re: [Qemu-devel] [PATCH v3 00/33] Multi-phase reset mechanism, Cornelia Huck, 2019/07/30