~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/ppc_oldworld.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2009-03-07 06:20:34 UTC
  • mfrom: (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090307062034-i3pead4mw653v2el
Tags: 0.10.0-1
[ Aurelien Jarno ]
* New upstream release:
  - Fix fr-be keyboard mapping (closes: bug#514462).
  - Fix stat64 structure on ppc-linux-user (closes: bug#470231).
  - Add a chroot option (closes: bug#415996).
  - Add evdev support (closes: bug#513210).
  - Fix loop on symlinks in user mode (closes: bug#297572).
  - Bump depends on openbios-sparc.
  - Depends on openbios-ppc.
  - Update 12_signal_powerpc_support.patch.
  - Update 21_net_soopts.patch.
  - Drop 44_socklen_t_check.patch (merged upstream).
  - Drop 49_null_check.patch (merged upstream).
  - Update 64_ppc_asm_constraints.patch.
  - Drop security/CVE-2008-0928-fedora.patch (merged upstream).
  - Drop security/CVE-2007-5730.patch (merged upstream).
* patches/80_stable-branch.patch: add patches from stable branch:
  - Fix race condition between signal handler/execution loop (closes:
    bug#474386, bug#501731).
* debian/copyright: update.
* Compile and install .dtb files:
  - debian/control: build-depends on device-tree-compiler.
  - debian/patches/81_compile_dtb.patch: new patch from upstream.
  - debian/rules: compile and install bamboo.dtb and mpc8544.dtb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * QEMU OldWorld PowerMac (currently ~G3 B&W) hardware System Emulator
 
2
 * QEMU OldWorld PowerMac (currently ~G3 Beige) hardware System Emulator
3
3
 *
4
4
 * Copyright (c) 2004-2007 Fabrice Bellard
5
5
 * Copyright (c) 2007 Jocelyn Mayer
25
25
#include "hw.h"
26
26
#include "ppc.h"
27
27
#include "ppc_mac.h"
 
28
#include "mac_dbdma.h"
28
29
#include "nvram.h"
29
30
#include "pc.h"
30
31
#include "sysemu.h"
32
33
#include "isa.h"
33
34
#include "pci.h"
34
35
#include "boards.h"
 
36
#include "fw_cfg.h"
 
37
#include "escc.h"
35
38
 
36
39
#define MAX_IDE_BUS 2
 
40
#define VGA_BIOS_SIZE 65536
 
41
#define CFG_ADDR 0xf0000510
37
42
 
38
43
/* temporary frame buffer OSI calls for the video.x driver. The right
39
44
   solution is to modify the driver to use VGA PCI I/Os */
103
108
    return 1; /* osi_call handled */
104
109
}
105
110
 
106
 
static void ppc_heathrow_init (int ram_size, int vga_ram_size,
107
 
                               const char *boot_device, DisplayState *ds,
 
111
static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size,
 
112
                               const char *boot_device,
108
113
                               const char *kernel_filename,
109
114
                               const char *kernel_cmdline,
110
115
                               const char *initrd_filename,
116
121
    nvram_t nvram;
117
122
    m48t59_t *m48t59;
118
123
    int linux_boot, i;
119
 
    unsigned long bios_offset, vga_bios_offset;
120
 
    uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
 
124
    ram_addr_t ram_offset, vga_ram_offset, bios_offset, vga_bios_offset;
 
125
    uint32_t kernel_base, initrd_base;
 
126
    int32_t kernel_size, initrd_size;
121
127
    PCIBus *pci_bus;
122
128
    MacIONVRAMState *nvr;
123
129
    int vga_bios_size, bios_size;
124
 
    qemu_irq *dummy_irq;
125
130
    int pic_mem_index, nvram_mem_index, dbdma_mem_index, cuda_mem_index;
126
 
    int ide_mem_index[2];
 
131
    int escc_mem_index, ide_mem_index[2];
127
132
    int ppc_boot_device;
128
133
    BlockDriverState *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
129
134
    int index;
 
135
    void *fw_cfg;
 
136
    void *dbdma;
130
137
 
131
138
    linux_boot = (kernel_filename != NULL);
132
139
 
133
140
    /* init CPUs */
134
141
    if (cpu_model == NULL)
135
 
        cpu_model = "default";
 
142
        cpu_model = "G3";
136
143
    for (i = 0; i < smp_cpus; i++) {
137
144
        env = cpu_init(cpu_model);
138
145
        if (!env) {
139
146
            fprintf(stderr, "Unable to find PowerPC CPU definition\n");
140
147
            exit(1);
141
148
        }
142
 
        /* Set time-base frequency to 100 Mhz */
143
 
        cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
 
149
        /* Set time-base frequency to 16.6 Mhz */
 
150
        cpu_ppc_tb_init(env,  16600000UL);
144
151
        env->osi_call = vga_osi_call;
145
152
        qemu_register_reset(&cpu_ppc_reset, env);
146
 
        register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
147
153
        envs[i] = env;
148
154
    }
149
 
    if (env->nip < 0xFFF80000) {
150
 
        /* Special test for PowerPC 601:
151
 
         * the boot vector is at 0xFFF00100, then we need a 1MB BIOS.
152
 
         * But the NVRAM is located at 0xFFF04000...
153
 
         */
154
 
        cpu_abort(env, "G3BW Mac hardware can not handle 1 MB BIOS\n");
155
 
    }
156
155
 
157
156
    /* allocate RAM */
158
 
    cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
 
157
    if (ram_size > (2047 << 20)) {
 
158
        fprintf(stderr,
 
159
                "qemu: Too much memory for this machine: %d MB, maximum 2047 MB\n",
 
160
                ((unsigned int)ram_size / (1 << 20)));
 
161
        exit(1);
 
162
    }
 
163
 
 
164
    ram_offset = qemu_ram_alloc(ram_size);
 
165
    cpu_register_physical_memory(0, ram_size, ram_offset);
 
166
 
 
167
    /* allocate VGA RAM */
 
168
    vga_ram_offset = qemu_ram_alloc(vga_ram_size);
159
169
 
160
170
    /* allocate and load BIOS */
161
 
    bios_offset = ram_size + vga_ram_size;
 
171
    bios_offset = qemu_ram_alloc(BIOS_SIZE);
162
172
    if (bios_name == NULL)
163
 
        bios_name = BIOS_FILENAME;
 
173
        bios_name = PROM_FILENAME;
164
174
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
165
 
    bios_size = load_image(buf, phys_ram_base + bios_offset);
 
175
    cpu_register_physical_memory(PROM_ADDR, BIOS_SIZE, bios_offset | IO_MEM_ROM);
 
176
 
 
177
    /* Load OpenBIOS (ELF) */
 
178
    bios_size = load_elf(buf, 0, NULL, NULL, NULL);
166
179
    if (bios_size < 0 || bios_size > BIOS_SIZE) {
167
180
        cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf);
168
181
        exit(1);
169
182
    }
170
 
    bios_size = (bios_size + 0xfff) & ~0xfff;
171
 
    if (bios_size > 0x00080000) {
172
 
        /* As the NVRAM is located at 0xFFF04000, we cannot use 1 MB BIOSes */
173
 
        cpu_abort(env, "G3BW Mac hardware can not handle 1 MB BIOS\n");
174
 
    }
175
 
    cpu_register_physical_memory((uint32_t)(-bios_size),
176
 
                                 bios_size, bios_offset | IO_MEM_ROM);
177
183
 
178
184
    /* allocate and load VGA BIOS */
179
 
    vga_bios_offset = bios_offset + bios_size;
 
185
    vga_bios_offset = qemu_ram_alloc(VGA_BIOS_SIZE);
180
186
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
181
187
    vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
182
188
    if (vga_bios_size < 0) {
194
200
                     vga_bios_size);
195
201
        vga_bios_size += 8;
196
202
    }
197
 
    vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff;
198
203
 
199
204
    if (linux_boot) {
 
205
        uint64_t lowaddr = 0;
200
206
        kernel_base = KERNEL_LOAD_ADDR;
201
 
        /* now we can load the kernel */
202
 
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
 
207
        /* Now we can load the kernel. The first step tries to load the kernel
 
208
           supposing PhysAddr = 0x00000000. If that was wrong the kernel is
 
209
           loaded again, the new PhysAddr being computed from lowaddr. */
 
210
        kernel_size = load_elf(kernel_filename, kernel_base, NULL, &lowaddr, NULL);
 
211
        if (kernel_size > 0 && lowaddr != KERNEL_LOAD_ADDR) {
 
212
            kernel_size = load_elf(kernel_filename, (2 * kernel_base) - lowaddr,
 
213
                                   NULL, 0, NULL);
 
214
        }
 
215
        if (kernel_size < 0)
 
216
            kernel_size = load_aout(kernel_filename, kernel_base,
 
217
                                    ram_size - kernel_base);
 
218
        if (kernel_size < 0)
 
219
            kernel_size = load_image_targphys(kernel_filename,
 
220
                                              kernel_base,
 
221
                                              ram_size - kernel_base);
203
222
        if (kernel_size < 0) {
204
223
            cpu_abort(env, "qemu: could not load kernel '%s'\n",
205
224
                      kernel_filename);
244
263
#endif
245
264
        }
246
265
        if (ppc_boot_device == '\0') {
247
 
            fprintf(stderr, "No valid boot device for Mac99 machine\n");
 
266
            fprintf(stderr, "No valid boot device for G3 Beige machine\n");
248
267
            exit(1);
249
268
        }
250
269
    }
279
298
    }
280
299
    pic = heathrow_pic_init(&pic_mem_index, 1, heathrow_irqs);
281
300
    pci_bus = pci_grackle_init(0xfec00000, pic);
282
 
    pci_vga_init(pci_bus, ds, phys_ram_base + ram_size,
283
 
                 ram_size, vga_ram_size,
 
301
    pci_vga_init(pci_bus, phys_ram_base + vga_ram_offset,
 
302
                 vga_ram_offset, vga_ram_size,
284
303
                 vga_bios_offset, vga_bios_size);
285
304
 
286
 
    /* XXX: suppress that */
287
 
    dummy_irq = i8259_init(NULL);
288
 
 
289
 
    /* XXX: use Mac Serial port */
290
 
    serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
291
 
 
292
 
    for(i = 0; i < nb_nics; i++) {
293
 
        if (!nd_table[i].model)
294
 
            nd_table[i].model = "ne2k_pci";
295
 
        pci_nic_init(pci_bus, &nd_table[i], -1);
296
 
    }
 
305
    escc_mem_index = escc_init(0x80013000, pic[0x0f], pic[0x10], serial_hds[0],
 
306
                               serial_hds[1], ESCC_CLOCK, 4);
 
307
 
 
308
    for(i = 0; i < nb_nics; i++)
 
309
        pci_nic_init(pci_bus, &nd_table[i], -1, "ne2k_pci");
297
310
 
298
311
    /* First IDE channel is a CMD646 on the PCI bus */
299
312
 
325
338
        hd[1] = NULL;
326
339
    else
327
340
        hd[1] =  drives_table[index].bdrv;
 
341
 
 
342
    dbdma = DBDMA_init(&dbdma_mem_index);
 
343
 
328
344
    ide_mem_index[0] = -1;
329
 
    ide_mem_index[1] = pmac_ide_init(hd, pic[0x0D]);
 
345
    ide_mem_index[1] = pmac_ide_init(hd, pic[0x0D], dbdma, 0x16, pic[0x02]);
330
346
 
331
347
    /* cuda also initialize ADB */
332
348
    cuda_init(&cuda_mem_index, pic[0x12]);
334
350
    adb_kbd_init(&adb_bus);
335
351
    adb_mouse_init(&adb_bus);
336
352
 
337
 
    nvr = macio_nvram_init(&nvram_mem_index, 0x2000);
 
353
    nvr = macio_nvram_init(&nvram_mem_index, 0x2000, 4);
338
354
    pmac_format_nvram_partition(nvr, 0x2000);
339
355
 
340
 
    dbdma_init(&dbdma_mem_index);
341
 
 
342
 
    macio_init(pci_bus, 0x0017, 1, pic_mem_index, dbdma_mem_index,
343
 
               cuda_mem_index, nvr, 2, ide_mem_index);
 
356
    macio_init(pci_bus, PCI_DEVICE_ID_APPLE_343S1201, 1, pic_mem_index,
 
357
               dbdma_mem_index, cuda_mem_index, nvr, 2, ide_mem_index,
 
358
               escc_mem_index);
344
359
 
345
360
    if (usb_enabled) {
346
361
        usb_ohci_init_pci(pci_bus, 3, -1);
349
364
    if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
350
365
        graphic_depth = 15;
351
366
 
352
 
    m48t59 = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
 
367
    m48t59 = m48t59_init(0, 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
353
368
    nvram.opaque = m48t59;
354
369
    nvram.read_fn = &m48t59_read;
355
370
    nvram.write_fn = &m48t59_write;
362
377
                         graphic_width, graphic_height, graphic_depth);
363
378
    /* No PCI init: the BIOS will do it */
364
379
 
365
 
    /* Special port to get debug messages from Open-Firmware */
366
 
    register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
 
380
    fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
 
381
    fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
 
382
    fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
 
383
    fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, ARCH_HEATHROW);
367
384
}
368
385
 
369
386
QEMUMachine heathrow_machine = {
370
 
    "g3bw",
371
 
    "Heathrow based PowerMAC",
372
 
    ppc_heathrow_init,
 
387
    .name = "g3beige",
 
388
    .desc = "Heathrow based PowerMAC",
 
389
    .init = ppc_heathrow_init,
 
390
    .ram_require = BIOS_SIZE + VGA_BIOS_SIZE + VGA_RAM_SIZE,
 
391
    .max_cpus = MAX_CPUS,
373
392
};