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" 25*a2f2f624SKrzysztof Kozlowski #include "qapi/error.h" 26f2ad5140SKrzysztof Kozlowski #include "qemu/error-report.h" 274771d756SPaolo Bonzini #include "qemu-common.h" 284771d756SPaolo Bonzini #include "cpu.h" 299c17d615SPaolo Bonzini #include "sysemu/sysemu.h" 304bd2f93fSAndreas Färber #include "sysemu/qtest.h" 3183c9f4caSPaolo Bonzini #include "hw/sysbus.h" 321422e32dSPaolo Bonzini #include "net/net.h" 33bd2be150SPeter Maydell #include "hw/arm/arm.h" 34022c62cbSPaolo Bonzini #include "exec/address-spaces.h" 350d09e41aSPaolo Bonzini #include "hw/arm/exynos4210.h" 3683c9f4caSPaolo Bonzini #include "hw/boards.h" 370caa7113SEvgeny Voevodin 380caa7113SEvgeny Voevodin #undef DEBUG 390caa7113SEvgeny Voevodin 400caa7113SEvgeny Voevodin //#define DEBUG 410caa7113SEvgeny Voevodin 420caa7113SEvgeny Voevodin #ifdef DEBUG 430caa7113SEvgeny Voevodin #undef PRINT_DEBUG 440caa7113SEvgeny Voevodin #define PRINT_DEBUG(fmt, args...) \ 450caa7113SEvgeny Voevodin do { \ 460caa7113SEvgeny Voevodin fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ 470caa7113SEvgeny Voevodin } while (0) 480caa7113SEvgeny Voevodin #else 490caa7113SEvgeny Voevodin #define PRINT_DEBUG(fmt, args...) do {} while (0) 500caa7113SEvgeny Voevodin #endif 510caa7113SEvgeny Voevodin 522c2c6496SEvgeny Voevodin #define SMDK_LAN9118_BASE_ADDR 0x05000000 532c2c6496SEvgeny Voevodin 540caa7113SEvgeny Voevodin typedef enum Exynos4BoardType { 550caa7113SEvgeny Voevodin EXYNOS4_BOARD_NURI, 560caa7113SEvgeny Voevodin EXYNOS4_BOARD_SMDKC210, 570caa7113SEvgeny Voevodin EXYNOS4_NUM_OF_BOARDS 580caa7113SEvgeny Voevodin } Exynos4BoardType; 590caa7113SEvgeny Voevodin 60*a2f2f624SKrzysztof Kozlowski typedef struct Exynos4BoardState { 61*a2f2f624SKrzysztof Kozlowski Exynos4210State *soc; 62*a2f2f624SKrzysztof Kozlowski MemoryRegion dram0_mem; 63*a2f2f624SKrzysztof Kozlowski MemoryRegion dram1_mem; 64*a2f2f624SKrzysztof Kozlowski } Exynos4BoardState; 65*a2f2f624SKrzysztof Kozlowski 660caa7113SEvgeny Voevodin static int exynos4_board_id[EXYNOS4_NUM_OF_BOARDS] = { 670caa7113SEvgeny Voevodin [EXYNOS4_BOARD_NURI] = 0xD33, 680caa7113SEvgeny Voevodin [EXYNOS4_BOARD_SMDKC210] = 0xB16, 690caa7113SEvgeny Voevodin }; 700caa7113SEvgeny Voevodin 710caa7113SEvgeny Voevodin static int exynos4_board_smp_bootreg_addr[EXYNOS4_NUM_OF_BOARDS] = { 720caa7113SEvgeny Voevodin [EXYNOS4_BOARD_NURI] = EXYNOS4210_SECOND_CPU_BOOTREG, 730caa7113SEvgeny Voevodin [EXYNOS4_BOARD_SMDKC210] = EXYNOS4210_SECOND_CPU_BOOTREG, 740caa7113SEvgeny Voevodin }; 750caa7113SEvgeny Voevodin 760caa7113SEvgeny Voevodin static unsigned long exynos4_board_ram_size[EXYNOS4_NUM_OF_BOARDS] = { 770caa7113SEvgeny Voevodin [EXYNOS4_BOARD_NURI] = 0x40000000, 780caa7113SEvgeny Voevodin [EXYNOS4_BOARD_SMDKC210] = 0x40000000, 790caa7113SEvgeny Voevodin }; 800caa7113SEvgeny Voevodin 810caa7113SEvgeny Voevodin static struct arm_boot_info exynos4_board_binfo = { 820caa7113SEvgeny Voevodin .loader_start = EXYNOS4210_BASE_BOOT_ADDR, 830caa7113SEvgeny Voevodin .smp_loader_start = EXYNOS4210_SMP_BOOT_ADDR, 840caa7113SEvgeny Voevodin .nb_cpus = EXYNOS4210_NCPUS, 853f088e36SEvgeny Voevodin .write_secondary_boot = exynos4210_write_secondary, 860caa7113SEvgeny Voevodin }; 870caa7113SEvgeny Voevodin 882c2c6496SEvgeny Voevodin static void lan9215_init(uint32_t base, qemu_irq irq) 892c2c6496SEvgeny Voevodin { 902c2c6496SEvgeny Voevodin DeviceState *dev; 912c2c6496SEvgeny Voevodin SysBusDevice *s; 922c2c6496SEvgeny Voevodin 932c2c6496SEvgeny Voevodin /* This should be a 9215 but the 9118 is close enough */ 94a005d073SStefan Hajnoczi if (nd_table[0].used) { 952c2c6496SEvgeny Voevodin qemu_check_nic_model(&nd_table[0], "lan9118"); 962c2c6496SEvgeny Voevodin dev = qdev_create(NULL, "lan9118"); 972c2c6496SEvgeny Voevodin qdev_set_nic_properties(dev, &nd_table[0]); 982c2c6496SEvgeny Voevodin qdev_prop_set_uint32(dev, "mode_16bit", 1); 992c2c6496SEvgeny Voevodin qdev_init_nofail(dev); 1001356b98dSAndreas Färber s = SYS_BUS_DEVICE(dev); 1012c2c6496SEvgeny Voevodin sysbus_mmio_map(s, 0, base); 1022c2c6496SEvgeny Voevodin sysbus_connect_irq(s, 0, irq); 1032c2c6496SEvgeny Voevodin } 1042c2c6496SEvgeny Voevodin } 1052c2c6496SEvgeny Voevodin 106*a2f2f624SKrzysztof Kozlowski static void exynos4_boards_init_ram(Exynos4BoardState *s, 107*a2f2f624SKrzysztof Kozlowski MemoryRegion *system_mem, 108*a2f2f624SKrzysztof Kozlowski unsigned long ram_size) 109*a2f2f624SKrzysztof Kozlowski { 110*a2f2f624SKrzysztof Kozlowski unsigned long mem_size = ram_size; 111*a2f2f624SKrzysztof Kozlowski 112*a2f2f624SKrzysztof Kozlowski if (mem_size > EXYNOS4210_DRAM_MAX_SIZE) { 113*a2f2f624SKrzysztof Kozlowski memory_region_init_ram(&s->dram1_mem, NULL, "exynos4210.dram1", 114*a2f2f624SKrzysztof Kozlowski mem_size - EXYNOS4210_DRAM_MAX_SIZE, 115*a2f2f624SKrzysztof Kozlowski &error_fatal); 116*a2f2f624SKrzysztof Kozlowski vmstate_register_ram_global(&s->dram1_mem); 117*a2f2f624SKrzysztof Kozlowski memory_region_add_subregion(system_mem, EXYNOS4210_DRAM1_BASE_ADDR, 118*a2f2f624SKrzysztof Kozlowski &s->dram1_mem); 119*a2f2f624SKrzysztof Kozlowski mem_size = EXYNOS4210_DRAM_MAX_SIZE; 120*a2f2f624SKrzysztof Kozlowski } 121*a2f2f624SKrzysztof Kozlowski 122*a2f2f624SKrzysztof Kozlowski memory_region_init_ram(&s->dram0_mem, NULL, "exynos4210.dram0", mem_size, 123*a2f2f624SKrzysztof Kozlowski &error_fatal); 124*a2f2f624SKrzysztof Kozlowski vmstate_register_ram_global(&s->dram0_mem); 125*a2f2f624SKrzysztof Kozlowski memory_region_add_subregion(system_mem, EXYNOS4210_DRAM0_BASE_ADDR, 126*a2f2f624SKrzysztof Kozlowski &s->dram0_mem); 127*a2f2f624SKrzysztof Kozlowski } 128*a2f2f624SKrzysztof Kozlowski 129*a2f2f624SKrzysztof Kozlowski static Exynos4BoardState * 130*a2f2f624SKrzysztof Kozlowski exynos4_boards_init_common(MachineState *machine, 1310caa7113SEvgeny Voevodin Exynos4BoardType board_type) 1320caa7113SEvgeny Voevodin { 133*a2f2f624SKrzysztof Kozlowski Exynos4BoardState *s = g_new(Exynos4BoardState, 1); 134ca177760SEduardo Habkost MachineClass *mc = MACHINE_GET_CLASS(machine); 135ca177760SEduardo Habkost 1364bd2f93fSAndreas Färber if (smp_cpus != EXYNOS4210_NCPUS && !qtest_enabled()) { 137f2ad5140SKrzysztof Kozlowski error_report("%s board supports only %d CPU cores, ignoring smp_cpus" 138f2ad5140SKrzysztof Kozlowski " value", 139ca177760SEduardo Habkost mc->name, EXYNOS4210_NCPUS); 1400caa7113SEvgeny Voevodin } 1410caa7113SEvgeny Voevodin 1420caa7113SEvgeny Voevodin exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type]; 1430caa7113SEvgeny Voevodin exynos4_board_binfo.board_id = exynos4_board_id[board_type]; 1440caa7113SEvgeny Voevodin exynos4_board_binfo.smp_bootreg_addr = 1450caa7113SEvgeny Voevodin exynos4_board_smp_bootreg_addr[board_type]; 1463ef96221SMarcel Apfelbaum exynos4_board_binfo.kernel_filename = machine->kernel_filename; 1473ef96221SMarcel Apfelbaum exynos4_board_binfo.initrd_filename = machine->initrd_filename; 1483ef96221SMarcel Apfelbaum exynos4_board_binfo.kernel_cmdline = machine->kernel_cmdline; 14996eacf64SPeter Maydell exynos4_board_binfo.gic_cpu_if_addr = 15096eacf64SPeter Maydell EXYNOS4210_SMP_PRIVATE_BASE_ADDR + 0x100; 1510caa7113SEvgeny Voevodin 1520caa7113SEvgeny Voevodin PRINT_DEBUG("\n ram_size: %luMiB [0x%08lx]\n" 1530caa7113SEvgeny Voevodin " kernel_filename: %s\n" 1540caa7113SEvgeny Voevodin " kernel_cmdline: %s\n" 1550caa7113SEvgeny Voevodin " initrd_filename: %s\n", 1560caa7113SEvgeny Voevodin exynos4_board_ram_size[board_type] / 1048576, 1570caa7113SEvgeny Voevodin exynos4_board_ram_size[board_type], 1583ef96221SMarcel Apfelbaum machine->kernel_filename, 1593ef96221SMarcel Apfelbaum machine->kernel_cmdline, 1603ef96221SMarcel Apfelbaum machine->initrd_filename); 1610caa7113SEvgeny Voevodin 162*a2f2f624SKrzysztof Kozlowski exynos4_boards_init_ram(s, get_system_memory(), 1630caa7113SEvgeny Voevodin exynos4_board_ram_size[board_type]); 164*a2f2f624SKrzysztof Kozlowski 165*a2f2f624SKrzysztof Kozlowski s->soc = exynos4210_init(get_system_memory()); 166*a2f2f624SKrzysztof Kozlowski 167*a2f2f624SKrzysztof Kozlowski return s; 1680caa7113SEvgeny Voevodin } 1690caa7113SEvgeny Voevodin 1703ef96221SMarcel Apfelbaum static void nuri_init(MachineState *machine) 1710caa7113SEvgeny Voevodin { 1723ef96221SMarcel Apfelbaum exynos4_boards_init_common(machine, EXYNOS4_BOARD_NURI); 1730caa7113SEvgeny Voevodin 174182735efSAndreas Färber arm_load_kernel(ARM_CPU(first_cpu), &exynos4_board_binfo); 1750caa7113SEvgeny Voevodin } 1760caa7113SEvgeny Voevodin 1773ef96221SMarcel Apfelbaum static void smdkc210_init(MachineState *machine) 1780caa7113SEvgeny Voevodin { 179*a2f2f624SKrzysztof Kozlowski Exynos4BoardState *s = exynos4_boards_init_common(machine, 1807f0f7740SPeter Maydell EXYNOS4_BOARD_SMDKC210); 1810caa7113SEvgeny Voevodin 1822c2c6496SEvgeny Voevodin lan9215_init(SMDK_LAN9118_BASE_ADDR, 183*a2f2f624SKrzysztof Kozlowski qemu_irq_invert(s->soc->irq_table[exynos4210_get_irq(37, 1)])); 184182735efSAndreas Färber arm_load_kernel(ARM_CPU(first_cpu), &exynos4_board_binfo); 1850caa7113SEvgeny Voevodin } 1860caa7113SEvgeny Voevodin 1878a661aeaSAndreas Färber static void nuri_class_init(ObjectClass *oc, void *data) 1880caa7113SEvgeny Voevodin { 1898a661aeaSAndreas Färber MachineClass *mc = MACHINE_CLASS(oc); 1908a661aeaSAndreas Färber 191e264d29dSEduardo Habkost mc->desc = "Samsung NURI board (Exynos4210)"; 192e264d29dSEduardo Habkost mc->init = nuri_init; 193e264d29dSEduardo Habkost mc->max_cpus = EXYNOS4210_NCPUS; 1940caa7113SEvgeny Voevodin } 1950caa7113SEvgeny Voevodin 1968a661aeaSAndreas Färber static const TypeInfo nuri_type = { 1978a661aeaSAndreas Färber .name = MACHINE_TYPE_NAME("nuri"), 1988a661aeaSAndreas Färber .parent = TYPE_MACHINE, 1998a661aeaSAndreas Färber .class_init = nuri_class_init, 2008a661aeaSAndreas Färber }; 201e264d29dSEduardo Habkost 2028a661aeaSAndreas Färber static void smdkc210_class_init(ObjectClass *oc, void *data) 203e264d29dSEduardo Habkost { 2048a661aeaSAndreas Färber MachineClass *mc = MACHINE_CLASS(oc); 2058a661aeaSAndreas Färber 206e264d29dSEduardo Habkost mc->desc = "Samsung SMDKC210 board (Exynos4210)"; 207e264d29dSEduardo Habkost mc->init = smdkc210_init; 208e264d29dSEduardo Habkost mc->max_cpus = EXYNOS4210_NCPUS; 209e264d29dSEduardo Habkost } 210e264d29dSEduardo Habkost 2118a661aeaSAndreas Färber static const TypeInfo smdkc210_type = { 2128a661aeaSAndreas Färber .name = MACHINE_TYPE_NAME("smdkc210"), 2138a661aeaSAndreas Färber .parent = TYPE_MACHINE, 2148a661aeaSAndreas Färber .class_init = smdkc210_class_init, 2158a661aeaSAndreas Färber }; 2168a661aeaSAndreas Färber 2178a661aeaSAndreas Färber static void exynos4_machines_init(void) 2188a661aeaSAndreas Färber { 2198a661aeaSAndreas Färber type_register_static(&nuri_type); 2208a661aeaSAndreas Färber type_register_static(&smdkc210_type); 2218a661aeaSAndreas Färber } 2228a661aeaSAndreas Färber 2230e6aac87SEduardo Habkost type_init(exynos4_machines_init) 224