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