Fix some compiler warnings related to format strings
[qemu/ar7.git] / hw / arm / s3c24xx_memc.c
blob5634ed83e56d167b0b5262fe7919a065b24e9d4c
1 /* hw/s3c24xx_memc.c
3 * Samsung S3C24XX memory controller emulation.
5 * The SDRAM controller on several S3C SOC is generic, the emulation needs to
6 * be little more than backing the registers.
8 * Copyright 2006, 2007 Daniel Silverstone and Vincent Sanders
10 * Copyright 2010, 2013 Stefan Weil
12 * This file is under the terms of the GNU General Public License Version 2.
15 #include "qemu/osdep.h"
16 #include "cpu.h"
17 #include "hw/hw.h"
18 #include "exec/address-spaces.h" /* get_system_memory */
19 #include "migration/register.h" /* register_savevm_live */
21 #include "s3c24xx.h"
23 /* Memory controller state */
24 struct s3c24xx_memc_state_s {
25 MemoryRegion mmio;
26 uint32_t memc_reg[13];
29 static void s3c24xx_memc_write(void *opaque, hwaddr addr_,
30 uint64_t value, unsigned size)
32 struct s3c24xx_memc_state_s *s = opaque;
33 int addr = (addr_ & 0x3f) >> 2;
35 if (addr < 0 || addr > 12)
36 addr = 12;
38 s->memc_reg[addr] = value;
41 static uint64_t s3c24xx_memc_read(void *opaque, hwaddr addr_,
42 unsigned size)
44 struct s3c24xx_memc_state_s *s = opaque;
45 int addr = (addr_ & 0x3f) >> 2;
47 if (addr < 0 || addr > 12)
48 addr = 12;
50 return s->memc_reg[addr];
53 static const MemoryRegionOps s3c24xx_memc_ops = {
54 .read = s3c24xx_memc_read,
55 .write = s3c24xx_memc_write,
56 .endianness = DEVICE_NATIVE_ENDIAN,
57 .valid = {
58 .min_access_size = 1,
59 .max_access_size = 4
63 static void s3c24xx_memc_save(QEMUFile *f, void *opaque)
65 struct s3c24xx_memc_state_s *s = opaque;
66 int i;
68 for (i = 0; i < 13; i ++)
69 qemu_put_be32s(f, &s->memc_reg[i]);
72 static int s3c24xx_memc_load(QEMUFile *f, void *opaque, int version_id)
74 struct s3c24xx_memc_state_s *s = opaque;
75 int i;
77 for (i = 0; i < 13; i ++)
78 qemu_get_be32s(f, &s->memc_reg[i]);
80 return 0;
83 static SaveVMHandlers savevm_s3c24xx_memc = {
84 .save_state = s3c24xx_memc_save,
85 .load_state = s3c24xx_memc_load
88 struct s3c24xx_memc_state_s *
89 s3c24xx_memc_init(hwaddr base_addr)
91 /* Memory controller is simple SDRAM control. As SDRAM is emulated and
92 * requires no setup the emulation needs to be nothing more than memory
93 * backing the registers.
95 * There are 13 registers, each 4 bytes.
97 struct s3c24xx_memc_state_s *s = g_new0(struct s3c24xx_memc_state_s, 1);
99 memory_region_init_io(&s->mmio, OBJECT(s), &s3c24xx_memc_ops, s,
100 "s3c24xx.memc", 13 * 4);
101 memory_region_add_subregion(get_system_memory(), base_addr, &s->mmio);
102 register_savevm_live(NULL, "s3c24xx_memc", 0, 0, &savevm_s3c24xx_memc, s);
104 return s;