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