qapi: Improve specificity of type/member descriptions
[qemu/armbru.git] / hw / alpha / dp264.c
blob4161f559a7bcfbc4117a4fdcd4af0eed71fda8e5
1 /*
2 * QEMU Alpha DP264/CLIPPER hardware system emulator.
4 * Choose CLIPPER IRQ mappings over, say, DP264, MONET, or WEBBRICK
5 * variants because CLIPPER doesn't have an SMC669 SuperIO controller
6 * that we need to emulate as well.
7 */
9 #include "qemu/osdep.h"
10 #include "cpu.h"
11 #include "elf.h"
12 #include "hw/loader.h"
13 #include "alpha_sys.h"
14 #include "qemu/error-report.h"
15 #include "hw/rtc/mc146818rtc.h"
16 #include "hw/ide/pci.h"
17 #include "hw/isa/superio.h"
18 #include "net/net.h"
19 #include "qemu/cutils.h"
20 #include "qemu/datadir.h"
22 static uint64_t cpu_alpha_superpage_to_phys(void *opaque, uint64_t addr)
24 if (((addr >> 41) & 3) == 2) {
25 addr &= 0xffffffffffull;
27 return addr;
30 /* Note that there are at least 3 viewpoints of IRQ numbers on Alpha systems.
31 (0) The dev_irq_n lines into the cpu, which we totally ignore,
32 (1) The DRIR lines in the typhoon chipset,
33 (2) The "vector" aka mangled interrupt number reported by SRM PALcode,
34 (3) The interrupt number assigned by the kernel.
35 The following function is concerned with (1) only. */
37 static int clipper_pci_map_irq(PCIDevice *d, int irq_num)
39 int slot = d->devfn >> 3;
41 assert(irq_num >= 0 && irq_num <= 3);
43 return (slot + 1) * 4 + irq_num;
46 static void clipper_init(MachineState *machine)
48 ram_addr_t ram_size = machine->ram_size;
49 const char *kernel_filename = machine->kernel_filename;
50 const char *kernel_cmdline = machine->kernel_cmdline;
51 const char *initrd_filename = machine->initrd_filename;
52 AlphaCPU *cpus[4];
53 PCIBus *pci_bus;
54 PCIDevice *pci_dev;
55 DeviceState *i82378_dev;
56 ISABus *isa_bus;
57 qemu_irq rtc_irq;
58 qemu_irq isa_irq;
59 long size, i;
60 char *palcode_filename;
61 uint64_t palcode_entry;
62 uint64_t kernel_entry, kernel_low;
63 unsigned int smp_cpus = machine->smp.cpus;
65 /* Create up to 4 cpus. */
66 memset(cpus, 0, sizeof(cpus));
67 for (i = 0; i < smp_cpus; ++i) {
68 cpus[i] = ALPHA_CPU(cpu_create(machine->cpu_type));
72 * arg0 -> memory size
73 * arg1 -> kernel entry point
74 * arg2 -> config word
76 * Config word: bits 0-5 -> ncpus
77 * bit 6 -> nographics option (for HWRPB CTB)
79 * See init_hwrpb() in the PALcode.
81 cpus[0]->env.trap_arg0 = ram_size;
82 cpus[0]->env.trap_arg1 = 0;
83 cpus[0]->env.trap_arg2 = smp_cpus | (!machine->enable_graphics << 6);
86 * Init the chipset. Because we're using CLIPPER IRQ mappings,
87 * the minimum PCI device IdSel is 1.
89 pci_bus = typhoon_init(machine->ram, &isa_irq, &rtc_irq, cpus,
90 clipper_pci_map_irq, PCI_DEVFN(1, 0));
93 * Init the PCI -> ISA bridge.
95 * Technically, PCI-based Alphas shipped with one of three different
96 * PCI-ISA bridges:
98 * - Intel i82378 SIO
99 * - Cypress CY82c693UB
100 * - ALI M1533
102 * (An Intel i82375 PCI-EISA bridge was also used on some models.)
104 * For simplicity, we model an i82378 here, even though it wouldn't
105 * have been on any Tsunami/Typhoon systems; it's close enough, and
106 * we don't want to deal with modelling the CY82c693UB (which has
107 * incompatible edge/level control registers, plus other peripherals
108 * like IDE and USB) or the M1533 (which also has IDE and USB).
110 * Importantly, we need to provide a PCI device node for it, otherwise
111 * some operating systems won't notice there's an ISA bus to configure.
113 i82378_dev = DEVICE(pci_create_simple(pci_bus, PCI_DEVFN(7, 0), "i82378"));
114 isa_bus = ISA_BUS(qdev_get_child_bus(i82378_dev, "isa.0"));
116 /* Connect the ISA PIC to the Typhoon IRQ used for ISA interrupts. */
117 qdev_connect_gpio_out(i82378_dev, 0, isa_irq);
119 /* Since we have an SRM-compatible PALcode, use the SRM epoch. */
120 mc146818_rtc_init(isa_bus, 1900, rtc_irq);
122 /* VGA setup. Don't bother loading the bios. */
123 pci_vga_init(pci_bus);
125 /* Network setup. e1000 is good enough, failing Tulip support. */
126 for (i = 0; i < nb_nics; i++) {
127 pci_nic_init_nofail(&nd_table[i], pci_bus, "e1000", NULL);
130 /* Super I/O */
131 isa_create_simple(isa_bus, TYPE_SMC37C669_SUPERIO);
133 /* IDE disk setup. */
134 pci_dev = pci_create_simple(pci_bus, -1, "cmd646-ide");
135 pci_ide_create_devs(pci_dev);
137 /* Load PALcode. Given that this is not "real" cpu palcode,
138 but one explicitly written for the emulation, we might as
139 well load it directly from and ELF image. */
140 palcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS,
141 machine->firmware ?: "palcode-clipper");
142 if (palcode_filename == NULL) {
143 error_report("no palcode provided");
144 exit(1);
146 size = load_elf(palcode_filename, NULL, cpu_alpha_superpage_to_phys,
147 NULL, &palcode_entry, NULL, NULL, NULL,
148 0, EM_ALPHA, 0, 0);
149 if (size < 0) {
150 error_report("could not load palcode '%s'", palcode_filename);
151 exit(1);
153 g_free(palcode_filename);
155 /* Start all cpus at the PALcode RESET entry point. */
156 for (i = 0; i < smp_cpus; ++i) {
157 cpus[i]->env.pc = palcode_entry;
158 cpus[i]->env.palbr = palcode_entry;
161 /* Load a kernel. */
162 if (kernel_filename) {
163 uint64_t param_offset;
165 size = load_elf(kernel_filename, NULL, cpu_alpha_superpage_to_phys,
166 NULL, &kernel_entry, &kernel_low, NULL, NULL,
167 0, EM_ALPHA, 0, 0);
168 if (size < 0) {
169 error_report("could not load kernel '%s'", kernel_filename);
170 exit(1);
173 cpus[0]->env.trap_arg1 = kernel_entry;
175 param_offset = kernel_low - 0x6000;
177 if (kernel_cmdline) {
178 pstrcpy_targphys("cmdline", param_offset, 0x100, kernel_cmdline);
181 if (initrd_filename) {
182 long initrd_base;
183 int64_t initrd_size;
185 initrd_size = get_image_size(initrd_filename);
186 if (initrd_size < 0) {
187 error_report("could not load initial ram disk '%s'",
188 initrd_filename);
189 exit(1);
192 /* Put the initrd image as high in memory as possible. */
193 initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK;
194 load_image_targphys(initrd_filename, initrd_base,
195 ram_size - initrd_base);
197 address_space_stq(&address_space_memory, param_offset + 0x100,
198 initrd_base + 0xfffffc0000000000ULL,
199 MEMTXATTRS_UNSPECIFIED,
200 NULL);
201 address_space_stq(&address_space_memory, param_offset + 0x108,
202 initrd_size, MEMTXATTRS_UNSPECIFIED, NULL);
207 static void clipper_machine_init(MachineClass *mc)
209 mc->desc = "Alpha DP264/CLIPPER";
210 mc->init = clipper_init;
211 mc->block_default_type = IF_IDE;
212 mc->max_cpus = 4;
213 mc->is_default = true;
214 mc->default_cpu_type = ALPHA_CPU_TYPE_NAME("ev67");
215 mc->default_ram_id = "ram";
218 DEFINE_MACHINE("clipper", clipper_machine_init)