2011-02-17 23:45:08 +01:00
|
|
|
/*
|
|
|
|
* LatticeMico32 JTAG UART model.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Michael Walle <michael@walle.cc>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2020-10-23 14:44:24 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2011-02-17 23:45:08 +01:00
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:16:57 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2011-02-17 23:45:08 +01:00
|
|
|
#include "trace.h"
|
2017-01-26 15:26:44 +01:00
|
|
|
#include "chardev/char-fe.h"
|
2011-02-17 23:45:08 +01:00
|
|
|
|
2013-07-24 22:49:02 +02:00
|
|
|
#include "hw/char/lm32_juart.h"
|
2019-08-12 07:23:51 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2020-12-11 23:05:12 +01:00
|
|
|
#include "hw/qdev-properties-system.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2011-02-17 23:45:08 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
LM32_JUART_MIN_SAVE_VERSION = 0,
|
|
|
|
LM32_JUART_CURRENT_SAVE_VERSION = 0,
|
|
|
|
LM32_JUART_MAX_SAVE_VERSION = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
JTX_FULL = (1<<8),
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
JRX_FULL = (1<<8),
|
|
|
|
};
|
|
|
|
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(LM32JuartState, LM32_JUART)
|
2013-07-24 22:56:36 +02:00
|
|
|
|
2011-02-17 23:45:08 +01:00
|
|
|
struct LM32JuartState {
|
2013-07-24 22:56:36 +02:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2016-10-22 11:52:51 +02:00
|
|
|
CharBackend chr;
|
2011-02-17 23:45:08 +01:00
|
|
|
|
|
|
|
uint32_t jtx;
|
|
|
|
uint32_t jrx;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t lm32_juart_get_jtx(DeviceState *d)
|
|
|
|
{
|
2013-07-24 22:56:36 +02:00
|
|
|
LM32JuartState *s = LM32_JUART(d);
|
2011-02-17 23:45:08 +01:00
|
|
|
|
|
|
|
trace_lm32_juart_get_jtx(s->jtx);
|
|
|
|
return s->jtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t lm32_juart_get_jrx(DeviceState *d)
|
|
|
|
{
|
2013-07-24 22:56:36 +02:00
|
|
|
LM32JuartState *s = LM32_JUART(d);
|
2011-02-17 23:45:08 +01:00
|
|
|
|
|
|
|
trace_lm32_juart_get_jrx(s->jrx);
|
|
|
|
return s->jrx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lm32_juart_set_jtx(DeviceState *d, uint32_t jtx)
|
|
|
|
{
|
2013-07-24 22:56:36 +02:00
|
|
|
LM32JuartState *s = LM32_JUART(d);
|
2011-02-17 23:45:08 +01:00
|
|
|
unsigned char ch = jtx & 0xff;
|
|
|
|
|
|
|
|
trace_lm32_juart_set_jtx(s->jtx);
|
|
|
|
|
|
|
|
s->jtx = jtx;
|
2016-10-22 11:52:59 +02: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);
|
2011-02-17 23:45:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lm32_juart_set_jrx(DeviceState *d, uint32_t jtx)
|
|
|
|
{
|
2013-07-24 22:56:36 +02:00
|
|
|
LM32JuartState *s = LM32_JUART(d);
|
2011-02-17 23:45:08 +01:00
|
|
|
|
|
|
|
trace_lm32_juart_set_jrx(s->jrx);
|
|
|
|
s->jrx &= ~JRX_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void juart_rx(void *opaque, const uint8_t *buf, int size)
|
|
|
|
{
|
|
|
|
LM32JuartState *s = opaque;
|
|
|
|
|
|
|
|
s->jrx = *buf | JRX_FULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int juart_can_rx(void *opaque)
|
|
|
|
{
|
|
|
|
LM32JuartState *s = opaque;
|
|
|
|
|
|
|
|
return !(s->jrx & JRX_FULL);
|
|
|
|
}
|
|
|
|
|
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 18:20:09 +01:00
|
|
|
static void juart_event(void *opaque, QEMUChrEvent event)
|
2011-02-17 23:45:08 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void juart_reset(DeviceState *d)
|
|
|
|
{
|
2013-07-24 22:56:36 +02:00
|
|
|
LM32JuartState *s = LM32_JUART(d);
|
2011-02-17 23:45:08 +01:00
|
|
|
|
|
|
|
s->jtx = 0;
|
|
|
|
s->jrx = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-25 08:39:02 +02:00
|
|
|
static void lm32_juart_realize(DeviceState *dev, Error **errp)
|
2011-02-17 23:45:08 +01:00
|
|
|
{
|
2013-07-24 22:56:36 +02:00
|
|
|
LM32JuartState *s = LM32_JUART(dev);
|
2011-02-17 23:45:08 +01:00
|
|
|
|
2016-10-22 11:52:59 +02:00
|
|
|
qemu_chr_fe_set_handlers(&s->chr, juart_can_rx, juart_rx,
|
2017-07-06 14:08:49 +02:00
|
|
|
juart_event, NULL, s, NULL, true);
|
2011-02-17 23:45:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_lm32_juart = {
|
|
|
|
.name = "lm32-juart",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
2014-04-16 16:01:33 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2011-02-17 23:45:08 +01:00
|
|
|
VMSTATE_UINT32(jtx, LM32JuartState),
|
|
|
|
VMSTATE_UINT32(jrx, LM32JuartState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-25 08:39:02 +02:00
|
|
|
static Property lm32_juart_properties[] = {
|
|
|
|
DEFINE_PROP_CHR("chardev", LM32JuartState, chr),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void lm32_juart_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->reset = juart_reset;
|
|
|
|
dc->vmsd = &vmstate_lm32_juart;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, lm32_juart_properties);
|
2016-05-25 08:39:02 +02:00
|
|
|
dc->realize = lm32_juart_realize;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo lm32_juart_info = {
|
2013-07-24 22:56:36 +02:00
|
|
|
.name = TYPE_LM32_JUART,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(LM32JuartState),
|
|
|
|
.class_init = lm32_juart_class_init,
|
2011-02-17 23:45:08 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void lm32_juart_register_types(void)
|
2011-02-17 23:45:08 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&lm32_juart_info);
|
2011-02-17 23:45:08 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(lm32_juart_register_types)
|