]> Git Repo - qemu.git/blame - hw/sparc64/sun4u.c
cpus: ignore ESRCH in qemu_cpu_kick_thread()
[qemu.git] / hw / sparc64 / sun4u.c
CommitLineData
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"
0a2e467b 25#include "qemu/units.h"
29bd7231 26#include "qemu/error-report.h"
da34e65c 27#include "qapi/error.h"
4771d756
PB
28#include "qemu-common.h"
29#include "cpu.h"
83c9f4ca
PB
30#include "hw/hw.h"
31#include "hw/pci/pci.h"
4272ad40 32#include "hw/pci/pci_bridge.h"
6864fa38 33#include "hw/pci/pci_bus.h"
0ea833c2 34#include "hw/pci/pci_host.h"
9b301794 35#include "hw/pci-host/sabre.h"
0d09e41a
PB
36#include "hw/i386/pc.h"
37#include "hw/char/serial.h"
bb3d5ea8 38#include "hw/char/parallel.h"
0d09e41a 39#include "hw/timer/m48t59.h"
47973a2d 40#include "hw/input/i8042.h"
0d09e41a 41#include "hw/block/fdc.h"
1422e32d 42#include "net/net.h"
1de7afc9 43#include "qemu/timer.h"
9c17d615 44#include "sysemu/sysemu.h"
83c9f4ca 45#include "hw/boards.h"
c6363bae 46#include "hw/nvram/sun_nvram.h"
2024c014 47#include "hw/nvram/chrp_nvram.h"
fff54d22 48#include "hw/sparc/sparc64.h"
0d09e41a 49#include "hw/nvram/fw_cfg.h"
83c9f4ca
PB
50#include "hw/sysbus.h"
51#include "hw/ide.h"
6864fa38 52#include "hw/ide/pci.h"
83c9f4ca 53#include "hw/loader.h"
0a1d5c45 54#include "hw/fw-path-provider.h"
ca20cf32 55#include "elf.h"
69520948 56#include "trace.h"
3475187d 57
83469015
FB
58#define KERNEL_LOAD_ADDR 0x00404000
59#define CMDLINE_ADDR 0x003ff000
0a2e467b 60#define PROM_SIZE_MAX (4 * MiB)
f930d07e 61#define PROM_VADDR 0x000ffd00000ULL
5795162a
MCA
62#define PBM_SPECIAL_BASE 0x1fe00000000ULL
63#define PBM_MEM_BASE 0x1ff00000000ULL
64#define PBM_PCI_IO_BASE (PBM_SPECIAL_BASE + 0x02000000ULL)
f930d07e 65#define PROM_FILENAME "openbios-sparc64"
83469015 66#define NVRAM_SIZE 0x2000
e4bcb14c 67#define MAX_IDE_BUS 2
3cce6243 68#define BIOS_CFG_IOPORT 0x510
7589690c
BS
69#define FW_CFG_SPARC64_WIDTH (FW_CFG_ARCH_LOCAL + 0x00)
70#define FW_CFG_SPARC64_HEIGHT (FW_CFG_ARCH_LOCAL + 0x01)
71#define FW_CFG_SPARC64_DEPTH (FW_CFG_ARCH_LOCAL + 0x02)
3475187d 72
852e82f3 73#define IVEC_MAX 0x40
9d926598 74
c7ba218d 75struct hwdef {
905fdcb5 76 uint16_t machine_id;
e87231d4
BS
77 uint64_t prom_addr;
78 uint64_t console_serial_base;
c7ba218d
BS
79};
80
c5e6fb7e 81typedef struct EbusState {
ad6856e8
MCA
82 /*< private >*/
83 PCIDevice parent_obj;
84
8c40b8d9 85 ISABus *isa_bus;
4b10c8d7 86 qemu_irq isa_bus_irqs[ISA_NUM_IRQS];
0fe22ffb 87 uint64_t console_serial_base;
c5e6fb7e
AK
88 MemoryRegion bar0;
89 MemoryRegion bar1;
90} EbusState;
91
ad6856e8
MCA
92#define TYPE_EBUS "ebus"
93#define EBUS(obj) OBJECT_CHECK(EbusState, (obj), TYPE_EBUS)
94
ddcd5531
GA
95static void fw_cfg_boot_set(void *opaque, const char *boot_device,
96 Error **errp)
81864572 97{
48779e50 98 fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
81864572
BS
99}
100
31688246 101static int sun4u_NVRAM_set_params(Nvram *nvram, uint16_t NVRAM_size,
43a34704
BS
102 const char *arch, ram_addr_t RAM_size,
103 const char *boot_devices,
104 uint32_t kernel_image, uint32_t kernel_size,
105 const char *cmdline,
106 uint32_t initrd_image, uint32_t initrd_size,
107 uint32_t NVRAM_image,
108 int width, int height, int depth,
109 const uint8_t *macaddr)
83469015 110{
66508601 111 unsigned int i;
2024c014 112 int sysp_end;
d2c63fc1 113 uint8_t image[0x1ff0];
31688246 114 NvramClass *k = NVRAM_GET_CLASS(nvram);
d2c63fc1
BS
115
116 memset(image, '\0', sizeof(image));
117
2024c014
TH
118 /* OpenBIOS nvram variables partition */
119 sysp_end = chrp_nvram_create_system_partition(image, 0);
83469015 120
2024c014
TH
121 /* Free space partition */
122 chrp_nvram_create_free_partition(&image[sysp_end], 0x1fd0 - sysp_end);
d2c63fc1 123
0d31cb99
BS
124 Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr, 0x80);
125
31688246
HP
126 for (i = 0; i < sizeof(image); i++) {
127 (k->write)(nvram, i, image[i]);
128 }
66508601 129
83469015 130 return 0;
3475187d 131}
5f2bf0fe
BS
132
133static uint64_t sun4u_load_kernel(const char *kernel_filename,
134 const char *initrd_filename,
135 ram_addr_t RAM_size, uint64_t *initrd_size,
136 uint64_t *initrd_addr, uint64_t *kernel_addr,
137 uint64_t *kernel_entry)
636aa70a
BS
138{
139 int linux_boot;
140 unsigned int i;
141 long kernel_size;
6908d9ce 142 uint8_t *ptr;
3ac24188 143 uint64_t kernel_top = 0;
636aa70a
BS
144
145 linux_boot = (kernel_filename != NULL);
146
147 kernel_size = 0;
148 if (linux_boot) {
ca20cf32
BS
149 int bswap_needed;
150
151#ifdef BSWAP_NEEDED
152 bswap_needed = 1;
153#else
154 bswap_needed = 0;
155#endif
5f2bf0fe 156 kernel_size = load_elf(kernel_filename, NULL, NULL, kernel_entry,
7ef295ea 157 kernel_addr, &kernel_top, 1, EM_SPARCV9, 0, 0);
5f2bf0fe
BS
158 if (kernel_size < 0) {
159 *kernel_addr = KERNEL_LOAD_ADDR;
160 *kernel_entry = KERNEL_LOAD_ADDR;
636aa70a 161 kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
ca20cf32
BS
162 RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
163 TARGET_PAGE_SIZE);
5f2bf0fe
BS
164 }
165 if (kernel_size < 0) {
636aa70a
BS
166 kernel_size = load_image_targphys(kernel_filename,
167 KERNEL_LOAD_ADDR,
168 RAM_size - KERNEL_LOAD_ADDR);
5f2bf0fe 169 }
636aa70a 170 if (kernel_size < 0) {
29bd7231 171 error_report("could not load kernel '%s'", kernel_filename);
636aa70a
BS
172 exit(1);
173 }
5f2bf0fe 174 /* load initrd above kernel */
636aa70a 175 *initrd_size = 0;
3ac24188 176 if (initrd_filename && kernel_top) {
5f2bf0fe
BS
177 *initrd_addr = TARGET_PAGE_ALIGN(kernel_top);
178
636aa70a 179 *initrd_size = load_image_targphys(initrd_filename,
5f2bf0fe
BS
180 *initrd_addr,
181 RAM_size - *initrd_addr);
182 if ((int)*initrd_size < 0) {
29bd7231
AF
183 error_report("could not load initial ram disk '%s'",
184 initrd_filename);
636aa70a
BS
185 exit(1);
186 }
187 }
188 if (*initrd_size > 0) {
189 for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
0f0f8b61
TH
190 ptr = rom_ptr(*kernel_addr + i, 32);
191 if (ptr && ldl_p(ptr + 8) == 0x48647253) { /* HdrS */
5f2bf0fe 192 stl_p(ptr + 24, *initrd_addr + *kernel_addr);
6908d9ce 193 stl_p(ptr + 28, *initrd_size);
636aa70a
BS
194 break;
195 }
196 }
197 }
198 }
199 return kernel_size;
200}
3475187d 201
e87231d4 202typedef struct ResetData {
403d7a2d 203 SPARCCPU *cpu;
44a99354 204 uint64_t prom_addr;
e87231d4
BS
205} ResetData;
206
25c5d5ac
MCA
207#define TYPE_SUN4U_POWER "power"
208#define SUN4U_POWER(obj) OBJECT_CHECK(PowerDevice, (obj), TYPE_SUN4U_POWER)
209
210typedef struct PowerDevice {
211 SysBusDevice parent_obj;
212
213 MemoryRegion power_mmio;
214} PowerDevice;
215
216/* Power */
217static void power_mem_write(void *opaque, hwaddr addr,
218 uint64_t val, unsigned size)
219{
220 /* According to a real Ultra 5, bit 24 controls the power */
221 if (val & 0x1000000) {
222 qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
223 }
224}
225
226static const MemoryRegionOps power_mem_ops = {
227 .write = power_mem_write,
228 .endianness = DEVICE_NATIVE_ENDIAN,
229 .valid = {
230 .min_access_size = 4,
231 .max_access_size = 4,
232 },
233};
234
235static void power_realize(DeviceState *dev, Error **errp)
236{
237 PowerDevice *d = SUN4U_POWER(dev);
238 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
239
240 memory_region_init_io(&d->power_mmio, OBJECT(dev), &power_mem_ops, d,
241 "power", sizeof(uint32_t));
242
243 sysbus_init_mmio(sbd, &d->power_mmio);
244}
245
246static void power_class_init(ObjectClass *klass, void *data)
247{
248 DeviceClass *dc = DEVICE_CLASS(klass);
249
250 dc->realize = power_realize;
251}
252
253static const TypeInfo power_info = {
254 .name = TYPE_SUN4U_POWER,
255 .parent = TYPE_SYS_BUS_DEVICE,
256 .instance_size = sizeof(PowerDevice),
257 .class_init = power_class_init,
258};
259
4b10c8d7 260static void ebus_isa_irq_handler(void *opaque, int n, int level)
1387fe4a 261{
4b10c8d7
MCA
262 EbusState *s = EBUS(opaque);
263 qemu_irq irq = s->isa_bus_irqs[n];
264
265 /* Pass ISA bus IRQs onto their gpio equivalent */
69520948 266 trace_ebus_isa_irq_handler(n, level);
4b10c8d7
MCA
267 if (irq) {
268 qemu_set_irq(irq, level);
361dea40 269 }
1387fe4a
BS
270}
271
c190ea07 272/* EBUS (Eight bit bus) bridge */
ad6856e8 273static void ebus_realize(PCIDevice *pci_dev, Error **errp)
53e3c4f9 274{
ad6856e8 275 EbusState *s = EBUS(pci_dev);
25c5d5ac 276 SysBusDevice *sbd;
0fe22ffb 277 DeviceState *dev;
c796edda 278 qemu_irq *isa_irq;
0fe22ffb
MCA
279 DriveInfo *fd[MAX_FD];
280 int i;
c5e6fb7e 281
8c40b8d9
MCA
282 s->isa_bus = isa_bus_new(DEVICE(pci_dev), get_system_memory(),
283 pci_address_space_io(pci_dev), errp);
284 if (!s->isa_bus) {
285 error_setg(errp, "unable to instantiate EBUS ISA bus");
d10e5432
MA
286 return;
287 }
c5e6fb7e 288
4b10c8d7
MCA
289 /* ISA bus */
290 isa_irq = qemu_allocate_irqs(ebus_isa_irq_handler, s, ISA_NUM_IRQS);
c796edda 291 isa_bus_irqs(s->isa_bus, isa_irq);
4b10c8d7
MCA
292 qdev_init_gpio_out_named(DEVICE(s), s->isa_bus_irqs, "isa-irq",
293 ISA_NUM_IRQS);
c796edda 294
0fe22ffb
MCA
295 /* Serial ports */
296 i = 0;
297 if (s->console_serial_base) {
298 serial_mm_init(pci_address_space(pci_dev), s->console_serial_base,
9bca0edb 299 0, NULL, 115200, serial_hd(i), DEVICE_BIG_ENDIAN);
0fe22ffb
MCA
300 i++;
301 }
def337ff 302 serial_hds_isa_init(s->isa_bus, i, MAX_ISA_SERIAL_PORTS);
0fe22ffb
MCA
303
304 /* Parallel ports */
305 parallel_hds_isa_init(s->isa_bus, MAX_PARALLEL_PORTS);
306
307 /* Keyboard */
308 isa_create_simple(s->isa_bus, "i8042");
309
310 /* Floppy */
311 for (i = 0; i < MAX_FD; i++) {
312 fd[i] = drive_get(IF_FLOPPY, 0, i);
313 }
314 dev = DEVICE(isa_create(s->isa_bus, TYPE_ISA_FDC));
315 if (fd[0]) {
316 qdev_prop_set_drive(dev, "driveA", blk_by_legacy_dinfo(fd[0]),
317 &error_abort);
318 }
319 if (fd[1]) {
320 qdev_prop_set_drive(dev, "driveB", blk_by_legacy_dinfo(fd[1]),
321 &error_abort);
322 }
323 qdev_prop_set_uint32(dev, "dma", -1);
324 qdev_init_nofail(dev);
325
25c5d5ac
MCA
326 /* Power */
327 dev = qdev_create(NULL, TYPE_SUN4U_POWER);
328 qdev_init_nofail(dev);
329 sbd = SYS_BUS_DEVICE(dev);
330 memory_region_add_subregion(pci_address_space_io(pci_dev), 0x7240,
331 sysbus_mmio_get_region(sbd, 0));
332
0fe22ffb 333 /* PCI */
c5e6fb7e
AK
334 pci_dev->config[0x04] = 0x06; // command = bus master, pci mem
335 pci_dev->config[0x05] = 0x00;
336 pci_dev->config[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
337 pci_dev->config[0x07] = 0x03; // status = medium devsel
338 pci_dev->config[0x09] = 0x00; // programming i/f
339 pci_dev->config[0x0D] = 0x0a; // latency_timer
340
0a70e094
PB
341 memory_region_init_alias(&s->bar0, OBJECT(s), "bar0", get_system_io(),
342 0, 0x1000000);
e824b2cc 343 pci_register_bar(pci_dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->bar0);
0a70e094 344 memory_region_init_alias(&s->bar1, OBJECT(s), "bar1", get_system_io(),
25c5d5ac 345 0, 0x8000);
a1cf8be5 346 pci_register_bar(pci_dev, 1, PCI_BASE_ADDRESS_SPACE_IO, &s->bar1);
c190ea07
BS
347}
348
0fe22ffb
MCA
349static Property ebus_properties[] = {
350 DEFINE_PROP_UINT64("console-serial-base", EbusState,
351 console_serial_base, 0),
352 DEFINE_PROP_END_OF_LIST(),
353};
354
40021f08
AL
355static void ebus_class_init(ObjectClass *klass, void *data)
356{
357 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
0fe22ffb 358 DeviceClass *dc = DEVICE_CLASS(klass);
40021f08 359
ad6856e8 360 k->realize = ebus_realize;
40021f08
AL
361 k->vendor_id = PCI_VENDOR_ID_SUN;
362 k->device_id = PCI_DEVICE_ID_SUN_EBUS;
363 k->revision = 0x01;
364 k->class_id = PCI_CLASS_BRIDGE_OTHER;
0fe22ffb 365 dc->props = ebus_properties;
40021f08
AL
366}
367
8c43a6f0 368static const TypeInfo ebus_info = {
ad6856e8 369 .name = TYPE_EBUS,
39bffca2 370 .parent = TYPE_PCI_DEVICE,
39bffca2 371 .class_init = ebus_class_init,
ad6856e8 372 .instance_size = sizeof(EbusState),
fd3b02c8
EH
373 .interfaces = (InterfaceInfo[]) {
374 { INTERFACE_CONVENTIONAL_PCI_DEVICE },
375 { },
376 },
53e3c4f9
BS
377};
378
13575cf6
AF
379#define TYPE_OPENPROM "openprom"
380#define OPENPROM(obj) OBJECT_CHECK(PROMState, (obj), TYPE_OPENPROM)
381
d4edce38 382typedef struct PROMState {
13575cf6
AF
383 SysBusDevice parent_obj;
384
d4edce38
AK
385 MemoryRegion prom;
386} PROMState;
387
409dbce5
AJ
388static uint64_t translate_prom_address(void *opaque, uint64_t addr)
389{
a8170e5e 390 hwaddr *base_addr = (hwaddr *)opaque;
409dbce5
AJ
391 return addr + *base_addr - PROM_VADDR;
392}
393
1baffa46 394/* Boot PROM (OpenBIOS) */
a8170e5e 395static void prom_init(hwaddr addr, const char *bios_name)
1baffa46
BS
396{
397 DeviceState *dev;
398 SysBusDevice *s;
399 char *filename;
400 int ret;
401
13575cf6 402 dev = qdev_create(NULL, TYPE_OPENPROM);
e23a1b33 403 qdev_init_nofail(dev);
1356b98d 404 s = SYS_BUS_DEVICE(dev);
1baffa46
BS
405
406 sysbus_mmio_map(s, 0, addr);
407
408 /* load boot prom */
409 if (bios_name == NULL) {
410 bios_name = PROM_FILENAME;
411 }
412 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
413 if (filename) {
409dbce5 414 ret = load_elf(filename, translate_prom_address, &addr,
7ef295ea 415 NULL, NULL, NULL, 1, EM_SPARCV9, 0, 0);
1baffa46
BS
416 if (ret < 0 || ret > PROM_SIZE_MAX) {
417 ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
418 }
7267c094 419 g_free(filename);
1baffa46
BS
420 } else {
421 ret = -1;
422 }
423 if (ret < 0 || ret > PROM_SIZE_MAX) {
29bd7231 424 error_report("could not load prom '%s'", bios_name);
1baffa46
BS
425 exit(1);
426 }
427}
428
92b19880 429static void prom_realize(DeviceState *ds, Error **errp)
1baffa46 430{
92b19880
TH
431 PROMState *s = OPENPROM(ds);
432 SysBusDevice *dev = SYS_BUS_DEVICE(ds);
433 Error *local_err = NULL;
434
435 memory_region_init_ram_nomigrate(&s->prom, OBJECT(ds), "sun4u.prom",
436 PROM_SIZE_MAX, &local_err);
437 if (local_err) {
438 error_propagate(errp, local_err);
439 return;
440 }
1baffa46 441
c5705a77 442 vmstate_register_ram_global(&s->prom);
d4edce38 443 memory_region_set_readonly(&s->prom, true);
750ecd44 444 sysbus_init_mmio(dev, &s->prom);
1baffa46
BS
445}
446
999e12bb
AL
447static Property prom_properties[] = {
448 {/* end of property list */},
449};
450
451static void prom_class_init(ObjectClass *klass, void *data)
452{
39bffca2 453 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 454
39bffca2 455 dc->props = prom_properties;
92b19880 456 dc->realize = prom_realize;
999e12bb
AL
457}
458
8c43a6f0 459static const TypeInfo prom_info = {
13575cf6 460 .name = TYPE_OPENPROM,
39bffca2
AL
461 .parent = TYPE_SYS_BUS_DEVICE,
462 .instance_size = sizeof(PROMState),
463 .class_init = prom_class_init,
1baffa46
BS
464};
465
bda42033 466
88c034d5
AF
467#define TYPE_SUN4U_MEMORY "memory"
468#define SUN4U_RAM(obj) OBJECT_CHECK(RamDevice, (obj), TYPE_SUN4U_MEMORY)
469
470typedef struct RamDevice {
471 SysBusDevice parent_obj;
472
d4edce38 473 MemoryRegion ram;
04843626 474 uint64_t size;
bda42033
BS
475} RamDevice;
476
477/* System RAM */
78fb261d 478static void ram_realize(DeviceState *dev, Error **errp)
bda42033 479{
88c034d5 480 RamDevice *d = SUN4U_RAM(dev);
78fb261d 481 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
bda42033 482
1cfe48c1 483 memory_region_init_ram_nomigrate(&d->ram, OBJECT(d), "sun4u.ram", d->size,
f8ed85ac 484 &error_fatal);
c5705a77 485 vmstate_register_ram_global(&d->ram);
78fb261d 486 sysbus_init_mmio(sbd, &d->ram);
bda42033
BS
487}
488
a8170e5e 489static void ram_init(hwaddr addr, ram_addr_t RAM_size)
bda42033
BS
490{
491 DeviceState *dev;
492 SysBusDevice *s;
493 RamDevice *d;
494
495 /* allocate RAM */
88c034d5 496 dev = qdev_create(NULL, TYPE_SUN4U_MEMORY);
1356b98d 497 s = SYS_BUS_DEVICE(dev);
bda42033 498
88c034d5 499 d = SUN4U_RAM(dev);
bda42033 500 d->size = RAM_size;
e23a1b33 501 qdev_init_nofail(dev);
bda42033
BS
502
503 sysbus_mmio_map(s, 0, addr);
504}
505
999e12bb
AL
506static Property ram_properties[] = {
507 DEFINE_PROP_UINT64("size", RamDevice, size, 0),
508 DEFINE_PROP_END_OF_LIST(),
509};
510
511static void ram_class_init(ObjectClass *klass, void *data)
512{
39bffca2 513 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 514
78fb261d 515 dc->realize = ram_realize;
39bffca2 516 dc->props = ram_properties;
999e12bb
AL
517}
518
8c43a6f0 519static const TypeInfo ram_info = {
88c034d5 520 .name = TYPE_SUN4U_MEMORY,
39bffca2
AL
521 .parent = TYPE_SYS_BUS_DEVICE,
522 .instance_size = sizeof(RamDevice),
523 .class_init = ram_class_init,
bda42033
BS
524};
525
38bc50f7 526static void sun4uv_init(MemoryRegion *address_space_mem,
3ef96221 527 MachineState *machine,
7b833f5b
BS
528 const struct hwdef *hwdef)
529{
f9d1465f 530 SPARCCPU *cpu;
31688246 531 Nvram *nvram;
7b833f5b 532 unsigned int i;
5f2bf0fe 533 uint64_t initrd_addr, initrd_size, kernel_addr, kernel_size, kernel_entry;
5795162a 534 SabreState *sabre;
311f2b7a 535 PCIBus *pci_bus, *pci_busA, *pci_busB;
8d932971 536 PCIDevice *ebus, *pci_dev;
f3b18f35 537 SysBusDevice *s;
f455e98c 538 DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
aea5b071 539 DeviceState *iommu, *dev;
a88b362c 540 FWCfgState *fw_cfg;
8d932971 541 NICInfo *nd;
6864fa38
MCA
542 MACAddr macaddr;
543 bool onboard_nic;
7b833f5b 544
7b833f5b 545 /* init CPUs */
58530461 546 cpu = sparc64_cpu_devinit(machine->cpu_type, hwdef->prom_addr);
7b833f5b 547
aea5b071
MCA
548 /* IOMMU */
549 iommu = qdev_create(NULL, TYPE_SUN4U_IOMMU);
550 qdev_init_nofail(iommu);
551
bda42033 552 /* set up devices */
3ef96221 553 ram_init(0, machine->ram_size);
3475187d 554
1baffa46 555 prom_init(hwdef->prom_addr, bios_name);
3475187d 556
b14dcaf4 557 /* Init sabre (PCI host bridge) */
5795162a
MCA
558 sabre = SABRE_DEVICE(qdev_create(NULL, TYPE_SABRE));
559 qdev_prop_set_uint64(DEVICE(sabre), "special-base", PBM_SPECIAL_BASE);
560 qdev_prop_set_uint64(DEVICE(sabre), "mem-base", PBM_MEM_BASE);
561 object_property_set_link(OBJECT(sabre), OBJECT(iommu), "iommu",
562 &error_abort);
563 qdev_init_nofail(DEVICE(sabre));
2a4d6af5
MCA
564
565 /* Wire up PCI interrupts to CPU */
566 for (i = 0; i < IVEC_MAX; i++) {
5795162a 567 qdev_connect_gpio_out_named(DEVICE(sabre), "ivec-irq", i,
2a4d6af5
MCA
568 qdev_get_gpio_in_named(DEVICE(cpu), "ivec-irq", i));
569 }
570
5795162a
MCA
571 pci_bus = PCI_HOST_BRIDGE(sabre)->bus;
572 pci_busA = pci_bridge_get_sec_bus(sabre->bridgeA);
573 pci_busB = pci_bridge_get_sec_bus(sabre->bridgeB);
83469015 574
5795162a 575 /* Only in-built Simba APBs can exist on the root bus, slot 0 on busA is
6864fa38
MCA
576 reserved (leaving no slots free after on-board devices) however slots
577 0-3 are free on busB */
578 pci_bus->slot_reserved_mask = 0xfffffffc;
579 pci_busA->slot_reserved_mask = 0xfffffff1;
580 pci_busB->slot_reserved_mask = 0xfffffff0;
581
ad6856e8 582 ebus = pci_create_multifunction(pci_busA, PCI_DEVFN(1, 0), true, TYPE_EBUS);
0fe22ffb
MCA
583 qdev_prop_set_uint64(DEVICE(ebus), "console-serial-base",
584 hwdef->console_serial_base);
6864fa38
MCA
585 qdev_init_nofail(DEVICE(ebus));
586
5795162a 587 /* Wire up "well-known" ISA IRQs to PBM legacy obio IRQs */
4b10c8d7 588 qdev_connect_gpio_out_named(DEVICE(ebus), "isa-irq", 7,
5795162a 589 qdev_get_gpio_in_named(DEVICE(sabre), "pbm-irq", OBIO_LPT_IRQ));
4b10c8d7 590 qdev_connect_gpio_out_named(DEVICE(ebus), "isa-irq", 6,
5795162a 591 qdev_get_gpio_in_named(DEVICE(sabre), "pbm-irq", OBIO_FDD_IRQ));
4b10c8d7 592 qdev_connect_gpio_out_named(DEVICE(ebus), "isa-irq", 1,
5795162a 593 qdev_get_gpio_in_named(DEVICE(sabre), "pbm-irq", OBIO_KBD_IRQ));
4b10c8d7 594 qdev_connect_gpio_out_named(DEVICE(ebus), "isa-irq", 12,
5795162a 595 qdev_get_gpio_in_named(DEVICE(sabre), "pbm-irq", OBIO_MSE_IRQ));
4b10c8d7 596 qdev_connect_gpio_out_named(DEVICE(ebus), "isa-irq", 4,
5795162a 597 qdev_get_gpio_in_named(DEVICE(sabre), "pbm-irq", OBIO_SER_IRQ));
4b10c8d7 598
6864fa38
MCA
599 pci_dev = pci_create_simple(pci_busA, PCI_DEVFN(2, 0), "VGA");
600
601 memset(&macaddr, 0, sizeof(MACAddr));
602 onboard_nic = false;
8d932971
MCA
603 for (i = 0; i < nb_nics; i++) {
604 nd = &nd_table[i];
605
6864fa38
MCA
606 if (!nd->model || strcmp(nd->model, "sunhme") == 0) {
607 if (!onboard_nic) {
608 pci_dev = pci_create_multifunction(pci_busA, PCI_DEVFN(1, 1),
609 true, "sunhme");
610 memcpy(&macaddr, &nd->macaddr.a, sizeof(MACAddr));
611 onboard_nic = true;
612 } else {
bcf9e2c2 613 pci_dev = pci_create(pci_busB, -1, "sunhme");
6864fa38 614 }
8d932971 615 } else {
bcf9e2c2 616 pci_dev = pci_create(pci_busB, -1, nd->model);
8d932971 617 }
6864fa38
MCA
618
619 dev = &pci_dev->qdev;
620 qdev_set_nic_properties(dev, nd);
621 qdev_init_nofail(dev);
622 }
623
624 /* If we don't have an onboard NIC, grab a default MAC address so that
625 * we have a valid machine id */
626 if (!onboard_nic) {
627 qemu_macaddr_default_if_unset(&macaddr);
8d932971 628 }
83469015 629
d8f94e1b 630 ide_drive_get(hd, ARRAY_SIZE(hd));
e4bcb14c 631
6864fa38
MCA
632 pci_dev = pci_create(pci_busA, PCI_DEVFN(3, 0), "cmd646-ide");
633 qdev_prop_set_uint32(&pci_dev->qdev, "secondary", 1);
634 qdev_init_nofail(&pci_dev->qdev);
635 pci_ide_create_devs(pci_dev, hd);
3b898dda 636
f3b18f35
MCA
637 /* Map NVRAM into I/O (ebus) space */
638 nvram = m48t59_init(NULL, 0, 0, NVRAM_SIZE, 1968, 59);
639 s = SYS_BUS_DEVICE(nvram);
07c84741 640 memory_region_add_subregion(pci_address_space_io(ebus), 0x2000,
f3b18f35
MCA
641 sysbus_mmio_get_region(s, 0));
642
636aa70a 643 initrd_size = 0;
5f2bf0fe 644 initrd_addr = 0;
3ef96221
MA
645 kernel_size = sun4u_load_kernel(machine->kernel_filename,
646 machine->initrd_filename,
5f2bf0fe
BS
647 ram_size, &initrd_size, &initrd_addr,
648 &kernel_addr, &kernel_entry);
636aa70a 649
3ef96221
MA
650 sun4u_NVRAM_set_params(nvram, NVRAM_SIZE, "Sun4u", machine->ram_size,
651 machine->boot_order,
5f2bf0fe 652 kernel_addr, kernel_size,
3ef96221 653 machine->kernel_cmdline,
5f2bf0fe 654 initrd_addr, initrd_size,
0d31cb99
BS
655 /* XXX: need an option to load a NVRAM image */
656 0,
657 graphic_width, graphic_height, graphic_depth,
6864fa38 658 (uint8_t *)&macaddr);
83469015 659
d6acc8a5
MCA
660 dev = qdev_create(NULL, TYPE_FW_CFG_IO);
661 qdev_prop_set_bit(dev, "dma_enabled", false);
07c84741 662 object_property_add_child(OBJECT(ebus), TYPE_FW_CFG, OBJECT(dev), NULL);
d6acc8a5 663 qdev_init_nofail(dev);
07c84741 664 memory_region_add_subregion(pci_address_space_io(ebus), BIOS_CFG_IOPORT,
d6acc8a5
MCA
665 &FW_CFG_IO(dev)->comb_iomem);
666
667 fw_cfg = FW_CFG(dev);
5836d168 668 fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
70db9222 669 fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
905fdcb5
BS
670 fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
671 fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
5f2bf0fe
BS
672 fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_ADDR, kernel_entry);
673 fw_cfg_add_i64(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
3ef96221 674 if (machine->kernel_cmdline) {
9c9b0512 675 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
3ef96221
MA
676 strlen(machine->kernel_cmdline) + 1);
677 fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, machine->kernel_cmdline);
513f789f 678 } else {
9c9b0512 679 fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
513f789f 680 }
5f2bf0fe
BS
681 fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_ADDR, initrd_addr);
682 fw_cfg_add_i64(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
3ef96221 683 fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, machine->boot_order[0]);
7589690c
BS
684
685 fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_WIDTH, graphic_width);
686 fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_HEIGHT, graphic_height);
687 fw_cfg_add_i16(fw_cfg, FW_CFG_SPARC64_DEPTH, graphic_depth);
688
513f789f 689 qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
3475187d
FB
690}
691
905fdcb5
BS
692enum {
693 sun4u_id = 0,
694 sun4v_id = 64,
695};
696
0a1d5c45
MCA
697/*
698 * Implementation of an interface to adjust firmware path
699 * for the bootindex property handling.
700 */
701static char *sun4u_fw_dev_path(FWPathProvider *p, BusState *bus,
702 DeviceState *dev)
703{
704 PCIDevice *pci;
705 IDEBus *ide_bus;
706 IDEState *ide_s;
707 int bus_id;
708
709 if (!strcmp(object_get_typename(OBJECT(dev)), "pbm-bridge")) {
710 pci = PCI_DEVICE(dev);
711
712 if (PCI_FUNC(pci->devfn)) {
713 return g_strdup_printf("pci@%x,%x", PCI_SLOT(pci->devfn),
714 PCI_FUNC(pci->devfn));
715 } else {
716 return g_strdup_printf("pci@%x", PCI_SLOT(pci->devfn));
717 }
718 }
719
720 if (!strcmp(object_get_typename(OBJECT(dev)), "ide-drive")) {
721 ide_bus = IDE_BUS(qdev_get_parent_bus(dev));
722 ide_s = idebus_active_if(ide_bus);
723 bus_id = ide_bus->bus_id;
724
725 if (ide_s->drive_kind == IDE_CD) {
726 return g_strdup_printf("ide@%x/cdrom", bus_id);
727 }
728
729 return g_strdup_printf("ide@%x/disk", bus_id);
730 }
731
732 if (!strcmp(object_get_typename(OBJECT(dev)), "ide-hd")) {
733 return g_strdup("disk");
734 }
735
736 if (!strcmp(object_get_typename(OBJECT(dev)), "ide-cd")) {
737 return g_strdup("cdrom");
738 }
739
740 if (!strcmp(object_get_typename(OBJECT(dev)), "virtio-blk-device")) {
741 return g_strdup("disk");
742 }
743
744 return NULL;
745}
746
c7ba218d
BS
747static const struct hwdef hwdefs[] = {
748 /* Sun4u generic PC-like machine */
749 {
905fdcb5 750 .machine_id = sun4u_id,
e87231d4
BS
751 .prom_addr = 0x1fff0000000ULL,
752 .console_serial_base = 0,
c7ba218d
BS
753 },
754 /* Sun4v generic PC-like machine */
755 {
905fdcb5 756 .machine_id = sun4v_id,
e87231d4
BS
757 .prom_addr = 0x1fff0000000ULL,
758 .console_serial_base = 0,
759 },
c7ba218d
BS
760};
761
762/* Sun4u hardware initialisation */
3ef96221 763static void sun4u_init(MachineState *machine)
5f072e1f 764{
3ef96221 765 sun4uv_init(get_system_memory(), machine, &hwdefs[0]);
c7ba218d
BS
766}
767
768/* Sun4v hardware initialisation */
3ef96221 769static void sun4v_init(MachineState *machine)
5f072e1f 770{
3ef96221 771 sun4uv_init(get_system_memory(), machine, &hwdefs[1]);
c7ba218d
BS
772}
773
8a661aea 774static void sun4u_class_init(ObjectClass *oc, void *data)
e264d29d 775{
8a661aea 776 MachineClass *mc = MACHINE_CLASS(oc);
0a1d5c45 777 FWPathProviderClass *fwc = FW_PATH_PROVIDER_CLASS(oc);
8a661aea 778
e264d29d
EH
779 mc->desc = "Sun4u platform";
780 mc->init = sun4u_init;
2059839b 781 mc->block_default_type = IF_IDE;
e264d29d
EH
782 mc->max_cpus = 1; /* XXX for now */
783 mc->is_default = 1;
784 mc->default_boot_order = "c";
58530461 785 mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-UltraSparc-IIi");
0a1d5c45
MCA
786 mc->ignore_boot_device_suffixes = true;
787 fwc->get_dev_path = sun4u_fw_dev_path;
e264d29d 788}
c7ba218d 789
8a661aea
AF
790static const TypeInfo sun4u_type = {
791 .name = MACHINE_TYPE_NAME("sun4u"),
792 .parent = TYPE_MACHINE,
793 .class_init = sun4u_class_init,
0a1d5c45
MCA
794 .interfaces = (InterfaceInfo[]) {
795 { TYPE_FW_PATH_PROVIDER },
796 { }
797 },
8a661aea 798};
e87231d4 799
8a661aea 800static void sun4v_class_init(ObjectClass *oc, void *data)
e264d29d 801{
8a661aea
AF
802 MachineClass *mc = MACHINE_CLASS(oc);
803
e264d29d
EH
804 mc->desc = "Sun4v platform";
805 mc->init = sun4v_init;
2059839b 806 mc->block_default_type = IF_IDE;
e264d29d
EH
807 mc->max_cpus = 1; /* XXX for now */
808 mc->default_boot_order = "c";
58530461 809 mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Sun-UltraSparc-T1");
e264d29d
EH
810}
811
8a661aea
AF
812static const TypeInfo sun4v_type = {
813 .name = MACHINE_TYPE_NAME("sun4v"),
814 .parent = TYPE_MACHINE,
815 .class_init = sun4v_class_init,
816};
e264d29d 817
83f7d43a
AF
818static void sun4u_register_types(void)
819{
25c5d5ac 820 type_register_static(&power_info);
83f7d43a
AF
821 type_register_static(&ebus_info);
822 type_register_static(&prom_info);
823 type_register_static(&ram_info);
83f7d43a 824
8a661aea
AF
825 type_register_static(&sun4u_type);
826 type_register_static(&sun4v_type);
8a661aea
AF
827}
828
83f7d43a 829type_init(sun4u_register_types)
This page took 1.210875 seconds and 4 git commands to generate.