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