]>
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 | */ | |
db5ebe5f | 24 | #include "qemu/osdep.h" |
da34e65c | 25 | #include "qapi/error.h" |
4771d756 PB |
26 | #include "qemu-common.h" |
27 | #include "cpu.h" | |
83c9f4ca PB |
28 | #include "hw/hw.h" |
29 | #include "hw/pci/pci.h" | |
0d09e41a PB |
30 | #include "hw/pci-host/apb.h" |
31 | #include "hw/i386/pc.h" | |
32 | #include "hw/char/serial.h" | |
33 | #include "hw/timer/m48t59.h" | |
34 | #include "hw/block/fdc.h" | |
1422e32d | 35 | #include "net/net.h" |
1de7afc9 | 36 | #include "qemu/timer.h" |
9c17d615 | 37 | #include "sysemu/sysemu.h" |
83c9f4ca | 38 | #include "hw/boards.h" |
ec0503b4 | 39 | #include "hw/nvram/openbios_firmware_abi.h" |
0d09e41a | 40 | #include "hw/nvram/fw_cfg.h" |
83c9f4ca PB |
41 | #include "hw/sysbus.h" |
42 | #include "hw/ide.h" | |
43 | #include "hw/loader.h" | |
ca20cf32 | 44 | #include "elf.h" |
4be74634 | 45 | #include "sysemu/block-backend.h" |
022c62cb | 46 | #include "exec/address-spaces.h" |
f348b6d1 | 47 | #include "qemu/cutils.h" |
3475187d | 48 | |
9d926598 | 49 | //#define DEBUG_IRQ |
b430a225 | 50 | //#define DEBUG_EBUS |
8f4efc55 | 51 | //#define DEBUG_TIMER |
9d926598 BS |
52 | |
53 | #ifdef DEBUG_IRQ | |
b430a225 | 54 | #define CPUIRQ_DPRINTF(fmt, ...) \ |
001faf32 | 55 | do { printf("CPUIRQ: " fmt , ## __VA_ARGS__); } while (0) |
9d926598 | 56 | #else |
b430a225 BS |
57 | #define CPUIRQ_DPRINTF(fmt, ...) |
58 | #endif | |
59 | ||
60 | #ifdef DEBUG_EBUS | |
61 | #define EBUS_DPRINTF(fmt, ...) \ | |
62 | do { printf("EBUS: " fmt , ## __VA_ARGS__); } while (0) | |
63 | #else | |
64 | #define EBUS_DPRINTF(fmt, ...) | |
9d926598 BS |
65 | #endif |
66 | ||
8f4efc55 IK |
67 | #ifdef DEBUG_TIMER |
68 | #define TIMER_DPRINTF(fmt, ...) \ | |
69 | do { printf("TIMER: " fmt , ## __VA_ARGS__); } while (0) | |
70 | #else | |
71 | #define TIMER_DPRINTF(fmt, ...) | |
72 | #endif | |
73 | ||
83469015 FB |
74 | #define KERNEL_LOAD_ADDR 0x00404000 |
75 | #define CMDLINE_ADDR 0x003ff000 | |
ac2e9d66 | 76 | #define PROM_SIZE_MAX (4 * 1024 * 1024) |
f930d07e | 77 | #define PROM_VADDR 0x000ffd00000ULL |
83469015 | 78 | #define APB_SPECIAL_BASE 0x1fe00000000ULL |
f930d07e | 79 | #define APB_MEM_BASE 0x1ff00000000ULL |
d63baf92 | 80 | #define APB_PCI_IO_BASE (APB_SPECIAL_BASE + 0x02000000ULL) |
f930d07e | 81 | #define PROM_FILENAME "openbios-sparc64" |
83469015 | 82 | #define NVRAM_SIZE 0x2000 |
e4bcb14c | 83 | #define MAX_IDE_BUS 2 |
3cce6243 | 84 | #define BIOS_CFG_IOPORT 0x510 |
7589690c BS |
85 | #define FW_CFG_SPARC64_WIDTH (FW_CFG_ARCH_LOCAL + 0x00) |
86 | #define FW_CFG_SPARC64_HEIGHT (FW_CFG_ARCH_LOCAL + 0x01) | |
87 | #define FW_CFG_SPARC64_DEPTH (FW_CFG_ARCH_LOCAL + 0x02) | |
3475187d | 88 | |
852e82f3 | 89 | #define IVEC_MAX 0x40 |
9d926598 | 90 | |
8fa211e8 BS |
91 | #define TICK_MAX 0x7fffffffffffffffULL |
92 | ||
c7ba218d BS |
93 | struct hwdef { |
94 | const char * const default_cpu_model; | |
905fdcb5 | 95 | uint16_t machine_id; |
e87231d4 BS |
96 | uint64_t prom_addr; |
97 | uint64_t console_serial_base; | |
c7ba218d BS |
98 | }; |
99 | ||
c5e6fb7e AK |
100 | typedef struct EbusState { |
101 | PCIDevice pci_dev; | |
102 | MemoryRegion bar0; | |
103 | MemoryRegion bar1; | |
104 | } EbusState; | |
105 | ||
57146941 | 106 | void DMA_init(ISABus *bus, int high_page_enable) |
4556bd8b BS |
107 | { |
108 | } | |
109 | ||
ddcd5531 GA |
110 | static void fw_cfg_boot_set(void *opaque, const char *boot_device, |
111 | Error **errp) | |
81864572 | 112 | { |
48779e50 | 113 | fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]); |
81864572 BS |
114 | } |
115 | ||
31688246 | 116 | static int sun4u_NVRAM_set_params(Nvram *nvram, uint16_t NVRAM_size, |
43a34704 BS |
117 | const char *arch, ram_addr_t RAM_size, |
118 | const char *boot_devices, | |
119 | uint32_t kernel_image, uint32_t kernel_size, | |
120 | const char *cmdline, | |
121 | uint32_t initrd_image, uint32_t initrd_size, | |
122 | uint32_t NVRAM_image, | |
123 | int width, int height, int depth, | |
124 | const uint8_t *macaddr) | |
83469015 | 125 | { |
66508601 BS |
126 | unsigned int i; |
127 | uint32_t start, end; | |
d2c63fc1 | 128 | uint8_t image[0x1ff0]; |
d2c63fc1 | 129 | struct OpenBIOS_nvpart_v1 *part_header; |
31688246 | 130 | NvramClass *k = NVRAM_GET_CLASS(nvram); |
d2c63fc1 BS |
131 | |
132 | memset(image, '\0', sizeof(image)); | |
133 | ||
513f789f | 134 | start = 0; |
83469015 | 135 | |
66508601 BS |
136 | // OpenBIOS nvram variables |
137 | // Variable partition | |
d2c63fc1 BS |
138 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start]; |
139 | part_header->signature = OPENBIOS_PART_SYSTEM; | |
363a37d5 | 140 | pstrcpy(part_header->name, sizeof(part_header->name), "system"); |
66508601 | 141 | |
d2c63fc1 | 142 | end = start + sizeof(struct OpenBIOS_nvpart_v1); |
66508601 | 143 | for (i = 0; i < nb_prom_envs; i++) |
d2c63fc1 BS |
144 | end = OpenBIOS_set_var(image, end, prom_envs[i]); |
145 | ||
146 | // End marker | |
147 | image[end++] = '\0'; | |
66508601 | 148 | |
66508601 | 149 | end = start + ((end - start + 15) & ~15); |
d2c63fc1 | 150 | OpenBIOS_finish_partition(part_header, end - start); |
66508601 BS |
151 | |
152 | // free partition | |
153 | start = end; | |
d2c63fc1 BS |
154 | part_header = (struct OpenBIOS_nvpart_v1 *)&image[start]; |
155 | part_header->signature = OPENBIOS_PART_FREE; | |
363a37d5 | 156 | pstrcpy(part_header->name, sizeof(part_header->name), "free"); |
66508601 BS |
157 | |
158 | end = 0x1fd0; | |
d2c63fc1 BS |
159 | OpenBIOS_finish_partition(part_header, end - start); |
160 | ||
0d31cb99 BS |
161 | Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80); |
162 | ||
31688246 HP |
163 | for (i = 0; i < sizeof(image); i++) { |
164 | (k->write)(nvram, i, image[i]); | |
165 | } | |
66508601 | 166 | |
83469015 | 167 | return 0; |
3475187d | 168 | } |
5f2bf0fe BS |
169 | |
170 | static uint64_t sun4u_load_kernel(const char *kernel_filename, | |
171 | const char *initrd_filename, | |
172 | ram_addr_t RAM_size, uint64_t *initrd_size, | |
173 | uint64_t *initrd_addr, uint64_t *kernel_addr, | |
174 | uint64_t *kernel_entry) | |
636aa70a BS |
175 | { |
176 | int linux_boot; | |
177 | unsigned int i; | |
178 | long kernel_size; | |
6908d9ce | 179 | uint8_t *ptr; |
5f2bf0fe | 180 | uint64_t kernel_top; |
636aa70a BS |
181 | |
182 | linux_boot = (kernel_filename != NULL); | |
183 | ||
184 | kernel_size = 0; | |
185 | if (linux_boot) { | |
ca20cf32 BS |
186 | int bswap_needed; |
187 | ||
188 | #ifdef BSWAP_NEEDED | |
189 | bswap_needed = 1; | |
190 | #else | |
191 | bswap_needed = 0; | |
192 | #endif | |
5f2bf0fe | 193 | kernel_size = load_elf(kernel_filename, NULL, NULL, kernel_entry, |
7ef295ea | 194 | kernel_addr, &kernel_top, 1, EM_SPARCV9, 0, 0); |
5f2bf0fe BS |
195 | if (kernel_size < 0) { |
196 | *kernel_addr = KERNEL_LOAD_ADDR; | |
197 | *kernel_entry = KERNEL_LOAD_ADDR; | |
636aa70a | 198 | kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR, |
ca20cf32 BS |
199 | RAM_size - KERNEL_LOAD_ADDR, bswap_needed, |
200 | TARGET_PAGE_SIZE); | |
5f2bf0fe BS |
201 | } |
202 | if (kernel_size < 0) { | |
636aa70a BS |
203 | kernel_size = load_image_targphys(kernel_filename, |
204 | KERNEL_LOAD_ADDR, | |
205 | RAM_size - KERNEL_LOAD_ADDR); | |
5f2bf0fe | 206 | } |
636aa70a BS |
207 | if (kernel_size < 0) { |
208 | fprintf(stderr, "qemu: could not load kernel '%s'\n", | |
209 | kernel_filename); | |
210 | exit(1); | |
211 | } | |
5f2bf0fe | 212 | /* load initrd above kernel */ |
636aa70a BS |
213 | *initrd_size = 0; |
214 | if (initrd_filename) { | |
5f2bf0fe BS |
215 | *initrd_addr = TARGET_PAGE_ALIGN(kernel_top); |
216 | ||
636aa70a | 217 | *initrd_size = load_image_targphys(initrd_filename, |
5f2bf0fe BS |
218 | *initrd_addr, |
219 | RAM_size - *initrd_addr); | |
220 | if ((int)*initrd_size < 0) { | |
636aa70a BS |
221 | fprintf(stderr, "qemu: could not load initial ram disk '%s'\n", |
222 | initrd_filename); | |
223 | exit(1); | |
224 | } | |
225 | } | |
226 | if (*initrd_size > 0) { | |
227 | for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) { | |
5f2bf0fe | 228 | ptr = rom_ptr(*kernel_addr + i); |
6908d9ce | 229 | if (ldl_p(ptr + 8) == 0x48647253) { /* HdrS */ |
5f2bf0fe | 230 | stl_p(ptr + 24, *initrd_addr + *kernel_addr); |
6908d9ce | 231 | stl_p(ptr + 28, *initrd_size); |
636aa70a BS |
232 | break; |
233 | } | |
234 | } | |
235 | } | |
236 | } | |
237 | return kernel_size; | |
238 | } | |
3475187d | 239 | |
98cec4a2 | 240 | void cpu_check_irqs(CPUSPARCState *env) |
9d926598 | 241 | { |
259186a7 | 242 | CPUState *cs; |
d532b26c IK |
243 | uint32_t pil = env->pil_in | |
244 | (env->softint & ~(SOFTINT_TIMER | SOFTINT_STIMER)); | |
245 | ||
a7be9bad AT |
246 | /* TT_IVEC has a higher priority (16) than TT_EXTINT (31..17) */ |
247 | if (env->ivec_status & 0x20) { | |
248 | return; | |
249 | } | |
259186a7 | 250 | cs = CPU(sparc_env_get_cpu(env)); |
d532b26c IK |
251 | /* check if TM or SM in SOFTINT are set |
252 | setting these also causes interrupt 14 */ | |
253 | if (env->softint & (SOFTINT_TIMER | SOFTINT_STIMER)) { | |
254 | pil |= 1 << 14; | |
255 | } | |
256 | ||
9f94778c AT |
257 | /* The bit corresponding to psrpil is (1<< psrpil), the next bit |
258 | is (2 << psrpil). */ | |
259 | if (pil < (2 << env->psrpil)){ | |
259186a7 | 260 | if (cs->interrupt_request & CPU_INTERRUPT_HARD) { |
d532b26c IK |
261 | CPUIRQ_DPRINTF("Reset CPU IRQ (current interrupt %x)\n", |
262 | env->interrupt_index); | |
263 | env->interrupt_index = 0; | |
d8ed887b | 264 | cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); |
d532b26c IK |
265 | } |
266 | return; | |
267 | } | |
268 | ||
269 | if (cpu_interrupts_enabled(env)) { | |
9d926598 | 270 | |
9d926598 BS |
271 | unsigned int i; |
272 | ||
d532b26c | 273 | for (i = 15; i > env->psrpil; i--) { |
9d926598 BS |
274 | if (pil & (1 << i)) { |
275 | int old_interrupt = env->interrupt_index; | |
d532b26c IK |
276 | int new_interrupt = TT_EXTINT | i; |
277 | ||
a7be9bad AT |
278 | if (unlikely(env->tl > 0 && cpu_tsptr(env)->tt > new_interrupt |
279 | && ((cpu_tsptr(env)->tt & 0x1f0) == TT_EXTINT))) { | |
d532b26c IK |
280 | CPUIRQ_DPRINTF("Not setting CPU IRQ: TL=%d " |
281 | "current %x >= pending %x\n", | |
282 | env->tl, cpu_tsptr(env)->tt, new_interrupt); | |
283 | } else if (old_interrupt != new_interrupt) { | |
284 | env->interrupt_index = new_interrupt; | |
285 | CPUIRQ_DPRINTF("Set CPU IRQ %d old=%x new=%x\n", i, | |
286 | old_interrupt, new_interrupt); | |
c3affe56 | 287 | cpu_interrupt(cs, CPU_INTERRUPT_HARD); |
9d926598 BS |
288 | } |
289 | break; | |
290 | } | |
291 | } | |
259186a7 | 292 | } else if (cs->interrupt_request & CPU_INTERRUPT_HARD) { |
d532b26c IK |
293 | CPUIRQ_DPRINTF("Interrupts disabled, pil=%08x pil_in=%08x softint=%08x " |
294 | "current interrupt %x\n", | |
295 | pil, env->pil_in, env->softint, env->interrupt_index); | |
9f94778c | 296 | env->interrupt_index = 0; |
d8ed887b | 297 | cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); |
9d926598 BS |
298 | } |
299 | } | |
300 | ||
ce18c558 | 301 | static void cpu_kick_irq(SPARCCPU *cpu) |
8f4efc55 | 302 | { |
259186a7 | 303 | CPUState *cs = CPU(cpu); |
ce18c558 AF |
304 | CPUSPARCState *env = &cpu->env; |
305 | ||
259186a7 | 306 | cs->halted = 0; |
8f4efc55 | 307 | cpu_check_irqs(env); |
259186a7 | 308 | qemu_cpu_kick(cs); |
8f4efc55 IK |
309 | } |
310 | ||
361dea40 | 311 | static void cpu_set_ivec_irq(void *opaque, int irq, int level) |
9d926598 | 312 | { |
b64ba4b2 AF |
313 | SPARCCPU *cpu = opaque; |
314 | CPUSPARCState *env = &cpu->env; | |
259186a7 | 315 | CPUState *cs; |
9d926598 BS |
316 | |
317 | if (level) { | |
23cf96e1 AT |
318 | if (!(env->ivec_status & 0x20)) { |
319 | CPUIRQ_DPRINTF("Raise IVEC IRQ %d\n", irq); | |
259186a7 AF |
320 | cs = CPU(cpu); |
321 | cs->halted = 0; | |
23cf96e1 AT |
322 | env->interrupt_index = TT_IVEC; |
323 | env->ivec_status |= 0x20; | |
324 | env->ivec_data[0] = (0x1f << 6) | irq; | |
325 | env->ivec_data[1] = 0; | |
326 | env->ivec_data[2] = 0; | |
c3affe56 | 327 | cpu_interrupt(cs, CPU_INTERRUPT_HARD); |
23cf96e1 AT |
328 | } |
329 | } else { | |
330 | if (env->ivec_status & 0x20) { | |
331 | CPUIRQ_DPRINTF("Lower IVEC IRQ %d\n", irq); | |
d8ed887b | 332 | cs = CPU(cpu); |
23cf96e1 | 333 | env->ivec_status &= ~0x20; |
d8ed887b | 334 | cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD); |
23cf96e1 | 335 | } |
9d926598 BS |
336 | } |
337 | } | |
338 | ||
e87231d4 | 339 | typedef struct ResetData { |
403d7a2d | 340 | SPARCCPU *cpu; |
44a99354 | 341 | uint64_t prom_addr; |
e87231d4 BS |
342 | } ResetData; |
343 | ||
6b678e1f | 344 | static CPUTimer *cpu_timer_create(const char *name, SPARCCPU *cpu, |
8f4efc55 | 345 | QEMUBHFunc *cb, uint32_t frequency, |
e913cac7 | 346 | uint64_t disabled_mask, uint64_t npt_mask) |
8f4efc55 | 347 | { |
7267c094 | 348 | CPUTimer *timer = g_malloc0(sizeof (CPUTimer)); |
8f4efc55 IK |
349 | |
350 | timer->name = name; | |
351 | timer->frequency = frequency; | |
352 | timer->disabled_mask = disabled_mask; | |
e913cac7 | 353 | timer->npt_mask = npt_mask; |
8f4efc55 IK |
354 | |
355 | timer->disabled = 1; | |
e913cac7 | 356 | timer->npt = 1; |
bc72ad67 | 357 | timer->clock_offset = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
8f4efc55 | 358 | |
bc72ad67 | 359 | timer->qtimer = timer_new_ns(QEMU_CLOCK_VIRTUAL, cb, cpu); |
8f4efc55 IK |
360 | |
361 | return timer; | |
362 | } | |
363 | ||
364 | static void cpu_timer_reset(CPUTimer *timer) | |
365 | { | |
366 | timer->disabled = 1; | |
bc72ad67 | 367 | timer->clock_offset = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
8f4efc55 | 368 | |
bc72ad67 | 369 | timer_del(timer->qtimer); |
8f4efc55 IK |
370 | } |
371 | ||
c68ea704 FB |
372 | static void main_cpu_reset(void *opaque) |
373 | { | |
e87231d4 | 374 | ResetData *s = (ResetData *)opaque; |
403d7a2d | 375 | CPUSPARCState *env = &s->cpu->env; |
44a99354 | 376 | static unsigned int nr_resets; |
20c9f095 | 377 | |
403d7a2d | 378 | cpu_reset(CPU(s->cpu)); |
8f4efc55 IK |
379 | |
380 | cpu_timer_reset(env->tick); | |
381 | cpu_timer_reset(env->stick); | |
382 | cpu_timer_reset(env->hstick); | |
383 | ||
e87231d4 BS |
384 | env->gregs[1] = 0; // Memory start |
385 | env->gregs[2] = ram_size; // Memory size | |
386 | env->gregs[3] = 0; // Machine description XXX | |
44a99354 BS |
387 | if (nr_resets++ == 0) { |
388 | /* Power on reset */ | |
389 | env->pc = s->prom_addr + 0x20ULL; | |
390 | } else { | |
391 | env->pc = s->prom_addr + 0x40ULL; | |
392 | } | |
e87231d4 | 393 | env->npc = env->pc + 4; |
20c9f095 BS |
394 | } |
395 | ||
22548760 | 396 | static void tick_irq(void *opaque) |
20c9f095 | 397 | { |
6b678e1f AF |
398 | SPARCCPU *cpu = opaque; |
399 | CPUSPARCState *env = &cpu->env; | |
20c9f095 | 400 | |
8f4efc55 IK |
401 | CPUTimer* timer = env->tick; |
402 | ||
403 | if (timer->disabled) { | |
404 | CPUIRQ_DPRINTF("tick_irq: softint disabled\n"); | |
405 | return; | |
406 | } else { | |
407 | CPUIRQ_DPRINTF("tick: fire\n"); | |
8fa211e8 | 408 | } |
8f4efc55 IK |
409 | |
410 | env->softint |= SOFTINT_TIMER; | |
ce18c558 | 411 | cpu_kick_irq(cpu); |
20c9f095 BS |
412 | } |
413 | ||
22548760 | 414 | static void stick_irq(void *opaque) |
20c9f095 | 415 | { |
6b678e1f AF |
416 | SPARCCPU *cpu = opaque; |
417 | CPUSPARCState *env = &cpu->env; | |
20c9f095 | 418 | |
8f4efc55 IK |
419 | CPUTimer* timer = env->stick; |
420 | ||
421 | if (timer->disabled) { | |
422 | CPUIRQ_DPRINTF("stick_irq: softint disabled\n"); | |
423 | return; | |
424 | } else { | |
425 | CPUIRQ_DPRINTF("stick: fire\n"); | |
8fa211e8 | 426 | } |
8f4efc55 IK |
427 | |
428 | env->softint |= SOFTINT_STIMER; | |
ce18c558 | 429 | cpu_kick_irq(cpu); |
20c9f095 BS |
430 | } |
431 | ||
22548760 | 432 | static void hstick_irq(void *opaque) |
20c9f095 | 433 | { |
6b678e1f AF |
434 | SPARCCPU *cpu = opaque; |
435 | CPUSPARCState *env = &cpu->env; | |
20c9f095 | 436 | |
8f4efc55 IK |
437 | CPUTimer* timer = env->hstick; |
438 | ||
439 | if (timer->disabled) { | |
440 | CPUIRQ_DPRINTF("hstick_irq: softint disabled\n"); | |
441 | return; | |
442 | } else { | |
443 | CPUIRQ_DPRINTF("hstick: fire\n"); | |
8fa211e8 | 444 | } |
8f4efc55 IK |
445 | |
446 | env->softint |= SOFTINT_STIMER; | |
ce18c558 | 447 | cpu_kick_irq(cpu); |
8f4efc55 IK |
448 | } |
449 | ||
450 | static int64_t cpu_to_timer_ticks(int64_t cpu_ticks, uint32_t frequency) | |
451 | { | |
73bcb24d | 452 | return muldiv64(cpu_ticks, NANOSECONDS_PER_SECOND, frequency); |
8f4efc55 IK |
453 | } |
454 | ||
455 | static uint64_t timer_to_cpu_ticks(int64_t timer_ticks, uint32_t frequency) | |
456 | { | |
73bcb24d | 457 | return muldiv64(timer_ticks, frequency, NANOSECONDS_PER_SECOND); |
c68ea704 FB |
458 | } |
459 | ||
8f4efc55 | 460 | void cpu_tick_set_count(CPUTimer *timer, uint64_t count) |
f4b1a842 | 461 | { |
bf43330a MCA |
462 | uint64_t real_count = count & ~timer->npt_mask; |
463 | uint64_t npt_bit = count & timer->npt_mask; | |
8f4efc55 | 464 | |
bc72ad67 | 465 | int64_t vm_clock_offset = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - |
8f4efc55 IK |
466 | cpu_to_timer_ticks(real_count, timer->frequency); |
467 | ||
bf43330a | 468 | TIMER_DPRINTF("%s set_count count=0x%016lx (npt %s) p=%p\n", |
8f4efc55 | 469 | timer->name, real_count, |
bf43330a | 470 | timer->npt ? "disabled" : "enabled", timer); |
8f4efc55 | 471 | |
bf43330a | 472 | timer->npt = npt_bit ? 1 : 0; |
8f4efc55 | 473 | timer->clock_offset = vm_clock_offset; |
f4b1a842 BS |
474 | } |
475 | ||
8f4efc55 | 476 | uint64_t cpu_tick_get_count(CPUTimer *timer) |
f4b1a842 | 477 | { |
8f4efc55 | 478 | uint64_t real_count = timer_to_cpu_ticks( |
bc72ad67 | 479 | qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - timer->clock_offset, |
8f4efc55 IK |
480 | timer->frequency); |
481 | ||
bf43330a | 482 | TIMER_DPRINTF("%s get_count count=0x%016lx (npt %s) p=%p\n", |
8f4efc55 | 483 | timer->name, real_count, |
bf43330a | 484 | timer->npt ? "disabled" : "enabled", timer); |
8f4efc55 | 485 | |
bf43330a MCA |
486 | if (timer->npt) { |
487 | real_count |= timer->npt_mask; | |
488 | } | |
8f4efc55 IK |
489 | |
490 | return real_count; | |
f4b1a842 BS |
491 | } |
492 | ||
8f4efc55 | 493 | void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit) |
f4b1a842 | 494 | { |
bc72ad67 | 495 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
8f4efc55 IK |
496 | |
497 | uint64_t real_limit = limit & ~timer->disabled_mask; | |
498 | timer->disabled = (limit & timer->disabled_mask) ? 1 : 0; | |
499 | ||
500 | int64_t expires = cpu_to_timer_ticks(real_limit, timer->frequency) + | |
501 | timer->clock_offset; | |
502 | ||
503 | if (expires < now) { | |
504 | expires = now + 1; | |
505 | } | |
506 | ||
507 | TIMER_DPRINTF("%s set_limit limit=0x%016lx (%s) p=%p " | |
508 | "called with limit=0x%016lx at 0x%016lx (delta=0x%016lx)\n", | |
509 | timer->name, real_limit, | |
510 | timer->disabled?"disabled":"enabled", | |
511 | timer, limit, | |
512 | timer_to_cpu_ticks(now - timer->clock_offset, | |
513 | timer->frequency), | |
514 | timer_to_cpu_ticks(expires - now, timer->frequency)); | |
515 | ||
516 | if (!real_limit) { | |
517 | TIMER_DPRINTF("%s set_limit limit=ZERO - not starting timer\n", | |
518 | timer->name); | |
bc72ad67 | 519 | timer_del(timer->qtimer); |
8f4efc55 | 520 | } else if (timer->disabled) { |
bc72ad67 | 521 | timer_del(timer->qtimer); |
8f4efc55 | 522 | } else { |
bc72ad67 | 523 | timer_mod(timer->qtimer, expires); |
8f4efc55 | 524 | } |
f4b1a842 BS |
525 | } |
526 | ||
361dea40 | 527 | static void isa_irq_handler(void *opaque, int n, int level) |
1387fe4a | 528 | { |
361dea40 BS |
529 | static const int isa_irq_to_ivec[16] = { |
530 | [1] = 0x29, /* keyboard */ | |
531 | [4] = 0x2b, /* serial */ | |
532 | [6] = 0x27, /* floppy */ | |
533 | [7] = 0x22, /* parallel */ | |
534 | [12] = 0x2a, /* mouse */ | |
535 | }; | |
536 | qemu_irq *irqs = opaque; | |
537 | int ivec; | |
538 | ||
539 | assert(n < 16); | |
540 | ivec = isa_irq_to_ivec[n]; | |
541 | EBUS_DPRINTF("Set ISA IRQ %d level %d -> ivec 0x%x\n", n, level, ivec); | |
542 | if (ivec) { | |
543 | qemu_set_irq(irqs[ivec], level); | |
544 | } | |
1387fe4a BS |
545 | } |
546 | ||
c190ea07 | 547 | /* EBUS (Eight bit bus) bridge */ |
48a18b3c | 548 | static ISABus * |
361dea40 | 549 | pci_ebus_init(PCIBus *bus, int devfn, qemu_irq *irqs) |
c190ea07 | 550 | { |
1387fe4a | 551 | qemu_irq *isa_irq; |
ab953e28 | 552 | PCIDevice *pci_dev; |
48a18b3c | 553 | ISABus *isa_bus; |
1387fe4a | 554 | |
ab953e28 | 555 | pci_dev = pci_create_simple(bus, devfn, "ebus"); |
2ae0e48d | 556 | isa_bus = ISA_BUS(qdev_get_child_bus(DEVICE(pci_dev), "isa.0")); |
361dea40 | 557 | isa_irq = qemu_allocate_irqs(isa_irq_handler, irqs, 16); |
48a18b3c HP |
558 | isa_bus_irqs(isa_bus, isa_irq); |
559 | return isa_bus; | |
53e3c4f9 | 560 | } |
c190ea07 | 561 | |
3a80cead | 562 | static void pci_ebus_realize(PCIDevice *pci_dev, Error **errp) |
53e3c4f9 | 563 | { |
c5e6fb7e AK |
564 | EbusState *s = DO_UPCAST(EbusState, pci_dev, pci_dev); |
565 | ||
d10e5432 MA |
566 | if (!isa_bus_new(DEVICE(pci_dev), get_system_memory(), |
567 | pci_address_space_io(pci_dev), errp)) { | |
568 | return; | |
569 | } | |
c5e6fb7e AK |
570 | |
571 | pci_dev->config[0x04] = 0x06; // command = bus master, pci mem | |
572 | pci_dev->config[0x05] = 0x00; | |
573 | pci_dev->config[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error | |
574 | pci_dev->config[0x07] = 0x03; // status = medium devsel | |
575 | pci_dev->config[0x09] = 0x00; // programming i/f | |
576 | pci_dev->config[0x0D] = 0x0a; // latency_timer | |
577 | ||
0a70e094 PB |
578 | memory_region_init_alias(&s->bar0, OBJECT(s), "bar0", get_system_io(), |
579 | 0, 0x1000000); | |
e824b2cc | 580 | pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar0); |
0a70e094 | 581 | memory_region_init_alias(&s->bar1, OBJECT(s), "bar1", get_system_io(), |
f3b18f35 | 582 | 0, 0x4000); |
a1cf8be5 | 583 | pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->bar1); |
c190ea07 BS |
584 | } |
585 | ||
40021f08 AL |
586 | static void ebus_class_init(ObjectClass *klass, void *data) |
587 | { | |
588 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); | |
589 | ||
3a80cead | 590 | k->realize = pci_ebus_realize; |
40021f08 AL |
591 | k->vendor_id = PCI_VENDOR_ID_SUN; |
592 | k->device_id = PCI_DEVICE_ID_SUN_EBUS; | |
593 | k->revision = 0x01; | |
594 | k->class_id = PCI_CLASS_BRIDGE_OTHER; | |
595 | } | |
596 | ||
8c43a6f0 | 597 | static const TypeInfo ebus_info = { |
39bffca2 AL |
598 | .name = "ebus", |
599 | .parent = TYPE_PCI_DEVICE, | |
600 | .instance_size = sizeof(EbusState), | |
601 | .class_init = ebus_class_init, | |
53e3c4f9 BS |
602 | }; |
603 | ||
13575cf6 AF |
604 | #define TYPE_OPENPROM "openprom" |
605 | #define OPENPROM(obj) OBJECT_CHECK(PROMState, (obj), TYPE_OPENPROM) | |
606 | ||
d4edce38 | 607 | typedef struct PROMState { |
13575cf6 AF |
608 | SysBusDevice parent_obj; |
609 | ||
d4edce38 AK |
610 | MemoryRegion prom; |
611 | } PROMState; | |
612 | ||
409dbce5 AJ |
613 | static uint64_t translate_prom_address(void *opaque, uint64_t addr) |
614 | { | |
a8170e5e | 615 | hwaddr *base_addr = (hwaddr *)opaque; |
409dbce5 AJ |
616 | return addr + *base_addr - PROM_VADDR; |
617 | } | |
618 | ||
1baffa46 | 619 | /* Boot PROM (OpenBIOS) */ |
a8170e5e | 620 | static void prom_init(hwaddr addr, const char *bios_name) |
1baffa46 BS |
621 | { |
622 | DeviceState *dev; | |
623 | SysBusDevice *s; | |
624 | char *filename; | |
625 | int ret; | |
626 | ||
13575cf6 | 627 | dev = qdev_create(NULL, TYPE_OPENPROM); |
e23a1b33 | 628 | qdev_init_nofail(dev); |
1356b98d | 629 | s = SYS_BUS_DEVICE(dev); |
1baffa46 BS |
630 | |
631 | sysbus_mmio_map(s, 0, addr); | |
632 | ||
633 | /* load boot prom */ | |
634 | if (bios_name == NULL) { | |
635 | bios_name = PROM_FILENAME; | |
636 | } | |
637 | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); | |
638 | if (filename) { | |
409dbce5 | 639 | ret = load_elf(filename, translate_prom_address, &addr, |
7ef295ea | 640 | NULL, NULL, NULL, 1, EM_SPARCV9, 0, 0); |
1baffa46 BS |
641 | if (ret < 0 || ret > PROM_SIZE_MAX) { |
642 | ret = load_image_targphys(filename, addr, PROM_SIZE_MAX); | |
643 | } | |
7267c094 | 644 | g_free(filename); |
1baffa46 BS |
645 | } else { |
646 | ret = -1; | |
647 | } | |
648 | if (ret < 0 || ret > PROM_SIZE_MAX) { | |
649 | fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name); | |
650 | exit(1); | |
651 | } | |
652 | } | |
653 | ||
81a322d4 | 654 | static int prom_init1(SysBusDevice *dev) |
1baffa46 | 655 | { |
13575cf6 | 656 | PROMState *s = OPENPROM(dev); |
1baffa46 | 657 | |
49946538 | 658 | memory_region_init_ram(&s->prom, OBJECT(s), "sun4u.prom", PROM_SIZE_MAX, |
f8ed85ac | 659 | &error_fatal); |
c5705a77 | 660 | vmstate_register_ram_global(&s->prom); |
d4edce38 | 661 | memory_region_set_readonly(&s->prom, true); |
750ecd44 | 662 | sysbus_init_mmio(dev, &s->prom); |
81a322d4 | 663 | return 0; |
1baffa46 BS |
664 | } |
665 | ||
999e12bb AL |
666 | static Property prom_properties[] = { |
667 | {/* end of property list */}, | |
668 | }; | |
669 | ||
670 | static void prom_class_init(ObjectClass *klass, void *data) | |
671 | { | |
39bffca2 | 672 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb AL |
673 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
674 | ||
675 | k->init = prom_init1; | |
39bffca2 | 676 | dc->props = prom_properties; |
999e12bb AL |
677 | } |
678 | ||
8c43a6f0 | 679 | static const TypeInfo prom_info = { |
13575cf6 | 680 | .name = TYPE_OPENPROM, |
39bffca2 AL |
681 | .parent = TYPE_SYS_BUS_DEVICE, |
682 | .instance_size = sizeof(PROMState), | |
683 | .class_init = prom_class_init, | |
1baffa46 BS |
684 | }; |
685 | ||
bda42033 | 686 | |
88c034d5 AF |
687 | #define TYPE_SUN4U_MEMORY "memory" |
688 | #define SUN4U_RAM(obj) OBJECT_CHECK(RamDevice, (obj), TYPE_SUN4U_MEMORY) | |
689 | ||
690 | typedef struct RamDevice { | |
691 | SysBusDevice parent_obj; | |
692 | ||
d4edce38 | 693 | MemoryRegion ram; |
04843626 | 694 | uint64_t size; |
bda42033 BS |
695 | } RamDevice; |
696 | ||
697 | /* System RAM */ | |
81a322d4 | 698 | static int ram_init1(SysBusDevice *dev) |
bda42033 | 699 | { |
88c034d5 | 700 | RamDevice *d = SUN4U_RAM(dev); |
bda42033 | 701 | |
49946538 | 702 | memory_region_init_ram(&d->ram, OBJECT(d), "sun4u.ram", d->size, |
f8ed85ac | 703 | &error_fatal); |
c5705a77 | 704 | vmstate_register_ram_global(&d->ram); |
750ecd44 | 705 | sysbus_init_mmio(dev, &d->ram); |
81a322d4 | 706 | return 0; |
bda42033 BS |
707 | } |
708 | ||
a8170e5e | 709 | static void ram_init(hwaddr addr, ram_addr_t RAM_size) |
bda42033 BS |
710 | { |
711 | DeviceState *dev; | |
712 | SysBusDevice *s; | |
713 | RamDevice *d; | |
714 | ||
715 | /* allocate RAM */ | |
88c034d5 | 716 | dev = qdev_create(NULL, TYPE_SUN4U_MEMORY); |
1356b98d | 717 | s = SYS_BUS_DEVICE(dev); |
bda42033 | 718 | |
88c034d5 | 719 | d = SUN4U_RAM(dev); |
bda42033 | 720 | d->size = RAM_size; |
e23a1b33 | 721 | qdev_init_nofail(dev); |
bda42033 BS |
722 | |
723 | sysbus_mmio_map(s, 0, addr); | |
724 | } | |
725 | ||
999e12bb AL |
726 | static Property ram_properties[] = { |
727 | DEFINE_PROP_UINT64("size", RamDevice, size, 0), | |
728 | DEFINE_PROP_END_OF_LIST(), | |
729 | }; | |
730 | ||
731 | static void ram_class_init(ObjectClass *klass, void *data) | |
732 | { | |
39bffca2 | 733 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb AL |
734 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
735 | ||
736 | k->init = ram_init1; | |
39bffca2 | 737 | dc->props = ram_properties; |
999e12bb AL |
738 | } |
739 | ||
8c43a6f0 | 740 | static const TypeInfo ram_info = { |
88c034d5 | 741 | .name = TYPE_SUN4U_MEMORY, |
39bffca2 AL |
742 | .parent = TYPE_SYS_BUS_DEVICE, |
743 | .instance_size = sizeof(RamDevice), | |
744 | .class_init = ram_class_init, | |
bda42033 BS |
745 | }; |
746 | ||
f9d1465f | 747 | static SPARCCPU *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef) |
3475187d | 748 | { |
8ebdf9dc | 749 | SPARCCPU *cpu; |
98cec4a2 | 750 | CPUSPARCState *env; |
e87231d4 | 751 | ResetData *reset_info; |
3475187d | 752 | |
8f4efc55 IK |
753 | uint32_t tick_frequency = 100*1000000; |
754 | uint32_t stick_frequency = 100*1000000; | |
755 | uint32_t hstick_frequency = 100*1000000; | |
756 | ||
8ebdf9dc | 757 | if (cpu_model == NULL) { |
c7ba218d | 758 | cpu_model = hwdef->default_cpu_model; |
8ebdf9dc AF |
759 | } |
760 | cpu = cpu_sparc_init(cpu_model); | |
761 | if (cpu == NULL) { | |
62724a37 BS |
762 | fprintf(stderr, "Unable to find Sparc CPU definition\n"); |
763 | exit(1); | |
764 | } | |
8ebdf9dc | 765 | env = &cpu->env; |
20c9f095 | 766 | |
6b678e1f | 767 | env->tick = cpu_timer_create("tick", cpu, tick_irq, |
e913cac7 MCA |
768 | tick_frequency, TICK_INT_DIS, |
769 | TICK_NPT_MASK); | |
8f4efc55 | 770 | |
6b678e1f | 771 | env->stick = cpu_timer_create("stick", cpu, stick_irq, |
e913cac7 MCA |
772 | stick_frequency, TICK_INT_DIS, |
773 | TICK_NPT_MASK); | |
20c9f095 | 774 | |
6b678e1f | 775 | env->hstick = cpu_timer_create("hstick", cpu, hstick_irq, |
e913cac7 MCA |
776 | hstick_frequency, TICK_INT_DIS, |
777 | TICK_NPT_MASK); | |
e87231d4 | 778 | |
7267c094 | 779 | reset_info = g_malloc0(sizeof(ResetData)); |
403d7a2d | 780 | reset_info->cpu = cpu; |
44a99354 | 781 | reset_info->prom_addr = hwdef->prom_addr; |
a08d4367 | 782 | qemu_register_reset(main_cpu_reset, reset_info); |
c68ea704 | 783 | |
f9d1465f | 784 | return cpu; |
7b833f5b BS |
785 | } |
786 | ||
38bc50f7 | 787 | static void sun4uv_init(MemoryRegion *address_space_mem, |
3ef96221 | 788 | MachineState *machine, |
7b833f5b BS |
789 | const struct hwdef *hwdef) |
790 | { | |
f9d1465f | 791 | SPARCCPU *cpu; |
31688246 | 792 | Nvram *nvram; |
7b833f5b | 793 | unsigned int i; |
5f2bf0fe | 794 | uint64_t initrd_addr, initrd_size, kernel_addr, kernel_size, kernel_entry; |
7b833f5b | 795 | PCIBus *pci_bus, *pci_bus2, *pci_bus3; |
48a18b3c | 796 | ISABus *isa_bus; |
f3b18f35 | 797 | SysBusDevice *s; |
361dea40 | 798 | qemu_irq *ivec_irqs, *pbm_irqs; |
f455e98c | 799 | DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS]; |
fd8014e1 | 800 | DriveInfo *fd[MAX_FD]; |
c3ae40e1 | 801 | DeviceState *dev; |
a88b362c | 802 | FWCfgState *fw_cfg; |
7b833f5b | 803 | |
7b833f5b | 804 | /* init CPUs */ |
3ef96221 | 805 | cpu = cpu_devinit(machine->cpu_model, hwdef); |
7b833f5b | 806 | |
bda42033 | 807 | /* set up devices */ |
3ef96221 | 808 | ram_init(0, machine->ram_size); |
3475187d | 809 | |
1baffa46 | 810 | prom_init(hwdef->prom_addr, bios_name); |
3475187d | 811 | |
b64ba4b2 | 812 | ivec_irqs = qemu_allocate_irqs(cpu_set_ivec_irq, cpu, IVEC_MAX); |
361dea40 BS |
813 | pci_bus = pci_apb_init(APB_SPECIAL_BASE, APB_MEM_BASE, ivec_irqs, &pci_bus2, |
814 | &pci_bus3, &pbm_irqs); | |
f2898771 | 815 | pci_vga_init(pci_bus); |
83469015 | 816 | |
c190ea07 | 817 | // XXX Should be pci_bus3 |
361dea40 | 818 | isa_bus = pci_ebus_init(pci_bus, -1, pbm_irqs); |
c190ea07 | 819 | |
e87231d4 BS |
820 | i = 0; |
821 | if (hwdef->console_serial_base) { | |
38bc50f7 | 822 | serial_mm_init(address_space_mem, hwdef->console_serial_base, 0, |
39186d8a | 823 | NULL, 115200, serial_hds[i], DEVICE_BIG_ENDIAN); |
e87231d4 BS |
824 | i++; |
825 | } | |
83469015 | 826 | |
4496dc49 | 827 | serial_hds_isa_init(isa_bus, i, MAX_SERIAL_PORTS); |
07dc7880 | 828 | parallel_hds_isa_init(isa_bus, MAX_PARALLEL_PORTS); |
83469015 | 829 | |
cb457d76 | 830 | for(i = 0; i < nb_nics; i++) |
29b358f9 | 831 | pci_nic_init_nofail(&nd_table[i], pci_bus, "ne2k_pci", NULL); |
83469015 | 832 | |
d8f94e1b | 833 | ide_drive_get(hd, ARRAY_SIZE(hd)); |
e4bcb14c | 834 | |
3b898dda BS |
835 | pci_cmd646_ide_init(pci_bus, hd, 1); |
836 | ||
48a18b3c | 837 | isa_create_simple(isa_bus, "i8042"); |
c3ae40e1 HP |
838 | |
839 | /* Floppy */ | |
e4bcb14c | 840 | for(i = 0; i < MAX_FD; i++) { |
fd8014e1 | 841 | fd[i] = drive_get(IF_FLOPPY, 0, i); |
e4bcb14c | 842 | } |
c3ae40e1 HP |
843 | dev = DEVICE(isa_create(isa_bus, TYPE_ISA_FDC)); |
844 | if (fd[0]) { | |
845 | qdev_prop_set_drive(dev, "driveA", blk_by_legacy_dinfo(fd[0]), | |
846 | &error_abort); | |
847 | } | |
848 | if (fd[1]) { | |
849 | qdev_prop_set_drive(dev, "driveB", blk_by_legacy_dinfo(fd[1]), | |
850 | &error_abort); | |
851 | } | |
852 | qdev_prop_set_uint32(dev, "dma", -1); | |
853 | qdev_init_nofail(dev); | |
636aa70a | 854 | |
f3b18f35 MCA |
855 | /* Map NVRAM into I/O (ebus) space */ |
856 | nvram = m48t59_init(NULL, 0, 0, NVRAM_SIZE, 1968, 59); | |
857 | s = SYS_BUS_DEVICE(nvram); | |
858 | memory_region_add_subregion(get_system_io(), 0x2000, | |
859 | sysbus_mmio_get_region(s, 0)); | |
860 | ||
636aa70a | 861 | initrd_size = 0; |
5f2bf0fe | 862 | initrd_addr = 0; |
3ef96221 MA |
863 | kernel_size = sun4u_load_kernel(machine->kernel_filename, |
864 | machine->initrd_filename, | |
5f2bf0fe BS |
865 | ram_size, &initrd_size, &initrd_addr, |
866 | &kernel_addr, &kernel_entry); | |
636aa70a | 867 | |
3ef96221 MA |
868 | sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", machine->ram_size, |
869 | machine->boot_order, | |
5f2bf0fe | 870 | kernel_addr, kernel_size, |
3ef96221 | 871 | machine->kernel_cmdline, |
5f2bf0fe | 872 | initrd_addr, initrd_size, |
0d31cb99 BS |
873 | /* XXX: need an option to load a NVRAM image */ |
874 | 0, | |
875 | graphic_width, graphic_height, graphic_depth, | |
876 | (uint8_t *)&nd_table[0].macaddr); | |
83469015 | 877 | |
66708822 | 878 | fw_cfg = fw_cfg_init_io(BIOS_CFG_IOPORT); |
70db9222 | 879 | fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus); |
905fdcb5 BS |
880 | fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); |
881 | fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id); | |
5f2bf0fe BS |
882 | fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry); |
883 | fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size); | |
3ef96221 | 884 | if (machine->kernel_cmdline) { |
9c9b0512 | 885 | fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, |
3ef96221 MA |
886 | strlen(machine->kernel_cmdline) + 1); |
887 | fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, machine->kernel_cmdline); | |
513f789f | 888 | } else { |
9c9b0512 | 889 | fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0); |
513f789f | 890 | } |
5f2bf0fe BS |
891 | fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr); |
892 | fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size); | |
3ef96221 | 893 | fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, machine->boot_order[0]); |
7589690c BS |
894 | |
895 | fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width); | |
896 | fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height); | |
897 | fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth); | |
898 | ||
513f789f | 899 | qemu_register_boot_set(fw_cfg_boot_set, fw_cfg); |
3475187d FB |
900 | } |
901 | ||
905fdcb5 BS |
902 | enum { |
903 | sun4u_id = 0, | |
904 | sun4v_id = 64, | |
e87231d4 | 905 | niagara_id, |
905fdcb5 BS |
906 | }; |
907 | ||
c7ba218d BS |
908 | static const struct hwdef hwdefs[] = { |
909 | /* Sun4u generic PC-like machine */ | |
910 | { | |
5910b047 | 911 | .default_cpu_model = "TI UltraSparc IIi", |
905fdcb5 | 912 | .machine_id = sun4u_id, |
e87231d4 BS |
913 | .prom_addr = 0x1fff0000000ULL, |
914 | .console_serial_base = 0, | |
c7ba218d BS |
915 | }, |
916 | /* Sun4v generic PC-like machine */ | |
917 | { | |
918 | .default_cpu_model = "Sun UltraSparc T1", | |
905fdcb5 | 919 | .machine_id = sun4v_id, |
e87231d4 BS |
920 | .prom_addr = 0x1fff0000000ULL, |
921 | .console_serial_base = 0, | |
922 | }, | |
923 | /* Sun4v generic Niagara machine */ | |
924 | { | |
925 | .default_cpu_model = "Sun UltraSparc T1", | |
926 | .machine_id = niagara_id, | |
927 | .prom_addr = 0xfff0000000ULL, | |
928 | .console_serial_base = 0xfff0c2c000ULL, | |
c7ba218d BS |
929 | }, |
930 | }; | |
931 | ||
932 | /* Sun4u hardware initialisation */ | |
3ef96221 | 933 | static void sun4u_init(MachineState *machine) |
5f072e1f | 934 | { |
3ef96221 | 935 | sun4uv_init(get_system_memory(), machine, &hwdefs[0]); |
c7ba218d BS |
936 | } |
937 | ||
938 | /* Sun4v hardware initialisation */ | |
3ef96221 | 939 | static void sun4v_init(MachineState *machine) |
5f072e1f | 940 | { |
3ef96221 | 941 | sun4uv_init(get_system_memory(), machine, &hwdefs[1]); |
c7ba218d BS |
942 | } |
943 | ||
e87231d4 | 944 | /* Niagara hardware initialisation */ |
3ef96221 | 945 | static void niagara_init(MachineState *machine) |
5f072e1f | 946 | { |
3ef96221 | 947 | sun4uv_init(get_system_memory(), machine, &hwdefs[2]); |
e87231d4 BS |
948 | } |
949 | ||
8a661aea | 950 | static void sun4u_class_init(ObjectClass *oc, void *data) |
e264d29d | 951 | { |
8a661aea AF |
952 | MachineClass *mc = MACHINE_CLASS(oc); |
953 | ||
e264d29d EH |
954 | mc->desc = "Sun4u platform"; |
955 | mc->init = sun4u_init; | |
956 | mc->max_cpus = 1; /* XXX for now */ | |
957 | mc->is_default = 1; | |
958 | mc->default_boot_order = "c"; | |
959 | } | |
c7ba218d | 960 | |
8a661aea AF |
961 | static const TypeInfo sun4u_type = { |
962 | .name = MACHINE_TYPE_NAME("sun4u"), | |
963 | .parent = TYPE_MACHINE, | |
964 | .class_init = sun4u_class_init, | |
965 | }; | |
e87231d4 | 966 | |
8a661aea | 967 | static void sun4v_class_init(ObjectClass *oc, void *data) |
e264d29d | 968 | { |
8a661aea AF |
969 | MachineClass *mc = MACHINE_CLASS(oc); |
970 | ||
e264d29d EH |
971 | mc->desc = "Sun4v platform"; |
972 | mc->init = sun4v_init; | |
973 | mc->max_cpus = 1; /* XXX for now */ | |
974 | mc->default_boot_order = "c"; | |
975 | } | |
976 | ||
8a661aea AF |
977 | static const TypeInfo sun4v_type = { |
978 | .name = MACHINE_TYPE_NAME("sun4v"), | |
979 | .parent = TYPE_MACHINE, | |
980 | .class_init = sun4v_class_init, | |
981 | }; | |
e264d29d | 982 | |
8a661aea | 983 | static void niagara_class_init(ObjectClass *oc, void *data) |
e264d29d | 984 | { |
8a661aea AF |
985 | MachineClass *mc = MACHINE_CLASS(oc); |
986 | ||
e264d29d EH |
987 | mc->desc = "Sun4v platform, Niagara"; |
988 | mc->init = niagara_init; | |
989 | mc->max_cpus = 1; /* XXX for now */ | |
990 | mc->default_boot_order = "c"; | |
991 | } | |
992 | ||
8a661aea AF |
993 | static const TypeInfo niagara_type = { |
994 | .name = MACHINE_TYPE_NAME("Niagara"), | |
995 | .parent = TYPE_MACHINE, | |
996 | .class_init = niagara_class_init, | |
997 | }; | |
f80f9ec9 | 998 | |
83f7d43a AF |
999 | static void sun4u_register_types(void) |
1000 | { | |
1001 | type_register_static(&ebus_info); | |
1002 | type_register_static(&prom_info); | |
1003 | type_register_static(&ram_info); | |
83f7d43a | 1004 | |
8a661aea AF |
1005 | type_register_static(&sun4u_type); |
1006 | type_register_static(&sun4v_type); | |
1007 | type_register_static(&niagara_type); | |
1008 | } | |
1009 | ||
83f7d43a | 1010 | type_init(sun4u_register_types) |