| 1 | /* |
| 2 | * QEMU Alpha DP264/CLIPPER hardware system emulator. |
| 3 | * |
| 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 | */ |
| 8 | |
| 9 | #include "qemu/osdep.h" |
| 10 | #include "target/alpha/cpu.h" |
| 11 | #include "exec/target_page.h" |
| 12 | #include "elf.h" |
| 13 | #include "hw/core/loader.h" |
| 14 | #include "alpha_sys.h" |
| 15 | #include "qemu/error-report.h" |
| 16 | #include "hw/rtc/mc146818rtc.h" |
| 17 | #include "hw/ide/pci.h" |
| 18 | #include "hw/isa/superio.h" |
| 19 | #include "qemu/datadir.h" |
| 20 | |
| 21 | static uint64_t cpu_alpha_superpage_to_phys(void *opaque, uint64_t addr) |
| 22 | { |
| 23 | if (((addr >> 41) & 3) == 2) { |
| 24 | addr &= 0xffffffffffull; |
| 25 | } |
| 26 | return addr; |
| 27 | } |
| 28 | |
| 29 | /* Note that there are at least 3 viewpoints of IRQ numbers on Alpha systems. |
| 30 | (0) The dev_irq_n lines into the cpu, which we totally ignore, |
| 31 | (1) The DRIR lines in the typhoon chipset, |
| 32 | (2) The "vector" aka mangled interrupt number reported by SRM PALcode, |
| 33 | (3) The interrupt number assigned by the kernel. |
| 34 | The following function is concerned with (1) only. */ |
| 35 | |
| 36 | static int clipper_pci_map_irq(PCIDevice *d, int irq_num) |
| 37 | { |
| 38 | int slot = d->devfn >> 3; |
| 39 | |
| 40 | assert(irq_num >= 0 && irq_num <= 3); |
| 41 | |
| 42 | return (slot + 1) * 4 + irq_num; |
| 43 | } |
| 44 | |
| 45 | static void clipper_init(MachineState *machine) |
| 46 | { |
| 47 | ram_addr_t ram_size = machine->ram_size; |
| 48 | const char *kernel_filename = machine->kernel_filename; |
| 49 | const char *kernel_cmdline = machine->kernel_cmdline; |
| 50 | const char *initrd_filename = machine->initrd_filename; |
| 51 | MachineClass *mc = MACHINE_GET_CLASS(machine); |
| 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; |
| 64 | |
| 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)); |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * arg0 -> memory size |
| 73 | * arg1 -> kernel entry point |
| 74 | * arg2 -> config word |
| 75 | * |
| 76 | * Config word: bits 0-5 -> ncpus |
| 77 | * bit 6 -> nographics option (for HWRPB CTB) |
| 78 | * |
| 79 | * See init_hwrpb() in the PALcode. |
| 80 | */ |
| 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); |
| 84 | |
| 85 | /* |
| 86 | * Init the chipset. Because we're using CLIPPER IRQ mappings, |
| 87 | * the minimum PCI device IdSel is 1. |
| 88 | */ |
| 89 | pci_bus = typhoon_init(machine->ram, &isa_irq, &rtc_irq, cpus, |
| 90 | clipper_pci_map_irq, PCI_DEVFN(1, 0)); |
| 91 | |
| 92 | /* |
| 93 | * Init the PCI -> ISA bridge. |
| 94 | * |
| 95 | * Technically, PCI-based Alphas shipped with one of three different |
| 96 | * PCI-ISA bridges: |
| 97 | * |
| 98 | * - Intel i82378 SIO |
| 99 | * - Cypress CY82c693UB |
| 100 | * - ALI M1533 |
| 101 | * |
| 102 | * (An Intel i82375 PCI-EISA bridge was also used on some models.) |
| 103 | * |
| 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). |
| 109 | * |
| 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. |
| 112 | */ |
| 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")); |
| 115 | |
| 116 | /* Connect the ISA PIC to the Typhoon IRQ used for ISA interrupts. */ |
| 117 | qdev_connect_gpio_out(i82378_dev, 0, isa_irq); |
| 118 | |
| 119 | /* Since we have an SRM-compatible PALcode, use the SRM epoch. */ |
| 120 | mc146818_rtc_init(isa_bus, 1900, rtc_irq); |
| 121 | |
| 122 | /* VGA setup. Don't bother loading the bios. */ |
| 123 | pci_vga_init(pci_bus); |
| 124 | |
| 125 | /* Network setup. e1000 is good enough, failing Tulip support. */ |
| 126 | pci_init_nic_devices(pci_bus, mc->default_nic); |
| 127 | |
| 128 | /* Super I/O */ |
| 129 | isa_create_simple(isa_bus, TYPE_SMC37C669_SUPERIO); |
| 130 | |
| 131 | /* IDE disk setup. */ |
| 132 | pci_dev = pci_create_simple(pci_bus, -1, "cmd646-ide"); |
| 133 | pci_ide_create_devs(pci_dev); |
| 134 | |
| 135 | /* Load PALcode. Given that this is not "real" cpu palcode, |
| 136 | but one explicitly written for the emulation, we might as |
| 137 | well load it directly from and ELF image. */ |
| 138 | palcode_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, |
| 139 | machine->firmware ?: "palcode-clipper"); |
| 140 | if (palcode_filename == NULL) { |
| 141 | error_report("no palcode provided"); |
| 142 | exit(1); |
| 143 | } |
| 144 | size = load_elf(palcode_filename, NULL, cpu_alpha_superpage_to_phys, |
| 145 | NULL, &palcode_entry, NULL, NULL, NULL, |
| 146 | ELFDATA2LSB, EM_ALPHA, 0, 0); |
| 147 | if (size < 0) { |
| 148 | error_report("could not load palcode '%s'", palcode_filename); |
| 149 | exit(1); |
| 150 | } |
| 151 | g_free(palcode_filename); |
| 152 | |
| 153 | /* Start all cpus at the PALcode RESET entry point. */ |
| 154 | for (i = 0; i < smp_cpus; ++i) { |
| 155 | cpus[i]->env.pc = palcode_entry; |
| 156 | cpus[i]->env.palbr = palcode_entry; |
| 157 | } |
| 158 | |
| 159 | /* Load a kernel. */ |
| 160 | if (kernel_filename) { |
| 161 | uint64_t param_offset; |
| 162 | |
| 163 | size = load_elf(kernel_filename, NULL, cpu_alpha_superpage_to_phys, |
| 164 | NULL, &kernel_entry, &kernel_low, NULL, NULL, |
| 165 | ELFDATA2LSB, EM_ALPHA, 0, 0); |
| 166 | if (size < 0) { |
| 167 | error_report("could not load kernel '%s'", kernel_filename); |
| 168 | exit(1); |
| 169 | } |
| 170 | |
| 171 | cpus[0]->env.trap_arg1 = kernel_entry; |
| 172 | |
| 173 | param_offset = kernel_low - 0x6000; |
| 174 | |
| 175 | if (kernel_cmdline) { |
| 176 | pstrcpy_targphys("cmdline", param_offset, 0x100, kernel_cmdline); |
| 177 | } |
| 178 | |
| 179 | if (initrd_filename) { |
| 180 | long initrd_base; |
| 181 | int64_t initrd_size; |
| 182 | |
| 183 | initrd_size = get_image_size(initrd_filename, NULL); |
| 184 | if (initrd_size < 0) { |
| 185 | error_report("could not load initial ram disk '%s'", |
| 186 | initrd_filename); |
| 187 | exit(1); |
| 188 | } |
| 189 | |
| 190 | /* Put the initrd image as high in memory as possible. */ |
| 191 | initrd_base = (ram_size - initrd_size) & TARGET_PAGE_MASK; |
| 192 | load_image_targphys(initrd_filename, initrd_base, |
| 193 | ram_size - initrd_base, &error_fatal); |
| 194 | |
| 195 | address_space_stq_le(&address_space_memory, param_offset + 0x100, |
| 196 | initrd_base + 0xfffffc0000000000ULL, |
| 197 | MEMTXATTRS_UNSPECIFIED, NULL); |
| 198 | address_space_stq_le(&address_space_memory, param_offset + 0x108, |
| 199 | initrd_size, MEMTXATTRS_UNSPECIFIED, NULL); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | static void clipper_machine_init(MachineClass *mc) |
| 205 | { |
| 206 | mc->desc = "Alpha DP264/CLIPPER"; |
| 207 | mc->init = clipper_init; |
| 208 | mc->block_default_type = IF_IDE; |
| 209 | mc->max_cpus = 4; |
| 210 | mc->is_default = true; |
| 211 | mc->default_cpu_type = ALPHA_CPU_TYPE_NAME("ev67"); |
| 212 | mc->default_ram_id = "ram"; |
| 213 | mc->default_nic = "e1000"; |
| 214 | } |
| 215 | |
| 216 | DEFINE_MACHINE("clipper", clipper_machine_init) |