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