]> git.proxmox.com Git - mirror_qemu.git/blame - hw/ppc_prep.c
create struct for machine initialization arguments
[mirror_qemu.git] / hw / ppc_prep.c
CommitLineData
9a64fbe4 1/*
a541f297 2 * QEMU PPC PREP hardware System Emulator
5fafdf24 3 *
47103572 4 * Copyright (c) 2003-2007 Jocelyn Mayer
5fafdf24 5 *
a541f297
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.
9a64fbe4 23 */
87ecb68b
PB
24#include "hw.h"
25#include "nvram.h"
26#include "pc.h"
27#include "fdc.h"
28#include "net.h"
29#include "sysemu.h"
30#include "isa.h"
31#include "pci.h"
8ca8c7bc 32#include "pci_host.h"
87ecb68b
PB
33#include "ppc.h"
34#include "boards.h"
3b3fb322 35#include "qemu-log.h"
ec82026c 36#include "ide.h"
ca20cf32 37#include "loader.h"
1d914fa0 38#include "mc146818rtc.h"
2446333c 39#include "blockdev.h"
9357b144 40#include "arch_init.h"
1e39101c 41#include "exec-memory.h"
9fddaa0c 42
9a64fbe4 43//#define HARD_DEBUG_PPC_IO
a541f297 44//#define DEBUG_PPC_IO
9a64fbe4 45
fe33cc71
JM
46/* SMP is not enabled, for now */
47#define MAX_CPUS 1
48
e4bcb14c
TS
49#define MAX_IDE_BUS 2
50
bba831e8 51#define BIOS_SIZE (1024 * 1024)
b6b8bd18
FB
52#define BIOS_FILENAME "ppc_rom.bin"
53#define KERNEL_LOAD_ADDR 0x01000000
54#define INITRD_LOAD_ADDR 0x01800000
64201201 55
9a64fbe4
FB
56#if defined (HARD_DEBUG_PPC_IO) && !defined (DEBUG_PPC_IO)
57#define DEBUG_PPC_IO
58#endif
59
60#if defined (HARD_DEBUG_PPC_IO)
001faf32 61#define PPC_IO_DPRINTF(fmt, ...) \
9a64fbe4 62do { \
8fec2b8c 63 if (qemu_loglevel_mask(CPU_LOG_IOPORT)) { \
001faf32 64 qemu_log("%s: " fmt, __func__ , ## __VA_ARGS__); \
9a64fbe4 65 } else { \
001faf32 66 printf("%s : " fmt, __func__ , ## __VA_ARGS__); \
9a64fbe4
FB
67 } \
68} while (0)
69#elif defined (DEBUG_PPC_IO)
0bf9e31a
BS
70#define PPC_IO_DPRINTF(fmt, ...) \
71qemu_log_mask(CPU_LOG_IOPORT, fmt, ## __VA_ARGS__)
9a64fbe4 72#else
001faf32 73#define PPC_IO_DPRINTF(fmt, ...) do { } while (0)
9a64fbe4
FB
74#endif
75
64201201 76/* Constants for devices init */
a541f297
FB
77static const int ide_iobase[2] = { 0x1f0, 0x170 };
78static const int ide_iobase2[2] = { 0x3f6, 0x376 };
79static const int ide_irq[2] = { 13, 13 };
80
81#define NE2000_NB_MAX 6
82
83static uint32_t ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
84static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
9a64fbe4 85
64201201 86/* ISA IO ports bridge */
9a64fbe4
FB
87#define PPC_IO_BASE 0x80000000
88
64201201
FB
89/* PowerPC control and status registers */
90#if 0 // Not used
91static struct {
92 /* IDs */
93 uint32_t veni_devi;
94 uint32_t revi;
95 /* Control and status */
96 uint32_t gcsr;
97 uint32_t xcfr;
98 uint32_t ct32;
99 uint32_t mcsr;
100 /* General purpose registers */
101 uint32_t gprg[6];
102 /* Exceptions */
103 uint32_t feen;
104 uint32_t fest;
105 uint32_t fema;
106 uint32_t fecl;
107 uint32_t eeen;
108 uint32_t eest;
109 uint32_t eecl;
110 uint32_t eeint;
111 uint32_t eemck0;
112 uint32_t eemck1;
113 /* Error diagnostic */
114} XCSR;
64201201 115
36081602 116static void PPC_XCSR_writeb (void *opaque,
c227f099 117 target_phys_addr_t addr, uint32_t value)
64201201 118{
90e189ec
BS
119 printf("%s: 0x" TARGET_FMT_plx " => 0x%08" PRIx32 "\n", __func__, addr,
120 value);
64201201
FB
121}
122
36081602 123static void PPC_XCSR_writew (void *opaque,
c227f099 124 target_phys_addr_t addr, uint32_t value)
9a64fbe4 125{
90e189ec
BS
126 printf("%s: 0x" TARGET_FMT_plx " => 0x%08" PRIx32 "\n", __func__, addr,
127 value);
9a64fbe4
FB
128}
129
36081602 130static void PPC_XCSR_writel (void *opaque,
c227f099 131 target_phys_addr_t addr, uint32_t value)
9a64fbe4 132{
90e189ec
BS
133 printf("%s: 0x" TARGET_FMT_plx " => 0x%08" PRIx32 "\n", __func__, addr,
134 value);
9a64fbe4
FB
135}
136
c227f099 137static uint32_t PPC_XCSR_readb (void *opaque, target_phys_addr_t addr)
64201201
FB
138{
139 uint32_t retval = 0;
9a64fbe4 140
90e189ec
BS
141 printf("%s: 0x" TARGET_FMT_plx " <= %08" PRIx32 "\n", __func__, addr,
142 retval);
9a64fbe4 143
64201201
FB
144 return retval;
145}
146
c227f099 147static uint32_t PPC_XCSR_readw (void *opaque, target_phys_addr_t addr)
9a64fbe4 148{
64201201
FB
149 uint32_t retval = 0;
150
90e189ec
BS
151 printf("%s: 0x" TARGET_FMT_plx " <= %08" PRIx32 "\n", __func__, addr,
152 retval);
64201201
FB
153
154 return retval;
9a64fbe4
FB
155}
156
c227f099 157static uint32_t PPC_XCSR_readl (void *opaque, target_phys_addr_t addr)
9a64fbe4
FB
158{
159 uint32_t retval = 0;
160
90e189ec
BS
161 printf("%s: 0x" TARGET_FMT_plx " <= %08" PRIx32 "\n", __func__, addr,
162 retval);
9a64fbe4
FB
163
164 return retval;
165}
166
0c90c52f
AK
167static const MemoryRegionOps PPC_XCSR_ops = {
168 .old_mmio = {
169 .read = { PPC_XCSR_readb, PPC_XCSR_readw, PPC_XCSR_readl, },
170 .write = { PPC_XCSR_writeb, PPC_XCSR_writew, PPC_XCSR_writel, },
171 },
172 .endianness = DEVICE_LITTLE_ENDIAN,
9a64fbe4
FB
173};
174
b6b8bd18 175#endif
9a64fbe4 176
64201201 177/* Fake super-io ports for PREP platform (Intel 82378ZB) */
c227f099 178typedef struct sysctrl_t {
c4781a51 179 qemu_irq reset_irq;
43a34704 180 M48t59State *nvram;
64201201
FB
181 uint8_t state;
182 uint8_t syscontrol;
183 uint8_t fake_io[2];
da9b266b 184 int contiguous_map;
fb3444b8 185 int endian;
c227f099 186} sysctrl_t;
9a64fbe4 187
64201201
FB
188enum {
189 STATE_HARDFILE = 0x01,
9a64fbe4 190};
9a64fbe4 191
c227f099 192static sysctrl_t *sysctrl;
9a64fbe4 193
a541f297 194static void PREP_io_write (void *opaque, uint32_t addr, uint32_t val)
9a64fbe4 195{
c227f099 196 sysctrl_t *sysctrl = opaque;
64201201 197
aae9366a
JM
198 PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
199 val);
64201201 200 sysctrl->fake_io[addr - 0x0398] = val;
9a64fbe4
FB
201}
202
a541f297 203static uint32_t PREP_io_read (void *opaque, uint32_t addr)
9a64fbe4 204{
c227f099 205 sysctrl_t *sysctrl = opaque;
9a64fbe4 206
aae9366a 207 PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n", addr - PPC_IO_BASE,
64201201
FB
208 sysctrl->fake_io[addr - 0x0398]);
209 return sysctrl->fake_io[addr - 0x0398];
210}
9a64fbe4 211
a541f297 212static void PREP_io_800_writeb (void *opaque, uint32_t addr, uint32_t val)
9a64fbe4 213{
c227f099 214 sysctrl_t *sysctrl = opaque;
64201201 215
aae9366a
JM
216 PPC_IO_DPRINTF("0x%08" PRIx32 " => 0x%02" PRIx32 "\n",
217 addr - PPC_IO_BASE, val);
9a64fbe4
FB
218 switch (addr) {
219 case 0x0092:
220 /* Special port 92 */
221 /* Check soft reset asked */
64201201 222 if (val & 0x01) {
c4781a51
JM
223 qemu_irq_raise(sysctrl->reset_irq);
224 } else {
225 qemu_irq_lower(sysctrl->reset_irq);
9a64fbe4
FB
226 }
227 /* Check LE mode */
64201201 228 if (val & 0x02) {
fb3444b8
FB
229 sysctrl->endian = 1;
230 } else {
231 sysctrl->endian = 0;
9a64fbe4
FB
232 }
233 break;
64201201
FB
234 case 0x0800:
235 /* Motorola CPU configuration register : read-only */
236 break;
237 case 0x0802:
238 /* Motorola base module feature register : read-only */
239 break;
240 case 0x0803:
241 /* Motorola base module status register : read-only */
242 break;
9a64fbe4 243 case 0x0808:
64201201
FB
244 /* Hardfile light register */
245 if (val & 1)
246 sysctrl->state |= STATE_HARDFILE;
247 else
248 sysctrl->state &= ~STATE_HARDFILE;
9a64fbe4
FB
249 break;
250 case 0x0810:
251 /* Password protect 1 register */
64201201
FB
252 if (sysctrl->nvram != NULL)
253 m48t59_toggle_lock(sysctrl->nvram, 1);
9a64fbe4
FB
254 break;
255 case 0x0812:
256 /* Password protect 2 register */
64201201
FB
257 if (sysctrl->nvram != NULL)
258 m48t59_toggle_lock(sysctrl->nvram, 2);
9a64fbe4
FB
259 break;
260 case 0x0814:
64201201 261 /* L2 invalidate register */
c68ea704 262 // tlb_flush(first_cpu, 1);
9a64fbe4
FB
263 break;
264 case 0x081C:
265 /* system control register */
64201201 266 sysctrl->syscontrol = val & 0x0F;
9a64fbe4
FB
267 break;
268 case 0x0850:
269 /* I/O map type register */
da9b266b 270 sysctrl->contiguous_map = val & 0x01;
9a64fbe4
FB
271 break;
272 default:
aae9366a
JM
273 printf("ERROR: unaffected IO port write: %04" PRIx32
274 " => %02" PRIx32"\n", addr, val);
9a64fbe4
FB
275 break;
276 }
277}
278
a541f297 279static uint32_t PREP_io_800_readb (void *opaque, uint32_t addr)
9a64fbe4 280{
c227f099 281 sysctrl_t *sysctrl = opaque;
9a64fbe4
FB
282 uint32_t retval = 0xFF;
283
284 switch (addr) {
285 case 0x0092:
286 /* Special port 92 */
64201201
FB
287 retval = 0x00;
288 break;
289 case 0x0800:
290 /* Motorola CPU configuration register */
291 retval = 0xEF; /* MPC750 */
292 break;
293 case 0x0802:
294 /* Motorola Base module feature register */
295 retval = 0xAD; /* No ESCC, PMC slot neither ethernet */
296 break;
297 case 0x0803:
298 /* Motorola base module status register */
299 retval = 0xE0; /* Standard MPC750 */
9a64fbe4
FB
300 break;
301 case 0x080C:
302 /* Equipment present register:
303 * no L2 cache
304 * no upgrade processor
305 * no cards in PCI slots
306 * SCSI fuse is bad
307 */
64201201
FB
308 retval = 0x3C;
309 break;
310 case 0x0810:
311 /* Motorola base module extended feature register */
312 retval = 0x39; /* No USB, CF and PCI bridge. NVRAM present */
9a64fbe4 313 break;
da9b266b
FB
314 case 0x0814:
315 /* L2 invalidate: don't care */
316 break;
9a64fbe4
FB
317 case 0x0818:
318 /* Keylock */
319 retval = 0x00;
320 break;
321 case 0x081C:
322 /* system control register
323 * 7 - 6 / 1 - 0: L2 cache enable
324 */
64201201 325 retval = sysctrl->syscontrol;
9a64fbe4
FB
326 break;
327 case 0x0823:
328 /* */
329 retval = 0x03; /* no L2 cache */
330 break;
331 case 0x0850:
332 /* I/O map type register */
da9b266b 333 retval = sysctrl->contiguous_map;
9a64fbe4
FB
334 break;
335 default:
aae9366a 336 printf("ERROR: unaffected IO port: %04" PRIx32 " read\n", addr);
9a64fbe4
FB
337 break;
338 }
aae9366a
JM
339 PPC_IO_DPRINTF("0x%08" PRIx32 " <= 0x%02" PRIx32 "\n",
340 addr - PPC_IO_BASE, retval);
9a64fbe4
FB
341
342 return retval;
343}
344
c227f099
AL
345static inline target_phys_addr_t prep_IO_address(sysctrl_t *sysctrl,
346 target_phys_addr_t addr)
da9b266b
FB
347{
348 if (sysctrl->contiguous_map == 0) {
349 /* 64 KB contiguous space for IOs */
350 addr &= 0xFFFF;
351 } else {
352 /* 8 MB non-contiguous space for IOs */
353 addr = (addr & 0x1F) | ((addr & 0x007FFF000) >> 7);
354 }
355
356 return addr;
357}
358
c227f099 359static void PPC_prep_io_writeb (void *opaque, target_phys_addr_t addr,
da9b266b
FB
360 uint32_t value)
361{
c227f099 362 sysctrl_t *sysctrl = opaque;
da9b266b
FB
363
364 addr = prep_IO_address(sysctrl, addr);
afcea8cb 365 cpu_outb(addr, value);
da9b266b
FB
366}
367
c227f099 368static uint32_t PPC_prep_io_readb (void *opaque, target_phys_addr_t addr)
da9b266b 369{
c227f099 370 sysctrl_t *sysctrl = opaque;
da9b266b
FB
371 uint32_t ret;
372
373 addr = prep_IO_address(sysctrl, addr);
afcea8cb 374 ret = cpu_inb(addr);
da9b266b
FB
375
376 return ret;
377}
378
c227f099 379static void PPC_prep_io_writew (void *opaque, target_phys_addr_t addr,
da9b266b
FB
380 uint32_t value)
381{
c227f099 382 sysctrl_t *sysctrl = opaque;
da9b266b
FB
383
384 addr = prep_IO_address(sysctrl, addr);
90e189ec 385 PPC_IO_DPRINTF("0x" TARGET_FMT_plx " => 0x%08" PRIx32 "\n", addr, value);
afcea8cb 386 cpu_outw(addr, value);
da9b266b
FB
387}
388
c227f099 389static uint32_t PPC_prep_io_readw (void *opaque, target_phys_addr_t addr)
da9b266b 390{
c227f099 391 sysctrl_t *sysctrl = opaque;
da9b266b
FB
392 uint32_t ret;
393
394 addr = prep_IO_address(sysctrl, addr);
afcea8cb 395 ret = cpu_inw(addr);
90e189ec 396 PPC_IO_DPRINTF("0x" TARGET_FMT_plx " <= 0x%08" PRIx32 "\n", addr, ret);
da9b266b
FB
397
398 return ret;
399}
400
c227f099 401static void PPC_prep_io_writel (void *opaque, target_phys_addr_t addr,
da9b266b
FB
402 uint32_t value)
403{
c227f099 404 sysctrl_t *sysctrl = opaque;
da9b266b
FB
405
406 addr = prep_IO_address(sysctrl, addr);
90e189ec 407 PPC_IO_DPRINTF("0x" TARGET_FMT_plx " => 0x%08" PRIx32 "\n", addr, value);
afcea8cb 408 cpu_outl(addr, value);
da9b266b
FB
409}
410
c227f099 411static uint32_t PPC_prep_io_readl (void *opaque, target_phys_addr_t addr)
da9b266b 412{
c227f099 413 sysctrl_t *sysctrl = opaque;
da9b266b
FB
414 uint32_t ret;
415
416 addr = prep_IO_address(sysctrl, addr);
afcea8cb 417 ret = cpu_inl(addr);
90e189ec 418 PPC_IO_DPRINTF("0x" TARGET_FMT_plx " <= 0x%08" PRIx32 "\n", addr, ret);
da9b266b
FB
419
420 return ret;
421}
422
0c90c52f
AK
423static const MemoryRegionOps PPC_prep_io_ops = {
424 .old_mmio = {
425 .read = { PPC_prep_io_readb, PPC_prep_io_readw, PPC_prep_io_readl },
426 .write = { PPC_prep_io_writeb, PPC_prep_io_writew, PPC_prep_io_writel },
427 },
428 .endianness = DEVICE_LITTLE_ENDIAN,
da9b266b
FB
429};
430
64201201 431#define NVRAM_SIZE 0x2000
a541f297 432
4556bd8b
BS
433static void cpu_request_exit(void *opaque, int irq, int level)
434{
e2684c0b 435 CPUPPCState *env = cpu_single_env;
4556bd8b
BS
436
437 if (env && level) {
438 cpu_exit(env);
439 }
440}
441
1bba0dc9
AF
442static void ppc_prep_reset(void *opaque)
443{
5c3e735f 444 PowerPCCPU *cpu = opaque;
1bba0dc9 445
5c3e735f 446 cpu_reset(CPU(cpu));
1bba0dc9
AF
447}
448
26aa7d72 449/* PowerPC PREP hardware initialisation */
5f072e1f 450static void ppc_prep_init(QEMUMachineInitArgs *args)
a541f297 451{
5f072e1f
EH
452 ram_addr_t ram_size = args->ram_size;
453 const char *cpu_model = args->cpu_model;
454 const char *kernel_filename = args->kernel_filename;
455 const char *kernel_cmdline = args->kernel_cmdline;
456 const char *initrd_filename = args->initrd_filename;
457 const char *boot_device = args->boot_device;
0c90c52f 458 MemoryRegion *sysmem = get_system_memory();
a9bf3df0 459 PowerPCCPU *cpu = NULL;
e2684c0b 460 CPUPPCState *env = NULL;
5cea8590 461 char *filename;
c227f099 462 nvram_t nvram;
43a34704 463 M48t59State *m48t59;
0c90c52f 464 MemoryRegion *PPC_io_memory = g_new(MemoryRegion, 1);
0c90c52f
AK
465#if 0
466 MemoryRegion *xcsr = g_new(MemoryRegion, 1);
467#endif
4157a662 468 int linux_boot, i, nb_nics1, bios_size;
0c90c52f
AK
469 MemoryRegion *ram = g_new(MemoryRegion, 1);
470 MemoryRegion *bios = g_new(MemoryRegion, 1);
093209cd
BS
471 uint32_t kernel_base, initrd_base;
472 long kernel_size, initrd_size;
8ca8c7bc 473 DeviceState *dev;
8ca8c7bc 474 PCIHostState *pcihost;
46e50e9d 475 PCIBus *pci_bus;
506b7ddf 476 PCIDevice *pci;
48a18b3c 477 ISABus *isa_bus;
4556bd8b 478 qemu_irq *cpu_exit_irq;
28c5af54 479 int ppc_boot_device;
f455e98c 480 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
fd8014e1 481 DriveInfo *fd[MAX_FD];
64201201 482
7267c094 483 sysctrl = g_malloc0(sizeof(sysctrl_t));
a541f297
FB
484
485 linux_boot = (kernel_filename != NULL);
0a032cbe 486
c68ea704 487 /* init CPUs */
94fc95cd 488 if (cpu_model == NULL)
b37fc148 489 cpu_model = "602";
fe33cc71 490 for (i = 0; i < smp_cpus; i++) {
a9bf3df0
AF
491 cpu = cpu_ppc_init(cpu_model);
492 if (cpu == NULL) {
aaed909a
FB
493 fprintf(stderr, "Unable to find PowerPC CPU definition\n");
494 exit(1);
495 }
a9bf3df0
AF
496 env = &cpu->env;
497
4018bae9
JM
498 if (env->flags & POWERPC_FLAG_RTC_CLK) {
499 /* POWER / PowerPC 601 RTC clock frequency is 7.8125 MHz */
500 cpu_ppc_tb_init(env, 7812500UL);
501 } else {
502 /* Set time-base frequency to 100 Mhz */
503 cpu_ppc_tb_init(env, 100UL * 1000UL * 1000UL);
504 }
5c3e735f 505 qemu_register_reset(ppc_prep_reset, cpu);
fe33cc71 506 }
a541f297
FB
507
508 /* allocate RAM */
c5705a77
AK
509 memory_region_init_ram(ram, "ppc_prep.ram", ram_size);
510 vmstate_register_ram_global(ram);
0c90c52f 511 memory_region_add_subregion(sysmem, 0, ram);
cf9c147c 512
64201201 513 /* allocate and load BIOS */
c5705a77 514 memory_region_init_ram(bios, "ppc_prep.bios", BIOS_SIZE);
809680c0
AF
515 memory_region_set_readonly(bios, true);
516 memory_region_add_subregion(sysmem, (uint32_t)(-BIOS_SIZE), bios);
c5705a77 517 vmstate_register_ram_global(bios);
1192dad8
JM
518 if (bios_name == NULL)
519 bios_name = BIOS_FILENAME;
5cea8590
PB
520 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
521 if (filename) {
522 bios_size = get_image_size(filename);
523 } else {
524 bios_size = -1;
525 }
dcac9679 526 if (bios_size > 0 && bios_size <= BIOS_SIZE) {
c227f099 527 target_phys_addr_t bios_addr;
dcac9679
PB
528 bios_size = (bios_size + 0xfff) & ~0xfff;
529 bios_addr = (uint32_t)(-bios_size);
5cea8590 530 bios_size = load_image_targphys(filename, bios_addr, bios_size);
dcac9679 531 }
4157a662 532 if (bios_size < 0 || bios_size > BIOS_SIZE) {
5cea8590
PB
533 hw_error("qemu: could not load PPC PREP bios '%s'\n", bios_name);
534 }
535 if (filename) {
7267c094 536 g_free(filename);
64201201 537 }
26aa7d72 538
a541f297 539 if (linux_boot) {
64201201 540 kernel_base = KERNEL_LOAD_ADDR;
a541f297 541 /* now we can load the kernel */
dcac9679
PB
542 kernel_size = load_image_targphys(kernel_filename, kernel_base,
543 ram_size - kernel_base);
64201201 544 if (kernel_size < 0) {
2ac71179 545 hw_error("qemu: could not load kernel '%s'\n", kernel_filename);
a541f297
FB
546 exit(1);
547 }
548 /* load initrd */
a541f297 549 if (initrd_filename) {
64201201 550 initrd_base = INITRD_LOAD_ADDR;
dcac9679
PB
551 initrd_size = load_image_targphys(initrd_filename, initrd_base,
552 ram_size - initrd_base);
a541f297 553 if (initrd_size < 0) {
2ac71179 554 hw_error("qemu: could not load initial ram disk '%s'\n",
4a057712 555 initrd_filename);
a541f297 556 }
64201201
FB
557 } else {
558 initrd_base = 0;
559 initrd_size = 0;
a541f297 560 }
6ac0e82d 561 ppc_boot_device = 'm';
a541f297 562 } else {
64201201
FB
563 kernel_base = 0;
564 kernel_size = 0;
565 initrd_base = 0;
566 initrd_size = 0;
28c5af54
JM
567 ppc_boot_device = '\0';
568 /* For now, OHW cannot boot from the network. */
0d913fdb
JM
569 for (i = 0; boot_device[i] != '\0'; i++) {
570 if (boot_device[i] >= 'a' && boot_device[i] <= 'f') {
571 ppc_boot_device = boot_device[i];
28c5af54 572 break;
0d913fdb 573 }
28c5af54
JM
574 }
575 if (ppc_boot_device == '\0') {
576 fprintf(stderr, "No valid boot device for Mac99 machine\n");
577 exit(1);
578 }
a541f297
FB
579 }
580
dd37a5e4 581 if (PPC_INPUT(env) != PPC_FLAGS_INPUT_6xx) {
2ac71179 582 hw_error("Only 6xx bus is supported on PREP machine\n");
dd37a5e4 583 }
8ca8c7bc
AF
584
585 dev = qdev_create(NULL, "raven-pcihost");
8558d942 586 pcihost = PCI_HOST_BRIDGE(dev);
8ca8c7bc 587 pcihost->address_space = get_system_memory();
f05f6b4a 588 object_property_add_child(qdev_get_machine(), "raven", OBJECT(dev), NULL);
f424d5c4 589 qdev_init_nofail(dev);
8ca8c7bc
AF
590 pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
591 if (pci_bus == NULL) {
592 fprintf(stderr, "Couldn't create PCI host controller.\n");
593 exit(1);
594 }
8ca8c7bc 595
506b7ddf
AF
596 /* PCI -> ISA bridge */
597 pci = pci_create_simple(pci_bus, PCI_DEVFN(1, 0), "i82378");
598 cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
599 qdev_connect_gpio_out(&pci->qdev, 0,
600 first_cpu->irq_inputs[PPC6xx_INPUT_INT]);
601 qdev_connect_gpio_out(&pci->qdev, 1, *cpu_exit_irq);
602 sysbus_connect_irq(&pcihost->busdev, 0, qdev_get_gpio_in(&pci->qdev, 9));
603 sysbus_connect_irq(&pcihost->busdev, 1, qdev_get_gpio_in(&pci->qdev, 11));
604 sysbus_connect_irq(&pcihost->busdev, 2, qdev_get_gpio_in(&pci->qdev, 9));
605 sysbus_connect_irq(&pcihost->busdev, 3, qdev_get_gpio_in(&pci->qdev, 11));
606 isa_bus = DO_UPCAST(ISABus, qbus, qdev_get_child_bus(&pci->qdev, "isa.0"));
607
da9b266b 608 /* Register 8 MB of ISA IO space (needed for non-contiguous map) */
0c90c52f
AK
609 memory_region_init_io(PPC_io_memory, &PPC_prep_io_ops, sysctrl,
610 "ppc-io", 0x00800000);
611 memory_region_add_subregion(sysmem, 0x80000000, PPC_io_memory);
64201201 612
a541f297 613 /* init basic PC hardware */
95fa01fa 614 pci_vga_init(pci_bus);
a541f297 615
ac0be998 616 if (serial_hds[0])
48a18b3c 617 serial_isa_init(isa_bus, 0, serial_hds[0]);
a541f297
FB
618 nb_nics1 = nb_nics;
619 if (nb_nics1 > NE2000_NB_MAX)
620 nb_nics1 = NE2000_NB_MAX;
621 for(i = 0; i < nb_nics1; i++) {
5652ef78 622 if (nd_table[i].model == NULL) {
7267c094 623 nd_table[i].model = g_strdup("ne2k_isa");
5652ef78
AJ
624 }
625 if (strcmp(nd_table[i].model, "ne2k_isa") == 0) {
48a18b3c
HP
626 isa_ne2000_init(isa_bus, ne2000_io[i], ne2000_irq[i],
627 &nd_table[i]);
a41b2ff2 628 } else {
07caea31 629 pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
a41b2ff2 630 }
a541f297 631 }
a541f297 632
75717903 633 ide_drive_get(hd, MAX_IDE_BUS);
81aa0647 634 for(i = 0; i < MAX_IDE_BUS; i++) {
48a18b3c 635 isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i], ide_irq[i],
e4bcb14c
TS
636 hd[2 * i],
637 hd[2 * i + 1]);
a541f297 638 }
48a18b3c 639 isa_create_simple(isa_bus, "i8042");
4556bd8b 640
a541f297
FB
641 // SB16_init();
642
e4bcb14c 643 for(i = 0; i < MAX_FD; i++) {
fd8014e1 644 fd[i] = drive_get(IF_FLOPPY, 0, i);
e4bcb14c 645 }
48a18b3c 646 fdctrl_init_isa(isa_bus, fd);
a541f297 647
a541f297 648 /* Register fake IO ports for PREP */
c4781a51 649 sysctrl->reset_irq = first_cpu->irq_inputs[PPC6xx_INPUT_HRESET];
64201201
FB
650 register_ioport_read(0x398, 2, 1, &PREP_io_read, sysctrl);
651 register_ioport_write(0x398, 2, 1, &PREP_io_write, sysctrl);
a541f297 652 /* System control ports */
64201201
FB
653 register_ioport_read(0x0092, 0x01, 1, &PREP_io_800_readb, sysctrl);
654 register_ioport_write(0x0092, 0x01, 1, &PREP_io_800_writeb, sysctrl);
655 register_ioport_read(0x0800, 0x52, 1, &PREP_io_800_readb, sysctrl);
656 register_ioport_write(0x0800, 0x52, 1, &PREP_io_800_writeb, sysctrl);
64201201 657 /* PowerPC control and status register group */
b6b8bd18 658#if 0
0c90c52f
AK
659 memory_region_init_io(xcsr, &PPC_XCSR_ops, NULL, "ppc-xcsr", 0x1000);
660 memory_region_add_subregion(sysmem, 0xFEFF0000, xcsr);
b6b8bd18 661#endif
a541f297 662
0d92ed30 663 if (usb_enabled) {
afb9a60e 664 pci_create_simple(pci_bus, -1, "pci-ohci");
0d92ed30
PB
665 }
666
48e93728 667 m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);
3cbee15b 668 if (m48t59 == NULL)
64201201 669 return;
3cbee15b 670 sysctrl->nvram = m48t59;
64201201
FB
671
672 /* Initialise NVRAM */
3cbee15b
JM
673 nvram.opaque = m48t59;
674 nvram.read_fn = &m48t59_read;
675 nvram.write_fn = &m48t59_write;
6ac0e82d 676 PPC_NVRAM_set_params(&nvram, NVRAM_SIZE, "PREP", ram_size, ppc_boot_device,
64201201 677 kernel_base, kernel_size,
b6b8bd18 678 kernel_cmdline,
64201201
FB
679 initrd_base, initrd_size,
680 /* XXX: need an option to load a NVRAM image */
b6b8bd18
FB
681 0,
682 graphic_width, graphic_height, graphic_depth);
c0e564d5
FB
683
684 /* Special port to get debug messages from Open-Firmware */
685 register_ioport_write(0x0F00, 4, 1, &PPC_debug_write, NULL);
9357b144
HP
686
687 /* Initialize audio subsystem */
688 audio_init(isa_bus, pci_bus);
a541f297 689}
c0e564d5 690
f80f9ec9 691static QEMUMachine prep_machine = {
4b32e168
AL
692 .name = "prep",
693 .desc = "PowerPC PREP platform",
694 .init = ppc_prep_init,
3d878caa 695 .max_cpus = MAX_CPUS,
c0e564d5 696};
f80f9ec9
AL
697
698static void prep_machine_init(void)
699{
700 qemu_register_machine(&prep_machine);
701}
702
703machine_init(prep_machine_init);