Statistics
| Branch: | Revision:

root / hw / ppc_chrp.c @ 0d913fdb

History | View | Annotate | Download (11.4 kB)

1 64201201 bellard
/*
2 3cbee15b j_mayer
 * QEMU PowerPC CHRP (currently NewWorld PowerMac) hardware System Emulator
3 5fafdf24 ths
 *
4 47103572 j_mayer
 * Copyright (c) 2004-2007 Fabrice Bellard
5 3cbee15b j_mayer
 * Copyright (c) 2007 Jocelyn Mayer
6 5fafdf24 ths
 *
7 64201201 bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 64201201 bellard
 * of this software and associated documentation files (the "Software"), to deal
9 64201201 bellard
 * in the Software without restriction, including without limitation the rights
10 64201201 bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 64201201 bellard
 * copies of the Software, and to permit persons to whom the Software is
12 64201201 bellard
 * furnished to do so, subject to the following conditions:
13 64201201 bellard
 *
14 64201201 bellard
 * The above copyright notice and this permission notice shall be included in
15 64201201 bellard
 * all copies or substantial portions of the Software.
16 64201201 bellard
 *
17 64201201 bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 64201201 bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 64201201 bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 64201201 bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 64201201 bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 64201201 bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 64201201 bellard
 * THE SOFTWARE.
24 64201201 bellard
 */
25 64201201 bellard
#include "vl.h"
26 3cbee15b j_mayer
#include "ppc_mac.h"
27 267002cd bellard
28 0aa6a4a2 bellard
/* UniN device */
29 0aa6a4a2 bellard
static void unin_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
30 0aa6a4a2 bellard
{
31 0aa6a4a2 bellard
}
32 0aa6a4a2 bellard
33 0aa6a4a2 bellard
static uint32_t unin_readl (void *opaque, target_phys_addr_t addr)
34 0aa6a4a2 bellard
{
35 0aa6a4a2 bellard
    return 0;
36 0aa6a4a2 bellard
}
37 0aa6a4a2 bellard
38 0aa6a4a2 bellard
static CPUWriteMemoryFunc *unin_write[] = {
39 0aa6a4a2 bellard
    &unin_writel,
40 0aa6a4a2 bellard
    &unin_writel,
41 0aa6a4a2 bellard
    &unin_writel,
42 0aa6a4a2 bellard
};
43 0aa6a4a2 bellard
44 0aa6a4a2 bellard
static CPUReadMemoryFunc *unin_read[] = {
45 0aa6a4a2 bellard
    &unin_readl,
46 0aa6a4a2 bellard
    &unin_readl,
47 0aa6a4a2 bellard
    &unin_readl,
48 0aa6a4a2 bellard
};
49 0aa6a4a2 bellard
50 3cbee15b j_mayer
/* PowerPC Mac99 hardware initialisation */
51 6ac0e82d balrog
static void ppc_core99_init (int ram_size, int vga_ram_size,
52 6ac0e82d balrog
                             const char *boot_device, DisplayState *ds,
53 6ac0e82d balrog
                             const char **fd_filename, int snapshot,
54 3cbee15b j_mayer
                             const char *kernel_filename,
55 3cbee15b j_mayer
                             const char *kernel_cmdline,
56 3cbee15b j_mayer
                             const char *initrd_filename,
57 3cbee15b j_mayer
                             const char *cpu_model)
58 64201201 bellard
{
59 aaed909a bellard
    CPUState *env = NULL, *envs[MAX_CPUS];
60 64201201 bellard
    char buf[1024];
61 e9df014c j_mayer
    qemu_irq *pic, **openpic_irqs;
62 aef445bd pbrook
    int unin_memory;
63 d5295253 bellard
    int linux_boot, i;
64 d5295253 bellard
    unsigned long bios_offset, vga_bios_offset;
65 b6b8bd18 bellard
    uint32_t kernel_base, kernel_size, initrd_base, initrd_size;
66 46e50e9d bellard
    PCIBus *pci_bus;
67 3cbee15b j_mayer
    nvram_t nvram;
68 3cbee15b j_mayer
#if 0
69 3cbee15b j_mayer
    MacIONVRAMState *nvr;
70 3cbee15b j_mayer
    int nvram_mem_index;
71 3cbee15b j_mayer
#endif
72 3cbee15b j_mayer
    m48t59_t *m48t59;
73 d5295253 bellard
    int vga_bios_size, bios_size;
74 d537cf6c pbrook
    qemu_irq *dummy_irq;
75 3cbee15b j_mayer
    int pic_mem_index, dbdma_mem_index, cuda_mem_index;
76 3cbee15b j_mayer
    int ide_mem_index[2];
77 28c5af54 j_mayer
    int ppc_boot_device;
78 46e50e9d bellard
79 64201201 bellard
    linux_boot = (kernel_filename != NULL);
80 64201201 bellard
81 c68ea704 bellard
    /* init CPUs */
82 94fc95cd j_mayer
    if (cpu_model == NULL)
83 d12f4c38 j_mayer
        cpu_model = "default";
84 e9df014c j_mayer
    for (i = 0; i < smp_cpus; i++) {
85 aaed909a bellard
        env = cpu_init(cpu_model);
86 aaed909a bellard
        if (!env) {
87 aaed909a bellard
            fprintf(stderr, "Unable to find PowerPC CPU definition\n");
88 aaed909a bellard
            exit(1);
89 aaed909a bellard
        }
90 e9df014c j_mayer
        /* Set time-base frequency to 100 Mhz */
91 e9df014c j_mayer
        cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
92 3cbee15b j_mayer
#if 0
93 e9df014c j_mayer
        env->osi_call = vga_osi_call;
94 3cbee15b j_mayer
#endif
95 fe33cc71 j_mayer
        qemu_register_reset(&cpu_ppc_reset, env);
96 fe33cc71 j_mayer
        register_savevm("cpu", 0, 3, cpu_save, cpu_load, env);
97 e9df014c j_mayer
        envs[i] = env;
98 e9df014c j_mayer
    }
99 4c823cff j_mayer
    if (env->nip < 0xFFF80000) {
100 4c823cff j_mayer
        /* Special test for PowerPC 601:
101 4c823cff j_mayer
         * the boot vector is at 0xFFF00100, then we need a 1MB BIOS.
102 4c823cff j_mayer
         * But the NVRAM is located at 0xFFF04000...
103 4c823cff j_mayer
         */
104 4c823cff j_mayer
        cpu_abort(env, "Mac99 hardware can not handle 1 MB BIOS\n");
105 4c823cff j_mayer
    }
106 c68ea704 bellard
107 64201201 bellard
    /* allocate RAM */
108 64201201 bellard
    cpu_register_physical_memory(0, ram_size, IO_MEM_RAM);
109 64201201 bellard
110 64201201 bellard
    /* allocate and load BIOS */
111 64201201 bellard
    bios_offset = ram_size + vga_ram_size;
112 1192dad8 j_mayer
    if (bios_name == NULL)
113 1192dad8 j_mayer
        bios_name = BIOS_FILENAME;
114 1192dad8 j_mayer
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name);
115 d5295253 bellard
    bios_size = load_image(buf, phys_ram_base + bios_offset);
116 d5295253 bellard
    if (bios_size < 0 || bios_size > BIOS_SIZE) {
117 4a057712 j_mayer
        cpu_abort(env, "qemu: could not load PowerPC bios '%s'\n", buf);
118 64201201 bellard
        exit(1);
119 64201201 bellard
    }
120 d5295253 bellard
    bios_size = (bios_size + 0xfff) & ~0xfff;
121 4c823cff j_mayer
    if (bios_size > 0x00080000) {
122 4c823cff j_mayer
        /* As the NVRAM is located at 0xFFF04000, we cannot use 1 MB BIOSes */
123 4c823cff j_mayer
        cpu_abort(env, "Mac99 hardware can not handle 1 MB BIOS\n");
124 4c823cff j_mayer
    }
125 4a057712 j_mayer
    cpu_register_physical_memory((uint32_t)(-bios_size),
126 d5295253 bellard
                                 bios_size, bios_offset | IO_MEM_ROM);
127 3b46e624 ths
128 d5295253 bellard
    /* allocate and load VGA BIOS */
129 d5295253 bellard
    vga_bios_offset = bios_offset + bios_size;
130 d5295253 bellard
    snprintf(buf, sizeof(buf), "%s/%s", bios_dir, VGABIOS_FILENAME);
131 d5295253 bellard
    vga_bios_size = load_image(buf, phys_ram_base + vga_bios_offset + 8);
132 d5295253 bellard
    if (vga_bios_size < 0) {
133 d5295253 bellard
        /* if no bios is present, we can still work */
134 d5295253 bellard
        fprintf(stderr, "qemu: warning: could not load VGA bios '%s'\n", buf);
135 d5295253 bellard
        vga_bios_size = 0;
136 d5295253 bellard
    } else {
137 d5295253 bellard
        /* set a specific header (XXX: find real Apple format for NDRV
138 d5295253 bellard
           drivers) */
139 d5295253 bellard
        phys_ram_base[vga_bios_offset] = 'N';
140 d5295253 bellard
        phys_ram_base[vga_bios_offset + 1] = 'D';
141 d5295253 bellard
        phys_ram_base[vga_bios_offset + 2] = 'R';
142 d5295253 bellard
        phys_ram_base[vga_bios_offset + 3] = 'V';
143 5fafdf24 ths
        cpu_to_be32w((uint32_t *)(phys_ram_base + vga_bios_offset + 4),
144 d5295253 bellard
                     vga_bios_size);
145 d5295253 bellard
        vga_bios_size += 8;
146 d5295253 bellard
    }
147 d5295253 bellard
    vga_bios_size = (vga_bios_size + 0xfff) & ~0xfff;
148 3b46e624 ths
149 b6b8bd18 bellard
    if (linux_boot) {
150 b6b8bd18 bellard
        kernel_base = KERNEL_LOAD_ADDR;
151 b6b8bd18 bellard
        /* now we can load the kernel */
152 b6b8bd18 bellard
        kernel_size = load_image(kernel_filename, phys_ram_base + kernel_base);
153 b6b8bd18 bellard
        if (kernel_size < 0) {
154 4a057712 j_mayer
            cpu_abort(env, "qemu: could not load kernel '%s'\n",
155 4a057712 j_mayer
                      kernel_filename);
156 b6b8bd18 bellard
            exit(1);
157 b6b8bd18 bellard
        }
158 b6b8bd18 bellard
        /* load initrd */
159 b6b8bd18 bellard
        if (initrd_filename) {
160 b6b8bd18 bellard
            initrd_base = INITRD_LOAD_ADDR;
161 b6b8bd18 bellard
            initrd_size = load_image(initrd_filename,
162 b6b8bd18 bellard
                                     phys_ram_base + initrd_base);
163 b6b8bd18 bellard
            if (initrd_size < 0) {
164 4a057712 j_mayer
                cpu_abort(env, "qemu: could not load initial ram disk '%s'\n",
165 4a057712 j_mayer
                          initrd_filename);
166 b6b8bd18 bellard
                exit(1);
167 b6b8bd18 bellard
            }
168 b6b8bd18 bellard
        } else {
169 b6b8bd18 bellard
            initrd_base = 0;
170 b6b8bd18 bellard
            initrd_size = 0;
171 b6b8bd18 bellard
        }
172 6ac0e82d balrog
        ppc_boot_device = 'm';
173 b6b8bd18 bellard
    } else {
174 b6b8bd18 bellard
        kernel_base = 0;
175 b6b8bd18 bellard
        kernel_size = 0;
176 b6b8bd18 bellard
        initrd_base = 0;
177 b6b8bd18 bellard
        initrd_size = 0;
178 28c5af54 j_mayer
        ppc_boot_device = '\0';
179 28c5af54 j_mayer
        /* We consider that NewWorld PowerMac never have any floppy drive
180 28c5af54 j_mayer
         * For now, OHW cannot boot from the network.
181 28c5af54 j_mayer
         */
182 0d913fdb j_mayer
        for (i = 0; boot_device[i] != '\0'; i++) {
183 0d913fdb j_mayer
            if (boot_device[i] >= 'c' && boot_device[i] <= 'f') {
184 0d913fdb j_mayer
                ppc_boot_device = boot_device[i];
185 28c5af54 j_mayer
                break;
186 0d913fdb j_mayer
            }
187 28c5af54 j_mayer
        }
188 28c5af54 j_mayer
        if (ppc_boot_device == '\0') {
189 28c5af54 j_mayer
            fprintf(stderr, "No valid boot device for Mac99 machine\n");
190 28c5af54 j_mayer
            exit(1);
191 28c5af54 j_mayer
        }
192 b6b8bd18 bellard
    }
193 0aa6a4a2 bellard
194 3cbee15b j_mayer
    isa_mem_base = 0x80000000;
195 aef445bd pbrook
196 3cbee15b j_mayer
    /* Register 8 MB of ISA IO space */
197 3cbee15b j_mayer
    isa_mmio_init(0xf2000000, 0x00800000);
198 3b46e624 ths
199 3cbee15b j_mayer
    /* UniN init */
200 3cbee15b j_mayer
    unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL);
201 3cbee15b j_mayer
    cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory);
202 47103572 j_mayer
203 3cbee15b j_mayer
    openpic_irqs = qemu_mallocz(smp_cpus * sizeof(qemu_irq *));
204 3cbee15b j_mayer
    openpic_irqs[0] =
205 3cbee15b j_mayer
        qemu_mallocz(smp_cpus * sizeof(qemu_irq) * OPENPIC_OUTPUT_NB);
206 3cbee15b j_mayer
    for (i = 0; i < smp_cpus; i++) {
207 3cbee15b j_mayer
        /* Mac99 IRQ connection between OpenPIC outputs pins
208 3cbee15b j_mayer
         * and PowerPC input pins
209 3cbee15b j_mayer
         */
210 3cbee15b j_mayer
        switch (PPC_INPUT(env)) {
211 3cbee15b j_mayer
        case PPC_FLAGS_INPUT_6xx:
212 3cbee15b j_mayer
            openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
213 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_INT] =
214 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
215 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_CINT] =
216 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_INT];
217 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_MCK] =
218 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_MCP];
219 3cbee15b j_mayer
            /* Not connected ? */
220 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
221 3cbee15b j_mayer
            /* Check this */
222 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_RESET] =
223 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC6xx_INPUT_HRESET];
224 3cbee15b j_mayer
            break;
225 00af685f j_mayer
#if defined(TARGET_PPC64)
226 3cbee15b j_mayer
        case PPC_FLAGS_INPUT_970:
227 3cbee15b j_mayer
            openpic_irqs[i] = openpic_irqs[0] + (i * OPENPIC_OUTPUT_NB);
228 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_INT] =
229 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
230 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_CINT] =
231 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_INT];
232 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_MCK] =
233 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_MCP];
234 3cbee15b j_mayer
            /* Not connected ? */
235 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_DEBUG] = NULL;
236 3cbee15b j_mayer
            /* Check this */
237 3cbee15b j_mayer
            openpic_irqs[i][OPENPIC_OUTPUT_RESET] =
238 3cbee15b j_mayer
                ((qemu_irq *)env->irq_inputs)[PPC970_INPUT_HRESET];
239 3cbee15b j_mayer
            break;
240 00af685f j_mayer
#endif /* defined(TARGET_PPC64) */
241 3cbee15b j_mayer
        default:
242 3cbee15b j_mayer
            cpu_abort(env, "Bus model not supported on mac99 machine\n");
243 3cbee15b j_mayer
            exit(1);
244 0aa6a4a2 bellard
        }
245 3cbee15b j_mayer
    }
246 3cbee15b j_mayer
    pic = openpic_init(NULL, &pic_mem_index, smp_cpus, openpic_irqs, NULL);
247 3cbee15b j_mayer
    pci_bus = pci_pmac_init(pic);
248 3cbee15b j_mayer
    /* init basic PC hardware */
249 3cbee15b j_mayer
    pci_vga_init(pci_bus, ds, phys_ram_base + ram_size,
250 3cbee15b j_mayer
                 ram_size, vga_ram_size,
251 3cbee15b j_mayer
                 vga_bios_offset, vga_bios_size);
252 3cbee15b j_mayer
    
253 3cbee15b j_mayer
    /* XXX: suppress that */
254 3cbee15b j_mayer
    dummy_irq = i8259_init(NULL);
255 3cbee15b j_mayer
256 3cbee15b j_mayer
    /* XXX: use Mac Serial port */
257 3cbee15b j_mayer
    serial_init(0x3f8, dummy_irq[4], serial_hds[0]);
258 3cbee15b j_mayer
    for(i = 0; i < nb_nics; i++) {
259 3cbee15b j_mayer
        if (!nd_table[i].model)
260 3cbee15b j_mayer
            nd_table[i].model = "ne2k_pci";
261 3cbee15b j_mayer
        pci_nic_init(pci_bus, &nd_table[i], -1);
262 3cbee15b j_mayer
    }
263 0aa6a4a2 bellard
#if 1
264 3cbee15b j_mayer
    ide_mem_index[0] = pmac_ide_init(&bs_table[0], pic[0x13]);
265 3cbee15b j_mayer
    ide_mem_index[1] = pmac_ide_init(&bs_table[2], pic[0x14]);
266 0aa6a4a2 bellard
#else
267 3cbee15b j_mayer
    pci_cmd646_ide_init(pci_bus, &bs_table[0], 0);
268 0aa6a4a2 bellard
#endif
269 3cbee15b j_mayer
    /* cuda also initialize ADB */
270 3cbee15b j_mayer
    cuda_init(&cuda_mem_index, pic[0x19]);
271 3cbee15b j_mayer
    
272 3cbee15b j_mayer
    adb_kbd_init(&adb_bus);
273 3cbee15b j_mayer
    adb_mouse_init(&adb_bus);
274 3b46e624 ths
275 3cbee15b j_mayer
    dbdma_init(&dbdma_mem_index);
276 3b46e624 ths
277 3cbee15b j_mayer
    macio_init(pci_bus, 0x0022, 0, pic_mem_index, dbdma_mem_index,
278 74e91155 j_mayer
               cuda_mem_index, NULL, 2, ide_mem_index);
279 0d92ed30 pbrook
280 0d92ed30 pbrook
    if (usb_enabled) {
281 e24ad6f1 pbrook
        usb_ohci_init_pci(pci_bus, 3, -1);
282 0d92ed30 pbrook
    }
283 0d92ed30 pbrook
284 b6b8bd18 bellard
    if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
285 b6b8bd18 bellard
        graphic_depth = 15;
286 3cbee15b j_mayer
#if 0 /* XXX: this is ugly but needed for now, or OHW won't boot */
287 3cbee15b j_mayer
    /* The NewWorld NVRAM is not located in the MacIO device */
288 74e91155 j_mayer
    nvr = macio_nvram_init(&nvram_mem_index, 0x2000);
289 3cbee15b j_mayer
    pmac_format_nvram_partition(nvr, 0x2000);
290 74e91155 j_mayer
    macio_nvram_map(nvr, 0xFFF04000);
291 3cbee15b j_mayer
    nvram.opaque = nvr;
292 3cbee15b j_mayer
    nvram.read_fn = &macio_nvram_read;
293 3cbee15b j_mayer
    nvram.write_fn = &macio_nvram_write;
294 3cbee15b j_mayer
#else
295 3cbee15b j_mayer
    m48t59 = m48t59_init(dummy_irq[8], 0xFFF04000, 0x0074, NVRAM_SIZE, 59);
296 3cbee15b j_mayer
    nvram.opaque = m48t59;
297 3cbee15b j_mayer
    nvram.read_fn = &m48t59_read;
298 3cbee15b j_mayer
    nvram.write_fn = &m48t59_write;
299 3cbee15b j_mayer
#endif
300 6ac0e82d balrog
    PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "MAC99", ram_size,
301 6ac0e82d balrog
                         ppc_boot_device, kernel_base, kernel_size,
302 b6b8bd18 bellard
                         kernel_cmdline,
303 b6b8bd18 bellard
                         initrd_base, initrd_size,
304 64201201 bellard
                         /* XXX: need an option to load a NVRAM image */
305 b6b8bd18 bellard
                         0,
306 b6b8bd18 bellard
                         graphic_width, graphic_height, graphic_depth);
307 b6b8bd18 bellard
    /* No PCI init: the BIOS will do it */
308 0aa6a4a2 bellard
309 0aa6a4a2 bellard
    /* Special port to get debug messages from Open-Firmware */
310 0aa6a4a2 bellard
    register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
311 3cbee15b j_mayer
 }
312 0aa6a4a2 bellard
313 0aa6a4a2 bellard
QEMUMachine core99_machine = {
314 0289b2c1 bellard
    "mac99",
315 0289b2c1 bellard
    "Mac99 based PowerMAC",
316 0aa6a4a2 bellard
    ppc_core99_init,
317 0aa6a4a2 bellard
};