]> git.proxmox.com Git - qemu.git/blame - hw/sun4m.c
Fix user timer mode change (Robert Reif)
[qemu.git] / hw / sun4m.c
CommitLineData
420557e8 1/*
ee76f82e 2 * QEMU Sun4m & Sun4d & Sun4c System Emulator
5fafdf24 3 *
b81b3b10 4 * Copyright (c) 2003-2005 Fabrice Bellard
5fafdf24 5 *
420557e8
FB
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 */
87ecb68b
PB
24#include "hw.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"
d2c63fc1
BS
33#include "firmware_abi.h"
34
b3a23197 35//#define DEBUG_IRQ
420557e8 36
36cd9210
BS
37/*
38 * Sun4m architecture was used in the following machines:
39 *
40 * SPARCserver 6xxMP/xx
41 * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15), SPARCclassic X (4/10)
42 * SPARCstation LX/ZX (4/30)
43 * SPARCstation Voyager
44 * SPARCstation 10/xx, SPARCserver 10/xx
45 * SPARCstation 5, SPARCserver 5
46 * SPARCstation 20/xx, SPARCserver 20
47 * SPARCstation 4
48 *
7d85892b
BS
49 * Sun4d architecture was used in the following machines:
50 *
51 * SPARCcenter 2000
52 * SPARCserver 1000
53 *
ee76f82e
BS
54 * Sun4c architecture was used in the following machines:
55 * SPARCstation 1/1+, SPARCserver 1/1+
56 * SPARCstation SLC
57 * SPARCstation IPC
58 * SPARCstation ELC
59 * SPARCstation IPX
60 *
36cd9210
BS
61 * See for example: http://www.sunhelp.org/faq/sunref1.html
62 */
63
b3a23197
BS
64#ifdef DEBUG_IRQ
65#define DPRINTF(fmt, args...) \
66 do { printf("CPUIRQ: " fmt , ##args); } while (0)
67#else
68#define DPRINTF(fmt, args...)
69#endif
70
420557e8 71#define KERNEL_LOAD_ADDR 0x00004000
b6f479d3 72#define CMDLINE_ADDR 0x007ff000
713c45fa 73#define INITRD_LOAD_ADDR 0x00800000
aa6ad6fe 74#define PROM_SIZE_MAX (512 * 1024)
40ce0a9a 75#define PROM_VADDR 0xffd00000
f930d07e 76#define PROM_FILENAME "openbios-sparc32"
b8174937 77
ba3c64fb 78#define MAX_CPUS 16
b3a23197 79#define MAX_PILS 16
420557e8 80
36cd9210 81struct hwdef {
5dcb6b91
BS
82 target_phys_addr_t iommu_base, slavio_base;
83 target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
84 target_phys_addr_t serial_base, fd_base;
4c2485de 85 target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
5dcb6b91 86 target_phys_addr_t tcx_base, cs_base, power_base;
7eb0c8e8
BS
87 target_phys_addr_t ecc_base;
88 uint32_t ecc_version;
ee76f82e 89 target_phys_addr_t sun4c_intctl_base, sun4c_counter_base;
36cd9210 90 long vram_size, nvram_size;
6341fdcb 91 // IRQ numbers are not PIL ones, but master interrupt controller
e3a79bca 92 // register bit numbers
d7edfd27 93 int intctl_g_intr, esp_irq, le_irq, clock_irq, clock1_irq;
e42c20b4 94 int ser_irq, ms_kb_irq, fd_irq, me_irq, cs_irq, ecc_irq;
36cd9210 95 int machine_id; // For NVRAM
7fbfb139 96 uint32_t iommu_version;
e0353fe2 97 uint32_t intbit_to_level[32];
3ebf5aaf
BS
98 uint64_t max_mem;
99 const char * const default_cpu_model;
36cd9210
BS
100};
101
7d85892b
BS
102#define MAX_IOUNITS 5
103
104struct sun4d_hwdef {
105 target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
106 target_phys_addr_t counter_base, nvram_base, ms_kb_base;
107 target_phys_addr_t serial_base;
108 target_phys_addr_t espdma_base, esp_base;
109 target_phys_addr_t ledma_base, le_base;
110 target_phys_addr_t tcx_base;
111 target_phys_addr_t sbi_base;
112 unsigned long vram_size, nvram_size;
113 // IRQ numbers are not PIL ones, but SBI register bit numbers
114 int esp_irq, le_irq, clock_irq, clock1_irq;
115 int ser_irq, ms_kb_irq, me_irq;
116 int machine_id; // For NVRAM
117 uint32_t iounit_version;
118 uint64_t max_mem;
119 const char * const default_cpu_model;
120};
121
420557e8
FB
122/* TSC handling */
123
124uint64_t cpu_get_tsc()
125{
126 return qemu_get_clock(vm_clock);
127}
128
6f7e9aec
FB
129int DMA_get_channel_mode (int nchan)
130{
131 return 0;
132}
133int DMA_read_memory (int nchan, void *buf, int pos, int size)
134{
135 return 0;
136}
137int DMA_write_memory (int nchan, void *buf, int pos, int size)
138{
139 return 0;
140}
141void DMA_hold_DREQ (int nchan) {}
142void DMA_release_DREQ (int nchan) {}
143void DMA_schedule(int nchan) {}
144void DMA_run (void) {}
145void DMA_init (int high_page_enable) {}
146void DMA_register_channel (int nchan,
147 DMA_transfer_handler transfer_handler,
148 void *opaque)
149{
150}
151
6f7e9aec
FB
152extern int nographic;
153
819385c5 154static void nvram_init(m48t59_t *nvram, uint8_t *macaddr, const char *cmdline,
d2c63fc1 155 const char *boot_devices, uint32_t RAM_size,
f930d07e
BS
156 uint32_t kernel_size,
157 int width, int height, int depth,
7d85892b 158 int machine_id, const char *arch)
e80cfcfc 159{
d2c63fc1 160 unsigned int i;
66508601 161 uint32_t start, end;
d2c63fc1
BS
162 uint8_t image[0x1ff0];
163 ohwcfg_v3_t *header = (ohwcfg_v3_t *)ℑ
164 struct sparc_arch_cfg *sparc_header;
165 struct OpenBIOS_nvpart_v1 *part_header;
166
167 memset(image, '\0', sizeof(image));
e80cfcfc 168
6f7e9aec 169 // Try to match PPC NVRAM
d2c63fc1
BS
170 strcpy(header->struct_ident, "QEMU_BIOS");
171 header->struct_version = cpu_to_be32(3); /* structure v3 */
172
173 header->nvram_size = cpu_to_be16(0x2000);
174 header->nvram_arch_ptr = cpu_to_be16(sizeof(ohwcfg_v3_t));
175 header->nvram_arch_size = cpu_to_be16(sizeof(struct sparc_arch_cfg));
7d85892b 176 strcpy(header->arch, arch);
d2c63fc1
BS
177 header->nb_cpus = smp_cpus & 0xff;
178 header->RAM0_base = 0;
179 header->RAM0_size = cpu_to_be64((uint64_t)RAM_size);
180 strcpy(header->boot_devices, boot_devices);
181 header->nboot_devices = strlen(boot_devices) & 0xff;
182 header->kernel_image = cpu_to_be64((uint64_t)KERNEL_LOAD_ADDR);
183 header->kernel_size = cpu_to_be64((uint64_t)kernel_size);
b6f479d3 184 if (cmdline) {
f930d07e 185 strcpy(phys_ram_base + CMDLINE_ADDR, cmdline);
d2c63fc1
BS
186 header->cmdline = cpu_to_be64((uint64_t)CMDLINE_ADDR);
187 header->cmdline_size = cpu_to_be64((uint64_t)strlen(cmdline));
b6f479d3 188 }
d2c63fc1
BS
189 // XXX add initrd_image, initrd_size
190 header->width = cpu_to_be16(width);
191 header->height = cpu_to_be16(height);
192 header->depth = cpu_to_be16(depth);
193 if (nographic)
194 header->graphic_flags = cpu_to_be16(OHW_GF_NOGRAPHICS);
195
196 header->crc = cpu_to_be16(OHW_compute_crc(header, 0x00, 0xF8));
197
198 // Architecture specific header
199 start = sizeof(ohwcfg_v3_t);
200 sparc_header = (struct sparc_arch_cfg *)&image[start];
201 sparc_header->valid = 0;
202 start += sizeof(struct sparc_arch_cfg);
b6f479d3 203
66508601
BS
204 // OpenBIOS nvram variables
205 // Variable partition
d2c63fc1
BS
206 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
207 part_header->signature = OPENBIOS_PART_SYSTEM;
208 strcpy(part_header->name, "system");
66508601 209
d2c63fc1 210 end = start + sizeof(struct OpenBIOS_nvpart_v1);
66508601 211 for (i = 0; i < nb_prom_envs; i++)
d2c63fc1
BS
212 end = OpenBIOS_set_var(image, end, prom_envs[i]);
213
214 // End marker
215 image[end++] = '\0';
66508601 216
66508601 217 end = start + ((end - start + 15) & ~15);
d2c63fc1 218 OpenBIOS_finish_partition(part_header, end - start);
66508601
BS
219
220 // free partition
221 start = end;
d2c63fc1
BS
222 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
223 part_header->signature = OPENBIOS_PART_FREE;
224 strcpy(part_header->name, "free");
66508601
BS
225
226 end = 0x1fd0;
d2c63fc1
BS
227 OpenBIOS_finish_partition(part_header, end - start);
228
229 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, machine_id);
230
231 for (i = 0; i < sizeof(image); i++)
232 m48t59_write(nvram, i, image[i]);
e80cfcfc
FB
233}
234
235static void *slavio_intctl;
236
237void pic_info()
238{
7d85892b
BS
239 if (slavio_intctl)
240 slavio_pic_info(slavio_intctl);
e80cfcfc
FB
241}
242
243void irq_info()
244{
7d85892b
BS
245 if (slavio_intctl)
246 slavio_irq_info(slavio_intctl);
e80cfcfc
FB
247}
248
327ac2e7
BS
249void cpu_check_irqs(CPUState *env)
250{
251 if (env->pil_in && (env->interrupt_index == 0 ||
252 (env->interrupt_index & ~15) == TT_EXTINT)) {
253 unsigned int i;
254
255 for (i = 15; i > 0; i--) {
256 if (env->pil_in & (1 << i)) {
257 int old_interrupt = env->interrupt_index;
258
259 env->interrupt_index = TT_EXTINT | i;
260 if (old_interrupt != env->interrupt_index)
261 cpu_interrupt(env, CPU_INTERRUPT_HARD);
262 break;
263 }
264 }
265 } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
266 env->interrupt_index = 0;
267 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
268 }
269}
270
b3a23197
BS
271static void cpu_set_irq(void *opaque, int irq, int level)
272{
273 CPUState *env = opaque;
274
275 if (level) {
276 DPRINTF("Raise CPU IRQ %d\n", irq);
b3a23197 277 env->halted = 0;
327ac2e7
BS
278 env->pil_in |= 1 << irq;
279 cpu_check_irqs(env);
b3a23197
BS
280 } else {
281 DPRINTF("Lower CPU IRQ %d\n", irq);
327ac2e7
BS
282 env->pil_in &= ~(1 << irq);
283 cpu_check_irqs(env);
b3a23197
BS
284 }
285}
286
287static void dummy_cpu_set_irq(void *opaque, int irq, int level)
288{
289}
290
3475187d
FB
291static void *slavio_misc;
292
293void qemu_system_powerdown(void)
294{
295 slavio_set_power_fail(slavio_misc, 1);
296}
297
c68ea704
FB
298static void main_cpu_reset(void *opaque)
299{
300 CPUState *env = opaque;
3d29fbef
BS
301
302 cpu_reset(env);
303 env->halted = 0;
304}
305
306static void secondary_cpu_reset(void *opaque)
307{
308 CPUState *env = opaque;
309
c68ea704 310 cpu_reset(env);
3d29fbef 311 env->halted = 1;
c68ea704
FB
312}
313
3ebf5aaf
BS
314static unsigned long sun4m_load_kernel(const char *kernel_filename,
315 const char *kernel_cmdline,
316 const char *initrd_filename)
317{
318 int linux_boot;
319 unsigned int i;
320 long initrd_size, kernel_size;
321
322 linux_boot = (kernel_filename != NULL);
323
324 kernel_size = 0;
325 if (linux_boot) {
326 kernel_size = load_elf(kernel_filename, -0xf0000000ULL, NULL, NULL,
327 NULL);
328 if (kernel_size < 0)
329 kernel_size = load_aout(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR);
330 if (kernel_size < 0)
331 kernel_size = load_image(kernel_filename, phys_ram_base + KERNEL_LOAD_ADDR);
332 if (kernel_size < 0) {
333 fprintf(stderr, "qemu: could not load kernel '%s'\n",
334 kernel_filename);
335 exit(1);
336 }
337
338 /* load initrd */
339 initrd_size = 0;
340 if (initrd_filename) {
341 initrd_size = load_image(initrd_filename, phys_ram_base + INITRD_LOAD_ADDR);
342 if (initrd_size < 0) {
343 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
344 initrd_filename);
345 exit(1);
346 }
347 }
348 if (initrd_size > 0) {
349 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
350 if (ldl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i)
351 == 0x48647253) { // HdrS
352 stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
353 stl_raw(phys_ram_base + KERNEL_LOAD_ADDR + i + 20, initrd_size);
354 break;
355 }
356 }
357 }
358 }
359 return kernel_size;
360}
361
362static void sun4m_hw_init(const struct hwdef *hwdef, int RAM_size,
363 const char *boot_device,
364 DisplayState *ds, const char *kernel_filename,
365 const char *kernel_cmdline,
366 const char *initrd_filename, const char *cpu_model)
36cd9210 367
420557e8 368{
ba3c64fb 369 CPUState *env, *envs[MAX_CPUS];
713c45fa 370 unsigned int i;
b3ceef24 371 void *iommu, *espdma, *ledma, *main_esp, *nvram;
b3a23197 372 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
d7edfd27 373 *espdma_irq, *ledma_irq;
2d069bab 374 qemu_irq *esp_reset, *le_reset;
3ebf5aaf
BS
375 unsigned long prom_offset, kernel_size;
376 int ret;
377 char buf[1024];
e4bcb14c
TS
378 BlockDriverState *fd[MAX_FD];
379 int index;
420557e8 380
ba3c64fb 381 /* init CPUs */
3ebf5aaf
BS
382 if (!cpu_model)
383 cpu_model = hwdef->default_cpu_model;
b3a23197 384
ba3c64fb 385 for(i = 0; i < smp_cpus; i++) {
aaed909a
FB
386 env = cpu_init(cpu_model);
387 if (!env) {
8e82c6a8 388 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
aaed909a
FB
389 exit(1);
390 }
391 cpu_sparc_set_id(env, i);
ba3c64fb 392 envs[i] = env;
3d29fbef
BS
393 if (i == 0) {
394 qemu_register_reset(main_cpu_reset, env);
395 } else {
396 qemu_register_reset(secondary_cpu_reset, env);
ba3c64fb 397 env->halted = 1;
3d29fbef 398 }
ba3c64fb 399 register_savevm("cpu", i, 3, cpu_save, cpu_load, env);
b3a23197 400 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
3ebf5aaf 401 env->prom_addr = hwdef->slavio_base;
ba3c64fb 402 }
b3a23197
BS
403
404 for (i = smp_cpus; i < MAX_CPUS; i++)
405 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
406
3ebf5aaf 407
420557e8 408 /* allocate RAM */
3ebf5aaf
BS
409 if ((uint64_t)RAM_size > hwdef->max_mem) {
410 fprintf(stderr, "qemu: Too much memory for this machine: %d, maximum %d\n",
411 (unsigned int)RAM_size / (1024 * 1024),
412 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
413 exit(1);
414 }
b3ceef24 415 cpu_register_physical_memory(0, RAM_size, 0);
420557e8 416
3ebf5aaf
BS
417 /* load boot prom */
418 prom_offset = RAM_size + hwdef->vram_size;
419 cpu_register_physical_memory(hwdef->slavio_base,
420 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
421 TARGET_PAGE_MASK,
422 prom_offset | IO_MEM_ROM);
423
424 if (bios_name == NULL)
425 bios_name = PROM_FILENAME;
426 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
427 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
428 if (ret < 0 || ret > PROM_SIZE_MAX)
429 ret = load_image(buf, phys_ram_base + prom_offset);
430 if (ret < 0 || ret > PROM_SIZE_MAX) {
431 fprintf(stderr, "qemu: could not load prom '%s'\n",
432 buf);
433 exit(1);
434 }
4c2485de 435 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
3ebf5aaf
BS
436
437 /* set up devices */
36cd9210 438 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
5dcb6b91 439 hwdef->intctl_base + 0x10000ULL,
d537cf6c 440 &hwdef->intbit_to_level[0],
d7edfd27 441 &slavio_irq, &slavio_cpu_irq,
b3a23197 442 cpu_irqs,
d7edfd27 443 hwdef->clock_irq);
b3a23197 444
4c2485de
BS
445 if (hwdef->idreg_base != (target_phys_addr_t)-1) {
446 stl_raw(phys_ram_base + prom_offset, 0xfe810103);
447
448 cpu_register_physical_memory(hwdef->idreg_base, sizeof(uint32_t),
449 prom_offset | IO_MEM_ROM);
450 }
451
ff403da6
BS
452 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
453 slavio_irq[hwdef->me_irq]);
454
5aca8c3b 455 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
2d069bab
BS
456 iommu, &espdma_irq, &esp_reset);
457
5aca8c3b 458 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
2d069bab
BS
459 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
460 &le_reset);
ba3c64fb 461
eee0b836
BS
462 if (graphic_depth != 8 && graphic_depth != 24) {
463 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
464 exit (1);
465 }
b3ceef24 466 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
eee0b836 467 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
dbe06e18
BS
468
469 if (nd_table[0].model == NULL
470 || strcmp(nd_table[0].model, "lance") == 0) {
2d069bab 471 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
c4a7060c
BS
472 } else if (strcmp(nd_table[0].model, "?") == 0) {
473 fprintf(stderr, "qemu: Supported NICs: lance\n");
474 exit (1);
dbe06e18
BS
475 } else {
476 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
477 exit (1);
a41b2ff2 478 }
dbe06e18 479
d537cf6c
PB
480 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
481 hwdef->nvram_size, 8);
81732d19
BS
482
483 slavio_timer_init_all(hwdef->counter_base, slavio_irq[hwdef->clock1_irq],
19f8e5dd 484 slavio_cpu_irq, smp_cpus);
81732d19 485
577390ff
BS
486 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
487 nographic);
b81b3b10
FB
488 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
489 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
d537cf6c
PB
490 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
491 serial_hds[1], serial_hds[0]);
741402f9 492
e4bcb14c
TS
493 if (hwdef->fd_base != (target_phys_addr_t)-1) {
494 /* there is zero or one floppy drive */
495 fd[1] = fd[0] = NULL;
496 index = drive_get_index(IF_FLOPPY, 0, 0);
497 if (index != -1)
498 fd[0] = drives_table[index].bdrv;
2d069bab 499
e4bcb14c
TS
500 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd);
501 }
502
503 if (drive_get_max_bus(IF_SCSI) > 0) {
504 fprintf(stderr, "qemu: too many SCSI bus\n");
505 exit(1);
506 }
507
508 main_esp = esp_init(hwdef->esp_base, espdma, *espdma_irq,
2d069bab 509 esp_reset);
f1587550 510
e4bcb14c
TS
511 for (i = 0; i < ESP_MAX_DEVS; i++) {
512 index = drive_get_index(IF_SCSI, 0, i);
513 if (index == -1)
514 continue;
515 esp_scsi_attach(main_esp, drives_table[index].bdrv, i);
f1587550
TS
516 }
517
5dcb6b91 518 slavio_misc = slavio_misc_init(hwdef->slavio_base, hwdef->power_base,
d537cf6c 519 slavio_irq[hwdef->me_irq]);
5dcb6b91 520 if (hwdef->cs_base != (target_phys_addr_t)-1)
803b3c7b 521 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
b3ceef24 522
3ebf5aaf
BS
523 kernel_size = sun4m_load_kernel(kernel_filename, kernel_cmdline,
524 initrd_filename);
36cd9210 525
36cd9210 526 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
b3ceef24 527 boot_device, RAM_size, kernel_size, graphic_width,
7d85892b 528 graphic_height, graphic_depth, hwdef->machine_id, "Sun4m");
7eb0c8e8
BS
529
530 if (hwdef->ecc_base != (target_phys_addr_t)-1)
e42c20b4
BS
531 ecc_init(hwdef->ecc_base, slavio_irq[hwdef->ecc_irq],
532 hwdef->ecc_version);
36cd9210
BS
533}
534
ee76f82e
BS
535static void sun4c_hw_init(const struct hwdef *hwdef, int RAM_size,
536 const char *boot_device,
537 DisplayState *ds, const char *kernel_filename,
538 const char *kernel_cmdline,
539 const char *initrd_filename, const char *cpu_model)
540{
541 CPUState *env;
542 unsigned int i;
543 void *iommu, *espdma, *ledma, *main_esp, *nvram;
544 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
545 qemu_irq *esp_reset, *le_reset;
546 unsigned long prom_offset, kernel_size;
547 int ret;
548 char buf[1024];
549 BlockDriverState *fd[MAX_FD];
550 int index;
551
552 /* init CPU */
553 if (!cpu_model)
554 cpu_model = hwdef->default_cpu_model;
555
556 env = cpu_init(cpu_model);
557 if (!env) {
8e82c6a8 558 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
ee76f82e
BS
559 exit(1);
560 }
561
562 cpu_sparc_set_id(env, 0);
563
564 qemu_register_reset(main_cpu_reset, env);
565 register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
566 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
cebb73aa 567 env->prom_addr = hwdef->slavio_base;
ee76f82e
BS
568
569 /* allocate RAM */
570 if ((uint64_t)RAM_size > hwdef->max_mem) {
571 fprintf(stderr, "qemu: Too much memory for this machine: %d, maximum %d\n",
572 (unsigned int)RAM_size / (1024 * 1024),
573 (unsigned int)hwdef->max_mem / (1024 * 1024));
574 exit(1);
575 }
576 cpu_register_physical_memory(0, RAM_size, 0);
577
578 /* load boot prom */
579 prom_offset = RAM_size + hwdef->vram_size;
580 cpu_register_physical_memory(hwdef->slavio_base,
581 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
582 TARGET_PAGE_MASK,
583 prom_offset | IO_MEM_ROM);
584
585 if (bios_name == NULL)
586 bios_name = PROM_FILENAME;
587 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
588 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
589 if (ret < 0 || ret > PROM_SIZE_MAX)
590 ret = load_image(buf, phys_ram_base + prom_offset);
591 if (ret < 0 || ret > PROM_SIZE_MAX) {
592 fprintf(stderr, "qemu: could not load prom '%s'\n",
593 buf);
594 exit(1);
595 }
596 prom_offset += (ret + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
597
598 /* set up devices */
599 slavio_intctl = sun4c_intctl_init(hwdef->sun4c_intctl_base,
600 &slavio_irq, cpu_irqs);
601
ff403da6
BS
602 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
603 slavio_irq[hwdef->me_irq]);
ee76f82e
BS
604
605 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[hwdef->esp_irq],
606 iommu, &espdma_irq, &esp_reset);
607
608 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
609 slavio_irq[hwdef->le_irq], iommu, &ledma_irq,
610 &le_reset);
611
612 if (graphic_depth != 8 && graphic_depth != 24) {
613 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
614 exit (1);
615 }
616 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
617 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
618
619 if (nd_table[0].model == NULL
620 || strcmp(nd_table[0].model, "lance") == 0) {
621 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
622 } else if (strcmp(nd_table[0].model, "?") == 0) {
623 fprintf(stderr, "qemu: Supported NICs: lance\n");
624 exit (1);
625 } else {
626 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
627 exit (1);
628 }
629
630 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0,
4aed2c33 631 hwdef->nvram_size, 2);
ee76f82e
BS
632
633 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[hwdef->ms_kb_irq],
634 nographic);
635 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
636 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
637 slavio_serial_init(hwdef->serial_base, slavio_irq[hwdef->ser_irq],
638 serial_hds[1], serial_hds[0]);
639
640 if (hwdef->fd_base != (target_phys_addr_t)-1) {
641 /* there is zero or one floppy drive */
642 fd[1] = fd[0] = NULL;
643 index = drive_get_index(IF_FLOPPY, 0, 0);
644 if (index != -1)
645 fd[0] = drives_table[index].bdrv;
646
647 sun4m_fdctrl_init(slavio_irq[hwdef->fd_irq], hwdef->fd_base, fd);
648 }
649
650 if (drive_get_max_bus(IF_SCSI) > 0) {
651 fprintf(stderr, "qemu: too many SCSI bus\n");
652 exit(1);
653 }
654
655 main_esp = esp_init(hwdef->esp_base, espdma, *espdma_irq,
656 esp_reset);
657
658 for (i = 0; i < ESP_MAX_DEVS; i++) {
659 index = drive_get_index(IF_SCSI, 0, i);
660 if (index == -1)
661 continue;
662 esp_scsi_attach(main_esp, drives_table[index].bdrv, i);
663 }
664
665 kernel_size = sun4m_load_kernel(kernel_filename, kernel_cmdline,
666 initrd_filename);
667
668 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
669 boot_device, RAM_size, kernel_size, graphic_width,
670 graphic_height, graphic_depth, hwdef->machine_id, "Sun4c");
671}
672
36cd9210
BS
673static const struct hwdef hwdefs[] = {
674 /* SS-5 */
675 {
676 .iommu_base = 0x10000000,
677 .tcx_base = 0x50000000,
678 .cs_base = 0x6c000000,
384ccb5d 679 .slavio_base = 0x70000000,
36cd9210
BS
680 .ms_kb_base = 0x71000000,
681 .serial_base = 0x71100000,
682 .nvram_base = 0x71200000,
683 .fd_base = 0x71400000,
684 .counter_base = 0x71d00000,
685 .intctl_base = 0x71e00000,
4c2485de 686 .idreg_base = 0x78000000,
36cd9210
BS
687 .dma_base = 0x78400000,
688 .esp_base = 0x78800000,
689 .le_base = 0x78c00000,
5dcb6b91 690 .power_base = 0x7a000000,
7eb0c8e8 691 .ecc_base = -1,
ee76f82e
BS
692 .sun4c_intctl_base = -1,
693 .sun4c_counter_base = -1,
36cd9210
BS
694 .vram_size = 0x00100000,
695 .nvram_size = 0x2000,
696 .esp_irq = 18,
697 .le_irq = 16,
e3a79bca 698 .clock_irq = 7,
36cd9210
BS
699 .clock1_irq = 19,
700 .ms_kb_irq = 14,
701 .ser_irq = 15,
702 .fd_irq = 22,
703 .me_irq = 30,
704 .cs_irq = 5,
705 .machine_id = 0x80,
cf3102ac 706 .iommu_version = 0x05000000,
e0353fe2 707 .intbit_to_level = {
f930d07e
BS
708 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
709 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
e0353fe2 710 },
3ebf5aaf
BS
711 .max_mem = 0x10000000,
712 .default_cpu_model = "Fujitsu MB86904",
e0353fe2
BS
713 },
714 /* SS-10 */
e0353fe2 715 {
5dcb6b91
BS
716 .iommu_base = 0xfe0000000ULL,
717 .tcx_base = 0xe20000000ULL,
803b3c7b 718 .cs_base = -1,
5dcb6b91
BS
719 .slavio_base = 0xff0000000ULL,
720 .ms_kb_base = 0xff1000000ULL,
721 .serial_base = 0xff1100000ULL,
722 .nvram_base = 0xff1200000ULL,
723 .fd_base = 0xff1700000ULL,
724 .counter_base = 0xff1300000ULL,
725 .intctl_base = 0xff1400000ULL,
4c2485de 726 .idreg_base = 0xef0000000ULL,
5dcb6b91
BS
727 .dma_base = 0xef0400000ULL,
728 .esp_base = 0xef0800000ULL,
729 .le_base = 0xef0c00000ULL,
730 .power_base = 0xefa000000ULL,
7eb0c8e8
BS
731 .ecc_base = 0xf00000000ULL,
732 .ecc_version = 0x10000000, // version 0, implementation 1
ee76f82e
BS
733 .sun4c_intctl_base = -1,
734 .sun4c_counter_base = -1,
e0353fe2
BS
735 .vram_size = 0x00100000,
736 .nvram_size = 0x2000,
737 .esp_irq = 18,
738 .le_irq = 16,
e3a79bca 739 .clock_irq = 7,
e0353fe2
BS
740 .clock1_irq = 19,
741 .ms_kb_irq = 14,
742 .ser_irq = 15,
743 .fd_irq = 22,
744 .me_irq = 30,
803b3c7b 745 .cs_irq = -1,
e42c20b4 746 .ecc_irq = 28,
803b3c7b 747 .machine_id = 0x72,
7fbfb139 748 .iommu_version = 0x03000000,
e0353fe2 749 .intbit_to_level = {
f930d07e
BS
750 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
751 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
e0353fe2 752 },
3ebf5aaf
BS
753 .max_mem = 0xffffffff, // XXX actually first 62GB ok
754 .default_cpu_model = "TI SuperSparc II",
36cd9210 755 },
6a3b9cc9
BS
756 /* SS-600MP */
757 {
758 .iommu_base = 0xfe0000000ULL,
759 .tcx_base = 0xe20000000ULL,
760 .cs_base = -1,
761 .slavio_base = 0xff0000000ULL,
762 .ms_kb_base = 0xff1000000ULL,
763 .serial_base = 0xff1100000ULL,
764 .nvram_base = 0xff1200000ULL,
765 .fd_base = -1,
766 .counter_base = 0xff1300000ULL,
767 .intctl_base = 0xff1400000ULL,
4c2485de 768 .idreg_base = -1,
6a3b9cc9
BS
769 .dma_base = 0xef0081000ULL,
770 .esp_base = 0xef0080000ULL,
771 .le_base = 0xef0060000ULL,
772 .power_base = 0xefa000000ULL,
7eb0c8e8
BS
773 .ecc_base = 0xf00000000ULL,
774 .ecc_version = 0x00000000, // version 0, implementation 0
ee76f82e
BS
775 .sun4c_intctl_base = -1,
776 .sun4c_counter_base = -1,
6a3b9cc9
BS
777 .vram_size = 0x00100000,
778 .nvram_size = 0x2000,
779 .esp_irq = 18,
780 .le_irq = 16,
e3a79bca 781 .clock_irq = 7,
6a3b9cc9
BS
782 .clock1_irq = 19,
783 .ms_kb_irq = 14,
784 .ser_irq = 15,
785 .fd_irq = 22,
786 .me_irq = 30,
787 .cs_irq = -1,
e42c20b4 788 .ecc_irq = 28,
6a3b9cc9 789 .machine_id = 0x71,
7fbfb139 790 .iommu_version = 0x01000000,
6a3b9cc9
BS
791 .intbit_to_level = {
792 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
793 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
794 },
3ebf5aaf
BS
795 .max_mem = 0xffffffff, // XXX actually first 62GB ok
796 .default_cpu_model = "TI SuperSparc II",
6a3b9cc9 797 },
ae40972f
BS
798 /* SS-20 */
799 {
800 .iommu_base = 0xfe0000000ULL,
801 .tcx_base = 0xe20000000ULL,
802 .cs_base = -1,
803 .slavio_base = 0xff0000000ULL,
804 .ms_kb_base = 0xff1000000ULL,
805 .serial_base = 0xff1100000ULL,
806 .nvram_base = 0xff1200000ULL,
807 .fd_base = 0xff1700000ULL,
808 .counter_base = 0xff1300000ULL,
809 .intctl_base = 0xff1400000ULL,
4c2485de 810 .idreg_base = 0xef0000000ULL,
ae40972f
BS
811 .dma_base = 0xef0400000ULL,
812 .esp_base = 0xef0800000ULL,
813 .le_base = 0xef0c00000ULL,
814 .power_base = 0xefa000000ULL,
815 .ecc_base = 0xf00000000ULL,
816 .ecc_version = 0x20000000, // version 0, implementation 2
ee76f82e
BS
817 .sun4c_intctl_base = -1,
818 .sun4c_counter_base = -1,
ae40972f
BS
819 .vram_size = 0x00100000,
820 .nvram_size = 0x2000,
821 .esp_irq = 18,
822 .le_irq = 16,
e3a79bca 823 .clock_irq = 7,
ae40972f
BS
824 .clock1_irq = 19,
825 .ms_kb_irq = 14,
826 .ser_irq = 15,
827 .fd_irq = 22,
828 .me_irq = 30,
829 .cs_irq = -1,
e42c20b4 830 .ecc_irq = 28,
ae40972f
BS
831 .machine_id = 0x72,
832 .iommu_version = 0x13000000,
833 .intbit_to_level = {
834 2, 3, 5, 7, 9, 11, 0, 14, 3, 5, 7, 9, 11, 13, 12, 12,
835 6, 0, 4, 10, 8, 0, 11, 0, 0, 0, 0, 0, 15, 0, 15, 0,
836 },
837 .max_mem = 0xffffffff, // XXX actually first 62GB ok
838 .default_cpu_model = "TI SuperSparc II",
839 },
ee76f82e
BS
840 /* SS-2 */
841 {
842 .iommu_base = 0xf8000000,
843 .tcx_base = 0xfe000000,
844 .cs_base = -1,
845 .slavio_base = 0xf6000000,
846 .ms_kb_base = 0xf0000000,
847 .serial_base = 0xf1000000,
848 .nvram_base = 0xf2000000,
849 .fd_base = 0xf7200000,
850 .counter_base = -1,
851 .intctl_base = -1,
852 .dma_base = 0xf8400000,
853 .esp_base = 0xf8800000,
854 .le_base = 0xf8c00000,
855 .power_base = -1,
856 .sun4c_intctl_base = 0xf5000000,
857 .sun4c_counter_base = 0xf3000000,
858 .vram_size = 0x00100000,
4aed2c33 859 .nvram_size = 0x800,
ee76f82e
BS
860 .esp_irq = 2,
861 .le_irq = 3,
862 .clock_irq = 5,
863 .clock1_irq = 7,
864 .ms_kb_irq = 1,
865 .ser_irq = 1,
866 .fd_irq = 1,
867 .me_irq = 1,
868 .cs_irq = -1,
869 .machine_id = 0x55,
870 .max_mem = 0x10000000,
871 .default_cpu_model = "Cypress CY7C601",
872 },
36cd9210
BS
873};
874
36cd9210 875/* SPARCstation 5 hardware initialisation */
b881c2c6
BS
876static void ss5_init(int RAM_size, int vga_ram_size,
877 const char *boot_device, DisplayState *ds,
878 const char *kernel_filename, const char *kernel_cmdline,
879 const char *initrd_filename, const char *cpu_model)
36cd9210 880{
3ebf5aaf
BS
881 sun4m_hw_init(&hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
882 kernel_cmdline, initrd_filename, cpu_model);
420557e8 883}
c0e564d5 884
e0353fe2 885/* SPARCstation 10 hardware initialisation */
b881c2c6
BS
886static void ss10_init(int RAM_size, int vga_ram_size,
887 const char *boot_device, DisplayState *ds,
888 const char *kernel_filename, const char *kernel_cmdline,
889 const char *initrd_filename, const char *cpu_model)
e0353fe2 890{
3ebf5aaf
BS
891 sun4m_hw_init(&hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
892 kernel_cmdline, initrd_filename, cpu_model);
e0353fe2
BS
893}
894
6a3b9cc9 895/* SPARCserver 600MP hardware initialisation */
b881c2c6
BS
896static void ss600mp_init(int RAM_size, int vga_ram_size,
897 const char *boot_device, DisplayState *ds,
6a3b9cc9
BS
898 const char *kernel_filename, const char *kernel_cmdline,
899 const char *initrd_filename, const char *cpu_model)
900{
3ebf5aaf
BS
901 sun4m_hw_init(&hwdefs[2], RAM_size, boot_device, ds, kernel_filename,
902 kernel_cmdline, initrd_filename, cpu_model);
6a3b9cc9
BS
903}
904
ae40972f
BS
905/* SPARCstation 20 hardware initialisation */
906static void ss20_init(int RAM_size, int vga_ram_size,
907 const char *boot_device, DisplayState *ds,
908 const char *kernel_filename, const char *kernel_cmdline,
909 const char *initrd_filename, const char *cpu_model)
910{
911 sun4m_hw_init(&hwdefs[3], RAM_size, boot_device, ds, kernel_filename,
912 kernel_cmdline, initrd_filename, cpu_model);
913}
914
ee76f82e
BS
915/* SPARCstation 2 hardware initialisation */
916static void ss2_init(int RAM_size, int vga_ram_size,
917 const char *boot_device, DisplayState *ds,
918 const char *kernel_filename, const char *kernel_cmdline,
919 const char *initrd_filename, const char *cpu_model)
920{
921 sun4c_hw_init(&hwdefs[4], RAM_size, boot_device, ds, kernel_filename,
922 kernel_cmdline, initrd_filename, cpu_model);
923}
924
36cd9210
BS
925QEMUMachine ss5_machine = {
926 "SS-5",
927 "Sun4m platform, SPARCstation 5",
928 ss5_init,
c0e564d5 929};
e0353fe2
BS
930
931QEMUMachine ss10_machine = {
932 "SS-10",
933 "Sun4m platform, SPARCstation 10",
934 ss10_init,
935};
6a3b9cc9
BS
936
937QEMUMachine ss600mp_machine = {
938 "SS-600MP",
939 "Sun4m platform, SPARCserver 600MP",
940 ss600mp_init,
941};
ae40972f
BS
942
943QEMUMachine ss20_machine = {
944 "SS-20",
945 "Sun4m platform, SPARCstation 20",
946 ss20_init,
947};
948
ee76f82e
BS
949QEMUMachine ss2_machine = {
950 "SS-2",
951 "Sun4c platform, SPARCstation 2",
952 ss2_init,
953};
7d85892b
BS
954
955static const struct sun4d_hwdef sun4d_hwdefs[] = {
956 /* SS-1000 */
957 {
958 .iounit_bases = {
959 0xfe0200000ULL,
960 0xfe1200000ULL,
961 0xfe2200000ULL,
962 0xfe3200000ULL,
963 -1,
964 },
965 .tcx_base = 0x820000000ULL,
966 .slavio_base = 0xf00000000ULL,
967 .ms_kb_base = 0xf00240000ULL,
968 .serial_base = 0xf00200000ULL,
969 .nvram_base = 0xf00280000ULL,
970 .counter_base = 0xf00300000ULL,
971 .espdma_base = 0x800081000ULL,
972 .esp_base = 0x800080000ULL,
973 .ledma_base = 0x800040000ULL,
974 .le_base = 0x800060000ULL,
975 .sbi_base = 0xf02800000ULL,
976 .vram_size = 0x00100000,
977 .nvram_size = 0x2000,
978 .esp_irq = 3,
979 .le_irq = 4,
980 .clock_irq = 14,
981 .clock1_irq = 10,
982 .ms_kb_irq = 12,
983 .ser_irq = 12,
984 .machine_id = 0x80,
985 .iounit_version = 0x03000000,
986 .max_mem = 0xffffffff, // XXX actually first 62GB ok
987 .default_cpu_model = "TI SuperSparc II",
988 },
989 /* SS-2000 */
990 {
991 .iounit_bases = {
992 0xfe0200000ULL,
993 0xfe1200000ULL,
994 0xfe2200000ULL,
995 0xfe3200000ULL,
996 0xfe4200000ULL,
997 },
998 .tcx_base = 0x820000000ULL,
999 .slavio_base = 0xf00000000ULL,
1000 .ms_kb_base = 0xf00240000ULL,
1001 .serial_base = 0xf00200000ULL,
1002 .nvram_base = 0xf00280000ULL,
1003 .counter_base = 0xf00300000ULL,
1004 .espdma_base = 0x800081000ULL,
1005 .esp_base = 0x800080000ULL,
1006 .ledma_base = 0x800040000ULL,
1007 .le_base = 0x800060000ULL,
1008 .sbi_base = 0xf02800000ULL,
1009 .vram_size = 0x00100000,
1010 .nvram_size = 0x2000,
1011 .esp_irq = 3,
1012 .le_irq = 4,
1013 .clock_irq = 14,
1014 .clock1_irq = 10,
1015 .ms_kb_irq = 12,
1016 .ser_irq = 12,
1017 .machine_id = 0x80,
1018 .iounit_version = 0x03000000,
1019 .max_mem = 0xffffffff, // XXX actually first 62GB ok
1020 .default_cpu_model = "TI SuperSparc II",
1021 },
1022};
1023
1024static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, int RAM_size,
1025 const char *boot_device,
1026 DisplayState *ds, const char *kernel_filename,
1027 const char *kernel_cmdline,
1028 const char *initrd_filename, const char *cpu_model)
1029{
1030 CPUState *env, *envs[MAX_CPUS];
1031 unsigned int i;
1032 void *iounits[MAX_IOUNITS], *espdma, *ledma, *main_esp, *nvram, *sbi;
1033 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1034 *espdma_irq, *ledma_irq;
1035 qemu_irq *esp_reset, *le_reset;
1036 unsigned long prom_offset, kernel_size;
1037 int ret;
1038 char buf[1024];
1039 int index;
1040
1041 /* init CPUs */
1042 if (!cpu_model)
1043 cpu_model = hwdef->default_cpu_model;
1044
1045 for (i = 0; i < smp_cpus; i++) {
1046 env = cpu_init(cpu_model);
1047 if (!env) {
8e82c6a8 1048 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
7d85892b
BS
1049 exit(1);
1050 }
1051 cpu_sparc_set_id(env, i);
1052 envs[i] = env;
1053 if (i == 0) {
1054 qemu_register_reset(main_cpu_reset, env);
1055 } else {
1056 qemu_register_reset(secondary_cpu_reset, env);
1057 env->halted = 1;
1058 }
1059 register_savevm("cpu", i, 3, cpu_save, cpu_load, env);
1060 cpu_irqs[i] = qemu_allocate_irqs(cpu_set_irq, envs[i], MAX_PILS);
1061 env->prom_addr = hwdef->slavio_base;
1062 }
1063
1064 for (i = smp_cpus; i < MAX_CPUS; i++)
1065 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1066
1067 /* allocate RAM */
1068 if ((uint64_t)RAM_size > hwdef->max_mem) {
1069 fprintf(stderr, "qemu: Too much memory for this machine: %d, maximum %d\n",
1070 (unsigned int)RAM_size / (1024 * 1024),
1071 (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1072 exit(1);
1073 }
1074 cpu_register_physical_memory(0, RAM_size, 0);
1075
1076 /* load boot prom */
1077 prom_offset = RAM_size + hwdef->vram_size;
1078 cpu_register_physical_memory(hwdef->slavio_base,
1079 (PROM_SIZE_MAX + TARGET_PAGE_SIZE - 1) &
1080 TARGET_PAGE_MASK,
1081 prom_offset | IO_MEM_ROM);
1082
1083 if (bios_name == NULL)
1084 bios_name = PROM_FILENAME;
1085 snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
1086 ret = load_elf(buf, hwdef->slavio_base - PROM_VADDR, NULL, NULL, NULL);
1087 if (ret < 0 || ret > PROM_SIZE_MAX)
1088 ret = load_image(buf, phys_ram_base + prom_offset);
1089 if (ret < 0 || ret > PROM_SIZE_MAX) {
1090 fprintf(stderr, "qemu: could not load prom '%s'\n",
1091 buf);
1092 exit(1);
1093 }
1094
1095 /* set up devices */
1096 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
1097
1098 for (i = 0; i < MAX_IOUNITS; i++)
1099 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
ff403da6
BS
1100 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1101 hwdef->iounit_version,
1102 sbi_irq[hwdef->me_irq]);
7d85892b
BS
1103
1104 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[hwdef->esp_irq],
1105 iounits[0], &espdma_irq, &esp_reset);
1106
1107 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[hwdef->le_irq],
1108 iounits[0], &ledma_irq, &le_reset);
1109
1110 if (graphic_depth != 8 && graphic_depth != 24) {
1111 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1112 exit (1);
1113 }
1114 tcx_init(ds, hwdef->tcx_base, phys_ram_base + RAM_size, RAM_size,
1115 hwdef->vram_size, graphic_width, graphic_height, graphic_depth);
1116
1117 if (nd_table[0].model == NULL
1118 || strcmp(nd_table[0].model, "lance") == 0) {
1119 lance_init(&nd_table[0], hwdef->le_base, ledma, *ledma_irq, le_reset);
1120 } else if (strcmp(nd_table[0].model, "?") == 0) {
1121 fprintf(stderr, "qemu: Supported NICs: lance\n");
1122 exit (1);
1123 } else {
1124 fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd_table[0].model);
1125 exit (1);
1126 }
1127
1128 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0,
1129 hwdef->nvram_size, 8);
1130
1131 slavio_timer_init_all(hwdef->counter_base, sbi_irq[hwdef->clock1_irq],
1132 sbi_cpu_irq, smp_cpus);
1133
1134 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[hwdef->ms_kb_irq],
1135 nographic);
1136 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1137 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
1138 slavio_serial_init(hwdef->serial_base, sbi_irq[hwdef->ser_irq],
1139 serial_hds[1], serial_hds[0]);
1140
1141 if (drive_get_max_bus(IF_SCSI) > 0) {
1142 fprintf(stderr, "qemu: too many SCSI bus\n");
1143 exit(1);
1144 }
1145
1146 main_esp = esp_init(hwdef->esp_base, espdma, *espdma_irq,
1147 esp_reset);
1148
1149 for (i = 0; i < ESP_MAX_DEVS; i++) {
1150 index = drive_get_index(IF_SCSI, 0, i);
1151 if (index == -1)
1152 continue;
1153 esp_scsi_attach(main_esp, drives_table[index].bdrv, i);
1154 }
1155
1156 kernel_size = sun4m_load_kernel(kernel_filename, kernel_cmdline,
1157 initrd_filename);
1158
1159 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1160 boot_device, RAM_size, kernel_size, graphic_width,
1161 graphic_height, graphic_depth, hwdef->machine_id, "Sun4d");
1162}
1163
1164/* SPARCserver 1000 hardware initialisation */
1165static void ss1000_init(int RAM_size, int vga_ram_size,
1166 const char *boot_device, DisplayState *ds,
1167 const char *kernel_filename, const char *kernel_cmdline,
1168 const char *initrd_filename, const char *cpu_model)
1169{
1170 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, ds, kernel_filename,
1171 kernel_cmdline, initrd_filename, cpu_model);
1172}
1173
1174/* SPARCcenter 2000 hardware initialisation */
1175static void ss2000_init(int RAM_size, int vga_ram_size,
1176 const char *boot_device, DisplayState *ds,
1177 const char *kernel_filename, const char *kernel_cmdline,
1178 const char *initrd_filename, const char *cpu_model)
1179{
1180 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, ds, kernel_filename,
1181 kernel_cmdline, initrd_filename, cpu_model);
1182}
1183
1184QEMUMachine ss1000_machine = {
1185 "SS-1000",
1186 "Sun4d platform, SPARCserver 1000",
1187 ss1000_init,
1188};
1189
1190QEMUMachine ss2000_machine = {
1191 "SS-2000",
1192 "Sun4d platform, SPARCcenter 2000",
1193 ss2000_init,
1194};