]> git.proxmox.com Git - mirror_qemu.git/blame - hw/sun4u.c
Sparc64: convert boot prom to qdev
[mirror_qemu.git] / hw / sun4u.c
CommitLineData
3475187d 1/*
c7ba218d 2 * QEMU Sun4u/Sun4v System Emulator
5fafdf24 3 *
3475187d 4 * Copyright (c) 2005 Fabrice Bellard
5fafdf24 5 *
3475187d
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 */
87ecb68b
PB
24#include "hw.h"
25#include "pci.h"
26#include "pc.h"
27#include "nvram.h"
28#include "fdc.h"
29#include "net.h"
30#include "qemu-timer.h"
31#include "sysemu.h"
32#include "boards.h"
d2c63fc1 33#include "firmware_abi.h"
3cce6243 34#include "fw_cfg.h"
1baffa46 35#include "sysbus.h"
3475187d 36
9d926598
BS
37//#define DEBUG_IRQ
38
39#ifdef DEBUG_IRQ
001faf32
BS
40#define DPRINTF(fmt, ...) \
41 do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
9d926598 42#else
001faf32 43#define DPRINTF(fmt, ...)
9d926598
BS
44#endif
45
83469015
FB
46#define KERNEL_LOAD_ADDR 0x00404000
47#define CMDLINE_ADDR 0x003ff000
48#define INITRD_LOAD_ADDR 0x00300000
ac2e9d66 49#define PROM_SIZE_MAX (4 * 1024 * 1024)
f930d07e 50#define PROM_VADDR 0x000ffd00000ULL
83469015 51#define APB_SPECIAL_BASE 0x1fe00000000ULL
f930d07e
BS
52#define APB_MEM_BASE 0x1ff00000000ULL
53#define VGA_BASE (APB_MEM_BASE + 0x400000ULL)
54#define PROM_FILENAME "openbios-sparc64"
83469015 55#define NVRAM_SIZE 0x2000
e4bcb14c 56#define MAX_IDE_BUS 2
3cce6243 57#define BIOS_CFG_IOPORT 0x510
3475187d 58
9d926598
BS
59#define MAX_PILS 16
60
8fa211e8
BS
61#define TICK_INT_DIS 0x8000000000000000ULL
62#define TICK_MAX 0x7fffffffffffffffULL
63
c7ba218d
BS
64struct hwdef {
65 const char * const default_cpu_model;
905fdcb5 66 uint16_t machine_id;
e87231d4
BS
67 uint64_t prom_addr;
68 uint64_t console_serial_base;
c7ba218d
BS
69};
70
3475187d
FB
71int DMA_get_channel_mode (int nchan)
72{
73 return 0;
74}
75int DMA_read_memory (int nchan, void *buf, int pos, int size)
76{
77 return 0;
78}
79int DMA_write_memory (int nchan, void *buf, int pos, int size)
80{
81 return 0;
82}
83void DMA_hold_DREQ (int nchan) {}
84void DMA_release_DREQ (int nchan) {}
85void DMA_schedule(int nchan) {}
3475187d
FB
86void DMA_init (int high_page_enable) {}
87void DMA_register_channel (int nchan,
88 DMA_transfer_handler transfer_handler,
89 void *opaque)
90{
91}
92
513f789f 93static int fw_cfg_boot_set(void *opaque, const char *boot_device)
81864572 94{
513f789f 95 fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
81864572
BS
96 return 0;
97}
98
d2c63fc1 99static int sun4u_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
e7fb1406 100 const char *arch,
77f193da
BS
101 ram_addr_t RAM_size,
102 const char *boot_devices,
d2c63fc1
BS
103 uint32_t kernel_image, uint32_t kernel_size,
104 const char *cmdline,
105 uint32_t initrd_image, uint32_t initrd_size,
106 uint32_t NVRAM_image,
0d31cb99
BS
107 int width, int height, int depth,
108 const uint8_t *macaddr)
83469015 109{
66508601
BS
110 unsigned int i;
111 uint32_t start, end;
d2c63fc1 112 uint8_t image[0x1ff0];
d2c63fc1
BS
113 struct OpenBIOS_nvpart_v1 *part_header;
114
115 memset(image, '\0', sizeof(image));
116
513f789f 117 start = 0;
83469015 118
66508601
BS
119 // OpenBIOS nvram variables
120 // Variable partition
d2c63fc1
BS
121 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
122 part_header->signature = OPENBIOS_PART_SYSTEM;
363a37d5 123 pstrcpy(part_header->name, sizeof(part_header->name), "system");
66508601 124
d2c63fc1 125 end = start + sizeof(struct OpenBIOS_nvpart_v1);
66508601 126 for (i = 0; i < nb_prom_envs; i++)
d2c63fc1
BS
127 end = OpenBIOS_set_var(image, end, prom_envs[i]);
128
129 // End marker
130 image[end++] = '\0';
66508601 131
66508601 132 end = start + ((end - start + 15) & ~15);
d2c63fc1 133 OpenBIOS_finish_partition(part_header, end - start);
66508601
BS
134
135 // free partition
136 start = end;
d2c63fc1
BS
137 part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
138 part_header->signature = OPENBIOS_PART_FREE;
363a37d5 139 pstrcpy(part_header->name, sizeof(part_header->name), "free");
66508601
BS
140
141 end = 0x1fd0;
d2c63fc1
BS
142 OpenBIOS_finish_partition(part_header, end - start);
143
0d31cb99
BS
144 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80);
145
d2c63fc1
BS
146 for (i = 0; i < sizeof(image); i++)
147 m48t59_write(nvram, i, image[i]);
66508601 148
83469015 149 return 0;
3475187d
FB
150}
151
b4950060 152void pic_info(Monitor *mon)
3475187d
FB
153{
154}
155
b4950060 156void irq_info(Monitor *mon)
3475187d
FB
157{
158}
159
9d926598
BS
160void cpu_check_irqs(CPUState *env)
161{
162 uint32_t pil = env->pil_in | (env->softint & ~SOFTINT_TIMER) |
163 ((env->softint & SOFTINT_TIMER) << 14);
164
165 if (pil && (env->interrupt_index == 0 ||
166 (env->interrupt_index & ~15) == TT_EXTINT)) {
167 unsigned int i;
168
169 for (i = 15; i > 0; i--) {
170 if (pil & (1 << i)) {
171 int old_interrupt = env->interrupt_index;
172
173 env->interrupt_index = TT_EXTINT | i;
174 if (old_interrupt != env->interrupt_index) {
175 DPRINTF("Set CPU IRQ %d\n", i);
176 cpu_interrupt(env, CPU_INTERRUPT_HARD);
177 }
178 break;
179 }
180 }
181 } else if (!pil && (env->interrupt_index & ~15) == TT_EXTINT) {
182 DPRINTF("Reset CPU IRQ %d\n", env->interrupt_index & 15);
183 env->interrupt_index = 0;
184 cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
185 }
186}
187
188static void cpu_set_irq(void *opaque, int irq, int level)
189{
190 CPUState *env = opaque;
191
192 if (level) {
193 DPRINTF("Raise CPU IRQ %d\n", irq);
194 env->halted = 0;
195 env->pil_in |= 1 << irq;
196 cpu_check_irqs(env);
197 } else {
198 DPRINTF("Lower CPU IRQ %d\n", irq);
199 env->pil_in &= ~(1 << irq);
200 cpu_check_irqs(env);
201 }
202}
203
83469015 204void qemu_system_powerdown(void)
3475187d
FB
205{
206}
207
e87231d4
BS
208typedef struct ResetData {
209 CPUState *env;
210 uint64_t reset_addr;
211} ResetData;
212
c68ea704
FB
213static void main_cpu_reset(void *opaque)
214{
e87231d4
BS
215 ResetData *s = (ResetData *)opaque;
216 CPUState *env = s->env;
20c9f095 217
c68ea704 218 cpu_reset(env);
8fa211e8
BS
219 env->tick_cmpr = TICK_INT_DIS | 0;
220 ptimer_set_limit(env->tick, TICK_MAX, 1);
2f43e00e 221 ptimer_run(env->tick, 1);
8fa211e8
BS
222 env->stick_cmpr = TICK_INT_DIS | 0;
223 ptimer_set_limit(env->stick, TICK_MAX, 1);
2f43e00e 224 ptimer_run(env->stick, 1);
8fa211e8
BS
225 env->hstick_cmpr = TICK_INT_DIS | 0;
226 ptimer_set_limit(env->hstick, TICK_MAX, 1);
2f43e00e 227 ptimer_run(env->hstick, 1);
e87231d4
BS
228 env->gregs[1] = 0; // Memory start
229 env->gregs[2] = ram_size; // Memory size
230 env->gregs[3] = 0; // Machine description XXX
231 env->pc = s->reset_addr;
232 env->npc = env->pc + 4;
20c9f095
BS
233}
234
22548760 235static void tick_irq(void *opaque)
20c9f095
BS
236{
237 CPUState *env = opaque;
238
8fa211e8
BS
239 if (!(env->tick_cmpr & TICK_INT_DIS)) {
240 env->softint |= SOFTINT_TIMER;
241 cpu_interrupt(env, CPU_INTERRUPT_TIMER);
242 }
20c9f095
BS
243}
244
22548760 245static void stick_irq(void *opaque)
20c9f095
BS
246{
247 CPUState *env = opaque;
248
8fa211e8
BS
249 if (!(env->stick_cmpr & TICK_INT_DIS)) {
250 env->softint |= SOFTINT_STIMER;
251 cpu_interrupt(env, CPU_INTERRUPT_TIMER);
252 }
20c9f095
BS
253}
254
22548760 255static void hstick_irq(void *opaque)
20c9f095
BS
256{
257 CPUState *env = opaque;
258
8fa211e8
BS
259 if (!(env->hstick_cmpr & TICK_INT_DIS)) {
260 cpu_interrupt(env, CPU_INTERRUPT_TIMER);
261 }
c68ea704
FB
262}
263
f4b1a842
BS
264void cpu_tick_set_count(void *opaque, uint64_t count)
265{
266 ptimer_set_count(opaque, -count);
267}
268
269uint64_t cpu_tick_get_count(void *opaque)
270{
271 return -ptimer_get_count(opaque);
272}
273
274void cpu_tick_set_limit(void *opaque, uint64_t limit)
275{
276 ptimer_set_limit(opaque, -limit, 0);
277}
278
83469015
FB
279static const int ide_iobase[2] = { 0x1f0, 0x170 };
280static const int ide_iobase2[2] = { 0x3f6, 0x376 };
281static const int ide_irq[2] = { 14, 15 };
3475187d 282
83469015
FB
283static const int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
284static const int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
285
286static const int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
287static const int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
288
289static fdctrl_t *floppy_controller;
3475187d 290
c190ea07
BS
291static void ebus_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
292 uint32_t addr, uint32_t size, int type)
293{
294 DPRINTF("Mapping region %d registers at %08x\n", region_num, addr);
295 switch (region_num) {
296 case 0:
297 isa_mmio_init(addr, 0x1000000);
298 break;
299 case 1:
300 isa_mmio_init(addr, 0x800000);
301 break;
302 }
303}
304
305/* EBUS (Eight bit bus) bridge */
306static void
307pci_ebus_init(PCIBus *bus, int devfn)
308{
53e3c4f9
BS
309 pci_create_simple(bus, devfn, "ebus");
310}
c190ea07 311
53e3c4f9
BS
312static void
313pci_ebus_init1(PCIDevice *s)
314{
deb54399
AL
315 pci_config_set_vendor_id(s->config, PCI_VENDOR_ID_SUN);
316 pci_config_set_device_id(s->config, PCI_DEVICE_ID_SUN_EBUS);
c190ea07
BS
317 s->config[0x04] = 0x06; // command = bus master, pci mem
318 s->config[0x05] = 0x00;
319 s->config[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
320 s->config[0x07] = 0x03; // status = medium devsel
321 s->config[0x08] = 0x01; // revision
322 s->config[0x09] = 0x00; // programming i/f
173a543b 323 pci_config_set_class(s->config, PCI_CLASS_BRIDGE_OTHER);
c190ea07 324 s->config[0x0D] = 0x0a; // latency_timer
6407f373 325 s->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
c190ea07 326
28c2c264 327 pci_register_bar(s, 0, 0x1000000, PCI_ADDRESS_SPACE_MEM,
c190ea07 328 ebus_mmio_mapfunc);
28c2c264 329 pci_register_bar(s, 1, 0x800000, PCI_ADDRESS_SPACE_MEM,
c190ea07
BS
330 ebus_mmio_mapfunc);
331}
332
53e3c4f9
BS
333static PCIDeviceInfo ebus_info = {
334 .qdev.name = "ebus",
335 .qdev.size = sizeof(PCIDevice),
336 .init = pci_ebus_init1,
337};
338
339static void pci_ebus_register(void)
340{
341 pci_qdev_register(&ebus_info);
342}
343
344device_init(pci_ebus_register);
345
1baffa46
BS
346/* Boot PROM (OpenBIOS) */
347static void prom_init(target_phys_addr_t addr, const char *bios_name)
348{
349 DeviceState *dev;
350 SysBusDevice *s;
351 char *filename;
352 int ret;
353
354 dev = qdev_create(NULL, "openprom");
355 qdev_init(dev);
356 s = sysbus_from_qdev(dev);
357
358 sysbus_mmio_map(s, 0, addr);
359
360 /* load boot prom */
361 if (bios_name == NULL) {
362 bios_name = PROM_FILENAME;
363 }
364 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
365 if (filename) {
366 ret = load_elf(filename, addr - PROM_VADDR, NULL, NULL, NULL);
367 if (ret < 0 || ret > PROM_SIZE_MAX) {
368 ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
369 }
370 qemu_free(filename);
371 } else {
372 ret = -1;
373 }
374 if (ret < 0 || ret > PROM_SIZE_MAX) {
375 fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
376 exit(1);
377 }
378}
379
380static void prom_init1(SysBusDevice *dev)
381{
382 ram_addr_t prom_offset;
383
384 prom_offset = qemu_ram_alloc(PROM_SIZE_MAX);
385 sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM);
386}
387
388static SysBusDeviceInfo prom_info = {
389 .init = prom_init1,
390 .qdev.name = "openprom",
391 .qdev.size = sizeof(SysBusDevice),
392 .qdev.props = (Property[]) {
393 {/* end of property list */}
394 }
395};
396
397static void prom_register_devices(void)
398{
399 sysbus_register_withprop(&prom_info);
400}
401
402device_init(prom_register_devices);
403
fbe1b595 404static void sun4uv_init(ram_addr_t RAM_size,
3023f332 405 const char *boot_devices,
c7ba218d
BS
406 const char *kernel_filename, const char *kernel_cmdline,
407 const char *initrd_filename, const char *cpu_model,
408 const struct hwdef *hwdef)
3475187d 409{
c68ea704 410 CPUState *env;
83469015 411 m48t59_t *nvram;
1baffa46 412 int linux_boot;
3475187d 413 unsigned int i;
1baffa46 414 ram_addr_t ram_offset;
5c6602c5 415 long initrd_size, kernel_size;
c190ea07 416 PCIBus *pci_bus, *pci_bus2, *pci_bus3;
20c9f095 417 QEMUBH *bh;
f19e918d 418 qemu_irq *irq;
22548760 419 int drive_index;
e4bcb14c
TS
420 BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
421 BlockDriverState *fd[MAX_FD];
3cce6243 422 void *fw_cfg;
e87231d4 423 ResetData *reset_info;
3475187d
FB
424
425 linux_boot = (kernel_filename != NULL);
426
62724a37 427 /* init CPUs */
c7ba218d
BS
428 if (!cpu_model)
429 cpu_model = hwdef->default_cpu_model;
430
aaed909a
FB
431 env = cpu_init(cpu_model);
432 if (!env) {
62724a37
BS
433 fprintf(stderr, "Unable to find Sparc CPU definition\n");
434 exit(1);
435 }
20c9f095
BS
436 bh = qemu_bh_new(tick_irq, env);
437 env->tick = ptimer_init(bh);
438 ptimer_set_period(env->tick, 1ULL);
439
440 bh = qemu_bh_new(stick_irq, env);
441 env->stick = ptimer_init(bh);
442 ptimer_set_period(env->stick, 1ULL);
443
444 bh = qemu_bh_new(hstick_irq, env);
445 env->hstick = ptimer_init(bh);
446 ptimer_set_period(env->hstick, 1ULL);
e87231d4
BS
447
448 reset_info = qemu_mallocz(sizeof(ResetData));
449 reset_info->env = env;
450 reset_info->reset_addr = hwdef->prom_addr + 0x40ULL;
a08d4367 451 qemu_register_reset(main_cpu_reset, reset_info);
e87231d4
BS
452 main_cpu_reset(reset_info);
453 // Override warm reset address with cold start address
454 env->pc = hwdef->prom_addr + 0x20ULL;
455 env->npc = env->pc + 4;
c68ea704 456
3475187d 457 /* allocate RAM */
5c6602c5
BS
458 ram_offset = qemu_ram_alloc(RAM_size);
459 cpu_register_physical_memory(0, RAM_size, ram_offset);
3475187d 460
1baffa46 461 prom_init(hwdef->prom_addr, bios_name);
3475187d
FB
462
463 kernel_size = 0;
83469015 464 initrd_size = 0;
3475187d 465 if (linux_boot) {
b3783731 466 /* XXX: put correct offset */
74287114 467 kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL);
3475187d 468 if (kernel_size < 0)
293f78bc
BS
469 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
470 ram_size - KERNEL_LOAD_ADDR);
f930d07e 471 if (kernel_size < 0)
293f78bc
BS
472 kernel_size = load_image_targphys(kernel_filename,
473 KERNEL_LOAD_ADDR,
474 ram_size - KERNEL_LOAD_ADDR);
3475187d 475 if (kernel_size < 0) {
5fafdf24 476 fprintf(stderr, "qemu: could not load kernel '%s'\n",
3475187d 477 kernel_filename);
f930d07e 478 exit(1);
3475187d
FB
479 }
480
481 /* load initrd */
3475187d 482 if (initrd_filename) {
293f78bc
BS
483 initrd_size = load_image_targphys(initrd_filename,
484 INITRD_LOAD_ADDR,
485 ram_size - INITRD_LOAD_ADDR);
3475187d 486 if (initrd_size < 0) {
5fafdf24 487 fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
3475187d
FB
488 initrd_filename);
489 exit(1);
490 }
491 }
492 if (initrd_size > 0) {
f930d07e 493 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
293f78bc
BS
494 if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
495 stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
496 stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
f930d07e
BS
497 break;
498 }
499 }
3475187d
FB
500 }
501 }
7d55273f
IK
502
503 irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
504 pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, irq, &pci_bus2,
c190ea07 505 &pci_bus3);
83469015 506 isa_mem_base = VGA_BASE;
fbe1b595 507 pci_vga_init(pci_bus, 0, 0);
83469015 508
c190ea07
BS
509 // XXX Should be pci_bus3
510 pci_ebus_init(pci_bus, -1);
511
e87231d4
BS
512 i = 0;
513 if (hwdef->console_serial_base) {
514 serial_mm_init(hwdef->console_serial_base, 0, NULL, 115200,
515 serial_hds[i], 1);
516 i++;
517 }
518 for(; i < MAX_SERIAL_PORTS; i++) {
83469015 519 if (serial_hds[i]) {
cbf5c748
BS
520 serial_init(serial_io[i], NULL/*serial_irq[i]*/, 115200,
521 serial_hds[i]);
83469015
FB
522 }
523 }
524
525 for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
526 if (parallel_hds[i]) {
77f193da
BS
527 parallel_init(parallel_io[i], NULL/*parallel_irq[i]*/,
528 parallel_hds[i]);
83469015
FB
529 }
530 }
531
cb457d76 532 for(i = 0; i < nb_nics; i++)
6d53bfd1 533 pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
83469015 534
e4bcb14c
TS
535 if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
536 fprintf(stderr, "qemu: too many IDE bus\n");
537 exit(1);
538 }
539 for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
22548760
BS
540 drive_index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS,
541 i % MAX_IDE_DEVS);
542 if (drive_index != -1)
543 hd[i] = drives_table[drive_index].bdrv;
e4bcb14c
TS
544 else
545 hd[i] = NULL;
546 }
547
3b898dda
BS
548 pci_cmd646_ide_init(pci_bus, hd, 1);
549
d537cf6c
PB
550 /* FIXME: wire up interrupts. */
551 i8042_init(NULL/*1*/, NULL/*12*/, 0x60);
e4bcb14c 552 for(i = 0; i < MAX_FD; i++) {
22548760
BS
553 drive_index = drive_get_index(IF_FLOPPY, 0, i);
554 if (drive_index != -1)
555 fd[i] = drives_table[drive_index].bdrv;
e4bcb14c
TS
556 else
557 fd[i] = NULL;
558 }
559 floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd);
d537cf6c 560 nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59);
22548760 561 sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices,
0d31cb99
BS
562 KERNEL_LOAD_ADDR, kernel_size,
563 kernel_cmdline,
564 INITRD_LOAD_ADDR, initrd_size,
565 /* XXX: need an option to load a NVRAM image */
566 0,
567 graphic_width, graphic_height, graphic_depth,
568 (uint8_t *)&nd_table[0].macaddr);
83469015 569
3cce6243
BS
570 fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
571 fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
905fdcb5
BS
572 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
573 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
513f789f
BS
574 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
575 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
576 if (kernel_cmdline) {
577 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
578 pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
579 } else {
580 fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
581 }
582 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
583 fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
584 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
585 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
3475187d
FB
586}
587
905fdcb5
BS
588enum {
589 sun4u_id = 0,
590 sun4v_id = 64,
e87231d4 591 niagara_id,
905fdcb5
BS
592};
593
c7ba218d
BS
594static const struct hwdef hwdefs[] = {
595 /* Sun4u generic PC-like machine */
596 {
597 .default_cpu_model = "TI UltraSparc II",
905fdcb5 598 .machine_id = sun4u_id,
e87231d4
BS
599 .prom_addr = 0x1fff0000000ULL,
600 .console_serial_base = 0,
c7ba218d
BS
601 },
602 /* Sun4v generic PC-like machine */
603 {
604 .default_cpu_model = "Sun UltraSparc T1",
905fdcb5 605 .machine_id = sun4v_id,
e87231d4
BS
606 .prom_addr = 0x1fff0000000ULL,
607 .console_serial_base = 0,
608 },
609 /* Sun4v generic Niagara machine */
610 {
611 .default_cpu_model = "Sun UltraSparc T1",
612 .machine_id = niagara_id,
613 .prom_addr = 0xfff0000000ULL,
614 .console_serial_base = 0xfff0c2c000ULL,
c7ba218d
BS
615 },
616};
617
618/* Sun4u hardware initialisation */
fbe1b595 619static void sun4u_init(ram_addr_t RAM_size,
3023f332 620 const char *boot_devices,
c7ba218d
BS
621 const char *kernel_filename, const char *kernel_cmdline,
622 const char *initrd_filename, const char *cpu_model)
623{
fbe1b595 624 sun4uv_init(RAM_size, boot_devices, kernel_filename,
c7ba218d
BS
625 kernel_cmdline, initrd_filename, cpu_model, &hwdefs[0]);
626}
627
628/* Sun4v hardware initialisation */
fbe1b595 629static void sun4v_init(ram_addr_t RAM_size,
3023f332 630 const char *boot_devices,
c7ba218d
BS
631 const char *kernel_filename, const char *kernel_cmdline,
632 const char *initrd_filename, const char *cpu_model)
633{
fbe1b595 634 sun4uv_init(RAM_size, boot_devices, kernel_filename,
c7ba218d
BS
635 kernel_cmdline, initrd_filename, cpu_model, &hwdefs[1]);
636}
637
e87231d4 638/* Niagara hardware initialisation */
fbe1b595 639static void niagara_init(ram_addr_t RAM_size,
3023f332 640 const char *boot_devices,
e87231d4
BS
641 const char *kernel_filename, const char *kernel_cmdline,
642 const char *initrd_filename, const char *cpu_model)
643{
fbe1b595 644 sun4uv_init(RAM_size, boot_devices, kernel_filename,
e87231d4
BS
645 kernel_cmdline, initrd_filename, cpu_model, &hwdefs[2]);
646}
647
f80f9ec9 648static QEMUMachine sun4u_machine = {
66de733b
BS
649 .name = "sun4u",
650 .desc = "Sun4u platform",
651 .init = sun4u_init,
1bcee014 652 .max_cpus = 1, // XXX for now
0c257437 653 .is_default = 1,
3475187d 654};
c7ba218d 655
f80f9ec9 656static QEMUMachine sun4v_machine = {
66de733b
BS
657 .name = "sun4v",
658 .desc = "Sun4v platform",
659 .init = sun4v_init,
1bcee014 660 .max_cpus = 1, // XXX for now
c7ba218d 661};
e87231d4 662
f80f9ec9 663static QEMUMachine niagara_machine = {
e87231d4
BS
664 .name = "Niagara",
665 .desc = "Sun4v platform, Niagara",
666 .init = niagara_init,
1bcee014 667 .max_cpus = 1, // XXX for now
e87231d4 668};
f80f9ec9
AL
669
670static void sun4u_machine_init(void)
671{
672 qemu_register_machine(&sun4u_machine);
673 qemu_register_machine(&sun4v_machine);
674 qemu_register_machine(&niagara_machine);
675}
676
677machine_init(sun4u_machine_init);