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 "sysemu/sysemu.h" 25 #include "sysemu/qtest.h" 26 #include "hw/sysbus.h" 27 #include "net/net.h" 28 #include "hw/arm/arm.h" 29 #include "exec/address-spaces.h" 30 #include "hw/arm/exynos4210.h" 31 #include "hw/boards.h" 32 33 #undef DEBUG 34 35 //#define DEBUG 36 37 #ifdef DEBUG 38 #undef PRINT_DEBUG 39 #define PRINT_DEBUG(fmt, args...) \ 40 do { \ 41 fprintf(stderr, " [%s:%d] "fmt, __func__, __LINE__, ##args); \ 42 } while (0) 43 #else 44 #define PRINT_DEBUG(fmt, args...) do {} while (0) 45 #endif 46 47 #define SMDK_LAN9118_BASE_ADDR 0x05000000 48 49 typedef enum Exynos4BoardType { 50 EXYNOS4_BOARD_NURI, 51 EXYNOS4_BOARD_SMDKC210, 52 EXYNOS4_NUM_OF_BOARDS 53 } Exynos4BoardType; 54 55 static int exynos4_board_id[EXYNOS4_NUM_OF_BOARDS] = { 56 [EXYNOS4_BOARD_NURI] = 0xD33, 57 [EXYNOS4_BOARD_SMDKC210] = 0xB16, 58 }; 59 60 static int exynos4_board_smp_bootreg_addr[EXYNOS4_NUM_OF_BOARDS] = { 61 [EXYNOS4_BOARD_NURI] = EXYNOS4210_SECOND_CPU_BOOTREG, 62 [EXYNOS4_BOARD_SMDKC210] = EXYNOS4210_SECOND_CPU_BOOTREG, 63 }; 64 65 static unsigned long exynos4_board_ram_size[EXYNOS4_NUM_OF_BOARDS] = { 66 [EXYNOS4_BOARD_NURI] = 0x40000000, 67 [EXYNOS4_BOARD_SMDKC210] = 0x40000000, 68 }; 69 70 static struct arm_boot_info exynos4_board_binfo = { 71 .loader_start = EXYNOS4210_BASE_BOOT_ADDR, 72 .smp_loader_start = EXYNOS4210_SMP_BOOT_ADDR, 73 .nb_cpus = EXYNOS4210_NCPUS, 74 .write_secondary_boot = exynos4210_write_secondary, 75 }; 76 77 static QEMUMachine exynos4_machines[EXYNOS4_NUM_OF_BOARDS]; 78 79 static void lan9215_init(uint32_t base, qemu_irq irq) 80 { 81 DeviceState *dev; 82 SysBusDevice *s; 83 84 /* This should be a 9215 but the 9118 is close enough */ 85 if (nd_table[0].used) { 86 qemu_check_nic_model(&nd_table[0], "lan9118"); 87 dev = qdev_create(NULL, "lan9118"); 88 qdev_set_nic_properties(dev, &nd_table[0]); 89 qdev_prop_set_uint32(dev, "mode_16bit", 1); 90 qdev_init_nofail(dev); 91 s = SYS_BUS_DEVICE(dev); 92 sysbus_mmio_map(s, 0, base); 93 sysbus_connect_irq(s, 0, irq); 94 } 95 } 96 97 static Exynos4210State *exynos4_boards_init_common(MachineState *machine, 98 Exynos4BoardType board_type) 99 { 100 if (smp_cpus != EXYNOS4210_NCPUS && !qtest_enabled()) { 101 fprintf(stderr, "%s board supports only %d CPU cores. Ignoring smp_cpus" 102 " value.\n", 103 exynos4_machines[board_type].name, 104 exynos4_machines[board_type].max_cpus); 105 } 106 107 exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type]; 108 exynos4_board_binfo.board_id = exynos4_board_id[board_type]; 109 exynos4_board_binfo.smp_bootreg_addr = 110 exynos4_board_smp_bootreg_addr[board_type]; 111 exynos4_board_binfo.kernel_filename = machine->kernel_filename; 112 exynos4_board_binfo.initrd_filename = machine->initrd_filename; 113 exynos4_board_binfo.kernel_cmdline = machine->kernel_cmdline; 114 exynos4_board_binfo.gic_cpu_if_addr = 115 EXYNOS4210_SMP_PRIVATE_BASE_ADDR + 0x100; 116 117 PRINT_DEBUG("\n ram_size: %luMiB [0x%08lx]\n" 118 " kernel_filename: %s\n" 119 " kernel_cmdline: %s\n" 120 " initrd_filename: %s\n", 121 exynos4_board_ram_size[board_type] / 1048576, 122 exynos4_board_ram_size[board_type], 123 machine->kernel_filename, 124 machine->kernel_cmdline, 125 machine->initrd_filename); 126 127 return exynos4210_init(get_system_memory(), 128 exynos4_board_ram_size[board_type]); 129 } 130 131 static void nuri_init(MachineState *machine) 132 { 133 exynos4_boards_init_common(machine, EXYNOS4_BOARD_NURI); 134 135 arm_load_kernel(ARM_CPU(first_cpu), &exynos4_board_binfo); 136 } 137 138 static void smdkc210_init(MachineState *machine) 139 { 140 Exynos4210State *s = exynos4_boards_init_common(machine, 141 EXYNOS4_BOARD_SMDKC210); 142 143 lan9215_init(SMDK_LAN9118_BASE_ADDR, 144 qemu_irq_invert(s->irq_table[exynos4210_get_irq(37, 1)])); 145 arm_load_kernel(ARM_CPU(first_cpu), &exynos4_board_binfo); 146 } 147 148 static QEMUMachine exynos4_machines[EXYNOS4_NUM_OF_BOARDS] = { 149 [EXYNOS4_BOARD_NURI] = { 150 .name = "nuri", 151 .desc = "Samsung NURI board (Exynos4210)", 152 .init = nuri_init, 153 .max_cpus = EXYNOS4210_NCPUS, 154 }, 155 [EXYNOS4_BOARD_SMDKC210] = { 156 .name = "smdkc210", 157 .desc = "Samsung SMDKC210 board (Exynos4210)", 158 .init = smdkc210_init, 159 .max_cpus = EXYNOS4210_NCPUS, 160 }, 161 }; 162 163 static void exynos4_machine_init(void) 164 { 165 qemu_register_machine(&exynos4_machines[EXYNOS4_BOARD_NURI]); 166 qemu_register_machine(&exynos4_machines[EXYNOS4_BOARD_SMDKC210]); 167 } 168 169 machine_init(exynos4_machine_init); 170