2012-02-16 13:56:05 +04:00
|
|
|
/*
|
|
|
|
* Exynos4210 UART Emulation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Samsung Electronics Co Ltd.
|
|
|
|
* Maksim Kozlov, <m.kozlov@samsung.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:05 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:31:58 +03:00
|
|
|
#include "qapi/error.h"
|
2015-12-17 19:35:09 +03:00
|
|
|
#include "qemu/error-report.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2020-01-23 18:22:41 +03:00
|
|
|
#include "qemu/timer.h"
|
2017-01-26 17:26:44 +03:00
|
|
|
#include "chardev/char-fe.h"
|
2017-01-26 16:33:39 +03:00
|
|
|
#include "chardev/char-serial.h"
|
2012-02-16 13:56:05 +04:00
|
|
|
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/arm/exynos4210.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-12 01:05:12 +03:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2012-02-16 13:56:05 +04:00
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
#include "trace.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2012-02-16 13:56:05 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Offsets for UART registers relative to SFR base address
|
|
|
|
* for UARTn
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define ULCON 0x0000 /* Line Control */
|
|
|
|
#define UCON 0x0004 /* Control */
|
|
|
|
#define UFCON 0x0008 /* FIFO Control */
|
|
|
|
#define UMCON 0x000C /* Modem Control */
|
|
|
|
#define UTRSTAT 0x0010 /* Tx/Rx Status */
|
|
|
|
#define UERSTAT 0x0014 /* UART Error Status */
|
|
|
|
#define UFSTAT 0x0018 /* FIFO Status */
|
|
|
|
#define UMSTAT 0x001C /* Modem Status */
|
|
|
|
#define UTXH 0x0020 /* Transmit Buffer */
|
|
|
|
#define URXH 0x0024 /* Receive Buffer */
|
|
|
|
#define UBRDIV 0x0028 /* Baud Rate Divisor */
|
|
|
|
#define UFRACVAL 0x002C /* Divisor Fractional Value */
|
|
|
|
#define UINTP 0x0030 /* Interrupt Pending */
|
|
|
|
#define UINTSP 0x0034 /* Interrupt Source Pending */
|
|
|
|
#define UINTM 0x0038 /* Interrupt Mask */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for indexing register in the uint32_t array
|
|
|
|
*
|
|
|
|
* 'reg' - register offset (see offsets definitions above)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#define I_(reg) (reg / sizeof(uint32_t))
|
|
|
|
|
|
|
|
typedef struct Exynos4210UartReg {
|
|
|
|
const char *name; /* the only reason is the debug output */
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr offset;
|
2012-02-16 13:56:05 +04:00
|
|
|
uint32_t reset_value;
|
|
|
|
} Exynos4210UartReg;
|
|
|
|
|
2017-04-20 19:32:28 +03:00
|
|
|
static const Exynos4210UartReg exynos4210_uart_regs[] = {
|
2012-02-16 13:56:05 +04:00
|
|
|
{"ULCON", ULCON, 0x00000000},
|
|
|
|
{"UCON", UCON, 0x00003000},
|
|
|
|
{"UFCON", UFCON, 0x00000000},
|
|
|
|
{"UMCON", UMCON, 0x00000000},
|
|
|
|
{"UTRSTAT", UTRSTAT, 0x00000006}, /* RO */
|
|
|
|
{"UERSTAT", UERSTAT, 0x00000000}, /* RO */
|
|
|
|
{"UFSTAT", UFSTAT, 0x00000000}, /* RO */
|
|
|
|
{"UMSTAT", UMSTAT, 0x00000000}, /* RO */
|
|
|
|
{"UTXH", UTXH, 0x5c5c5c5c}, /* WO, undefined reset value*/
|
|
|
|
{"URXH", URXH, 0x00000000}, /* RO */
|
|
|
|
{"UBRDIV", UBRDIV, 0x00000000},
|
|
|
|
{"UFRACVAL", UFRACVAL, 0x00000000},
|
|
|
|
{"UINTP", UINTP, 0x00000000},
|
|
|
|
{"UINTSP", UINTSP, 0x00000000},
|
|
|
|
{"UINTM", UINTM, 0x00000000},
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EXYNOS4210_UART_REGS_MEM_SIZE 0x3C
|
|
|
|
|
|
|
|
/* UART FIFO Control */
|
|
|
|
#define UFCON_FIFO_ENABLE 0x1
|
|
|
|
#define UFCON_Rx_FIFO_RESET 0x2
|
|
|
|
#define UFCON_Tx_FIFO_RESET 0x4
|
|
|
|
#define UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT 8
|
|
|
|
#define UFCON_Tx_FIFO_TRIGGER_LEVEL (7 << UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT)
|
|
|
|
#define UFCON_Rx_FIFO_TRIGGER_LEVEL_SHIFT 4
|
|
|
|
#define UFCON_Rx_FIFO_TRIGGER_LEVEL (7 << UFCON_Rx_FIFO_TRIGGER_LEVEL_SHIFT)
|
|
|
|
|
|
|
|
/* Uart FIFO Status */
|
|
|
|
#define UFSTAT_Rx_FIFO_COUNT 0xff
|
|
|
|
#define UFSTAT_Rx_FIFO_FULL 0x100
|
|
|
|
#define UFSTAT_Rx_FIFO_ERROR 0x200
|
|
|
|
#define UFSTAT_Tx_FIFO_COUNT_SHIFT 16
|
|
|
|
#define UFSTAT_Tx_FIFO_COUNT (0xff << UFSTAT_Tx_FIFO_COUNT_SHIFT)
|
|
|
|
#define UFSTAT_Tx_FIFO_FULL_SHIFT 24
|
|
|
|
#define UFSTAT_Tx_FIFO_FULL (1 << UFSTAT_Tx_FIFO_FULL_SHIFT)
|
|
|
|
|
|
|
|
/* UART Interrupt Source Pending */
|
|
|
|
#define UINTSP_RXD 0x1 /* Receive interrupt */
|
|
|
|
#define UINTSP_ERROR 0x2 /* Error interrupt */
|
|
|
|
#define UINTSP_TXD 0x4 /* Transmit interrupt */
|
|
|
|
#define UINTSP_MODEM 0x8 /* Modem interrupt */
|
|
|
|
|
|
|
|
/* UART Line Control */
|
|
|
|
#define ULCON_IR_MODE_SHIFT 6
|
|
|
|
#define ULCON_PARITY_SHIFT 3
|
|
|
|
#define ULCON_STOP_BIT_SHIFT 1
|
|
|
|
|
|
|
|
/* UART Tx/Rx Status */
|
2020-01-23 18:22:41 +03:00
|
|
|
#define UTRSTAT_Rx_TIMEOUT 0x8
|
2012-02-16 13:56:05 +04:00
|
|
|
#define UTRSTAT_TRANSMITTER_EMPTY 0x4
|
|
|
|
#define UTRSTAT_Tx_BUFFER_EMPTY 0x2
|
|
|
|
#define UTRSTAT_Rx_BUFFER_DATA_READY 0x1
|
|
|
|
|
|
|
|
/* UART Error Status */
|
|
|
|
#define UERSTAT_OVERRUN 0x1
|
|
|
|
#define UERSTAT_PARITY 0x2
|
|
|
|
#define UERSTAT_FRAME 0x4
|
|
|
|
#define UERSTAT_BREAK 0x8
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t *data;
|
|
|
|
uint32_t sp, rp; /* store and retrieve pointers */
|
|
|
|
uint32_t size;
|
|
|
|
} Exynos4210UartFIFO;
|
|
|
|
|
2013-07-25 00:21:05 +04:00
|
|
|
#define TYPE_EXYNOS4210_UART "exynos4210.uart"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(Exynos4210UartState, EXYNOS4210_UART)
|
2013-07-25 00:21:05 +04:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct Exynos4210UartState {
|
2013-07-25 00:21:05 +04:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2012-02-16 13:56:05 +04:00
|
|
|
MemoryRegion iomem;
|
|
|
|
|
|
|
|
uint32_t reg[EXYNOS4210_UART_REGS_MEM_SIZE / sizeof(uint32_t)];
|
|
|
|
Exynos4210UartFIFO rx;
|
|
|
|
Exynos4210UartFIFO tx;
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
QEMUTimer *fifo_timeout_timer;
|
|
|
|
uint64_t wordtime; /* word time in ns */
|
|
|
|
|
2016-10-22 12:52:51 +03:00
|
|
|
CharBackend chr;
|
2012-02-16 13:56:05 +04:00
|
|
|
qemu_irq irq;
|
2020-01-23 18:22:42 +03:00
|
|
|
qemu_irq dmairq;
|
2012-02-16 13:56:05 +04:00
|
|
|
|
|
|
|
uint32_t channel;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2012-02-16 13:56:05 +04:00
|
|
|
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
/* Used only for tracing */
|
2012-10-23 14:30:10 +04:00
|
|
|
static const char *exynos4210_uart_regname(hwaddr offset)
|
2012-02-16 13:56:05 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
2013-12-07 17:48:06 +04:00
|
|
|
for (i = 0; i < ARRAY_SIZE(exynos4210_uart_regs); i++) {
|
2012-02-16 13:56:05 +04:00
|
|
|
if (offset == exynos4210_uart_regs[i].offset) {
|
|
|
|
return exynos4210_uart_regs[i].name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void fifo_store(Exynos4210UartFIFO *q, uint8_t ch)
|
|
|
|
{
|
|
|
|
q->data[q->sp] = ch;
|
|
|
|
q->sp = (q->sp + 1) % q->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t fifo_retrieve(Exynos4210UartFIFO *q)
|
|
|
|
{
|
|
|
|
uint8_t ret = q->data[q->rp];
|
|
|
|
q->rp = (q->rp + 1) % q->size;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-20 19:32:28 +03:00
|
|
|
static int fifo_elements_number(const Exynos4210UartFIFO *q)
|
2012-02-16 13:56:05 +04:00
|
|
|
{
|
|
|
|
if (q->sp < q->rp) {
|
|
|
|
return q->size - q->rp + q->sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return q->sp - q->rp;
|
|
|
|
}
|
|
|
|
|
2017-04-20 19:32:28 +03:00
|
|
|
static int fifo_empty_elements_number(const Exynos4210UartFIFO *q)
|
2012-02-16 13:56:05 +04:00
|
|
|
{
|
|
|
|
return q->size - fifo_elements_number(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fifo_reset(Exynos4210UartFIFO *q)
|
|
|
|
{
|
2015-08-26 15:02:53 +03:00
|
|
|
g_free(q->data);
|
|
|
|
q->data = NULL;
|
2012-02-16 13:56:05 +04:00
|
|
|
|
2022-09-23 15:00:24 +03:00
|
|
|
q->data = g_malloc0(q->size);
|
2012-02-16 13:56:05 +04:00
|
|
|
|
|
|
|
q->sp = 0;
|
|
|
|
q->rp = 0;
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
static uint32_t exynos4210_uart_FIFO_trigger_level(uint32_t channel,
|
|
|
|
uint32_t reg)
|
2012-02-16 13:56:05 +04:00
|
|
|
{
|
2020-01-23 18:22:41 +03:00
|
|
|
uint32_t level;
|
2012-02-16 13:56:05 +04:00
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
switch (channel) {
|
2012-02-16 13:56:05 +04:00
|
|
|
case 0:
|
|
|
|
level = reg * 32;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 4:
|
|
|
|
level = reg * 8;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
level = reg * 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
level = 0;
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_channel_error(channel);
|
|
|
|
break;
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
static uint32_t
|
|
|
|
exynos4210_uart_Tx_FIFO_trigger_level(const Exynos4210UartState *s)
|
|
|
|
{
|
|
|
|
uint32_t reg;
|
|
|
|
|
|
|
|
reg = (s->reg[I_(UFCON)] & UFCON_Tx_FIFO_TRIGGER_LEVEL) >>
|
|
|
|
UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT;
|
|
|
|
|
|
|
|
return exynos4210_uart_FIFO_trigger_level(s->channel, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
exynos4210_uart_Rx_FIFO_trigger_level(const Exynos4210UartState *s)
|
|
|
|
{
|
|
|
|
uint32_t reg;
|
|
|
|
|
|
|
|
reg = ((s->reg[I_(UFCON)] & UFCON_Rx_FIFO_TRIGGER_LEVEL) >>
|
|
|
|
UFCON_Rx_FIFO_TRIGGER_LEVEL_SHIFT) + 1;
|
|
|
|
|
|
|
|
return exynos4210_uart_FIFO_trigger_level(s->channel, reg);
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:22:42 +03:00
|
|
|
/*
|
|
|
|
* Update Rx DMA busy signal if Rx DMA is enabled. For simplicity,
|
|
|
|
* mark DMA as busy if DMA is enabled and the receive buffer is empty.
|
|
|
|
*/
|
|
|
|
static void exynos4210_uart_update_dmabusy(Exynos4210UartState *s)
|
|
|
|
{
|
|
|
|
bool rx_dma_enabled = (s->reg[I_(UCON)] & 0x03) == 0x02;
|
|
|
|
uint32_t count = fifo_elements_number(&s->rx);
|
|
|
|
|
|
|
|
if (rx_dma_enabled && !count) {
|
|
|
|
qemu_irq_raise(s->dmairq);
|
|
|
|
trace_exynos_uart_dmabusy(s->channel);
|
|
|
|
} else {
|
|
|
|
qemu_irq_lower(s->dmairq);
|
|
|
|
trace_exynos_uart_dmaready(s->channel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 13:56:05 +04:00
|
|
|
static void exynos4210_uart_update_irq(Exynos4210UartState *s)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The Tx interrupt is always requested if the number of data in the
|
|
|
|
* transmit FIFO is smaller than the trigger level.
|
|
|
|
*/
|
2012-04-13 15:39:06 +04:00
|
|
|
if (s->reg[I_(UFCON)] & UFCON_FIFO_ENABLE) {
|
|
|
|
uint32_t count = (s->reg[I_(UFSTAT)] & UFSTAT_Tx_FIFO_COUNT) >>
|
2012-02-16 13:56:05 +04:00
|
|
|
UFSTAT_Tx_FIFO_COUNT_SHIFT;
|
|
|
|
|
|
|
|
if (count <= exynos4210_uart_Tx_FIFO_trigger_level(s)) {
|
|
|
|
s->reg[I_(UINTSP)] |= UINTSP_TXD;
|
|
|
|
}
|
2020-01-23 18:22:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Rx interrupt if trigger level is reached or if rx timeout
|
|
|
|
* interrupt is disabled and there is data in the receive buffer
|
|
|
|
*/
|
|
|
|
count = fifo_elements_number(&s->rx);
|
|
|
|
if ((count && !(s->reg[I_(UCON)] & 0x80)) ||
|
|
|
|
count >= exynos4210_uart_Rx_FIFO_trigger_level(s)) {
|
2020-01-23 18:22:42 +03:00
|
|
|
exynos4210_uart_update_dmabusy(s);
|
2020-01-23 18:22:41 +03:00
|
|
|
s->reg[I_(UINTSP)] |= UINTSP_RXD;
|
|
|
|
timer_del(s->fifo_timeout_timer);
|
|
|
|
}
|
|
|
|
} else if (s->reg[I_(UTRSTAT)] & UTRSTAT_Rx_BUFFER_DATA_READY) {
|
2020-01-23 18:22:42 +03:00
|
|
|
exynos4210_uart_update_dmabusy(s);
|
2020-01-23 18:22:41 +03:00
|
|
|
s->reg[I_(UINTSP)] |= UINTSP_RXD;
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
s->reg[I_(UINTP)] = s->reg[I_(UINTSP)] & ~s->reg[I_(UINTM)];
|
|
|
|
|
|
|
|
if (s->reg[I_(UINTP)]) {
|
|
|
|
qemu_irq_raise(s->irq);
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_irq_raised(s->channel, s->reg[I_(UINTP)]);
|
2012-02-16 13:56:05 +04:00
|
|
|
} else {
|
|
|
|
qemu_irq_lower(s->irq);
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_irq_lowered(s->channel);
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
static void exynos4210_uart_timeout_int(void *opaque)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = opaque;
|
|
|
|
|
|
|
|
trace_exynos_uart_rx_timeout(s->channel, s->reg[I_(UTRSTAT)],
|
|
|
|
s->reg[I_(UINTSP)]);
|
|
|
|
|
|
|
|
if ((s->reg[I_(UTRSTAT)] & UTRSTAT_Rx_BUFFER_DATA_READY) ||
|
|
|
|
(s->reg[I_(UCON)] & (1 << 11))) {
|
|
|
|
s->reg[I_(UINTSP)] |= UINTSP_RXD;
|
|
|
|
s->reg[I_(UTRSTAT)] |= UTRSTAT_Rx_TIMEOUT;
|
2020-01-23 18:22:42 +03:00
|
|
|
exynos4210_uart_update_dmabusy(s);
|
2020-01-23 18:22:41 +03:00
|
|
|
exynos4210_uart_update_irq(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 13:56:05 +04:00
|
|
|
static void exynos4210_uart_update_parameters(Exynos4210UartState *s)
|
|
|
|
{
|
2017-01-27 18:20:25 +03:00
|
|
|
int speed, parity, data_bits, stop_bits;
|
2012-02-16 13:56:05 +04:00
|
|
|
QEMUSerialSetParams ssp;
|
|
|
|
uint64_t uclk_rate;
|
|
|
|
|
|
|
|
if (s->reg[I_(UBRDIV)] == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->reg[I_(ULCON)] & 0x20) {
|
|
|
|
if (s->reg[I_(ULCON)] & 0x28) {
|
|
|
|
parity = 'E';
|
|
|
|
} else {
|
|
|
|
parity = 'O';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
parity = 'N';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->reg[I_(ULCON)] & 0x4) {
|
|
|
|
stop_bits = 2;
|
|
|
|
} else {
|
|
|
|
stop_bits = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data_bits = (s->reg[I_(ULCON)] & 0x3) + 5;
|
|
|
|
|
|
|
|
uclk_rate = 24000000;
|
|
|
|
|
|
|
|
speed = uclk_rate / ((16 * (s->reg[I_(UBRDIV)]) & 0xffff) +
|
|
|
|
(s->reg[I_(UFRACVAL)] & 0x7) + 16);
|
|
|
|
|
|
|
|
ssp.speed = speed;
|
|
|
|
ssp.parity = parity;
|
|
|
|
ssp.data_bits = data_bits;
|
|
|
|
ssp.stop_bits = stop_bits;
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
s->wordtime = NANOSECONDS_PER_SECOND * (data_bits + stop_bits + 1) / speed;
|
|
|
|
|
2016-10-22 12:52:55 +03:00
|
|
|
qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp);
|
2012-02-16 13:56:05 +04:00
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_update_params(
|
2020-01-23 18:22:41 +03:00
|
|
|
s->channel, speed, parity, data_bits, stop_bits, s->wordtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void exynos4210_uart_rx_timeout_set(Exynos4210UartState *s)
|
|
|
|
{
|
|
|
|
if (s->reg[I_(UCON)] & 0x80) {
|
|
|
|
uint32_t timeout = ((s->reg[I_(UCON)] >> 12) & 0x0f) * s->wordtime;
|
|
|
|
|
|
|
|
timer_mod(s->fifo_timeout_timer,
|
|
|
|
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + timeout);
|
|
|
|
} else {
|
|
|
|
timer_del(s->fifo_timeout_timer);
|
|
|
|
}
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void exynos4210_uart_write(void *opaque, hwaddr offset,
|
2012-02-16 13:56:05 +04:00
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = (Exynos4210UartState *)opaque;
|
|
|
|
uint8_t ch;
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_write(s->channel, offset,
|
|
|
|
exynos4210_uart_regname(offset), val);
|
2012-02-16 13:56:05 +04:00
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case ULCON:
|
|
|
|
case UBRDIV:
|
|
|
|
case UFRACVAL:
|
|
|
|
s->reg[I_(offset)] = val;
|
|
|
|
exynos4210_uart_update_parameters(s);
|
|
|
|
break;
|
|
|
|
case UFCON:
|
|
|
|
s->reg[I_(UFCON)] = val;
|
|
|
|
if (val & UFCON_Rx_FIFO_RESET) {
|
|
|
|
fifo_reset(&s->rx);
|
|
|
|
s->reg[I_(UFCON)] &= ~UFCON_Rx_FIFO_RESET;
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_rx_fifo_reset(s->channel);
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
if (val & UFCON_Tx_FIFO_RESET) {
|
|
|
|
fifo_reset(&s->tx);
|
|
|
|
s->reg[I_(UFCON)] &= ~UFCON_Tx_FIFO_RESET;
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_tx_fifo_reset(s->channel);
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UTXH:
|
2017-07-06 15:08:52 +03:00
|
|
|
if (qemu_chr_fe_backend_connected(&s->chr)) {
|
2012-02-16 13:56:05 +04:00
|
|
|
s->reg[I_(UTRSTAT)] &= ~(UTRSTAT_TRANSMITTER_EMPTY |
|
|
|
|
UTRSTAT_Tx_BUFFER_EMPTY);
|
|
|
|
ch = (uint8_t)val;
|
2016-09-06 16:56:04 +03:00
|
|
|
/* XXX this blocks entire thread. Rewrite to use
|
|
|
|
* qemu_chr_fe_write and background I/O callbacks */
|
2016-10-22 12:52:55 +03:00
|
|
|
qemu_chr_fe_write_all(&s->chr, &ch, 1);
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_tx(s->channel, ch);
|
2012-02-16 13:56:05 +04:00
|
|
|
s->reg[I_(UTRSTAT)] |= UTRSTAT_TRANSMITTER_EMPTY |
|
|
|
|
UTRSTAT_Tx_BUFFER_EMPTY;
|
|
|
|
s->reg[I_(UINTSP)] |= UINTSP_TXD;
|
|
|
|
exynos4210_uart_update_irq(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UINTP:
|
|
|
|
s->reg[I_(UINTP)] &= ~val;
|
|
|
|
s->reg[I_(UINTSP)] &= ~val;
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_intclr(s->channel, s->reg[I_(UINTP)]);
|
2012-02-16 13:56:05 +04:00
|
|
|
exynos4210_uart_update_irq(s);
|
|
|
|
break;
|
|
|
|
case UTRSTAT:
|
2020-01-23 18:22:41 +03:00
|
|
|
if (val & UTRSTAT_Rx_TIMEOUT) {
|
|
|
|
s->reg[I_(UTRSTAT)] &= ~UTRSTAT_Rx_TIMEOUT;
|
|
|
|
}
|
|
|
|
break;
|
2012-02-16 13:56:05 +04:00
|
|
|
case UERSTAT:
|
|
|
|
case UFSTAT:
|
|
|
|
case UMSTAT:
|
|
|
|
case URXH:
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_ro_write(
|
2012-02-16 13:56:05 +04:00
|
|
|
s->channel, exynos4210_uart_regname(offset), offset);
|
|
|
|
break;
|
|
|
|
case UINTSP:
|
|
|
|
s->reg[I_(UINTSP)] &= ~val;
|
|
|
|
break;
|
|
|
|
case UINTM:
|
|
|
|
s->reg[I_(UINTM)] = val;
|
|
|
|
exynos4210_uart_update_irq(s);
|
|
|
|
break;
|
|
|
|
case UCON:
|
|
|
|
case UMCON:
|
|
|
|
default:
|
|
|
|
s->reg[I_(offset)] = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-01-23 18:22:41 +03:00
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t exynos4210_uart_read(void *opaque, hwaddr offset,
|
2012-02-16 13:56:05 +04:00
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = (Exynos4210UartState *)opaque;
|
|
|
|
uint32_t res;
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case UERSTAT: /* Read Only */
|
|
|
|
res = s->reg[I_(UERSTAT)];
|
|
|
|
s->reg[I_(UERSTAT)] = 0;
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_read(s->channel, offset,
|
|
|
|
exynos4210_uart_regname(offset), res);
|
2012-02-16 13:56:05 +04:00
|
|
|
return res;
|
|
|
|
case UFSTAT: /* Read Only */
|
|
|
|
s->reg[I_(UFSTAT)] = fifo_elements_number(&s->rx) & 0xff;
|
|
|
|
if (fifo_empty_elements_number(&s->rx) == 0) {
|
|
|
|
s->reg[I_(UFSTAT)] |= UFSTAT_Rx_FIFO_FULL;
|
|
|
|
s->reg[I_(UFSTAT)] &= ~0xff;
|
|
|
|
}
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_read(s->channel, offset,
|
|
|
|
exynos4210_uart_regname(offset),
|
|
|
|
s->reg[I_(UFSTAT)]);
|
2012-02-16 13:56:05 +04:00
|
|
|
return s->reg[I_(UFSTAT)];
|
|
|
|
case URXH:
|
|
|
|
if (s->reg[I_(UFCON)] & UFCON_FIFO_ENABLE) {
|
|
|
|
if (fifo_elements_number(&s->rx)) {
|
|
|
|
res = fifo_retrieve(&s->rx);
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_rx(s->channel, res);
|
2012-02-16 13:56:05 +04:00
|
|
|
if (!fifo_elements_number(&s->rx)) {
|
|
|
|
s->reg[I_(UTRSTAT)] &= ~UTRSTAT_Rx_BUFFER_DATA_READY;
|
|
|
|
} else {
|
|
|
|
s->reg[I_(UTRSTAT)] |= UTRSTAT_Rx_BUFFER_DATA_READY;
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_rx_error(s->channel);
|
2012-02-16 13:56:05 +04:00
|
|
|
s->reg[I_(UINTSP)] |= UINTSP_ERROR;
|
|
|
|
exynos4210_uart_update_irq(s);
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s->reg[I_(UTRSTAT)] &= ~UTRSTAT_Rx_BUFFER_DATA_READY;
|
|
|
|
res = s->reg[I_(URXH)];
|
|
|
|
}
|
2021-01-30 21:40:17 +03:00
|
|
|
qemu_chr_fe_accept_input(&s->chr);
|
2020-01-23 18:22:42 +03:00
|
|
|
exynos4210_uart_update_dmabusy(s);
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_read(s->channel, offset,
|
|
|
|
exynos4210_uart_regname(offset), res);
|
2012-02-16 13:56:05 +04:00
|
|
|
return res;
|
|
|
|
case UTXH:
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_wo_read(s->channel, exynos4210_uart_regname(offset),
|
|
|
|
offset);
|
2012-02-16 13:56:05 +04:00
|
|
|
break;
|
|
|
|
default:
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_read(s->channel, offset,
|
|
|
|
exynos4210_uart_regname(offset),
|
|
|
|
s->reg[I_(offset)]);
|
2012-02-16 13:56:05 +04:00
|
|
|
return s->reg[I_(offset)];
|
|
|
|
}
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_read(s->channel, offset, exynos4210_uart_regname(offset),
|
|
|
|
0);
|
2012-02-16 13:56:05 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps exynos4210_uart_ops = {
|
|
|
|
.read = exynos4210_uart_read,
|
|
|
|
.write = exynos4210_uart_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.max_access_size = 4,
|
|
|
|
.unaligned = false
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int exynos4210_uart_can_receive(void *opaque)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = (Exynos4210UartState *)opaque;
|
|
|
|
|
2021-01-28 06:36:55 +03:00
|
|
|
if (s->reg[I_(UFCON)] & UFCON_FIFO_ENABLE) {
|
|
|
|
return fifo_empty_elements_number(&s->rx);
|
|
|
|
} else {
|
|
|
|
return !(s->reg[I_(UTRSTAT)] & UTRSTAT_Rx_BUFFER_DATA_READY);
|
|
|
|
}
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void exynos4210_uart_receive(void *opaque, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = (Exynos4210UartState *)opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (s->reg[I_(UFCON)] & UFCON_FIFO_ENABLE) {
|
|
|
|
if (fifo_empty_elements_number(&s->rx) < size) {
|
2020-01-23 18:22:41 +03:00
|
|
|
size = fifo_empty_elements_number(&s->rx);
|
2012-02-16 13:56:05 +04:00
|
|
|
s->reg[I_(UINTSP)] |= UINTSP_ERROR;
|
|
|
|
}
|
2020-01-23 18:22:41 +03:00
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
fifo_store(&s->rx, buf[i]);
|
|
|
|
}
|
|
|
|
exynos4210_uart_rx_timeout_set(s);
|
2012-02-16 13:56:05 +04:00
|
|
|
} else {
|
|
|
|
s->reg[I_(URXH)] = buf[0];
|
|
|
|
}
|
2020-01-23 18:22:41 +03:00
|
|
|
s->reg[I_(UTRSTAT)] |= UTRSTAT_Rx_BUFFER_DATA_READY;
|
2012-02-16 13:56:05 +04:00
|
|
|
|
|
|
|
exynos4210_uart_update_irq(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
chardev: Use QEMUChrEvent enum in IOEventHandler typedef
The Chardev events are listed in the QEMUChrEvent enum.
By using the enum in the IOEventHandler typedef we:
- make the IOEventHandler type more explicit (this handler
process out-of-band information, while the IOReadHandler
is in-band),
- help static code analyzers.
This patch was produced with the following spatch script:
@match@
expression backend, opaque, context, set_open;
identifier fd_can_read, fd_read, fd_event, be_change;
@@
qemu_chr_fe_set_handlers(backend, fd_can_read, fd_read, fd_event,
be_change, opaque, context, set_open);
@depends on match@
identifier opaque, event;
identifier match.fd_event;
@@
static
-void fd_event(void *opaque, int event)
+void fd_event(void *opaque, QEMUChrEvent event)
{
...
}
Then the typedef was modified manually in
include/chardev/char-fe.h.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Acked-by: Corey Minyard <cminyard@mvista.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20191218172009.8868-15-philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2019-12-18 20:20:09 +03:00
|
|
|
static void exynos4210_uart_event(void *opaque, QEMUChrEvent event)
|
2012-02-16 13:56:05 +04:00
|
|
|
{
|
|
|
|
Exynos4210UartState *s = (Exynos4210UartState *)opaque;
|
|
|
|
|
|
|
|
if (event == CHR_EVENT_BREAK) {
|
|
|
|
/* When the RxDn is held in logic 0, then a null byte is pushed into the
|
|
|
|
* fifo */
|
|
|
|
fifo_store(&s->rx, '\0');
|
|
|
|
s->reg[I_(UERSTAT)] |= UERSTAT_BREAK;
|
|
|
|
exynos4210_uart_update_irq(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void exynos4210_uart_reset(DeviceState *dev)
|
|
|
|
{
|
2013-07-25 00:21:05 +04:00
|
|
|
Exynos4210UartState *s = EXYNOS4210_UART(dev);
|
2012-02-16 13:56:05 +04:00
|
|
|
int i;
|
|
|
|
|
2013-12-07 17:48:06 +04:00
|
|
|
for (i = 0; i < ARRAY_SIZE(exynos4210_uart_regs); i++) {
|
2012-02-16 13:56:05 +04:00
|
|
|
s->reg[I_(exynos4210_uart_regs[i].offset)] =
|
|
|
|
exynos4210_uart_regs[i].reset_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
fifo_reset(&s->rx);
|
|
|
|
fifo_reset(&s->tx);
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
trace_exynos_uart_rxsize(s->channel, s->rx.size);
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
static int exynos4210_uart_post_load(void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = (Exynos4210UartState *)opaque;
|
|
|
|
|
|
|
|
exynos4210_uart_update_parameters(s);
|
2020-01-23 18:22:41 +03:00
|
|
|
exynos4210_uart_rx_timeout_set(s);
|
2020-01-23 18:22:41 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 13:56:05 +04:00
|
|
|
static const VMStateDescription vmstate_exynos4210_uart_fifo = {
|
|
|
|
.name = "exynos4210.uart.fifo",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2023-12-21 06:16:06 +03:00
|
|
|
.fields = (const VMStateField[]) {
|
2012-02-16 13:56:05 +04:00
|
|
|
VMSTATE_UINT32(sp, Exynos4210UartFIFO),
|
|
|
|
VMSTATE_UINT32(rp, Exynos4210UartFIFO),
|
2017-02-03 20:52:17 +03:00
|
|
|
VMSTATE_VBUFFER_UINT32(data, Exynos4210UartFIFO, 1, NULL, size),
|
2012-02-16 13:56:05 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_exynos4210_uart = {
|
|
|
|
.name = "exynos4210.uart",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2022-01-20 18:16:48 +03:00
|
|
|
.post_load = exynos4210_uart_post_load,
|
2023-12-21 06:16:06 +03:00
|
|
|
.fields = (const VMStateField[]) {
|
2012-02-16 13:56:05 +04:00
|
|
|
VMSTATE_STRUCT(rx, Exynos4210UartState, 1,
|
|
|
|
vmstate_exynos4210_uart_fifo, Exynos4210UartFIFO),
|
|
|
|
VMSTATE_UINT32_ARRAY(reg, Exynos4210UartState,
|
|
|
|
EXYNOS4210_UART_REGS_MEM_SIZE / sizeof(uint32_t)),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
DeviceState *exynos4210_uart_create(hwaddr addr,
|
2013-07-25 00:21:05 +04:00
|
|
|
int fifo_size,
|
|
|
|
int channel,
|
2016-12-07 16:20:22 +03:00
|
|
|
Chardev *chr,
|
2013-07-25 00:21:05 +04:00
|
|
|
qemu_irq irq)
|
2012-02-16 13:56:05 +04:00
|
|
|
{
|
|
|
|
DeviceState *dev;
|
|
|
|
SysBusDevice *bus;
|
|
|
|
|
qdev: Convert uses of qdev_create() with Coccinelle
This is the transformation explained in the commit before previous.
Takes care of just one pattern that needs conversion. More to come in
this series.
Coccinelle script:
@ depends on !(file in "hw/arm/highbank.c")@
expression bus, type_name, dev, expr;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr;
identifier DOWN;
@@
- dev = DOWN(qdev_create(bus, type_name));
+ dev = DOWN(qdev_new(type_name));
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ qdev_realize_and_unref(DEVICE(dev), bus, &error_fatal);
@@
expression bus, type_name, expr;
identifier dev;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- qdev_init_nofail(dev);
+ qdev_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, type_name, dev, expr, errp;
symbol true;
@@
- dev = qdev_create(bus, type_name);
+ dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
@@
expression bus, type_name, expr, errp;
identifier dev;
symbol true;
@@
- DeviceState *dev = qdev_create(bus, type_name);
+ DeviceState *dev = qdev_new(type_name);
... when != dev = expr
- object_property_set_bool(OBJECT(dev), true, "realized", errp);
+ qdev_realize_and_unref(dev, bus, errp);
The first rule exempts hw/arm/highbank.c, because it matches along two
control flow paths there, with different @type_name. Covered by the
next commit's manual conversions.
Missing #include "qapi/error.h" added manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-10-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:31:58 +03:00
|
|
|
dev = qdev_new(TYPE_EXYNOS4210_UART);
|
2012-02-16 13:56:05 +04:00
|
|
|
|
|
|
|
qdev_prop_set_chr(dev, "chardev", chr);
|
|
|
|
qdev_prop_set_uint32(dev, "channel", channel);
|
|
|
|
qdev_prop_set_uint32(dev, "rx-size", fifo_size);
|
|
|
|
qdev_prop_set_uint32(dev, "tx-size", fifo_size);
|
|
|
|
|
2013-01-20 05:47:33 +04:00
|
|
|
bus = SYS_BUS_DEVICE(dev);
|
sysbus: Convert to sysbus_realize() etc. with Coccinelle
Convert from qdev_realize(), qdev_realize_and_unref() with null @bus
argument to sysbus_realize(), sysbus_realize_and_unref().
Coccinelle script:
@@
expression dev, errp;
@@
- qdev_realize(DEVICE(dev), NULL, errp);
+ sysbus_realize(SYS_BUS_DEVICE(dev), errp);
@@
expression sysbus_dev, dev, errp;
@@
+ sysbus_dev = SYS_BUS_DEVICE(dev);
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
- sysbus_dev = SYS_BUS_DEVICE(dev);
@@
expression sysbus_dev, dev, errp;
expression expr;
@@
sysbus_dev = SYS_BUS_DEVICE(dev);
... when != dev = expr;
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(sysbus_dev, errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(DEVICE(dev), NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
@@
expression dev, errp;
@@
- qdev_realize_and_unref(dev, NULL, errp);
+ sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
Whitespace changes minimized manually.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-46-armbru@redhat.com>
[Conflicts in hw/misc/empty_slot.c and hw/sparc/leon3.c resolved]
2020-06-10 08:32:34 +03:00
|
|
|
sysbus_realize_and_unref(bus, &error_fatal);
|
2012-10-23 14:30:10 +04:00
|
|
|
if (addr != (hwaddr)-1) {
|
2012-02-16 13:56:05 +04:00
|
|
|
sysbus_mmio_map(bus, 0, addr);
|
|
|
|
}
|
|
|
|
sysbus_connect_irq(bus, 0, irq);
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2017-01-09 14:40:21 +03:00
|
|
|
static void exynos4210_uart_init(Object *obj)
|
2012-02-16 13:56:05 +04:00
|
|
|
{
|
2017-01-09 14:40:21 +03:00
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
|
2013-07-25 00:21:05 +04:00
|
|
|
Exynos4210UartState *s = EXYNOS4210_UART(dev);
|
2012-02-16 13:56:05 +04:00
|
|
|
|
2020-01-23 18:22:41 +03:00
|
|
|
s->wordtime = NANOSECONDS_PER_SECOND * 10 / 9600;
|
|
|
|
|
2012-02-16 13:56:05 +04:00
|
|
|
/* memory mapping */
|
2017-01-09 14:40:21 +03:00
|
|
|
memory_region_init_io(&s->iomem, obj, &exynos4210_uart_ops, s,
|
2013-06-07 05:25:08 +04:00
|
|
|
"exynos4210.uart", EXYNOS4210_UART_REGS_MEM_SIZE);
|
2012-02-16 13:56:05 +04:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
|
|
|
|
|
|
|
sysbus_init_irq(dev, &s->irq);
|
2020-01-23 18:22:42 +03:00
|
|
|
sysbus_init_irq(dev, &s->dmairq);
|
2017-01-09 14:40:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void exynos4210_uart_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
Exynos4210UartState *s = EXYNOS4210_UART(dev);
|
2012-02-16 13:56:05 +04:00
|
|
|
|
2020-02-13 05:56:03 +03:00
|
|
|
s->fifo_timeout_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
|
|
|
|
exynos4210_uart_timeout_int, s);
|
|
|
|
|
2016-10-22 12:52:55 +03:00
|
|
|
qemu_chr_fe_set_handlers(&s->chr, exynos4210_uart_can_receive,
|
|
|
|
exynos4210_uart_receive, exynos4210_uart_event,
|
2017-07-06 15:08:49 +03:00
|
|
|
NULL, s, NULL, true);
|
2012-02-16 13:56:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static Property exynos4210_uart_properties[] = {
|
|
|
|
DEFINE_PROP_CHR("chardev", Exynos4210UartState, chr),
|
|
|
|
DEFINE_PROP_UINT32("channel", Exynos4210UartState, channel, 0),
|
|
|
|
DEFINE_PROP_UINT32("rx-size", Exynos4210UartState, rx.size, 16),
|
|
|
|
DEFINE_PROP_UINT32("tx-size", Exynos4210UartState, tx.size, 16),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void exynos4210_uart_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
2017-01-09 14:40:21 +03:00
|
|
|
dc->realize = exynos4210_uart_realize;
|
2024-09-13 17:31:44 +03:00
|
|
|
device_class_set_legacy_reset(dc, exynos4210_uart_reset);
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, exynos4210_uart_properties);
|
2012-02-16 13:56:05 +04:00
|
|
|
dc->vmsd = &vmstate_exynos4210_uart;
|
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo exynos4210_uart_info = {
|
2013-07-25 00:21:05 +04:00
|
|
|
.name = TYPE_EXYNOS4210_UART,
|
2012-02-16 13:56:05 +04:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(Exynos4210UartState),
|
2017-01-09 14:40:21 +03:00
|
|
|
.instance_init = exynos4210_uart_init,
|
2012-02-16 13:56:05 +04:00
|
|
|
.class_init = exynos4210_uart_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void exynos4210_uart_register(void)
|
|
|
|
{
|
|
|
|
type_register_static(&exynos4210_uart_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(exynos4210_uart_register)
|