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