Statistics
| Branch: | Revision:

root / hw / sun4u.c @ 7b833f5b

History | View | Annotate | Download (21.4 kB)

1
/*
2
 * QEMU Sun4u/Sun4v System Emulator
3
 *
4
 * Copyright (c) 2005 Fabrice Bellard
5
 *
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
 */
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"
33
#include "firmware_abi.h"
34
#include "fw_cfg.h"
35
#include "sysbus.h"
36

    
37
//#define DEBUG_IRQ
38

    
39
#ifdef DEBUG_IRQ
40
#define DPRINTF(fmt, ...)                                       \
41
    do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0)
42
#else
43
#define DPRINTF(fmt, ...)
44
#endif
45

    
46
#define KERNEL_LOAD_ADDR     0x00404000
47
#define CMDLINE_ADDR         0x003ff000
48
#define INITRD_LOAD_ADDR     0x00300000
49
#define PROM_SIZE_MAX        (4 * 1024 * 1024)
50
#define PROM_VADDR           0x000ffd00000ULL
51
#define APB_SPECIAL_BASE     0x1fe00000000ULL
52
#define APB_MEM_BASE         0x1ff00000000ULL
53
#define VGA_BASE             (APB_MEM_BASE + 0x400000ULL)
54
#define PROM_FILENAME        "openbios-sparc64"
55
#define NVRAM_SIZE           0x2000
56
#define MAX_IDE_BUS          2
57
#define BIOS_CFG_IOPORT      0x510
58

    
59
#define MAX_PILS 16
60

    
61
#define TICK_INT_DIS         0x8000000000000000ULL
62
#define TICK_MAX             0x7fffffffffffffffULL
63

    
64
struct hwdef {
65
    const char * const default_cpu_model;
66
    uint16_t machine_id;
67
    uint64_t prom_addr;
68
    uint64_t console_serial_base;
69
};
70

    
71
int DMA_get_channel_mode (int nchan)
72
{
73
    return 0;
74
}
75
int DMA_read_memory (int nchan, void *buf, int pos, int size)
76
{
77
    return 0;
78
}
79
int DMA_write_memory (int nchan, void *buf, int pos, int size)
80
{
81
    return 0;
82
}
83
void DMA_hold_DREQ (int nchan) {}
84
void DMA_release_DREQ (int nchan) {}
85
void DMA_schedule(int nchan) {}
86
void DMA_init (int high_page_enable) {}
87
void DMA_register_channel (int nchan,
88
                           DMA_transfer_handler transfer_handler,
89
                           void *opaque)
90
{
91
}
92

    
93
static int fw_cfg_boot_set(void *opaque, const char *boot_device)
94
{
95
    fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
96
    return 0;
97
}
98

    
99
static int sun4u_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size,
100
                                   const char *arch,
101
                                   ram_addr_t RAM_size,
102
                                   const char *boot_devices,
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,
107
                                   int width, int height, int depth,
108
                                   const uint8_t *macaddr)
109
{
110
    unsigned int i;
111
    uint32_t start, end;
112
    uint8_t image[0x1ff0];
113
    struct OpenBIOS_nvpart_v1 *part_header;
114

    
115
    memset(image, '\0', sizeof(image));
116

    
117
    start = 0;
118

    
119
    // OpenBIOS nvram variables
120
    // Variable partition
121
    part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
122
    part_header->signature = OPENBIOS_PART_SYSTEM;
123
    pstrcpy(part_header->name, sizeof(part_header->name), "system");
124

    
125
    end = start + sizeof(struct OpenBIOS_nvpart_v1);
126
    for (i = 0; i < nb_prom_envs; i++)
127
        end = OpenBIOS_set_var(image, end, prom_envs[i]);
128

    
129
    // End marker
130
    image[end++] = '\0';
131

    
132
    end = start + ((end - start + 15) & ~15);
133
    OpenBIOS_finish_partition(part_header, end - start);
134

    
135
    // free partition
136
    start = end;
137
    part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
138
    part_header->signature = OPENBIOS_PART_FREE;
139
    pstrcpy(part_header->name, sizeof(part_header->name), "free");
140

    
141
    end = 0x1fd0;
142
    OpenBIOS_finish_partition(part_header, end - start);
143

    
144
    Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80);
145

    
146
    for (i = 0; i < sizeof(image); i++)
147
        m48t59_write(nvram, i, image[i]);
148

    
149
    return 0;
150
}
151

    
152
void pic_info(Monitor *mon)
153
{
154
}
155

    
156
void irq_info(Monitor *mon)
157
{
158
}
159

    
160
void 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

    
188
static 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

    
204
void qemu_system_powerdown(void)
205
{
206
}
207

    
208
typedef struct ResetData {
209
    CPUState *env;
210
    uint64_t reset_addr;
211
} ResetData;
212

    
213
static void main_cpu_reset(void *opaque)
214
{
215
    ResetData *s = (ResetData *)opaque;
216
    CPUState *env = s->env;
217

    
218
    cpu_reset(env);
219
    env->tick_cmpr = TICK_INT_DIS | 0;
220
    ptimer_set_limit(env->tick, TICK_MAX, 1);
221
    ptimer_run(env->tick, 1);
222
    env->stick_cmpr = TICK_INT_DIS | 0;
223
    ptimer_set_limit(env->stick, TICK_MAX, 1);
224
    ptimer_run(env->stick, 1);
225
    env->hstick_cmpr = TICK_INT_DIS | 0;
226
    ptimer_set_limit(env->hstick, TICK_MAX, 1);
227
    ptimer_run(env->hstick, 1);
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;
233
}
234

    
235
static void tick_irq(void *opaque)
236
{
237
    CPUState *env = opaque;
238

    
239
    if (!(env->tick_cmpr & TICK_INT_DIS)) {
240
        env->softint |= SOFTINT_TIMER;
241
        cpu_interrupt(env, CPU_INTERRUPT_TIMER);
242
    }
243
}
244

    
245
static void stick_irq(void *opaque)
246
{
247
    CPUState *env = opaque;
248

    
249
    if (!(env->stick_cmpr & TICK_INT_DIS)) {
250
        env->softint |= SOFTINT_STIMER;
251
        cpu_interrupt(env, CPU_INTERRUPT_TIMER);
252
    }
253
}
254

    
255
static void hstick_irq(void *opaque)
256
{
257
    CPUState *env = opaque;
258

    
259
    if (!(env->hstick_cmpr & TICK_INT_DIS)) {
260
        cpu_interrupt(env, CPU_INTERRUPT_TIMER);
261
    }
262
}
263

    
264
void cpu_tick_set_count(void *opaque, uint64_t count)
265
{
266
    ptimer_set_count(opaque, -count);
267
}
268

    
269
uint64_t cpu_tick_get_count(void *opaque)
270
{
271
    return -ptimer_get_count(opaque);
272
}
273

    
274
void cpu_tick_set_limit(void *opaque, uint64_t limit)
275
{
276
    ptimer_set_limit(opaque, -limit, 0);
277
}
278

    
279
static const int ide_iobase[2] = { 0x1f0, 0x170 };
280
static const int ide_iobase2[2] = { 0x3f6, 0x376 };
281
static const int ide_irq[2] = { 14, 15 };
282

    
283
static const int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
284
static const int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
285

    
286
static const int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
287
static const int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
288

    
289
static fdctrl_t *floppy_controller;
290

    
291
static 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 */
306
static void
307
pci_ebus_init(PCIBus *bus, int devfn)
308
{
309
    pci_create_simple(bus, devfn, "ebus");
310
}
311

    
312
static void
313
pci_ebus_init1(PCIDevice *s)
314
{
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);
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
323
    pci_config_set_class(s->config, PCI_CLASS_BRIDGE_OTHER);
324
    s->config[0x0D] = 0x0a; // latency_timer
325
    s->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
326

    
327
    pci_register_bar(s, 0, 0x1000000, PCI_ADDRESS_SPACE_MEM,
328
                           ebus_mmio_mapfunc);
329
    pci_register_bar(s, 1, 0x800000,  PCI_ADDRESS_SPACE_MEM,
330
                           ebus_mmio_mapfunc);
331
}
332

    
333
static PCIDeviceInfo ebus_info = {
334
    .qdev.name = "ebus",
335
    .qdev.size = sizeof(PCIDevice),
336
    .init = pci_ebus_init1,
337
};
338

    
339
static void pci_ebus_register(void)
340
{
341
    pci_qdev_register(&ebus_info);
342
}
343

    
344
device_init(pci_ebus_register);
345

    
346
/* Boot PROM (OpenBIOS) */
347
static 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

    
380
static 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

    
388
static 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

    
397
static void prom_register_devices(void)
398
{
399
    sysbus_register_withprop(&prom_info);
400
}
401

    
402
device_init(prom_register_devices);
403

    
404

    
405
typedef struct RamDevice
406
{
407
    SysBusDevice busdev;
408
    uint32_t size; // XXX
409
} RamDevice;
410

    
411
/* System RAM */
412
static void ram_init1(SysBusDevice *dev)
413
{
414
    ram_addr_t RAM_size, ram_offset;
415
    RamDevice *d = FROM_SYSBUS(RamDevice, dev);
416

    
417
    RAM_size = d->size;
418

    
419
    ram_offset = qemu_ram_alloc(RAM_size);
420
    sysbus_init_mmio(dev, RAM_size, ram_offset);
421
}
422

    
423
static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size)
424
{
425
    DeviceState *dev;
426
    SysBusDevice *s;
427
    RamDevice *d;
428

    
429
    /* allocate RAM */
430
    dev = qdev_create(NULL, "memory");
431
    s = sysbus_from_qdev(dev);
432

    
433
    d = FROM_SYSBUS(RamDevice, s);
434
    d->size = RAM_size;
435
    qdev_init(dev);
436

    
437
    sysbus_mmio_map(s, 0, addr);
438
}
439

    
440
static SysBusDeviceInfo ram_info = {
441
    .init = ram_init1,
442
    .qdev.name  = "memory",
443
    .qdev.size  = sizeof(RamDevice),
444
    .qdev.props = (Property[]) {
445
        {
446
            .name = "size",
447
            .info = &qdev_prop_uint32,
448
            .offset = offsetof(RamDevice, size),
449
        },
450
        {/* end of property list */}
451
    }
452
};
453

    
454
static void ram_register_devices(void)
455
{
456
    sysbus_register_withprop(&ram_info);
457
}
458

    
459
device_init(ram_register_devices);
460

    
461
static CPUState *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef)
462
{
463
    CPUState *env;
464
    QEMUBH *bh;
465
    ResetData *reset_info;
466

    
467
    if (!cpu_model)
468
        cpu_model = hwdef->default_cpu_model;
469
    env = cpu_init(cpu_model);
470
    if (!env) {
471
        fprintf(stderr, "Unable to find Sparc CPU definition\n");
472
        exit(1);
473
    }
474
    bh = qemu_bh_new(tick_irq, env);
475
    env->tick = ptimer_init(bh);
476
    ptimer_set_period(env->tick, 1ULL);
477

    
478
    bh = qemu_bh_new(stick_irq, env);
479
    env->stick = ptimer_init(bh);
480
    ptimer_set_period(env->stick, 1ULL);
481

    
482
    bh = qemu_bh_new(hstick_irq, env);
483
    env->hstick = ptimer_init(bh);
484
    ptimer_set_period(env->hstick, 1ULL);
485

    
486
    reset_info = qemu_mallocz(sizeof(ResetData));
487
    reset_info->env = env;
488
    reset_info->reset_addr = hwdef->prom_addr + 0x40ULL;
489
    qemu_register_reset(main_cpu_reset, reset_info);
490
    main_cpu_reset(reset_info);
491
    // Override warm reset address with cold start address
492
    env->pc = hwdef->prom_addr + 0x20ULL;
493
    env->npc = env->pc + 4;
494

    
495
    return env;
496
}
497

    
498
static void sun4uv_init(ram_addr_t RAM_size,
499
                        const char *boot_devices,
500
                        const char *kernel_filename, const char *kernel_cmdline,
501
                        const char *initrd_filename, const char *cpu_model,
502
                        const struct hwdef *hwdef)
503
{
504
    CPUState *env;
505
    m48t59_t *nvram;
506
    int linux_boot;
507
    unsigned int i;
508
    long initrd_size, kernel_size;
509
    PCIBus *pci_bus, *pci_bus2, *pci_bus3;
510
    qemu_irq *irq;
511
    int drive_index;
512
    BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
513
    BlockDriverState *fd[MAX_FD];
514
    void *fw_cfg;
515

    
516
    linux_boot = (kernel_filename != NULL);
517

    
518
    /* init CPUs */
519
    env = cpu_devinit(cpu_model, hwdef);
520

    
521
    /* set up devices */
522
    ram_init(0, RAM_size);
523

    
524
    prom_init(hwdef->prom_addr, bios_name);
525

    
526
    kernel_size = 0;
527
    initrd_size = 0;
528
    if (linux_boot) {
529
        /* XXX: put correct offset */
530
        kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL);
531
        if (kernel_size < 0)
532
            kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
533
                                    ram_size - KERNEL_LOAD_ADDR);
534
        if (kernel_size < 0)
535
            kernel_size = load_image_targphys(kernel_filename,
536
                                              KERNEL_LOAD_ADDR,
537
                                              ram_size - KERNEL_LOAD_ADDR);
538
        if (kernel_size < 0) {
539
            fprintf(stderr, "qemu: could not load kernel '%s'\n",
540
                    kernel_filename);
541
            exit(1);
542
        }
543

    
544
        /* load initrd */
545
        if (initrd_filename) {
546
            initrd_size = load_image_targphys(initrd_filename,
547
                                              INITRD_LOAD_ADDR,
548
                                              ram_size - INITRD_LOAD_ADDR);
549
            if (initrd_size < 0) {
550
                fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
551
                        initrd_filename);
552
                exit(1);
553
            }
554
        }
555
        if (initrd_size > 0) {
556
            for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
557
                if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS
558
                    stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR);
559
                    stl_phys(KERNEL_LOAD_ADDR + i + 20, initrd_size);
560
                    break;
561
                }
562
            }
563
        }
564
    }
565

    
566
    irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
567
    pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, irq, &pci_bus2,
568
                           &pci_bus3);
569
    isa_mem_base = VGA_BASE;
570
    pci_vga_init(pci_bus, 0, 0);
571

    
572
    // XXX Should be pci_bus3
573
    pci_ebus_init(pci_bus, -1);
574

    
575
    i = 0;
576
    if (hwdef->console_serial_base) {
577
        serial_mm_init(hwdef->console_serial_base, 0, NULL, 115200,
578
                       serial_hds[i], 1);
579
        i++;
580
    }
581
    for(; i < MAX_SERIAL_PORTS; i++) {
582
        if (serial_hds[i]) {
583
            serial_init(serial_io[i], NULL/*serial_irq[i]*/, 115200,
584
                        serial_hds[i]);
585
        }
586
    }
587

    
588
    for(i = 0; i < MAX_PARALLEL_PORTS; i++) {
589
        if (parallel_hds[i]) {
590
            parallel_init(parallel_io[i], NULL/*parallel_irq[i]*/,
591
                          parallel_hds[i]);
592
        }
593
    }
594

    
595
    for(i = 0; i < nb_nics; i++)
596
        pci_nic_init(&nd_table[i], "ne2k_pci", NULL);
597

    
598
    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
599
        fprintf(stderr, "qemu: too many IDE bus\n");
600
        exit(1);
601
    }
602
    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
603
        drive_index = drive_get_index(IF_IDE, i / MAX_IDE_DEVS,
604
                                      i % MAX_IDE_DEVS);
605
       if (drive_index != -1)
606
           hd[i] = drives_table[drive_index].bdrv;
607
       else
608
           hd[i] = NULL;
609
    }
610

    
611
    pci_cmd646_ide_init(pci_bus, hd, 1);
612

    
613
    /* FIXME: wire up interrupts.  */
614
    i8042_init(NULL/*1*/, NULL/*12*/, 0x60);
615
    for(i = 0; i < MAX_FD; i++) {
616
        drive_index = drive_get_index(IF_FLOPPY, 0, i);
617
       if (drive_index != -1)
618
           fd[i] = drives_table[drive_index].bdrv;
619
       else
620
           fd[i] = NULL;
621
    }
622
    floppy_controller = fdctrl_init(NULL/*6*/, 2, 0, 0x3f0, fd);
623
    nvram = m48t59_init(NULL/*8*/, 0, 0x0074, NVRAM_SIZE, 59);
624
    sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices,
625
                           KERNEL_LOAD_ADDR, kernel_size,
626
                           kernel_cmdline,
627
                           INITRD_LOAD_ADDR, initrd_size,
628
                           /* XXX: need an option to load a NVRAM image */
629
                           0,
630
                           graphic_width, graphic_height, graphic_depth,
631
                           (uint8_t *)&nd_table[0].macaddr);
632

    
633
    fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0);
634
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
635
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
636
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
637
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
638
    fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
639
    if (kernel_cmdline) {
640
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
641
        pstrcpy_targphys(CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
642
    } else {
643
        fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
644
    }
645
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
646
    fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
647
    fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]);
648
    qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
649
}
650

    
651
enum {
652
    sun4u_id = 0,
653
    sun4v_id = 64,
654
    niagara_id,
655
};
656

    
657
static const struct hwdef hwdefs[] = {
658
    /* Sun4u generic PC-like machine */
659
    {
660
        .default_cpu_model = "TI UltraSparc II",
661
        .machine_id = sun4u_id,
662
        .prom_addr = 0x1fff0000000ULL,
663
        .console_serial_base = 0,
664
    },
665
    /* Sun4v generic PC-like machine */
666
    {
667
        .default_cpu_model = "Sun UltraSparc T1",
668
        .machine_id = sun4v_id,
669
        .prom_addr = 0x1fff0000000ULL,
670
        .console_serial_base = 0,
671
    },
672
    /* Sun4v generic Niagara machine */
673
    {
674
        .default_cpu_model = "Sun UltraSparc T1",
675
        .machine_id = niagara_id,
676
        .prom_addr = 0xfff0000000ULL,
677
        .console_serial_base = 0xfff0c2c000ULL,
678
    },
679
};
680

    
681
/* Sun4u hardware initialisation */
682
static void sun4u_init(ram_addr_t RAM_size,
683
                       const char *boot_devices,
684
                       const char *kernel_filename, const char *kernel_cmdline,
685
                       const char *initrd_filename, const char *cpu_model)
686
{
687
    sun4uv_init(RAM_size, boot_devices, kernel_filename,
688
                kernel_cmdline, initrd_filename, cpu_model, &hwdefs[0]);
689
}
690

    
691
/* Sun4v hardware initialisation */
692
static void sun4v_init(ram_addr_t RAM_size,
693
                       const char *boot_devices,
694
                       const char *kernel_filename, const char *kernel_cmdline,
695
                       const char *initrd_filename, const char *cpu_model)
696
{
697
    sun4uv_init(RAM_size, boot_devices, kernel_filename,
698
                kernel_cmdline, initrd_filename, cpu_model, &hwdefs[1]);
699
}
700

    
701
/* Niagara hardware initialisation */
702
static void niagara_init(ram_addr_t RAM_size,
703
                         const char *boot_devices,
704
                         const char *kernel_filename, const char *kernel_cmdline,
705
                         const char *initrd_filename, const char *cpu_model)
706
{
707
    sun4uv_init(RAM_size, boot_devices, kernel_filename,
708
                kernel_cmdline, initrd_filename, cpu_model, &hwdefs[2]);
709
}
710

    
711
static QEMUMachine sun4u_machine = {
712
    .name = "sun4u",
713
    .desc = "Sun4u platform",
714
    .init = sun4u_init,
715
    .max_cpus = 1, // XXX for now
716
    .is_default = 1,
717
};
718

    
719
static QEMUMachine sun4v_machine = {
720
    .name = "sun4v",
721
    .desc = "Sun4v platform",
722
    .init = sun4v_init,
723
    .max_cpus = 1, // XXX for now
724
};
725

    
726
static QEMUMachine niagara_machine = {
727
    .name = "Niagara",
728
    .desc = "Sun4v platform, Niagara",
729
    .init = niagara_init,
730
    .max_cpus = 1, // XXX for now
731
};
732

    
733
static void sun4u_machine_init(void)
734
{
735
    qemu_register_machine(&sun4u_machine);
736
    qemu_register_machine(&sun4v_machine);
737
    qemu_register_machine(&niagara_machine);
738
}
739

    
740
machine_init(sun4u_machine_init);