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