Update GitHub action for new Meson based build
[qemu/ar7.git] / hw / arm / smdk2410.c
blob858794e7be7f4dc07ac69fd977fc785c1ea97f49
1 /* hw/smdk2410.c
3 * System emulation for the Samsung SMDK2410
5 * Copyright 2006, 2008 Daniel Silverstone and Vincent Sanders
7 * This file is under the terms of the GNU General Public
8 * License Version 2.
9 */
11 #include "qemu/osdep.h"
12 #include "hw/hw.h"
13 #include "hw/arm/boot.h"
14 #include "hw/boards.h"
15 #include "hw/devices.h"
16 #include "hw/loader.h" /* load_image_targphys */
17 #include "hw/s3c2410x.h"
18 #include "hw/i2c/i2c.h" /* i2c_create_slave */
19 #include "exec/address-spaces.h" /* get_system_memory */
20 #include "sysemu/blockdev.h" /* drive_get */
21 #include "sysemu/sysemu.h"
22 #include "net/net.h"
24 #define BIOS_FILENAME "smdk2410.bin"
26 typedef struct {
27 MemoryRegion flash;
28 S3CState *soc;
29 unsigned char cpld_ctrl2;
30 DeviceState *nand[4];
31 } SMDK2410State;
33 /* Bits in a byte */
34 #define BIT 8
36 /* Useful defines */
37 #define SMDK2410_NOR_BASE CPU_S3C2410X_CS0
38 #define SMDK2410_NOR_SIZE 16 * MiB / BIT
39 #define SMDK2410_BOARD_ID 193
41 static struct arm_boot_info smdk2410_binfo = {
42 .board_id = SMDK2410_BOARD_ID,
43 .ram_size = 0x10000000, /* 256MB */
46 static void smdk2410_init(MachineState *machine)
48 DriveInfo *dinfo;
49 SMDK2410State *stcb;
50 int ret;
52 /* ensure memory is limited to 256MB */
53 if (machine->ram_size > (256 * MiB)) {
54 machine->ram_size = 256 * MiB;
56 ram_size = machine->ram_size;
58 /* allocate storage for board state */
59 stcb = g_new0(SMDK2410State, 1);
61 /* initialise CPU and memory */
62 stcb->soc = s3c2410x_init(ram_size);
64 /* Register the NOR flash ROM */
65 memory_region_init_ram(&stcb->flash, NULL,
66 "smdk2410.flash", SMDK2410_NOR_SIZE);
67 memory_region_set_readonly(&stcb->flash, true);
68 memory_region_add_subregion(get_system_memory(),
69 SMDK2410_NOR_BASE, &stcb->flash);
71 /* initialise board informations */
72 smdk2410_binfo.ram_size = ram_size;
73 smdk2410_binfo.kernel_filename = machine->kernel_filename;
74 smdk2410_binfo.kernel_cmdline = machine->kernel_cmdline;
75 smdk2410_binfo.initrd_filename = machine->initrd_filename;
76 smdk2410_binfo.nb_cpus = 1;
77 smdk2410_binfo.loader_start = SMDK2410_NOR_BASE;
79 if (machine->kernel_filename == NULL) {
80 /* No kernel given so try and acquire a bootloader */
81 char *filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BIOS_FILENAME);
82 if (filename) {
83 ret = load_image_targphys(filename, smdk2410_binfo.loader_start,
84 SMDK2410_NOR_SIZE);
85 if (ret <= 0) {
86 perror("qemu");
87 fprintf(stderr,
88 "qemu: warning, could not load SMDK2410 BIOS from %s\n",
89 filename);
90 exit (1);
92 fprintf(stdout,
93 "qemu: info, loaded SMDK2410 BIOS %d bytes from %s\n",
94 ret, filename);
95 g_free(filename);
96 } else {
97 perror("qemu");
98 fprintf(stderr,
99 "qemu: warning, could not load SMDK2410 BIOS from %s\n",
100 BIOS_FILENAME);
101 exit(1);
103 } else {
104 smdk2410_binfo.loader_start = CPU_S3C2410X_DRAM;
105 arm_load_kernel(stcb->soc->cpu, &smdk2410_binfo);
108 /* Setup initial (reset) program counter */
109 stcb->soc->cpu->env.regs[15] = smdk2410_binfo.loader_start;
111 /* Attach some NAND devices */
112 stcb->nand[0] = NULL;
113 stcb->nand[1] = NULL;
114 dinfo = drive_get(IF_MTD, 0, 0);
115 if (!dinfo) {
116 stcb->nand[2] = NULL;
117 } else {
118 stcb->nand[2] = nand_init(NULL, 0xEC, 0x79); /* 128MiB small-page */
122 static void smdk2410_machine_init(MachineClass *mc)
124 mc->desc = "Samsung SMDK2410 (S3C2410A, ARM920T)";
125 mc->init = smdk2410_init;
126 mc->max_cpus = 1;
129 DEFINE_MACHINE("smdk2410", smdk2410_machine_init)