From: Michael Walle <michael@walle.cc>
To: qemu-devel@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>,
"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
Michael Walle <michael@walle.cc>, Alexander Graf <agraf@suse.de>,
Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH 11/17] lm32: system control model
Date: Thu, 17 Feb 2011 23:45:12 +0100 [thread overview]
Message-ID: <1297982718-21865-12-git-send-email-michael@walle.cc> (raw)
In-Reply-To: <1297982718-21865-1-git-send-email-michael@walle.cc>
This patch add support for a system control block. It is supposed to
act as helper for the emulated program. E.g. shutting down the VM or
printing test results. This model is intended for testing purposes only and
doesn't fit to any real hardware. Therefore, it is not added to any board
by default. Instead a user has to add it explicitly with the '-device'
commandline parameter.
Signed-off-by: Michael Walle <michael@walle.cc>
---
Makefile.target | 1 +
hw/lm32_sys.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
trace-events | 3 +
3 files changed, 165 insertions(+), 0 deletions(-)
create mode 100644 hw/lm32_sys.c
diff --git a/Makefile.target b/Makefile.target
index 91dbf88..00eda77 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -252,6 +252,7 @@ obj-lm32-y += lm32_pic.o
obj-lm32-y += lm32_juart.o
obj-lm32-y += lm32_timer.o
obj-lm32-y += lm32_uart.o
+obj-lm32-y += lm32_sys.o
obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
obj-mips-y += mips_addr.o mips_timer.o mips_int.o
diff --git a/hw/lm32_sys.c b/hw/lm32_sys.c
new file mode 100644
index 0000000..427b05f
--- /dev/null
+++ b/hw/lm32_sys.c
@@ -0,0 +1,161 @@
+/*
+ * QEMU model of the LatticeMico32 system control block.
+ *
+ * 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/>.
+ */
+
+/*
+ * This model is mainly intended for testing purposes and doesn't fit to any
+ * real hardware. On the one hand it provides a control register (R_CTRL) on
+ * the other hand it supports the lm32 tests.
+ *
+ * A write to the control register causes a system shutdown.
+ * Tests first write the pointer to a test name to the test name register
+ * (R_TESTNAME) and then write a zero to the pass/fail register (R_PASSFAIL) if
+ * the test is passed or any non-zero value to it if the test is failed.
+ */
+
+#include "hw.h"
+#include "sysbus.h"
+#include "trace.h"
+#include "qemu-log.h"
+#include "qemu-error.h"
+#include "sysemu.h"
+#include "qemu-log.h"
+
+enum {
+ R_CTRL = 0,
+ R_PASSFAIL,
+ R_TESTNAME,
+ R_MAX
+};
+
+#define MAX_TESTNAME_LEN 16
+
+struct LM32SysState {
+ SysBusDevice busdev;
+ uint32_t base;
+ uint32_t regs[R_MAX];
+ uint8_t testname[MAX_TESTNAME_LEN];
+};
+typedef struct LM32SysState LM32SysState;
+
+static void copy_testname(LM32SysState *s)
+{
+ cpu_physical_memory_read(s->regs[R_TESTNAME], s->testname,
+ MAX_TESTNAME_LEN);
+ s->testname[MAX_TESTNAME_LEN - 1] = '\0';
+}
+
+static void sys_write(void *opaque, target_phys_addr_t addr, uint32_t value)
+{
+ LM32SysState *s = opaque;
+ char *testname;
+
+ trace_lm32_sys_memory_write(addr, value);
+
+ addr >>= 2;
+ switch (addr) {
+ case R_CTRL:
+ qemu_system_shutdown_request();
+ break;
+ case R_PASSFAIL:
+ s->regs[addr] = value;
+ testname = (char *)s->testname;
+ qemu_log("TC %-16s %s\n", testname, (value) ? "FAILED" : "OK");
+ break;
+ case R_TESTNAME:
+ s->regs[addr] = value;
+ copy_testname(s);
+ break;
+
+ default:
+ error_report("lm32_sys: write access to unkown register 0x"
+ TARGET_FMT_plx, addr << 2);
+ break;
+ }
+}
+
+static CPUReadMemoryFunc * const sys_read_fn[] = {
+ NULL,
+ NULL,
+ NULL,
+};
+
+static CPUWriteMemoryFunc * const sys_write_fn[] = {
+ NULL,
+ NULL,
+ &sys_write,
+};
+
+static void sys_reset(DeviceState *d)
+{
+ LM32SysState *s = container_of(d, LM32SysState, busdev.qdev);
+ int i;
+
+ for (i = 0; i < R_MAX; i++) {
+ s->regs[i] = 0;
+ }
+ memset(s->testname, 0, MAX_TESTNAME_LEN);
+}
+
+static int lm32_sys_init(SysBusDevice *dev)
+{
+ LM32SysState *s = FROM_SYSBUS(typeof(*s), dev);
+ int sys_regs;
+
+ sys_regs = cpu_register_io_memory(sys_read_fn, sys_write_fn, s,
+ DEVICE_NATIVE_ENDIAN);
+ sysbus_init_mmio(dev, R_MAX * 4, sys_regs);
+
+ /* Note: This device is not created in the board initialization,
+ * instead it has to be added with the -device parameter. Therefore,
+ * the device maps itself. */
+ sysbus_mmio_map(dev, 0, s->base);
+
+ return 0;
+}
+
+static const VMStateDescription vmstate_lm32_sys = {
+ .name = "lm32-sys",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .minimum_version_id_old = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32_ARRAY(regs, LM32SysState, R_MAX),
+ VMSTATE_BUFFER(testname, LM32SysState),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static SysBusDeviceInfo lm32_sys_info = {
+ .init = lm32_sys_init,
+ .qdev.name = "lm32-sys",
+ .qdev.size = sizeof(LM32SysState),
+ .qdev.vmsd = &vmstate_lm32_sys,
+ .qdev.reset = sys_reset,
+ .qdev.props = (Property[]) {
+ DEFINE_PROP_UINT32("base", LM32SysState, base, 0xffff0000),
+ DEFINE_PROP_END_OF_LIST(),
+ }
+};
+
+static void lm32_sys_register(void)
+{
+ sysbus_register_withprop(&lm32_sys_info);
+}
+
+device_init(lm32_sys_register)
diff --git a/trace-events b/trace-events
index 90bbbc1..c791719 100644
--- a/trace-events
+++ b/trace-events
@@ -280,3 +280,6 @@ disable lm32_timer_irq_state(int level) "irq state %d"
disable lm32_uart_memory_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x"
disable lm32_uart_memory_read(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x"
disable lm32_uart_irq_state(int level) "irq state %d"
+
+# hw/lm32_sys.c
+disable lm32_sys_memory_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x"
--
1.7.2.3
next prev parent reply other threads:[~2011-02-17 22:46 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-17 22:45 [Qemu-devel] [PATCH 00/17 v3] LatticeMico32 target Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 01/17] LatticeMico32 target support Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 02/17] lm32: translation routines Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 03/17] lm32: translation code helper Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 04/17] lm32: machine state loading/saving Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 05/17] lm32: gdbstub support Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 06/17] lm32: interrupt controller model Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 07/17] lm32: juart model Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 08/17] lm32: pic and juart helper functions Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 09/17] lm32: timer model Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 10/17] lm32: uart model Michael Walle
2011-02-17 22:45 ` Michael Walle [this message]
2011-02-17 22:45 ` [Qemu-devel] [PATCH 12/17] lm32: support for creating device tree Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 13/17] lm32: EVR32 and uclinux BSP Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 14/17] lm32: todo and documentation Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 15/17] lm32: opcode testsuite Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 16/17] Add lm32 target to configure Michael Walle
2011-02-17 22:45 ` [Qemu-devel] [PATCH 17/17] MAINTAINERS: add LatticeMico32 maintainer Michael Walle
2011-02-24 23:03 ` [Qemu-devel] [PATCH 00/17 v3] LatticeMico32 target Michael Walle
2011-03-01 21:31 ` Edgar E. Iglesias
2011-03-05 9:55 ` Blue Swirl
2011-03-06 22:47 ` Michael Walle
2011-03-07 13:20 ` Edgar E. Iglesias
2011-03-13 22:36 ` Michael Walle
-- 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 11/17] lm32: system control model Michael Walle
2011-02-11 21:03 ` Blue Swirl
2011-02-11 22:35 ` Michael Walle
2011-02-12 7:54 ` Blue Swirl
2011-01-31 0:30 [Qemu-devel] [PATCH 00/17] LatticeMico32 target Michael Walle
2011-01-31 0:30 ` [Qemu-devel] [PATCH 11/17] lm32: system control 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=1297982718-21865-12-git-send-email-michael@walle.cc \
--to=michael@walle.cc \
--cc=agraf@suse.de \
--cc=blauwirbel@gmail.com \
--cc=edgar.iglesias@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/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).