puv3.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Generic PKUnity SoC machine and board descriptor
  3. *
  4. * Copyright (C) 2010-2012 Guan Xuetao
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation, or any later version.
  9. * See the COPYING file in the top-level directory.
  10. */
  11. #include "qemu-common.h"
  12. #include "ui/console.h"
  13. #include "elf.h"
  14. #include "exec/address-spaces.h"
  15. #include "sysbus.h"
  16. #include "boards.h"
  17. #include "loader.h"
  18. #include "pc.h"
  19. #undef DEBUG_PUV3
  20. #include "puv3.h"
  21. #define KERNEL_LOAD_ADDR 0x03000000
  22. #define KERNEL_MAX_SIZE 0x00800000 /* Just a guess */
  23. static void puv3_intc_cpu_handler(void *opaque, int irq, int level)
  24. {
  25. CPUUniCore32State *env = opaque;
  26. assert(irq == 0);
  27. if (level) {
  28. cpu_interrupt(env, CPU_INTERRUPT_HARD);
  29. } else {
  30. cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
  31. }
  32. }
  33. static void puv3_soc_init(CPUUniCore32State *env)
  34. {
  35. qemu_irq *cpu_intc, irqs[PUV3_IRQS_NR];
  36. DeviceState *dev;
  37. MemoryRegion *i8042 = g_new(MemoryRegion, 1);
  38. int i;
  39. /* Initialize interrupt controller */
  40. cpu_intc = qemu_allocate_irqs(puv3_intc_cpu_handler, env, 1);
  41. dev = sysbus_create_simple("puv3_intc", PUV3_INTC_BASE, *cpu_intc);
  42. for (i = 0; i < PUV3_IRQS_NR; i++) {
  43. irqs[i] = qdev_get_gpio_in(dev, i);
  44. }
  45. /* Initialize minimal necessary devices for kernel booting */
  46. sysbus_create_simple("puv3_pm", PUV3_PM_BASE, NULL);
  47. sysbus_create_simple("puv3_dma", PUV3_DMA_BASE, NULL);
  48. sysbus_create_simple("puv3_ost", PUV3_OST_BASE, irqs[PUV3_IRQS_OST0]);
  49. sysbus_create_varargs("puv3_gpio", PUV3_GPIO_BASE,
  50. irqs[PUV3_IRQS_GPIOLOW0], irqs[PUV3_IRQS_GPIOLOW1],
  51. irqs[PUV3_IRQS_GPIOLOW2], irqs[PUV3_IRQS_GPIOLOW3],
  52. irqs[PUV3_IRQS_GPIOLOW4], irqs[PUV3_IRQS_GPIOLOW5],
  53. irqs[PUV3_IRQS_GPIOLOW6], irqs[PUV3_IRQS_GPIOLOW7],
  54. irqs[PUV3_IRQS_GPIOHIGH], NULL);
  55. /* Keyboard (i8042), mouse disabled for nographic */
  56. i8042_mm_init(irqs[PUV3_IRQS_PS2_KBD], NULL, i8042, PUV3_REGS_OFFSET, 4);
  57. memory_region_add_subregion(get_system_memory(), PUV3_PS2_BASE, i8042);
  58. }
  59. static void puv3_board_init(CPUUniCore32State *env, ram_addr_t ram_size)
  60. {
  61. MemoryRegion *ram_memory = g_new(MemoryRegion, 1);
  62. /* SDRAM at address zero. */
  63. memory_region_init_ram(ram_memory, "puv3.ram", ram_size);
  64. vmstate_register_ram_global(ram_memory);
  65. memory_region_add_subregion(get_system_memory(), 0, ram_memory);
  66. }
  67. static void puv3_load_kernel(const char *kernel_filename)
  68. {
  69. int size;
  70. assert(kernel_filename != NULL);
  71. /* only zImage format supported */
  72. size = load_image_targphys(kernel_filename, KERNEL_LOAD_ADDR,
  73. KERNEL_MAX_SIZE);
  74. if (size < 0) {
  75. hw_error("Load kernel error: '%s'\n", kernel_filename);
  76. }
  77. /* cheat curses that we have a graphic console, only under ocd console */
  78. graphic_console_init(NULL, NULL, NULL, NULL, NULL);
  79. }
  80. static void puv3_init(QEMUMachineInitArgs *args)
  81. {
  82. ram_addr_t ram_size = args->ram_size;
  83. const char *cpu_model = args->cpu_model;
  84. const char *kernel_filename = args->kernel_filename;
  85. const char *initrd_filename = args->initrd_filename;
  86. CPUUniCore32State *env;
  87. if (initrd_filename) {
  88. hw_error("Please use kernel built-in initramdisk.\n");
  89. }
  90. if (!cpu_model) {
  91. cpu_model = "UniCore-II";
  92. }
  93. env = cpu_init(cpu_model);
  94. if (!env) {
  95. hw_error("Unable to find CPU definition\n");
  96. }
  97. puv3_soc_init(env);
  98. puv3_board_init(env, ram_size);
  99. puv3_load_kernel(kernel_filename);
  100. }
  101. static QEMUMachine puv3_machine = {
  102. .name = "puv3",
  103. .desc = "PKUnity Version-3 based on UniCore32",
  104. .init = puv3_init,
  105. .is_default = 1,
  106. DEFAULT_MACHINE_OPTIONS,
  107. };
  108. static void puv3_machine_init(void)
  109. {
  110. qemu_register_machine(&puv3_machine);
  111. }
  112. machine_init(puv3_machine_init)