niagara.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * QEMU Sun4v/Niagara System Emulator
  3. *
  4. * Copyright (c) 2016 Artyom Tarasenko
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "qemu/osdep.h"
  25. #include "qemu/units.h"
  26. #include "cpu.h"
  27. #include "hw/boards.h"
  28. #include "hw/char/serial.h"
  29. #include "hw/misc/unimp.h"
  30. #include "hw/loader.h"
  31. #include "hw/sparc/sparc64.h"
  32. #include "hw/rtc/sun4v-rtc.h"
  33. #include "sysemu/block-backend.h"
  34. #include "qemu/error-report.h"
  35. #include "sysemu/qtest.h"
  36. #include "sysemu/sysemu.h"
  37. #include "qapi/error.h"
  38. typedef struct NiagaraBoardState {
  39. MemoryRegion hv_ram;
  40. MemoryRegion nvram;
  41. MemoryRegion md_rom;
  42. MemoryRegion hv_rom;
  43. MemoryRegion vdisk_ram;
  44. MemoryRegion prom;
  45. } NiagaraBoardState;
  46. #define NIAGARA_HV_RAM_BASE 0x100000ULL
  47. #define NIAGARA_HV_RAM_SIZE 0x3f00000ULL /* 63 MiB */
  48. #define NIAGARA_PARTITION_RAM_BASE 0x80000000ULL
  49. #define NIAGARA_UART_BASE 0x1f10000000ULL
  50. #define NIAGARA_NVRAM_BASE 0x1f11000000ULL
  51. #define NIAGARA_NVRAM_SIZE 0x2000
  52. #define NIAGARA_MD_ROM_BASE 0x1f12000000ULL
  53. #define NIAGARA_MD_ROM_SIZE 0x2000
  54. #define NIAGARA_HV_ROM_BASE 0x1f12080000ULL
  55. #define NIAGARA_HV_ROM_SIZE 0x2000
  56. #define NIAGARA_IOBBASE 0x9800000000ULL
  57. #define NIAGARA_IOBSIZE 0x0100000000ULL
  58. #define NIAGARA_VDISK_BASE 0x1f40000000ULL
  59. #define NIAGARA_RTC_BASE 0xfff0c1fff8ULL
  60. /* Firmware layout
  61. *
  62. * |------------------|
  63. * | openboot.bin |
  64. * |------------------| PROM_ADDR + OBP_OFFSET
  65. * | q.bin |
  66. * |------------------| PROM_ADDR + Q_OFFSET
  67. * | reset.bin |
  68. * |------------------| PROM_ADDR
  69. */
  70. #define NIAGARA_PROM_BASE 0xfff0000000ULL
  71. #define NIAGARA_Q_OFFSET 0x10000ULL
  72. #define NIAGARA_OBP_OFFSET 0x80000ULL
  73. #define PROM_SIZE_MAX (4 * MiB)
  74. static void add_rom_or_fail(const char *file, const hwaddr addr)
  75. {
  76. /* XXX remove qtest_enabled() check once firmware files are
  77. * in the qemu tree
  78. */
  79. if (!qtest_enabled() && rom_add_file_fixed(file, addr, -1)) {
  80. error_report("Unable to load a firmware for -M niagara");
  81. exit(1);
  82. }
  83. }
  84. /* Niagara hardware initialisation */
  85. static void niagara_init(MachineState *machine)
  86. {
  87. NiagaraBoardState *s = g_new(NiagaraBoardState, 1);
  88. DriveInfo *dinfo = drive_get(IF_PFLASH, 0, 0);
  89. MemoryRegion *sysmem = get_system_memory();
  90. /* init CPUs */
  91. sparc64_cpu_devinit(machine->cpu_type, NIAGARA_PROM_BASE);
  92. /* set up devices */
  93. memory_region_init_ram(&s->hv_ram, NULL, "sun4v-hv.ram",
  94. NIAGARA_HV_RAM_SIZE, &error_fatal);
  95. memory_region_add_subregion(sysmem, NIAGARA_HV_RAM_BASE, &s->hv_ram);
  96. memory_region_add_subregion(sysmem, NIAGARA_PARTITION_RAM_BASE,
  97. machine->ram);
  98. memory_region_init_ram(&s->nvram, NULL, "sun4v.nvram", NIAGARA_NVRAM_SIZE,
  99. &error_fatal);
  100. memory_region_add_subregion(sysmem, NIAGARA_NVRAM_BASE, &s->nvram);
  101. memory_region_init_ram(&s->md_rom, NULL, "sun4v-md.rom",
  102. NIAGARA_MD_ROM_SIZE, &error_fatal);
  103. memory_region_add_subregion(sysmem, NIAGARA_MD_ROM_BASE, &s->md_rom);
  104. memory_region_init_ram(&s->hv_rom, NULL, "sun4v-hv.rom",
  105. NIAGARA_HV_ROM_SIZE, &error_fatal);
  106. memory_region_add_subregion(sysmem, NIAGARA_HV_ROM_BASE, &s->hv_rom);
  107. memory_region_init_ram(&s->prom, NULL, "sun4v.prom", PROM_SIZE_MAX,
  108. &error_fatal);
  109. memory_region_add_subregion(sysmem, NIAGARA_PROM_BASE, &s->prom);
  110. add_rom_or_fail("nvram1", NIAGARA_NVRAM_BASE);
  111. add_rom_or_fail("1up-md.bin", NIAGARA_MD_ROM_BASE);
  112. add_rom_or_fail("1up-hv.bin", NIAGARA_HV_ROM_BASE);
  113. add_rom_or_fail("reset.bin", NIAGARA_PROM_BASE);
  114. add_rom_or_fail("q.bin", NIAGARA_PROM_BASE + NIAGARA_Q_OFFSET);
  115. add_rom_or_fail("openboot.bin", NIAGARA_PROM_BASE + NIAGARA_OBP_OFFSET);
  116. /* the virtual ramdisk is kind of initrd, but it resides
  117. outside of the partition RAM */
  118. if (dinfo) {
  119. BlockBackend *blk = blk_by_legacy_dinfo(dinfo);
  120. int size = blk_getlength(blk);
  121. if (size > 0) {
  122. memory_region_init_ram(&s->vdisk_ram, NULL, "sun4v_vdisk.ram", size,
  123. &error_fatal);
  124. memory_region_add_subregion(get_system_memory(),
  125. NIAGARA_VDISK_BASE, &s->vdisk_ram);
  126. dinfo->is_default = 1;
  127. rom_add_file_fixed(blk_name(blk), NIAGARA_VDISK_BASE, -1);
  128. } else {
  129. error_report("could not load ram disk '%s'", blk_name(blk));
  130. exit(1);
  131. }
  132. }
  133. serial_mm_init(sysmem, NIAGARA_UART_BASE, 0, NULL,
  134. 115200, serial_hd(0), DEVICE_BIG_ENDIAN);
  135. create_unimplemented_device("sun4v-iob", NIAGARA_IOBBASE, NIAGARA_IOBSIZE);
  136. sun4v_rtc_init(NIAGARA_RTC_BASE);
  137. }
  138. static void niagara_class_init(ObjectClass *oc, void *data)
  139. {
  140. MachineClass *mc = MACHINE_CLASS(oc);
  141. mc->desc = "Sun4v platform, Niagara";
  142. mc->init = niagara_init;
  143. mc->max_cpus = 1; /* XXX for now */
  144. mc->default_boot_order = "c";
  145. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1");
  146. mc->default_ram_id = "sun4v-partition.ram";
  147. }
  148. static const TypeInfo niagara_type = {
  149. .name = MACHINE_TYPE_NAME("niagara"),
  150. .parent = TYPE_MACHINE,
  151. .class_init = niagara_class_init,
  152. };
  153. static void niagara_register_types(void)
  154. {
  155. type_register_static(&niagara_type);
  156. }
  157. type_init(niagara_register_types)