sun4u.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * QEMU Sun4u/Sun4v System Emulator
  3. *
  4. * Copyright (c) 2005 Fabrice Bellard
  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 "hw.h"
  25. #include "pci.h"
  26. #include "pc.h"
  27. #include "nvram.h"
  28. #include "fdc.h"
  29. #include "net.h"
  30. #include "qemu-timer.h"
  31. #include "sysemu.h"
  32. #include "boards.h"
  33. #include "firmware_abi.h"
  34. #include "fw_cfg.h"
  35. //#define DEBUG_IRQ
  36. #ifdef DEBUG_IRQ
  37. #define DPRINTF(fmt, args...) \
  38. do { printf("CPUIRQ: " fmt , ##args); } while (0)
  39. #else
  40. #define DPRINTF(fmt, args...)
  41. #endif
  42. #define KERNEL_LOAD_ADDR 0x00404000
  43. #define CMDLINE_ADDR 0x003ff000
  44. #define INITRD_LOAD_ADDR 0x00300000
  45. #define PROM_SIZE_MAX (4 * 1024 * 1024)
  46. #define PROM_VADDR 0x000ffd00000ULL
  47. #define APB_SPECIAL_BASE 0x1fe00000000ULL
  48. #define APB_MEM_BASE 0x1ff00000000ULL
  49. #define VGA_BASE (APB_MEM_BASE + 0x400000ULL)
  50. #define PROM_FILENAME "openbios-sparc64"
  51. #define NVRAM_SIZE 0x2000
  52. #define MAX_IDE_BUS 2
  53. #define BIOS_CFG_IOPORT 0x510
  54. #define MAX_PILS 16
  55. #define TICK_INT_DIS 0x8000000000000000ULL
  56. #define TICK_MAX 0x7fffffffffffffffULL
  57. struct hwdef {
  58. const char * const default_cpu_model;
  59. uint16_t machine_id;
  60. uint64_t prom_addr;
  61. uint64_t console_serial_base;
  62. };
  63. int DMA_get_channel_mode (int nchan)
  64. {
  65. return 0;
  66. }
  67. int DMA_read_memory (int nchan, void *buf, int pos, int size)
  68. {
  69. return 0;
  70. }
  71. int DMA_write_memory (int nchan, void *buf, int pos, int size)
  72. {
  73. return 0;
  74. }
  75. void DMA_hold_DREQ (int nchan) {}
  76. void DMA_release_DREQ (int nchan) {}
  77. void DMA_schedule(int nchan) {}
  78. void DMA_init (int high_page_enable) {}
  79. void DMA_register_channel (int nchan,
  80. DMA_transfer_handler transfer_handler,
  81. void *opaque)
  82. {
  83. }
  84. static int nvram_boot_set(void *opaque, const char *boot_device)
  85. {
  86. unsigned int i;
  87. uint8_t image[sizeof(ohwcfg_v3_t)];
  88. ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
  89. m48t59_t *nvram = (m48t59_t *)opaque;
  90. for (i = 0; i < sizeof(image); i++)
  91. image[i] = m48t59_read(nvram, i) & 0xff;
  92. pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
  93. boot_device);
  94. header->nboot_devices = strlen(boot_device) & 0xff;
  95. header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
  96. for (i = 0; i < sizeof(image); i++)
  97. m48t59_write(nvram, i, image[i]);
  98. return 0;
  99. }
  100. static int sun4u_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
  101. const char *arch,
  102. ram_addr_t RAM_size,
  103. const char *boot_devices,
  104. uint32_t kernel_image, uint32_t kernel_size,
  105. const char *cmdline,
  106. uint32_t initrd_image, uint32_t initrd_size,
  107. uint32_t NVRAM_image,
  108. int width, int height, int depth,
  109. const uint8_t *macaddr)
  110. {
  111. unsigned int i;
  112. uint32_t start, end;
  113. uint8_t image[0x1ff0];
  114. ohwcfg_v3_t *header = (ohwcfg_v3_t *)&image;
  115. struct sparc_arch_cfg *sparc_header;
  116. struct OpenBIOS_nvpart_v1 *part_header;
  117. memset(image, '\0', sizeof(image));
  118. // Try to match PPC NVRAM
  119. pstrcpy((char *)header->struct_ident, sizeof(header->struct_ident),
  120. "QEMU_BIOS");
  121. header->struct_version = cpu_to_be32(3); /* structure v3 */
  122. header->nvram_size = cpu_to_be16(NVRAM_size);
  123. header->nvram_arch_ptr = cpu_to_be16(sizeof(ohwcfg_v3_t));
  124. header->nvram_arch_size = cpu_to_be16(sizeof(struct sparc_arch_cfg));
  125. pstrcpy((char *)header->arch, sizeof(header->arch), arch);
  126. header->nb_cpus = smp_cpus & 0xff;
  127. header->RAM0_base = 0;
  128. header->RAM0_size = cpu_to_be64((uint64_t)RAM_size);
  129. pstrcpy((char *)header->boot_devices, sizeof(header->boot_devices),
  130. boot_devices);
  131. header->nboot_devices = strlen(boot_devices) & 0xff;
  132. header->kernel_image = cpu_to_be64((uint64_t)kernel_image);
  133. header->kernel_size = cpu_to_be64((uint64_t)kernel_size);
  134. if (cmdline) {
  135. pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, cmdline);
  136. header->cmdline = cpu_to_be64((uint64_t)CMDLINE_ADDR);
  137. header->cmdline_size = cpu_to_be64((uint64_t)strlen(cmdline));
  138. }
  139. header->initrd_image = cpu_to_be64((uint64_t)initrd_image);
  140. header->initrd_size = cpu_to_be64((uint64_t)initrd_size);
  141. header->NVRAM_image = cpu_to_be64((uint64_t)NVRAM_image);
  142. header->width = cpu_to_be16(width);
  143. header->height = cpu_to_be16(height);
  144. header->depth = cpu_to_be16(depth);
  145. if (nographic)
  146. header->graphic_flags = cpu_to_be16(OHW_GF_NOGRAPHICS);
  147. header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
  148. // Architecture specific header
  149. start = sizeof(ohwcfg_v3_t);
  150. sparc_header = (struct sparc_arch_cfg *)&image[start];
  151. sparc_header->valid = 0;
  152. start += sizeof(struct sparc_arch_cfg);
  153. // OpenBIOS nvram variables
  154. // Variable partition
  155. part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
  156. part_header->signature = OPENBIOS_PART_SYSTEM;
  157. pstrcpy(part_header->name, sizeof(part_header->name), "system");
  158. end = start + sizeof(struct OpenBIOS_nvpart_v1);
  159. for (i = 0; i < nb_prom_envs; i++)
  160. end = OpenBIOS_set_var(image, end, prom_envs[i]);
  161. // End marker
  162. image[end++] = '\0';
  163. end = start + ((end - start + 15) & ~15);
  164. OpenBIOS_finish_partition(part_header, end - start);
  165. // free partition
  166. start = end;
  167. part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
  168. part_header->signature = OPENBIOS_PART_FREE;
  169. pstrcpy(part_header->name, sizeof(part_header->name), "free");
  170. end = 0x1fd0;
  171. OpenBIOS_finish_partition(part_header, end - start);
  172. Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80);
  173. for (i = 0; i < sizeof(image); i++)
  174. m48t59_write(nvram, i, image[i]);
  175. qemu_register_boot_set(nvram_boot_set, nvram);
  176. return 0;
  177. }
  178. void pic_info(void)
  179. {
  180. }
  181. void irq_info(void)
  182. {
  183. }
  184. void cpu_check_irqs(CPUState *env)
  185. {
  186. uint32_t pil = env->pil_in | (env->softint & ~SOFTINT_TIMER) |
  187. ((env->softint & SOFTINT_TIMER) << 14);
  188. if (pil && (env->interrupt_index == 0 ||
  189. (env->interrupt_index & ~15) == TT_EXTINT)) {
  190. unsigned int i;
  191. for (i = 15; i > 0; i--) {
  192. if (pil & (1 << i)) {
  193. int old_interrupt = env->interrupt_index;
  194. env->interrupt_index = TT_EXTINT | i;
  195. if (old_interrupt != env->interrupt_index) {
  196. DPRINTF("Set CPU IRQ %d\n", i);
  197. cpu_interrupt(env, CPU_INTERRUPT_HARD);
  198. }
  199. break;
  200. }
  201. }
  202. } else if (!pil && (env->interrupt_index & ~15) == TT_EXTINT) {
  203. DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
  204. env->interrupt_index = 0;
  205. cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
  206. }
  207. }
  208. static void cpu_set_irq(void *opaque, int irq, int level)
  209. {
  210. CPUState *env = opaque;
  211. if (level) {
  212. DPRINTF("Raise CPU IRQ %d\n", irq);
  213. env->halted = 0;
  214. env->pil_in |= 1 << irq;
  215. cpu_check_irqs(env);
  216. } else {
  217. DPRINTF("Lower CPU IRQ %d\n", irq);
  218. env->pil_in &= ~(1 << irq);
  219. cpu_check_irqs(env);
  220. }
  221. }
  222. void qemu_system_powerdown(void)
  223. {
  224. }
  225. typedef struct ResetData {
  226. CPUState *env;
  227. uint64_t reset_addr;
  228. } ResetData;
  229. static void main_cpu_reset(void *opaque)
  230. {
  231. ResetData *s = (ResetData *)opaque;
  232. CPUState *env = s->env;
  233. cpu_reset(env);
  234. env->tick_cmpr = TICK_INT_DIS | 0;
  235. ptimer_set_limit(env->tick, TICK_MAX, 1);
  236. ptimer_run(env->tick, 1);
  237. env->stick_cmpr = TICK_INT_DIS | 0;
  238. ptimer_set_limit(env->stick, TICK_MAX, 1);
  239. ptimer_run(env->stick, 1);
  240. env->hstick_cmpr = TICK_INT_DIS | 0;
  241. ptimer_set_limit(env->hstick, TICK_MAX, 1);
  242. ptimer_run(env->hstick, 1);
  243. env->gregs[1] = 0; // Memory start
  244. env->gregs[2] = ram_size; // Memory size
  245. env->gregs[3] = 0; // Machine description XXX
  246. env->pc = s->reset_addr;
  247. env->npc = env->pc + 4;
  248. }
  249. static void tick_irq(void *opaque)
  250. {
  251. CPUState *env = opaque;
  252. if (!(env->tick_cmpr & TICK_INT_DIS)) {
  253. env->softint |= SOFTINT_TIMER;
  254. cpu_interrupt(env, CPU_INTERRUPT_TIMER);
  255. }
  256. }
  257. static void stick_irq(void *opaque)
  258. {
  259. CPUState *env = opaque;
  260. if (!(env->stick_cmpr & TICK_INT_DIS)) {
  261. env->softint |= SOFTINT_STIMER;
  262. cpu_interrupt(env, CPU_INTERRUPT_TIMER);
  263. }
  264. }
  265. static void hstick_irq(void *opaque)
  266. {
  267. CPUState *env = opaque;
  268. if (!(env->hstick_cmpr & TICK_INT_DIS)) {
  269. cpu_interrupt(env, CPU_INTERRUPT_TIMER);
  270. }
  271. }
  272. void cpu_tick_set_count(void *opaque, uint64_t count)
  273. {
  274. ptimer_set_count(opaque, -count);
  275. }
  276. uint64_t cpu_tick_get_count(void *opaque)
  277. {
  278. return -ptimer_get_count(opaque);
  279. }
  280. void cpu_tick_set_limit(void *opaque, uint64_t limit)
  281. {
  282. ptimer_set_limit(opaque, -limit, 0);
  283. }
  284. static const int ide_iobase[2] = { 0x1f0, 0x170 };
  285. static const int ide_iobase2[2] = { 0x3f6, 0x376 };
  286. static const int ide_irq[2] = { 14, 15 };
  287. static const int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
  288. static const int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
  289. static const int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
  290. static const int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
  291. static fdctrl_t *floppy_controller;
  292. static void ebus_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
  293. uint32_t addr, uint32_t size, int type)
  294. {
  295. DPRINTF("Mapping region %d registers at %08x\n", region_num, addr);
  296. switch (region_num) {
  297. case 0:
  298. isa_mmio_init(addr, 0x1000000);
  299. break;
  300. case 1:
  301. isa_mmio_init(addr, 0x800000);
  302. break;
  303. }
  304. }
  305. /* EBUS (Eight bit bus) bridge */
  306. static void
  307. pci_ebus_init(PCIBus *bus, int devfn)
  308. {
  309. PCIDevice *s;
  310. s = pci_register_device(bus, "EBUS", sizeof(*s), devfn, NULL, NULL);
  311. pci_config_set_vendor_id(s->config, PCI_VENDOR_ID_SUN);
  312. pci_config_set_device_id(s->config, PCI_DEVICE_ID_SUN_EBUS);
  313. s->config[0x04] = 0x06; // command = bus master, pci mem
  314. s->config[0x05] = 0x00;
  315. s->config[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
  316. s->config[0x07] = 0x03; // status = medium devsel
  317. s->config[0x08] = 0x01; // revision
  318. s->config[0x09] = 0x00; // programming i/f
  319. pci_config_set_class(s->config, PCI_CLASS_BRIDGE_OTHER);
  320. s->config[0x0D] = 0x0a; // latency_timer
  321. s->config[0x0E] = 0x00; // header_type
  322. pci_register_io_region(s, 0, 0x1000000, PCI_ADDRESS_SPACE_MEM,
  323. ebus_mmio_mapfunc);
  324. pci_register_io_region(s, 1, 0x800000, PCI_ADDRESS_SPACE_MEM,
  325. ebus_mmio_mapfunc);
  326. }
  327. static void sun4uv_init(ram_addr_t RAM_size, int vga_ram_size,
  328. const char *boot_devices,
  329. const char *kernel_filename, const char *kernel_cmdline,
  330. const char *initrd_filename, const char *cpu_model,
  331. const struct hwdef *hwdef)
  332. {
  333. CPUState *env;
  334. char buf[1024];
  335. m48t59_t *nvram;
  336. int ret, linux_boot;
  337. unsigned int i;
  338. ram_addr_t ram_offset, prom_offset, vga_ram_offset;
  339. long initrd_size, kernel_size;
  340. PCIBus *pci_bus, *pci_bus2, *pci_bus3;
  341. QEMUBH *bh;
  342. qemu_irq *irq;
  343. int drive_index;
  344. BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
  345. BlockDriverState *fd[MAX_FD];
  346. void *fw_cfg;
  347. ResetData *reset_info;
  348. linux_boot = (kernel_filename != NULL);
  349. /* init CPUs */
  350. if (!cpu_model)
  351. cpu_model = hwdef->default_cpu_model;
  352. env = cpu_init(cpu_model);
  353. if (!env) {
  354. fprintf(stderr, "Unable to find Sparc CPU definition\n");
  355. exit(1);
  356. }
  357. bh = qemu_bh_new(tick_irq, env);
  358. env->tick = ptimer_init(bh);
  359. ptimer_set_period(env->tick, 1ULL);
  360. bh = qemu_bh_new(stick_irq, env);
  361. env->stick = ptimer_init(bh);
  362. ptimer_set_period(env->stick, 1ULL);
  363. bh = qemu_bh_new(hstick_irq, env);
  364. env->hstick = ptimer_init(bh);
  365. ptimer_set_period(env->hstick, 1ULL);
  366. reset_info = qemu_mallocz(sizeof(ResetData));
  367. reset_info->env = env;
  368. reset_info->reset_addr = hwdef->prom_addr + 0x40ULL;
  369. qemu_register_reset(main_cpu_reset, reset_info);
  370. main_cpu_reset(reset_info);
  371. // Override warm reset address with cold start address
  372. env->pc = hwdef->prom_addr + 0x20ULL;
  373. env->npc = env->pc + 4;
  374. /* allocate RAM */
  375. ram_offset = qemu_ram_alloc(RAM_size);
  376. cpu_register_physical_memory(0, RAM_size, ram_offset);
  377. prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
  378. cpu_register_physical_memory(hwdef->prom_addr,
  379. (PROM_SIZE_MAX + TARGET_PAGE_SIZE) &
  380. TARGET_PAGE_MASK,
  381. prom_offset | IO_MEM_ROM);
  382. if (bios_name == NULL)
  383. bios_name = PROM_FILENAME;
  384. snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
  385. ret = load_elf(buf, hwdef->prom_addr - PROM_VADDR, NULL, NULL, NULL);
  386. if (ret < 0) {
  387. ret = load_image_targphys(buf, hwdef->prom_addr,
  388. (PROM_SIZE_MAX + TARGET_PAGE_SIZE) &
  389. TARGET_PAGE_MASK);
  390. if (ret < 0) {
  391. fprintf(stderr, "qemu: could not load prom '%s'\n",
  392. buf);
  393. exit(1);
  394. }
  395. }
  396. kernel_size = 0;
  397. initrd_size = 0;
  398. if (linux_boot) {
  399. /* XXX: put correct offset */
  400. kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL);
  401. if (kernel_size < 0)
  402. kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
  403. ram_size - KERNEL_LOAD_ADDR);
  404. if (kernel_size < 0)
  405. kernel_size = load_image_targphys(kernel_filename,
  406. KERNEL_LOAD_ADDR,
  407. ram_size - KERNEL_LOAD_ADDR);
  408. if (kernel_size < 0) {
  409. fprintf(stderr, "qemu: could not load kernel '%s'\n",
  410. kernel_filename);
  411. exit(1);
  412. }
  413. /* load initrd */
  414. if (initrd_filename) {
  415. initrd_size = load_image_targphys(initrd_filename,
  416. INITRD_LOAD_ADDR,
  417. ram_size - INITRD_LOAD_ADDR);
  418. if (initrd_size < 0) {
  419. fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
  420. initrd_filename);
  421. exit(1);
  422. }
  423. }
  424. if (initrd_size > 0) {
  425. for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
  426. if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
  427. stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
  428. stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
  429. break;
  430. }
  431. }
  432. }
  433. }
  434. pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, NULL, &pci_bus2,
  435. &pci_bus3);
  436. isa_mem_base = VGA_BASE;
  437. vga_ram_offset = qemu_ram_alloc(vga_ram_size);
  438. pci_vga_init(pci_bus, phys_ram_base + vga_ram_offset,
  439. vga_ram_offset, vga_ram_size,
  440. 0, 0);
  441. // XXX Should be pci_bus3
  442. pci_ebus_init(pci_bus, -1);
  443. i = 0;
  444. if (hwdef->console_serial_base) {
  445. serial_mm_init(hwdef->console_serial_base, 0, NULL, 115200,
  446. serial_hds[i], 1);
  447. i++;
  448. }
  449. for(; i < MAX_SERIAL_PORTS; i++) {
  450. if (serial_hds[i]) {
  451. serial_init(serial_io[i], NULL/*serial_irq[i]*/, 115200,
  452. serial_hds[i]);
  453. }
  454. }
  455. for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
  456. if (parallel_hds[i]) {
  457. parallel_init(parallel_io[i], NULL/*parallel_irq[i]*/,
  458. parallel_hds[i]);
  459. }
  460. }
  461. for(i = 0; i < nb_nics; i++)
  462. pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
  463. irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
  464. if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
  465. fprintf(stderr, "qemu: too many IDE bus\n");
  466. exit(1);
  467. }
  468. for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
  469. drive_index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS,
  470. i % MAX_IDE_DEVS);
  471. if (drive_index != -1)
  472. hd[i] = drives_table[drive_index].bdrv;
  473. else
  474. hd[i] = NULL;
  475. }
  476. pci_cmd646_ide_init(pci_bus, hd, 1);
  477. /* FIXME: wire up interrupts. */
  478. i8042_init(NULL/*1*/, NULL/*12*/, 0x60);
  479. for(i = 0; i < MAX_FD; i++) {
  480. drive_index = drive_get_index(IF_FLOPPY, 0, i);
  481. if (drive_index != -1)
  482. fd[i] = drives_table[drive_index].bdrv;
  483. else
  484. fd[i] = NULL;
  485. }
  486. floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd);
  487. nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59);
  488. sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices,
  489. KERNEL_LOAD_ADDR, kernel_size,
  490. kernel_cmdline,
  491. INITRD_LOAD_ADDR, initrd_size,
  492. /* XXX: need an option to load a NVRAM image */
  493. 0,
  494. graphic_width, graphic_height, graphic_depth,
  495. (uint8_t *)&nd_table[0].macaddr);
  496. fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
  497. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  498. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  499. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  500. }
  501. enum {
  502. sun4u_id = 0,
  503. sun4v_id = 64,
  504. niagara_id,
  505. };
  506. static const struct hwdef hwdefs[] = {
  507. /* Sun4u generic PC-like machine */
  508. {
  509. .default_cpu_model = "TI UltraSparc II",
  510. .machine_id = sun4u_id,
  511. .prom_addr = 0x1fff0000000ULL,
  512. .console_serial_base = 0,
  513. },
  514. /* Sun4v generic PC-like machine */
  515. {
  516. .default_cpu_model = "Sun UltraSparc T1",
  517. .machine_id = sun4v_id,
  518. .prom_addr = 0x1fff0000000ULL,
  519. .console_serial_base = 0,
  520. },
  521. /* Sun4v generic Niagara machine */
  522. {
  523. .default_cpu_model = "Sun UltraSparc T1",
  524. .machine_id = niagara_id,
  525. .prom_addr = 0xfff0000000ULL,
  526. .console_serial_base = 0xfff0c2c000ULL,
  527. },
  528. };
  529. /* Sun4u hardware initialisation */
  530. static void sun4u_init(ram_addr_t RAM_size, int vga_ram_size,
  531. const char *boot_devices,
  532. const char *kernel_filename, const char *kernel_cmdline,
  533. const char *initrd_filename, const char *cpu_model)
  534. {
  535. sun4uv_init(RAM_size, vga_ram_size, boot_devices, kernel_filename,
  536. kernel_cmdline, initrd_filename, cpu_model, &hwdefs[0]);
  537. }
  538. /* Sun4v hardware initialisation */
  539. static void sun4v_init(ram_addr_t RAM_size, int vga_ram_size,
  540. const char *boot_devices,
  541. const char *kernel_filename, const char *kernel_cmdline,
  542. const char *initrd_filename, const char *cpu_model)
  543. {
  544. sun4uv_init(RAM_size, vga_ram_size, boot_devices, kernel_filename,
  545. kernel_cmdline, initrd_filename, cpu_model, &hwdefs[1]);
  546. }
  547. /* Niagara hardware initialisation */
  548. static void niagara_init(ram_addr_t RAM_size, int vga_ram_size,
  549. const char *boot_devices,
  550. const char *kernel_filename, const char *kernel_cmdline,
  551. const char *initrd_filename, const char *cpu_model)
  552. {
  553. sun4uv_init(RAM_size, vga_ram_size, boot_devices, kernel_filename,
  554. kernel_cmdline, initrd_filename, cpu_model, &hwdefs[2]);
  555. }
  556. QEMUMachine sun4u_machine = {
  557. .name = "sun4u",
  558. .desc = "Sun4u platform",
  559. .init = sun4u_init,
  560. .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE,
  561. .nodisk_ok = 1,
  562. .max_cpus = 1, // XXX for now
  563. };
  564. QEMUMachine sun4v_machine = {
  565. .name = "sun4v",
  566. .desc = "Sun4v platform",
  567. .init = sun4v_init,
  568. .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE,
  569. .nodisk_ok = 1,
  570. .max_cpus = 1, // XXX for now
  571. };
  572. QEMUMachine niagara_machine = {
  573. .name = "Niagara",
  574. .desc = "Sun4v platform, Niagara",
  575. .init = niagara_init,
  576. .ram_require = PROM_SIZE_MAX + VGA_RAM_SIZE,
  577. .nodisk_ok = 1,
  578. .max_cpus = 1, // XXX for now
  579. };