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