]> git.proxmox.com Git - qemu.git/blame - hw/sun4m.c
oss: refactor code around policy setting
[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;
c5de386a 98 target_phys_addr_t afx_base, idreg_base, dma_base, esp_base, le_base;
c227f099
AL
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
c5de386a
AT
603/* SS-5 TCX AFX register */
604static void afx_init(target_phys_addr_t addr)
605{
606 DeviceState *dev;
607 SysBusDevice *s;
608
609 dev = qdev_create(NULL, "tcx_afx");
610 qdev_init_nofail(dev);
611 s = sysbus_from_qdev(dev);
612
613 sysbus_mmio_map(s, 0, addr);
614}
615
616static int afx_init1(SysBusDevice *dev)
617{
618 ram_addr_t afx_offset;
619
620 afx_offset = qemu_ram_alloc(4);
621 sysbus_init_mmio(dev, 4, afx_offset | IO_MEM_RAM);
622 return 0;
623}
624
625static SysBusDeviceInfo afx_info = {
626 .init = afx_init1,
627 .qdev.name = "tcx_afx",
628 .qdev.size = sizeof(SysBusDevice),
629};
630
631static void afx_register_devices(void)
632{
633 sysbus_register_withprop(&afx_info);
634}
635
636device_init(afx_register_devices);
637
f48f6569 638/* Boot PROM (OpenBIOS) */
c227f099 639static void prom_init(target_phys_addr_t addr, const char *bios_name)
f48f6569
BS
640{
641 DeviceState *dev;
642 SysBusDevice *s;
643 char *filename;
644 int ret;
645
646 dev = qdev_create(NULL, "openprom");
e23a1b33 647 qdev_init_nofail(dev);
f48f6569
BS
648 s = sysbus_from_qdev(dev);
649
650 sysbus_mmio_map(s, 0, addr);
651
652 /* load boot prom */
653 if (bios_name == NULL) {
654 bios_name = PROM_FILENAME;
655 }
656 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
657 if (filename) {
ca20cf32
BS
658 ret = load_elf(filename, addr - PROM_VADDR, NULL, NULL, NULL,
659 1, ELF_MACHINE, 0);
f48f6569
BS
660 if (ret < 0 || ret > PROM_SIZE_MAX) {
661 ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
662 }
663 qemu_free(filename);
664 } else {
665 ret = -1;
666 }
667 if (ret < 0 || ret > PROM_SIZE_MAX) {
668 fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
669 exit(1);
670 }
671}
672
81a322d4 673static int prom_init1(SysBusDevice *dev)
f48f6569 674{
c227f099 675 ram_addr_t prom_offset;
f48f6569
BS
676
677 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
678 sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM);
81a322d4 679 return 0;
f48f6569
BS
680}
681
682static SysBusDeviceInfo prom_info = {
683 .init = prom_init1,
684 .qdev.name = "openprom",
685 .qdev.size = sizeof(SysBusDevice),
ee6847d1
GH
686 .qdev.props = (Property[]) {
687 {/* end of property list */}
f48f6569
BS
688 }
689};
690
691static void prom_register_devices(void)
692{
693 sysbus_register_withprop(&prom_info);
694}
695
696device_init(prom_register_devices);
697
ee6847d1
GH
698typedef struct RamDevice
699{
700 SysBusDevice busdev;
04843626 701 uint64_t size;
ee6847d1
GH
702} RamDevice;
703
a350db85 704/* System RAM */
81a322d4 705static int ram_init1(SysBusDevice *dev)
a350db85 706{
c227f099 707 ram_addr_t RAM_size, ram_offset;
ee6847d1 708 RamDevice *d = FROM_SYSBUS(RamDevice, dev);
a350db85 709
ee6847d1 710 RAM_size = d->size;
a350db85
BS
711
712 ram_offset = qemu_ram_alloc(RAM_size);
713 sysbus_init_mmio(dev, RAM_size, ram_offset);
81a322d4 714 return 0;
a350db85
BS
715}
716
c227f099 717static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size,
a350db85
BS
718 uint64_t max_mem)
719{
720 DeviceState *dev;
721 SysBusDevice *s;
ee6847d1 722 RamDevice *d;
a350db85
BS
723
724 /* allocate RAM */
725 if ((uint64_t)RAM_size > max_mem) {
726 fprintf(stderr,
727 "qemu: Too much memory for this machine: %d, maximum %d\n",
728 (unsigned int)(RAM_size / (1024 * 1024)),
729 (unsigned int)(max_mem / (1024 * 1024)));
730 exit(1);
731 }
732 dev = qdev_create(NULL, "memory");
a350db85
BS
733 s = sysbus_from_qdev(dev);
734
ee6847d1
GH
735 d = FROM_SYSBUS(RamDevice, s);
736 d->size = RAM_size;
e23a1b33 737 qdev_init_nofail(dev);
ee6847d1 738
a350db85
BS
739 sysbus_mmio_map(s, 0, addr);
740}
741
742static SysBusDeviceInfo ram_info = {
743 .init = ram_init1,
744 .qdev.name = "memory",
ee6847d1
GH
745 .qdev.size = sizeof(RamDevice),
746 .qdev.props = (Property[]) {
c885159a
GH
747 DEFINE_PROP_UINT64("size", RamDevice, size, 0),
748 DEFINE_PROP_END_OF_LIST(),
a350db85
BS
749 }
750};
751
752static void ram_register_devices(void)
753{
754 sysbus_register_withprop(&ram_info);
755}
756
757device_init(ram_register_devices);
758
666713c0
BS
759static CPUState *cpu_devinit(const char *cpu_model, unsigned int id,
760 uint64_t prom_addr, qemu_irq **cpu_irqs)
761{
762 CPUState *env;
763
764 env = cpu_init(cpu_model);
765 if (!env) {
766 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
767 exit(1);
768 }
769
770 cpu_sparc_set_id(env, id);
771 if (id == 0) {
772 qemu_register_reset(main_cpu_reset, env);
773 } else {
774 qemu_register_reset(secondary_cpu_reset, env);
775 env->halted = 1;
776 }
777 *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
778 env->prom_addr = prom_addr;
779
780 return env;
781}
782
c227f099 783static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
3ebf5aaf 784 const char *boot_device,
3023f332 785 const char *kernel_filename,
3ebf5aaf
BS
786 const char *kernel_cmdline,
787 const char *initrd_filename, const char *cpu_model)
420557e8 788{
666713c0 789 CPUState *envs[MAX_CPUS];
713c45fa 790 unsigned int i;
cfb9de9c 791 void *iommu, *espdma, *ledma, *nvram;
a1961a4b 792 qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
6f6260c7 793 espdma_irq, ledma_irq;
74ff8d90 794 qemu_irq esp_reset;
2582cfa0 795 qemu_irq fdc_tc;
6d0c293d 796 qemu_irq *cpu_halt;
5c6602c5 797 unsigned long kernel_size;
fd8014e1 798 DriveInfo *fd[MAX_FD];
3cce6243 799 void *fw_cfg;
420557e8 800
ba3c64fb 801 /* init CPUs */
3ebf5aaf
BS
802 if (!cpu_model)
803 cpu_model = hwdef->default_cpu_model;
b3a23197 804
ba3c64fb 805 for(i = 0; i < smp_cpus; i++) {
666713c0 806 envs[i] = cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
ba3c64fb 807 }
b3a23197
BS
808
809 for (i = smp_cpus; i < MAX_CPUS; i++)
810 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
811
3ebf5aaf 812
3ebf5aaf 813 /* set up devices */
a350db85
BS
814 ram_init(0, RAM_size, hwdef->max_mem);
815
f48f6569
BS
816 prom_init(hwdef->slavio_base, bios_name);
817
d453c2c3
BS
818 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
819 hwdef->intctl_base + 0x10000ULL,
462eda24 820 cpu_irqs);
a1961a4b
BS
821
822 for (i = 0; i < 32; i++) {
d453c2c3 823 slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
a1961a4b
BS
824 }
825 for (i = 0; i < MAX_CPUS; i++) {
d453c2c3 826 slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
a1961a4b 827 }
b3a23197 828
fe096129 829 if (hwdef->idreg_base) {
325f2747 830 idreg_init(hwdef->idreg_base);
4c2485de
BS
831 }
832
c5de386a
AT
833 if (hwdef->afx_base) {
834 afx_init(hwdef->afx_base);
835 }
836
ff403da6 837 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
c533e0b3 838 slavio_irq[30]);
ff403da6 839
c533e0b3 840 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[18],
74ff8d90 841 iommu, &espdma_irq);
2d069bab 842
5aca8c3b 843 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
74ff8d90 844 slavio_irq[16], iommu, &ledma_irq);
ba3c64fb 845
eee0b836
BS
846 if (graphic_depth != 8 && graphic_depth != 24) {
847 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
848 exit (1);
849 }
d95d8f1c 850 tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
dc828ca1 851 graphic_depth);
dbe06e18 852
74ff8d90 853 lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
dbe06e18 854
d95d8f1c 855 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
81732d19 856
c533e0b3 857 slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
81732d19 858
c533e0b3 859 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[14],
993fbfdb 860 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
b81b3b10
FB
861 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
862 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
c533e0b3 863 escc_init(hwdef->serial_base, slavio_irq[15], slavio_irq[15],
aeeb69c7 864 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
741402f9 865
6d0c293d 866 cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
b2b6f6ec
BS
867 slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
868 slavio_irq[30], fdc_tc);
869
2582cfa0
BS
870 if (hwdef->apc_base) {
871 apc_init(hwdef->apc_base, cpu_halt[0]);
872 }
2be17ebd 873
fe096129 874 if (hwdef->fd_base) {
e4bcb14c 875 /* there is zero or one floppy drive */
309e60bd 876 memset(fd, 0, sizeof(fd));
fd8014e1 877 fd[0] = drive_get(IF_FLOPPY, 0, 0);
c533e0b3 878 sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
2582cfa0 879 &fdc_tc);
e4bcb14c
TS
880 }
881
882 if (drive_get_max_bus(IF_SCSI) > 0) {
883 fprintf(stderr, "qemu: too many SCSI bus\n");
884 exit(1);
885 }
886
74ff8d90 887 esp_reset = qdev_get_gpio_in(espdma, 0);
cfb9de9c
PB
888 esp_init(hwdef->esp_base, 2,
889 espdma_memory_read, espdma_memory_write,
74ff8d90
BS
890 espdma, espdma_irq, &esp_reset);
891
f1587550 892
fa28ec52
BS
893 if (hwdef->cs_base) {
894 sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
c533e0b3 895 slavio_irq[5]);
fa28ec52 896 }
b3ceef24 897
293f78bc
BS
898 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
899 RAM_size);
36cd9210 900
36cd9210 901 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
b3ceef24 902 boot_device, RAM_size, kernel_size, graphic_width,
905fdcb5
BS
903 graphic_height, graphic_depth, hwdef->nvram_machine_id,
904 "Sun4m");
7eb0c8e8 905
fe096129 906 if (hwdef->ecc_base)
c533e0b3 907 ecc_init(hwdef->ecc_base, slavio_irq[28],
e42c20b4 908 hwdef->ecc_version);
3cce6243
BS
909
910 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
911 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
912 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
913 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
fbfcf955 914 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
513f789f
BS
915 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
916 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
917 if (kernel_cmdline) {
918 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
3c178e72 919 pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
6bb4ca57
BS
920 fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
921 (uint8_t*)strdup(kernel_cmdline),
922 strlen(kernel_cmdline) + 1);
513f789f
BS
923 } else {
924 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
925 }
926 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
927 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
928 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
929 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
36cd9210
BS
930}
931
905fdcb5
BS
932enum {
933 ss2_id = 0,
934 ss5_id = 32,
935 vger_id,
936 lx_id,
937 ss4_id,
938 scls_id,
939 sbook_id,
940 ss10_id = 64,
941 ss20_id,
942 ss600mp_id,
943 ss1000_id = 96,
944 ss2000_id,
945};
946
8137cde8 947static const struct sun4m_hwdef sun4m_hwdefs[] = {
36cd9210
BS
948 /* SS-5 */
949 {
950 .iommu_base = 0x10000000,
951 .tcx_base = 0x50000000,
952 .cs_base = 0x6c000000,
384ccb5d 953 .slavio_base = 0x70000000,
36cd9210
BS
954 .ms_kb_base = 0x71000000,
955 .serial_base = 0x71100000,
956 .nvram_base = 0x71200000,
957 .fd_base = 0x71400000,
958 .counter_base = 0x71d00000,
959 .intctl_base = 0x71e00000,
4c2485de 960 .idreg_base = 0x78000000,
36cd9210
BS
961 .dma_base = 0x78400000,
962 .esp_base = 0x78800000,
963 .le_base = 0x78c00000,
127fc407 964 .apc_base = 0x6a000000,
c5de386a 965 .afx_base = 0x6e000000,
0019ad53
BS
966 .aux1_base = 0x71900000,
967 .aux2_base = 0x71910000,
905fdcb5
BS
968 .nvram_machine_id = 0x80,
969 .machine_id = ss5_id,
cf3102ac 970 .iommu_version = 0x05000000,
3ebf5aaf
BS
971 .max_mem = 0x10000000,
972 .default_cpu_model = "Fujitsu MB86904",
e0353fe2
BS
973 },
974 /* SS-10 */
e0353fe2 975 {
5dcb6b91
BS
976 .iommu_base = 0xfe0000000ULL,
977 .tcx_base = 0xe20000000ULL,
5dcb6b91
BS
978 .slavio_base = 0xff0000000ULL,
979 .ms_kb_base = 0xff1000000ULL,
980 .serial_base = 0xff1100000ULL,
981 .nvram_base = 0xff1200000ULL,
982 .fd_base = 0xff1700000ULL,
983 .counter_base = 0xff1300000ULL,
984 .intctl_base = 0xff1400000ULL,
4c2485de 985 .idreg_base = 0xef0000000ULL,
5dcb6b91
BS
986 .dma_base = 0xef0400000ULL,
987 .esp_base = 0xef0800000ULL,
988 .le_base = 0xef0c00000ULL,
0019ad53 989 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
990 .aux1_base = 0xff1800000ULL,
991 .aux2_base = 0xff1a01000ULL,
7eb0c8e8
BS
992 .ecc_base = 0xf00000000ULL,
993 .ecc_version = 0x10000000, // version 0, implementation 1
905fdcb5
BS
994 .nvram_machine_id = 0x72,
995 .machine_id = ss10_id,
7fbfb139 996 .iommu_version = 0x03000000,
6ef05b95 997 .max_mem = 0xf00000000ULL,
3ebf5aaf 998 .default_cpu_model = "TI SuperSparc II",
36cd9210 999 },
6a3b9cc9
BS
1000 /* SS-600MP */
1001 {
1002 .iommu_base = 0xfe0000000ULL,
1003 .tcx_base = 0xe20000000ULL,
6a3b9cc9
BS
1004 .slavio_base = 0xff0000000ULL,
1005 .ms_kb_base = 0xff1000000ULL,
1006 .serial_base = 0xff1100000ULL,
1007 .nvram_base = 0xff1200000ULL,
6a3b9cc9
BS
1008 .counter_base = 0xff1300000ULL,
1009 .intctl_base = 0xff1400000ULL,
1010 .dma_base = 0xef0081000ULL,
1011 .esp_base = 0xef0080000ULL,
1012 .le_base = 0xef0060000ULL,
0019ad53 1013 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
1014 .aux1_base = 0xff1800000ULL,
1015 .aux2_base = 0xff1a01000ULL, // XXX should not exist
7eb0c8e8
BS
1016 .ecc_base = 0xf00000000ULL,
1017 .ecc_version = 0x00000000, // version 0, implementation 0
905fdcb5
BS
1018 .nvram_machine_id = 0x71,
1019 .machine_id = ss600mp_id,
7fbfb139 1020 .iommu_version = 0x01000000,
6ef05b95 1021 .max_mem = 0xf00000000ULL,
3ebf5aaf 1022 .default_cpu_model = "TI SuperSparc II",
6a3b9cc9 1023 },
ae40972f
BS
1024 /* SS-20 */
1025 {
1026 .iommu_base = 0xfe0000000ULL,
1027 .tcx_base = 0xe20000000ULL,
ae40972f
BS
1028 .slavio_base = 0xff0000000ULL,
1029 .ms_kb_base = 0xff1000000ULL,
1030 .serial_base = 0xff1100000ULL,
1031 .nvram_base = 0xff1200000ULL,
1032 .fd_base = 0xff1700000ULL,
1033 .counter_base = 0xff1300000ULL,
1034 .intctl_base = 0xff1400000ULL,
4c2485de 1035 .idreg_base = 0xef0000000ULL,
ae40972f
BS
1036 .dma_base = 0xef0400000ULL,
1037 .esp_base = 0xef0800000ULL,
1038 .le_base = 0xef0c00000ULL,
0019ad53 1039 .apc_base = 0xefa000000ULL, // XXX should not exist
577d8dd4
BS
1040 .aux1_base = 0xff1800000ULL,
1041 .aux2_base = 0xff1a01000ULL,
ae40972f
BS
1042 .ecc_base = 0xf00000000ULL,
1043 .ecc_version = 0x20000000, // version 0, implementation 2
905fdcb5
BS
1044 .nvram_machine_id = 0x72,
1045 .machine_id = ss20_id,
ae40972f 1046 .iommu_version = 0x13000000,
6ef05b95 1047 .max_mem = 0xf00000000ULL,
ae40972f
BS
1048 .default_cpu_model = "TI SuperSparc II",
1049 },
a526a31c
BS
1050 /* Voyager */
1051 {
1052 .iommu_base = 0x10000000,
1053 .tcx_base = 0x50000000,
a526a31c
BS
1054 .slavio_base = 0x70000000,
1055 .ms_kb_base = 0x71000000,
1056 .serial_base = 0x71100000,
1057 .nvram_base = 0x71200000,
1058 .fd_base = 0x71400000,
1059 .counter_base = 0x71d00000,
1060 .intctl_base = 0x71e00000,
1061 .idreg_base = 0x78000000,
1062 .dma_base = 0x78400000,
1063 .esp_base = 0x78800000,
1064 .le_base = 0x78c00000,
1065 .apc_base = 0x71300000, // pmc
1066 .aux1_base = 0x71900000,
1067 .aux2_base = 0x71910000,
905fdcb5
BS
1068 .nvram_machine_id = 0x80,
1069 .machine_id = vger_id,
a526a31c 1070 .iommu_version = 0x05000000,
a526a31c
BS
1071 .max_mem = 0x10000000,
1072 .default_cpu_model = "Fujitsu MB86904",
1073 },
1074 /* LX */
1075 {
1076 .iommu_base = 0x10000000,
1077 .tcx_base = 0x50000000,
a526a31c
BS
1078 .slavio_base = 0x70000000,
1079 .ms_kb_base = 0x71000000,
1080 .serial_base = 0x71100000,
1081 .nvram_base = 0x71200000,
1082 .fd_base = 0x71400000,
1083 .counter_base = 0x71d00000,
1084 .intctl_base = 0x71e00000,
1085 .idreg_base = 0x78000000,
1086 .dma_base = 0x78400000,
1087 .esp_base = 0x78800000,
1088 .le_base = 0x78c00000,
a526a31c
BS
1089 .aux1_base = 0x71900000,
1090 .aux2_base = 0x71910000,
905fdcb5
BS
1091 .nvram_machine_id = 0x80,
1092 .machine_id = lx_id,
a526a31c 1093 .iommu_version = 0x04000000,
a526a31c
BS
1094 .max_mem = 0x10000000,
1095 .default_cpu_model = "TI MicroSparc I",
1096 },
1097 /* SS-4 */
1098 {
1099 .iommu_base = 0x10000000,
1100 .tcx_base = 0x50000000,
1101 .cs_base = 0x6c000000,
1102 .slavio_base = 0x70000000,
1103 .ms_kb_base = 0x71000000,
1104 .serial_base = 0x71100000,
1105 .nvram_base = 0x71200000,
1106 .fd_base = 0x71400000,
1107 .counter_base = 0x71d00000,
1108 .intctl_base = 0x71e00000,
1109 .idreg_base = 0x78000000,
1110 .dma_base = 0x78400000,
1111 .esp_base = 0x78800000,
1112 .le_base = 0x78c00000,
1113 .apc_base = 0x6a000000,
1114 .aux1_base = 0x71900000,
1115 .aux2_base = 0x71910000,
905fdcb5
BS
1116 .nvram_machine_id = 0x80,
1117 .machine_id = ss4_id,
a526a31c 1118 .iommu_version = 0x05000000,
a526a31c
BS
1119 .max_mem = 0x10000000,
1120 .default_cpu_model = "Fujitsu MB86904",
1121 },
1122 /* SPARCClassic */
1123 {
1124 .iommu_base = 0x10000000,
1125 .tcx_base = 0x50000000,
a526a31c
BS
1126 .slavio_base = 0x70000000,
1127 .ms_kb_base = 0x71000000,
1128 .serial_base = 0x71100000,
1129 .nvram_base = 0x71200000,
1130 .fd_base = 0x71400000,
1131 .counter_base = 0x71d00000,
1132 .intctl_base = 0x71e00000,
1133 .idreg_base = 0x78000000,
1134 .dma_base = 0x78400000,
1135 .esp_base = 0x78800000,
1136 .le_base = 0x78c00000,
1137 .apc_base = 0x6a000000,
1138 .aux1_base = 0x71900000,
1139 .aux2_base = 0x71910000,
905fdcb5
BS
1140 .nvram_machine_id = 0x80,
1141 .machine_id = scls_id,
a526a31c 1142 .iommu_version = 0x05000000,
a526a31c
BS
1143 .max_mem = 0x10000000,
1144 .default_cpu_model = "TI MicroSparc I",
1145 },
1146 /* SPARCbook */
1147 {
1148 .iommu_base = 0x10000000,
1149 .tcx_base = 0x50000000, // XXX
a526a31c
BS
1150 .slavio_base = 0x70000000,
1151 .ms_kb_base = 0x71000000,
1152 .serial_base = 0x71100000,
1153 .nvram_base = 0x71200000,
1154 .fd_base = 0x71400000,
1155 .counter_base = 0x71d00000,
1156 .intctl_base = 0x71e00000,
1157 .idreg_base = 0x78000000,
1158 .dma_base = 0x78400000,
1159 .esp_base = 0x78800000,
1160 .le_base = 0x78c00000,
1161 .apc_base = 0x6a000000,
1162 .aux1_base = 0x71900000,
1163 .aux2_base = 0x71910000,
905fdcb5
BS
1164 .nvram_machine_id = 0x80,
1165 .machine_id = sbook_id,
a526a31c 1166 .iommu_version = 0x05000000,
a526a31c
BS
1167 .max_mem = 0x10000000,
1168 .default_cpu_model = "TI MicroSparc I",
1169 },
36cd9210
BS
1170};
1171
36cd9210 1172/* SPARCstation 5 hardware initialisation */
c227f099 1173static void ss5_init(ram_addr_t RAM_size,
3023f332 1174 const char *boot_device,
b881c2c6
BS
1175 const char *kernel_filename, const char *kernel_cmdline,
1176 const char *initrd_filename, const char *cpu_model)
36cd9210 1177{
3023f332 1178 sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1179 kernel_cmdline, initrd_filename, cpu_model);
420557e8 1180}
c0e564d5 1181
e0353fe2 1182/* SPARCstation 10 hardware initialisation */
c227f099 1183static void ss10_init(ram_addr_t RAM_size,
3023f332 1184 const char *boot_device,
b881c2c6
BS
1185 const char *kernel_filename, const char *kernel_cmdline,
1186 const char *initrd_filename, const char *cpu_model)
e0353fe2 1187{
3023f332 1188 sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1189 kernel_cmdline, initrd_filename, cpu_model);
e0353fe2
BS
1190}
1191
6a3b9cc9 1192/* SPARCserver 600MP hardware initialisation */
c227f099 1193static void ss600mp_init(ram_addr_t RAM_size,
3023f332 1194 const char *boot_device,
77f193da
BS
1195 const char *kernel_filename,
1196 const char *kernel_cmdline,
6a3b9cc9
BS
1197 const char *initrd_filename, const char *cpu_model)
1198{
3023f332 1199 sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1200 kernel_cmdline, initrd_filename, cpu_model);
6a3b9cc9
BS
1201}
1202
ae40972f 1203/* SPARCstation 20 hardware initialisation */
c227f099 1204static void ss20_init(ram_addr_t RAM_size,
3023f332 1205 const char *boot_device,
ae40972f
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[3], RAM_size, boot_device, kernel_filename,
ee76f82e
BS
1210 kernel_cmdline, initrd_filename, cpu_model);
1211}
1212
a526a31c 1213/* SPARCstation Voyager hardware initialisation */
c227f099 1214static void vger_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[4], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1220 kernel_cmdline, initrd_filename, cpu_model);
1221}
1222
1223/* SPARCstation LX hardware initialisation */
c227f099 1224static void ss_lx_init(ram_addr_t RAM_size,
3023f332 1225 const char *boot_device,
a526a31c
BS
1226 const char *kernel_filename, const char *kernel_cmdline,
1227 const char *initrd_filename, const char *cpu_model)
1228{
3023f332 1229 sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1230 kernel_cmdline, initrd_filename, cpu_model);
1231}
1232
1233/* SPARCstation 4 hardware initialisation */
c227f099 1234static void ss4_init(ram_addr_t RAM_size,
3023f332 1235 const char *boot_device,
a526a31c
BS
1236 const char *kernel_filename, const char *kernel_cmdline,
1237 const char *initrd_filename, const char *cpu_model)
1238{
3023f332 1239 sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1240 kernel_cmdline, initrd_filename, cpu_model);
1241}
1242
1243/* SPARCClassic hardware initialisation */
c227f099 1244static void scls_init(ram_addr_t RAM_size,
3023f332 1245 const char *boot_device,
a526a31c
BS
1246 const char *kernel_filename, const char *kernel_cmdline,
1247 const char *initrd_filename, const char *cpu_model)
1248{
3023f332 1249 sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1250 kernel_cmdline, initrd_filename, cpu_model);
1251}
1252
1253/* SPARCbook hardware initialisation */
c227f099 1254static void sbook_init(ram_addr_t RAM_size,
3023f332 1255 const char *boot_device,
a526a31c
BS
1256 const char *kernel_filename, const char *kernel_cmdline,
1257 const char *initrd_filename, const char *cpu_model)
1258{
3023f332 1259 sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1260 kernel_cmdline, initrd_filename, cpu_model);
1261}
1262
f80f9ec9 1263static QEMUMachine ss5_machine = {
66de733b
BS
1264 .name = "SS-5",
1265 .desc = "Sun4m platform, SPARCstation 5",
1266 .init = ss5_init,
c9b1ae2c 1267 .use_scsi = 1,
0c257437 1268 .is_default = 1,
c0e564d5 1269};
e0353fe2 1270
f80f9ec9 1271static QEMUMachine ss10_machine = {
66de733b
BS
1272 .name = "SS-10",
1273 .desc = "Sun4m platform, SPARCstation 10",
1274 .init = ss10_init,
c9b1ae2c 1275 .use_scsi = 1,
1bcee014 1276 .max_cpus = 4,
e0353fe2 1277};
6a3b9cc9 1278
f80f9ec9 1279static QEMUMachine ss600mp_machine = {
66de733b
BS
1280 .name = "SS-600MP",
1281 .desc = "Sun4m platform, SPARCserver 600MP",
1282 .init = ss600mp_init,
c9b1ae2c 1283 .use_scsi = 1,
1bcee014 1284 .max_cpus = 4,
6a3b9cc9 1285};
ae40972f 1286
f80f9ec9 1287static QEMUMachine ss20_machine = {
66de733b
BS
1288 .name = "SS-20",
1289 .desc = "Sun4m platform, SPARCstation 20",
1290 .init = ss20_init,
c9b1ae2c 1291 .use_scsi = 1,
1bcee014 1292 .max_cpus = 4,
ae40972f
BS
1293};
1294
f80f9ec9 1295static QEMUMachine voyager_machine = {
66de733b
BS
1296 .name = "Voyager",
1297 .desc = "Sun4m platform, SPARCstation Voyager",
1298 .init = vger_init,
c9b1ae2c 1299 .use_scsi = 1,
a526a31c
BS
1300};
1301
f80f9ec9 1302static QEMUMachine ss_lx_machine = {
66de733b
BS
1303 .name = "LX",
1304 .desc = "Sun4m platform, SPARCstation LX",
1305 .init = ss_lx_init,
c9b1ae2c 1306 .use_scsi = 1,
a526a31c
BS
1307};
1308
f80f9ec9 1309static QEMUMachine ss4_machine = {
66de733b
BS
1310 .name = "SS-4",
1311 .desc = "Sun4m platform, SPARCstation 4",
1312 .init = ss4_init,
c9b1ae2c 1313 .use_scsi = 1,
a526a31c
BS
1314};
1315
f80f9ec9 1316static QEMUMachine scls_machine = {
66de733b
BS
1317 .name = "SPARCClassic",
1318 .desc = "Sun4m platform, SPARCClassic",
1319 .init = scls_init,
c9b1ae2c 1320 .use_scsi = 1,
a526a31c
BS
1321};
1322
f80f9ec9 1323static QEMUMachine sbook_machine = {
66de733b
BS
1324 .name = "SPARCbook",
1325 .desc = "Sun4m platform, SPARCbook",
1326 .init = sbook_init,
c9b1ae2c 1327 .use_scsi = 1,
a526a31c
BS
1328};
1329
7d85892b
BS
1330static const struct sun4d_hwdef sun4d_hwdefs[] = {
1331 /* SS-1000 */
1332 {
1333 .iounit_bases = {
1334 0xfe0200000ULL,
1335 0xfe1200000ULL,
1336 0xfe2200000ULL,
1337 0xfe3200000ULL,
1338 -1,
1339 },
1340 .tcx_base = 0x820000000ULL,
1341 .slavio_base = 0xf00000000ULL,
1342 .ms_kb_base = 0xf00240000ULL,
1343 .serial_base = 0xf00200000ULL,
1344 .nvram_base = 0xf00280000ULL,
1345 .counter_base = 0xf00300000ULL,
1346 .espdma_base = 0x800081000ULL,
1347 .esp_base = 0x800080000ULL,
1348 .ledma_base = 0x800040000ULL,
1349 .le_base = 0x800060000ULL,
1350 .sbi_base = 0xf02800000ULL,
905fdcb5
BS
1351 .nvram_machine_id = 0x80,
1352 .machine_id = ss1000_id,
7d85892b 1353 .iounit_version = 0x03000000,
6ef05b95 1354 .max_mem = 0xf00000000ULL,
7d85892b
BS
1355 .default_cpu_model = "TI SuperSparc II",
1356 },
1357 /* SS-2000 */
1358 {
1359 .iounit_bases = {
1360 0xfe0200000ULL,
1361 0xfe1200000ULL,
1362 0xfe2200000ULL,
1363 0xfe3200000ULL,
1364 0xfe4200000ULL,
1365 },
1366 .tcx_base = 0x820000000ULL,
1367 .slavio_base = 0xf00000000ULL,
1368 .ms_kb_base = 0xf00240000ULL,
1369 .serial_base = 0xf00200000ULL,
1370 .nvram_base = 0xf00280000ULL,
1371 .counter_base = 0xf00300000ULL,
1372 .espdma_base = 0x800081000ULL,
1373 .esp_base = 0x800080000ULL,
1374 .ledma_base = 0x800040000ULL,
1375 .le_base = 0x800060000ULL,
1376 .sbi_base = 0xf02800000ULL,
905fdcb5
BS
1377 .nvram_machine_id = 0x80,
1378 .machine_id = ss2000_id,
7d85892b 1379 .iounit_version = 0x03000000,
6ef05b95 1380 .max_mem = 0xf00000000ULL,
7d85892b
BS
1381 .default_cpu_model = "TI SuperSparc II",
1382 },
1383};
1384
c227f099 1385static DeviceState *sbi_init(target_phys_addr_t addr, qemu_irq **parent_irq)
4b48bf05
BS
1386{
1387 DeviceState *dev;
1388 SysBusDevice *s;
1389 unsigned int i;
1390
1391 dev = qdev_create(NULL, "sbi");
e23a1b33 1392 qdev_init_nofail(dev);
4b48bf05
BS
1393
1394 s = sysbus_from_qdev(dev);
1395
1396 for (i = 0; i < MAX_CPUS; i++) {
1397 sysbus_connect_irq(s, i, *parent_irq[i]);
1398 }
1399
1400 sysbus_mmio_map(s, 0, addr);
1401
1402 return dev;
1403}
1404
c227f099 1405static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
7d85892b 1406 const char *boot_device,
3023f332 1407 const char *kernel_filename,
7d85892b
BS
1408 const char *kernel_cmdline,
1409 const char *initrd_filename, const char *cpu_model)
1410{
666713c0 1411 CPUState *envs[MAX_CPUS];
7d85892b 1412 unsigned int i;
7fc06735
BS
1413 void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram;
1414 qemu_irq *cpu_irqs[MAX_CPUS], sbi_irq[32], sbi_cpu_irq[MAX_CPUS],
6f6260c7 1415 espdma_irq, ledma_irq;
74ff8d90 1416 qemu_irq esp_reset;
5c6602c5 1417 unsigned long kernel_size;
3cce6243 1418 void *fw_cfg;
7fc06735 1419 DeviceState *dev;
7d85892b
BS
1420
1421 /* init CPUs */
1422 if (!cpu_model)
1423 cpu_model = hwdef->default_cpu_model;
1424
666713c0
BS
1425 for(i = 0; i < smp_cpus; i++) {
1426 envs[i] = cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
7d85892b
BS
1427 }
1428
1429 for (i = smp_cpus; i < MAX_CPUS; i++)
1430 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1431
7d85892b 1432 /* set up devices */
a350db85
BS
1433 ram_init(0, RAM_size, hwdef->max_mem);
1434
f48f6569
BS
1435 prom_init(hwdef->slavio_base, bios_name);
1436
7fc06735
BS
1437 dev = sbi_init(hwdef->sbi_base, cpu_irqs);
1438
1439 for (i = 0; i < 32; i++) {
1440 sbi_irq[i] = qdev_get_gpio_in(dev, i);
1441 }
1442 for (i = 0; i < MAX_CPUS; i++) {
1443 sbi_cpu_irq[i] = qdev_get_gpio_in(dev, 32 + i);
1444 }
7d85892b
BS
1445
1446 for (i = 0; i < MAX_IOUNITS; i++)
c227f099 1447 if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
ff403da6
BS
1448 iounits[i] = iommu_init(hwdef->iounit_bases[i],
1449 hwdef->iounit_version,
c533e0b3 1450 sbi_irq[0]);
7d85892b 1451
c533e0b3 1452 espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[3],
74ff8d90 1453 iounits[0], &espdma_irq);
7d85892b 1454
c533e0b3 1455 ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[4],
74ff8d90 1456 iounits[0], &ledma_irq);
7d85892b
BS
1457
1458 if (graphic_depth != 8 && graphic_depth != 24) {
1459 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1460 exit (1);
1461 }
d95d8f1c 1462 tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
dc828ca1 1463 graphic_depth);
7d85892b 1464
74ff8d90 1465 lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
7d85892b 1466
d95d8f1c 1467 nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
7d85892b 1468
c533e0b3 1469 slavio_timer_init_all(hwdef->counter_base, sbi_irq[10], sbi_cpu_irq, smp_cpus);
7d85892b 1470
c533e0b3 1471 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[12],
993fbfdb 1472 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
7d85892b
BS
1473 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1474 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
c533e0b3 1475 escc_init(hwdef->serial_base, sbi_irq[12], sbi_irq[12],
aeeb69c7 1476 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
7d85892b
BS
1477
1478 if (drive_get_max_bus(IF_SCSI) > 0) {
1479 fprintf(stderr, "qemu: too many SCSI bus\n");
1480 exit(1);
1481 }
1482
74ff8d90 1483 esp_reset = qdev_get_gpio_in(espdma, 0);
cfb9de9c
PB
1484 esp_init(hwdef->esp_base, 2,
1485 espdma_memory_read, espdma_memory_write,
74ff8d90 1486 espdma, espdma_irq, &esp_reset);
7d85892b 1487
293f78bc
BS
1488 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1489 RAM_size);
7d85892b
BS
1490
1491 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1492 boot_device, RAM_size, kernel_size, graphic_width,
905fdcb5
BS
1493 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1494 "Sun4d");
3cce6243
BS
1495
1496 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1497 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
1498 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1499 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
513f789f
BS
1500 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1501 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1502 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1503 if (kernel_cmdline) {
1504 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
3c178e72 1505 pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
6bb4ca57
BS
1506 fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
1507 (uint8_t*)strdup(kernel_cmdline),
1508 strlen(kernel_cmdline) + 1);
513f789f
BS
1509 } else {
1510 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1511 }
1512 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1513 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1514 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1515 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
7d85892b
BS
1516}
1517
1518/* SPARCserver 1000 hardware initialisation */
c227f099 1519static void ss1000_init(ram_addr_t RAM_size,
3023f332 1520 const char *boot_device,
7d85892b
BS
1521 const char *kernel_filename, const char *kernel_cmdline,
1522 const char *initrd_filename, const char *cpu_model)
1523{
3023f332 1524 sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
7d85892b
BS
1525 kernel_cmdline, initrd_filename, cpu_model);
1526}
1527
1528/* SPARCcenter 2000 hardware initialisation */
c227f099 1529static void ss2000_init(ram_addr_t RAM_size,
3023f332 1530 const char *boot_device,
7d85892b
BS
1531 const char *kernel_filename, const char *kernel_cmdline,
1532 const char *initrd_filename, const char *cpu_model)
1533{
3023f332 1534 sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
7d85892b
BS
1535 kernel_cmdline, initrd_filename, cpu_model);
1536}
1537
f80f9ec9 1538static QEMUMachine ss1000_machine = {
66de733b
BS
1539 .name = "SS-1000",
1540 .desc = "Sun4d platform, SPARCserver 1000",
1541 .init = ss1000_init,
c9b1ae2c 1542 .use_scsi = 1,
1bcee014 1543 .max_cpus = 8,
7d85892b
BS
1544};
1545
f80f9ec9 1546static QEMUMachine ss2000_machine = {
66de733b
BS
1547 .name = "SS-2000",
1548 .desc = "Sun4d platform, SPARCcenter 2000",
1549 .init = ss2000_init,
c9b1ae2c 1550 .use_scsi = 1,
1bcee014 1551 .max_cpus = 20,
7d85892b 1552};
8137cde8
BS
1553
1554static const struct sun4c_hwdef sun4c_hwdefs[] = {
1555 /* SS-2 */
1556 {
1557 .iommu_base = 0xf8000000,
1558 .tcx_base = 0xfe000000,
8137cde8
BS
1559 .slavio_base = 0xf6000000,
1560 .intctl_base = 0xf5000000,
1561 .counter_base = 0xf3000000,
1562 .ms_kb_base = 0xf0000000,
1563 .serial_base = 0xf1000000,
1564 .nvram_base = 0xf2000000,
1565 .fd_base = 0xf7200000,
1566 .dma_base = 0xf8400000,
1567 .esp_base = 0xf8800000,
1568 .le_base = 0xf8c00000,
8137cde8 1569 .aux1_base = 0xf7400003,
8137cde8
BS
1570 .nvram_machine_id = 0x55,
1571 .machine_id = ss2_id,
1572 .max_mem = 0x10000000,
1573 .default_cpu_model = "Cypress CY7C601",
1574 },
1575};
1576
c227f099 1577static DeviceState *sun4c_intctl_init(target_phys_addr_t addr,
4b48bf05
BS
1578 qemu_irq *parent_irq)
1579{
1580 DeviceState *dev;
1581 SysBusDevice *s;
1582 unsigned int i;
1583
1584 dev = qdev_create(NULL, "sun4c_intctl");
e23a1b33 1585 qdev_init_nofail(dev);
4b48bf05
BS
1586
1587 s = sysbus_from_qdev(dev);
1588
1589 for (i = 0; i < MAX_PILS; i++) {
1590 sysbus_connect_irq(s, i, parent_irq[i]);
1591 }
1592 sysbus_mmio_map(s, 0, addr);
1593
1594 return dev;
1595}
1596
c227f099 1597static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
8137cde8 1598 const char *boot_device,
3023f332 1599 const char *kernel_filename,
8137cde8
BS
1600 const char *kernel_cmdline,
1601 const char *initrd_filename, const char *cpu_model)
1602{
1603 CPUState *env;
cfb9de9c 1604 void *iommu, *espdma, *ledma, *nvram;
e32cba29 1605 qemu_irq *cpu_irqs, slavio_irq[8], espdma_irq, ledma_irq;
74ff8d90 1606 qemu_irq esp_reset;
2582cfa0 1607 qemu_irq fdc_tc;
5c6602c5 1608 unsigned long kernel_size;
fd8014e1 1609 DriveInfo *fd[MAX_FD];
8137cde8 1610 void *fw_cfg;
e32cba29
BS
1611 DeviceState *dev;
1612 unsigned int i;
8137cde8
BS
1613
1614 /* init CPU */
1615 if (!cpu_model)
1616 cpu_model = hwdef->default_cpu_model;
1617
666713c0 1618 env = cpu_devinit(cpu_model, 0, hwdef->slavio_base, &cpu_irqs);
8137cde8 1619
8137cde8 1620 /* set up devices */
a350db85
BS
1621 ram_init(0, RAM_size, hwdef->max_mem);
1622
f48f6569
BS
1623 prom_init(hwdef->slavio_base, bios_name);
1624
e32cba29
BS
1625 dev = sun4c_intctl_init(hwdef->intctl_base, cpu_irqs);
1626
1627 for (i = 0; i < 8; i++) {
1628 slavio_irq[i] = qdev_get_gpio_in(dev, i);
1629 }
8137cde8
BS
1630
1631 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
c533e0b3 1632 slavio_irq[1]);
8137cde8 1633
c533e0b3 1634 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[2],
74ff8d90 1635 iommu, &espdma_irq);
8137cde8
BS
1636
1637 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
74ff8d90 1638 slavio_irq[3], iommu, &ledma_irq);
8137cde8
BS
1639
1640 if (graphic_depth != 8 && graphic_depth != 24) {
1641 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
1642 exit (1);
1643 }
d95d8f1c 1644 tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
dc828ca1 1645 graphic_depth);
8137cde8 1646
74ff8d90 1647 lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
8137cde8 1648
d95d8f1c 1649 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x800, 2);
8137cde8 1650
c533e0b3 1651 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[1],
993fbfdb 1652 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
8137cde8
BS
1653 // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
1654 // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
c533e0b3
BS
1655 escc_init(hwdef->serial_base, slavio_irq[1],
1656 slavio_irq[1], serial_hds[0], serial_hds[1],
aeeb69c7 1657 ESCC_CLOCK, 1);
8137cde8 1658
b2b6f6ec 1659 slavio_misc_init(0, hwdef->aux1_base, 0, slavio_irq[1], fdc_tc);
8137cde8 1660
c227f099 1661 if (hwdef->fd_base != (target_phys_addr_t)-1) {
8137cde8 1662 /* there is zero or one floppy drive */
ce802585 1663 memset(fd, 0, sizeof(fd));
fd8014e1 1664 fd[0] = drive_get(IF_FLOPPY, 0, 0);
c533e0b3 1665 sun4m_fdctrl_init(slavio_irq[1], hwdef->fd_base, fd,
2582cfa0 1666 &fdc_tc);
8137cde8
BS
1667 }
1668
1669 if (drive_get_max_bus(IF_SCSI) > 0) {
1670 fprintf(stderr, "qemu: too many SCSI bus\n");
1671 exit(1);
1672 }
1673
74ff8d90 1674 esp_reset = qdev_get_gpio_in(espdma, 0);
cfb9de9c
PB
1675 esp_init(hwdef->esp_base, 2,
1676 espdma_memory_read, espdma_memory_write,
74ff8d90 1677 espdma, espdma_irq, &esp_reset);
8137cde8
BS
1678
1679 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1680 RAM_size);
1681
1682 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
1683 boot_device, RAM_size, kernel_size, graphic_width,
1684 graphic_height, graphic_depth, hwdef->nvram_machine_id,
1685 "Sun4c");
1686
1687 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
1688 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
1689 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
1690 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
513f789f
BS
1691 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1692 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1693 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1694 if (kernel_cmdline) {
1695 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
3c178e72 1696 pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
6bb4ca57
BS
1697 fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
1698 (uint8_t*)strdup(kernel_cmdline),
1699 strlen(kernel_cmdline) + 1);
513f789f
BS
1700 } else {
1701 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1702 }
1703 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1704 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1705 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1706 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
8137cde8
BS
1707}
1708
1709/* SPARCstation 2 hardware initialisation */
c227f099 1710static void ss2_init(ram_addr_t RAM_size,
3023f332 1711 const char *boot_device,
8137cde8
BS
1712 const char *kernel_filename, const char *kernel_cmdline,
1713 const char *initrd_filename, const char *cpu_model)
1714{
3023f332 1715 sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
8137cde8
BS
1716 kernel_cmdline, initrd_filename, cpu_model);
1717}
1718
f80f9ec9 1719static QEMUMachine ss2_machine = {
8137cde8
BS
1720 .name = "SS-2",
1721 .desc = "Sun4c platform, SPARCstation 2",
1722 .init = ss2_init,
8137cde8 1723 .use_scsi = 1,
8137cde8 1724};
f80f9ec9
AL
1725
1726static void ss2_machine_init(void)
1727{
1728 qemu_register_machine(&ss5_machine);
1729 qemu_register_machine(&ss10_machine);
1730 qemu_register_machine(&ss600mp_machine);
1731 qemu_register_machine(&ss20_machine);
1732 qemu_register_machine(&voyager_machine);
1733 qemu_register_machine(&ss_lx_machine);
1734 qemu_register_machine(&ss4_machine);
1735 qemu_register_machine(&scls_machine);
1736 qemu_register_machine(&sbook_machine);
1737 qemu_register_machine(&ss1000_machine);
1738 qemu_register_machine(&ss2000_machine);
1739 qemu_register_machine(&ss2_machine);
1740}
1741
1742machine_init(ss2_machine_init);