xref: /openbmc/qemu/hw/arm/exynos4_boards.c (revision 795c40b8)
1 /*
2  *  Samsung exynos4 SoC based boards emulation
3  *
4  *  Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *    Maksim Kozlov <m.kozlov@samsung.com>
6  *    Evgeny Voevodin <e.voevodin@samsung.com>
7  *    Igor Mitsyanko  <i.mitsyanko@samsung.com>
8  *
9  *  This program is free software; you can redistribute it and/or modify it
10  *  under the terms of the GNU General Public License as published by the
11  *  Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful, but WITHOUT
15  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17  *  for more details.
18  *
19  *  You should have received a copy of the GNU General Public License along
20  *  with this program; if not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23 
24 #include "qemu/osdep.h"
25 #include "qemu/error-report.h"
26 #include "qemu-common.h"
27 #include "cpu.h"
28 #include "sysemu/sysemu.h"
29 #include "sysemu/qtest.h"
30 #include "hw/sysbus.h"
31 #include "net/net.h"
32 #include "hw/arm/arm.h"
33 #include "exec/address-spaces.h"
34 #include "hw/arm/exynos4210.h"
35 #include "hw/boards.h"
36 
37 #undef DEBUG
38 
39 //#define DEBUG
40 
41 #ifdef DEBUG
42     #undef PRINT_DEBUG
43     #define  PRINT_DEBUG(fmt, args...) \
44         do { \
45             fprintf(stderr, "  [%s:%d]   "fmt, __func__, __LINE__, ##args); \
46         } while (0)
47 #else
48     #define  PRINT_DEBUG(fmt, args...)  do {} while (0)
49 #endif
50 
51 #define SMDK_LAN9118_BASE_ADDR      0x05000000
52 
53 typedef enum Exynos4BoardType {
54     EXYNOS4_BOARD_NURI,
55     EXYNOS4_BOARD_SMDKC210,
56     EXYNOS4_NUM_OF_BOARDS
57 } Exynos4BoardType;
58 
59 static int exynos4_board_id[EXYNOS4_NUM_OF_BOARDS] = {
60     [EXYNOS4_BOARD_NURI]     = 0xD33,
61     [EXYNOS4_BOARD_SMDKC210] = 0xB16,
62 };
63 
64 static int exynos4_board_smp_bootreg_addr[EXYNOS4_NUM_OF_BOARDS] = {
65     [EXYNOS4_BOARD_NURI]     = EXYNOS4210_SECOND_CPU_BOOTREG,
66     [EXYNOS4_BOARD_SMDKC210] = EXYNOS4210_SECOND_CPU_BOOTREG,
67 };
68 
69 static unsigned long exynos4_board_ram_size[EXYNOS4_NUM_OF_BOARDS] = {
70     [EXYNOS4_BOARD_NURI]     = 0x40000000,
71     [EXYNOS4_BOARD_SMDKC210] = 0x40000000,
72 };
73 
74 static struct arm_boot_info exynos4_board_binfo = {
75     .loader_start     = EXYNOS4210_BASE_BOOT_ADDR,
76     .smp_loader_start = EXYNOS4210_SMP_BOOT_ADDR,
77     .nb_cpus          = EXYNOS4210_NCPUS,
78     .write_secondary_boot = exynos4210_write_secondary,
79 };
80 
81 static void lan9215_init(uint32_t base, qemu_irq irq)
82 {
83     DeviceState *dev;
84     SysBusDevice *s;
85 
86     /* This should be a 9215 but the 9118 is close enough */
87     if (nd_table[0].used) {
88         qemu_check_nic_model(&nd_table[0], "lan9118");
89         dev = qdev_create(NULL, "lan9118");
90         qdev_set_nic_properties(dev, &nd_table[0]);
91         qdev_prop_set_uint32(dev, "mode_16bit", 1);
92         qdev_init_nofail(dev);
93         s = SYS_BUS_DEVICE(dev);
94         sysbus_mmio_map(s, 0, base);
95         sysbus_connect_irq(s, 0, irq);
96     }
97 }
98 
99 static Exynos4210State *exynos4_boards_init_common(MachineState *machine,
100                                                    Exynos4BoardType board_type)
101 {
102     MachineClass *mc = MACHINE_GET_CLASS(machine);
103 
104     if (smp_cpus != EXYNOS4210_NCPUS && !qtest_enabled()) {
105         error_report("%s board supports only %d CPU cores, ignoring smp_cpus"
106                      " value",
107                      mc->name, EXYNOS4210_NCPUS);
108     }
109 
110     exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type];
111     exynos4_board_binfo.board_id = exynos4_board_id[board_type];
112     exynos4_board_binfo.smp_bootreg_addr =
113             exynos4_board_smp_bootreg_addr[board_type];
114     exynos4_board_binfo.kernel_filename = machine->kernel_filename;
115     exynos4_board_binfo.initrd_filename = machine->initrd_filename;
116     exynos4_board_binfo.kernel_cmdline = machine->kernel_cmdline;
117     exynos4_board_binfo.gic_cpu_if_addr =
118             EXYNOS4210_SMP_PRIVATE_BASE_ADDR + 0x100;
119 
120     PRINT_DEBUG("\n ram_size: %luMiB [0x%08lx]\n"
121             " kernel_filename: %s\n"
122             " kernel_cmdline: %s\n"
123             " initrd_filename: %s\n",
124             exynos4_board_ram_size[board_type] / 1048576,
125             exynos4_board_ram_size[board_type],
126             machine->kernel_filename,
127             machine->kernel_cmdline,
128             machine->initrd_filename);
129 
130     return exynos4210_init(get_system_memory(),
131             exynos4_board_ram_size[board_type]);
132 }
133 
134 static void nuri_init(MachineState *machine)
135 {
136     exynos4_boards_init_common(machine, EXYNOS4_BOARD_NURI);
137 
138     arm_load_kernel(ARM_CPU(first_cpu), &exynos4_board_binfo);
139 }
140 
141 static void smdkc210_init(MachineState *machine)
142 {
143     Exynos4210State *s = exynos4_boards_init_common(machine,
144                                                     EXYNOS4_BOARD_SMDKC210);
145 
146     lan9215_init(SMDK_LAN9118_BASE_ADDR,
147             qemu_irq_invert(s->irq_table[exynos4210_get_irq(37, 1)]));
148     arm_load_kernel(ARM_CPU(first_cpu), &exynos4_board_binfo);
149 }
150 
151 static void nuri_class_init(ObjectClass *oc, void *data)
152 {
153     MachineClass *mc = MACHINE_CLASS(oc);
154 
155     mc->desc = "Samsung NURI board (Exynos4210)";
156     mc->init = nuri_init;
157     mc->max_cpus = EXYNOS4210_NCPUS;
158 }
159 
160 static const TypeInfo nuri_type = {
161     .name = MACHINE_TYPE_NAME("nuri"),
162     .parent = TYPE_MACHINE,
163     .class_init = nuri_class_init,
164 };
165 
166 static void smdkc210_class_init(ObjectClass *oc, void *data)
167 {
168     MachineClass *mc = MACHINE_CLASS(oc);
169 
170     mc->desc = "Samsung SMDKC210 board (Exynos4210)";
171     mc->init = smdkc210_init;
172     mc->max_cpus = EXYNOS4210_NCPUS;
173 }
174 
175 static const TypeInfo smdkc210_type = {
176     .name = MACHINE_TYPE_NAME("smdkc210"),
177     .parent = TYPE_MACHINE,
178     .class_init = smdkc210_class_init,
179 };
180 
181 static void exynos4_machines_init(void)
182 {
183     type_register_static(&nuri_type);
184     type_register_static(&smdkc210_type);
185 }
186 
187 type_init(exynos4_machines_init)
188