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