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