xref: /openbmc/qemu/hw/sparc/sun4m.c (revision 2df1eb27)
1 /*
2  * QEMU Sun4m & Sun4d & Sun4c System Emulator
3  *
4  * Copyright (c) 2003-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 
25 #include "qemu/osdep.h"
26 #include "qemu/units.h"
27 #include "qapi/error.h"
28 #include "qemu/datadir.h"
29 #include "cpu.h"
30 #include "hw/sysbus.h"
31 #include "qemu/error-report.h"
32 #include "qemu/timer.h"
33 #include "hw/sparc/sun4m_iommu.h"
34 #include "hw/rtc/m48t59.h"
35 #include "migration/vmstate.h"
36 #include "hw/sparc/sparc32_dma.h"
37 #include "hw/block/fdc.h"
38 #include "sysemu/reset.h"
39 #include "sysemu/runstate.h"
40 #include "sysemu/sysemu.h"
41 #include "net/net.h"
42 #include "hw/boards.h"
43 #include "hw/scsi/esp.h"
44 #include "hw/nvram/sun_nvram.h"
45 #include "hw/qdev-properties.h"
46 #include "hw/nvram/chrp_nvram.h"
47 #include "hw/nvram/fw_cfg.h"
48 #include "hw/char/escc.h"
49 #include "hw/misc/empty_slot.h"
50 #include "hw/misc/unimp.h"
51 #include "hw/irq.h"
52 #include "hw/or-irq.h"
53 #include "hw/loader.h"
54 #include "elf.h"
55 #include "trace.h"
56 #include "qom/object.h"
57 
58 /*
59  * Sun4m architecture was used in the following machines:
60  *
61  * SPARCserver 6xxMP/xx
62  * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
63  * SPARCclassic X (4/10)
64  * SPARCstation LX/ZX (4/30)
65  * SPARCstation Voyager
66  * SPARCstation 10/xx, SPARCserver 10/xx
67  * SPARCstation 5, SPARCserver 5
68  * SPARCstation 20/xx, SPARCserver 20
69  * SPARCstation 4
70  *
71  * See for example: http://www.sunhelp.org/faq/sunref1.html
72  */
73 
74 #define KERNEL_LOAD_ADDR     0x00004000
75 #define CMDLINE_ADDR         0x007ff000
76 #define INITRD_LOAD_ADDR     0x00800000
77 #define PROM_SIZE_MAX        (1 * MiB)
78 #define PROM_VADDR           0xffd00000
79 #define PROM_FILENAME        "openbios-sparc32"
80 #define CFG_ADDR             0xd00000510ULL
81 #define FW_CFG_SUN4M_DEPTH   (FW_CFG_ARCH_LOCAL + 0x00)
82 #define FW_CFG_SUN4M_WIDTH   (FW_CFG_ARCH_LOCAL + 0x01)
83 #define FW_CFG_SUN4M_HEIGHT  (FW_CFG_ARCH_LOCAL + 0x02)
84 
85 #define MAX_CPUS 16
86 #define MAX_PILS 16
87 #define MAX_VSIMMS 4
88 
89 #define ESCC_CLOCK 4915200
90 
91 struct sun4m_hwdef {
92     hwaddr iommu_base, iommu_pad_base, iommu_pad_len, slavio_base;
93     hwaddr intctl_base, counter_base, nvram_base, ms_kb_base;
94     hwaddr serial_base, fd_base;
95     hwaddr afx_base, idreg_base, dma_base, esp_base, le_base;
96     hwaddr tcx_base, cs_base, apc_base, aux1_base, aux2_base;
97     hwaddr bpp_base, dbri_base, sx_base;
98     struct {
99         hwaddr reg_base, vram_base;
100     } vsimm[MAX_VSIMMS];
101     hwaddr ecc_base;
102     uint64_t max_mem;
103     uint32_t ecc_version;
104     uint32_t iommu_version;
105     uint16_t machine_id;
106     uint8_t nvram_machine_id;
107 };
108 
109 struct Sun4mMachineClass {
110     /*< private >*/
111     MachineClass parent_obj;
112     /*< public >*/
113     const struct sun4m_hwdef *hwdef;
114 };
115 typedef struct Sun4mMachineClass Sun4mMachineClass;
116 
117 #define TYPE_SUN4M_MACHINE MACHINE_TYPE_NAME("sun4m-common")
118 DECLARE_CLASS_CHECKERS(Sun4mMachineClass, SUN4M_MACHINE, TYPE_SUN4M_MACHINE)
119 
120 const char *fw_cfg_arch_key_name(uint16_t key)
121 {
122     static const struct {
123         uint16_t key;
124         const char *name;
125     } fw_cfg_arch_wellknown_keys[] = {
126         {FW_CFG_SUN4M_DEPTH, "depth"},
127         {FW_CFG_SUN4M_WIDTH, "width"},
128         {FW_CFG_SUN4M_HEIGHT, "height"},
129     };
130 
131     for (size_t i = 0; i < ARRAY_SIZE(fw_cfg_arch_wellknown_keys); i++) {
132         if (fw_cfg_arch_wellknown_keys[i].key == key) {
133             return fw_cfg_arch_wellknown_keys[i].name;
134         }
135     }
136     return NULL;
137 }
138 
139 static void fw_cfg_boot_set(void *opaque, const char *boot_device,
140                             Error **errp)
141 {
142     fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
143 }
144 
145 static void nvram_init(Nvram *nvram, uint8_t *macaddr,
146                        const char *cmdline, const char *boot_devices,
147                        ram_addr_t RAM_size, uint32_t kernel_size,
148                        int width, int height, int depth,
149                        int nvram_machine_id, const char *arch)
150 {
151     unsigned int i;
152     int sysp_end;
153     uint8_t image[0x1ff0];
154     NvramClass *k = NVRAM_GET_CLASS(nvram);
155 
156     memset(image, '\0', sizeof(image));
157 
158     /* OpenBIOS nvram variables partition */
159     sysp_end = chrp_nvram_create_system_partition(image, 0, 0x1fd0);
160 
161     /* Free space partition */
162     chrp_nvram_create_free_partition(&image[sysp_end], 0x1fd0 - sysp_end);
163 
164     Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
165                     nvram_machine_id);
166 
167     for (i = 0; i < sizeof(image); i++) {
168         (k->write)(nvram, i, image[i]);
169     }
170 }
171 
172 static void cpu_kick_irq(SPARCCPU *cpu)
173 {
174     CPUSPARCState *env = &cpu->env;
175     CPUState *cs = CPU(cpu);
176 
177     cs->halted = 0;
178     cpu_check_irqs(env);
179     qemu_cpu_kick(cs);
180 }
181 
182 static void cpu_set_irq(void *opaque, int irq, int level)
183 {
184     SPARCCPU *cpu = opaque;
185     CPUSPARCState *env = &cpu->env;
186 
187     if (level) {
188         trace_sun4m_cpu_set_irq_raise(irq);
189         env->pil_in |= 1 << irq;
190         cpu_kick_irq(cpu);
191     } else {
192         trace_sun4m_cpu_set_irq_lower(irq);
193         env->pil_in &= ~(1 << irq);
194         cpu_check_irqs(env);
195     }
196 }
197 
198 static void dummy_cpu_set_irq(void *opaque, int irq, int level)
199 {
200 }
201 
202 static void sun4m_cpu_reset(void *opaque)
203 {
204     SPARCCPU *cpu = opaque;
205     CPUState *cs = CPU(cpu);
206 
207     cpu_reset(cs);
208 }
209 
210 static void cpu_halt_signal(void *opaque, int irq, int level)
211 {
212     if (level && current_cpu) {
213         cpu_interrupt(current_cpu, CPU_INTERRUPT_HALT);
214     }
215 }
216 
217 static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
218 {
219     return addr - 0xf0000000ULL;
220 }
221 
222 static unsigned long sun4m_load_kernel(const char *kernel_filename,
223                                        const char *initrd_filename,
224                                        ram_addr_t RAM_size,
225                                        uint32_t *initrd_size)
226 {
227     int linux_boot;
228     unsigned int i;
229     long kernel_size;
230     uint8_t *ptr;
231 
232     linux_boot = (kernel_filename != NULL);
233 
234     kernel_size = 0;
235     if (linux_boot) {
236         int bswap_needed;
237 
238 #ifdef BSWAP_NEEDED
239         bswap_needed = 1;
240 #else
241         bswap_needed = 0;
242 #endif
243         kernel_size = load_elf(kernel_filename, NULL,
244                                translate_kernel_address, NULL,
245                                NULL, NULL, NULL, NULL, 1, EM_SPARC, 0, 0);
246         if (kernel_size < 0)
247             kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
248                                     RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
249                                     TARGET_PAGE_SIZE);
250         if (kernel_size < 0)
251             kernel_size = load_image_targphys(kernel_filename,
252                                               KERNEL_LOAD_ADDR,
253                                               RAM_size - KERNEL_LOAD_ADDR);
254         if (kernel_size < 0) {
255             error_report("could not load kernel '%s'", kernel_filename);
256             exit(1);
257         }
258 
259         /* load initrd */
260         *initrd_size = 0;
261         if (initrd_filename) {
262             *initrd_size = load_image_targphys(initrd_filename,
263                                                INITRD_LOAD_ADDR,
264                                                RAM_size - INITRD_LOAD_ADDR);
265             if ((int)*initrd_size < 0) {
266                 error_report("could not load initial ram disk '%s'",
267                              initrd_filename);
268                 exit(1);
269             }
270         }
271         if (*initrd_size > 0) {
272             for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
273                 ptr = rom_ptr(KERNEL_LOAD_ADDR + i, 24);
274                 if (ptr && ldl_p(ptr) == 0x48647253) { /* HdrS */
275                     stl_p(ptr + 16, INITRD_LOAD_ADDR);
276                     stl_p(ptr + 20, *initrd_size);
277                     break;
278                 }
279             }
280         }
281     }
282     return kernel_size;
283 }
284 
285 static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
286 {
287     DeviceState *dev;
288     SysBusDevice *s;
289 
290     dev = qdev_new(TYPE_SUN4M_IOMMU);
291     qdev_prop_set_uint32(dev, "version", version);
292     s = SYS_BUS_DEVICE(dev);
293     sysbus_realize_and_unref(s, &error_fatal);
294     sysbus_connect_irq(s, 0, irq);
295     sysbus_mmio_map(s, 0, addr);
296 
297     return s;
298 }
299 
300 static void *sparc32_dma_init(hwaddr dma_base,
301                               hwaddr esp_base, qemu_irq espdma_irq,
302                               hwaddr le_base, qemu_irq ledma_irq,
303                               MACAddr *mac)
304 {
305     DeviceState *dma;
306     ESPDMADeviceState *espdma;
307     LEDMADeviceState *ledma;
308     SysBusESPState *esp;
309     SysBusPCNetState *lance;
310     NICInfo *nd = qemu_find_nic_info("lance", true, NULL);
311 
312     dma = qdev_new(TYPE_SPARC32_DMA);
313     espdma = SPARC32_ESPDMA_DEVICE(object_resolve_path_component(
314                                    OBJECT(dma), "espdma"));
315     sysbus_connect_irq(SYS_BUS_DEVICE(espdma), 0, espdma_irq);
316 
317     esp = SYSBUS_ESP(object_resolve_path_component(OBJECT(espdma), "esp"));
318 
319     ledma = SPARC32_LEDMA_DEVICE(object_resolve_path_component(
320                                  OBJECT(dma), "ledma"));
321     sysbus_connect_irq(SYS_BUS_DEVICE(ledma), 0, ledma_irq);
322 
323     lance = SYSBUS_PCNET(object_resolve_path_component(
324                          OBJECT(ledma), "lance"));
325 
326     if (nd) {
327         qdev_set_nic_properties(DEVICE(lance), nd);
328         memcpy(mac->a, nd->macaddr.a, sizeof(mac->a));
329     } else {
330         qemu_macaddr_default_if_unset(mac);
331         qdev_prop_set_macaddr(DEVICE(lance), "mac", mac->a);
332     }
333 
334     sysbus_realize_and_unref(SYS_BUS_DEVICE(dma), &error_fatal);
335     sysbus_mmio_map(SYS_BUS_DEVICE(dma), 0, dma_base);
336 
337     sysbus_mmio_map(SYS_BUS_DEVICE(esp), 0, esp_base);
338     scsi_bus_legacy_handle_cmdline(&esp->esp.bus);
339 
340     sysbus_mmio_map(SYS_BUS_DEVICE(lance), 0, le_base);
341 
342     return dma;
343 }
344 
345 static DeviceState *slavio_intctl_init(hwaddr addr,
346                                        hwaddr addrg,
347                                        qemu_irq **parent_irq)
348 {
349     DeviceState *dev;
350     SysBusDevice *s;
351     unsigned int i, j;
352 
353     dev = qdev_new("slavio_intctl");
354 
355     s = SYS_BUS_DEVICE(dev);
356     sysbus_realize_and_unref(s, &error_fatal);
357 
358     for (i = 0; i < MAX_CPUS; i++) {
359         for (j = 0; j < MAX_PILS; j++) {
360             sysbus_connect_irq(s, i * MAX_PILS + j, parent_irq[i][j]);
361         }
362     }
363     sysbus_mmio_map(s, 0, addrg);
364     for (i = 0; i < MAX_CPUS; i++) {
365         sysbus_mmio_map(s, i + 1, addr + i * TARGET_PAGE_SIZE);
366     }
367 
368     return dev;
369 }
370 
371 #define SYS_TIMER_OFFSET      0x10000ULL
372 #define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
373 
374 static void slavio_timer_init_all(hwaddr addr, qemu_irq master_irq,
375                                   qemu_irq *cpu_irqs, unsigned int num_cpus)
376 {
377     DeviceState *dev;
378     SysBusDevice *s;
379     unsigned int i;
380 
381     dev = qdev_new("slavio_timer");
382     qdev_prop_set_uint32(dev, "num_cpus", num_cpus);
383     s = SYS_BUS_DEVICE(dev);
384     sysbus_realize_and_unref(s, &error_fatal);
385     sysbus_connect_irq(s, 0, master_irq);
386     sysbus_mmio_map(s, 0, addr + SYS_TIMER_OFFSET);
387 
388     for (i = 0; i < MAX_CPUS; i++) {
389         sysbus_mmio_map(s, i + 1, addr + (hwaddr)CPU_TIMER_OFFSET(i));
390         sysbus_connect_irq(s, i + 1, cpu_irqs[i]);
391     }
392 }
393 
394 static qemu_irq  slavio_system_powerdown;
395 
396 static void slavio_powerdown_req(Notifier *n, void *opaque)
397 {
398     qemu_irq_raise(slavio_system_powerdown);
399 }
400 
401 static Notifier slavio_system_powerdown_notifier = {
402     .notify = slavio_powerdown_req
403 };
404 
405 #define MISC_LEDS 0x01600000
406 #define MISC_CFG  0x01800000
407 #define MISC_DIAG 0x01a00000
408 #define MISC_MDM  0x01b00000
409 #define MISC_SYS  0x01f00000
410 
411 static void slavio_misc_init(hwaddr base,
412                              hwaddr aux1_base,
413                              hwaddr aux2_base, qemu_irq irq,
414                              qemu_irq fdc_tc)
415 {
416     DeviceState *dev;
417     SysBusDevice *s;
418 
419     dev = qdev_new("slavio_misc");
420     s = SYS_BUS_DEVICE(dev);
421     sysbus_realize_and_unref(s, &error_fatal);
422     if (base) {
423         /* 8 bit registers */
424         /* Slavio control */
425         sysbus_mmio_map(s, 0, base + MISC_CFG);
426         /* Diagnostics */
427         sysbus_mmio_map(s, 1, base + MISC_DIAG);
428         /* Modem control */
429         sysbus_mmio_map(s, 2, base + MISC_MDM);
430         /* 16 bit registers */
431         /* ss600mp diag LEDs */
432         sysbus_mmio_map(s, 3, base + MISC_LEDS);
433         /* 32 bit registers */
434         /* System control */
435         sysbus_mmio_map(s, 4, base + MISC_SYS);
436     }
437     if (aux1_base) {
438         /* AUX 1 (Misc System Functions) */
439         sysbus_mmio_map(s, 5, aux1_base);
440     }
441     if (aux2_base) {
442         /* AUX 2 (Software Powerdown Control) */
443         sysbus_mmio_map(s, 6, aux2_base);
444     }
445     sysbus_connect_irq(s, 0, irq);
446     sysbus_connect_irq(s, 1, fdc_tc);
447     slavio_system_powerdown = qdev_get_gpio_in(dev, 0);
448     qemu_register_powerdown_notifier(&slavio_system_powerdown_notifier);
449 }
450 
451 static void ecc_init(hwaddr base, qemu_irq irq, uint32_t version)
452 {
453     DeviceState *dev;
454     SysBusDevice *s;
455 
456     dev = qdev_new("eccmemctl");
457     qdev_prop_set_uint32(dev, "version", version);
458     s = SYS_BUS_DEVICE(dev);
459     sysbus_realize_and_unref(s, &error_fatal);
460     sysbus_connect_irq(s, 0, irq);
461     sysbus_mmio_map(s, 0, base);
462     if (version == 0) { // SS-600MP only
463         sysbus_mmio_map(s, 1, base + 0x1000);
464     }
465 }
466 
467 static void apc_init(hwaddr power_base, qemu_irq cpu_halt)
468 {
469     DeviceState *dev;
470     SysBusDevice *s;
471 
472     dev = qdev_new("apc");
473     s = SYS_BUS_DEVICE(dev);
474     sysbus_realize_and_unref(s, &error_fatal);
475     /* Power management (APC) XXX: not a Slavio device */
476     sysbus_mmio_map(s, 0, power_base);
477     sysbus_connect_irq(s, 0, cpu_halt);
478 }
479 
480 static void tcx_init(hwaddr addr, qemu_irq irq, int vram_size, int width,
481                      int height, int depth)
482 {
483     DeviceState *dev;
484     SysBusDevice *s;
485 
486     dev = qdev_new("sun-tcx");
487     qdev_prop_set_uint32(dev, "vram_size", vram_size);
488     qdev_prop_set_uint16(dev, "width", width);
489     qdev_prop_set_uint16(dev, "height", height);
490     qdev_prop_set_uint16(dev, "depth", depth);
491     s = SYS_BUS_DEVICE(dev);
492     sysbus_realize_and_unref(s, &error_fatal);
493 
494     /* 10/ROM : FCode ROM */
495     sysbus_mmio_map(s, 0, addr);
496     /* 2/STIP : Stipple */
497     sysbus_mmio_map(s, 1, addr + 0x04000000ULL);
498     /* 3/BLIT : Blitter */
499     sysbus_mmio_map(s, 2, addr + 0x06000000ULL);
500     /* 5/RSTIP : Raw Stipple */
501     sysbus_mmio_map(s, 3, addr + 0x0c000000ULL);
502     /* 6/RBLIT : Raw Blitter */
503     sysbus_mmio_map(s, 4, addr + 0x0e000000ULL);
504     /* 7/TEC : Transform Engine */
505     sysbus_mmio_map(s, 5, addr + 0x00700000ULL);
506     /* 8/CMAP  : DAC */
507     sysbus_mmio_map(s, 6, addr + 0x00200000ULL);
508     /* 9/THC : */
509     if (depth == 8) {
510         sysbus_mmio_map(s, 7, addr + 0x00300000ULL);
511     } else {
512         sysbus_mmio_map(s, 7, addr + 0x00301000ULL);
513     }
514     /* 11/DHC : */
515     sysbus_mmio_map(s, 8, addr + 0x00240000ULL);
516     /* 12/ALT : */
517     sysbus_mmio_map(s, 9, addr + 0x00280000ULL);
518     /* 0/DFB8 : 8-bit plane */
519     sysbus_mmio_map(s, 10, addr + 0x00800000ULL);
520     /* 1/DFB24 : 24bit plane */
521     sysbus_mmio_map(s, 11, addr + 0x02000000ULL);
522     /* 4/RDFB32: Raw framebuffer. Control plane */
523     sysbus_mmio_map(s, 12, addr + 0x0a000000ULL);
524     /* 9/THC24bits : NetBSD writes here even with 8-bit display: dummy */
525     if (depth == 8) {
526         sysbus_mmio_map(s, 13, addr + 0x00301000ULL);
527     }
528 
529     sysbus_connect_irq(s, 0, irq);
530 }
531 
532 static void cg3_init(hwaddr addr, qemu_irq irq, int vram_size, int width,
533                      int height, int depth)
534 {
535     DeviceState *dev;
536     SysBusDevice *s;
537 
538     dev = qdev_new("cgthree");
539     qdev_prop_set_uint32(dev, "vram-size", vram_size);
540     qdev_prop_set_uint16(dev, "width", width);
541     qdev_prop_set_uint16(dev, "height", height);
542     qdev_prop_set_uint16(dev, "depth", depth);
543     s = SYS_BUS_DEVICE(dev);
544     sysbus_realize_and_unref(s, &error_fatal);
545 
546     /* FCode ROM */
547     sysbus_mmio_map(s, 0, addr);
548     /* DAC */
549     sysbus_mmio_map(s, 1, addr + 0x400000ULL);
550     /* 8-bit plane */
551     sysbus_mmio_map(s, 2, addr + 0x800000ULL);
552 
553     sysbus_connect_irq(s, 0, irq);
554 }
555 
556 /* NCR89C100/MACIO Internal ID register */
557 
558 #define TYPE_MACIO_ID_REGISTER "macio_idreg"
559 
560 static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
561 
562 static void idreg_init(hwaddr addr)
563 {
564     DeviceState *dev;
565     SysBusDevice *s;
566 
567     dev = qdev_new(TYPE_MACIO_ID_REGISTER);
568     s = SYS_BUS_DEVICE(dev);
569     sysbus_realize_and_unref(s, &error_fatal);
570 
571     sysbus_mmio_map(s, 0, addr);
572     address_space_write_rom(&address_space_memory, addr,
573                             MEMTXATTRS_UNSPECIFIED,
574                             idreg_data, sizeof(idreg_data));
575 }
576 
577 OBJECT_DECLARE_SIMPLE_TYPE(IDRegState, MACIO_ID_REGISTER)
578 
579 struct IDRegState {
580     SysBusDevice parent_obj;
581 
582     MemoryRegion mem;
583 };
584 
585 static void idreg_realize(DeviceState *ds, Error **errp)
586 {
587     IDRegState *s = MACIO_ID_REGISTER(ds);
588     SysBusDevice *dev = SYS_BUS_DEVICE(ds);
589 
590     if (!memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.idreg",
591                                           sizeof(idreg_data), errp)) {
592         return;
593     }
594 
595     vmstate_register_ram_global(&s->mem);
596     memory_region_set_readonly(&s->mem, true);
597     sysbus_init_mmio(dev, &s->mem);
598 }
599 
600 static void idreg_class_init(ObjectClass *oc, void *data)
601 {
602     DeviceClass *dc = DEVICE_CLASS(oc);
603 
604     dc->realize = idreg_realize;
605 }
606 
607 static const TypeInfo idreg_info = {
608     .name          = TYPE_MACIO_ID_REGISTER,
609     .parent        = TYPE_SYS_BUS_DEVICE,
610     .instance_size = sizeof(IDRegState),
611     .class_init    = idreg_class_init,
612 };
613 
614 #define TYPE_TCX_AFX "tcx_afx"
615 OBJECT_DECLARE_SIMPLE_TYPE(AFXState, TCX_AFX)
616 
617 struct AFXState {
618     SysBusDevice parent_obj;
619 
620     MemoryRegion mem;
621 };
622 
623 /* SS-5 TCX AFX register */
624 static void afx_init(hwaddr addr)
625 {
626     DeviceState *dev;
627     SysBusDevice *s;
628 
629     dev = qdev_new(TYPE_TCX_AFX);
630     s = SYS_BUS_DEVICE(dev);
631     sysbus_realize_and_unref(s, &error_fatal);
632 
633     sysbus_mmio_map(s, 0, addr);
634 }
635 
636 static void afx_realize(DeviceState *ds, Error **errp)
637 {
638     AFXState *s = TCX_AFX(ds);
639     SysBusDevice *dev = SYS_BUS_DEVICE(ds);
640 
641     if (!memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.afx",
642                                           4, errp)) {
643         return;
644     }
645 
646     vmstate_register_ram_global(&s->mem);
647     sysbus_init_mmio(dev, &s->mem);
648 }
649 
650 static void afx_class_init(ObjectClass *oc, void *data)
651 {
652     DeviceClass *dc = DEVICE_CLASS(oc);
653 
654     dc->realize = afx_realize;
655 }
656 
657 static const TypeInfo afx_info = {
658     .name          = TYPE_TCX_AFX,
659     .parent        = TYPE_SYS_BUS_DEVICE,
660     .instance_size = sizeof(AFXState),
661     .class_init    = afx_class_init,
662 };
663 
664 #define TYPE_OPENPROM "openprom"
665 typedef struct PROMState PROMState;
666 DECLARE_INSTANCE_CHECKER(PROMState, OPENPROM,
667                          TYPE_OPENPROM)
668 
669 struct PROMState {
670     SysBusDevice parent_obj;
671 
672     MemoryRegion prom;
673 };
674 
675 /* Boot PROM (OpenBIOS) */
676 static uint64_t translate_prom_address(void *opaque, uint64_t addr)
677 {
678     hwaddr *base_addr = (hwaddr *)opaque;
679     return addr + *base_addr - PROM_VADDR;
680 }
681 
682 static void prom_init(hwaddr addr, const char *bios_name)
683 {
684     DeviceState *dev;
685     SysBusDevice *s;
686     char *filename;
687     int ret;
688 
689     dev = qdev_new(TYPE_OPENPROM);
690     s = SYS_BUS_DEVICE(dev);
691     sysbus_realize_and_unref(s, &error_fatal);
692 
693     sysbus_mmio_map(s, 0, addr);
694 
695     /* load boot prom */
696     if (bios_name == NULL) {
697         bios_name = PROM_FILENAME;
698     }
699     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
700     if (filename) {
701         ret = load_elf(filename, NULL,
702                        translate_prom_address, &addr, NULL,
703                        NULL, NULL, NULL, 1, EM_SPARC, 0, 0);
704         if (ret < 0 || ret > PROM_SIZE_MAX) {
705             ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
706         }
707         g_free(filename);
708     } else {
709         ret = -1;
710     }
711     if (ret < 0 || ret > PROM_SIZE_MAX) {
712         error_report("could not load prom '%s'", bios_name);
713         exit(1);
714     }
715 }
716 
717 static void prom_realize(DeviceState *ds, Error **errp)
718 {
719     PROMState *s = OPENPROM(ds);
720     SysBusDevice *dev = SYS_BUS_DEVICE(ds);
721 
722     if (!memory_region_init_ram_nomigrate(&s->prom, OBJECT(ds), "sun4m.prom",
723                                           PROM_SIZE_MAX, errp)) {
724         return;
725     }
726 
727     vmstate_register_ram_global(&s->prom);
728     memory_region_set_readonly(&s->prom, true);
729     sysbus_init_mmio(dev, &s->prom);
730 }
731 
732 static Property prom_properties[] = {
733     {/* end of property list */},
734 };
735 
736 static void prom_class_init(ObjectClass *klass, void *data)
737 {
738     DeviceClass *dc = DEVICE_CLASS(klass);
739 
740     device_class_set_props(dc, prom_properties);
741     dc->realize = prom_realize;
742 }
743 
744 static const TypeInfo prom_info = {
745     .name          = TYPE_OPENPROM,
746     .parent        = TYPE_SYS_BUS_DEVICE,
747     .instance_size = sizeof(PROMState),
748     .class_init    = prom_class_init,
749 };
750 
751 #define TYPE_SUN4M_MEMORY "memory"
752 typedef struct RamDevice RamDevice;
753 DECLARE_INSTANCE_CHECKER(RamDevice, SUN4M_RAM,
754                          TYPE_SUN4M_MEMORY)
755 
756 struct RamDevice {
757     SysBusDevice parent_obj;
758     HostMemoryBackend *memdev;
759 };
760 
761 /* System RAM */
762 static void ram_realize(DeviceState *dev, Error **errp)
763 {
764     RamDevice *d = SUN4M_RAM(dev);
765     MemoryRegion *ram = host_memory_backend_get_memory(d->memdev);
766 
767     sysbus_init_mmio(SYS_BUS_DEVICE(dev), ram);
768 }
769 
770 static void ram_initfn(Object *obj)
771 {
772     RamDevice *d = SUN4M_RAM(obj);
773     object_property_add_link(obj, "memdev", TYPE_MEMORY_BACKEND,
774                              (Object **)&d->memdev,
775                              object_property_allow_set_link,
776                              OBJ_PROP_LINK_STRONG);
777     object_property_set_description(obj, "memdev", "Set RAM backend"
778                                     "Valid value is ID of a hostmem backend");
779 }
780 
781 static void ram_class_init(ObjectClass *klass, void *data)
782 {
783     DeviceClass *dc = DEVICE_CLASS(klass);
784 
785     dc->realize = ram_realize;
786 }
787 
788 static const TypeInfo ram_info = {
789     .name          = TYPE_SUN4M_MEMORY,
790     .parent        = TYPE_SYS_BUS_DEVICE,
791     .instance_size = sizeof(RamDevice),
792     .instance_init = ram_initfn,
793     .class_init    = ram_class_init,
794 };
795 
796 static void cpu_devinit(const char *cpu_type, unsigned int id,
797                         uint64_t prom_addr, qemu_irq **cpu_irqs)
798 {
799     SPARCCPU *cpu;
800     CPUSPARCState *env;
801 
802     cpu = SPARC_CPU(object_new(cpu_type));
803     env = &cpu->env;
804 
805     qemu_register_reset(sun4m_cpu_reset, cpu);
806     object_property_set_bool(OBJECT(cpu), "start-powered-off", id != 0,
807                              &error_abort);
808     qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal);
809     cpu_sparc_set_id(env, id);
810     *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS);
811     env->prom_addr = prom_addr;
812 }
813 
814 static void dummy_fdc_tc(void *opaque, int irq, int level)
815 {
816 }
817 
818 static void sun4m_hw_init(MachineState *machine)
819 {
820     const struct sun4m_hwdef *hwdef = SUN4M_MACHINE_GET_CLASS(machine)->hwdef;
821     DeviceState *slavio_intctl;
822     unsigned int i;
823     Nvram *nvram;
824     qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
825     qemu_irq fdc_tc;
826     unsigned long kernel_size;
827     uint32_t initrd_size;
828     DriveInfo *fd[MAX_FD];
829     FWCfgState *fw_cfg;
830     DeviceState *dev, *ms_kb_orgate, *serial_orgate;
831     SysBusDevice *s;
832     unsigned int smp_cpus = machine->smp.cpus;
833     unsigned int max_cpus = machine->smp.max_cpus;
834     HostMemoryBackend *ram_memdev = machine->memdev;
835     MACAddr hostid;
836 
837     if (machine->ram_size > hwdef->max_mem) {
838         error_report("Too much memory for this machine: %" PRId64 ","
839                      " maximum %" PRId64,
840                      machine->ram_size / MiB, hwdef->max_mem / MiB);
841         exit(1);
842     }
843 
844     /* init CPUs */
845     for(i = 0; i < smp_cpus; i++) {
846         cpu_devinit(machine->cpu_type, i, hwdef->slavio_base, &cpu_irqs[i]);
847     }
848 
849     for (i = smp_cpus; i < MAX_CPUS; i++)
850         cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
851 
852     /* Create and map RAM frontend */
853     dev = qdev_new("memory");
854     object_property_set_link(OBJECT(dev), "memdev", OBJECT(ram_memdev), &error_fatal);
855     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
856     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0);
857 
858     /* models without ECC don't trap when missing ram is accessed */
859     if (!hwdef->ecc_base) {
860         empty_slot_init("ecc", machine->ram_size,
861                         hwdef->max_mem - machine->ram_size);
862     }
863 
864     prom_init(hwdef->slavio_base, machine->firmware);
865 
866     slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
867                                        hwdef->intctl_base + 0x10000ULL,
868                                        cpu_irqs);
869 
870     for (i = 0; i < 32; i++) {
871         slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
872     }
873     for (i = 0; i < MAX_CPUS; i++) {
874         slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
875     }
876 
877     if (hwdef->idreg_base) {
878         idreg_init(hwdef->idreg_base);
879     }
880 
881     if (hwdef->afx_base) {
882         afx_init(hwdef->afx_base);
883     }
884 
885     iommu_init(hwdef->iommu_base, hwdef->iommu_version, slavio_irq[30]);
886 
887     if (hwdef->iommu_pad_base) {
888         /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
889            Software shouldn't use aliased addresses, neither should it crash
890            when does. Using empty_slot instead of aliasing can help with
891            debugging such accesses */
892         empty_slot_init("iommu.alias",
893                         hwdef->iommu_pad_base, hwdef->iommu_pad_len);
894     }
895 
896     sparc32_dma_init(hwdef->dma_base,
897                      hwdef->esp_base, slavio_irq[18],
898                      hwdef->le_base, slavio_irq[16], &hostid);
899 
900     if (graphic_depth != 8 && graphic_depth != 24) {
901         error_report("Unsupported depth: %d", graphic_depth);
902         exit (1);
903     }
904     if (vga_interface_type != VGA_NONE) {
905         if (vga_interface_type == VGA_CG3) {
906             if (graphic_depth != 8) {
907                 error_report("Unsupported depth: %d", graphic_depth);
908                 exit(1);
909             }
910 
911             if (!(graphic_width == 1024 && graphic_height == 768) &&
912                 !(graphic_width == 1152 && graphic_height == 900)) {
913                 error_report("Unsupported resolution: %d x %d", graphic_width,
914                              graphic_height);
915                 exit(1);
916             }
917 
918             /* sbus irq 5 */
919             cg3_init(hwdef->tcx_base, slavio_irq[11], 0x00100000,
920                      graphic_width, graphic_height, graphic_depth);
921             vga_interface_created = true;
922         } else {
923             /* If no display specified, default to TCX */
924             if (graphic_depth != 8 && graphic_depth != 24) {
925                 error_report("Unsupported depth: %d", graphic_depth);
926                 exit(1);
927             }
928 
929             if (!(graphic_width == 1024 && graphic_height == 768)) {
930                 error_report("Unsupported resolution: %d x %d",
931                              graphic_width, graphic_height);
932                 exit(1);
933             }
934 
935             tcx_init(hwdef->tcx_base, slavio_irq[11], 0x00100000,
936                      graphic_width, graphic_height, graphic_depth);
937             vga_interface_created = true;
938         }
939     }
940 
941     for (i = 0; i < MAX_VSIMMS; i++) {
942         /* vsimm registers probed by OBP */
943         if (hwdef->vsimm[i].reg_base) {
944             char *name = g_strdup_printf("vsimm[%d]", i);
945             empty_slot_init(name, hwdef->vsimm[i].reg_base, 0x2000);
946             g_free(name);
947         }
948     }
949 
950     if (hwdef->sx_base) {
951         create_unimplemented_device("sun-sx", hwdef->sx_base, 0x2000);
952     }
953 
954     dev = qdev_new("sysbus-m48t08");
955     qdev_prop_set_int32(dev, "base-year", 1968);
956     s = SYS_BUS_DEVICE(dev);
957     sysbus_realize_and_unref(s, &error_fatal);
958     sysbus_connect_irq(s, 0, slavio_irq[0]);
959     sysbus_mmio_map(s, 0, hwdef->nvram_base);
960     nvram = NVRAM(dev);
961 
962     slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
963 
964     /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
965        Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
966     dev = qdev_new(TYPE_ESCC);
967     qdev_prop_set_uint32(dev, "disabled", !machine->enable_graphics);
968     qdev_prop_set_uint32(dev, "frequency", ESCC_CLOCK);
969     qdev_prop_set_uint32(dev, "it_shift", 1);
970     qdev_prop_set_chr(dev, "chrB", NULL);
971     qdev_prop_set_chr(dev, "chrA", NULL);
972     qdev_prop_set_uint32(dev, "chnBtype", escc_mouse);
973     qdev_prop_set_uint32(dev, "chnAtype", escc_kbd);
974     s = SYS_BUS_DEVICE(dev);
975     sysbus_realize_and_unref(s, &error_fatal);
976     sysbus_mmio_map(s, 0, hwdef->ms_kb_base);
977 
978     /* Logically OR both its IRQs together */
979     ms_kb_orgate = DEVICE(object_new(TYPE_OR_IRQ));
980     object_property_set_int(OBJECT(ms_kb_orgate), "num-lines", 2, &error_fatal);
981     qdev_realize_and_unref(ms_kb_orgate, NULL, &error_fatal);
982     sysbus_connect_irq(s, 0, qdev_get_gpio_in(ms_kb_orgate, 0));
983     sysbus_connect_irq(s, 1, qdev_get_gpio_in(ms_kb_orgate, 1));
984     qdev_connect_gpio_out(ms_kb_orgate, 0, slavio_irq[14]);
985 
986     dev = qdev_new(TYPE_ESCC);
987     qdev_prop_set_uint32(dev, "disabled", 0);
988     qdev_prop_set_uint32(dev, "frequency", ESCC_CLOCK);
989     qdev_prop_set_uint32(dev, "it_shift", 1);
990     qdev_prop_set_chr(dev, "chrB", serial_hd(1));
991     qdev_prop_set_chr(dev, "chrA", serial_hd(0));
992     qdev_prop_set_uint32(dev, "chnBtype", escc_serial);
993     qdev_prop_set_uint32(dev, "chnAtype", escc_serial);
994 
995     s = SYS_BUS_DEVICE(dev);
996     sysbus_realize_and_unref(s, &error_fatal);
997     sysbus_mmio_map(s, 0, hwdef->serial_base);
998 
999     /* Logically OR both its IRQs together */
1000     serial_orgate = DEVICE(object_new(TYPE_OR_IRQ));
1001     object_property_set_int(OBJECT(serial_orgate), "num-lines", 2,
1002                             &error_fatal);
1003     qdev_realize_and_unref(serial_orgate, NULL, &error_fatal);
1004     sysbus_connect_irq(s, 0, qdev_get_gpio_in(serial_orgate, 0));
1005     sysbus_connect_irq(s, 1, qdev_get_gpio_in(serial_orgate, 1));
1006     qdev_connect_gpio_out(serial_orgate, 0, slavio_irq[15]);
1007 
1008     if (hwdef->apc_base) {
1009         apc_init(hwdef->apc_base, qemu_allocate_irq(cpu_halt_signal, NULL, 0));
1010     }
1011 
1012     if (hwdef->fd_base) {
1013         /* there is zero or one floppy drive */
1014         memset(fd, 0, sizeof(fd));
1015         fd[0] = drive_get(IF_FLOPPY, 0, 0);
1016         sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
1017                           &fdc_tc);
1018     } else {
1019         fdc_tc = qemu_allocate_irq(dummy_fdc_tc, NULL, 0);
1020     }
1021 
1022     slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
1023                      slavio_irq[30], fdc_tc);
1024 
1025     if (hwdef->cs_base) {
1026         sysbus_create_simple("sun-CS4231", hwdef->cs_base,
1027                              slavio_irq[5]);
1028     }
1029 
1030     if (hwdef->dbri_base) {
1031         /* ISDN chip with attached CS4215 audio codec */
1032         /* prom space */
1033         create_unimplemented_device("sun-DBRI.prom",
1034                                     hwdef->dbri_base + 0x1000, 0x30);
1035         /* reg space */
1036         create_unimplemented_device("sun-DBRI",
1037                                     hwdef->dbri_base + 0x10000, 0x100);
1038     }
1039 
1040     if (hwdef->bpp_base) {
1041         /* parallel port */
1042         create_unimplemented_device("sun-bpp", hwdef->bpp_base, 0x20);
1043     }
1044 
1045     initrd_size = 0;
1046     kernel_size = sun4m_load_kernel(machine->kernel_filename,
1047                                     machine->initrd_filename,
1048                                     machine->ram_size, &initrd_size);
1049 
1050     nvram_init(nvram, hostid.a, machine->kernel_cmdline,
1051                machine->boot_config.order, machine->ram_size, kernel_size,
1052                graphic_width, graphic_height, graphic_depth,
1053                hwdef->nvram_machine_id, "Sun4m");
1054 
1055     if (hwdef->ecc_base)
1056         ecc_init(hwdef->ecc_base, slavio_irq[28],
1057                  hwdef->ecc_version);
1058 
1059     dev = qdev_new(TYPE_FW_CFG_MEM);
1060     fw_cfg = FW_CFG(dev);
1061     qdev_prop_set_uint32(dev, "data_width", 1);
1062     qdev_prop_set_bit(dev, "dma_enabled", false);
1063     object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG,
1064                               OBJECT(fw_cfg));
1065     s = SYS_BUS_DEVICE(dev);
1066     sysbus_realize_and_unref(s, &error_fatal);
1067     sysbus_mmio_map(s, 0, CFG_ADDR);
1068     sysbus_mmio_map(s, 1, CFG_ADDR + 2);
1069 
1070     fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
1071     fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
1072     fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size);
1073     fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
1074     fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
1075     fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_WIDTH, graphic_width);
1076     fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_HEIGHT, graphic_height);
1077     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
1078     fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
1079     if (machine->kernel_cmdline) {
1080         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
1081         pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE,
1082                          machine->kernel_cmdline);
1083         fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, machine->kernel_cmdline);
1084         fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
1085                        strlen(machine->kernel_cmdline) + 1);
1086     } else {
1087         fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
1088         fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
1089     }
1090     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
1091     fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
1092     fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, machine->boot_config.order[0]);
1093     qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
1094 }
1095 
1096 enum {
1097     ss5_id = 32,
1098     vger_id,
1099     lx_id,
1100     ss4_id,
1101     scls_id,
1102     sbook_id,
1103     ss10_id = 64,
1104     ss20_id,
1105     ss600mp_id,
1106 };
1107 
1108 static void sun4m_machine_class_init(ObjectClass *oc, void *data)
1109 {
1110     MachineClass *mc = MACHINE_CLASS(oc);
1111 
1112     mc->init = sun4m_hw_init;
1113     mc->block_default_type = IF_SCSI;
1114     mc->default_boot_order = "c";
1115     mc->default_display = "tcx";
1116     mc->default_ram_id = "sun4m.ram";
1117 }
1118 
1119 static void ss5_class_init(ObjectClass *oc, void *data)
1120 {
1121     MachineClass *mc = MACHINE_CLASS(oc);
1122     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1123     static const struct sun4m_hwdef ss5_hwdef = {
1124         .iommu_base   = 0x10000000,
1125         .iommu_pad_base = 0x10004000,
1126         .iommu_pad_len  = 0x0fffb000,
1127         .tcx_base     = 0x50000000,
1128         .cs_base      = 0x6c000000,
1129         .slavio_base  = 0x70000000,
1130         .ms_kb_base   = 0x71000000,
1131         .serial_base  = 0x71100000,
1132         .nvram_base   = 0x71200000,
1133         .fd_base      = 0x71400000,
1134         .counter_base = 0x71d00000,
1135         .intctl_base  = 0x71e00000,
1136         .idreg_base   = 0x78000000,
1137         .dma_base     = 0x78400000,
1138         .esp_base     = 0x78800000,
1139         .le_base      = 0x78c00000,
1140         .apc_base     = 0x6a000000,
1141         .afx_base     = 0x6e000000,
1142         .aux1_base    = 0x71900000,
1143         .aux2_base    = 0x71910000,
1144         .nvram_machine_id = 0x80,
1145         .machine_id = ss5_id,
1146         .iommu_version = 0x05000000,
1147         .max_mem = 0x10000000,
1148     };
1149 
1150     mc->desc = "Sun4m platform, SPARCstation 5";
1151     mc->is_default = true;
1152     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
1153     smc->hwdef = &ss5_hwdef;
1154 }
1155 
1156 static void ss10_class_init(ObjectClass *oc, void *data)
1157 {
1158     MachineClass *mc = MACHINE_CLASS(oc);
1159     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1160     static const struct sun4m_hwdef ss10_hwdef = {
1161         .iommu_base   = 0xfe0000000ULL,
1162         .tcx_base     = 0xe20000000ULL,
1163         .slavio_base  = 0xff0000000ULL,
1164         .ms_kb_base   = 0xff1000000ULL,
1165         .serial_base  = 0xff1100000ULL,
1166         .nvram_base   = 0xff1200000ULL,
1167         .fd_base      = 0xff1700000ULL,
1168         .counter_base = 0xff1300000ULL,
1169         .intctl_base  = 0xff1400000ULL,
1170         .idreg_base   = 0xef0000000ULL,
1171         .dma_base     = 0xef0400000ULL,
1172         .esp_base     = 0xef0800000ULL,
1173         .le_base      = 0xef0c00000ULL,
1174         .apc_base     = 0xefa000000ULL, /* XXX should not exist */
1175         .aux1_base    = 0xff1800000ULL,
1176         .aux2_base    = 0xff1a01000ULL,
1177         .ecc_base     = 0xf00000000ULL,
1178         .ecc_version  = 0x10000000, /* version 0, implementation 1 */
1179         .nvram_machine_id = 0x72,
1180         .machine_id = ss10_id,
1181         .iommu_version = 0x03000000,
1182         .max_mem = 0xf00000000ULL,
1183     };
1184 
1185     mc->desc = "Sun4m platform, SPARCstation 10";
1186     mc->max_cpus = 4;
1187     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
1188     smc->hwdef = &ss10_hwdef;
1189 }
1190 
1191 static void ss600mp_class_init(ObjectClass *oc, void *data)
1192 {
1193     MachineClass *mc = MACHINE_CLASS(oc);
1194     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1195     static const struct sun4m_hwdef ss600mp_hwdef = {
1196         .iommu_base   = 0xfe0000000ULL,
1197         .tcx_base     = 0xe20000000ULL,
1198         .slavio_base  = 0xff0000000ULL,
1199         .ms_kb_base   = 0xff1000000ULL,
1200         .serial_base  = 0xff1100000ULL,
1201         .nvram_base   = 0xff1200000ULL,
1202         .counter_base = 0xff1300000ULL,
1203         .intctl_base  = 0xff1400000ULL,
1204         .dma_base     = 0xef0081000ULL,
1205         .esp_base     = 0xef0080000ULL,
1206         .le_base      = 0xef0060000ULL,
1207         .apc_base     = 0xefa000000ULL, /* XXX should not exist */
1208         .aux1_base    = 0xff1800000ULL,
1209         .aux2_base    = 0xff1a01000ULL, /* XXX should not exist */
1210         .ecc_base     = 0xf00000000ULL,
1211         .ecc_version  = 0x00000000, /* version 0, implementation 0 */
1212         .nvram_machine_id = 0x71,
1213         .machine_id = ss600mp_id,
1214         .iommu_version = 0x01000000,
1215         .max_mem = 0xf00000000ULL,
1216     };
1217 
1218     mc->desc = "Sun4m platform, SPARCserver 600MP";
1219     mc->max_cpus = 4;
1220     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
1221     smc->hwdef = &ss600mp_hwdef;
1222 }
1223 
1224 static void ss20_class_init(ObjectClass *oc, void *data)
1225 {
1226     MachineClass *mc = MACHINE_CLASS(oc);
1227     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1228     static const struct sun4m_hwdef ss20_hwdef = {
1229         .iommu_base   = 0xfe0000000ULL,
1230         .tcx_base     = 0xe20000000ULL,
1231         .slavio_base  = 0xff0000000ULL,
1232         .ms_kb_base   = 0xff1000000ULL,
1233         .serial_base  = 0xff1100000ULL,
1234         .nvram_base   = 0xff1200000ULL,
1235         .fd_base      = 0xff1700000ULL,
1236         .counter_base = 0xff1300000ULL,
1237         .intctl_base  = 0xff1400000ULL,
1238         .idreg_base   = 0xef0000000ULL,
1239         .dma_base     = 0xef0400000ULL,
1240         .esp_base     = 0xef0800000ULL,
1241         .le_base      = 0xef0c00000ULL,
1242         .bpp_base     = 0xef4800000ULL,
1243         .apc_base     = 0xefa000000ULL, /* XXX should not exist */
1244         .aux1_base    = 0xff1800000ULL,
1245         .aux2_base    = 0xff1a01000ULL,
1246         .dbri_base    = 0xee0000000ULL,
1247         .sx_base      = 0xf80000000ULL,
1248         .vsimm        = {
1249             {
1250                 .reg_base  = 0x9c000000ULL,
1251                 .vram_base = 0xfc000000ULL
1252             }, {
1253                 .reg_base  = 0x90000000ULL,
1254                 .vram_base = 0xf0000000ULL
1255             }, {
1256                 .reg_base  = 0x94000000ULL
1257             }, {
1258                 .reg_base  = 0x98000000ULL
1259             }
1260         },
1261         .ecc_base     = 0xf00000000ULL,
1262         .ecc_version  = 0x20000000, /* version 0, implementation 2 */
1263         .nvram_machine_id = 0x72,
1264         .machine_id = ss20_id,
1265         .iommu_version = 0x13000000,
1266         .max_mem = 0xf00000000ULL,
1267     };
1268 
1269     mc->desc = "Sun4m platform, SPARCstation 20";
1270     mc->max_cpus = 4;
1271     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
1272     smc->hwdef = &ss20_hwdef;
1273 }
1274 
1275 static void voyager_class_init(ObjectClass *oc, void *data)
1276 {
1277     MachineClass *mc = MACHINE_CLASS(oc);
1278     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1279     static const struct sun4m_hwdef voyager_hwdef = {
1280         .iommu_base   = 0x10000000,
1281         .tcx_base     = 0x50000000,
1282         .slavio_base  = 0x70000000,
1283         .ms_kb_base   = 0x71000000,
1284         .serial_base  = 0x71100000,
1285         .nvram_base   = 0x71200000,
1286         .fd_base      = 0x71400000,
1287         .counter_base = 0x71d00000,
1288         .intctl_base  = 0x71e00000,
1289         .idreg_base   = 0x78000000,
1290         .dma_base     = 0x78400000,
1291         .esp_base     = 0x78800000,
1292         .le_base      = 0x78c00000,
1293         .apc_base     = 0x71300000, /* pmc */
1294         .aux1_base    = 0x71900000,
1295         .aux2_base    = 0x71910000,
1296         .nvram_machine_id = 0x80,
1297         .machine_id = vger_id,
1298         .iommu_version = 0x05000000,
1299         .max_mem = 0x10000000,
1300     };
1301 
1302     mc->desc = "Sun4m platform, SPARCstation Voyager";
1303     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
1304     smc->hwdef = &voyager_hwdef;
1305 }
1306 
1307 static void ss_lx_class_init(ObjectClass *oc, void *data)
1308 {
1309     MachineClass *mc = MACHINE_CLASS(oc);
1310     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1311     static const struct sun4m_hwdef ss_lx_hwdef = {
1312         .iommu_base   = 0x10000000,
1313         .iommu_pad_base = 0x10004000,
1314         .iommu_pad_len  = 0x0fffb000,
1315         .tcx_base     = 0x50000000,
1316         .slavio_base  = 0x70000000,
1317         .ms_kb_base   = 0x71000000,
1318         .serial_base  = 0x71100000,
1319         .nvram_base   = 0x71200000,
1320         .fd_base      = 0x71400000,
1321         .counter_base = 0x71d00000,
1322         .intctl_base  = 0x71e00000,
1323         .idreg_base   = 0x78000000,
1324         .dma_base     = 0x78400000,
1325         .esp_base     = 0x78800000,
1326         .le_base      = 0x78c00000,
1327         .aux1_base    = 0x71900000,
1328         .aux2_base    = 0x71910000,
1329         .nvram_machine_id = 0x80,
1330         .machine_id = lx_id,
1331         .iommu_version = 0x04000000,
1332         .max_mem = 0x10000000,
1333     };
1334 
1335     mc->desc = "Sun4m platform, SPARCstation LX";
1336     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
1337     smc->hwdef = &ss_lx_hwdef;
1338 }
1339 
1340 static void ss4_class_init(ObjectClass *oc, void *data)
1341 {
1342     MachineClass *mc = MACHINE_CLASS(oc);
1343     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1344     static const struct sun4m_hwdef ss4_hwdef = {
1345         .iommu_base   = 0x10000000,
1346         .tcx_base     = 0x50000000,
1347         .cs_base      = 0x6c000000,
1348         .slavio_base  = 0x70000000,
1349         .ms_kb_base   = 0x71000000,
1350         .serial_base  = 0x71100000,
1351         .nvram_base   = 0x71200000,
1352         .fd_base      = 0x71400000,
1353         .counter_base = 0x71d00000,
1354         .intctl_base  = 0x71e00000,
1355         .idreg_base   = 0x78000000,
1356         .dma_base     = 0x78400000,
1357         .esp_base     = 0x78800000,
1358         .le_base      = 0x78c00000,
1359         .apc_base     = 0x6a000000,
1360         .aux1_base    = 0x71900000,
1361         .aux2_base    = 0x71910000,
1362         .nvram_machine_id = 0x80,
1363         .machine_id = ss4_id,
1364         .iommu_version = 0x05000000,
1365         .max_mem = 0x10000000,
1366     };
1367 
1368     mc->desc = "Sun4m platform, SPARCstation 4";
1369     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
1370     smc->hwdef = &ss4_hwdef;
1371 }
1372 
1373 static void scls_class_init(ObjectClass *oc, void *data)
1374 {
1375     MachineClass *mc = MACHINE_CLASS(oc);
1376     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1377     static const struct sun4m_hwdef scls_hwdef = {
1378         .iommu_base   = 0x10000000,
1379         .tcx_base     = 0x50000000,
1380         .slavio_base  = 0x70000000,
1381         .ms_kb_base   = 0x71000000,
1382         .serial_base  = 0x71100000,
1383         .nvram_base   = 0x71200000,
1384         .fd_base      = 0x71400000,
1385         .counter_base = 0x71d00000,
1386         .intctl_base  = 0x71e00000,
1387         .idreg_base   = 0x78000000,
1388         .dma_base     = 0x78400000,
1389         .esp_base     = 0x78800000,
1390         .le_base      = 0x78c00000,
1391         .apc_base     = 0x6a000000,
1392         .aux1_base    = 0x71900000,
1393         .aux2_base    = 0x71910000,
1394         .nvram_machine_id = 0x80,
1395         .machine_id = scls_id,
1396         .iommu_version = 0x05000000,
1397         .max_mem = 0x10000000,
1398     };
1399 
1400     mc->desc = "Sun4m platform, SPARCClassic";
1401     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
1402     smc->hwdef = &scls_hwdef;
1403 }
1404 
1405 static void sbook_class_init(ObjectClass *oc, void *data)
1406 {
1407     MachineClass *mc = MACHINE_CLASS(oc);
1408     Sun4mMachineClass *smc = SUN4M_MACHINE_CLASS(mc);
1409     static const struct sun4m_hwdef sbook_hwdef = {
1410         .iommu_base   = 0x10000000,
1411         .tcx_base     = 0x50000000, /* XXX */
1412         .slavio_base  = 0x70000000,
1413         .ms_kb_base   = 0x71000000,
1414         .serial_base  = 0x71100000,
1415         .nvram_base   = 0x71200000,
1416         .fd_base      = 0x71400000,
1417         .counter_base = 0x71d00000,
1418         .intctl_base  = 0x71e00000,
1419         .idreg_base   = 0x78000000,
1420         .dma_base     = 0x78400000,
1421         .esp_base     = 0x78800000,
1422         .le_base      = 0x78c00000,
1423         .apc_base     = 0x6a000000,
1424         .aux1_base    = 0x71900000,
1425         .aux2_base    = 0x71910000,
1426         .nvram_machine_id = 0x80,
1427         .machine_id = sbook_id,
1428         .iommu_version = 0x05000000,
1429         .max_mem = 0x10000000,
1430     };
1431 
1432     mc->desc = "Sun4m platform, SPARCbook";
1433     mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
1434     smc->hwdef = &sbook_hwdef;
1435 }
1436 
1437 static const TypeInfo sun4m_machine_types[] = {
1438     {
1439         .name           = MACHINE_TYPE_NAME("SS-5"),
1440         .parent         = TYPE_SUN4M_MACHINE,
1441         .class_init     = ss5_class_init,
1442     }, {
1443         .name           = MACHINE_TYPE_NAME("SS-10"),
1444         .parent         = TYPE_SUN4M_MACHINE,
1445         .class_init     = ss10_class_init,
1446     }, {
1447         .name           = MACHINE_TYPE_NAME("SS-600MP"),
1448         .parent         = TYPE_SUN4M_MACHINE,
1449         .class_init     = ss600mp_class_init,
1450     }, {
1451         .name           = MACHINE_TYPE_NAME("SS-20"),
1452         .parent         = TYPE_SUN4M_MACHINE,
1453         .class_init     = ss20_class_init,
1454     }, {
1455         .name           = MACHINE_TYPE_NAME("Voyager"),
1456         .parent         = TYPE_SUN4M_MACHINE,
1457         .class_init     = voyager_class_init,
1458     }, {
1459         .name           = MACHINE_TYPE_NAME("LX"),
1460         .parent         = TYPE_SUN4M_MACHINE,
1461         .class_init     = ss_lx_class_init,
1462     }, {
1463         .name           = MACHINE_TYPE_NAME("SS-4"),
1464         .parent         = TYPE_SUN4M_MACHINE,
1465         .class_init     = ss4_class_init,
1466     }, {
1467         .name           = MACHINE_TYPE_NAME("SPARCClassic"),
1468         .parent         = TYPE_SUN4M_MACHINE,
1469         .class_init     = scls_class_init,
1470     }, {
1471         .name           = MACHINE_TYPE_NAME("SPARCbook"),
1472         .parent         = TYPE_SUN4M_MACHINE,
1473         .class_init     = sbook_class_init,
1474     }, {
1475         .name           = TYPE_SUN4M_MACHINE,
1476         .parent         = TYPE_MACHINE,
1477         .class_size     = sizeof(Sun4mMachineClass),
1478         .class_init     = sun4m_machine_class_init,
1479         .abstract       = true,
1480     }
1481 };
1482 
1483 DEFINE_TYPES(sun4m_machine_types)
1484 
1485 static void sun4m_register_types(void)
1486 {
1487     type_register_static(&idreg_info);
1488     type_register_static(&afx_info);
1489     type_register_static(&prom_info);
1490     type_register_static(&ram_info);
1491 }
1492 
1493 type_init(sun4m_register_types)
1494