2007-09-29 23:43:54 +04:00
|
|
|
/*
|
|
|
|
* QEMU SCI/SCIF serial port emulation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Magnus Damm
|
|
|
|
*
|
|
|
|
* Based on serial.c - QEMU 16450 UART emulation
|
|
|
|
* Copyright (c) 2003-2004 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2019-08-12 08:23:42 +03:00
|
|
|
|
2016-01-26 21:17:30 +03:00
|
|
|
#include "qemu/osdep.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/sh4/sh.h"
|
2017-01-26 17:26:44 +03:00
|
|
|
#include "chardev/char-fe.h"
|
2016-10-22 12:52:52 +03:00
|
|
|
#include "qapi/error.h"
|
2018-09-05 16:11:25 +03:00
|
|
|
#include "qemu/timer.h"
|
2021-10-30 00:02:09 +03:00
|
|
|
#include "qemu/log.h"
|
2021-10-30 00:02:09 +03:00
|
|
|
#include "trace.h"
|
2007-09-29 23:43:54 +04:00
|
|
|
|
|
|
|
#define SH_SERIAL_FLAG_TEND (1 << 0)
|
|
|
|
#define SH_SERIAL_FLAG_TDE (1 << 1)
|
|
|
|
#define SH_SERIAL_FLAG_RDF (1 << 2)
|
|
|
|
#define SH_SERIAL_FLAG_BRK (1 << 3)
|
|
|
|
#define SH_SERIAL_FLAG_DR (1 << 4)
|
|
|
|
|
2008-09-15 11:05:18 +04:00
|
|
|
#define SH_RX_FIFO_LENGTH (16)
|
|
|
|
|
2007-09-29 23:43:54 +04:00
|
|
|
typedef struct {
|
2011-11-17 17:23:02 +04:00
|
|
|
MemoryRegion iomem;
|
|
|
|
MemoryRegion iomem_p4;
|
|
|
|
MemoryRegion iomem_a7;
|
2007-09-29 23:43:54 +04:00
|
|
|
uint8_t smr;
|
|
|
|
uint8_t brr;
|
|
|
|
uint8_t scr;
|
|
|
|
uint8_t dr; /* ftdr / tdr */
|
|
|
|
uint8_t sr; /* fsr / ssr */
|
|
|
|
uint16_t fcr;
|
|
|
|
uint8_t sptr;
|
|
|
|
|
2008-09-15 11:05:18 +04:00
|
|
|
uint8_t rx_fifo[SH_RX_FIFO_LENGTH]; /* frdr / rdr */
|
2007-09-29 23:43:54 +04:00
|
|
|
uint8_t rx_cnt;
|
2008-09-15 11:05:18 +04:00
|
|
|
uint8_t rx_tail;
|
|
|
|
uint8_t rx_head;
|
2007-09-29 23:43:54 +04:00
|
|
|
|
|
|
|
int freq;
|
|
|
|
int feat;
|
|
|
|
int flags;
|
2008-09-15 11:05:18 +04:00
|
|
|
int rtrg;
|
2007-09-29 23:43:54 +04:00
|
|
|
|
2016-10-22 12:52:52 +03:00
|
|
|
CharBackend chr;
|
2021-10-30 00:02:09 +03:00
|
|
|
QEMUTimer fifo_timeout_timer;
|
2018-09-05 16:11:25 +03:00
|
|
|
uint64_t etu; /* Elementary Time Unit (ns) */
|
2008-05-09 22:46:04 +04:00
|
|
|
|
2008-11-22 00:06:51 +03:00
|
|
|
qemu_irq eri;
|
|
|
|
qemu_irq rxi;
|
|
|
|
qemu_irq txi;
|
|
|
|
qemu_irq tei;
|
|
|
|
qemu_irq bri;
|
2021-10-30 00:02:09 +03:00
|
|
|
} SHSerialState;
|
2007-09-29 23:43:54 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
static void sh_serial_clear_fifo(SHSerialState *s)
|
2008-09-15 11:05:18 +04:00
|
|
|
{
|
|
|
|
memset(s->rx_fifo, 0, SH_RX_FIFO_LENGTH);
|
|
|
|
s->rx_cnt = 0;
|
|
|
|
s->rx_head = 0;
|
|
|
|
s->rx_tail = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void sh_serial_write(void *opaque, hwaddr offs,
|
2011-11-17 17:23:02 +04:00
|
|
|
uint64_t val, unsigned size)
|
2007-09-29 23:43:54 +04:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
SHSerialState *s = opaque;
|
2007-09-29 23:43:54 +04:00
|
|
|
unsigned char ch;
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_serial_write(size, offs, val);
|
2021-10-30 00:02:09 +03:00
|
|
|
switch (offs) {
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x00: /* SMR */
|
|
|
|
s->smr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0x7b : 0xff);
|
|
|
|
return;
|
|
|
|
case 0x04: /* BRR */
|
|
|
|
s->brr = val;
|
2018-12-14 01:37:37 +03:00
|
|
|
return;
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x08: /* SCR */
|
2008-09-15 11:05:18 +04:00
|
|
|
/* TODO : For SH7751, SCIF mask should be 0xfb. */
|
2008-05-09 22:46:04 +04:00
|
|
|
s->scr = val & ((s->feat & SH_SERIAL_FEAT_SCIF) ? 0xfa : 0xff);
|
2021-10-30 00:02:09 +03:00
|
|
|
if (!(val & (1 << 5))) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->flags |= SH_SERIAL_FLAG_TEND;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2008-05-09 22:46:04 +04:00
|
|
|
if ((s->feat & SH_SERIAL_FEAT_SCIF) && s->txi) {
|
2018-12-14 01:37:37 +03:00
|
|
|
qemu_set_irq(s->txi, val & (1 << 7));
|
2008-05-09 22:46:04 +04:00
|
|
|
}
|
2008-11-22 00:06:51 +03:00
|
|
|
if (!(val & (1 << 6))) {
|
2018-12-14 01:37:37 +03:00
|
|
|
qemu_set_irq(s->rxi, 0);
|
2008-09-15 11:05:18 +04:00
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
return;
|
|
|
|
case 0x0c: /* FTDR / TDR */
|
2017-07-06 15:08:52 +03:00
|
|
|
if (qemu_chr_fe_backend_connected(&s->chr)) {
|
2007-09-29 23:43:54 +04:00
|
|
|
ch = val;
|
2021-10-30 00:02:09 +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);
|
2018-12-14 01:37:37 +03:00
|
|
|
}
|
|
|
|
s->dr = val;
|
|
|
|
s->flags &= ~SH_SERIAL_FLAG_TDE;
|
2007-09-29 23:43:54 +04:00
|
|
|
return;
|
|
|
|
#if 0
|
|
|
|
case 0x14: /* FRDR / RDR */
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (s->feat & SH_SERIAL_FEAT_SCIF) {
|
2021-10-30 00:02:09 +03:00
|
|
|
switch (offs) {
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x10: /* FSR */
|
2021-10-30 00:02:09 +03:00
|
|
|
if (!(val & (1 << 6))) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->flags &= ~SH_SERIAL_FLAG_TEND;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (!(val & (1 << 5))) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->flags &= ~SH_SERIAL_FLAG_TDE;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (!(val & (1 << 4))) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->flags &= ~SH_SERIAL_FLAG_BRK;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (!(val & (1 << 1))) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->flags &= ~SH_SERIAL_FLAG_RDF;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (!(val & (1 << 0))) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->flags &= ~SH_SERIAL_FLAG_DR;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2008-09-15 11:05:18 +04:00
|
|
|
|
|
|
|
if (!(val & (1 << 1)) || !(val & (1 << 0))) {
|
2008-11-22 00:06:51 +03:00
|
|
|
if (s->rxi) {
|
|
|
|
qemu_set_irq(s->rxi, 0);
|
2008-09-15 11:05:18 +04:00
|
|
|
}
|
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
return;
|
|
|
|
case 0x18: /* FCR */
|
|
|
|
s->fcr = val;
|
2008-09-15 11:05:18 +04:00
|
|
|
switch ((val >> 6) & 3) {
|
|
|
|
case 0:
|
|
|
|
s->rtrg = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
s->rtrg = 4;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
s->rtrg = 8;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
s->rtrg = 14;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (val & (1 << 1)) {
|
|
|
|
sh_serial_clear_fifo(s);
|
|
|
|
s->sr &= ~(1 << 1);
|
|
|
|
}
|
|
|
|
|
2007-09-29 23:43:54 +04:00
|
|
|
return;
|
|
|
|
case 0x20: /* SPTR */
|
2008-09-15 11:05:18 +04:00
|
|
|
s->sptr = val & 0xf3;
|
2007-09-29 23:43:54 +04:00
|
|
|
return;
|
|
|
|
case 0x24: /* LSR */
|
|
|
|
return;
|
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
} else {
|
|
|
|
switch (offs) {
|
2008-12-08 01:46:49 +03:00
|
|
|
#if 0
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x0c:
|
|
|
|
ret = s->dr;
|
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
2008-12-08 01:46:49 +03:00
|
|
|
#endif
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x1c:
|
2008-12-08 01:46:49 +03:00
|
|
|
s->sptr = val & 0x8f;
|
|
|
|
return;
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"%s: unsupported write to 0x%02" HWADDR_PRIx "\n",
|
|
|
|
__func__, offs);
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t sh_serial_read(void *opaque, hwaddr offs,
|
2011-11-17 17:23:02 +04:00
|
|
|
unsigned size)
|
2007-09-29 23:43:54 +04:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
SHSerialState *s = opaque;
|
2021-10-30 00:02:09 +03:00
|
|
|
uint32_t ret = UINT32_MAX;
|
2007-09-29 23:43:54 +04:00
|
|
|
|
|
|
|
#if 0
|
2021-10-30 00:02:09 +03:00
|
|
|
switch (offs) {
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x00:
|
|
|
|
ret = s->smr;
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
ret = s->brr;
|
2018-12-14 01:37:37 +03:00
|
|
|
break;
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x08:
|
|
|
|
ret = s->scr;
|
|
|
|
break;
|
|
|
|
case 0x14:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (s->feat & SH_SERIAL_FEAT_SCIF) {
|
2021-10-30 00:02:09 +03:00
|
|
|
switch (offs) {
|
2008-05-09 22:46:04 +04:00
|
|
|
case 0x00: /* SMR */
|
|
|
|
ret = s->smr;
|
|
|
|
break;
|
|
|
|
case 0x08: /* SCR */
|
|
|
|
ret = s->scr;
|
|
|
|
break;
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x10: /* FSR */
|
|
|
|
ret = 0;
|
2021-10-30 00:02:09 +03:00
|
|
|
if (s->flags & SH_SERIAL_FLAG_TEND) {
|
2007-09-29 23:43:54 +04:00
|
|
|
ret |= (1 << 6);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (s->flags & SH_SERIAL_FLAG_TDE) {
|
2007-09-29 23:43:54 +04:00
|
|
|
ret |= (1 << 5);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (s->flags & SH_SERIAL_FLAG_BRK) {
|
2007-09-29 23:43:54 +04:00
|
|
|
ret |= (1 << 4);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (s->flags & SH_SERIAL_FLAG_RDF) {
|
2007-09-29 23:43:54 +04:00
|
|
|
ret |= (1 << 1);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (s->flags & SH_SERIAL_FLAG_DR) {
|
2007-09-29 23:43:54 +04:00
|
|
|
ret |= (1 << 0);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (s->scr & (1 << 5)) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->flags |= SH_SERIAL_FLAG_TDE | SH_SERIAL_FLAG_TEND;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
|
2008-09-15 11:05:18 +04:00
|
|
|
break;
|
|
|
|
case 0x14:
|
|
|
|
if (s->rx_cnt > 0) {
|
|
|
|
ret = s->rx_fifo[s->rx_tail++];
|
|
|
|
s->rx_cnt--;
|
2021-10-30 00:02:09 +03:00
|
|
|
if (s->rx_tail == SH_RX_FIFO_LENGTH) {
|
2008-09-15 11:05:18 +04:00
|
|
|
s->rx_tail = 0;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
if (s->rx_cnt < s->rtrg) {
|
2008-09-15 11:05:18 +04:00
|
|
|
s->flags &= ~SH_SERIAL_FLAG_RDF;
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2008-09-15 11:05:18 +04:00
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
break;
|
|
|
|
case 0x18:
|
|
|
|
ret = s->fcr;
|
|
|
|
break;
|
|
|
|
case 0x1c:
|
|
|
|
ret = s->rx_cnt;
|
|
|
|
break;
|
|
|
|
case 0x20:
|
|
|
|
ret = s->sptr;
|
|
|
|
break;
|
|
|
|
case 0x24:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
} else {
|
|
|
|
switch (offs) {
|
2008-12-08 01:46:49 +03:00
|
|
|
#if 0
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x0c:
|
|
|
|
ret = s->dr;
|
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
ret = 0;
|
|
|
|
break;
|
2008-09-15 11:05:18 +04:00
|
|
|
case 0x14:
|
|
|
|
ret = s->rx_fifo[0];
|
|
|
|
break;
|
2008-12-08 01:46:49 +03:00
|
|
|
#endif
|
2007-09-29 23:43:54 +04:00
|
|
|
case 0x1c:
|
|
|
|
ret = s->sptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-10-30 00:02:09 +03:00
|
|
|
trace_sh_serial_read(size, offs, ret);
|
2007-09-29 23:43:54 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (ret > UINT16_MAX) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"%s: unsupported read from 0x%02" HWADDR_PRIx "\n",
|
|
|
|
__func__, offs);
|
|
|
|
ret = 0;
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
static int sh_serial_can_receive(SHSerialState *s)
|
2007-09-29 23:43:54 +04:00
|
|
|
{
|
2008-09-15 11:05:18 +04:00
|
|
|
return s->scr & (1 << 4);
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
static void sh_serial_receive_break(SHSerialState *s)
|
2007-09-29 23:43:54 +04:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
if (s->feat & SH_SERIAL_FEAT_SCIF) {
|
2008-09-15 11:05:18 +04:00
|
|
|
s->sr |= (1 << 4);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_can_receive1(void *opaque)
|
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
SHSerialState *s = opaque;
|
2007-09-29 23:43:54 +04:00
|
|
|
return sh_serial_can_receive(s);
|
|
|
|
}
|
|
|
|
|
2018-09-05 16:11:25 +03:00
|
|
|
static void sh_serial_timeout_int(void *opaque)
|
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
SHSerialState *s = opaque;
|
2018-09-05 16:11:25 +03:00
|
|
|
|
|
|
|
s->flags |= SH_SERIAL_FLAG_RDF;
|
|
|
|
if (s->scr & (1 << 6) && s->rxi) {
|
|
|
|
qemu_set_irq(s->rxi, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-29 23:43:54 +04:00
|
|
|
static void sh_serial_receive1(void *opaque, const uint8_t *buf, int size)
|
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
SHSerialState *s = opaque;
|
2011-01-19 13:38:36 +03:00
|
|
|
|
|
|
|
if (s->feat & SH_SERIAL_FEAT_SCIF) {
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
if (s->rx_cnt < SH_RX_FIFO_LENGTH) {
|
|
|
|
s->rx_fifo[s->rx_head++] = buf[i];
|
|
|
|
if (s->rx_head == SH_RX_FIFO_LENGTH) {
|
|
|
|
s->rx_head = 0;
|
|
|
|
}
|
|
|
|
s->rx_cnt++;
|
|
|
|
if (s->rx_cnt >= s->rtrg) {
|
|
|
|
s->flags |= SH_SERIAL_FLAG_RDF;
|
|
|
|
if (s->scr & (1 << 6) && s->rxi) {
|
2021-10-30 00:02:09 +03:00
|
|
|
timer_del(&s->fifo_timeout_timer);
|
2011-01-19 13:38:36 +03:00
|
|
|
qemu_set_irq(s->rxi, 1);
|
|
|
|
}
|
2018-09-05 16:11:25 +03:00
|
|
|
} else {
|
2021-10-30 00:02:09 +03:00
|
|
|
timer_mod(&s->fifo_timeout_timer,
|
2018-09-05 16:11:25 +03:00
|
|
|
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 15 * s->etu);
|
2011-01-19 13:38:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s->rx_fifo[0] = buf[0];
|
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|
|
|
|
|
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 sh_serial_event(void *opaque, QEMUChrEvent event)
|
2007-09-29 23:43:54 +04:00
|
|
|
{
|
2021-10-30 00:02:09 +03:00
|
|
|
SHSerialState *s = opaque;
|
2021-10-30 00:02:09 +03:00
|
|
|
if (event == CHR_EVENT_BREAK) {
|
2007-09-29 23:43:54 +04:00
|
|
|
sh_serial_receive_break(s);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|
|
|
|
|
2011-11-17 17:23:02 +04:00
|
|
|
static const MemoryRegionOps sh_serial_ops = {
|
|
|
|
.read = sh_serial_read,
|
|
|
|
.write = sh_serial_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2007-09-29 23:43:54 +04:00
|
|
|
};
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
static void sh_serial_reset(SHSerialState *s)
|
2007-09-29 23:43:54 +04:00
|
|
|
{
|
|
|
|
s->flags = SH_SERIAL_FLAG_TEND | SH_SERIAL_FLAG_TDE;
|
2008-09-15 11:05:18 +04:00
|
|
|
s->rtrg = 1;
|
2007-09-29 23:43:54 +04:00
|
|
|
|
|
|
|
s->smr = 0;
|
|
|
|
s->brr = 0xff;
|
2007-12-12 03:40:24 +03:00
|
|
|
s->scr = 1 << 5; /* pretend that TX is enabled so early printk works */
|
2007-09-29 23:43:54 +04:00
|
|
|
s->sptr = 0;
|
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
if (s->feat & SH_SERIAL_FEAT_SCIF) {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->fcr = 0;
|
2021-10-30 00:02:09 +03:00
|
|
|
} else {
|
2007-09-29 23:43:54 +04:00
|
|
|
s->dr = 0xff;
|
|
|
|
}
|
|
|
|
|
2008-09-15 11:05:18 +04:00
|
|
|
sh_serial_clear_fifo(s);
|
2021-10-30 00:02:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void sh_serial_init(MemoryRegion *sysmem,
|
|
|
|
hwaddr base, int feat,
|
|
|
|
uint32_t freq, Chardev *chr,
|
|
|
|
qemu_irq eri_source,
|
|
|
|
qemu_irq rxi_source,
|
|
|
|
qemu_irq txi_source,
|
|
|
|
qemu_irq tei_source,
|
|
|
|
qemu_irq bri_source)
|
|
|
|
{
|
|
|
|
SHSerialState *s = g_malloc0(sizeof(*s));
|
|
|
|
|
|
|
|
s->feat = feat;
|
|
|
|
sh_serial_reset(s);
|
2007-09-29 23:43:54 +04:00
|
|
|
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(&s->iomem, NULL, &sh_serial_ops, s,
|
2011-11-17 17:23:02 +04:00
|
|
|
"serial", 0x100000000ULL);
|
|
|
|
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_alias(&s->iomem_p4, NULL, "serial-p4", &s->iomem,
|
2011-11-17 17:23:02 +04:00
|
|
|
0, 0x28);
|
|
|
|
memory_region_add_subregion(sysmem, P4ADDR(base), &s->iomem_p4);
|
|
|
|
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_alias(&s->iomem_a7, NULL, "serial-a7", &s->iomem,
|
2011-11-17 17:23:02 +04:00
|
|
|
0, 0x28);
|
|
|
|
memory_region_add_subregion(sysmem, A7ADDR(base), &s->iomem_a7);
|
2007-09-29 23:43:54 +04:00
|
|
|
|
2013-03-27 23:29:40 +04:00
|
|
|
if (chr) {
|
2016-10-22 12:52:52 +03:00
|
|
|
qemu_chr_fe_init(&s->chr, chr, &error_abort);
|
2016-10-22 12:52:55 +03:00
|
|
|
qemu_chr_fe_set_handlers(&s->chr, sh_serial_can_receive1,
|
|
|
|
sh_serial_receive1,
|
2017-07-06 15:08:49 +03:00
|
|
|
sh_serial_event, NULL, s, NULL, true);
|
2013-03-27 23:29:40 +04:00
|
|
|
}
|
2008-05-09 22:46:04 +04:00
|
|
|
|
2021-10-30 00:02:09 +03:00
|
|
|
timer_init_ns(&s->fifo_timeout_timer, QEMU_CLOCK_VIRTUAL,
|
|
|
|
sh_serial_timeout_int, s);
|
2018-09-05 16:11:25 +03:00
|
|
|
s->etu = NANOSECONDS_PER_SECOND / 9600;
|
2008-05-09 22:46:04 +04:00
|
|
|
s->eri = eri_source;
|
|
|
|
s->rxi = rxi_source;
|
|
|
|
s->txi = txi_source;
|
|
|
|
s->tei = tei_source;
|
|
|
|
s->bri = bri_source;
|
2007-09-29 23:43:54 +04:00
|
|
|
}
|