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