]> git.proxmox.com Git - mirror_qemu.git/blame - hw/sparc/sun4m.c
cpu: Replace cpu_single_env with CPUState current_cpu
[mirror_qemu.git] / hw / sparc / 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 */
83c9f4ca 24#include "hw/sysbus.h"
1de7afc9 25#include "qemu/timer.h"
0d09e41a
PB
26#include "hw/sparc/sun4m.h"
27#include "hw/timer/m48t59.h"
28#include "hw/sparc/sparc32_dma.h"
29#include "hw/block/fdc.h"
9c17d615 30#include "sysemu/sysemu.h"
1422e32d 31#include "net/net.h"
83c9f4ca 32#include "hw/boards.h"
ec0503b4 33#include "hw/nvram/openbios_firmware_abi.h"
0d09e41a
PB
34#include "hw/scsi/esp.h"
35#include "hw/i386/pc.h"
36#include "hw/isa/isa.h"
37#include "hw/nvram/fw_cfg.h"
38#include "hw/char/escc.h"
83c9f4ca 39#include "hw/empty_slot.h"
83c9f4ca 40#include "hw/loader.h"
ca20cf32 41#include "elf.h"
9c17d615 42#include "sysemu/blockdev.h"
97bf4851 43#include "trace.h"
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 *
58 * See for example: http://www.sunhelp.org/faq/sunref1.html
59 */
60
420557e8 61#define KERNEL_LOAD_ADDR 0x00004000
b6f479d3 62#define CMDLINE_ADDR 0x007ff000
713c45fa 63#define INITRD_LOAD_ADDR 0x00800000
a7227727 64#define PROM_SIZE_MAX (1024 * 1024)
40ce0a9a 65#define PROM_VADDR 0xffd00000
f930d07e 66#define PROM_FILENAME "openbios-sparc32"
3cce6243 67#define CFG_ADDR 0xd00000510ULL
fbfcf955 68#define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
b8174937 69
ba3c64fb 70#define MAX_CPUS 16
b3a23197 71#define MAX_PILS 16
9a62fb24 72#define MAX_VSIMMS 4
420557e8 73
b4ed08e0
BS
74#define ESCC_CLOCK 4915200
75
8137cde8 76struct sun4m_hwdef {
a8170e5e
AK
77 hwaddr iommu_base, iommu_pad_base, iommu_pad_len, slavio_base;
78 hwaddr intctl_base, counter_base, nvram_base, ms_kb_base;
79 hwaddr serial_base, fd_base;
80 hwaddr afx_base, idreg_base, dma_base, esp_base, le_base;
81 hwaddr tcx_base, cs_base, apc_base, aux1_base, aux2_base;
82 hwaddr bpp_base, dbri_base, sx_base;
9a62fb24 83 struct {
a8170e5e 84 hwaddr reg_base, vram_base;
9a62fb24 85 } vsimm[MAX_VSIMMS];
a8170e5e 86 hwaddr ecc_base;
3ebf5aaf
BS
87 uint64_t max_mem;
88 const char * const default_cpu_model;
61999750
BS
89 uint32_t ecc_version;
90 uint32_t iommu_version;
91 uint16_t machine_id;
92 uint8_t nvram_machine_id;
36cd9210
BS
93};
94
6f7e9aec
FB
95int DMA_get_channel_mode (int nchan)
96{
97 return 0;
98}
99int DMA_read_memory (int nchan, void *buf, int pos, int size)
100{
101 return 0;
102}
103int DMA_write_memory (int nchan, void *buf, int pos, int size)
104{
105 return 0;
106}
107void DMA_hold_DREQ (int nchan) {}
108void DMA_release_DREQ (int nchan) {}
109void DMA_schedule(int nchan) {}
4556bd8b
BS
110
111void DMA_init(int high_page_enable, qemu_irq *cpu_request_exit)
112{
113}
114
6f7e9aec
FB
115void DMA_register_channel (int nchan,
116 DMA_transfer_handler transfer_handler,
117 void *opaque)
118{
119}
120
513f789f 121static int fw_cfg_boot_set(void *opaque, const char *boot_device)
81864572 122{
513f789f 123 fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
81864572
BS
124 return 0;
125}
126
43a34704
BS
127static void nvram_init(M48t59State *nvram, uint8_t *macaddr,
128 const char *cmdline, const char *boot_devices,
129 ram_addr_t RAM_size, uint32_t kernel_size,
f930d07e 130 int width, int height, int depth,
905fdcb5 131 int nvram_machine_id, const char *arch)
e80cfcfc 132{
d2c63fc1 133 unsigned int i;
66508601 134 uint32_t start, end;
d2c63fc1 135 uint8_t image[0x1ff0];
d2c63fc1
BS
136 struct OpenBIOS_nvpart_v1 *part_header;
137
138 memset(image, '\0', sizeof(image));
e80cfcfc 139
513f789f 140 start = 0;
b6f479d3 141
66508601
BS
142 // OpenBIOS nvram variables
143 // Variable partition
d2c63fc1
BS
144 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
145 part_header->signature = OPENBIOS_PART_SYSTEM;
363a37d5 146 pstrcpy(part_header->name, sizeof(part_header->name), "system");
66508601 147
d2c63fc1 148 end = start + sizeof(struct OpenBIOS_nvpart_v1);
66508601 149 for (i = 0; i < nb_prom_envs; i++)
d2c63fc1
BS
150 end = OpenBIOS_set_var(image, end, prom_envs[i]);
151
152 // End marker
153 image[end++] = '\0';
66508601 154
66508601 155 end = start + ((end - start + 15) & ~15);
d2c63fc1 156 OpenBIOS_finish_partition(part_header, end - start);
66508601
BS
157
158 // free partition
159 start = end;
d2c63fc1
BS
160 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
161 part_header->signature = OPENBIOS_PART_FREE;
363a37d5 162 pstrcpy(part_header->name, sizeof(part_header->name), "free");
66508601
BS
163
164 end = 0x1fd0;
d2c63fc1
BS
165 OpenBIOS_finish_partition(part_header, end - start);
166
905fdcb5
BS
167 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
168 nvram_machine_id);
d2c63fc1
BS
169
170 for (i = 0; i < sizeof(image); i++)
171 m48t59_write(nvram, i, image[i]);
e80cfcfc
FB
172}
173
d453c2c3 174static DeviceState *slavio_intctl;
e80cfcfc 175
84f2d0ea 176void sun4m_pic_info(Monitor *mon, const QDict *qdict)
e80cfcfc 177{
7d85892b 178 if (slavio_intctl)
376253ec 179 slavio_pic_info(mon, slavio_intctl);
e80cfcfc
FB
180}
181
84f2d0ea 182void sun4m_irq_info(Monitor *mon, const QDict *qdict)
e80cfcfc 183{
7d85892b 184 if (slavio_intctl)
376253ec 185 slavio_irq_info(mon, slavio_intctl);
e80cfcfc
FB
186}
187
98cec4a2 188void cpu_check_irqs(CPUSPARCState *env)
327ac2e7 189{
d8ed887b
AF
190 CPUState *cs;
191
327ac2e7
BS
192 if (env->pil_in && (env->interrupt_index == 0 ||
193 (env->interrupt_index & ~15) == TT_EXTINT)) {
194 unsigned int i;
195
196 for (i = 15; i > 0; i--) {
197 if (env->pil_in & (1 << i)) {
198 int old_interrupt = env->interrupt_index;
199
200 env->interrupt_index = TT_EXTINT | i;
f32d7ec5 201 if (old_interrupt != env->interrupt_index) {
c3affe56 202 cs = CPU(sparc_env_get_cpu(env));
97bf4851 203 trace_sun4m_cpu_interrupt(i);
c3affe56 204 cpu_interrupt(cs, CPU_INTERRUPT_HARD);
f32d7ec5 205 }
327ac2e7
BS
206 break;
207 }
208 }
209 } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
d8ed887b 210 cs = CPU(sparc_env_get_cpu(env));
97bf4851 211 trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15);
327ac2e7 212 env->interrupt_index = 0;
d8ed887b 213 cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
327ac2e7
BS
214 }
215}
216
38c66cf2 217static void cpu_kick_irq(SPARCCPU *cpu)
94ad5b00 218{
38c66cf2 219 CPUSPARCState *env = &cpu->env;
259186a7 220 CPUState *cs = CPU(cpu);
38c66cf2 221
259186a7 222 cs->halted = 0;
94ad5b00 223 cpu_check_irqs(env);
259186a7 224 qemu_cpu_kick(cs);
94ad5b00
PB
225}
226
b3a23197
BS
227static void cpu_set_irq(void *opaque, int irq, int level)
228{
e0bbf9b5
AF
229 SPARCCPU *cpu = opaque;
230 CPUSPARCState *env = &cpu->env;
b3a23197
BS
231
232 if (level) {
97bf4851 233 trace_sun4m_cpu_set_irq_raise(irq);
327ac2e7 234 env->pil_in |= 1 << irq;
38c66cf2 235 cpu_kick_irq(cpu);
b3a23197 236 } else {
97bf4851 237 trace_sun4m_cpu_set_irq_lower(irq);
327ac2e7
BS
238 env->pil_in &= ~(1 << irq);
239 cpu_check_irqs(env);
b3a23197
BS
240 }
241}
242
243static void dummy_cpu_set_irq(void *opaque, int irq, int level)
244{
245}
246
c68ea704
FB
247static void main_cpu_reset(void *opaque)
248{
5414dec6 249 SPARCCPU *cpu = opaque;
259186a7 250 CPUState *cs = CPU(cpu);
3d29fbef 251
259186a7
AF
252 cpu_reset(cs);
253 cs->halted = 0;
3d29fbef
BS
254}
255
256static void secondary_cpu_reset(void *opaque)
257{
5414dec6 258 SPARCCPU *cpu = opaque;
259186a7 259 CPUState *cs = CPU(cpu);
3d29fbef 260
259186a7
AF
261 cpu_reset(cs);
262 cs->halted = 1;
c68ea704
FB
263}
264
6d0c293d
BS
265static void cpu_halt_signal(void *opaque, int irq, int level)
266{
4917cf44
AF
267 if (level && current_cpu) {
268 cpu_interrupt(current_cpu, CPU_INTERRUPT_HALT);
c3affe56 269 }
6d0c293d
BS
270}
271
409dbce5
AJ
272static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
273{
274 return addr - 0xf0000000ULL;
275}
276
3ebf5aaf 277static unsigned long sun4m_load_kernel(const char *kernel_filename,
293f78bc 278 const char *initrd_filename,
c227f099 279 ram_addr_t RAM_size)
3ebf5aaf
BS
280{
281 int linux_boot;
282 unsigned int i;
283 long initrd_size, kernel_size;
3c178e72 284 uint8_t *ptr;
3ebf5aaf
BS
285
286 linux_boot = (kernel_filename != NULL);
287
288 kernel_size = 0;
289 if (linux_boot) {
ca20cf32
BS
290 int bswap_needed;
291
292#ifdef BSWAP_NEEDED
293 bswap_needed = 1;
294#else
295 bswap_needed = 0;
296#endif
409dbce5
AJ
297 kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL,
298 NULL, NULL, NULL, 1, ELF_MACHINE, 0);
3ebf5aaf 299 if (kernel_size < 0)
293f78bc 300 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
ca20cf32
BS
301 RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
302 TARGET_PAGE_SIZE);
3ebf5aaf 303 if (kernel_size < 0)
293f78bc
BS
304 kernel_size = load_image_targphys(kernel_filename,
305 KERNEL_LOAD_ADDR,
306 RAM_size - KERNEL_LOAD_ADDR);
3ebf5aaf
BS
307 if (kernel_size < 0) {
308 fprintf(stderr, "qemu: could not load kernel '%s'\n",
309 kernel_filename);
310 exit(1);
311 }
312
313 /* load initrd */
314 initrd_size = 0;
315 if (initrd_filename) {
293f78bc
BS
316 initrd_size = load_image_targphys(initrd_filename,
317 INITRD_LOAD_ADDR,
318 RAM_size - INITRD_LOAD_ADDR);
3ebf5aaf
BS
319 if (initrd_size < 0) {
320 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
321 initrd_filename);
322 exit(1);
323 }
324 }
325 if (initrd_size > 0) {
326 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
3c178e72
GH
327 ptr = rom_ptr(KERNEL_LOAD_ADDR + i);
328 if (ldl_p(ptr) == 0x48647253) { // HdrS
329 stl_p(ptr + 16, INITRD_LOAD_ADDR);
330 stl_p(ptr + 20, initrd_size);
3ebf5aaf
BS
331 break;
332 }
333 }
334 }
335 }
336 return kernel_size;
337}
338
a8170e5e 339static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
4b48bf05
BS
340{
341 DeviceState *dev;
342 SysBusDevice *s;
343
344 dev = qdev_create(NULL, "iommu");
345 qdev_prop_set_uint32(dev, "version", version);
e23a1b33 346 qdev_init_nofail(dev);
1356b98d 347 s = SYS_BUS_DEVICE(dev);
4b48bf05
BS
348 sysbus_connect_irq(s, 0, irq);
349 sysbus_mmio_map(s, 0, addr);
350
351 return s;
352}
353
a8170e5e 354static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
86d1c388 355 void *iommu, qemu_irq *dev_irq, int is_ledma)
74ff8d90
BS
356{
357 DeviceState *dev;
358 SysBusDevice *s;
359
360 dev = qdev_create(NULL, "sparc32_dma");
361 qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
86d1c388 362 qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
e23a1b33 363 qdev_init_nofail(dev);
1356b98d 364 s = SYS_BUS_DEVICE(dev);
74ff8d90
BS
365 sysbus_connect_irq(s, 0, parent_irq);
366 *dev_irq = qdev_get_gpio_in(dev, 0);
367 sysbus_mmio_map(s, 0, daddr);
368
369 return s;
370}
371
a8170e5e 372static void lance_init(NICInfo *nd, hwaddr leaddr,
74ff8d90 373 void *dma_opaque, qemu_irq irq)
9d07d757
PB
374{
375 DeviceState *dev;
376 SysBusDevice *s;
74ff8d90 377 qemu_irq reset;
9d07d757
PB
378
379 qemu_check_nic_model(&nd_table[0], "lance");
380
381 dev = qdev_create(NULL, "lance");
76224833 382 qdev_set_nic_properties(dev, nd);
daa65491 383 qdev_prop_set_ptr(dev, "dma", dma_opaque);
e23a1b33 384 qdev_init_nofail(dev);
1356b98d 385 s = SYS_BUS_DEVICE(dev);
9d07d757
PB
386 sysbus_mmio_map(s, 0, leaddr);
387 sysbus_connect_irq(s, 0, irq);
74ff8d90
BS
388 reset = qdev_get_gpio_in(dev, 0);
389 qdev_connect_gpio_out(dma_opaque, 0, reset);
9d07d757
PB
390}
391
a8170e5e
AK
392static DeviceState *slavio_intctl_init(hwaddr addr,
393 hwaddr addrg,
462eda24 394 qemu_irq **parent_irq)
4b48bf05
BS
395{
396 DeviceState *dev;
397 SysBusDevice *s;
398 unsigned int i, j;
399
400 dev = qdev_create(NULL, "slavio_intctl");
e23a1b33 401 qdev_init_nofail(dev);
4b48bf05 402
1356b98d 403 s = SYS_BUS_DEVICE(dev);
4b48bf05
BS
404
405 for (i = 0; i < MAX_CPUS; i++) {
406 for (j = 0; j < MAX_PILS; j++) {
407 sysbus_connect_irq(s, i * MAX_PILS + j, parent_irq[i][j]);
408 }
409 }
410 sysbus_mmio_map(s, 0, addrg);
411 for (i = 0; i < MAX_CPUS; i++) {
412 sysbus_mmio_map(s, i + 1, addr + i * TARGET_PAGE_SIZE);
413 }
414
415 return dev;
416}
417
418#define SYS_TIMER_OFFSET 0x10000ULL
419#define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
420
a8170e5e 421static void slavio_timer_init_all(hwaddr addr, qemu_irq master_irq,
4b48bf05
BS
422 qemu_irq *cpu_irqs, unsigned int num_cpus)
423{
424 DeviceState *dev;
425 SysBusDevice *s;
426 unsigned int i;
427
428 dev = qdev_create(NULL, "slavio_timer");
429 qdev_prop_set_uint32(dev, "num_cpus", num_cpus);
e23a1b33 430 qdev_init_nofail(dev);
1356b98d 431 s = SYS_BUS_DEVICE(dev);
4b48bf05
BS
432 sysbus_connect_irq(s, 0, master_irq);
433 sysbus_mmio_map(s, 0, addr + SYS_TIMER_OFFSET);
434
435 for (i = 0; i < MAX_CPUS; i++) {
a8170e5e 436 sysbus_mmio_map(s, i + 1, addr + (hwaddr)CPU_TIMER_OFFSET(i));
4b48bf05
BS
437 sysbus_connect_irq(s, i + 1, cpu_irqs[i]);
438 }
439}
440
bea42280
IM
441static qemu_irq slavio_system_powerdown;
442
443static void slavio_powerdown_req(Notifier *n, void *opaque)
444{
445 qemu_irq_raise(slavio_system_powerdown);
446}
447
448static Notifier slavio_system_powerdown_notifier = {
449 .notify = slavio_powerdown_req
450};
451
4b48bf05
BS
452#define MISC_LEDS 0x01600000
453#define MISC_CFG 0x01800000
454#define MISC_DIAG 0x01a00000
455#define MISC_MDM 0x01b00000
456#define MISC_SYS 0x01f00000
457
a8170e5e
AK
458static void slavio_misc_init(hwaddr base,
459 hwaddr aux1_base,
460 hwaddr aux2_base, qemu_irq irq,
b2b6f6ec 461 qemu_irq fdc_tc)
4b48bf05
BS
462{
463 DeviceState *dev;
464 SysBusDevice *s;
465
466 dev = qdev_create(NULL, "slavio_misc");
e23a1b33 467 qdev_init_nofail(dev);
1356b98d 468 s = SYS_BUS_DEVICE(dev);
4b48bf05
BS
469 if (base) {
470 /* 8 bit registers */
471 /* Slavio control */
472 sysbus_mmio_map(s, 0, base + MISC_CFG);
473 /* Diagnostics */
474 sysbus_mmio_map(s, 1, base + MISC_DIAG);
475 /* Modem control */
476 sysbus_mmio_map(s, 2, base + MISC_MDM);
477 /* 16 bit registers */
478 /* ss600mp diag LEDs */
479 sysbus_mmio_map(s, 3, base + MISC_LEDS);
480 /* 32 bit registers */
481 /* System control */
482 sysbus_mmio_map(s, 4, base + MISC_SYS);
483 }
484 if (aux1_base) {
485 /* AUX 1 (Misc System Functions) */
486 sysbus_mmio_map(s, 5, aux1_base);
487 }
488 if (aux2_base) {
489 /* AUX 2 (Software Powerdown Control) */
490 sysbus_mmio_map(s, 6, aux2_base);
491 }
492 sysbus_connect_irq(s, 0, irq);
493 sysbus_connect_irq(s, 1, fdc_tc);
bea42280
IM
494 slavio_system_powerdown = qdev_get_gpio_in(dev, 0);
495 qemu_register_powerdown_notifier(&slavio_system_powerdown_notifier);
4b48bf05
BS
496}
497
a8170e5e 498static void ecc_init(hwaddr base, qemu_irq irq, uint32_t version)
4b48bf05
BS
499{
500 DeviceState *dev;
501 SysBusDevice *s;
502
503 dev = qdev_create(NULL, "eccmemctl");
504 qdev_prop_set_uint32(dev, "version", version);
e23a1b33 505 qdev_init_nofail(dev);
1356b98d 506 s = SYS_BUS_DEVICE(dev);
4b48bf05
BS
507 sysbus_connect_irq(s, 0, irq);
508 sysbus_mmio_map(s, 0, base);
509 if (version == 0) { // SS-600MP only
510 sysbus_mmio_map(s, 1, base + 0x1000);
511 }
512}
513
a8170e5e 514static void apc_init(hwaddr power_base, qemu_irq cpu_halt)
4b48bf05
BS
515{
516 DeviceState *dev;
517 SysBusDevice *s;
518
519 dev = qdev_create(NULL, "apc");
e23a1b33 520 qdev_init_nofail(dev);
1356b98d 521 s = SYS_BUS_DEVICE(dev);
4b48bf05
BS
522 /* Power management (APC) XXX: not a Slavio device */
523 sysbus_mmio_map(s, 0, power_base);
524 sysbus_connect_irq(s, 0, cpu_halt);
525}
526
a8170e5e 527static void tcx_init(hwaddr addr, int vram_size, int width,
4b48bf05
BS
528 int height, int depth)
529{
530 DeviceState *dev;
531 SysBusDevice *s;
532
533 dev = qdev_create(NULL, "SUNW,tcx");
4b48bf05
BS
534 qdev_prop_set_uint32(dev, "vram_size", vram_size);
535 qdev_prop_set_uint16(dev, "width", width);
536 qdev_prop_set_uint16(dev, "height", height);
537 qdev_prop_set_uint16(dev, "depth", depth);
e23a1b33 538 qdev_init_nofail(dev);
1356b98d 539 s = SYS_BUS_DEVICE(dev);
4b48bf05
BS
540 /* 8-bit plane */
541 sysbus_mmio_map(s, 0, addr + 0x00800000ULL);
542 /* DAC */
543 sysbus_mmio_map(s, 1, addr + 0x00200000ULL);
544 /* TEC (dummy) */
545 sysbus_mmio_map(s, 2, addr + 0x00700000ULL);
546 /* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */
547 sysbus_mmio_map(s, 3, addr + 0x00301000ULL);
548 if (depth == 24) {
549 /* 24-bit plane */
550 sysbus_mmio_map(s, 4, addr + 0x02000000ULL);
551 /* Control plane */
552 sysbus_mmio_map(s, 5, addr + 0x0a000000ULL);
553 } else {
554 /* THC 8 bit (dummy) */
555 sysbus_mmio_map(s, 4, addr + 0x00300000ULL);
556 }
557}
558
325f2747
BS
559/* NCR89C100/MACIO Internal ID register */
560static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
561
a8170e5e 562static void idreg_init(hwaddr addr)
325f2747
BS
563{
564 DeviceState *dev;
565 SysBusDevice *s;
566
567 dev = qdev_create(NULL, "macio_idreg");
e23a1b33 568 qdev_init_nofail(dev);
1356b98d 569 s = SYS_BUS_DEVICE(dev);
325f2747
BS
570
571 sysbus_mmio_map(s, 0, addr);
572 cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data));
573}
574
3150fa50
AK
575typedef struct IDRegState {
576 SysBusDevice busdev;
577 MemoryRegion mem;
578} IDRegState;
579
81a322d4 580static int idreg_init1(SysBusDevice *dev)
325f2747 581{
3150fa50 582 IDRegState *s = FROM_SYSBUS(IDRegState, dev);
325f2747 583
29776739
PB
584 memory_region_init_ram(&s->mem, OBJECT(s),
585 "sun4m.idreg", sizeof(idreg_data));
c5705a77 586 vmstate_register_ram_global(&s->mem);
3150fa50 587 memory_region_set_readonly(&s->mem, true);
750ecd44 588 sysbus_init_mmio(dev, &s->mem);
81a322d4 589 return 0;
325f2747
BS
590}
591
999e12bb
AL
592static void idreg_class_init(ObjectClass *klass, void *data)
593{
594 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
595
596 k->init = idreg_init1;
597}
598
8c43a6f0 599static const TypeInfo idreg_info = {
39bffca2
AL
600 .name = "macio_idreg",
601 .parent = TYPE_SYS_BUS_DEVICE,
602 .instance_size = sizeof(IDRegState),
603 .class_init = idreg_class_init,
325f2747
BS
604};
605
3150fa50
AK
606typedef struct AFXState {
607 SysBusDevice busdev;
608 MemoryRegion mem;
609} AFXState;
610
c5de386a 611/* SS-5 TCX AFX register */
a8170e5e 612static void afx_init(hwaddr addr)
c5de386a
AT
613{
614 DeviceState *dev;
615 SysBusDevice *s;
616
617 dev = qdev_create(NULL, "tcx_afx");
618 qdev_init_nofail(dev);
1356b98d 619 s = SYS_BUS_DEVICE(dev);
c5de386a
AT
620
621 sysbus_mmio_map(s, 0, addr);
622}
623
624static int afx_init1(SysBusDevice *dev)
625{
3150fa50 626 AFXState *s = FROM_SYSBUS(AFXState, dev);
c5de386a 627
29776739 628 memory_region_init_ram(&s->mem, OBJECT(s), "sun4m.afx", 4);
c5705a77 629 vmstate_register_ram_global(&s->mem);
750ecd44 630 sysbus_init_mmio(dev, &s->mem);
c5de386a
AT
631 return 0;
632}
633
999e12bb
AL
634static void afx_class_init(ObjectClass *klass, void *data)
635{
636 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
637
638 k->init = afx_init1;
639}
640
8c43a6f0 641static const TypeInfo afx_info = {
39bffca2
AL
642 .name = "tcx_afx",
643 .parent = TYPE_SYS_BUS_DEVICE,
644 .instance_size = sizeof(AFXState),
645 .class_init = afx_class_init,
c5de386a
AT
646};
647
3150fa50
AK
648typedef struct PROMState {
649 SysBusDevice busdev;
650 MemoryRegion prom;
651} PROMState;
652
f48f6569 653/* Boot PROM (OpenBIOS) */
409dbce5
AJ
654static uint64_t translate_prom_address(void *opaque, uint64_t addr)
655{
a8170e5e 656 hwaddr *base_addr = (hwaddr *)opaque;
409dbce5
AJ
657 return addr + *base_addr - PROM_VADDR;
658}
659
a8170e5e 660static void prom_init(hwaddr addr, const char *bios_name)
f48f6569
BS
661{
662 DeviceState *dev;
663 SysBusDevice *s;
664 char *filename;
665 int ret;
666
667 dev = qdev_create(NULL, "openprom");
e23a1b33 668 qdev_init_nofail(dev);
1356b98d 669 s = SYS_BUS_DEVICE(dev);
f48f6569
BS
670
671 sysbus_mmio_map(s, 0, addr);
672
673 /* load boot prom */
674 if (bios_name == NULL) {
675 bios_name = PROM_FILENAME;
676 }
677 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
678 if (filename) {
409dbce5
AJ
679 ret = load_elf(filename, translate_prom_address, &addr, NULL,
680 NULL, NULL, 1, ELF_MACHINE, 0);
f48f6569
BS
681 if (ret < 0 || ret > PROM_SIZE_MAX) {
682 ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
683 }
7267c094 684 g_free(filename);
f48f6569
BS
685 } else {
686 ret = -1;
687 }
688 if (ret < 0 || ret > PROM_SIZE_MAX) {
689 fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
690 exit(1);
691 }
692}
693
81a322d4 694static int prom_init1(SysBusDevice *dev)
f48f6569 695{
3150fa50 696 PROMState *s = FROM_SYSBUS(PROMState, dev);
f48f6569 697
29776739 698 memory_region_init_ram(&s->prom, OBJECT(s), "sun4m.prom", PROM_SIZE_MAX);
c5705a77 699 vmstate_register_ram_global(&s->prom);
3150fa50 700 memory_region_set_readonly(&s->prom, true);
750ecd44 701 sysbus_init_mmio(dev, &s->prom);
81a322d4 702 return 0;
f48f6569
BS
703}
704
999e12bb
AL
705static Property prom_properties[] = {
706 {/* end of property list */},
707};
708
709static void prom_class_init(ObjectClass *klass, void *data)
710{
39bffca2 711 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb
AL
712 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
713
714 k->init = prom_init1;
39bffca2 715 dc->props = prom_properties;
999e12bb
AL
716}
717
8c43a6f0 718static const TypeInfo prom_info = {
39bffca2
AL
719 .name = "openprom",
720 .parent = TYPE_SYS_BUS_DEVICE,
721 .instance_size = sizeof(PROMState),
722 .class_init = prom_class_init,
f48f6569
BS
723};
724
ee6847d1
GH
725typedef struct RamDevice
726{
727 SysBusDevice busdev;
3150fa50 728 MemoryRegion ram;
04843626 729 uint64_t size;
ee6847d1
GH
730} RamDevice;
731
a350db85 732/* System RAM */
81a322d4 733static int ram_init1(SysBusDevice *dev)
a350db85 734{
ee6847d1 735 RamDevice *d = FROM_SYSBUS(RamDevice, dev);
a350db85 736
29776739 737 memory_region_init_ram(&d->ram, OBJECT(d), "sun4m.ram", d->size);
c5705a77 738 vmstate_register_ram_global(&d->ram);
750ecd44 739 sysbus_init_mmio(dev, &d->ram);
81a322d4 740 return 0;
a350db85
BS
741}
742
a8170e5e 743static void ram_init(hwaddr addr, ram_addr_t RAM_size,
a350db85
BS
744 uint64_t max_mem)
745{
746 DeviceState *dev;
747 SysBusDevice *s;
ee6847d1 748 RamDevice *d;
a350db85
BS
749
750 /* allocate RAM */
751 if ((uint64_t)RAM_size > max_mem) {
752 fprintf(stderr,
753 "qemu: Too much memory for this machine: %d, maximum %d\n",
754 (unsigned int)(RAM_size / (1024 * 1024)),
755 (unsigned int)(max_mem / (1024 * 1024)));
756 exit(1);
757 }
758 dev = qdev_create(NULL, "memory");
1356b98d 759 s = SYS_BUS_DEVICE(dev);
a350db85 760
ee6847d1
GH
761 d = FROM_SYSBUS(RamDevice, s);
762 d->size = RAM_size;
e23a1b33 763 qdev_init_nofail(dev);
ee6847d1 764
a350db85
BS
765 sysbus_mmio_map(s, 0, addr);
766}
767
999e12bb
AL
768static Property ram_properties[] = {
769 DEFINE_PROP_UINT64("size", RamDevice, size, 0),
770 DEFINE_PROP_END_OF_LIST(),
771};
772
773static void ram_class_init(ObjectClass *klass, void *data)
774{
39bffca2 775 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb
AL
776 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
777
778 k->init = ram_init1;
39bffca2 779 dc->props = ram_properties;
999e12bb
AL
780}
781
8c43a6f0 782static const TypeInfo ram_info = {
39bffca2
AL
783 .name = "memory",
784 .parent = TYPE_SYS_BUS_DEVICE,
785 .instance_size = sizeof(RamDevice),
786 .class_init = ram_class_init,
a350db85
BS
787};
788
89835363
BS
789static void cpu_devinit(const char *cpu_model, unsigned int id,
790 uint64_t prom_addr, qemu_irq **cpu_irqs)
666713c0 791{
259186a7 792 CPUState *cs;
8968f588 793 SPARCCPU *cpu;
98cec4a2 794 CPUSPARCState *env;
666713c0 795
8968f588
AF
796 cpu = cpu_sparc_init(cpu_model);
797 if (cpu == NULL) {
666713c0
BS
798 fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
799 exit(1);
800 }
8968f588 801 env = &cpu->env;
666713c0
BS
802
803 cpu_sparc_set_id(env, id);
804 if (id == 0) {
5414dec6 805 qemu_register_reset(main_cpu_reset, cpu);
666713c0 806 } else {
5414dec6 807 qemu_register_reset(secondary_cpu_reset, cpu);
259186a7
AF
808 cs = CPU(cpu);
809 cs->halted = 1;
666713c0 810 }
e0bbf9b5 811 *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS);
666713c0 812 env->prom_addr = prom_addr;
666713c0
BS
813}
814
acfbe712
BS
815static void dummy_fdc_tc(void *opaque, int irq, int level)
816{
817}
818
c227f099 819static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
3ebf5aaf 820 const char *boot_device,
3023f332 821 const char *kernel_filename,
3ebf5aaf
BS
822 const char *kernel_cmdline,
823 const char *initrd_filename, const char *cpu_model)
420557e8 824{
713c45fa 825 unsigned int i;
cfb9de9c 826 void *iommu, *espdma, *ledma, *nvram;
a1961a4b 827 qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
6f6260c7 828 espdma_irq, ledma_irq;
73d74342 829 qemu_irq esp_reset, dma_enable;
2582cfa0 830 qemu_irq fdc_tc;
6d0c293d 831 qemu_irq *cpu_halt;
5c6602c5 832 unsigned long kernel_size;
fd8014e1 833 DriveInfo *fd[MAX_FD];
a88b362c 834 FWCfgState *fw_cfg;
9a62fb24 835 unsigned int num_vsimms;
420557e8 836
ba3c64fb 837 /* init CPUs */
3ebf5aaf
BS
838 if (!cpu_model)
839 cpu_model = hwdef->default_cpu_model;
b3a23197 840
ba3c64fb 841 for(i = 0; i < smp_cpus; i++) {
89835363 842 cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
ba3c64fb 843 }
b3a23197
BS
844
845 for (i = smp_cpus; i < MAX_CPUS; i++)
846 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
847
3ebf5aaf 848
3ebf5aaf 849 /* set up devices */
a350db85 850 ram_init(0, RAM_size, hwdef->max_mem);
676d9b9b
AT
851 /* models without ECC don't trap when missing ram is accessed */
852 if (!hwdef->ecc_base) {
853 empty_slot_init(RAM_size, hwdef->max_mem - RAM_size);
854 }
a350db85 855
f48f6569
BS
856 prom_init(hwdef->slavio_base, bios_name);
857
d453c2c3
BS
858 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
859 hwdef->intctl_base + 0x10000ULL,
462eda24 860 cpu_irqs);
a1961a4b
BS
861
862 for (i = 0; i < 32; i++) {
d453c2c3 863 slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
a1961a4b
BS
864 }
865 for (i = 0; i < MAX_CPUS; i++) {
d453c2c3 866 slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
a1961a4b 867 }
b3a23197 868
fe096129 869 if (hwdef->idreg_base) {
325f2747 870 idreg_init(hwdef->idreg_base);
4c2485de
BS
871 }
872
c5de386a
AT
873 if (hwdef->afx_base) {
874 afx_init(hwdef->afx_base);
875 }
876
ff403da6 877 iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
c533e0b3 878 slavio_irq[30]);
ff403da6 879
3386376c
AT
880 if (hwdef->iommu_pad_base) {
881 /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
882 Software shouldn't use aliased addresses, neither should it crash
883 when does. Using empty_slot instead of aliasing can help with
884 debugging such accesses */
885 empty_slot_init(hwdef->iommu_pad_base,hwdef->iommu_pad_len);
886 }
887
c533e0b3 888 espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[18],
86d1c388 889 iommu, &espdma_irq, 0);
2d069bab 890
5aca8c3b 891 ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
86d1c388 892 slavio_irq[16], iommu, &ledma_irq, 1);
ba3c64fb 893
eee0b836
BS
894 if (graphic_depth != 8 && graphic_depth != 24) {
895 fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
896 exit (1);
897 }
9a62fb24
BB
898 num_vsimms = 0;
899 if (num_vsimms == 0) {
900 tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
901 graphic_depth);
902 }
903
904 for (i = num_vsimms; i < MAX_VSIMMS; i++) {
905 /* vsimm registers probed by OBP */
906 if (hwdef->vsimm[i].reg_base) {
907 empty_slot_init(hwdef->vsimm[i].reg_base, 0x2000);
908 }
909 }
910
911 if (hwdef->sx_base) {
912 empty_slot_init(hwdef->sx_base, 0x2000);
913 }
dbe06e18 914
74ff8d90 915 lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
dbe06e18 916
d95d8f1c 917 nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
81732d19 918
c533e0b3 919 slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
81732d19 920
c533e0b3 921 slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[14],
993fbfdb 922 display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
5cbdb3a3
SW
923 /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
924 Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
c533e0b3 925 escc_init(hwdef->serial_base, slavio_irq[15], slavio_irq[15],
aeeb69c7 926 serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
741402f9 927
6d0c293d 928 cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
2582cfa0
BS
929 if (hwdef->apc_base) {
930 apc_init(hwdef->apc_base, cpu_halt[0]);
931 }
2be17ebd 932
fe096129 933 if (hwdef->fd_base) {
e4bcb14c 934 /* there is zero or one floppy drive */
309e60bd 935 memset(fd, 0, sizeof(fd));
fd8014e1 936 fd[0] = drive_get(IF_FLOPPY, 0, 0);
c533e0b3 937 sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
2582cfa0 938 &fdc_tc);
acfbe712
BS
939 } else {
940 fdc_tc = *qemu_allocate_irqs(dummy_fdc_tc, NULL, 1);
e4bcb14c
TS
941 }
942
acfbe712
BS
943 slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
944 slavio_irq[30], fdc_tc);
945
e4bcb14c
TS
946 if (drive_get_max_bus(IF_SCSI) > 0) {
947 fprintf(stderr, "qemu: too many SCSI bus\n");
948 exit(1);
949 }
950
cfb9de9c
PB
951 esp_init(hwdef->esp_base, 2,
952 espdma_memory_read, espdma_memory_write,
73d74342 953 espdma, espdma_irq, &esp_reset, &dma_enable);
74ff8d90 954
73d74342
BS
955 qdev_connect_gpio_out(espdma, 0, esp_reset);
956 qdev_connect_gpio_out(espdma, 1, dma_enable);
f1587550 957
fa28ec52
BS
958 if (hwdef->cs_base) {
959 sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
c533e0b3 960 slavio_irq[5]);
fa28ec52 961 }
b3ceef24 962
9a62fb24
BB
963 if (hwdef->dbri_base) {
964 /* ISDN chip with attached CS4215 audio codec */
965 /* prom space */
966 empty_slot_init(hwdef->dbri_base+0x1000, 0x30);
967 /* reg space */
968 empty_slot_init(hwdef->dbri_base+0x10000, 0x100);
969 }
970
971 if (hwdef->bpp_base) {
972 /* parallel port */
973 empty_slot_init(hwdef->bpp_base, 0x20);
974 }
975
293f78bc
BS
976 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
977 RAM_size);
36cd9210 978
36cd9210 979 nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
b3ceef24 980 boot_device, RAM_size, kernel_size, graphic_width,
905fdcb5
BS
981 graphic_height, graphic_depth, hwdef->nvram_machine_id,
982 "Sun4m");
7eb0c8e8 983
fe096129 984 if (hwdef->ecc_base)
c533e0b3 985 ecc_init(hwdef->ecc_base, slavio_irq[28],
e42c20b4 986 hwdef->ecc_version);
3cce6243
BS
987
988 fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
70db9222 989 fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
3cce6243 990 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
991 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
992 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
fbfcf955 993 fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
513f789f
BS
994 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
995 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
996 if (kernel_cmdline) {
997 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
3c178e72 998 pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
0e0d2d62 999 fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
748a4ee3
BS
1000 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
1001 strlen(kernel_cmdline) + 1);
513f789f
BS
1002 } else {
1003 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
748a4ee3 1004 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
513f789f
BS
1005 }
1006 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1007 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
1008 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
1009 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
36cd9210
BS
1010}
1011
905fdcb5 1012enum {
905fdcb5
BS
1013 ss5_id = 32,
1014 vger_id,
1015 lx_id,
1016 ss4_id,
1017 scls_id,
1018 sbook_id,
1019 ss10_id = 64,
1020 ss20_id,
1021 ss600mp_id,
905fdcb5
BS
1022};
1023
8137cde8 1024static const struct sun4m_hwdef sun4m_hwdefs[] = {
36cd9210
BS
1025 /* SS-5 */
1026 {
1027 .iommu_base = 0x10000000,
3386376c
AT
1028 .iommu_pad_base = 0x10004000,
1029 .iommu_pad_len = 0x0fffb000,
36cd9210
BS
1030 .tcx_base = 0x50000000,
1031 .cs_base = 0x6c000000,
384ccb5d 1032 .slavio_base = 0x70000000,
36cd9210
BS
1033 .ms_kb_base = 0x71000000,
1034 .serial_base = 0x71100000,
1035 .nvram_base = 0x71200000,
1036 .fd_base = 0x71400000,
1037 .counter_base = 0x71d00000,
1038 .intctl_base = 0x71e00000,
4c2485de 1039 .idreg_base = 0x78000000,
36cd9210
BS
1040 .dma_base = 0x78400000,
1041 .esp_base = 0x78800000,
1042 .le_base = 0x78c00000,
127fc407 1043 .apc_base = 0x6a000000,
c5de386a 1044 .afx_base = 0x6e000000,
0019ad53
BS
1045 .aux1_base = 0x71900000,
1046 .aux2_base = 0x71910000,
905fdcb5
BS
1047 .nvram_machine_id = 0x80,
1048 .machine_id = ss5_id,
cf3102ac 1049 .iommu_version = 0x05000000,
3ebf5aaf
BS
1050 .max_mem = 0x10000000,
1051 .default_cpu_model = "Fujitsu MB86904",
e0353fe2
BS
1052 },
1053 /* SS-10 */
e0353fe2 1054 {
5dcb6b91
BS
1055 .iommu_base = 0xfe0000000ULL,
1056 .tcx_base = 0xe20000000ULL,
5dcb6b91
BS
1057 .slavio_base = 0xff0000000ULL,
1058 .ms_kb_base = 0xff1000000ULL,
1059 .serial_base = 0xff1100000ULL,
1060 .nvram_base = 0xff1200000ULL,
1061 .fd_base = 0xff1700000ULL,
1062 .counter_base = 0xff1300000ULL,
1063 .intctl_base = 0xff1400000ULL,
4c2485de 1064 .idreg_base = 0xef0000000ULL,
5dcb6b91
BS
1065 .dma_base = 0xef0400000ULL,
1066 .esp_base = 0xef0800000ULL,
1067 .le_base = 0xef0c00000ULL,
0019ad53 1068 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
1069 .aux1_base = 0xff1800000ULL,
1070 .aux2_base = 0xff1a01000ULL,
7eb0c8e8
BS
1071 .ecc_base = 0xf00000000ULL,
1072 .ecc_version = 0x10000000, // version 0, implementation 1
905fdcb5
BS
1073 .nvram_machine_id = 0x72,
1074 .machine_id = ss10_id,
7fbfb139 1075 .iommu_version = 0x03000000,
6ef05b95 1076 .max_mem = 0xf00000000ULL,
3ebf5aaf 1077 .default_cpu_model = "TI SuperSparc II",
36cd9210 1078 },
6a3b9cc9
BS
1079 /* SS-600MP */
1080 {
1081 .iommu_base = 0xfe0000000ULL,
1082 .tcx_base = 0xe20000000ULL,
6a3b9cc9
BS
1083 .slavio_base = 0xff0000000ULL,
1084 .ms_kb_base = 0xff1000000ULL,
1085 .serial_base = 0xff1100000ULL,
1086 .nvram_base = 0xff1200000ULL,
6a3b9cc9
BS
1087 .counter_base = 0xff1300000ULL,
1088 .intctl_base = 0xff1400000ULL,
1089 .dma_base = 0xef0081000ULL,
1090 .esp_base = 0xef0080000ULL,
1091 .le_base = 0xef0060000ULL,
0019ad53 1092 .apc_base = 0xefa000000ULL, // XXX should not exist
127fc407
BS
1093 .aux1_base = 0xff1800000ULL,
1094 .aux2_base = 0xff1a01000ULL, // XXX should not exist
7eb0c8e8
BS
1095 .ecc_base = 0xf00000000ULL,
1096 .ecc_version = 0x00000000, // version 0, implementation 0
905fdcb5
BS
1097 .nvram_machine_id = 0x71,
1098 .machine_id = ss600mp_id,
7fbfb139 1099 .iommu_version = 0x01000000,
6ef05b95 1100 .max_mem = 0xf00000000ULL,
3ebf5aaf 1101 .default_cpu_model = "TI SuperSparc II",
6a3b9cc9 1102 },
ae40972f
BS
1103 /* SS-20 */
1104 {
1105 .iommu_base = 0xfe0000000ULL,
1106 .tcx_base = 0xe20000000ULL,
ae40972f
BS
1107 .slavio_base = 0xff0000000ULL,
1108 .ms_kb_base = 0xff1000000ULL,
1109 .serial_base = 0xff1100000ULL,
1110 .nvram_base = 0xff1200000ULL,
1111 .fd_base = 0xff1700000ULL,
1112 .counter_base = 0xff1300000ULL,
1113 .intctl_base = 0xff1400000ULL,
4c2485de 1114 .idreg_base = 0xef0000000ULL,
ae40972f
BS
1115 .dma_base = 0xef0400000ULL,
1116 .esp_base = 0xef0800000ULL,
1117 .le_base = 0xef0c00000ULL,
9a62fb24 1118 .bpp_base = 0xef4800000ULL,
0019ad53 1119 .apc_base = 0xefa000000ULL, // XXX should not exist
577d8dd4
BS
1120 .aux1_base = 0xff1800000ULL,
1121 .aux2_base = 0xff1a01000ULL,
9a62fb24
BB
1122 .dbri_base = 0xee0000000ULL,
1123 .sx_base = 0xf80000000ULL,
1124 .vsimm = {
1125 {
1126 .reg_base = 0x9c000000ULL,
1127 .vram_base = 0xfc000000ULL
1128 }, {
1129 .reg_base = 0x90000000ULL,
1130 .vram_base = 0xf0000000ULL
1131 }, {
1132 .reg_base = 0x94000000ULL
1133 }, {
1134 .reg_base = 0x98000000ULL
1135 }
1136 },
ae40972f
BS
1137 .ecc_base = 0xf00000000ULL,
1138 .ecc_version = 0x20000000, // version 0, implementation 2
905fdcb5
BS
1139 .nvram_machine_id = 0x72,
1140 .machine_id = ss20_id,
ae40972f 1141 .iommu_version = 0x13000000,
6ef05b95 1142 .max_mem = 0xf00000000ULL,
ae40972f
BS
1143 .default_cpu_model = "TI SuperSparc II",
1144 },
a526a31c
BS
1145 /* Voyager */
1146 {
1147 .iommu_base = 0x10000000,
1148 .tcx_base = 0x50000000,
a526a31c
BS
1149 .slavio_base = 0x70000000,
1150 .ms_kb_base = 0x71000000,
1151 .serial_base = 0x71100000,
1152 .nvram_base = 0x71200000,
1153 .fd_base = 0x71400000,
1154 .counter_base = 0x71d00000,
1155 .intctl_base = 0x71e00000,
1156 .idreg_base = 0x78000000,
1157 .dma_base = 0x78400000,
1158 .esp_base = 0x78800000,
1159 .le_base = 0x78c00000,
1160 .apc_base = 0x71300000, // pmc
1161 .aux1_base = 0x71900000,
1162 .aux2_base = 0x71910000,
905fdcb5
BS
1163 .nvram_machine_id = 0x80,
1164 .machine_id = vger_id,
a526a31c 1165 .iommu_version = 0x05000000,
a526a31c
BS
1166 .max_mem = 0x10000000,
1167 .default_cpu_model = "Fujitsu MB86904",
1168 },
1169 /* LX */
1170 {
1171 .iommu_base = 0x10000000,
3386376c
AT
1172 .iommu_pad_base = 0x10004000,
1173 .iommu_pad_len = 0x0fffb000,
a526a31c 1174 .tcx_base = 0x50000000,
a526a31c
BS
1175 .slavio_base = 0x70000000,
1176 .ms_kb_base = 0x71000000,
1177 .serial_base = 0x71100000,
1178 .nvram_base = 0x71200000,
1179 .fd_base = 0x71400000,
1180 .counter_base = 0x71d00000,
1181 .intctl_base = 0x71e00000,
1182 .idreg_base = 0x78000000,
1183 .dma_base = 0x78400000,
1184 .esp_base = 0x78800000,
1185 .le_base = 0x78c00000,
a526a31c
BS
1186 .aux1_base = 0x71900000,
1187 .aux2_base = 0x71910000,
905fdcb5
BS
1188 .nvram_machine_id = 0x80,
1189 .machine_id = lx_id,
a526a31c 1190 .iommu_version = 0x04000000,
a526a31c
BS
1191 .max_mem = 0x10000000,
1192 .default_cpu_model = "TI MicroSparc I",
1193 },
1194 /* SS-4 */
1195 {
1196 .iommu_base = 0x10000000,
1197 .tcx_base = 0x50000000,
1198 .cs_base = 0x6c000000,
1199 .slavio_base = 0x70000000,
1200 .ms_kb_base = 0x71000000,
1201 .serial_base = 0x71100000,
1202 .nvram_base = 0x71200000,
1203 .fd_base = 0x71400000,
1204 .counter_base = 0x71d00000,
1205 .intctl_base = 0x71e00000,
1206 .idreg_base = 0x78000000,
1207 .dma_base = 0x78400000,
1208 .esp_base = 0x78800000,
1209 .le_base = 0x78c00000,
1210 .apc_base = 0x6a000000,
1211 .aux1_base = 0x71900000,
1212 .aux2_base = 0x71910000,
905fdcb5
BS
1213 .nvram_machine_id = 0x80,
1214 .machine_id = ss4_id,
a526a31c 1215 .iommu_version = 0x05000000,
a526a31c
BS
1216 .max_mem = 0x10000000,
1217 .default_cpu_model = "Fujitsu MB86904",
1218 },
1219 /* SPARCClassic */
1220 {
1221 .iommu_base = 0x10000000,
1222 .tcx_base = 0x50000000,
a526a31c
BS
1223 .slavio_base = 0x70000000,
1224 .ms_kb_base = 0x71000000,
1225 .serial_base = 0x71100000,
1226 .nvram_base = 0x71200000,
1227 .fd_base = 0x71400000,
1228 .counter_base = 0x71d00000,
1229 .intctl_base = 0x71e00000,
1230 .idreg_base = 0x78000000,
1231 .dma_base = 0x78400000,
1232 .esp_base = 0x78800000,
1233 .le_base = 0x78c00000,
1234 .apc_base = 0x6a000000,
1235 .aux1_base = 0x71900000,
1236 .aux2_base = 0x71910000,
905fdcb5
BS
1237 .nvram_machine_id = 0x80,
1238 .machine_id = scls_id,
a526a31c 1239 .iommu_version = 0x05000000,
a526a31c
BS
1240 .max_mem = 0x10000000,
1241 .default_cpu_model = "TI MicroSparc I",
1242 },
1243 /* SPARCbook */
1244 {
1245 .iommu_base = 0x10000000,
1246 .tcx_base = 0x50000000, // XXX
a526a31c
BS
1247 .slavio_base = 0x70000000,
1248 .ms_kb_base = 0x71000000,
1249 .serial_base = 0x71100000,
1250 .nvram_base = 0x71200000,
1251 .fd_base = 0x71400000,
1252 .counter_base = 0x71d00000,
1253 .intctl_base = 0x71e00000,
1254 .idreg_base = 0x78000000,
1255 .dma_base = 0x78400000,
1256 .esp_base = 0x78800000,
1257 .le_base = 0x78c00000,
1258 .apc_base = 0x6a000000,
1259 .aux1_base = 0x71900000,
1260 .aux2_base = 0x71910000,
905fdcb5
BS
1261 .nvram_machine_id = 0x80,
1262 .machine_id = sbook_id,
a526a31c 1263 .iommu_version = 0x05000000,
a526a31c
BS
1264 .max_mem = 0x10000000,
1265 .default_cpu_model = "TI MicroSparc I",
1266 },
36cd9210
BS
1267};
1268
36cd9210 1269/* SPARCstation 5 hardware initialisation */
5f072e1f 1270static void ss5_init(QEMUMachineInitArgs *args)
36cd9210 1271{
5f072e1f
EH
1272 ram_addr_t RAM_size = args->ram_size;
1273 const char *cpu_model = args->cpu_model;
1274 const char *kernel_filename = args->kernel_filename;
1275 const char *kernel_cmdline = args->kernel_cmdline;
1276 const char *initrd_filename = args->initrd_filename;
1277 const char *boot_device = args->boot_device;
3023f332 1278 sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1279 kernel_cmdline, initrd_filename, cpu_model);
420557e8 1280}
c0e564d5 1281
e0353fe2 1282/* SPARCstation 10 hardware initialisation */
5f072e1f 1283static void ss10_init(QEMUMachineInitArgs *args)
e0353fe2 1284{
5f072e1f
EH
1285 ram_addr_t RAM_size = args->ram_size;
1286 const char *cpu_model = args->cpu_model;
1287 const char *kernel_filename = args->kernel_filename;
1288 const char *kernel_cmdline = args->kernel_cmdline;
1289 const char *initrd_filename = args->initrd_filename;
1290 const char *boot_device = args->boot_device;
3023f332 1291 sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1292 kernel_cmdline, initrd_filename, cpu_model);
e0353fe2
BS
1293}
1294
6a3b9cc9 1295/* SPARCserver 600MP hardware initialisation */
5f072e1f 1296static void ss600mp_init(QEMUMachineInitArgs *args)
6a3b9cc9 1297{
5f072e1f
EH
1298 ram_addr_t RAM_size = args->ram_size;
1299 const char *cpu_model = args->cpu_model;
1300 const char *kernel_filename = args->kernel_filename;
1301 const char *kernel_cmdline = args->kernel_cmdline;
1302 const char *initrd_filename = args->initrd_filename;
1303 const char *boot_device = args->boot_device;
3023f332 1304 sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
3ebf5aaf 1305 kernel_cmdline, initrd_filename, cpu_model);
6a3b9cc9
BS
1306}
1307
ae40972f 1308/* SPARCstation 20 hardware initialisation */
5f072e1f 1309static void ss20_init(QEMUMachineInitArgs *args)
ae40972f 1310{
5f072e1f
EH
1311 ram_addr_t RAM_size = args->ram_size;
1312 const char *cpu_model = args->cpu_model;
1313 const char *kernel_filename = args->kernel_filename;
1314 const char *kernel_cmdline = args->kernel_cmdline;
1315 const char *initrd_filename = args->initrd_filename;
1316 const char *boot_device = args->boot_device;
3023f332 1317 sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
ee76f82e
BS
1318 kernel_cmdline, initrd_filename, cpu_model);
1319}
1320
a526a31c 1321/* SPARCstation Voyager hardware initialisation */
5f072e1f 1322static void vger_init(QEMUMachineInitArgs *args)
a526a31c 1323{
5f072e1f
EH
1324 ram_addr_t RAM_size = args->ram_size;
1325 const char *cpu_model = args->cpu_model;
1326 const char *kernel_filename = args->kernel_filename;
1327 const char *kernel_cmdline = args->kernel_cmdline;
1328 const char *initrd_filename = args->initrd_filename;
1329 const char *boot_device = args->boot_device;
3023f332 1330 sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1331 kernel_cmdline, initrd_filename, cpu_model);
1332}
1333
1334/* SPARCstation LX hardware initialisation */
5f072e1f 1335static void ss_lx_init(QEMUMachineInitArgs *args)
a526a31c 1336{
5f072e1f
EH
1337 ram_addr_t RAM_size = args->ram_size;
1338 const char *cpu_model = args->cpu_model;
1339 const char *kernel_filename = args->kernel_filename;
1340 const char *kernel_cmdline = args->kernel_cmdline;
1341 const char *initrd_filename = args->initrd_filename;
1342 const char *boot_device = args->boot_device;
3023f332 1343 sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1344 kernel_cmdline, initrd_filename, cpu_model);
1345}
1346
1347/* SPARCstation 4 hardware initialisation */
5f072e1f 1348static void ss4_init(QEMUMachineInitArgs *args)
a526a31c 1349{
5f072e1f
EH
1350 ram_addr_t RAM_size = args->ram_size;
1351 const char *cpu_model = args->cpu_model;
1352 const char *kernel_filename = args->kernel_filename;
1353 const char *kernel_cmdline = args->kernel_cmdline;
1354 const char *initrd_filename = args->initrd_filename;
1355 const char *boot_device = args->boot_device;
3023f332 1356 sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1357 kernel_cmdline, initrd_filename, cpu_model);
1358}
1359
1360/* SPARCClassic hardware initialisation */
5f072e1f 1361static void scls_init(QEMUMachineInitArgs *args)
a526a31c 1362{
5f072e1f
EH
1363 ram_addr_t RAM_size = args->ram_size;
1364 const char *cpu_model = args->cpu_model;
1365 const char *kernel_filename = args->kernel_filename;
1366 const char *kernel_cmdline = args->kernel_cmdline;
1367 const char *initrd_filename = args->initrd_filename;
1368 const char *boot_device = args->boot_device;
3023f332 1369 sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1370 kernel_cmdline, initrd_filename, cpu_model);
1371}
1372
1373/* SPARCbook hardware initialisation */
5f072e1f 1374static void sbook_init(QEMUMachineInitArgs *args)
a526a31c 1375{
5f072e1f
EH
1376 ram_addr_t RAM_size = args->ram_size;
1377 const char *cpu_model = args->cpu_model;
1378 const char *kernel_filename = args->kernel_filename;
1379 const char *kernel_cmdline = args->kernel_cmdline;
1380 const char *initrd_filename = args->initrd_filename;
1381 const char *boot_device = args->boot_device;
3023f332 1382 sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
a526a31c
BS
1383 kernel_cmdline, initrd_filename, cpu_model);
1384}
1385
f80f9ec9 1386static QEMUMachine ss5_machine = {
66de733b
BS
1387 .name = "SS-5",
1388 .desc = "Sun4m platform, SPARCstation 5",
1389 .init = ss5_init,
2d0d2837 1390 .block_default_type = IF_SCSI,
0c257437 1391 .is_default = 1,
e4ada29e 1392 DEFAULT_MACHINE_OPTIONS,
c0e564d5 1393};
e0353fe2 1394
f80f9ec9 1395static QEMUMachine ss10_machine = {
66de733b
BS
1396 .name = "SS-10",
1397 .desc = "Sun4m platform, SPARCstation 10",
1398 .init = ss10_init,
2d0d2837 1399 .block_default_type = IF_SCSI,
1bcee014 1400 .max_cpus = 4,
e4ada29e 1401 DEFAULT_MACHINE_OPTIONS,
e0353fe2 1402};
6a3b9cc9 1403
f80f9ec9 1404static QEMUMachine ss600mp_machine = {
66de733b
BS
1405 .name = "SS-600MP",
1406 .desc = "Sun4m platform, SPARCserver 600MP",
1407 .init = ss600mp_init,
2d0d2837 1408 .block_default_type = IF_SCSI,
1bcee014 1409 .max_cpus = 4,
e4ada29e 1410 DEFAULT_MACHINE_OPTIONS,
6a3b9cc9 1411};
ae40972f 1412
f80f9ec9 1413static QEMUMachine ss20_machine = {
66de733b
BS
1414 .name = "SS-20",
1415 .desc = "Sun4m platform, SPARCstation 20",
1416 .init = ss20_init,
2d0d2837 1417 .block_default_type = IF_SCSI,
1bcee014 1418 .max_cpus = 4,
e4ada29e 1419 DEFAULT_MACHINE_OPTIONS,
ae40972f
BS
1420};
1421
f80f9ec9 1422static QEMUMachine voyager_machine = {
66de733b
BS
1423 .name = "Voyager",
1424 .desc = "Sun4m platform, SPARCstation Voyager",
1425 .init = vger_init,
2d0d2837 1426 .block_default_type = IF_SCSI,
e4ada29e 1427 DEFAULT_MACHINE_OPTIONS,
a526a31c
BS
1428};
1429
f80f9ec9 1430static QEMUMachine ss_lx_machine = {
66de733b
BS
1431 .name = "LX",
1432 .desc = "Sun4m platform, SPARCstation LX",
1433 .init = ss_lx_init,
2d0d2837 1434 .block_default_type = IF_SCSI,
e4ada29e 1435 DEFAULT_MACHINE_OPTIONS,
a526a31c
BS
1436};
1437
f80f9ec9 1438static QEMUMachine ss4_machine = {
66de733b
BS
1439 .name = "SS-4",
1440 .desc = "Sun4m platform, SPARCstation 4",
1441 .init = ss4_init,
2d0d2837 1442 .block_default_type = IF_SCSI,
e4ada29e 1443 DEFAULT_MACHINE_OPTIONS,
a526a31c
BS
1444};
1445
f80f9ec9 1446static QEMUMachine scls_machine = {
66de733b
BS
1447 .name = "SPARCClassic",
1448 .desc = "Sun4m platform, SPARCClassic",
1449 .init = scls_init,
2d0d2837 1450 .block_default_type = IF_SCSI,
e4ada29e 1451 DEFAULT_MACHINE_OPTIONS,
a526a31c
BS
1452};
1453
f80f9ec9 1454static QEMUMachine sbook_machine = {
66de733b
BS
1455 .name = "SPARCbook",
1456 .desc = "Sun4m platform, SPARCbook",
1457 .init = sbook_init,
2d0d2837 1458 .block_default_type = IF_SCSI,
e4ada29e 1459 DEFAULT_MACHINE_OPTIONS,
a526a31c
BS
1460};
1461
83f7d43a
AF
1462static void sun4m_register_types(void)
1463{
1464 type_register_static(&idreg_info);
1465 type_register_static(&afx_info);
1466 type_register_static(&prom_info);
1467 type_register_static(&ram_info);
1468}
1469
6a4e1771 1470static void sun4m_machine_init(void)
f80f9ec9
AL
1471{
1472 qemu_register_machine(&ss5_machine);
1473 qemu_register_machine(&ss10_machine);
1474 qemu_register_machine(&ss600mp_machine);
1475 qemu_register_machine(&ss20_machine);
1476 qemu_register_machine(&voyager_machine);
1477 qemu_register_machine(&ss_lx_machine);
1478 qemu_register_machine(&ss4_machine);
1479 qemu_register_machine(&scls_machine);
1480 qemu_register_machine(&sbook_machine);
f80f9ec9
AL
1481}
1482
83f7d43a 1483type_init(sun4m_register_types)
6a4e1771 1484machine_init(sun4m_machine_init);