]>
Commit | Line | Data |
---|---|---|
3475187d | 1 | /* |
c7ba218d | 2 | * QEMU Sun4u/Sun4v System Emulator |
5fafdf24 | 3 | * |
3475187d | 4 | * Copyright (c) 2005 Fabrice Bellard |
5fafdf24 | 5 | * |
3475187d 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. | |
23 | */ | |
87ecb68b PB |
24 | #include "hw.h" |
25 | #include "pci.h" | |
18e08a55 | 26 | #include "apb_pci.h" |
87ecb68b PB |
27 | #include "pc.h" |
28 | #include "nvram.h" | |
29 | #include "fdc.h" | |
30 | #include "net.h" | |
31 | #include "qemu-timer.h" | |
32 | #include "sysemu.h" | |
33 | #include "boards.h" | |
d2c63fc1 | 34 | #include "firmware_abi.h" |
3cce6243 | 35 | #include "fw_cfg.h" |
1baffa46 | 36 | #include "sysbus.h" |
977e1244 | 37 | #include "ide.h" |
ca20cf32 BS |
38 | #include "loader.h" |
39 | #include "elf.h" | |
3475187d | 40 | |
9d926598 | 41 | //#define DEBUG_IRQ |
b430a225 | 42 | //#define DEBUG_EBUS |
9d926598 BS |
43 | |
44 | #ifdef DEBUG_IRQ | |
b430a225 | 45 | #define CPUIRQ_DPRINTF(fmt, ...) \ |
001faf32 | 46 | do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0) |
9d926598 | 47 | #else |
b430a225 BS |
48 | #define CPUIRQ_DPRINTF(fmt, ...) |
49 | #endif | |
50 | ||
51 | #ifdef DEBUG_EBUS | |
52 | #define EBUS_DPRINTF(fmt, ...) \ | |
53 | do { printf("EBUS: " fmt , ## __VA_ARGS__); } while (0) | |
54 | #else | |
55 | #define EBUS_DPRINTF(fmt, ...) | |
9d926598 BS |
56 | #endif |
57 | ||
83469015 FB |
58 | #define KERNEL_LOAD_ADDR 0x00404000 |
59 | #define CMDLINE_ADDR 0x003ff000 | |
60 | #define INITRD_LOAD_ADDR 0x00300000 | |
ac2e9d66 | 61 | #define PROM_SIZE_MAX (4 * 1024 * 1024) |
f930d07e | 62 | #define PROM_VADDR 0x000ffd00000ULL |
83469015 | 63 | #define APB_SPECIAL_BASE 0x1fe00000000ULL |
f930d07e BS |
64 | #define APB_MEM_BASE 0x1ff00000000ULL |
65 | #define VGA_BASE (APB_MEM_BASE + 0x400000ULL) | |
66 | #define PROM_FILENAME "openbios-sparc64" | |
83469015 | 67 | #define NVRAM_SIZE 0x2000 |
e4bcb14c | 68 | #define MAX_IDE_BUS 2 |
3cce6243 | 69 | #define BIOS_CFG_IOPORT 0x510 |
7589690c BS |
70 | #define FW_CFG_SPARC64_WIDTH (FW_CFG_ARCH_LOCAL + 0x00) |
71 | #define FW_CFG_SPARC64_HEIGHT (FW_CFG_ARCH_LOCAL + 0x01) | |
72 | #define FW_CFG_SPARC64_DEPTH (FW_CFG_ARCH_LOCAL + 0x02) | |
3475187d | 73 | |
9d926598 BS |
74 | #define MAX_PILS 16 |
75 | ||
8fa211e8 BS |
76 | #define TICK_MAX 0x7fffffffffffffffULL |
77 | ||
c7ba218d BS |
78 | struct hwdef { |
79 | const char * const default_cpu_model; | |
905fdcb5 | 80 | uint16_t machine_id; |
e87231d4 BS |
81 | uint64_t prom_addr; |
82 | uint64_t console_serial_base; | |
c7ba218d BS |
83 | }; |
84 | ||
3475187d FB |
85 | int DMA_get_channel_mode (int nchan) |
86 | { | |
87 | return 0; | |
88 | } | |
89 | int DMA_read_memory (int nchan, void *buf, int pos, int size) | |
90 | { | |
91 | return 0; | |
92 | } | |
93 | int DMA_write_memory (int nchan, void *buf, int pos, int size) | |
94 | { | |
95 | return 0; | |
96 | } | |
97 | void DMA_hold_DREQ (int nchan) {} | |
98 | void DMA_release_DREQ (int nchan) {} | |
99 | void DMA_schedule(int nchan) {} | |
3475187d FB |
100 | void DMA_init (int high_page_enable) {} |
101 | void DMA_register_channel (int nchan, | |
102 | DMA_transfer_handler transfer_handler, | |
103 | void *opaque) | |
104 | { | |
105 | } | |
106 | ||
513f789f | 107 | static int fw_cfg_boot_set(void *opaque, const char *boot_device) |
81864572 | 108 | { |
513f789f | 109 | fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); |
81864572 BS |
110 | return 0; |
111 | } | |
112 | ||
c227f099 | 113 | static int sun4u_NVRAM_set_params (m48t59_t *nvram, uint16_t NVRAM_size, |
e7fb1406 | 114 | const char *arch, |
c227f099 | 115 | ram_addr_t RAM_size, |
77f193da | 116 | const char *boot_devices, |
d2c63fc1 BS |
117 | uint32_t kernel_image, uint32_t kernel_size, |
118 | const char *cmdline, | |
119 | uint32_t initrd_image, uint32_t initrd_size, | |
120 | uint32_t NVRAM_image, | |
0d31cb99 BS |
121 | int width, int height, int depth, |
122 | const uint8_t *macaddr) | |
83469015 | 123 | { |
66508601 BS |
124 | unsigned int i; |
125 | uint32_t start, end; | |
d2c63fc1 | 126 | uint8_t image[0x1ff0]; |
d2c63fc1 BS |
127 | struct OpenBIOS_nvpart_v1 *part_header; |
128 | ||
129 | memset(image, '\0', sizeof(image)); | |
130 | ||
513f789f | 131 | start = 0; |
83469015 | 132 | |
66508601 BS |
133 | // OpenBIOS nvram variables |
134 | // Variable partition | |
d2c63fc1 BS |
135 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start]; |
136 | part_header->signature = OPENBIOS_PART_SYSTEM; | |
363a37d5 | 137 | pstrcpy(part_header->name, sizeof(part_header->name), "system"); |
66508601 | 138 | |
d2c63fc1 | 139 | end = start + sizeof(struct OpenBIOS_nvpart_v1); |
66508601 | 140 | for (i = 0; i < nb_prom_envs; i++) |
d2c63fc1 BS |
141 | end = OpenBIOS_set_var(image, end, prom_envs[i]); |
142 | ||
143 | // End marker | |
144 | image[end++] = '\0'; | |
66508601 | 145 | |
66508601 | 146 | end = start + ((end - start + 15) & ~15); |
d2c63fc1 | 147 | OpenBIOS_finish_partition(part_header, end - start); |
66508601 BS |
148 | |
149 | // free partition | |
150 | start = end; | |
d2c63fc1 BS |
151 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start]; |
152 | part_header->signature = OPENBIOS_PART_FREE; | |
363a37d5 | 153 | pstrcpy(part_header->name, sizeof(part_header->name), "free"); |
66508601 BS |
154 | |
155 | end = 0x1fd0; | |
d2c63fc1 BS |
156 | OpenBIOS_finish_partition(part_header, end - start); |
157 | ||
0d31cb99 BS |
158 | Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80); |
159 | ||
d2c63fc1 BS |
160 | for (i = 0; i < sizeof(image); i++) |
161 | m48t59_write(nvram, i, image[i]); | |
66508601 | 162 | |
83469015 | 163 | return 0; |
3475187d | 164 | } |
636aa70a BS |
165 | static unsigned long sun4u_load_kernel(const char *kernel_filename, |
166 | const char *initrd_filename, | |
c227f099 | 167 | ram_addr_t RAM_size, long *initrd_size) |
636aa70a BS |
168 | { |
169 | int linux_boot; | |
170 | unsigned int i; | |
171 | long kernel_size; | |
172 | ||
173 | linux_boot = (kernel_filename != NULL); | |
174 | ||
175 | kernel_size = 0; | |
176 | if (linux_boot) { | |
ca20cf32 BS |
177 | int bswap_needed; |
178 | ||
179 | #ifdef BSWAP_NEEDED | |
180 | bswap_needed = 1; | |
181 | #else | |
182 | bswap_needed = 0; | |
183 | #endif | |
184 | kernel_size = load_elf(kernel_filename, 0, NULL, NULL, NULL, | |
185 | 1, ELF_MACHINE, 0); | |
636aa70a BS |
186 | if (kernel_size < 0) |
187 | kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR, | |
ca20cf32 BS |
188 | RAM_size - KERNEL_LOAD_ADDR, bswap_needed, |
189 | TARGET_PAGE_SIZE); | |
636aa70a BS |
190 | if (kernel_size < 0) |
191 | kernel_size = load_image_targphys(kernel_filename, | |
192 | KERNEL_LOAD_ADDR, | |
193 | RAM_size - KERNEL_LOAD_ADDR); | |
194 | if (kernel_size < 0) { | |
195 | fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
196 | kernel_filename); | |
197 | exit(1); | |
198 | } | |
199 | ||
200 | /* load initrd */ | |
201 | *initrd_size = 0; | |
202 | if (initrd_filename) { | |
203 | *initrd_size = load_image_targphys(initrd_filename, | |
204 | INITRD_LOAD_ADDR, | |
205 | RAM_size - INITRD_LOAD_ADDR); | |
206 | if (*initrd_size < 0) { | |
207 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", | |
208 | initrd_filename); | |
209 | exit(1); | |
210 | } | |
211 | } | |
212 | if (*initrd_size > 0) { | |
213 | for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { | |
214 | if (ldl_phys(KERNEL_LOAD_ADDR + i) == 0x48647253) { // HdrS | |
215 | stl_phys(KERNEL_LOAD_ADDR + i + 16, INITRD_LOAD_ADDR); | |
216 | stl_phys(KERNEL_LOAD_ADDR + i + 20, *initrd_size); | |
217 | break; | |
218 | } | |
219 | } | |
220 | } | |
221 | } | |
222 | return kernel_size; | |
223 | } | |
3475187d | 224 | |
b4950060 | 225 | void pic_info(Monitor *mon) |
3475187d FB |
226 | { |
227 | } | |
228 | ||
b4950060 | 229 | void irq_info(Monitor *mon) |
3475187d FB |
230 | { |
231 | } | |
232 | ||
9d926598 BS |
233 | void cpu_check_irqs(CPUState *env) |
234 | { | |
d532b26c IK |
235 | uint32_t pil = env->pil_in | |
236 | (env->softint & ~(SOFTINT_TIMER | SOFTINT_STIMER)); | |
237 | ||
238 | /* check if TM or SM in SOFTINT are set | |
239 | setting these also causes interrupt 14 */ | |
240 | if (env->softint & (SOFTINT_TIMER | SOFTINT_STIMER)) { | |
241 | pil |= 1 << 14; | |
242 | } | |
243 | ||
244 | if (!pil) { | |
245 | if (env->interrupt_request & CPU_INTERRUPT_HARD) { | |
246 | CPUIRQ_DPRINTF("Reset CPU IRQ (current interrupt %x)\n", | |
247 | env->interrupt_index); | |
248 | env->interrupt_index = 0; | |
249 | cpu_reset_interrupt(env, CPU_INTERRUPT_HARD); | |
250 | } | |
251 | return; | |
252 | } | |
253 | ||
254 | if (cpu_interrupts_enabled(env)) { | |
9d926598 | 255 | |
9d926598 BS |
256 | unsigned int i; |
257 | ||
d532b26c | 258 | for (i = 15; i > env->psrpil; i--) { |
9d926598 BS |
259 | if (pil & (1 << i)) { |
260 | int old_interrupt = env->interrupt_index; | |
d532b26c IK |
261 | int new_interrupt = TT_EXTINT | i; |
262 | ||
263 | if (env->tl > 0 && cpu_tsptr(env)->tt > new_interrupt) { | |
264 | CPUIRQ_DPRINTF("Not setting CPU IRQ: TL=%d " | |
265 | "current %x >= pending %x\n", | |
266 | env->tl, cpu_tsptr(env)->tt, new_interrupt); | |
267 | } else if (old_interrupt != new_interrupt) { | |
268 | env->interrupt_index = new_interrupt; | |
269 | CPUIRQ_DPRINTF("Set CPU IRQ %d old=%x new=%x\n", i, | |
270 | old_interrupt, new_interrupt); | |
9d926598 BS |
271 | cpu_interrupt(env, CPU_INTERRUPT_HARD); |
272 | } | |
273 | break; | |
274 | } | |
275 | } | |
d532b26c IK |
276 | } else { |
277 | CPUIRQ_DPRINTF("Interrupts disabled, pil=%08x pil_in=%08x softint=%08x " | |
278 | "current interrupt %x\n", | |
279 | pil, env->pil_in, env->softint, env->interrupt_index); | |
9d926598 BS |
280 | } |
281 | } | |
282 | ||
283 | static void cpu_set_irq(void *opaque, int irq, int level) | |
284 | { | |
285 | CPUState *env = opaque; | |
286 | ||
287 | if (level) { | |
b430a225 | 288 | CPUIRQ_DPRINTF("Raise CPU IRQ %d\n", irq); |
9d926598 BS |
289 | env->halted = 0; |
290 | env->pil_in |= 1 << irq; | |
291 | cpu_check_irqs(env); | |
292 | } else { | |
b430a225 | 293 | CPUIRQ_DPRINTF("Lower CPU IRQ %d\n", irq); |
9d926598 BS |
294 | env->pil_in &= ~(1 << irq); |
295 | cpu_check_irqs(env); | |
296 | } | |
297 | } | |
298 | ||
e87231d4 BS |
299 | typedef struct ResetData { |
300 | CPUState *env; | |
44a99354 | 301 | uint64_t prom_addr; |
e87231d4 BS |
302 | } ResetData; |
303 | ||
c68ea704 FB |
304 | static void main_cpu_reset(void *opaque) |
305 | { | |
e87231d4 BS |
306 | ResetData *s = (ResetData *)opaque; |
307 | CPUState *env = s->env; | |
44a99354 | 308 | static unsigned int nr_resets; |
20c9f095 | 309 | |
c68ea704 | 310 | cpu_reset(env); |
8fa211e8 BS |
311 | env->tick_cmpr = TICK_INT_DIS | 0; |
312 | ptimer_set_limit(env->tick, TICK_MAX, 1); | |
2f43e00e | 313 | ptimer_run(env->tick, 1); |
8fa211e8 BS |
314 | env->stick_cmpr = TICK_INT_DIS | 0; |
315 | ptimer_set_limit(env->stick, TICK_MAX, 1); | |
2f43e00e | 316 | ptimer_run(env->stick, 1); |
8fa211e8 BS |
317 | env->hstick_cmpr = TICK_INT_DIS | 0; |
318 | ptimer_set_limit(env->hstick, TICK_MAX, 1); | |
2f43e00e | 319 | ptimer_run(env->hstick, 1); |
e87231d4 BS |
320 | env->gregs[1] = 0; // Memory start |
321 | env->gregs[2] = ram_size; // Memory size | |
322 | env->gregs[3] = 0; // Machine description XXX | |
44a99354 BS |
323 | if (nr_resets++ == 0) { |
324 | /* Power on reset */ | |
325 | env->pc = s->prom_addr + 0x20ULL; | |
326 | } else { | |
327 | env->pc = s->prom_addr + 0x40ULL; | |
328 | } | |
e87231d4 | 329 | env->npc = env->pc + 4; |
20c9f095 BS |
330 | } |
331 | ||
22548760 | 332 | static void tick_irq(void *opaque) |
20c9f095 BS |
333 | { |
334 | CPUState *env = opaque; | |
335 | ||
8fa211e8 BS |
336 | if (!(env->tick_cmpr & TICK_INT_DIS)) { |
337 | env->softint |= SOFTINT_TIMER; | |
338 | cpu_interrupt(env, CPU_INTERRUPT_TIMER); | |
339 | } | |
20c9f095 BS |
340 | } |
341 | ||
22548760 | 342 | static void stick_irq(void *opaque) |
20c9f095 BS |
343 | { |
344 | CPUState *env = opaque; | |
345 | ||
8fa211e8 BS |
346 | if (!(env->stick_cmpr & TICK_INT_DIS)) { |
347 | env->softint |= SOFTINT_STIMER; | |
348 | cpu_interrupt(env, CPU_INTERRUPT_TIMER); | |
349 | } | |
20c9f095 BS |
350 | } |
351 | ||
22548760 | 352 | static void hstick_irq(void *opaque) |
20c9f095 BS |
353 | { |
354 | CPUState *env = opaque; | |
355 | ||
8fa211e8 BS |
356 | if (!(env->hstick_cmpr & TICK_INT_DIS)) { |
357 | cpu_interrupt(env, CPU_INTERRUPT_TIMER); | |
358 | } | |
c68ea704 FB |
359 | } |
360 | ||
f4b1a842 BS |
361 | void cpu_tick_set_count(void *opaque, uint64_t count) |
362 | { | |
363 | ptimer_set_count(opaque, -count); | |
364 | } | |
365 | ||
366 | uint64_t cpu_tick_get_count(void *opaque) | |
367 | { | |
368 | return -ptimer_get_count(opaque); | |
369 | } | |
370 | ||
371 | void cpu_tick_set_limit(void *opaque, uint64_t limit) | |
372 | { | |
373 | ptimer_set_limit(opaque, -limit, 0); | |
374 | } | |
375 | ||
c190ea07 | 376 | static void ebus_mmio_mapfunc(PCIDevice *pci_dev, int region_num, |
6e355d90 | 377 | pcibus_t addr, pcibus_t size, int type) |
c190ea07 | 378 | { |
b430a225 BS |
379 | EBUS_DPRINTF("Mapping region %d registers at %" FMT_PCIBUS "\n", |
380 | region_num, addr); | |
c190ea07 BS |
381 | switch (region_num) { |
382 | case 0: | |
383 | isa_mmio_init(addr, 0x1000000); | |
384 | break; | |
385 | case 1: | |
386 | isa_mmio_init(addr, 0x800000); | |
387 | break; | |
388 | } | |
389 | } | |
390 | ||
1387fe4a BS |
391 | static void dummy_isa_irq_handler(void *opaque, int n, int level) |
392 | { | |
393 | } | |
394 | ||
c190ea07 BS |
395 | /* EBUS (Eight bit bus) bridge */ |
396 | static void | |
397 | pci_ebus_init(PCIBus *bus, int devfn) | |
398 | { | |
1387fe4a BS |
399 | qemu_irq *isa_irq; |
400 | ||
53e3c4f9 | 401 | pci_create_simple(bus, devfn, "ebus"); |
1387fe4a BS |
402 | isa_irq = qemu_allocate_irqs(dummy_isa_irq_handler, NULL, 16); |
403 | isa_bus_irqs(isa_irq); | |
53e3c4f9 | 404 | } |
c190ea07 | 405 | |
81a322d4 | 406 | static int |
53e3c4f9 BS |
407 | pci_ebus_init1(PCIDevice *s) |
408 | { | |
0c5b8d83 BS |
409 | isa_bus_new(&s->qdev); |
410 | ||
deb54399 AL |
411 | pci_config_set_vendor_id(s->config, PCI_VENDOR_ID_SUN); |
412 | pci_config_set_device_id(s->config, PCI_DEVICE_ID_SUN_EBUS); | |
c190ea07 BS |
413 | s->config[0x04] = 0x06; // command = bus master, pci mem |
414 | s->config[0x05] = 0x00; | |
415 | s->config[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error | |
416 | s->config[0x07] = 0x03; // status = medium devsel | |
417 | s->config[0x08] = 0x01; // revision | |
418 | s->config[0x09] = 0x00; // programming i/f | |
173a543b | 419 | pci_config_set_class(s->config, PCI_CLASS_BRIDGE_OTHER); |
c190ea07 | 420 | s->config[0x0D] = 0x0a; // latency_timer |
6407f373 | 421 | s->config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type |
c190ea07 | 422 | |
0392a017 | 423 | pci_register_bar(s, 0, 0x1000000, PCI_BASE_ADDRESS_SPACE_MEMORY, |
c190ea07 | 424 | ebus_mmio_mapfunc); |
0392a017 | 425 | pci_register_bar(s, 1, 0x800000, PCI_BASE_ADDRESS_SPACE_MEMORY, |
c190ea07 | 426 | ebus_mmio_mapfunc); |
81a322d4 | 427 | return 0; |
c190ea07 BS |
428 | } |
429 | ||
53e3c4f9 BS |
430 | static PCIDeviceInfo ebus_info = { |
431 | .qdev.name = "ebus", | |
432 | .qdev.size = sizeof(PCIDevice), | |
433 | .init = pci_ebus_init1, | |
434 | }; | |
435 | ||
436 | static void pci_ebus_register(void) | |
437 | { | |
438 | pci_qdev_register(&ebus_info); | |
439 | } | |
440 | ||
441 | device_init(pci_ebus_register); | |
442 | ||
1baffa46 | 443 | /* Boot PROM (OpenBIOS) */ |
c227f099 | 444 | static void prom_init(target_phys_addr_t addr, const char *bios_name) |
1baffa46 BS |
445 | { |
446 | DeviceState *dev; | |
447 | SysBusDevice *s; | |
448 | char *filename; | |
449 | int ret; | |
450 | ||
451 | dev = qdev_create(NULL, "openprom"); | |
e23a1b33 | 452 | qdev_init_nofail(dev); |
1baffa46 BS |
453 | s = sysbus_from_qdev(dev); |
454 | ||
455 | sysbus_mmio_map(s, 0, addr); | |
456 | ||
457 | /* load boot prom */ | |
458 | if (bios_name == NULL) { | |
459 | bios_name = PROM_FILENAME; | |
460 | } | |
461 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); | |
462 | if (filename) { | |
ca20cf32 BS |
463 | ret = load_elf(filename, addr - PROM_VADDR, NULL, NULL, NULL, |
464 | 1, ELF_MACHINE, 0); | |
1baffa46 BS |
465 | if (ret < 0 || ret > PROM_SIZE_MAX) { |
466 | ret = load_image_targphys(filename, addr, PROM_SIZE_MAX); | |
467 | } | |
468 | qemu_free(filename); | |
469 | } else { | |
470 | ret = -1; | |
471 | } | |
472 | if (ret < 0 || ret > PROM_SIZE_MAX) { | |
473 | fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name); | |
474 | exit(1); | |
475 | } | |
476 | } | |
477 | ||
81a322d4 | 478 | static int prom_init1(SysBusDevice *dev) |
1baffa46 | 479 | { |
c227f099 | 480 | ram_addr_t prom_offset; |
1baffa46 BS |
481 | |
482 | prom_offset = qemu_ram_alloc(PROM_SIZE_MAX); | |
483 | sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM); | |
81a322d4 | 484 | return 0; |
1baffa46 BS |
485 | } |
486 | ||
487 | static SysBusDeviceInfo prom_info = { | |
488 | .init = prom_init1, | |
489 | .qdev.name = "openprom", | |
490 | .qdev.size = sizeof(SysBusDevice), | |
491 | .qdev.props = (Property[]) { | |
492 | {/* end of property list */} | |
493 | } | |
494 | }; | |
495 | ||
496 | static void prom_register_devices(void) | |
497 | { | |
498 | sysbus_register_withprop(&prom_info); | |
499 | } | |
500 | ||
501 | device_init(prom_register_devices); | |
502 | ||
bda42033 BS |
503 | |
504 | typedef struct RamDevice | |
505 | { | |
506 | SysBusDevice busdev; | |
04843626 | 507 | uint64_t size; |
bda42033 BS |
508 | } RamDevice; |
509 | ||
510 | /* System RAM */ | |
81a322d4 | 511 | static int ram_init1(SysBusDevice *dev) |
bda42033 | 512 | { |
c227f099 | 513 | ram_addr_t RAM_size, ram_offset; |
bda42033 BS |
514 | RamDevice *d = FROM_SYSBUS(RamDevice, dev); |
515 | ||
516 | RAM_size = d->size; | |
517 | ||
518 | ram_offset = qemu_ram_alloc(RAM_size); | |
519 | sysbus_init_mmio(dev, RAM_size, ram_offset); | |
81a322d4 | 520 | return 0; |
bda42033 BS |
521 | } |
522 | ||
c227f099 | 523 | static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size) |
bda42033 BS |
524 | { |
525 | DeviceState *dev; | |
526 | SysBusDevice *s; | |
527 | RamDevice *d; | |
528 | ||
529 | /* allocate RAM */ | |
530 | dev = qdev_create(NULL, "memory"); | |
531 | s = sysbus_from_qdev(dev); | |
532 | ||
533 | d = FROM_SYSBUS(RamDevice, s); | |
534 | d->size = RAM_size; | |
e23a1b33 | 535 | qdev_init_nofail(dev); |
bda42033 BS |
536 | |
537 | sysbus_mmio_map(s, 0, addr); | |
538 | } | |
539 | ||
540 | static SysBusDeviceInfo ram_info = { | |
541 | .init = ram_init1, | |
542 | .qdev.name = "memory", | |
543 | .qdev.size = sizeof(RamDevice), | |
544 | .qdev.props = (Property[]) { | |
32a7ee98 GH |
545 | DEFINE_PROP_UINT64("size", RamDevice, size, 0), |
546 | DEFINE_PROP_END_OF_LIST(), | |
bda42033 BS |
547 | } |
548 | }; | |
549 | ||
550 | static void ram_register_devices(void) | |
551 | { | |
552 | sysbus_register_withprop(&ram_info); | |
553 | } | |
554 | ||
555 | device_init(ram_register_devices); | |
556 | ||
7b833f5b | 557 | static CPUState *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef) |
3475187d | 558 | { |
c68ea704 | 559 | CPUState *env; |
20c9f095 | 560 | QEMUBH *bh; |
e87231d4 | 561 | ResetData *reset_info; |
3475187d | 562 | |
c7ba218d BS |
563 | if (!cpu_model) |
564 | cpu_model = hwdef->default_cpu_model; | |
aaed909a FB |
565 | env = cpu_init(cpu_model); |
566 | if (!env) { | |
62724a37 BS |
567 | fprintf(stderr, "Unable to find Sparc CPU definition\n"); |
568 | exit(1); | |
569 | } | |
20c9f095 BS |
570 | bh = qemu_bh_new(tick_irq, env); |
571 | env->tick = ptimer_init(bh); | |
572 | ptimer_set_period(env->tick, 1ULL); | |
573 | ||
574 | bh = qemu_bh_new(stick_irq, env); | |
575 | env->stick = ptimer_init(bh); | |
576 | ptimer_set_period(env->stick, 1ULL); | |
577 | ||
578 | bh = qemu_bh_new(hstick_irq, env); | |
579 | env->hstick = ptimer_init(bh); | |
580 | ptimer_set_period(env->hstick, 1ULL); | |
e87231d4 BS |
581 | |
582 | reset_info = qemu_mallocz(sizeof(ResetData)); | |
583 | reset_info->env = env; | |
44a99354 | 584 | reset_info->prom_addr = hwdef->prom_addr; |
a08d4367 | 585 | qemu_register_reset(main_cpu_reset, reset_info); |
c68ea704 | 586 | |
7b833f5b BS |
587 | return env; |
588 | } | |
589 | ||
c227f099 | 590 | static void sun4uv_init(ram_addr_t RAM_size, |
7b833f5b BS |
591 | const char *boot_devices, |
592 | const char *kernel_filename, const char *kernel_cmdline, | |
593 | const char *initrd_filename, const char *cpu_model, | |
594 | const struct hwdef *hwdef) | |
595 | { | |
596 | CPUState *env; | |
c227f099 | 597 | m48t59_t *nvram; |
7b833f5b BS |
598 | unsigned int i; |
599 | long initrd_size, kernel_size; | |
600 | PCIBus *pci_bus, *pci_bus2, *pci_bus3; | |
601 | qemu_irq *irq; | |
f455e98c | 602 | DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; |
fd8014e1 | 603 | DriveInfo *fd[MAX_FD]; |
7b833f5b BS |
604 | void *fw_cfg; |
605 | ||
7b833f5b BS |
606 | /* init CPUs */ |
607 | env = cpu_devinit(cpu_model, hwdef); | |
608 | ||
bda42033 BS |
609 | /* set up devices */ |
610 | ram_init(0, RAM_size); | |
3475187d | 611 | |
1baffa46 | 612 | prom_init(hwdef->prom_addr, bios_name); |
3475187d | 613 | |
7d55273f IK |
614 | |
615 | irq = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS); | |
616 | pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, irq, &pci_bus2, | |
c190ea07 | 617 | &pci_bus3); |
83469015 | 618 | isa_mem_base = VGA_BASE; |
fbe1b595 | 619 | pci_vga_init(pci_bus, 0, 0); |
83469015 | 620 | |
c190ea07 BS |
621 | // XXX Should be pci_bus3 |
622 | pci_ebus_init(pci_bus, -1); | |
623 | ||
e87231d4 BS |
624 | i = 0; |
625 | if (hwdef->console_serial_base) { | |
626 | serial_mm_init(hwdef->console_serial_base, 0, NULL, 115200, | |
627 | serial_hds[i], 1); | |
628 | i++; | |
629 | } | |
630 | for(; i < MAX_SERIAL_PORTS; i++) { | |
83469015 | 631 | if (serial_hds[i]) { |
ac0be998 | 632 | serial_isa_init(i, serial_hds[i]); |
83469015 FB |
633 | } |
634 | } | |
635 | ||
636 | for(i = 0; i < MAX_PARALLEL_PORTS; i++) { | |
637 | if (parallel_hds[i]) { | |
021f0674 | 638 | parallel_init(i, parallel_hds[i]); |
83469015 FB |
639 | } |
640 | } | |
641 | ||
cb457d76 | 642 | for(i = 0; i < nb_nics; i++) |
07caea31 | 643 | pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL); |
83469015 | 644 | |
e4bcb14c TS |
645 | if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) { |
646 | fprintf(stderr, "qemu: too many IDE bus\n"); | |
647 | exit(1); | |
648 | } | |
649 | for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) { | |
f455e98c | 650 | hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, |
751c6a17 | 651 | i % MAX_IDE_DEVS); |
e4bcb14c TS |
652 | } |
653 | ||
3b898dda BS |
654 | pci_cmd646_ide_init(pci_bus, hd, 1); |
655 | ||
2e15e23b | 656 | isa_create_simple("i8042"); |
e4bcb14c | 657 | for(i = 0; i < MAX_FD; i++) { |
fd8014e1 | 658 | fd[i] = drive_get(IF_FLOPPY, 0, i); |
e4bcb14c | 659 | } |
86c86157 | 660 | fdctrl_init_isa(fd); |
f80237d4 | 661 | nvram = m48t59_init_isa(0x0074, NVRAM_SIZE, 59); |
636aa70a BS |
662 | |
663 | initrd_size = 0; | |
664 | kernel_size = sun4u_load_kernel(kernel_filename, initrd_filename, | |
665 | ram_size, &initrd_size); | |
666 | ||
22548760 | 667 | sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", RAM_size, boot_devices, |
0d31cb99 BS |
668 | KERNEL_LOAD_ADDR, kernel_size, |
669 | kernel_cmdline, | |
670 | INITRD_LOAD_ADDR, initrd_size, | |
671 | /* XXX: need an option to load a NVRAM image */ | |
672 | 0, | |
673 | graphic_width, graphic_height, graphic_depth, | |
674 | (uint8_t *)&nd_table[0].macaddr); | |
83469015 | 675 | |
3cce6243 BS |
676 | fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0); |
677 | fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); | |
905fdcb5 BS |
678 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); |
679 | fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); | |
513f789f BS |
680 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR); |
681 | fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); | |
682 | if (kernel_cmdline) { | |
9c9b0512 BS |
683 | fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, |
684 | strlen(kernel_cmdline) + 1); | |
6bb4ca57 BS |
685 | fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA, |
686 | (uint8_t*)strdup(kernel_cmdline), | |
687 | strlen(kernel_cmdline) + 1); | |
513f789f | 688 | } else { |
9c9b0512 | 689 | fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0); |
513f789f BS |
690 | } |
691 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR); | |
692 | fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); | |
693 | fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_devices[0]); | |
7589690c BS |
694 | |
695 | fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width); | |
696 | fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height); | |
697 | fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth); | |
698 | ||
513f789f | 699 | qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); |
3475187d FB |
700 | } |
701 | ||
905fdcb5 BS |
702 | enum { |
703 | sun4u_id = 0, | |
704 | sun4v_id = 64, | |
e87231d4 | 705 | niagara_id, |
905fdcb5 BS |
706 | }; |
707 | ||
c7ba218d BS |
708 | static const struct hwdef hwdefs[] = { |
709 | /* Sun4u generic PC-like machine */ | |
710 | { | |
711 | .default_cpu_model = "TI UltraSparc II", | |
905fdcb5 | 712 | .machine_id = sun4u_id, |
e87231d4 BS |
713 | .prom_addr = 0x1fff0000000ULL, |
714 | .console_serial_base = 0, | |
c7ba218d BS |
715 | }, |
716 | /* Sun4v generic PC-like machine */ | |
717 | { | |
718 | .default_cpu_model = "Sun UltraSparc T1", | |
905fdcb5 | 719 | .machine_id = sun4v_id, |
e87231d4 BS |
720 | .prom_addr = 0x1fff0000000ULL, |
721 | .console_serial_base = 0, | |
722 | }, | |
723 | /* Sun4v generic Niagara machine */ | |
724 | { | |
725 | .default_cpu_model = "Sun UltraSparc T1", | |
726 | .machine_id = niagara_id, | |
727 | .prom_addr = 0xfff0000000ULL, | |
728 | .console_serial_base = 0xfff0c2c000ULL, | |
c7ba218d BS |
729 | }, |
730 | }; | |
731 | ||
732 | /* Sun4u hardware initialisation */ | |
c227f099 | 733 | static void sun4u_init(ram_addr_t RAM_size, |
3023f332 | 734 | const char *boot_devices, |
c7ba218d BS |
735 | const char *kernel_filename, const char *kernel_cmdline, |
736 | const char *initrd_filename, const char *cpu_model) | |
737 | { | |
fbe1b595 | 738 | sun4uv_init(RAM_size, boot_devices, kernel_filename, |
c7ba218d BS |
739 | kernel_cmdline, initrd_filename, cpu_model, &hwdefs[0]); |
740 | } | |
741 | ||
742 | /* Sun4v hardware initialisation */ | |
c227f099 | 743 | static void sun4v_init(ram_addr_t RAM_size, |
3023f332 | 744 | const char *boot_devices, |
c7ba218d BS |
745 | const char *kernel_filename, const char *kernel_cmdline, |
746 | const char *initrd_filename, const char *cpu_model) | |
747 | { | |
fbe1b595 | 748 | sun4uv_init(RAM_size, boot_devices, kernel_filename, |
c7ba218d BS |
749 | kernel_cmdline, initrd_filename, cpu_model, &hwdefs[1]); |
750 | } | |
751 | ||
e87231d4 | 752 | /* Niagara hardware initialisation */ |
c227f099 | 753 | static void niagara_init(ram_addr_t RAM_size, |
3023f332 | 754 | const char *boot_devices, |
e87231d4 BS |
755 | const char *kernel_filename, const char *kernel_cmdline, |
756 | const char *initrd_filename, const char *cpu_model) | |
757 | { | |
fbe1b595 | 758 | sun4uv_init(RAM_size, boot_devices, kernel_filename, |
e87231d4 BS |
759 | kernel_cmdline, initrd_filename, cpu_model, &hwdefs[2]); |
760 | } | |
761 | ||
f80f9ec9 | 762 | static QEMUMachine sun4u_machine = { |
66de733b BS |
763 | .name = "sun4u", |
764 | .desc = "Sun4u platform", | |
765 | .init = sun4u_init, | |
1bcee014 | 766 | .max_cpus = 1, // XXX for now |
0c257437 | 767 | .is_default = 1, |
3475187d | 768 | }; |
c7ba218d | 769 | |
f80f9ec9 | 770 | static QEMUMachine sun4v_machine = { |
66de733b BS |
771 | .name = "sun4v", |
772 | .desc = "Sun4v platform", | |
773 | .init = sun4v_init, | |
1bcee014 | 774 | .max_cpus = 1, // XXX for now |
c7ba218d | 775 | }; |
e87231d4 | 776 | |
f80f9ec9 | 777 | static QEMUMachine niagara_machine = { |
e87231d4 BS |
778 | .name = "Niagara", |
779 | .desc = "Sun4v platform, Niagara", | |
780 | .init = niagara_init, | |
1bcee014 | 781 | .max_cpus = 1, // XXX for now |
e87231d4 | 782 | }; |
f80f9ec9 AL |
783 | |
784 | static void sun4u_machine_init(void) | |
785 | { | |
786 | qemu_register_machine(&sun4u_machine); | |
787 | qemu_register_machine(&sun4v_machine); | |
788 | qemu_register_machine(&niagara_machine); | |
789 | } | |
790 | ||
791 | machine_init(sun4u_machine_init); |