2012-07-04 14:43:33 +04:00
|
|
|
/*
|
|
|
|
* IMX31 UARTS
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 OKL
|
|
|
|
* Originally Written by Hans Jiang
|
|
|
|
* Copyright (c) 2011 NICTA Pty Ltd.
|
2015-08-13 13:26:19 +03:00
|
|
|
* Updated by Jean-Christophe Dubois <jcd@tribudubois.net>
|
2012-07-04 14:43:33 +04:00
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
* This is a `bare-bones' implementation of the IMX series serial ports.
|
|
|
|
* TODO:
|
|
|
|
* -- implement FIFOs. The real hardware has 32 word transmit
|
|
|
|
* and receive FIFOs; we currently use a 1-char buffer
|
|
|
|
* -- implement DMA
|
|
|
|
* -- implement BAUD-rate and modem lines, for when the backend
|
|
|
|
* is a real serial device.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:05 +03:00
|
|
|
#include "qemu/osdep.h"
|
2015-08-13 13:26:19 +03:00
|
|
|
#include "hw/char/imx_serial.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"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2015-12-15 15:16:16 +03:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2024-01-25 18:19:32 +03:00
|
|
|
#include "qemu/fifo32.h"
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2015-10-25 17:16:06 +03:00
|
|
|
#ifndef DEBUG_IMX_UART
|
|
|
|
#define DEBUG_IMX_UART 0
|
2012-07-04 14:43:33 +04:00
|
|
|
#endif
|
|
|
|
|
2015-10-25 17:16:06 +03:00
|
|
|
#define DPRINTF(fmt, args...) \
|
|
|
|
do { \
|
|
|
|
if (DEBUG_IMX_UART) { \
|
|
|
|
fprintf(stderr, "[%s]%s: " fmt , TYPE_IMX_SERIAL, \
|
|
|
|
__func__, ##args); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2012-07-04 14:43:33 +04:00
|
|
|
|
|
|
|
static const VMStateDescription vmstate_imx_serial = {
|
2015-08-13 13:26:19 +03:00
|
|
|
.name = TYPE_IMX_SERIAL,
|
2024-01-25 18:19:32 +03:00
|
|
|
.version_id = 3,
|
|
|
|
.minimum_version_id = 3,
|
2023-12-21 06:16:06 +03:00
|
|
|
.fields = (const VMStateField[]) {
|
2024-01-25 18:19:32 +03:00
|
|
|
VMSTATE_FIFO32(rx_fifo, IMXSerialState),
|
|
|
|
VMSTATE_TIMER(ageing_timer, IMXSerialState),
|
2012-07-04 14:43:33 +04:00
|
|
|
VMSTATE_UINT32(usr1, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(usr2, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(ucr1, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(uts1, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(onems, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(ufcr, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(ubmr, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(ubrc, IMXSerialState),
|
|
|
|
VMSTATE_UINT32(ucr3, IMXSerialState),
|
2018-03-15 22:11:41 +03:00
|
|
|
VMSTATE_UINT32(ucr4, IMXSerialState),
|
2012-07-04 14:43:33 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void imx_update(IMXSerialState *s)
|
|
|
|
{
|
2018-03-15 22:11:40 +03:00
|
|
|
uint32_t usr1;
|
|
|
|
uint32_t usr2;
|
|
|
|
uint32_t mask;
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2018-03-15 22:11:40 +03:00
|
|
|
/*
|
|
|
|
* Lucky for us TRDY and RRDY has the same offset in both USR1 and
|
|
|
|
* UCR1, so we can get away with something as simple as the
|
|
|
|
* following:
|
|
|
|
*/
|
|
|
|
usr1 = s->usr1 & s->ucr1 & (USR1_TRDY | USR1_RRDY);
|
2024-01-25 18:19:32 +03:00
|
|
|
/*
|
|
|
|
* Interrupt if AGTIM is set (ageing timer interrupt in RxFIFO)
|
|
|
|
*/
|
|
|
|
usr1 |= (s->ucr2 & UCR2_ATEN) ? (s->usr1 & USR1_AGTIM) : 0;
|
2018-03-15 22:11:40 +03:00
|
|
|
/*
|
|
|
|
* Bits that we want in USR2 are not as conveniently laid out,
|
|
|
|
* unfortunately.
|
|
|
|
*/
|
|
|
|
mask = (s->ucr1 & UCR1_TXMPTYEN) ? USR2_TXFE : 0;
|
2018-03-15 22:11:41 +03:00
|
|
|
/*
|
|
|
|
* TCEN and TXDC are both bit 3
|
2024-01-25 18:19:32 +03:00
|
|
|
* ORE and OREN are both bit 1
|
2018-08-20 13:24:31 +03:00
|
|
|
* RDR and DREN are both bit 0
|
2018-03-15 22:11:41 +03:00
|
|
|
*/
|
2024-01-25 18:19:32 +03:00
|
|
|
mask |= s->ucr4 & (UCR4_WKEN | UCR4_TCEN | UCR4_DREN | UCR4_OREN);
|
2018-03-15 22:11:41 +03:00
|
|
|
|
2018-03-15 22:11:40 +03:00
|
|
|
usr2 = s->usr2 & mask;
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2018-03-15 22:11:40 +03:00
|
|
|
qemu_set_irq(s->irq, usr1 || usr2);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
|
2024-01-25 18:19:32 +03:00
|
|
|
static void imx_serial_rx_fifo_push(IMXSerialState *s, uint32_t value)
|
|
|
|
{
|
|
|
|
uint32_t pushed_value = value;
|
|
|
|
if (fifo32_is_full(&s->rx_fifo)) {
|
|
|
|
/* Set ORE if FIFO is already full */
|
|
|
|
s->usr2 |= USR2_ORE;
|
|
|
|
} else {
|
|
|
|
if (fifo32_num_used(&s->rx_fifo) == FIFO_SIZE - 1) {
|
|
|
|
/* Set OVRRUN on 32nd character in FIFO */
|
|
|
|
pushed_value |= URXD_ERR | URXD_OVRRUN;
|
|
|
|
}
|
|
|
|
fifo32_push(&s->rx_fifo, pushed_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t imx_serial_rx_fifo_pop(IMXSerialState *s)
|
|
|
|
{
|
|
|
|
if (fifo32_is_empty(&s->rx_fifo)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return fifo32_pop(&s->rx_fifo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_serial_rx_fifo_ageing_timer_int(void *opaque)
|
|
|
|
{
|
|
|
|
IMXSerialState *s = (IMXSerialState *) opaque;
|
|
|
|
s->usr1 |= USR1_AGTIM;
|
|
|
|
imx_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_serial_rx_fifo_ageing_timer_restart(void *opaque)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Ageing timer starts ticking when
|
|
|
|
* RX FIFO is non empty and below trigger level.
|
|
|
|
* Timer is reset if new character is received or
|
|
|
|
* a FIFO read occurs.
|
|
|
|
* Timer triggers an interrupt when duration of
|
|
|
|
* 8 characters has passed (assuming 115200 baudrate).
|
|
|
|
*/
|
|
|
|
IMXSerialState *s = (IMXSerialState *) opaque;
|
|
|
|
|
|
|
|
if (!(s->usr1 & USR1_RRDY) && !(s->uts1 & UTS1_RXEMPTY)) {
|
|
|
|
timer_mod_ns(&s->ageing_timer,
|
|
|
|
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + AGE_DURATION_NS);
|
|
|
|
} else {
|
|
|
|
timer_del(&s->ageing_timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
static void imx_serial_reset(IMXSerialState *s)
|
|
|
|
{
|
|
|
|
|
|
|
|
s->usr1 = USR1_TRDY | USR1_RXDS;
|
|
|
|
/*
|
|
|
|
* Fake attachment of a terminal: assert RTS.
|
|
|
|
*/
|
|
|
|
s->usr1 |= USR1_RTSS;
|
|
|
|
s->usr2 = USR2_TXFE | USR2_TXDC | USR2_DCDIN;
|
|
|
|
s->uts1 = UTS1_RXEMPTY | UTS1_TXEMPTY;
|
|
|
|
s->ucr1 = 0;
|
|
|
|
s->ucr2 = UCR2_SRST;
|
|
|
|
s->ucr3 = 0x700;
|
|
|
|
s->ubmr = 0;
|
|
|
|
s->ubrc = 4;
|
2024-01-25 18:19:32 +03:00
|
|
|
|
|
|
|
fifo32_reset(&s->rx_fifo);
|
|
|
|
timer_del(&s->ageing_timer);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_serial_reset_at_boot(DeviceState *dev)
|
|
|
|
{
|
2013-07-25 00:43:22 +04:00
|
|
|
IMXSerialState *s = IMX_SERIAL(dev);
|
2012-07-04 14:43:33 +04:00
|
|
|
|
|
|
|
imx_serial_reset(s);
|
|
|
|
|
|
|
|
/*
|
2023-07-14 14:32:24 +03:00
|
|
|
* enable the uart on boot, so messages from the linux decompressor
|
2012-07-04 14:43:33 +04:00
|
|
|
* are visible. On real hardware this is done by the boot rom
|
|
|
|
* before anything else is loaded.
|
|
|
|
*/
|
|
|
|
s->ucr1 = UCR1_UARTEN;
|
|
|
|
s->ucr2 = UCR2_TXEN;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t imx_serial_read(void *opaque, hwaddr offset,
|
2012-07-04 14:43:33 +04:00
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
IMXSerialState *s = (IMXSerialState *)opaque;
|
2024-01-25 18:19:32 +03:00
|
|
|
uint32_t c, rx_used;
|
|
|
|
uint8_t rxtl = s->ufcr & TL_MASK;
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2015-10-25 17:16:06 +03:00
|
|
|
DPRINTF("read(offset=0x%" HWADDR_PRIx ")\n", offset);
|
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0x0: /* URXD */
|
2024-01-25 18:19:32 +03:00
|
|
|
c = imx_serial_rx_fifo_pop(s);
|
2012-07-04 14:43:33 +04:00
|
|
|
if (!(s->uts1 & UTS1_RXEMPTY)) {
|
|
|
|
/* Character is valid */
|
|
|
|
c |= URXD_CHARRDY;
|
2024-01-25 18:19:32 +03:00
|
|
|
rx_used = fifo32_num_used(&s->rx_fifo);
|
|
|
|
/* Clear RRDY if below threshold */
|
|
|
|
if (rx_used < rxtl) {
|
|
|
|
s->usr1 &= ~USR1_RRDY;
|
|
|
|
}
|
|
|
|
if (rx_used == 0) {
|
|
|
|
s->usr2 &= ~USR2_RDR;
|
|
|
|
s->uts1 |= UTS1_RXEMPTY;
|
|
|
|
}
|
2012-07-04 14:43:33 +04:00
|
|
|
imx_update(s);
|
2024-01-25 18:19:32 +03:00
|
|
|
imx_serial_rx_fifo_ageing_timer_restart(s);
|
2016-10-22 12:52:59 +03:00
|
|
|
qemu_chr_fe_accept_input(&s->chr);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
|
|
|
|
case 0x20: /* UCR1 */
|
|
|
|
return s->ucr1;
|
|
|
|
|
|
|
|
case 0x21: /* UCR2 */
|
|
|
|
return s->ucr2;
|
|
|
|
|
|
|
|
case 0x25: /* USR1 */
|
|
|
|
return s->usr1;
|
|
|
|
|
|
|
|
case 0x26: /* USR2 */
|
|
|
|
return s->usr2;
|
|
|
|
|
|
|
|
case 0x2A: /* BRM Modulator */
|
|
|
|
return s->ubmr;
|
|
|
|
|
|
|
|
case 0x2B: /* Baud Rate Count */
|
|
|
|
return s->ubrc;
|
|
|
|
|
|
|
|
case 0x2d: /* Test register */
|
|
|
|
return s->uts1;
|
|
|
|
|
|
|
|
case 0x24: /* UFCR */
|
|
|
|
return s->ufcr;
|
|
|
|
|
|
|
|
case 0x2c:
|
|
|
|
return s->onems;
|
|
|
|
|
|
|
|
case 0x22: /* UCR3 */
|
|
|
|
return s->ucr3;
|
|
|
|
|
|
|
|
case 0x23: /* UCR4 */
|
2018-03-15 22:11:41 +03:00
|
|
|
return s->ucr4;
|
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
case 0x29: /* BRM Incremental */
|
|
|
|
return 0x0; /* TODO */
|
|
|
|
|
|
|
|
default:
|
2015-10-25 17:16:06 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register at offset 0x%"
|
|
|
|
HWADDR_PRIx "\n", TYPE_IMX_SERIAL, __func__, offset);
|
2012-07-04 14:43:33 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void imx_serial_write(void *opaque, hwaddr offset,
|
2015-08-13 13:26:19 +03:00
|
|
|
uint64_t value, unsigned size)
|
2012-07-04 14:43:33 +04:00
|
|
|
{
|
|
|
|
IMXSerialState *s = (IMXSerialState *)opaque;
|
2016-12-07 16:20:22 +03:00
|
|
|
Chardev *chr = qemu_chr_fe_get_driver(&s->chr);
|
2012-07-04 14:43:33 +04:00
|
|
|
unsigned char ch;
|
|
|
|
|
2015-10-25 17:16:06 +03:00
|
|
|
DPRINTF("write(offset=0x%" HWADDR_PRIx ", value = 0x%x) to %s\n",
|
2016-10-22 12:52:55 +03:00
|
|
|
offset, (unsigned int)value, chr ? chr->label : "NODEV");
|
2012-07-04 14:43:33 +04:00
|
|
|
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0x10: /* UTXD */
|
|
|
|
ch = value;
|
|
|
|
if (s->ucr2 & UCR2_TXEN) {
|
2016-10-22 12:52:59 +03:00
|
|
|
/* XXX this blocks entire thread. Rewrite to use
|
|
|
|
* qemu_chr_fe_write and background I/O callbacks */
|
|
|
|
qemu_chr_fe_write_all(&s->chr, &ch, 1);
|
2012-07-04 14:43:33 +04:00
|
|
|
s->usr1 &= ~USR1_TRDY;
|
2018-03-15 22:11:41 +03:00
|
|
|
s->usr2 &= ~USR2_TXDC;
|
2012-07-04 14:43:33 +04:00
|
|
|
imx_update(s);
|
|
|
|
s->usr1 |= USR1_TRDY;
|
2018-03-15 22:11:41 +03:00
|
|
|
s->usr2 |= USR2_TXDC;
|
2012-07-04 14:43:33 +04:00
|
|
|
imx_update(s);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x20: /* UCR1 */
|
|
|
|
s->ucr1 = value & 0xffff;
|
2015-10-25 17:16:06 +03:00
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
DPRINTF("write(ucr1=%x)\n", (unsigned int)value);
|
2015-10-25 17:16:06 +03:00
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
imx_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x21: /* UCR2 */
|
|
|
|
/*
|
|
|
|
* Only a few bits in control register 2 are implemented as yet.
|
|
|
|
* If it's intended to use a real serial device as a back-end, this
|
|
|
|
* register will have to be implemented more fully.
|
|
|
|
*/
|
|
|
|
if (!(value & UCR2_SRST)) {
|
|
|
|
imx_serial_reset(s);
|
|
|
|
imx_update(s);
|
|
|
|
value |= UCR2_SRST;
|
|
|
|
}
|
|
|
|
if (value & UCR2_RXEN) {
|
|
|
|
if (!(s->ucr2 & UCR2_RXEN)) {
|
2016-10-22 12:52:59 +03:00
|
|
|
qemu_chr_fe_accept_input(&s->chr);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
s->ucr2 = value & 0xffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x25: /* USR1 */
|
|
|
|
value &= USR1_AWAKE | USR1_AIRINT | USR1_DTRD | USR1_AGTIM |
|
2015-08-13 13:26:19 +03:00
|
|
|
USR1_FRAMERR | USR1_ESCF | USR1_RTSD | USR1_PARTYER;
|
2012-07-04 14:43:33 +04:00
|
|
|
s->usr1 &= ~value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x26: /* USR2 */
|
2015-08-13 13:26:19 +03:00
|
|
|
/*
|
|
|
|
* Writing 1 to some bits clears them; all other
|
|
|
|
* values are ignored
|
|
|
|
*/
|
2012-07-04 14:43:33 +04:00
|
|
|
value &= USR2_ADET | USR2_DTRF | USR2_IDLE | USR2_ACST |
|
2015-08-13 13:26:19 +03:00
|
|
|
USR2_RIDELT | USR2_IRINT | USR2_WAKE |
|
|
|
|
USR2_DCDDELT | USR2_RTSF | USR2_BRCD | USR2_ORE;
|
2012-07-04 14:43:33 +04:00
|
|
|
s->usr2 &= ~value;
|
|
|
|
break;
|
|
|
|
|
2015-08-13 13:26:19 +03:00
|
|
|
/*
|
|
|
|
* Linux expects to see what it writes to these registers
|
|
|
|
* We don't currently alter the baud rate
|
|
|
|
*/
|
2012-07-04 14:43:33 +04:00
|
|
|
case 0x29: /* UBIR */
|
|
|
|
s->ubrc = value & 0xffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x2a: /* UBMR */
|
|
|
|
s->ubmr = value & 0xffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x2c: /* One ms reg */
|
|
|
|
s->onems = value & 0xffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x24: /* FIFO control register */
|
|
|
|
s->ufcr = value & 0xffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x22: /* UCR3 */
|
|
|
|
s->ucr3 = value & 0xffff;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x23: /* UCR4 */
|
2018-03-15 22:11:41 +03:00
|
|
|
s->ucr4 = value & 0xffff;
|
|
|
|
imx_update(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x2d: /* UTS1 */
|
2015-10-25 17:16:06 +03:00
|
|
|
qemu_log_mask(LOG_UNIMP, "[%s]%s: Unimplemented reg 0x%"
|
|
|
|
HWADDR_PRIx "\n", TYPE_IMX_SERIAL, __func__, offset);
|
2012-07-04 14:43:33 +04:00
|
|
|
/* TODO */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-10-25 17:16:06 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Bad register at offset 0x%"
|
|
|
|
HWADDR_PRIx "\n", TYPE_IMX_SERIAL, __func__, offset);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_can_receive(void *opaque)
|
|
|
|
{
|
|
|
|
IMXSerialState *s = (IMXSerialState *)opaque;
|
2024-01-25 18:19:32 +03:00
|
|
|
return s->ucr2 & UCR2_RXEN && fifo32_num_used(&s->rx_fifo) < FIFO_SIZE;
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_put_data(void *opaque, uint32_t value)
|
|
|
|
{
|
|
|
|
IMXSerialState *s = (IMXSerialState *)opaque;
|
2024-01-25 18:19:32 +03:00
|
|
|
uint8_t rxtl = s->ufcr & TL_MASK;
|
2015-10-25 17:16:06 +03:00
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
DPRINTF("received char\n");
|
2024-01-25 18:19:32 +03:00
|
|
|
imx_serial_rx_fifo_push(s, value);
|
|
|
|
if (fifo32_num_used(&s->rx_fifo) >= rxtl) {
|
|
|
|
s->usr1 |= USR1_RRDY;
|
|
|
|
}
|
|
|
|
|
|
|
|
imx_serial_rx_fifo_ageing_timer_restart(s);
|
2015-10-25 17:16:06 +03:00
|
|
|
|
2012-07-04 14:43:33 +04:00
|
|
|
s->usr2 |= USR2_RDR;
|
|
|
|
s->uts1 &= ~UTS1_RXEMPTY;
|
2018-03-23 21:26:45 +03:00
|
|
|
if (value & URXD_BRK) {
|
|
|
|
s->usr2 |= USR2_BRCD;
|
|
|
|
}
|
2012-07-04 14:43:33 +04:00
|
|
|
imx_update(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_receive(void *opaque, const uint8_t *buf, int size)
|
|
|
|
{
|
2023-06-15 17:22:56 +03:00
|
|
|
IMXSerialState *s = (IMXSerialState *)opaque;
|
|
|
|
|
|
|
|
s->usr2 |= USR2_WAKE;
|
2012-07-04 14:43:33 +04:00
|
|
|
imx_put_data(opaque, *buf);
|
|
|
|
}
|
|
|
|
|
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 imx_event(void *opaque, QEMUChrEvent event)
|
2012-07-04 14:43:33 +04:00
|
|
|
{
|
|
|
|
if (event == CHR_EVENT_BREAK) {
|
2018-03-23 21:26:45 +03:00
|
|
|
imx_put_data(opaque, URXD_BRK | URXD_FRMERR | URXD_ERR);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct MemoryRegionOps imx_serial_ops = {
|
|
|
|
.read = imx_serial_read,
|
|
|
|
.write = imx_serial_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2015-08-13 13:26:19 +03:00
|
|
|
static void imx_serial_realize(DeviceState *dev, Error **errp)
|
2012-07-04 14:43:33 +04:00
|
|
|
{
|
2013-07-25 00:43:22 +04:00
|
|
|
IMXSerialState *s = IMX_SERIAL(dev);
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2024-01-25 18:19:32 +03:00
|
|
|
fifo32_create(&s->rx_fifo, FIFO_SIZE);
|
|
|
|
timer_init_ns(&s->ageing_timer, QEMU_CLOCK_VIRTUAL,
|
|
|
|
imx_serial_rx_fifo_ageing_timer_int, s);
|
|
|
|
|
2016-10-22 12:52:59 +03:00
|
|
|
DPRINTF("char dev for uart: %p\n", qemu_chr_fe_get_driver(&s->chr));
|
|
|
|
|
|
|
|
qemu_chr_fe_set_handlers(&s->chr, imx_can_receive, imx_receive,
|
2017-07-06 15:08:49 +03:00
|
|
|
imx_event, NULL, s, NULL, true);
|
2015-08-13 13:26:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_serial_init(Object *obj)
|
|
|
|
{
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
|
|
|
IMXSerialState *s = IMX_SERIAL(obj);
|
2012-07-04 14:43:33 +04:00
|
|
|
|
2015-08-13 13:26:19 +03:00
|
|
|
memory_region_init_io(&s->iomem, obj, &imx_serial_ops, s,
|
|
|
|
TYPE_IMX_SERIAL, 0x1000);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
|
2015-08-13 13:26:19 +03:00
|
|
|
static Property imx_serial_properties[] = {
|
2012-07-04 14:43:33 +04:00
|
|
|
DEFINE_PROP_CHR("chardev", IMXSerialState, chr),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void imx_serial_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
2015-08-13 13:26:19 +03:00
|
|
|
dc->realize = imx_serial_realize;
|
2012-07-04 14:43:33 +04:00
|
|
|
dc->vmsd = &vmstate_imx_serial;
|
|
|
|
dc->reset = imx_serial_reset_at_boot;
|
2013-07-29 18:17:45 +04:00
|
|
|
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
2012-07-04 14:43:33 +04:00
|
|
|
dc->desc = "i.MX series UART";
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, imx_serial_properties);
|
2012-07-04 14:43:33 +04:00
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo imx_serial_info = {
|
2015-08-13 13:26:19 +03:00
|
|
|
.name = TYPE_IMX_SERIAL,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(IMXSerialState),
|
|
|
|
.instance_init = imx_serial_init,
|
|
|
|
.class_init = imx_serial_class_init,
|
2012-07-04 14:43:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void imx_serial_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&imx_serial_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(imx_serial_register_types)
|