]> Git Repo - qemu.git/blame_incremental - hw/sun4m.c
Sparc32: convert boot prom to qdev
[qemu.git] / hw / sun4m.c
... / ...
CommitLineData
1/*
2 * QEMU Sun4m & Sun4d & Sun4c System Emulator
3 *
4 * Copyright (c) 2003-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 "sysbus.h"
25#include "qemu-timer.h"
26#include "sun4m.h"
27#include "nvram.h"
28#include "sparc32_dma.h"
29#include "fdc.h"
30#include "sysemu.h"
31#include "net.h"
32#include "boards.h"
33#include "firmware_abi.h"
34#include "scsi.h"
35#include "pc.h"
36#include "isa.h"
37#include "fw_cfg.h"
38#include "escc.h"
39
40//#define DEBUG_IRQ
41
42/*
43 * Sun4m architecture was used in the following machines:
44 *
45 * SPARCserver 6xxMP/xx
46 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
47 * SPARCclassic X (4/10)
48 * SPARCstation LX/ZX (4/30)
49 * SPARCstation Voyager
50 * SPARCstation 10/xx, SPARCserver 10/xx
51 * SPARCstation 5, SPARCserver 5
52 * SPARCstation 20/xx, SPARCserver 20
53 * SPARCstation 4
54 *
55 * Sun4d architecture was used in the following machines:
56 *
57 * SPARCcenter 2000
58 * SPARCserver 1000
59 *
60 * Sun4c architecture was used in the following machines:
61 * SPARCstation 1/1+, SPARCserver 1/1+
62 * SPARCstation SLC
63 * SPARCstation IPC
64 * SPARCstation ELC
65 * SPARCstation IPX
66 *
67 * See for example: http://www.sunhelp.org/faq/sunref1.html
68 */
69
70#ifdef DEBUG_IRQ
71#define DPRINTF(fmt, ...) \
72 do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
73#else
74#define DPRINTF(fmt, ...)
75#endif
76
77#define KERNEL_LOAD_ADDR 0x00004000
78#define CMDLINE_ADDR 0x007ff000
79#define INITRD_LOAD_ADDR 0x00800000
80#define PROM_SIZE_MAX (1024 * 1024)
81#define PROM_VADDR 0xffd00000
82#define PROM_FILENAME "openbios-sparc32"
83#define CFG_ADDR 0xd00000510ULL
84#define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
85
86#define MAX_CPUS 16
87#define MAX_PILS 16
88
89#define ESCC_CLOCK 4915200
90
91struct sun4m_hwdef {
92 target_phys_addr_t iommu_base, slavio_base;
93 target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
94 target_phys_addr_t serial_base, fd_base;
95 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
96 target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
97 target_phys_addr_t ecc_base;
98 uint32_t ecc_version;
99 long vram_size, nvram_size;
100 // IRQ numbers are not PIL ones, but master interrupt controller
101 // register bit numbers
102 int esp_irq, le_irq, clock_irq, clock1_irq;
103 int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq;
104 uint8_t nvram_machine_id;
105 uint16_t machine_id;
106 uint32_t iommu_version;
107 uint32_t intbit_to_level[32];
108 uint64_t max_mem;
109 const char * const default_cpu_model;
110};
111
112#define MAX_IOUNITS 5
113
114struct sun4d_hwdef {
115 target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
116 target_phys_addr_t counter_base, nvram_base, ms_kb_base;
117 target_phys_addr_t serial_base;
118 target_phys_addr_t espdma_base, esp_base;
119 target_phys_addr_t ledma_base, le_base;
120 target_phys_addr_t tcx_base;
121 target_phys_addr_t sbi_base;
122 unsigned long vram_size, nvram_size;
123 // IRQ numbers are not PIL ones, but SBI register bit numbers
124 int esp_irq, le_irq, clock_irq, clock1_irq;
125 int ser_irq, ms_kb_irq, me_irq;
126 uint8_t nvram_machine_id;
127 uint16_t machine_id;
128 uint32_t iounit_version;
129 uint64_t max_mem;
130 const char * const default_cpu_model;
131};
132
133struct sun4c_hwdef {
134 target_phys_addr_t iommu_base, slavio_base;
135 target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
136 target_phys_addr_t serial_base, fd_base;
137 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
138 target_phys_addr_t tcx_base, aux1_base;
139 long vram_size, nvram_size;
140 // IRQ numbers are not PIL ones, but master interrupt controller
141 // register bit numbers
142 int esp_irq, le_irq, clock_irq, clock1_irq;
143 int ser_irq, ms_kb_irq, fd_irq, me_irq;
144 uint8_t nvram_machine_id;
145 uint16_t machine_id;
146 uint32_t iommu_version;
147 uint32_t intbit_to_level[32];
148 uint64_t max_mem;
149 const char * const default_cpu_model;
150};
151
152int DMA_get_channel_mode (int nchan)
153{
154 return 0;
155}
156int DMA_read_memory (int nchan, void *buf, int pos, int size)
157{
158 return 0;
159}
160int DMA_write_memory (int nchan, void *buf, int pos, int size)
161{
162 return 0;
163}
164void DMA_hold_DREQ (int nchan) {}
165void DMA_release_DREQ (int nchan) {}
166void DMA_schedule(int nchan) {}
167void DMA_init (int high_page_enable) {}
168void DMA_register_channel (int nchan,
169 DMA_transfer_handler transfer_handler,
170 void *opaque)
171{
172}
173
174static int fw_cfg_boot_set(void *opaque, const char *boot_device)
175{
176 fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
177 return 0;
178}
179
180static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
181 const char *boot_devices, ram_addr_t RAM_size,
182 uint32_t kernel_size,
183 int width, int height, int depth,
184 int nvram_machine_id, const char *arch)
185{
186 unsigned int i;
187 uint32_t start, end;
188 uint8_t image[0x1ff0];
189 struct OpenBIOS_nvpart_v1 *part_header;
190
191 memset(image, '\0', sizeof(image));
192
193 start = 0;
194
195 // OpenBIOS nvram variables
196 // Variable partition
197 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
198 part_header->signature = OPENBIOS_PART_SYSTEM;
199 pstrcpy(part_header->name, sizeof(part_header->name), "system");
200
201 end = start + sizeof(struct OpenBIOS_nvpart_v1);
202 for (i = 0; i < nb_prom_envs; i++)
203 end = OpenBIOS_set_var(image, end, prom_envs[i]);
204
205 // End marker
206 image[end++] = '\0';
207
208 end = start + ((end - start + 15) & ~15);
209 OpenBIOS_finish_partition(part_header, end - start);
210
211 // free partition
212 start = end;
213 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
214 part_header->signature = OPENBIOS_PART_FREE;
215 pstrcpy(part_header->name, sizeof(part_header->name), "free");
216
217 end = 0x1fd0;
218 OpenBIOS_finish_partition(part_header, end - start);
219
220 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
221 nvram_machine_id);
222
223 for (i = 0; i < sizeof(image); i++)
224 m48t59_write(nvram, i, image[i]);
225}
226
227static void *slavio_intctl;
228
229void pic_info(Monitor *mon)
230{
231 if (slavio_intctl)
232 slavio_pic_info(mon, slavio_intctl);
233}
234
235void irq_info(Monitor *mon)
236{
237 if (slavio_intctl)
238 slavio_irq_info(mon, slavio_intctl);
239}
240
241void cpu_check_irqs(CPUState *env)
242{
243 if (env->pil_in && (env->interrupt_index == 0 ||
244 (env->interrupt_index & ~15) == TT_EXTINT)) {
245 unsigned int i;
246
247 for (i = 15; i > 0; i--) {
248 if (env->pil_in & (1 << i)) {
249 int old_interrupt = env->interrupt_index;
250
251 env->interrupt_index = TT_EXTINT | i;
252 if (old_interrupt != env->interrupt_index) {
253 DPRINTF("Set CPU IRQ %d\n", i);
254 cpu_interrupt(env, CPU_INTERRUPT_HARD);
255 }
256 break;
257 }
258 }
259 } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
260 DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
261 env->interrupt_index = 0;
262 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
263 }
264}
265
266static void cpu_set_irq(void *opaque, int irq, int level)
267{
268 CPUState *env = opaque;
269
270 if (level) {
271 DPRINTF("Raise CPU IRQ %d\n", irq);
272 env->halted = 0;
273 env->pil_in |= 1 << irq;
274 cpu_check_irqs(env);
275 } else {
276 DPRINTF("Lower CPU IRQ %d\n", irq);
277 env->pil_in &= ~(1 << irq);
278 cpu_check_irqs(env);
279 }
280}
281
282static void dummy_cpu_set_irq(void *opaque, int irq, int level)
283{
284}
285
286static void *slavio_misc;
287
288void qemu_system_powerdown(void)
289{
290 slavio_set_power_fail(slavio_misc, 1);
291}
292
293static void main_cpu_reset(void *opaque)
294{
295 CPUState *env = opaque;
296
297 cpu_reset(env);
298 env->halted = 0;
299}
300
301static void secondary_cpu_reset(void *opaque)
302{
303 CPUState *env = opaque;
304
305 cpu_reset(env);
306 env->halted = 1;
307}
308
309static void cpu_halt_signal(void *opaque, int irq, int level)
310{
311 if (level && cpu_single_env)
312 cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT);
313}
314
315static unsigned long sun4m_load_kernel(const char *kernel_filename,
316 const char *initrd_filename,
317 ram_addr_t RAM_size)
318{
319 int linux_boot;
320 unsigned int i;
321 long initrd_size, kernel_size;
322
323 linux_boot = (kernel_filename != NULL);
324
325 kernel_size = 0;
326 if (linux_boot) {
327 kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL,
328 NULL);
329 if (kernel_size < 0)
330 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
331 RAM_size - KERNEL_LOAD_ADDR);
332 if (kernel_size < 0)
333 kernel_size = load_image_targphys(kernel_filename,
334 KERNEL_LOAD_ADDR,
335 RAM_size - KERNEL_LOAD_ADDR);
336 if (kernel_size < 0) {
337 fprintf(stderr, "qemu: could not load kernel '%s'\n",
338 kernel_filename);
339 exit(1);
340 }
341
342 /* load initrd */
343 initrd_size = 0;
344 if (initrd_filename) {
345 initrd_size = load_image_targphys(initrd_filename,
346 INITRD_LOAD_ADDR,
347 RAM_size - INITRD_LOAD_ADDR);
348 if (initrd_size < 0) {
349 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
350 initrd_filename);
351 exit(1);
352 }
353 }
354 if (initrd_size > 0) {
355 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
356 if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
357 stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
358 stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
359 break;
360 }
361 }
362 }
363 }
364 return kernel_size;
365}
366
367static void lance_init(NICInfo *nd, target_phys_addr_t leaddr,
368 void *dma_opaque, qemu_irq irq, qemu_irq *reset)
369{
370 DeviceState *dev;
371 SysBusDevice *s;
372
373 qemu_check_nic_model(&nd_table[0], "lance");
374
375 dev = qdev_create(NULL, "lance");
376 qdev_set_netdev(dev, nd);
377 qdev_set_prop_ptr(dev, "dma", dma_opaque);
378 qdev_init(dev);
379 s = sysbus_from_qdev(dev);
380 sysbus_mmio_map(s, 0, leaddr);
381 sysbus_connect_irq(s, 0, irq);
382 *reset = qdev_get_gpio_in(dev, 0);
383}
384
385/* NCR89C100/MACIO Internal ID register */
386static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
387
388static void idreg_init(target_phys_addr_t addr)
389{
390 DeviceState *dev;
391 SysBusDevice *s;
392
393 dev = qdev_create(NULL, "macio_idreg");
394 qdev_init(dev);
395 s = sysbus_from_qdev(dev);
396
397 sysbus_mmio_map(s, 0, addr);
398 cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data));
399}
400
401static void idreg_init1(SysBusDevice *dev)
402{
403 ram_addr_t idreg_offset;
404
405 idreg_offset = qemu_ram_alloc(sizeof(idreg_data));
406 sysbus_init_mmio(dev, sizeof(idreg_data), idreg_offset | IO_MEM_ROM);
407}
408
409static SysBusDeviceInfo idreg_info = {
410 .init = idreg_init1,
411 .qdev.name = "macio_idreg",
412 .qdev.size = sizeof(SysBusDevice),
413 .qdev.props = (DevicePropList[]) {
414 {.name = NULL}
415 }
416};
417
418static void idreg_register_devices(void)
419{
420 sysbus_register_withprop(&idreg_info);
421}
422
423device_init(idreg_register_devices);
424
425/* Boot PROM (OpenBIOS) */
426static void prom_init(target_phys_addr_t addr, const char *bios_name)
427{
428 DeviceState *dev;
429 SysBusDevice *s;
430 char *filename;
431 int ret;
432
433 dev = qdev_create(NULL, "openprom");
434 qdev_init(dev);
435 s = sysbus_from_qdev(dev);
436
437 sysbus_mmio_map(s, 0, addr);
438
439 /* load boot prom */
440 if (bios_name == NULL) {
441 bios_name = PROM_FILENAME;
442 }
443 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
444 if (filename) {
445 ret = load_elf(filename, addr - PROM_VADDR, NULL, NULL, NULL);
446 if (ret < 0 || ret > PROM_SIZE_MAX) {
447 ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
448 }
449 qemu_free(filename);
450 } else {
451 ret = -1;
452 }
453 if (ret < 0 || ret > PROM_SIZE_MAX) {
454 fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
455 exit(1);
456 }
457}
458
459static void prom_init1(SysBusDevice *dev)
460{
461 ram_addr_t prom_offset;
462
463 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
464 sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM);
465}
466
467static SysBusDeviceInfo prom_info = {
468 .init = prom_init1,
469 .qdev.name = "openprom",
470 .qdev.size = sizeof(SysBusDevice),
471 .qdev.props = (DevicePropList[]) {
472 {.name = NULL}
473 }
474};
475
476static void prom_register_devices(void)
477{
478 sysbus_register_withprop(&prom_info);
479}
480
481device_init(prom_register_devices);
482
483static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
484 const char *boot_device,
485 const char *kernel_filename,
486 const char *kernel_cmdline,
487 const char *initrd_filename, const char *cpu_model)
488
489{
490 CPUState *env, *envs[MAX_CPUS];
491 unsigned int i;
492 void *iommu, *espdma, *ledma, *nvram;
493 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
494 espdma_irq, ledma_irq;
495 qemu_irq *esp_reset, *le_reset;
496 qemu_irq fdc_tc;
497 qemu_irq *cpu_halt;
498 ram_addr_t ram_offset;
499 unsigned long kernel_size;
500 BlockDriverState *fd[MAX_FD];
501 int drive_index;
502 void *fw_cfg;
503
504 /* init CPUs */
505 if (!cpu_model)
506 cpu_model = hwdef->default_cpu_model;
507
508 for(i = 0; i < smp_cpus; i++) {
509 env = cpu_init(cpu_model);
510 if (!env) {
511 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
512 exit(1);
513 }
514 cpu_sparc_set_id(env, i);
515 envs[i] = env;
516 if (i == 0) {
517 qemu_register_reset(main_cpu_reset, env);
518 } else {
519 qemu_register_reset(secondary_cpu_reset, env);
520 env->halted = 1;
521 }
522 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
523 env->prom_addr = hwdef->slavio_base;
524 }
525
526 for (i = smp_cpus; i < MAX_CPUS; i++)
527 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
528
529
530 /* allocate RAM */
531 if ((uint64_t)RAM_size > hwdef->max_mem) {
532 fprintf(stderr,
533 "qemu: Too much memory for this machine: %d, maximum %d\n",
534 (unsigned int)(RAM_size / (1024 * 1024)),
535 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
536 exit(1);
537 }
538 ram_offset = qemu_ram_alloc(RAM_size);
539 cpu_register_physical_memory(0, RAM_size, ram_offset);
540
541 /* set up devices */
542 prom_init(hwdef->slavio_base, bios_name);
543
544 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
545 hwdef->intctl_base + 0x10000ULL,
546 &hwdef->intbit_to_level[0],
547 &slavio_irq, &slavio_cpu_irq,
548 cpu_irqs,
549 hwdef->clock_irq);
550
551 if (hwdef->idreg_base) {
552 idreg_init(hwdef->idreg_base);
553 }
554
555 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
556 slavio_irq[hwdef->me_irq]);
557
558 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
559 iommu, &espdma_irq, &esp_reset);
560
561 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
562 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
563 &le_reset);
564
565 if (graphic_depth != 8 && graphic_depth != 24) {
566 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
567 exit (1);
568 }
569 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
570 graphic_depth);
571
572 lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq, le_reset);
573
574 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
575 hwdef->nvram_size, 8);
576
577 slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
578 slavio_cpu_irq, smp_cpus);
579
580 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
581 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
582 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
583 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
584 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq], slavio_irq[hwdef->ser_irq],
585 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
586
587 cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
588 slavio_misc = slavio_misc_init(hwdef->slavio_base,
589 hwdef->aux1_base, hwdef->aux2_base,
590 slavio_irq[hwdef->me_irq], fdc_tc);
591 if (hwdef->apc_base) {
592 apc_init(hwdef->apc_base, cpu_halt[0]);
593 }
594
595 if (hwdef->fd_base) {
596 /* there is zero or one floppy drive */
597 memset(fd, 0, sizeof(fd));
598 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
599 if (drive_index != -1)
600 fd[0] = drives_table[drive_index].bdrv;
601
602 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
603 &fdc_tc);
604 }
605
606 if (drive_get_max_bus(IF_SCSI) > 0) {
607 fprintf(stderr, "qemu: too many SCSI bus\n");
608 exit(1);
609 }
610
611 esp_init(hwdef->esp_base, 2,
612 espdma_memory_read, espdma_memory_write,
613 espdma, espdma_irq, esp_reset);
614
615 if (hwdef->cs_base) {
616 sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
617 slavio_irq[hwdef->cs_irq]);
618 }
619
620 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
621 RAM_size);
622
623 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
624 boot_device, RAM_size, kernel_size, graphic_width,
625 graphic_height, graphic_depth, hwdef->nvram_machine_id,
626 "Sun4m");
627
628 if (hwdef->ecc_base)
629 ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
630 hwdef->ecc_version);
631
632 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
633 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
634 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
635 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
636 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
637 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
638 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
639 if (kernel_cmdline) {
640 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
641 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
642 } else {
643 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
644 }
645 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
646 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
647 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
648 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
649}
650
651enum {
652 ss2_id = 0,
653 ss5_id = 32,
654 vger_id,
655 lx_id,
656 ss4_id,
657 scls_id,
658 sbook_id,
659 ss10_id = 64,
660 ss20_id,
661 ss600mp_id,
662 ss1000_id = 96,
663 ss2000_id,
664};
665
666static const struct sun4m_hwdef sun4m_hwdefs[] = {
667 /* SS-5 */
668 {
669 .iommu_base = 0x10000000,
670 .tcx_base = 0x50000000,
671 .cs_base = 0x6c000000,
672 .slavio_base = 0x70000000,
673 .ms_kb_base = 0x71000000,
674 .serial_base = 0x71100000,
675 .nvram_base = 0x71200000,
676 .fd_base = 0x71400000,
677 .counter_base = 0x71d00000,
678 .intctl_base = 0x71e00000,
679 .idreg_base = 0x78000000,
680 .dma_base = 0x78400000,
681 .esp_base = 0x78800000,
682 .le_base = 0x78c00000,
683 .apc_base = 0x6a000000,
684 .aux1_base = 0x71900000,
685 .aux2_base = 0x71910000,
686 .vram_size = 0x00100000,
687 .nvram_size = 0x2000,
688 .esp_irq = 18,
689 .le_irq = 16,
690 .clock_irq = 7,
691 .clock1_irq = 19,
692 .ms_kb_irq = 14,
693 .ser_irq = 15,
694 .fd_irq = 22,
695 .me_irq = 30,
696 .cs_irq = 5,
697 .nvram_machine_id = 0x80,
698 .machine_id = ss5_id,
699 .iommu_version = 0x05000000,
700 .intbit_to_level = {
701 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
702 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
703 },
704 .max_mem = 0x10000000,
705 .default_cpu_model = "Fujitsu MB86904",
706 },
707 /* SS-10 */
708 {
709 .iommu_base = 0xfe0000000ULL,
710 .tcx_base = 0xe20000000ULL,
711 .slavio_base = 0xff0000000ULL,
712 .ms_kb_base = 0xff1000000ULL,
713 .serial_base = 0xff1100000ULL,
714 .nvram_base = 0xff1200000ULL,
715 .fd_base = 0xff1700000ULL,
716 .counter_base = 0xff1300000ULL,
717 .intctl_base = 0xff1400000ULL,
718 .idreg_base = 0xef0000000ULL,
719 .dma_base = 0xef0400000ULL,
720 .esp_base = 0xef0800000ULL,
721 .le_base = 0xef0c00000ULL,
722 .apc_base = 0xefa000000ULL, // XXX should not exist
723 .aux1_base = 0xff1800000ULL,
724 .aux2_base = 0xff1a01000ULL,
725 .ecc_base = 0xf00000000ULL,
726 .ecc_version = 0x10000000, // version 0, implementation 1
727 .vram_size = 0x00100000,
728 .nvram_size = 0x2000,
729 .esp_irq = 18,
730 .le_irq = 16,
731 .clock_irq = 7,
732 .clock1_irq = 19,
733 .ms_kb_irq = 14,
734 .ser_irq = 15,
735 .fd_irq = 22,
736 .me_irq = 30,
737 .ecc_irq = 28,
738 .nvram_machine_id = 0x72,
739 .machine_id = ss10_id,
740 .iommu_version = 0x03000000,
741 .intbit_to_level = {
742 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
743 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
744 },
745 .max_mem = 0xf00000000ULL,
746 .default_cpu_model = "TI SuperSparc II",
747 },
748 /* SS-600MP */
749 {
750 .iommu_base = 0xfe0000000ULL,
751 .tcx_base = 0xe20000000ULL,
752 .slavio_base = 0xff0000000ULL,
753 .ms_kb_base = 0xff1000000ULL,
754 .serial_base = 0xff1100000ULL,
755 .nvram_base = 0xff1200000ULL,
756 .counter_base = 0xff1300000ULL,
757 .intctl_base = 0xff1400000ULL,
758 .dma_base = 0xef0081000ULL,
759 .esp_base = 0xef0080000ULL,
760 .le_base = 0xef0060000ULL,
761 .apc_base = 0xefa000000ULL, // XXX should not exist
762 .aux1_base = 0xff1800000ULL,
763 .aux2_base = 0xff1a01000ULL, // XXX should not exist
764 .ecc_base = 0xf00000000ULL,
765 .ecc_version = 0x00000000, // version 0, implementation 0
766 .vram_size = 0x00100000,
767 .nvram_size = 0x2000,
768 .esp_irq = 18,
769 .le_irq = 16,
770 .clock_irq = 7,
771 .clock1_irq = 19,
772 .ms_kb_irq = 14,
773 .ser_irq = 15,
774 .fd_irq = 22,
775 .me_irq = 30,
776 .ecc_irq = 28,
777 .nvram_machine_id = 0x71,
778 .machine_id = ss600mp_id,
779 .iommu_version = 0x01000000,
780 .intbit_to_level = {
781 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
782 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
783 },
784 .max_mem = 0xf00000000ULL,
785 .default_cpu_model = "TI SuperSparc II",
786 },
787 /* SS-20 */
788 {
789 .iommu_base = 0xfe0000000ULL,
790 .tcx_base = 0xe20000000ULL,
791 .slavio_base = 0xff0000000ULL,
792 .ms_kb_base = 0xff1000000ULL,
793 .serial_base = 0xff1100000ULL,
794 .nvram_base = 0xff1200000ULL,
795 .fd_base = 0xff1700000ULL,
796 .counter_base = 0xff1300000ULL,
797 .intctl_base = 0xff1400000ULL,
798 .idreg_base = 0xef0000000ULL,
799 .dma_base = 0xef0400000ULL,
800 .esp_base = 0xef0800000ULL,
801 .le_base = 0xef0c00000ULL,
802 .apc_base = 0xefa000000ULL, // XXX should not exist
803 .aux1_base = 0xff1800000ULL,
804 .aux2_base = 0xff1a01000ULL,
805 .ecc_base = 0xf00000000ULL,
806 .ecc_version = 0x20000000, // version 0, implementation 2
807 .vram_size = 0x00100000,
808 .nvram_size = 0x2000,
809 .esp_irq = 18,
810 .le_irq = 16,
811 .clock_irq = 7,
812 .clock1_irq = 19,
813 .ms_kb_irq = 14,
814 .ser_irq = 15,
815 .fd_irq = 22,
816 .me_irq = 30,
817 .ecc_irq = 28,
818 .nvram_machine_id = 0x72,
819 .machine_id = ss20_id,
820 .iommu_version = 0x13000000,
821 .intbit_to_level = {
822 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
823 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
824 },
825 .max_mem = 0xf00000000ULL,
826 .default_cpu_model = "TI SuperSparc II",
827 },
828 /* Voyager */
829 {
830 .iommu_base = 0x10000000,
831 .tcx_base = 0x50000000,
832 .slavio_base = 0x70000000,
833 .ms_kb_base = 0x71000000,
834 .serial_base = 0x71100000,
835 .nvram_base = 0x71200000,
836 .fd_base = 0x71400000,
837 .counter_base = 0x71d00000,
838 .intctl_base = 0x71e00000,
839 .idreg_base = 0x78000000,
840 .dma_base = 0x78400000,
841 .esp_base = 0x78800000,
842 .le_base = 0x78c00000,
843 .apc_base = 0x71300000, // pmc
844 .aux1_base = 0x71900000,
845 .aux2_base = 0x71910000,
846 .vram_size = 0x00100000,
847 .nvram_size = 0x2000,
848 .esp_irq = 18,
849 .le_irq = 16,
850 .clock_irq = 7,
851 .clock1_irq = 19,
852 .ms_kb_irq = 14,
853 .ser_irq = 15,
854 .fd_irq = 22,
855 .me_irq = 30,
856 .nvram_machine_id = 0x80,
857 .machine_id = vger_id,
858 .iommu_version = 0x05000000,
859 .intbit_to_level = {
860 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
861 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
862 },
863 .max_mem = 0x10000000,
864 .default_cpu_model = "Fujitsu MB86904",
865 },
866 /* LX */
867 {
868 .iommu_base = 0x10000000,
869 .tcx_base = 0x50000000,
870 .slavio_base = 0x70000000,
871 .ms_kb_base = 0x71000000,
872 .serial_base = 0x71100000,
873 .nvram_base = 0x71200000,
874 .fd_base = 0x71400000,
875 .counter_base = 0x71d00000,
876 .intctl_base = 0x71e00000,
877 .idreg_base = 0x78000000,
878 .dma_base = 0x78400000,
879 .esp_base = 0x78800000,
880 .le_base = 0x78c00000,
881 .aux1_base = 0x71900000,
882 .aux2_base = 0x71910000,
883 .vram_size = 0x00100000,
884 .nvram_size = 0x2000,
885 .esp_irq = 18,
886 .le_irq = 16,
887 .clock_irq = 7,
888 .clock1_irq = 19,
889 .ms_kb_irq = 14,
890 .ser_irq = 15,
891 .fd_irq = 22,
892 .me_irq = 30,
893 .nvram_machine_id = 0x80,
894 .machine_id = lx_id,
895 .iommu_version = 0x04000000,
896 .intbit_to_level = {
897 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
898 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
899 },
900 .max_mem = 0x10000000,
901 .default_cpu_model = "TI MicroSparc I",
902 },
903 /* SS-4 */
904 {
905 .iommu_base = 0x10000000,
906 .tcx_base = 0x50000000,
907 .cs_base = 0x6c000000,
908 .slavio_base = 0x70000000,
909 .ms_kb_base = 0x71000000,
910 .serial_base = 0x71100000,
911 .nvram_base = 0x71200000,
912 .fd_base = 0x71400000,
913 .counter_base = 0x71d00000,
914 .intctl_base = 0x71e00000,
915 .idreg_base = 0x78000000,
916 .dma_base = 0x78400000,
917 .esp_base = 0x78800000,
918 .le_base = 0x78c00000,
919 .apc_base = 0x6a000000,
920 .aux1_base = 0x71900000,
921 .aux2_base = 0x71910000,
922 .vram_size = 0x00100000,
923 .nvram_size = 0x2000,
924 .esp_irq = 18,
925 .le_irq = 16,
926 .clock_irq = 7,
927 .clock1_irq = 19,
928 .ms_kb_irq = 14,
929 .ser_irq = 15,
930 .fd_irq = 22,
931 .me_irq = 30,
932 .cs_irq = 5,
933 .nvram_machine_id = 0x80,
934 .machine_id = ss4_id,
935 .iommu_version = 0x05000000,
936 .intbit_to_level = {
937 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
938 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
939 },
940 .max_mem = 0x10000000,
941 .default_cpu_model = "Fujitsu MB86904",
942 },
943 /* SPARCClassic */
944 {
945 .iommu_base = 0x10000000,
946 .tcx_base = 0x50000000,
947 .slavio_base = 0x70000000,
948 .ms_kb_base = 0x71000000,
949 .serial_base = 0x71100000,
950 .nvram_base = 0x71200000,
951 .fd_base = 0x71400000,
952 .counter_base = 0x71d00000,
953 .intctl_base = 0x71e00000,
954 .idreg_base = 0x78000000,
955 .dma_base = 0x78400000,
956 .esp_base = 0x78800000,
957 .le_base = 0x78c00000,
958 .apc_base = 0x6a000000,
959 .aux1_base = 0x71900000,
960 .aux2_base = 0x71910000,
961 .vram_size = 0x00100000,
962 .nvram_size = 0x2000,
963 .esp_irq = 18,
964 .le_irq = 16,
965 .clock_irq = 7,
966 .clock1_irq = 19,
967 .ms_kb_irq = 14,
968 .ser_irq = 15,
969 .fd_irq = 22,
970 .me_irq = 30,
971 .nvram_machine_id = 0x80,
972 .machine_id = scls_id,
973 .iommu_version = 0x05000000,
974 .intbit_to_level = {
975 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
976 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
977 },
978 .max_mem = 0x10000000,
979 .default_cpu_model = "TI MicroSparc I",
980 },
981 /* SPARCbook */
982 {
983 .iommu_base = 0x10000000,
984 .tcx_base = 0x50000000, // XXX
985 .slavio_base = 0x70000000,
986 .ms_kb_base = 0x71000000,
987 .serial_base = 0x71100000,
988 .nvram_base = 0x71200000,
989 .fd_base = 0x71400000,
990 .counter_base = 0x71d00000,
991 .intctl_base = 0x71e00000,
992 .idreg_base = 0x78000000,
993 .dma_base = 0x78400000,
994 .esp_base = 0x78800000,
995 .le_base = 0x78c00000,
996 .apc_base = 0x6a000000,
997 .aux1_base = 0x71900000,
998 .aux2_base = 0x71910000,
999 .vram_size = 0x00100000,
1000 .nvram_size = 0x2000,
1001 .esp_irq = 18,
1002 .le_irq = 16,
1003 .clock_irq = 7,
1004 .clock1_irq = 19,
1005 .ms_kb_irq = 14,
1006 .ser_irq = 15,
1007 .fd_irq = 22,
1008 .me_irq = 30,
1009 .nvram_machine_id = 0x80,
1010 .machine_id = sbook_id,
1011 .iommu_version = 0x05000000,
1012 .intbit_to_level = {
1013 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
1014 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
1015 },
1016 .max_mem = 0x10000000,
1017 .default_cpu_model = "TI MicroSparc I",
1018 },
1019};
1020
1021/* SPARCstation 5 hardware initialisation */
1022static void ss5_init(ram_addr_t RAM_size,
1023 const char *boot_device,
1024 const char *kernel_filename, const char *kernel_cmdline,
1025 const char *initrd_filename, const char *cpu_model)
1026{
1027 sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
1028 kernel_cmdline, initrd_filename, cpu_model);
1029}
1030
1031/* SPARCstation 10 hardware initialisation */
1032static void ss10_init(ram_addr_t RAM_size,
1033 const char *boot_device,
1034 const char *kernel_filename, const char *kernel_cmdline,
1035 const char *initrd_filename, const char *cpu_model)
1036{
1037 sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
1038 kernel_cmdline, initrd_filename, cpu_model);
1039}
1040
1041/* SPARCserver 600MP hardware initialisation */
1042static void ss600mp_init(ram_addr_t RAM_size,
1043 const char *boot_device,
1044 const char *kernel_filename,
1045 const char *kernel_cmdline,
1046 const char *initrd_filename, const char *cpu_model)
1047{
1048 sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
1049 kernel_cmdline, initrd_filename, cpu_model);
1050}
1051
1052/* SPARCstation 20 hardware initialisation */
1053static void ss20_init(ram_addr_t RAM_size,
1054 const char *boot_device,
1055 const char *kernel_filename, const char *kernel_cmdline,
1056 const char *initrd_filename, const char *cpu_model)
1057{
1058 sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
1059 kernel_cmdline, initrd_filename, cpu_model);
1060}
1061
1062/* SPARCstation Voyager hardware initialisation */
1063static void vger_init(ram_addr_t RAM_size,
1064 const char *boot_device,
1065 const char *kernel_filename, const char *kernel_cmdline,
1066 const char *initrd_filename, const char *cpu_model)
1067{
1068 sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
1069 kernel_cmdline, initrd_filename, cpu_model);
1070}
1071
1072/* SPARCstation LX hardware initialisation */
1073static void ss_lx_init(ram_addr_t RAM_size,
1074 const char *boot_device,
1075 const char *kernel_filename, const char *kernel_cmdline,
1076 const char *initrd_filename, const char *cpu_model)
1077{
1078 sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
1079 kernel_cmdline, initrd_filename, cpu_model);
1080}
1081
1082/* SPARCstation 4 hardware initialisation */
1083static void ss4_init(ram_addr_t RAM_size,
1084 const char *boot_device,
1085 const char *kernel_filename, const char *kernel_cmdline,
1086 const char *initrd_filename, const char *cpu_model)
1087{
1088 sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
1089 kernel_cmdline, initrd_filename, cpu_model);
1090}
1091
1092/* SPARCClassic hardware initialisation */
1093static void scls_init(ram_addr_t RAM_size,
1094 const char *boot_device,
1095 const char *kernel_filename, const char *kernel_cmdline,
1096 const char *initrd_filename, const char *cpu_model)
1097{
1098 sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
1099 kernel_cmdline, initrd_filename, cpu_model);
1100}
1101
1102/* SPARCbook hardware initialisation */
1103static void sbook_init(ram_addr_t RAM_size,
1104 const char *boot_device,
1105 const char *kernel_filename, const char *kernel_cmdline,
1106 const char *initrd_filename, const char *cpu_model)
1107{
1108 sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
1109 kernel_cmdline, initrd_filename, cpu_model);
1110}
1111
1112static QEMUMachine ss5_machine = {
1113 .name = "SS-5",
1114 .desc = "Sun4m platform, SPARCstation 5",
1115 .init = ss5_init,
1116 .use_scsi = 1,
1117 .is_default = 1,
1118};
1119
1120static QEMUMachine ss10_machine = {
1121 .name = "SS-10",
1122 .desc = "Sun4m platform, SPARCstation 10",
1123 .init = ss10_init,
1124 .use_scsi = 1,
1125 .max_cpus = 4,
1126};
1127
1128static QEMUMachine ss600mp_machine = {
1129 .name = "SS-600MP",
1130 .desc = "Sun4m platform, SPARCserver 600MP",
1131 .init = ss600mp_init,
1132 .use_scsi = 1,
1133 .max_cpus = 4,
1134};
1135
1136static QEMUMachine ss20_machine = {
1137 .name = "SS-20",
1138 .desc = "Sun4m platform, SPARCstation 20",
1139 .init = ss20_init,
1140 .use_scsi = 1,
1141 .max_cpus = 4,
1142};
1143
1144static QEMUMachine voyager_machine = {
1145 .name = "Voyager",
1146 .desc = "Sun4m platform, SPARCstation Voyager",
1147 .init = vger_init,
1148 .use_scsi = 1,
1149};
1150
1151static QEMUMachine ss_lx_machine = {
1152 .name = "LX",
1153 .desc = "Sun4m platform, SPARCstation LX",
1154 .init = ss_lx_init,
1155 .use_scsi = 1,
1156};
1157
1158static QEMUMachine ss4_machine = {
1159 .name = "SS-4",
1160 .desc = "Sun4m platform, SPARCstation 4",
1161 .init = ss4_init,
1162 .use_scsi = 1,
1163};
1164
1165static QEMUMachine scls_machine = {
1166 .name = "SPARCClassic",
1167 .desc = "Sun4m platform, SPARCClassic",
1168 .init = scls_init,
1169 .use_scsi = 1,
1170};
1171
1172static QEMUMachine sbook_machine = {
1173 .name = "SPARCbook",
1174 .desc = "Sun4m platform, SPARCbook",
1175 .init = sbook_init,
1176 .use_scsi = 1,
1177};
1178
1179static const struct sun4d_hwdef sun4d_hwdefs[] = {
1180 /* SS-1000 */
1181 {
1182 .iounit_bases = {
1183 0xfe0200000ULL,
1184 0xfe1200000ULL,
1185 0xfe2200000ULL,
1186 0xfe3200000ULL,
1187 -1,
1188 },
1189 .tcx_base = 0x820000000ULL,
1190 .slavio_base = 0xf00000000ULL,
1191 .ms_kb_base = 0xf00240000ULL,
1192 .serial_base = 0xf00200000ULL,
1193 .nvram_base = 0xf00280000ULL,
1194 .counter_base = 0xf00300000ULL,
1195 .espdma_base = 0x800081000ULL,
1196 .esp_base = 0x800080000ULL,
1197 .ledma_base = 0x800040000ULL,
1198 .le_base = 0x800060000ULL,
1199 .sbi_base = 0xf02800000ULL,
1200 .vram_size = 0x00100000,
1201 .nvram_size = 0x2000,
1202 .esp_irq = 3,
1203 .le_irq = 4,
1204 .clock_irq = 14,
1205 .clock1_irq = 10,
1206 .ms_kb_irq = 12,
1207 .ser_irq = 12,
1208 .nvram_machine_id = 0x80,
1209 .machine_id = ss1000_id,
1210 .iounit_version = 0x03000000,
1211 .max_mem = 0xf00000000ULL,
1212 .default_cpu_model = "TI SuperSparc II",
1213 },
1214 /* SS-2000 */
1215 {
1216 .iounit_bases = {
1217 0xfe0200000ULL,
1218 0xfe1200000ULL,
1219 0xfe2200000ULL,
1220 0xfe3200000ULL,
1221 0xfe4200000ULL,
1222 },
1223 .tcx_base = 0x820000000ULL,
1224 .slavio_base = 0xf00000000ULL,
1225 .ms_kb_base = 0xf00240000ULL,
1226 .serial_base = 0xf00200000ULL,
1227 .nvram_base = 0xf00280000ULL,
1228 .counter_base = 0xf00300000ULL,
1229 .espdma_base = 0x800081000ULL,
1230 .esp_base = 0x800080000ULL,
1231 .ledma_base = 0x800040000ULL,
1232 .le_base = 0x800060000ULL,
1233 .sbi_base = 0xf02800000ULL,
1234 .vram_size = 0x00100000,
1235 .nvram_size = 0x2000,
1236 .esp_irq = 3,
1237 .le_irq = 4,
1238 .clock_irq = 14,
1239 .clock1_irq = 10,
1240 .ms_kb_irq = 12,
1241 .ser_irq = 12,
1242 .nvram_machine_id = 0x80,
1243 .machine_id = ss2000_id,
1244 .iounit_version = 0x03000000,
1245 .max_mem = 0xf00000000ULL,
1246 .default_cpu_model = "TI SuperSparc II",
1247 },
1248};
1249
1250static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1251 const char *boot_device,
1252 const char *kernel_filename,
1253 const char *kernel_cmdline,
1254 const char *initrd_filename, const char *cpu_model)
1255{
1256 CPUState *env, *envs[MAX_CPUS];
1257 unsigned int i;
1258 void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram, *sbi;
1259 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1260 espdma_irq, ledma_irq;
1261 qemu_irq *esp_reset, *le_reset;
1262 ram_addr_t ram_offset;
1263 unsigned long kernel_size;
1264 void *fw_cfg;
1265
1266 /* init CPUs */
1267 if (!cpu_model)
1268 cpu_model = hwdef->default_cpu_model;
1269
1270 for (i = 0; i < smp_cpus; i++) {
1271 env = cpu_init(cpu_model);
1272 if (!env) {
1273 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1274 exit(1);
1275 }
1276 cpu_sparc_set_id(env, i);
1277 envs[i] = env;
1278 if (i == 0) {
1279 qemu_register_reset(main_cpu_reset, env);
1280 } else {
1281 qemu_register_reset(secondary_cpu_reset, env);
1282 env->halted = 1;
1283 }
1284 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1285 env->prom_addr = hwdef->slavio_base;
1286 }
1287
1288 for (i = smp_cpus; i < MAX_CPUS; i++)
1289 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1290
1291 /* allocate RAM */
1292 if ((uint64_t)RAM_size > hwdef->max_mem) {
1293 fprintf(stderr,
1294 "qemu: Too much memory for this machine: %d, maximum %d\n",
1295 (unsigned int)(RAM_size / (1024 * 1024)),
1296 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1297 exit(1);
1298 }
1299 ram_offset = qemu_ram_alloc(RAM_size);
1300 cpu_register_physical_memory(0, RAM_size, ram_offset);
1301
1302 /* set up devices */
1303 prom_init(hwdef->slavio_base, bios_name);
1304
1305 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1306
1307 for (i = 0; i < MAX_IOUNITS; i++)
1308 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
1309 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1310 hwdef->iounit_version,
1311 sbi_irq[hwdef->me_irq]);
1312
1313 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1314 iounits[0], &espdma_irq, &esp_reset);
1315
1316 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1317 iounits[0], &ledma_irq, &le_reset);
1318
1319 if (graphic_depth != 8 && graphic_depth != 24) {
1320 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1321 exit (1);
1322 }
1323 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
1324 graphic_depth);
1325
1326 lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq, le_reset);
1327
1328 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1329 hwdef->nvram_size, 8);
1330
1331 slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1332 sbi_cpu_irq, smp_cpus);
1333
1334 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
1335 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
1336 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1337 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1338 escc_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq], sbi_irq[hwdef->ser_irq],
1339 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
1340
1341 if (drive_get_max_bus(IF_SCSI) > 0) {
1342 fprintf(stderr, "qemu: too many SCSI bus\n");
1343 exit(1);
1344 }
1345
1346 esp_init(hwdef->esp_base, 2,
1347 espdma_memory_read, espdma_memory_write,
1348 espdma, espdma_irq, esp_reset);
1349
1350 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1351 RAM_size);
1352
1353 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1354 boot_device, RAM_size, kernel_size, graphic_width,
1355 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1356 "Sun4d");
1357
1358 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1359 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1360 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1361 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1362 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1363 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1364 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1365 if (kernel_cmdline) {
1366 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1367 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1368 } else {
1369 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1370 }
1371 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1372 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1373 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1374 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
1375}
1376
1377/* SPARCserver 1000 hardware initialisation */
1378static void ss1000_init(ram_addr_t RAM_size,
1379 const char *boot_device,
1380 const char *kernel_filename, const char *kernel_cmdline,
1381 const char *initrd_filename, const char *cpu_model)
1382{
1383 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
1384 kernel_cmdline, initrd_filename, cpu_model);
1385}
1386
1387/* SPARCcenter 2000 hardware initialisation */
1388static void ss2000_init(ram_addr_t RAM_size,
1389 const char *boot_device,
1390 const char *kernel_filename, const char *kernel_cmdline,
1391 const char *initrd_filename, const char *cpu_model)
1392{
1393 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
1394 kernel_cmdline, initrd_filename, cpu_model);
1395}
1396
1397static QEMUMachine ss1000_machine = {
1398 .name = "SS-1000",
1399 .desc = "Sun4d platform, SPARCserver 1000",
1400 .init = ss1000_init,
1401 .use_scsi = 1,
1402 .max_cpus = 8,
1403};
1404
1405static QEMUMachine ss2000_machine = {
1406 .name = "SS-2000",
1407 .desc = "Sun4d platform, SPARCcenter 2000",
1408 .init = ss2000_init,
1409 .use_scsi = 1,
1410 .max_cpus = 20,
1411};
1412
1413static const struct sun4c_hwdef sun4c_hwdefs[] = {
1414 /* SS-2 */
1415 {
1416 .iommu_base = 0xf8000000,
1417 .tcx_base = 0xfe000000,
1418 .slavio_base = 0xf6000000,
1419 .intctl_base = 0xf5000000,
1420 .counter_base = 0xf3000000,
1421 .ms_kb_base = 0xf0000000,
1422 .serial_base = 0xf1000000,
1423 .nvram_base = 0xf2000000,
1424 .fd_base = 0xf7200000,
1425 .dma_base = 0xf8400000,
1426 .esp_base = 0xf8800000,
1427 .le_base = 0xf8c00000,
1428 .aux1_base = 0xf7400003,
1429 .vram_size = 0x00100000,
1430 .nvram_size = 0x800,
1431 .esp_irq = 2,
1432 .le_irq = 3,
1433 .clock_irq = 5,
1434 .clock1_irq = 7,
1435 .ms_kb_irq = 1,
1436 .ser_irq = 1,
1437 .fd_irq = 1,
1438 .me_irq = 1,
1439 .nvram_machine_id = 0x55,
1440 .machine_id = ss2_id,
1441 .max_mem = 0x10000000,
1442 .default_cpu_model = "Cypress CY7C601",
1443 },
1444};
1445
1446static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1447 const char *boot_device,
1448 const char *kernel_filename,
1449 const char *kernel_cmdline,
1450 const char *initrd_filename, const char *cpu_model)
1451{
1452 CPUState *env;
1453 void *iommu, *espdma, *ledma, *nvram;
1454 qemu_irq *cpu_irqs, *slavio_irq, espdma_irq, ledma_irq;
1455 qemu_irq *esp_reset, *le_reset;
1456 qemu_irq fdc_tc;
1457 ram_addr_t ram_offset;
1458 unsigned long kernel_size;
1459 BlockDriverState *fd[MAX_FD];
1460 int drive_index;
1461 void *fw_cfg;
1462
1463 /* init CPU */
1464 if (!cpu_model)
1465 cpu_model = hwdef->default_cpu_model;
1466
1467 env = cpu_init(cpu_model);
1468 if (!env) {
1469 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
1470 exit(1);
1471 }
1472
1473 cpu_sparc_set_id(env, 0);
1474
1475 qemu_register_reset(main_cpu_reset, env);
1476 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
1477 env->prom_addr = hwdef->slavio_base;
1478
1479 /* allocate RAM */
1480 if ((uint64_t)RAM_size > hwdef->max_mem) {
1481 fprintf(stderr,
1482 "qemu: Too much memory for this machine: %d, maximum %d\n",
1483 (unsigned int)(RAM_size / (1024 * 1024)),
1484 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1485 exit(1);
1486 }
1487 ram_offset = qemu_ram_alloc(RAM_size);
1488 cpu_register_physical_memory(0, RAM_size, ram_offset);
1489
1490 /* set up devices */
1491 prom_init(hwdef->slavio_base, bios_name);
1492
1493 slavio_intctl = sun4c_intctl_init(hwdef->intctl_base,
1494 &slavio_irq, cpu_irqs);
1495
1496 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
1497 slavio_irq[hwdef->me_irq]);
1498
1499 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
1500 iommu, &espdma_irq, &esp_reset);
1501
1502 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
1503 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
1504 &le_reset);
1505
1506 if (graphic_depth != 8 && graphic_depth != 24) {
1507 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1508 exit (1);
1509 }
1510 tcx_init(hwdef->tcx_base, hwdef->vram_size, graphic_width, graphic_height,
1511 graphic_depth);
1512
1513 lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq, le_reset);
1514
1515 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
1516 hwdef->nvram_size, 2);
1517
1518 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
1519 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
1520 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1521 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1522 escc_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
1523 slavio_irq[hwdef->ser_irq], serial_hds[0], serial_hds[1],
1524 ESCC_CLOCK, 1);
1525
1526 slavio_misc = slavio_misc_init(0, hwdef->aux1_base, 0,
1527 slavio_irq[hwdef->me_irq], fdc_tc);
1528
1529 if (hwdef->fd_base != (target_phys_addr_t)-1) {
1530 /* there is zero or one floppy drive */
1531 memset(fd, 0, sizeof(fd));
1532 drive_index = drive_get_index(IF_FLOPPY, 0, 0);
1533 if (drive_index != -1)
1534 fd[0] = drives_table[drive_index].bdrv;
1535
1536 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd,
1537 &fdc_tc);
1538 }
1539
1540 if (drive_get_max_bus(IF_SCSI) > 0) {
1541 fprintf(stderr, "qemu: too many SCSI bus\n");
1542 exit(1);
1543 }
1544
1545 esp_init(hwdef->esp_base, 2,
1546 espdma_memory_read, espdma_memory_write,
1547 espdma, espdma_irq, esp_reset);
1548
1549 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1550 RAM_size);
1551
1552 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1553 boot_device, RAM_size, kernel_size, graphic_width,
1554 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1555 "Sun4c");
1556
1557 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1558 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1559 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1560 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1561 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1562 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1563 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1564 if (kernel_cmdline) {
1565 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1566 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
1567 } else {
1568 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1569 }
1570 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1571 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1572 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1573 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
1574}
1575
1576/* SPARCstation 2 hardware initialisation */
1577static void ss2_init(ram_addr_t RAM_size,
1578 const char *boot_device,
1579 const char *kernel_filename, const char *kernel_cmdline,
1580 const char *initrd_filename, const char *cpu_model)
1581{
1582 sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
1583 kernel_cmdline, initrd_filename, cpu_model);
1584}
1585
1586static QEMUMachine ss2_machine = {
1587 .name = "SS-2",
1588 .desc = "Sun4c platform, SPARCstation 2",
1589 .init = ss2_init,
1590 .use_scsi = 1,
1591};
1592
1593static void ss2_machine_init(void)
1594{
1595 qemu_register_machine(&ss5_machine);
1596 qemu_register_machine(&ss10_machine);
1597 qemu_register_machine(&ss600mp_machine);
1598 qemu_register_machine(&ss20_machine);
1599 qemu_register_machine(&voyager_machine);
1600 qemu_register_machine(&ss_lx_machine);
1601 qemu_register_machine(&ss4_machine);
1602 qemu_register_machine(&scls_machine);
1603 qemu_register_machine(&sbook_machine);
1604 qemu_register_machine(&ss1000_machine);
1605 qemu_register_machine(&ss2000_machine);
1606 qemu_register_machine(&ss2_machine);
1607}
1608
1609machine_init(ss2_machine_init);
This page took 0.042495 seconds and 4 git commands to generate.