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