2012-03-05 08:39:13 +04:00
|
|
|
/*
|
|
|
|
* Status and system control registers for Xilinx Zynq Platform
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 Michal Simek <monstr@monstr.eu>
|
|
|
|
* Copyright (c) 2012 PetaLogix Pty Ltd.
|
|
|
|
* Based on hw/arm_sysctl.c, written by Paul Brook
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 21:17:05 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/hw.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/timer.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/sysbus.h"
|
2012-12-17 21:20:04 +04:00
|
|
|
#include "sysemu/sysemu.h"
|
2015-12-15 15:16:16 +03:00
|
|
|
#include "qemu/log.h"
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
#ifndef ZYNQ_SLCR_ERR_DEBUG
|
|
|
|
#define ZYNQ_SLCR_ERR_DEBUG 0
|
|
|
|
#endif
|
|
|
|
|
2012-03-05 08:39:13 +04:00
|
|
|
#define DB_PRINT(...) do { \
|
2014-04-15 22:49:11 +04:00
|
|
|
if (ZYNQ_SLCR_ERR_DEBUG) { \
|
|
|
|
fprintf(stderr, ": %s: ", __func__); \
|
|
|
|
fprintf(stderr, ## __VA_ARGS__); \
|
|
|
|
} \
|
maint: Fix macros with broken 'do/while(0); ' usage
The point of writing a macro embedded in a 'do { ... } while (0)'
loop (particularly if the macro has multiple statements or would
otherwise end with an 'if' statement) is so that the macro can be
used as a drop-in statement with the caller supplying the
trailing ';'. Although our coding style frowns on brace-less 'if':
if (cond)
statement;
else
something else;
that is the classic case where failure to use do/while(0) wrapping
would cause the 'else' to pair with any embedded 'if' in the macro
rather than the intended outer 'if'. But conversely, if the macro
includes an embedded ';', then the same brace-less coding style
would now have two statements, making the 'else' a syntax error
rather than pairing with the outer 'if'. Thus, even though our
coding style with required braces is not impacted, ending a macro
with ';' makes our code harder to port to projects that use
brace-less styles.
The change should have no semantic impact. I was not able to
fully compile-test all of the changes (as some of them are
examples of the ugly bit-rotting debug print statements that are
completely elided by default, and I didn't want to recompile
with the necessary -D witnesses - cleaning those up is left as a
bite-sized task for another day); I did, however, audit that for
all files touched, all callers of the changed macros DID supply
a trailing ';' at the callsite, and did not appear to be used
as part of a brace-less conditional.
Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-Id: <20171201232433.25193-7-eblake@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2017-12-02 02:24:32 +03:00
|
|
|
} while (0)
|
2012-03-05 08:39:13 +04:00
|
|
|
|
|
|
|
#define XILINX_LOCK_KEY 0x767b
|
|
|
|
#define XILINX_UNLOCK_KEY 0xdf0d
|
|
|
|
|
2014-02-05 11:31:55 +04:00
|
|
|
#define R_PSS_RST_CTRL_SOFT_RST 0x1
|
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
enum {
|
|
|
|
SCL = 0x000 / 4,
|
|
|
|
LOCK,
|
|
|
|
UNLOCK,
|
|
|
|
LOCKSTA,
|
|
|
|
|
|
|
|
ARM_PLL_CTRL = 0x100 / 4,
|
|
|
|
DDR_PLL_CTRL,
|
|
|
|
IO_PLL_CTRL,
|
|
|
|
PLL_STATUS,
|
|
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 0xa30 / 4,
|
|
|
|
|
|
|
|
DMAC_RAM = 0xa50 / 4,
|
|
|
|
|
|
|
|
AFI0 = 0xa60 / 4,
|
|
|
|
AFI1 = AFI0 + 3,
|
|
|
|
AFI2 = AFI1 + 3,
|
|
|
|
AFI3 = AFI2 + 3,
|
|
|
|
#define AFI_LENGTH 3
|
|
|
|
|
|
|
|
OCM = 0xa90 / 4,
|
|
|
|
|
|
|
|
DEVCI_RAM = 0xaa0 / 4,
|
|
|
|
|
|
|
|
CSG_RAM = 0xab0 / 4,
|
|
|
|
|
|
|
|
GPIOB_CTRL = 0xb00 / 4,
|
|
|
|
GPIOB_CFG_CMOS18,
|
|
|
|
GPIOB_CFG_CMOS25,
|
|
|
|
GPIOB_CFG_CMOS33,
|
|
|
|
GPIOB_CFG_HSTL = 0xb14 / 4,
|
|
|
|
GPIOB_DRVR_BIAS_CTRL,
|
|
|
|
|
|
|
|
DDRIOB = 0xb40 / 4,
|
|
|
|
#define DDRIOB_LENGTH 14
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ZYNQ_SLCR_MMIO_SIZE 0x1000
|
|
|
|
#define ZYNQ_SLCR_NUM_REGS (ZYNQ_SLCR_MMIO_SIZE / 4)
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2013-07-27 01:29:03 +04:00
|
|
|
#define TYPE_ZYNQ_SLCR "xilinx,zynq_slcr"
|
|
|
|
#define ZYNQ_SLCR(obj) OBJECT_CHECK(ZynqSLCRState, (obj), TYPE_ZYNQ_SLCR)
|
|
|
|
|
|
|
|
typedef struct ZynqSLCRState {
|
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2012-03-05 08:39:13 +04:00
|
|
|
MemoryRegion iomem;
|
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
uint32_t regs[ZYNQ_SLCR_NUM_REGS];
|
2012-03-05 08:39:13 +04:00
|
|
|
} ZynqSLCRState;
|
|
|
|
|
|
|
|
static void zynq_slcr_reset(DeviceState *d)
|
|
|
|
{
|
2013-07-27 01:29:03 +04:00
|
|
|
ZynqSLCRState *s = ZYNQ_SLCR(d);
|
2012-03-05 08:39:13 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
DB_PRINT("RESET\n");
|
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[LOCKSTA] = 1;
|
2012-03-05 08:39:13 +04:00
|
|
|
/* 0x100 - 0x11C */
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[ARM_PLL_CTRL] = 0x0001A008;
|
|
|
|
s->regs[DDR_PLL_CTRL] = 0x0001A008;
|
|
|
|
s->regs[IO_PLL_CTRL] = 0x0001A008;
|
|
|
|
s->regs[PLL_STATUS] = 0x0000003F;
|
|
|
|
s->regs[ARM_PLL_CFG] = 0x00014000;
|
|
|
|
s->regs[DDR_PLL_CFG] = 0x00014000;
|
|
|
|
s->regs[IO_PLL_CFG] = 0x00014000;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
|
|
|
/* 0x120 - 0x16C */
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[ARM_CLK_CTRL] = 0x1F000400;
|
|
|
|
s->regs[DDR_CLK_CTRL] = 0x18400003;
|
|
|
|
s->regs[DCI_CLK_CTRL] = 0x01E03201;
|
|
|
|
s->regs[APER_CLK_CTRL] = 0x01FFCCCD;
|
|
|
|
s->regs[USB0_CLK_CTRL] = s->regs[USB1_CLK_CTRL] = 0x00101941;
|
|
|
|
s->regs[GEM0_RCLK_CTRL] = s->regs[GEM1_RCLK_CTRL] = 0x00000001;
|
|
|
|
s->regs[GEM0_CLK_CTRL] = s->regs[GEM1_CLK_CTRL] = 0x00003C01;
|
|
|
|
s->regs[SMC_CLK_CTRL] = 0x00003C01;
|
|
|
|
s->regs[LQSPI_CLK_CTRL] = 0x00002821;
|
|
|
|
s->regs[SDIO_CLK_CTRL] = 0x00001E03;
|
|
|
|
s->regs[UART_CLK_CTRL] = 0x00003F03;
|
|
|
|
s->regs[SPI_CLK_CTRL] = 0x00003F03;
|
|
|
|
s->regs[CAN_CLK_CTRL] = 0x00501903;
|
|
|
|
s->regs[DBG_CLK_CTRL] = 0x00000F03;
|
|
|
|
s->regs[PCAP_CLK_CTRL] = 0x00000F01;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
|
|
|
/* 0x170 - 0x1AC */
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[FPGA0_CLK_CTRL] = s->regs[FPGA1_CLK_CTRL] = s->regs[FPGA2_CLK_CTRL]
|
|
|
|
= s->regs[FPGA3_CLK_CTRL] = 0x00101800;
|
|
|
|
s->regs[FPGA0_THR_STA] = s->regs[FPGA1_THR_STA] = s->regs[FPGA2_THR_STA]
|
|
|
|
= s->regs[FPGA3_THR_STA] = 0x00010000;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
|
|
|
/* 0x1B0 - 0x1D8 */
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[BANDGAP_TRIP] = 0x0000001F;
|
|
|
|
s->regs[PLL_PREDIVISOR] = 0x00000001;
|
|
|
|
s->regs[CLK_621_TRUE] = 0x00000001;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
|
|
|
/* 0x200 - 0x25C */
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[FPGA_RST_CTRL] = 0x01F33F0F;
|
|
|
|
s->regs[RST_REASON] = 0x00000040;
|
|
|
|
|
|
|
|
s->regs[BOOT_MODE] = 0x00000001;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
|
|
|
/* 0x700 - 0x7D4 */
|
|
|
|
for (i = 0; i < 54; i++) {
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[MIO + i] = 0x00001601;
|
2012-03-05 08:39:13 +04:00
|
|
|
}
|
|
|
|
for (i = 2; i <= 8; i++) {
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[MIO + i] = 0x00000601;
|
2012-03-05 08:39:13 +04:00
|
|
|
}
|
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[MIO_MST_TRI0] = s->regs[MIO_MST_TRI1] = 0xFFFFFFFF;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[CPU_RAM + 0] = s->regs[CPU_RAM + 1] = s->regs[CPU_RAM + 3]
|
|
|
|
= s->regs[CPU_RAM + 4] = s->regs[CPU_RAM + 7]
|
|
|
|
= 0x00010101;
|
|
|
|
s->regs[CPU_RAM + 2] = s->regs[CPU_RAM + 5] = 0x01010101;
|
|
|
|
s->regs[CPU_RAM + 6] = 0x00000001;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[IOU + 0] = s->regs[IOU + 1] = s->regs[IOU + 2] = s->regs[IOU + 3]
|
|
|
|
= 0x09090909;
|
|
|
|
s->regs[IOU + 4] = s->regs[IOU + 5] = 0x00090909;
|
|
|
|
s->regs[IOU + 6] = 0x00000909;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[DMAC_RAM] = 0x00000009;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[AFI0 + 0] = s->regs[AFI0 + 1] = 0x09090909;
|
|
|
|
s->regs[AFI1 + 0] = s->regs[AFI1 + 1] = 0x09090909;
|
|
|
|
s->regs[AFI2 + 0] = s->regs[AFI2 + 1] = 0x09090909;
|
|
|
|
s->regs[AFI3 + 0] = s->regs[AFI3 + 1] = 0x09090909;
|
|
|
|
s->regs[AFI0 + 2] = s->regs[AFI1 + 2] = s->regs[AFI2 + 2]
|
|
|
|
= s->regs[AFI3 + 2] = 0x00000909;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[OCM + 0] = 0x01010101;
|
|
|
|
s->regs[OCM + 1] = s->regs[OCM + 2] = 0x09090909;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[DEVCI_RAM] = 0x00000909;
|
|
|
|
s->regs[CSG_RAM] = 0x00000001;
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[DDRIOB + 0] = s->regs[DDRIOB + 1] = s->regs[DDRIOB + 2]
|
|
|
|
= s->regs[DDRIOB + 3] = 0x00000e00;
|
|
|
|
s->regs[DDRIOB + 4] = s->regs[DDRIOB + 5] = s->regs[DDRIOB + 6]
|
|
|
|
= 0x00000e00;
|
|
|
|
s->regs[DDRIOB + 12] = 0x00000021;
|
2012-03-05 08:39:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
static bool zynq_slcr_check_offset(hwaddr offset, bool rnw)
|
|
|
|
{
|
2012-03-05 08:39:13 +04:00
|
|
|
switch (offset) {
|
2014-04-15 22:49:11 +04:00
|
|
|
case LOCK:
|
|
|
|
case UNLOCK:
|
|
|
|
case DDR_CAL_START:
|
|
|
|
case DDR_REF_START:
|
|
|
|
return !rnw; /* Write only */
|
|
|
|
case LOCKSTA:
|
|
|
|
case FPGA0_THR_STA:
|
|
|
|
case FPGA1_THR_STA:
|
|
|
|
case FPGA2_THR_STA:
|
|
|
|
case FPGA3_THR_STA:
|
|
|
|
case BOOT_MODE:
|
|
|
|
case PSS_IDCODE:
|
|
|
|
case DDR_CMD_STA:
|
|
|
|
case DDR_DFI_STATUS:
|
|
|
|
case PLL_STATUS:
|
|
|
|
return rnw;/* read only */
|
|
|
|
case SCL:
|
|
|
|
case ARM_PLL_CTRL ... IO_PLL_CTRL:
|
|
|
|
case ARM_PLL_CFG ... IO_PLL_CFG:
|
|
|
|
case ARM_CLK_CTRL ... TOPSW_CLK_CTRL:
|
|
|
|
case FPGA0_CLK_CTRL ... FPGA0_THR_CNT:
|
|
|
|
case FPGA1_CLK_CTRL ... FPGA1_THR_CNT:
|
|
|
|
case FPGA2_CLK_CTRL ... FPGA2_THR_CNT:
|
|
|
|
case FPGA3_CLK_CTRL ... FPGA3_THR_CNT:
|
|
|
|
case BANDGAP_TRIP:
|
|
|
|
case PLL_PREDIVISOR:
|
|
|
|
case CLK_621_TRUE:
|
|
|
|
case PSS_RST_CTRL ... A9_CPU_RST_CTRL:
|
|
|
|
case RS_AWDT_CTRL:
|
|
|
|
case RST_REASON:
|
|
|
|
case REBOOT_STATUS:
|
|
|
|
case APU_CTRL:
|
|
|
|
case WDT_CLK_SEL:
|
|
|
|
case TZ_DMA_NS ... TZ_DMA_PERIPH_NS:
|
|
|
|
case DDR_URGENT:
|
|
|
|
case DDR_URGENT_SEL:
|
|
|
|
case MIO ... MIO + MIO_LENGTH - 1:
|
|
|
|
case MIO_LOOPBACK ... MIO_MST_TRI1:
|
|
|
|
case SD0_WP_CD_SEL:
|
|
|
|
case SD1_WP_CD_SEL:
|
|
|
|
case LVL_SHFTR_EN:
|
|
|
|
case OCM_CFG:
|
|
|
|
case CPU_RAM:
|
|
|
|
case IOU:
|
|
|
|
case DMAC_RAM:
|
|
|
|
case AFI0 ... AFI3 + AFI_LENGTH - 1:
|
|
|
|
case OCM:
|
|
|
|
case DEVCI_RAM:
|
|
|
|
case CSG_RAM:
|
|
|
|
case GPIOB_CTRL ... GPIOB_CFG_CMOS33:
|
|
|
|
case GPIOB_CFG_HSTL:
|
|
|
|
case GPIOB_DRVR_BIAS_CTRL:
|
|
|
|
case DDRIOB ... DDRIOB + DDRIOB_LENGTH - 1:
|
|
|
|
return true;
|
2012-03-05 08:39:13 +04:00
|
|
|
default:
|
2014-04-15 22:49:11 +04:00
|
|
|
return false;
|
2012-03-05 08:39:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static uint64_t zynq_slcr_read(void *opaque, hwaddr offset,
|
2012-03-05 08:39:13 +04:00
|
|
|
unsigned size)
|
|
|
|
{
|
2014-04-15 22:49:11 +04:00
|
|
|
ZynqSLCRState *s = opaque;
|
|
|
|
offset /= 4;
|
|
|
|
uint32_t ret = s->regs[offset];
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
if (!zynq_slcr_check_offset(offset, true)) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "zynq_slcr: Invalid read access to "
|
|
|
|
" addr %" HWADDR_PRIx "\n", offset * 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
DB_PRINT("addr: %08" HWADDR_PRIx " data: %08" PRIx32 "\n", offset * 4, ret);
|
2012-03-05 08:39:13 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void zynq_slcr_write(void *opaque, hwaddr offset,
|
2012-03-05 08:39:13 +04:00
|
|
|
uint64_t val, unsigned size)
|
|
|
|
{
|
|
|
|
ZynqSLCRState *s = (ZynqSLCRState *)opaque;
|
2014-04-15 22:49:11 +04:00
|
|
|
offset /= 4;
|
|
|
|
|
|
|
|
DB_PRINT("addr: %08" HWADDR_PRIx " data: %08" PRIx64 "\n", offset * 4, val);
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
if (!zynq_slcr_check_offset(offset, false)) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "zynq_slcr: Invalid write access to "
|
|
|
|
"addr %" HWADDR_PRIx "\n", offset * 4);
|
|
|
|
return;
|
|
|
|
}
|
2012-03-05 08:39:13 +04:00
|
|
|
|
|
|
|
switch (offset) {
|
2014-04-15 22:49:11 +04:00
|
|
|
case SCL:
|
|
|
|
s->regs[SCL] = val & 0x1;
|
|
|
|
return;
|
|
|
|
case LOCK:
|
2012-03-05 08:39:13 +04:00
|
|
|
if ((val & 0xFFFF) == XILINX_LOCK_KEY) {
|
|
|
|
DB_PRINT("XILINX LOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset,
|
|
|
|
(unsigned)val & 0xFFFF);
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[LOCKSTA] = 1;
|
2012-03-05 08:39:13 +04:00
|
|
|
} else {
|
|
|
|
DB_PRINT("WRONG XILINX LOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
|
|
|
|
(int)offset, (unsigned)val & 0xFFFF);
|
|
|
|
}
|
|
|
|
return;
|
2014-04-15 22:49:11 +04:00
|
|
|
case UNLOCK:
|
2012-03-05 08:39:13 +04:00
|
|
|
if ((val & 0xFFFF) == XILINX_UNLOCK_KEY) {
|
|
|
|
DB_PRINT("XILINX UNLOCK 0xF8000000 + 0x%x <= 0x%x\n", (int)offset,
|
|
|
|
(unsigned)val & 0xFFFF);
|
2014-04-15 22:49:11 +04:00
|
|
|
s->regs[LOCKSTA] = 0;
|
2012-03-05 08:39:13 +04:00
|
|
|
} else {
|
|
|
|
DB_PRINT("WRONG XILINX UNLOCK KEY 0xF8000000 + 0x%x <= 0x%x\n",
|
|
|
|
(int)offset, (unsigned)val & 0xFFFF);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-16 13:14:53 +03:00
|
|
|
if (s->regs[LOCKSTA]) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"SCLR registers are locked. Unlock them first\n");
|
2014-04-15 22:49:11 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-10-16 13:14:53 +03:00
|
|
|
s->regs[offset] = val;
|
2014-04-15 22:49:11 +04:00
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case PSS_RST_CTRL:
|
|
|
|
if (val & R_PSS_RST_CTRL_SOFT_RST) {
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2014-04-15 22:49:11 +04:00
|
|
|
}
|
|
|
|
break;
|
2012-03-05 08:39:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps slcr_ops = {
|
|
|
|
.read = zynq_slcr_read,
|
|
|
|
.write = zynq_slcr_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
static void zynq_slcr_init(Object *obj)
|
2012-03-05 08:39:13 +04:00
|
|
|
{
|
2014-04-15 22:49:11 +04:00
|
|
|
ZynqSLCRState *s = ZYNQ_SLCR(obj);
|
2012-03-05 08:39:13 +04:00
|
|
|
|
2014-04-15 22:49:11 +04:00
|
|
|
memory_region_init_io(&s->iomem, obj, &slcr_ops, s, "slcr",
|
2014-04-15 22:49:11 +04:00
|
|
|
ZYNQ_SLCR_MMIO_SIZE);
|
2014-04-15 22:49:11 +04:00
|
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem);
|
2012-03-05 08:39:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_zynq_slcr = {
|
|
|
|
.name = "zynq_slcr",
|
2014-04-15 22:49:11 +04:00
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2014-05-13 19:09:35 +04:00
|
|
|
.fields = (VMStateField[]) {
|
2014-04-15 22:49:11 +04:00
|
|
|
VMSTATE_UINT32_ARRAY(regs, ZynqSLCRState, ZYNQ_SLCR_NUM_REGS),
|
2012-03-05 08:39:13 +04:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void zynq_slcr_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->vmsd = &vmstate_zynq_slcr;
|
|
|
|
dc->reset = zynq_slcr_reset;
|
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo zynq_slcr_info = {
|
2012-03-05 08:39:13 +04:00
|
|
|
.class_init = zynq_slcr_class_init,
|
2013-07-27 01:29:03 +04:00
|
|
|
.name = TYPE_ZYNQ_SLCR,
|
2012-03-05 08:39:13 +04:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(ZynqSLCRState),
|
2014-04-15 22:49:11 +04:00
|
|
|
.instance_init = zynq_slcr_init,
|
2012-03-05 08:39:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void zynq_slcr_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&zynq_slcr_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(zynq_slcr_register_types)
|