xref: /qemu/hw/arm/exynos4_boards.c (revision 3e80f6902c13f6edb6675c0f33edcbbf0163ec32)
10caa7113SEvgeny Voevodin /*
20caa7113SEvgeny Voevodin  *  Samsung exynos4 SoC based boards emulation
30caa7113SEvgeny Voevodin  *
40caa7113SEvgeny Voevodin  *  Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
50caa7113SEvgeny Voevodin  *    Maksim Kozlov <m.kozlov@samsung.com>
60caa7113SEvgeny Voevodin  *    Evgeny Voevodin <e.voevodin@samsung.com>
70caa7113SEvgeny Voevodin  *    Igor Mitsyanko  <i.mitsyanko@samsung.com>
80caa7113SEvgeny Voevodin  *
90caa7113SEvgeny Voevodin  *  This program is free software; you can redistribute it and/or modify it
100caa7113SEvgeny Voevodin  *  under the terms of the GNU General Public License as published by the
110caa7113SEvgeny Voevodin  *  Free Software Foundation; either version 2 of the License, or
120caa7113SEvgeny Voevodin  *  (at your option) any later version.
130caa7113SEvgeny Voevodin  *
140caa7113SEvgeny Voevodin  *  This program is distributed in the hope that it will be useful, but WITHOUT
150caa7113SEvgeny Voevodin  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
160caa7113SEvgeny Voevodin  *  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
170caa7113SEvgeny Voevodin  *  for more details.
180caa7113SEvgeny Voevodin  *
190caa7113SEvgeny Voevodin  *  You should have received a copy of the GNU General Public License along
200caa7113SEvgeny Voevodin  *  with this program; if not, see <http://www.gnu.org/licenses/>.
210caa7113SEvgeny Voevodin  *
220caa7113SEvgeny Voevodin  */
230caa7113SEvgeny Voevodin 
2412b16722SPeter Maydell #include "qemu/osdep.h"
25e12a0dd2SPhilippe Mathieu-Daudé #include "qemu/units.h"
26a2f2f624SKrzysztof Kozlowski #include "qapi/error.h"
27f2ad5140SKrzysztof Kozlowski #include "qemu/error-report.h"
284771d756SPaolo Bonzini #include "cpu.h"
299c17d615SPaolo Bonzini #include "sysemu/sysemu.h"
3083c9f4caSPaolo Bonzini #include "hw/sysbus.h"
311422e32dSPaolo Bonzini #include "net/net.h"
3212ec8bd5SPeter Maydell #include "hw/arm/boot.h"
33022c62cbSPaolo Bonzini #include "exec/address-spaces.h"
340d09e41aSPaolo Bonzini #include "hw/arm/exynos4210.h"
3594630665SPhilippe Mathieu-Daudé #include "hw/net/lan9118.h"
36a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h"
3783c9f4caSPaolo Bonzini #include "hw/boards.h"
3864552b6bSMarkus Armbruster #include "hw/irq.h"
390caa7113SEvgeny Voevodin 
402c2c6496SEvgeny Voevodin #define SMDK_LAN9118_BASE_ADDR      0x05000000
412c2c6496SEvgeny Voevodin 
420caa7113SEvgeny Voevodin typedef enum Exynos4BoardType {
430caa7113SEvgeny Voevodin     EXYNOS4_BOARD_NURI,
440caa7113SEvgeny Voevodin     EXYNOS4_BOARD_SMDKC210,
450caa7113SEvgeny Voevodin     EXYNOS4_NUM_OF_BOARDS
460caa7113SEvgeny Voevodin } Exynos4BoardType;
470caa7113SEvgeny Voevodin 
48a2f2f624SKrzysztof Kozlowski typedef struct Exynos4BoardState {
4998e4f4fdSPhilippe Mathieu-Daudé     Exynos4210State soc;
50a2f2f624SKrzysztof Kozlowski     MemoryRegion dram0_mem;
51a2f2f624SKrzysztof Kozlowski     MemoryRegion dram1_mem;
52a2f2f624SKrzysztof Kozlowski } Exynos4BoardState;
53a2f2f624SKrzysztof Kozlowski 
540caa7113SEvgeny Voevodin static int exynos4_board_id[EXYNOS4_NUM_OF_BOARDS] = {
550caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_NURI]     = 0xD33,
560caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_SMDKC210] = 0xB16,
570caa7113SEvgeny Voevodin };
580caa7113SEvgeny Voevodin 
590caa7113SEvgeny Voevodin static int exynos4_board_smp_bootreg_addr[EXYNOS4_NUM_OF_BOARDS] = {
600caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_NURI]     = EXYNOS4210_SECOND_CPU_BOOTREG,
610caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_SMDKC210] = EXYNOS4210_SECOND_CPU_BOOTREG,
620caa7113SEvgeny Voevodin };
630caa7113SEvgeny Voevodin 
640caa7113SEvgeny Voevodin static unsigned long exynos4_board_ram_size[EXYNOS4_NUM_OF_BOARDS] = {
65e12a0dd2SPhilippe Mathieu-Daudé     [EXYNOS4_BOARD_NURI]     = 1 * GiB,
66e12a0dd2SPhilippe Mathieu-Daudé     [EXYNOS4_BOARD_SMDKC210] = 1 * GiB,
670caa7113SEvgeny Voevodin };
680caa7113SEvgeny Voevodin 
690caa7113SEvgeny Voevodin static struct arm_boot_info exynos4_board_binfo = {
700caa7113SEvgeny Voevodin     .loader_start     = EXYNOS4210_BASE_BOOT_ADDR,
710caa7113SEvgeny Voevodin     .smp_loader_start = EXYNOS4210_SMP_BOOT_ADDR,
720caa7113SEvgeny Voevodin     .nb_cpus          = EXYNOS4210_NCPUS,
733f088e36SEvgeny Voevodin     .write_secondary_boot = exynos4210_write_secondary,
740caa7113SEvgeny Voevodin };
750caa7113SEvgeny Voevodin 
762c2c6496SEvgeny Voevodin static void lan9215_init(uint32_t base, qemu_irq irq)
772c2c6496SEvgeny Voevodin {
782c2c6496SEvgeny Voevodin     DeviceState *dev;
792c2c6496SEvgeny Voevodin     SysBusDevice *s;
802c2c6496SEvgeny Voevodin 
812c2c6496SEvgeny Voevodin     /* This should be a 9215 but the 9118 is close enough */
82a005d073SStefan Hajnoczi     if (nd_table[0].used) {
832c2c6496SEvgeny Voevodin         qemu_check_nic_model(&nd_table[0], "lan9118");
84*3e80f690SMarkus Armbruster         dev = qdev_new(TYPE_LAN9118);
852c2c6496SEvgeny Voevodin         qdev_set_nic_properties(dev, &nd_table[0]);
862c2c6496SEvgeny Voevodin         qdev_prop_set_uint32(dev, "mode_16bit", 1);
87*3e80f690SMarkus Armbruster         qdev_realize_and_unref(dev, NULL, &error_fatal);
881356b98dSAndreas Färber         s = SYS_BUS_DEVICE(dev);
892c2c6496SEvgeny Voevodin         sysbus_mmio_map(s, 0, base);
902c2c6496SEvgeny Voevodin         sysbus_connect_irq(s, 0, irq);
912c2c6496SEvgeny Voevodin     }
922c2c6496SEvgeny Voevodin }
932c2c6496SEvgeny Voevodin 
94a2f2f624SKrzysztof Kozlowski static void exynos4_boards_init_ram(Exynos4BoardState *s,
95a2f2f624SKrzysztof Kozlowski                                     MemoryRegion *system_mem,
96a2f2f624SKrzysztof Kozlowski                                     unsigned long ram_size)
97a2f2f624SKrzysztof Kozlowski {
98a2f2f624SKrzysztof Kozlowski     unsigned long mem_size = ram_size;
99a2f2f624SKrzysztof Kozlowski 
100a2f2f624SKrzysztof Kozlowski     if (mem_size > EXYNOS4210_DRAM_MAX_SIZE) {
10198a99ce0SPeter Maydell         memory_region_init_ram(&s->dram1_mem, NULL, "exynos4210.dram1",
102a2f2f624SKrzysztof Kozlowski                                mem_size - EXYNOS4210_DRAM_MAX_SIZE,
103a2f2f624SKrzysztof Kozlowski                                &error_fatal);
104a2f2f624SKrzysztof Kozlowski         memory_region_add_subregion(system_mem, EXYNOS4210_DRAM1_BASE_ADDR,
105a2f2f624SKrzysztof Kozlowski                                     &s->dram1_mem);
106a2f2f624SKrzysztof Kozlowski         mem_size = EXYNOS4210_DRAM_MAX_SIZE;
107a2f2f624SKrzysztof Kozlowski     }
108a2f2f624SKrzysztof Kozlowski 
10998a99ce0SPeter Maydell     memory_region_init_ram(&s->dram0_mem, NULL, "exynos4210.dram0", mem_size,
110a2f2f624SKrzysztof Kozlowski                            &error_fatal);
111a2f2f624SKrzysztof Kozlowski     memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR,
112a2f2f624SKrzysztof Kozlowski                                 &s->dram0_mem);
113a2f2f624SKrzysztof Kozlowski }
114a2f2f624SKrzysztof Kozlowski 
115a2f2f624SKrzysztof Kozlowski static Exynos4BoardState *
116a2f2f624SKrzysztof Kozlowski exynos4_boards_init_common(MachineState *machine,
1170caa7113SEvgeny Voevodin                            Exynos4BoardType board_type)
1180caa7113SEvgeny Voevodin {
119a2f2f624SKrzysztof Kozlowski     Exynos4BoardState *s = g_new(Exynos4BoardState, 1);
1200caa7113SEvgeny Voevodin 
1210caa7113SEvgeny Voevodin     exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type];
1220caa7113SEvgeny Voevodin     exynos4_board_binfo.board_id = exynos4_board_id[board_type];
1230caa7113SEvgeny Voevodin     exynos4_board_binfo.smp_bootreg_addr =
1240caa7113SEvgeny Voevodin             exynos4_board_smp_bootreg_addr[board_type];
12596eacf64SPeter Maydell     exynos4_board_binfo.gic_cpu_if_addr =
12696eacf64SPeter Maydell             EXYNOS4210_SMP_PRIVATE_BASE_ADDR + 0x100;
1270caa7113SEvgeny Voevodin 
128a2f2f624SKrzysztof Kozlowski     exynos4_boards_init_ram(s, get_system_memory(),
1290caa7113SEvgeny Voevodin                             exynos4_board_ram_size[board_type]);
130a2f2f624SKrzysztof Kozlowski 
1315e039af8SPhilippe Mathieu-Daudé     sysbus_init_child_obj(OBJECT(machine), "soc",
1325e039af8SPhilippe Mathieu-Daudé                           &s->soc, sizeof(s->soc), TYPE_EXYNOS4210_SOC);
13398e4f4fdSPhilippe Mathieu-Daudé     object_property_set_bool(OBJECT(&s->soc), true, "realized",
13498e4f4fdSPhilippe Mathieu-Daudé                              &error_fatal);
135a2f2f624SKrzysztof Kozlowski 
136a2f2f624SKrzysztof Kozlowski     return s;
1370caa7113SEvgeny Voevodin }
1380caa7113SEvgeny Voevodin 
1393ef96221SMarcel Apfelbaum static void nuri_init(MachineState *machine)
1400caa7113SEvgeny Voevodin {
1413ef96221SMarcel Apfelbaum     exynos4_boards_init_common(machine, EXYNOS4_BOARD_NURI);
1420caa7113SEvgeny Voevodin 
1432744ece8STao Xu     arm_load_kernel(ARM_CPU(first_cpu), machine, &exynos4_board_binfo);
1440caa7113SEvgeny Voevodin }
1450caa7113SEvgeny Voevodin 
1463ef96221SMarcel Apfelbaum static void smdkc210_init(MachineState *machine)
1470caa7113SEvgeny Voevodin {
148a2f2f624SKrzysztof Kozlowski     Exynos4BoardState *s = exynos4_boards_init_common(machine,
1497f0f7740SPeter Maydell                                                       EXYNOS4_BOARD_SMDKC210);
1500caa7113SEvgeny Voevodin 
1512c2c6496SEvgeny Voevodin     lan9215_init(SMDK_LAN9118_BASE_ADDR,
15298e4f4fdSPhilippe Mathieu-Daudé             qemu_irq_invert(s->soc.irq_table[exynos4210_get_irq(37, 1)]));
1532744ece8STao Xu     arm_load_kernel(ARM_CPU(first_cpu), machine, &exynos4_board_binfo);
1540caa7113SEvgeny Voevodin }
1550caa7113SEvgeny Voevodin 
1568a661aeaSAndreas Färber static void nuri_class_init(ObjectClass *oc, void *data)
1570caa7113SEvgeny Voevodin {
1588a661aeaSAndreas Färber     MachineClass *mc = MACHINE_CLASS(oc);
1598a661aeaSAndreas Färber 
160e264d29dSEduardo Habkost     mc->desc = "Samsung NURI board (Exynos4210)";
161e264d29dSEduardo Habkost     mc->init = nuri_init;
162e264d29dSEduardo Habkost     mc->max_cpus = EXYNOS4210_NCPUS;
16372649619SEmilio G. Cota     mc->min_cpus = EXYNOS4210_NCPUS;
16472649619SEmilio G. Cota     mc->default_cpus = EXYNOS4210_NCPUS;
1654672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
1660caa7113SEvgeny Voevodin }
1670caa7113SEvgeny Voevodin 
1688a661aeaSAndreas Färber static const TypeInfo nuri_type = {
1698a661aeaSAndreas Färber     .name = MACHINE_TYPE_NAME("nuri"),
1708a661aeaSAndreas Färber     .parent = TYPE_MACHINE,
1718a661aeaSAndreas Färber     .class_init = nuri_class_init,
1728a661aeaSAndreas Färber };
173e264d29dSEduardo Habkost 
1748a661aeaSAndreas Färber static void smdkc210_class_init(ObjectClass *oc, void *data)
175e264d29dSEduardo Habkost {
1768a661aeaSAndreas Färber     MachineClass *mc = MACHINE_CLASS(oc);
1778a661aeaSAndreas Färber 
178e264d29dSEduardo Habkost     mc->desc = "Samsung SMDKC210 board (Exynos4210)";
179e264d29dSEduardo Habkost     mc->init = smdkc210_init;
180e264d29dSEduardo Habkost     mc->max_cpus = EXYNOS4210_NCPUS;
18172649619SEmilio G. Cota     mc->min_cpus = EXYNOS4210_NCPUS;
18272649619SEmilio G. Cota     mc->default_cpus = EXYNOS4210_NCPUS;
1834672cbd7SPeter Maydell     mc->ignore_memory_transaction_failures = true;
184e264d29dSEduardo Habkost }
185e264d29dSEduardo Habkost 
1868a661aeaSAndreas Färber static const TypeInfo smdkc210_type = {
1878a661aeaSAndreas Färber     .name = MACHINE_TYPE_NAME("smdkc210"),
1888a661aeaSAndreas Färber     .parent = TYPE_MACHINE,
1898a661aeaSAndreas Färber     .class_init = smdkc210_class_init,
1908a661aeaSAndreas Färber };
1918a661aeaSAndreas Färber 
1928a661aeaSAndreas Färber static void exynos4_machines_init(void)
1938a661aeaSAndreas Färber {
1948a661aeaSAndreas Färber     type_register_static(&nuri_type);
1958a661aeaSAndreas Färber     type_register_static(&smdkc210_type);
1968a661aeaSAndreas Färber }
1978a661aeaSAndreas Färber 
1980e6aac87SEduardo Habkost type_init(exynos4_machines_init)
199