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