From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 17/39] hw/misc/mps2-fpgaio: FPGA control block for MPS2 AN505
Date: Fri, 2 Mar 2018 11:06:18 +0000 [thread overview]
Message-ID: <20180302110640.28004-18-peter.maydell@linaro.org> (raw)
In-Reply-To: <20180302110640.28004-1-peter.maydell@linaro.org>
The MPS2 AN505 FPGA image includes a "FPGA control block"
which is a small set of registers handling LEDs, buttons
and some counters.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20180220180325.29818-14-peter.maydell@linaro.org
---
hw/misc/Makefile.objs | 1 +
include/hw/misc/mps2-fpgaio.h | 43 ++++++++++
hw/misc/mps2-fpgaio.c | 176 ++++++++++++++++++++++++++++++++++++++++
default-configs/arm-softmmu.mak | 1 +
hw/misc/trace-events | 6 ++
5 files changed, 227 insertions(+)
create mode 100644 include/hw/misc/mps2-fpgaio.h
create mode 100644 hw/misc/mps2-fpgaio.c
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index f33b37a8e5..31f83dcfe7 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -58,6 +58,7 @@ obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
obj-$(CONFIG_MIPS_CPS) += mips_cmgcr.o
obj-$(CONFIG_MIPS_CPS) += mips_cpc.o
obj-$(CONFIG_MIPS_ITU) += mips_itu.o
+obj-$(CONFIG_MPS2_FPGAIO) += mps2-fpgaio.o
obj-$(CONFIG_MPS2_SCC) += mps2-scc.o
obj-$(CONFIG_PVPANIC) += pvpanic.o
diff --git a/include/hw/misc/mps2-fpgaio.h b/include/hw/misc/mps2-fpgaio.h
new file mode 100644
index 0000000000..eedf17ebc6
--- /dev/null
+++ b/include/hw/misc/mps2-fpgaio.h
@@ -0,0 +1,43 @@
+/*
+ * ARM MPS2 FPGAIO emulation
+ *
+ * Copyright (c) 2018 Linaro Limited
+ * Written by Peter Maydell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or
+ * (at your option) any later version.
+ */
+
+/* This is a model of the FPGAIO register block in the AN505
+ * FPGA image for the MPS2 dev board; it is documented in the
+ * application note:
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
+ *
+ * QEMU interface:
+ * + sysbus MMIO region 0: the register bank
+ */
+
+#ifndef MPS2_FPGAIO_H
+#define MPS2_FPGAIO_H
+
+#include "hw/sysbus.h"
+
+#define TYPE_MPS2_FPGAIO "mps2-fpgaio"
+#define MPS2_FPGAIO(obj) OBJECT_CHECK(MPS2FPGAIO, (obj), TYPE_MPS2_FPGAIO)
+
+typedef struct {
+ /*< private >*/
+ SysBusDevice parent_obj;
+
+ /*< public >*/
+ MemoryRegion iomem;
+
+ uint32_t led0;
+ uint32_t prescale;
+ uint32_t misc;
+
+ uint32_t prescale_clk;
+} MPS2FPGAIO;
+
+#endif
diff --git a/hw/misc/mps2-fpgaio.c b/hw/misc/mps2-fpgaio.c
new file mode 100644
index 0000000000..7394a057d8
--- /dev/null
+++ b/hw/misc/mps2-fpgaio.c
@@ -0,0 +1,176 @@
+/*
+ * ARM MPS2 AN505 FPGAIO emulation
+ *
+ * Copyright (c) 2018 Linaro Limited
+ * Written by Peter Maydell
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 or
+ * (at your option) any later version.
+ */
+
+/* This is a model of the "FPGA system control and I/O" block found
+ * in the AN505 FPGA image for the MPS2 devboard.
+ * It is documented in AN505:
+ * http://infocenter.arm.com/help/topic/com.arm.doc.dai0505b/index.html
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qapi/error.h"
+#include "trace.h"
+#include "hw/sysbus.h"
+#include "hw/registerfields.h"
+#include "hw/misc/mps2-fpgaio.h"
+
+REG32(LED0, 0)
+REG32(BUTTON, 8)
+REG32(CLK1HZ, 0x10)
+REG32(CLK100HZ, 0x14)
+REG32(COUNTER, 0x18)
+REG32(PRESCALE, 0x1c)
+REG32(PSCNTR, 0x20)
+REG32(MISC, 0x4c)
+
+static uint64_t mps2_fpgaio_read(void *opaque, hwaddr offset, unsigned size)
+{
+ MPS2FPGAIO *s = MPS2_FPGAIO(opaque);
+ uint64_t r;
+
+ switch (offset) {
+ case A_LED0:
+ r = s->led0;
+ break;
+ case A_BUTTON:
+ /* User-pressable board buttons. We don't model that, so just return
+ * zeroes.
+ */
+ r = 0;
+ break;
+ case A_PRESCALE:
+ r = s->prescale;
+ break;
+ case A_MISC:
+ r = s->misc;
+ break;
+ case A_CLK1HZ:
+ case A_CLK100HZ:
+ case A_COUNTER:
+ case A_PSCNTR:
+ /* These are all upcounters of various frequencies. */
+ qemu_log_mask(LOG_UNIMP, "MPS2 FPGAIO: counters unimplemented\n");
+ r = 0;
+ break;
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "MPS2 FPGAIO read: bad offset %x\n", (int) offset);
+ r = 0;
+ break;
+ }
+
+ trace_mps2_fpgaio_read(offset, r, size);
+ return r;
+}
+
+static void mps2_fpgaio_write(void *opaque, hwaddr offset, uint64_t value,
+ unsigned size)
+{
+ MPS2FPGAIO *s = MPS2_FPGAIO(opaque);
+
+ trace_mps2_fpgaio_write(offset, value, size);
+
+ switch (offset) {
+ case A_LED0:
+ /* LED bits [1:0] control board LEDs. We don't currently have
+ * a mechanism for displaying this graphically, so use a trace event.
+ */
+ trace_mps2_fpgaio_leds(value & 0x02 ? '*' : '.',
+ value & 0x01 ? '*' : '.');
+ s->led0 = value & 0x3;
+ break;
+ case A_PRESCALE:
+ s->prescale = value;
+ break;
+ case A_MISC:
+ /* These are control bits for some of the other devices on the
+ * board (SPI, CLCD, etc). We don't implement that yet, so just
+ * make the bits read as written.
+ */
+ qemu_log_mask(LOG_UNIMP,
+ "MPS2 FPGAIO: MISC control bits unimplemented\n");
+ s->misc = value;
+ break;
+ default:
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "MPS2 FPGAIO write: bad offset 0x%x\n", (int) offset);
+ break;
+ }
+}
+
+static const MemoryRegionOps mps2_fpgaio_ops = {
+ .read = mps2_fpgaio_read,
+ .write = mps2_fpgaio_write,
+ .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
+static void mps2_fpgaio_reset(DeviceState *dev)
+{
+ MPS2FPGAIO *s = MPS2_FPGAIO(dev);
+
+ trace_mps2_fpgaio_reset();
+ s->led0 = 0;
+ s->prescale = 0;
+ s->misc = 0;
+}
+
+static void mps2_fpgaio_init(Object *obj)
+{
+ SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+ MPS2FPGAIO *s = MPS2_FPGAIO(obj);
+
+ memory_region_init_io(&s->iomem, obj, &mps2_fpgaio_ops, s,
+ "mps2-fpgaio", 0x1000);
+ sysbus_init_mmio(sbd, &s->iomem);
+}
+
+static const VMStateDescription mps2_fpgaio_vmstate = {
+ .name = "mps2-fpgaio",
+ .version_id = 1,
+ .minimum_version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_UINT32(led0, MPS2FPGAIO),
+ VMSTATE_UINT32(prescale, MPS2FPGAIO),
+ VMSTATE_UINT32(misc, MPS2FPGAIO),
+ VMSTATE_END_OF_LIST()
+ }
+};
+
+static Property mps2_fpgaio_properties[] = {
+ /* Frequency of the prescale counter */
+ DEFINE_PROP_UINT32("prescale-clk", MPS2FPGAIO, prescale_clk, 20000000),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void mps2_fpgaio_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->vmsd = &mps2_fpgaio_vmstate;
+ dc->reset = mps2_fpgaio_reset;
+ dc->props = mps2_fpgaio_properties;
+}
+
+static const TypeInfo mps2_fpgaio_info = {
+ .name = TYPE_MPS2_FPGAIO,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(MPS2FPGAIO),
+ .instance_init = mps2_fpgaio_init,
+ .class_init = mps2_fpgaio_class_init,
+};
+
+static void mps2_fpgaio_register_types(void)
+{
+ type_register_static(&mps2_fpgaio_info);
+}
+
+type_init(mps2_fpgaio_register_types);
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index 54f855d072..5eaafee394 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -102,6 +102,7 @@ CONFIG_STM32F205_SOC=y
CONFIG_CMSDK_APB_TIMER=y
CONFIG_CMSDK_APB_UART=y
+CONFIG_MPS2_FPGAIO=y
CONFIG_MPS2_SCC=y
CONFIG_VERSATILE_PCI=y
diff --git a/hw/misc/trace-events b/hw/misc/trace-events
index b340d4e81c..ef852ffae7 100644
--- a/hw/misc/trace-events
+++ b/hw/misc/trace-events
@@ -62,6 +62,12 @@ mps2_scc_leds(char led7, char led6, char led5, char led4, char led3, char led2,
mps2_scc_cfg_write(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config write: function %d device %d data 0x%" PRIx32
mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC config read: function %d device %d data 0x%" PRIx32
+# hw/misc/mps2_fpgaio.c
+mps2_fpgaio_read(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
+mps2_fpgaio_write(uint64_t offset, uint64_t data, unsigned size) "MPS2 FPGAIO write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u"
+mps2_fpgaio_reset(void) "MPS2 FPGAIO: reset"
+mps2_fpgaio_leds(char led1, char led0) "MPS2 FPGAIO LEDs: %c%c"
+
# hw/misc/msf2-sysreg.c
msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32
msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32
--
2.16.2
next prev parent reply other threads:[~2018-03-02 11:06 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-02 11:06 [Qemu-devel] [PULL 00/39] target-arm queue Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 01/39] xlnx-zynqmp-rtc: Initial commit Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 02/39] xlnx-zynqmp-rtc: Add basic time support Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 03/39] xlnx-zynqmp: Connect the RTC device Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 04/39] decodetree: Propagate return value from translate subroutines Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 05/39] loader: Add new load_ramdisk_as() Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 06/39] hw/arm/boot: Honour CPU's address space for image loads Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 07/39] hw/arm/armv7m: " Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 08/39] target/arm: Define an IDAU interface Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 09/39] armv7m: Forward idau property to CPU object Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 10/39] target/arm: Define init-svtor property for the reset secure VTOR value Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 11/39] armv7m: Forward init-svtor property to CPU object Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 12/39] target/arm: Add Cortex-M33 Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 13/39] hw/misc/unimp: Move struct to header file Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 14/39] include/hw/or-irq.h: Add missing include guard Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 15/39] qdev: Add new qdev_init_gpio_in_named_with_opaque() Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 16/39] hw/core/split-irq: Device that splits IRQ lines Peter Maydell
2018-03-02 11:06 ` Peter Maydell [this message]
2018-03-02 11:06 ` [Qemu-devel] [PULL 18/39] hw/misc/tz-ppc: Model TrustZone peripheral protection controller Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 19/39] hw/misc/iotkit-secctl: Arm IoT Kit security controller initial skeleton Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 20/39] hw/misc/iotkit-secctl: Add handling for PPCs Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 21/39] hw/misc/iotkit-secctl: Add remaining simple registers Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 22/39] hw/arm/iotkit: Model Arm IOT Kit Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 23/39] mps2-an505: New board model: MPS2 with AN505 Cortex-M33 FPGA image Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 24/39] target/arm: Add ARM_FEATURE_V8_RDM Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 25/39] target/arm: Refactor disas_simd_indexed decode Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 26/39] target/arm: Refactor disas_simd_indexed size checks Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 27/39] target/arm: Decode aa64 armv8.1 scalar three same extra Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 28/39] target/arm: Decode aa64 armv8.1 " Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 29/39] target/arm: Decode aa64 armv8.1 scalar/vector x indexed element Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 30/39] target/arm: Decode aa32 armv8.1 three same Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 31/39] target/arm: Decode aa32 armv8.1 two reg and a scalar Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 32/39] target/arm: Enable ARM_FEATURE_V8_RDM Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 33/39] target/arm: Add ARM_FEATURE_V8_FCMA Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 34/39] target/arm: Decode aa64 armv8.3 fcadd Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 35/39] target/arm: Decode aa64 armv8.3 fcmla Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 36/39] target/arm: Decode aa32 armv8.3 3-same Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 37/39] target/arm: Decode aa32 armv8.3 2-reg-index Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 38/39] target/arm: Decode t32 simd 3reg and 2reg_scalar extension Peter Maydell
2018-03-02 11:06 ` [Qemu-devel] [PULL 39/39] target/arm: Enable ARM_FEATURE_V8_FCMA Peter Maydell
2018-03-02 11:42 ` [Qemu-devel] [PULL 00/39] target-arm queue no-reply
2018-03-02 15:45 ` Peter Maydell
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=20180302110640.28004-18-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--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).