xref: /qemu/hw/arm/exynos4_boards.c (revision 3f088e36de5a72a69e530d4bbf1fabaa507da0db)
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 
240caa7113SEvgeny Voevodin #include "sysemu.h"
250caa7113SEvgeny Voevodin #include "sysbus.h"
262c2c6496SEvgeny Voevodin #include "net.h"
270caa7113SEvgeny Voevodin #include "arm-misc.h"
280caa7113SEvgeny Voevodin #include "exec-memory.h"
290caa7113SEvgeny Voevodin #include "exynos4210.h"
300caa7113SEvgeny Voevodin #include "boards.h"
310caa7113SEvgeny Voevodin 
320caa7113SEvgeny Voevodin #undef DEBUG
330caa7113SEvgeny Voevodin 
340caa7113SEvgeny Voevodin //#define DEBUG
350caa7113SEvgeny Voevodin 
360caa7113SEvgeny Voevodin #ifdef DEBUG
370caa7113SEvgeny Voevodin     #undef PRINT_DEBUG
380caa7113SEvgeny Voevodin     #define  PRINT_DEBUG(fmt, args...) \
390caa7113SEvgeny Voevodin         do { \
400caa7113SEvgeny Voevodin             fprintf(stderr, "  [%s:%d]   "fmt, __func__, __LINE__, ##args); \
410caa7113SEvgeny Voevodin         } while (0)
420caa7113SEvgeny Voevodin #else
430caa7113SEvgeny Voevodin     #define  PRINT_DEBUG(fmt, args...)  do {} while (0)
440caa7113SEvgeny Voevodin #endif
450caa7113SEvgeny Voevodin 
462c2c6496SEvgeny Voevodin #define SMDK_LAN9118_BASE_ADDR      0x05000000
472c2c6496SEvgeny Voevodin 
480caa7113SEvgeny Voevodin typedef enum Exynos4BoardType {
490caa7113SEvgeny Voevodin     EXYNOS4_BOARD_NURI,
500caa7113SEvgeny Voevodin     EXYNOS4_BOARD_SMDKC210,
510caa7113SEvgeny Voevodin     EXYNOS4_NUM_OF_BOARDS
520caa7113SEvgeny Voevodin } Exynos4BoardType;
530caa7113SEvgeny Voevodin 
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] = {
650caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_NURI]     = 0x40000000,
660caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_SMDKC210] = 0x40000000,
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,
73*3f088e36SEvgeny Voevodin     .write_secondary_boot = exynos4210_write_secondary,
740caa7113SEvgeny Voevodin };
750caa7113SEvgeny Voevodin 
760caa7113SEvgeny Voevodin static QEMUMachine exynos4_machines[EXYNOS4_NUM_OF_BOARDS];
770caa7113SEvgeny Voevodin 
782c2c6496SEvgeny Voevodin static void lan9215_init(uint32_t base, qemu_irq irq)
792c2c6496SEvgeny Voevodin {
802c2c6496SEvgeny Voevodin     DeviceState *dev;
812c2c6496SEvgeny Voevodin     SysBusDevice *s;
822c2c6496SEvgeny Voevodin 
832c2c6496SEvgeny Voevodin     /* This should be a 9215 but the 9118 is close enough */
842c2c6496SEvgeny Voevodin     if (nd_table[0].vlan) {
852c2c6496SEvgeny Voevodin         qemu_check_nic_model(&nd_table[0], "lan9118");
862c2c6496SEvgeny Voevodin         dev = qdev_create(NULL, "lan9118");
872c2c6496SEvgeny Voevodin         qdev_set_nic_properties(dev, &nd_table[0]);
882c2c6496SEvgeny Voevodin         qdev_prop_set_uint32(dev, "mode_16bit", 1);
892c2c6496SEvgeny Voevodin         qdev_init_nofail(dev);
902c2c6496SEvgeny Voevodin         s = sysbus_from_qdev(dev);
912c2c6496SEvgeny Voevodin         sysbus_mmio_map(s, 0, base);
922c2c6496SEvgeny Voevodin         sysbus_connect_irq(s, 0, irq);
932c2c6496SEvgeny Voevodin     }
942c2c6496SEvgeny Voevodin }
952c2c6496SEvgeny Voevodin 
960caa7113SEvgeny Voevodin static Exynos4210State *exynos4_boards_init_common(
970caa7113SEvgeny Voevodin         const char *kernel_filename,
980caa7113SEvgeny Voevodin         const char *kernel_cmdline,
990caa7113SEvgeny Voevodin         const char *initrd_filename,
1000caa7113SEvgeny Voevodin         Exynos4BoardType board_type)
1010caa7113SEvgeny Voevodin {
1020caa7113SEvgeny Voevodin     if (smp_cpus != EXYNOS4210_NCPUS) {
1030caa7113SEvgeny Voevodin         fprintf(stderr, "%s board supports only %d CPU cores. Ignoring smp_cpus"
1040caa7113SEvgeny Voevodin                 " value.\n",
1050caa7113SEvgeny Voevodin                 exynos4_machines[board_type].name,
1060caa7113SEvgeny Voevodin                 exynos4_machines[board_type].max_cpus);
1070caa7113SEvgeny Voevodin     }
1080caa7113SEvgeny Voevodin 
1090caa7113SEvgeny Voevodin     exynos4_board_binfo.ram_size = exynos4_board_ram_size[board_type];
1100caa7113SEvgeny Voevodin     exynos4_board_binfo.board_id = exynos4_board_id[board_type];
1110caa7113SEvgeny Voevodin     exynos4_board_binfo.smp_bootreg_addr =
1120caa7113SEvgeny Voevodin             exynos4_board_smp_bootreg_addr[board_type];
1130caa7113SEvgeny Voevodin     exynos4_board_binfo.kernel_filename = kernel_filename;
1140caa7113SEvgeny Voevodin     exynos4_board_binfo.initrd_filename = initrd_filename;
1150caa7113SEvgeny Voevodin     exynos4_board_binfo.kernel_cmdline = kernel_cmdline;
11696eacf64SPeter Maydell     exynos4_board_binfo.gic_cpu_if_addr =
11796eacf64SPeter Maydell             EXYNOS4210_SMP_PRIVATE_BASE_ADDR + 0x100;
1180caa7113SEvgeny Voevodin 
1190caa7113SEvgeny Voevodin     PRINT_DEBUG("\n ram_size: %luMiB [0x%08lx]\n"
1200caa7113SEvgeny Voevodin             " kernel_filename: %s\n"
1210caa7113SEvgeny Voevodin             " kernel_cmdline: %s\n"
1220caa7113SEvgeny Voevodin             " initrd_filename: %s\n",
1230caa7113SEvgeny Voevodin             exynos4_board_ram_size[board_type] / 1048576,
1240caa7113SEvgeny Voevodin             exynos4_board_ram_size[board_type],
1250caa7113SEvgeny Voevodin             kernel_filename,
1260caa7113SEvgeny Voevodin             kernel_cmdline,
1270caa7113SEvgeny Voevodin             initrd_filename);
1280caa7113SEvgeny Voevodin 
1290caa7113SEvgeny Voevodin     return exynos4210_init(get_system_memory(),
1300caa7113SEvgeny Voevodin             exynos4_board_ram_size[board_type]);
1310caa7113SEvgeny Voevodin }
1320caa7113SEvgeny Voevodin 
1330caa7113SEvgeny Voevodin static void nuri_init(ram_addr_t ram_size,
1340caa7113SEvgeny Voevodin         const char *boot_device,
1350caa7113SEvgeny Voevodin         const char *kernel_filename, const char *kernel_cmdline,
1360caa7113SEvgeny Voevodin         const char *initrd_filename, const char *cpu_model)
1370caa7113SEvgeny Voevodin {
1380caa7113SEvgeny Voevodin     exynos4_boards_init_common(kernel_filename, kernel_cmdline,
1390caa7113SEvgeny Voevodin                 initrd_filename, EXYNOS4_BOARD_NURI);
1400caa7113SEvgeny Voevodin 
1410caa7113SEvgeny Voevodin     arm_load_kernel(first_cpu, &exynos4_board_binfo);
1420caa7113SEvgeny Voevodin }
1430caa7113SEvgeny Voevodin 
1440caa7113SEvgeny Voevodin static void smdkc210_init(ram_addr_t ram_size,
1450caa7113SEvgeny Voevodin         const char *boot_device,
1460caa7113SEvgeny Voevodin         const char *kernel_filename, const char *kernel_cmdline,
1470caa7113SEvgeny Voevodin         const char *initrd_filename, const char *cpu_model)
1480caa7113SEvgeny Voevodin {
1492c2c6496SEvgeny Voevodin     Exynos4210State *s = exynos4_boards_init_common(kernel_filename,
1502c2c6496SEvgeny Voevodin             kernel_cmdline, initrd_filename, EXYNOS4_BOARD_SMDKC210);
1510caa7113SEvgeny Voevodin 
1522c2c6496SEvgeny Voevodin     lan9215_init(SMDK_LAN9118_BASE_ADDR,
1532c2c6496SEvgeny Voevodin             qemu_irq_invert(s->irq_table[exynos4210_get_irq(37, 1)]));
1540caa7113SEvgeny Voevodin     arm_load_kernel(first_cpu, &exynos4_board_binfo);
1550caa7113SEvgeny Voevodin }
1560caa7113SEvgeny Voevodin 
1570caa7113SEvgeny Voevodin static QEMUMachine exynos4_machines[EXYNOS4_NUM_OF_BOARDS] = {
1580caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_NURI] = {
1590caa7113SEvgeny Voevodin         .name = "nuri",
1600caa7113SEvgeny Voevodin         .desc = "Samsung NURI board (Exynos4210)",
1610caa7113SEvgeny Voevodin         .init = nuri_init,
1620caa7113SEvgeny Voevodin         .max_cpus = EXYNOS4210_NCPUS,
1630caa7113SEvgeny Voevodin     },
1640caa7113SEvgeny Voevodin     [EXYNOS4_BOARD_SMDKC210] = {
1650caa7113SEvgeny Voevodin         .name = "smdkc210",
1660caa7113SEvgeny Voevodin         .desc = "Samsung SMDKC210 board (Exynos4210)",
1670caa7113SEvgeny Voevodin         .init = smdkc210_init,
1680caa7113SEvgeny Voevodin         .max_cpus = EXYNOS4210_NCPUS,
1690caa7113SEvgeny Voevodin     },
1700caa7113SEvgeny Voevodin };
1710caa7113SEvgeny Voevodin 
1720caa7113SEvgeny Voevodin static void exynos4_machine_init(void)
1730caa7113SEvgeny Voevodin {
1740caa7113SEvgeny Voevodin     qemu_register_machine(&exynos4_machines[EXYNOS4_BOARD_NURI]);
1750caa7113SEvgeny Voevodin     qemu_register_machine(&exynos4_machines[EXYNOS4_BOARD_SMDKC210]);
1760caa7113SEvgeny Voevodin }
1770caa7113SEvgeny Voevodin 
1780caa7113SEvgeny Voevodin machine_init(exynos4_machine_init);
179