From: Michael Walle <michael@walle.cc>
To: qemu-devel@nongnu.org
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
Michael Walle <michael@walle.cc>, Alexander Graf <agraf@suse.de>
Subject: [Qemu-devel] [PATCH 07/17] lm32: juart model
Date: Mon, 31 Jan 2011 01:30:36 +0100 [thread overview]
Message-ID: <1296433846-18097-8-git-send-email-michael@walle.cc> (raw)
In-Reply-To: <1296433846-18097-1-git-send-email-michael@walle.cc>
This patch adds the JTAG UART model. It is accessed through special control
registers and opcodes. Therefore the translation uses callbacks to this
model.
Signed-off-by: Michael Walle <michael@walle.cc>
---
hw/lm32_juart.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/lm32_juart.h | 10 ++++
trace-events | 6 ++
3 files changed, 167 insertions(+), 0 deletions(-)
create mode 100644 hw/lm32_juart.c
create mode 100644 hw/lm32_juart.h
diff --git a/hw/lm32_juart.c b/hw/lm32_juart.c
new file mode 100644
index 0000000..fdeeefd
--- /dev/null
+++ b/hw/lm32_juart.c
@@ -0,0 +1,151 @@
+/*
+ * 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
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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/>.
+ */
+
+#include "hw.h"
+#include "sysbus.h"
+#include "trace.h"
+#include "qemu-char.h"
+
+#include "lm32_juart.h"
+
+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),
+};
+
+struct LM32JuartState {
+ SysBusDevice busdev;
+ CharDriverState *chr;
+
+ uint32_t jtx;
+ uint32_t jrx;
+};
+typedef struct LM32JuartState LM32JuartState;
+
+uint32_t lm32_juart_get_jtx(CPUState *env)
+{
+ LM32JuartState *s = env->juart_env;
+
+ trace_lm32_juart_get_jtx(s->jtx);
+ return s->jtx;
+}
+
+uint32_t lm32_juart_get_jrx(CPUState *env)
+{
+ LM32JuartState *s = env->juart_env;
+
+ trace_lm32_juart_get_jrx(s->jrx);
+ return s->jrx;
+}
+
+void lm32_juart_set_jtx(CPUState *env, uint32_t jtx)
+{
+ LM32JuartState *s = env->juart_env;
+ unsigned char ch = jtx & 0xff;
+
+ trace_lm32_juart_set_jtx(s->jtx);
+
+ s->jtx = jtx;
+ if (s->chr) {
+ qemu_chr_write(s->chr, &ch, 1);
+ }
+}
+
+void lm32_juart_set_jrx(CPUState *env, uint32_t jtx)
+{
+ LM32JuartState *s = env->juart_env;
+
+ trace_lm32_juart_set_jrx(s->jrx);
+ env->juart_env->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);
+}
+
+static void juart_event(void *opaque, int event)
+{
+}
+
+static void juart_reset(void *opaque)
+{
+ LM32JuartState *s = opaque;
+
+ s->jtx = 0;
+ s->jrx = 0;
+}
+
+static int lm32_juart_init(SysBusDevice *dev)
+{
+ LM32JuartState *s = FROM_SYSBUS(typeof(*s), dev);
+
+ s->chr = qdev_init_chardev(&dev->qdev);
+ if (s->chr) {
+ qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s);
+ }
+
+ qemu_register_reset(juart_reset, s);
+
+ return 0;
+}
+
+static const VMStateDescription vmstate_lm32_juart = {
+ .name = "lm32-juart",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32(jtx, LM32JuartState),
+ VMSTATE_UINT32(jrx, LM32JuartState),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static SysBusDeviceInfo lm32_juart_info = {
+ .init = lm32_juart_init,
+ .qdev.name = "lm32-juart",
+ .qdev.size = sizeof(LM32JuartState),
+ .qdev.vmsd = &vmstate_lm32_juart,
+};
+
+static void lm32_juart_register(void)
+{
+ sysbus_register_withprop(&lm32_juart_info);
+}
+
+device_init(lm32_juart_register)
diff --git a/hw/lm32_juart.h b/hw/lm32_juart.h
new file mode 100644
index 0000000..5dc0338
--- /dev/null
+++ b/hw/lm32_juart.h
@@ -0,0 +1,10 @@
+#ifndef __LM32_JUART
+#define __LM32_JUART
+
+#include "qemu-common.h"
+
+uint32_t lm32_juart_get_jtx(CPUState *env);
+uint32_t lm32_juart_get_jrx(CPUState *env);
+void lm32_juart_set_jtx(CPUState *env, uint32_t jtx);
+void lm32_juart_set_jrx(CPUState *env, uint32_t jrx);
+#endif
diff --git a/trace-events b/trace-events
index 377bc25..c82588f 100644
--- a/trace-events
+++ b/trace-events
@@ -222,3 +222,9 @@ disable lm32_pic_set_im(uint32_t im) "im=%08x"
disable lm32_pic_set_ip(uint32_t ip) "ip=%08x"
disable lm32_pic_get_im(uint32_t im) "im=%08x"
disable lm32_pic_get_ip(uint32_t ip) "ip=%08x"
+
+# hw/lm32_juart.c
+disable lm32_juart_get_jtx(uint32_t value) "value=%08x"
+disable lm32_juart_set_jtx(uint32_t value) "value=%08x"
+disable lm32_juart_get_jrx(uint32_t value) "value=%08x"
+disable lm32_juart_set_jrx(uint32_t value) "value=%08x"
--
1.7.2.3
next prev parent reply other threads:[~2011-01-31 0:31 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-31 0:30 [Qemu-devel] [PATCH 00/17] LatticeMico32 target Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 01/17] LatticeMico32 target support Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 02/17] lm32: translation routines Michael Walle
2011-02-07 18:41 ` [Qemu-devel] " Edgar E. Iglesias
2011-02-07 22:00 ` Michael Walle
2011-02-07 22:20 ` Edgar E. Iglesias
2011-02-07 22:55 ` Michael Walle
2011-02-07 23:01 ` Alexander Graf
2011-02-08 17:32 ` [Qemu-devel] " Richard Henderson
2011-02-08 20:00 ` Edgar E. Iglesias
2011-02-08 21:32 ` Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 03/17] lm32: translation code helper Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 04/17] lm32: machine state loading/saving Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 05/17] lm32: gdbstub support Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 06/17] lm32: interrupt controller model Michael Walle
2011-01-31 0:30 ` Michael Walle [this message]
2011-01-31 0:30 ` [Qemu-devel] [PATCH 08/17] lm32: pic and juart helper functions Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 09/17] lm32: timer model Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 10/17] lm32: uart model Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 11/17] lm32: system control model Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 12/17] lm32: support for creating device tree Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 13/17] lm32: EVR32 and uclinux BSP Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 14/17] lm32: todo and documentation Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 15/17] lm32: opcode testsuite Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 16/17] Add lm32 target to configure Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 17/17] MAINTAINERS: add LatticeMico32 maintainer Michael Walle
2011-02-07 16:28 ` [Qemu-devel] Re: [PATCH 00/17] LatticeMico32 target Alexander Graf
-- strict thread matches above, loose matches on Subject: below --
2011-02-10 23:11 [Qemu-devel] [PATCH 00/17 v2] " Michael Walle
2011-02-10 23:12 ` [Qemu-devel] [PATCH 07/17] lm32: juart model Michael Walle
2011-02-11 21:09 ` Blue Swirl
2011-02-17 22:45 [Qemu-devel] [PATCH 00/17 v3] LatticeMico32 target Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 07/17] lm32: juart model Michael Walle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1296433846-18097-8-git-send-email-michael@walle.cc \
--to=michael@walle.cc \
--cc=agraf@suse.de \
--cc=edgar.iglesias@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).