]>
Commit | Line | Data |
---|---|---|
813dff13 HD |
1 | /* |
2 | * QEMU HPPA hardware system emulator. | |
3 | * Copyright 2018 Helge Deller <deller@gmx.de> | |
4 | */ | |
5 | ||
6 | #include "qemu/osdep.h" | |
7 | #include "qemu-common.h" | |
8 | #include "cpu.h" | |
813dff13 HD |
9 | #include "elf.h" |
10 | #include "hw/loader.h" | |
11 | #include "hw/boards.h" | |
12 | #include "qemu/error-report.h" | |
71e8a915 | 13 | #include "sysemu/reset.h" |
813dff13 | 14 | #include "sysemu/sysemu.h" |
bcdb9064 | 15 | #include "hw/rtc/mc146818rtc.h" |
813dff13 HD |
16 | #include "hw/timer/i8254.h" |
17 | #include "hw/char/serial.h" | |
376b8519 | 18 | #include "hw/net/lasi_82596.h" |
070e9a1e | 19 | #include "hppa_sys.h" |
c108cc59 | 20 | #include "qemu/units.h" |
813dff13 | 21 | #include "qapi/error.h" |
852c27e2 | 22 | #include "net/net.h" |
691cbbad | 23 | #include "qemu/log.h" |
e07c4f44 | 24 | #include "net/net.h" |
813dff13 | 25 | |
a72bd606 HD |
26 | #define MAX_IDE_BUS 2 |
27 | ||
28 | static ISABus *hppa_isa_bus(void) | |
29 | { | |
30 | ISABus *isa_bus; | |
31 | qemu_irq *isa_irqs; | |
32 | MemoryRegion *isa_region; | |
33 | ||
34 | isa_region = g_new(MemoryRegion, 1); | |
35 | memory_region_init_io(isa_region, NULL, &hppa_pci_ignore_ops, | |
36 | NULL, "isa-io", 0x800); | |
37 | memory_region_add_subregion(get_system_memory(), IDE_HPA, | |
38 | isa_region); | |
39 | ||
40 | isa_bus = isa_bus_new(NULL, get_system_memory(), isa_region, | |
41 | &error_abort); | |
42 | isa_irqs = i8259_init(isa_bus, | |
43 | /* qemu_allocate_irq(dino_set_isa_irq, s, 0)); */ | |
44 | NULL); | |
45 | isa_bus_irqs(isa_bus, isa_irqs); | |
46 | ||
47 | return isa_bus; | |
48 | } | |
49 | ||
50 | static uint64_t cpu_hppa_to_phys(void *opaque, uint64_t addr) | |
51 | { | |
52 | addr &= (0x10000000 - 1); | |
53 | return addr; | |
54 | } | |
55 | ||
56 | static HPPACPU *cpu[HPPA_MAX_CPUS]; | |
57 | static uint64_t firmware_entry; | |
813dff13 HD |
58 | |
59 | static void machine_hppa_init(MachineState *machine) | |
60 | { | |
a72bd606 HD |
61 | const char *kernel_filename = machine->kernel_filename; |
62 | const char *kernel_cmdline = machine->kernel_cmdline; | |
63 | const char *initrd_filename = machine->initrd_filename; | |
877eb21d | 64 | DeviceState *dev; |
a72bd606 HD |
65 | PCIBus *pci_bus; |
66 | ISABus *isa_bus; | |
67 | qemu_irq rtc_irq, serial_irq; | |
68 | char *firmware_filename; | |
69 | uint64_t firmware_low, firmware_high; | |
70 | long size; | |
71 | uint64_t kernel_entry = 0, kernel_low, kernel_high; | |
72 | MemoryRegion *addr_space = get_system_memory(); | |
73 | MemoryRegion *rom_region; | |
a72bd606 HD |
74 | MemoryRegion *cpu_region; |
75 | long i; | |
33decbd2 | 76 | unsigned int smp_cpus = machine->smp.cpus; |
4765384c | 77 | SysBusDevice *s; |
a72bd606 | 78 | |
a72bd606 HD |
79 | /* Create CPUs. */ |
80 | for (i = 0; i < smp_cpus; i++) { | |
266a880e | 81 | char *name = g_strdup_printf("cpu%ld-io-eir", i); |
a72bd606 HD |
82 | cpu[i] = HPPA_CPU(cpu_create(machine->cpu_type)); |
83 | ||
84 | cpu_region = g_new(MemoryRegion, 1); | |
85 | memory_region_init_io(cpu_region, OBJECT(cpu[i]), &hppa_io_eir_ops, | |
266a880e | 86 | cpu[i], name, 4); |
a72bd606 HD |
87 | memory_region_add_subregion(addr_space, CPU_HPA + i * 0x1000, |
88 | cpu_region); | |
266a880e | 89 | g_free(name); |
a72bd606 HD |
90 | } |
91 | ||
a72bd606 | 92 | /* Main memory region. */ |
b7746b11 PMD |
93 | if (machine->ram_size > 3 * GiB) { |
94 | error_report("RAM size is currently restricted to 3GB"); | |
95 | exit(EXIT_FAILURE); | |
96 | } | |
7c59c1e0 IM |
97 | memory_region_add_subregion_overlap(addr_space, 0, machine->ram, -1); |
98 | ||
a72bd606 | 99 | |
376b8519 HD |
100 | /* Init Lasi chip */ |
101 | lasi_init(addr_space); | |
102 | ||
a72bd606 HD |
103 | /* Init Dino (PCI host bus chip). */ |
104 | pci_bus = dino_init(addr_space, &rtc_irq, &serial_irq); | |
105 | assert(pci_bus); | |
106 | ||
107 | /* Create ISA bus. */ | |
108 | isa_bus = hppa_isa_bus(); | |
109 | assert(isa_bus); | |
110 | ||
111 | /* Realtime clock, used by firmware for PDC_TOD call. */ | |
112 | mc146818_rtc_init(isa_bus, 2000, rtc_irq); | |
113 | ||
114 | /* Serial code setup. */ | |
9bca0edb | 115 | if (serial_hd(0)) { |
a72bd606 HD |
116 | uint32_t addr = DINO_UART_HPA + 0x800; |
117 | serial_mm_init(addr_space, addr, 0, serial_irq, | |
9bca0edb | 118 | 115200, serial_hd(0), DEVICE_BIG_ENDIAN); |
a72bd606 HD |
119 | } |
120 | ||
121 | /* SCSI disk setup. */ | |
877eb21d MCA |
122 | dev = DEVICE(pci_create_simple(pci_bus, -1, "lsi53c895a")); |
123 | lsi53c8xx_handle_legacy_cmdline(dev); | |
a72bd606 | 124 | |
4765384c SS |
125 | /* Graphics setup. */ |
126 | if (machine->enable_graphics && vga_interface_type != VGA_NONE) { | |
3e80f690 MA |
127 | dev = qdev_new("artist"); |
128 | qdev_realize_and_unref(dev, NULL, &error_fatal); | |
4765384c SS |
129 | s = SYS_BUS_DEVICE(dev); |
130 | sysbus_mmio_map(s, 0, LASI_GFX_HPA); | |
131 | sysbus_mmio_map(s, 1, ARTIST_FB_ADDR); | |
132 | } | |
133 | ||
0e6de551 | 134 | /* Network setup. */ |
a72bd606 | 135 | for (i = 0; i < nb_nics; i++) { |
376b8519 | 136 | if (!enable_lasi_lan()) { |
0e6de551 | 137 | pci_nic_init_nofail(&nd_table[i], pci_bus, "tulip", NULL); |
376b8519 | 138 | } |
a72bd606 HD |
139 | } |
140 | ||
141 | /* Load firmware. Given that this is not "real" firmware, | |
142 | but one explicitly written for the emulation, we might as | |
143 | well load it directly from an ELF image. */ | |
144 | firmware_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, | |
145 | bios_name ? bios_name : | |
146 | "hppa-firmware.img"); | |
147 | if (firmware_filename == NULL) { | |
148 | error_report("no firmware provided"); | |
149 | exit(1); | |
150 | } | |
151 | ||
4366e1db | 152 | size = load_elf(firmware_filename, NULL, NULL, NULL, |
6cdda0ff | 153 | &firmware_entry, &firmware_low, &firmware_high, NULL, |
a72bd606 HD |
154 | true, EM_PARISC, 0, 0); |
155 | ||
156 | /* Unfortunately, load_elf sign-extends reading elf32. */ | |
157 | firmware_entry = (target_ureg)firmware_entry; | |
158 | firmware_low = (target_ureg)firmware_low; | |
159 | firmware_high = (target_ureg)firmware_high; | |
160 | ||
161 | if (size < 0) { | |
162 | error_report("could not load firmware '%s'", firmware_filename); | |
163 | exit(1); | |
164 | } | |
691cbbad RH |
165 | qemu_log_mask(CPU_LOG_PAGE, "Firmware loaded at 0x%08" PRIx64 |
166 | "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 ".\n", | |
167 | firmware_low, firmware_high, firmware_entry); | |
8262863d | 168 | if (firmware_low < FIRMWARE_START || firmware_high >= FIRMWARE_END) { |
a72bd606 HD |
169 | error_report("Firmware overlaps with memory or IO space"); |
170 | exit(1); | |
171 | } | |
172 | g_free(firmware_filename); | |
173 | ||
174 | rom_region = g_new(MemoryRegion, 1); | |
6a3a2e82 IM |
175 | memory_region_init_ram(rom_region, NULL, "firmware", |
176 | (FIRMWARE_END - FIRMWARE_START), &error_fatal); | |
a72bd606 HD |
177 | memory_region_add_subregion(addr_space, FIRMWARE_START, rom_region); |
178 | ||
179 | /* Load kernel */ | |
180 | if (kernel_filename) { | |
4366e1db | 181 | size = load_elf(kernel_filename, NULL, &cpu_hppa_to_phys, |
6cdda0ff | 182 | NULL, &kernel_entry, &kernel_low, &kernel_high, NULL, |
a72bd606 HD |
183 | true, EM_PARISC, 0, 0); |
184 | ||
185 | /* Unfortunately, load_elf sign-extends reading elf32. */ | |
186 | kernel_entry = (target_ureg) cpu_hppa_to_phys(NULL, kernel_entry); | |
187 | kernel_low = (target_ureg)kernel_low; | |
188 | kernel_high = (target_ureg)kernel_high; | |
189 | ||
190 | if (size < 0) { | |
191 | error_report("could not load kernel '%s'", kernel_filename); | |
192 | exit(1); | |
193 | } | |
691cbbad RH |
194 | qemu_log_mask(CPU_LOG_PAGE, "Kernel loaded at 0x%08" PRIx64 |
195 | "-0x%08" PRIx64 ", entry at 0x%08" PRIx64 | |
c108cc59 PMD |
196 | ", size %" PRIu64 " kB\n", |
197 | kernel_low, kernel_high, kernel_entry, size / KiB); | |
a72bd606 HD |
198 | |
199 | if (kernel_cmdline) { | |
200 | cpu[0]->env.gr[24] = 0x4000; | |
201 | pstrcpy_targphys("cmdline", cpu[0]->env.gr[24], | |
202 | TARGET_PAGE_SIZE, kernel_cmdline); | |
203 | } | |
204 | ||
205 | if (initrd_filename) { | |
206 | ram_addr_t initrd_base; | |
f3839fda | 207 | int64_t initrd_size; |
a72bd606 HD |
208 | |
209 | initrd_size = get_image_size(initrd_filename); | |
210 | if (initrd_size < 0) { | |
211 | error_report("could not load initial ram disk '%s'", | |
212 | initrd_filename); | |
213 | exit(1); | |
214 | } | |
215 | ||
216 | /* Load the initrd image high in memory. | |
217 | Mirror the algorithm used by palo: | |
218 | (1) Due to sign-extension problems and PDC, | |
219 | put the initrd no higher than 1G. | |
220 | (2) Reserve 64k for stack. */ | |
c108cc59 PMD |
221 | initrd_base = MIN(ram_size, 1 * GiB); |
222 | initrd_base = initrd_base - 64 * KiB; | |
a72bd606 HD |
223 | initrd_base = (initrd_base - initrd_size) & TARGET_PAGE_MASK; |
224 | ||
225 | if (initrd_base < kernel_high) { | |
226 | error_report("kernel and initial ram disk too large!"); | |
227 | exit(1); | |
228 | } | |
229 | ||
230 | load_image_targphys(initrd_filename, initrd_base, initrd_size); | |
231 | cpu[0]->env.gr[23] = initrd_base; | |
232 | cpu[0]->env.gr[22] = initrd_base + initrd_size; | |
233 | } | |
234 | } | |
235 | ||
236 | if (!kernel_entry) { | |
237 | /* When booting via firmware, tell firmware if we want interactive | |
238 | * mode (kernel_entry=1), and to boot from CD (gr[24]='d') | |
239 | * or hard disc * (gr[24]='c'). | |
240 | */ | |
241 | kernel_entry = boot_menu ? 1 : 0; | |
242 | cpu[0]->env.gr[24] = machine->boot_order[0]; | |
243 | } | |
244 | ||
245 | /* We jump to the firmware entry routine and pass the | |
246 | * various parameters in registers. After firmware initialization, | |
247 | * firmware will start the Linux kernel with ramdisk and cmdline. | |
248 | */ | |
249 | cpu[0]->env.gr[26] = ram_size; | |
250 | cpu[0]->env.gr[25] = kernel_entry; | |
251 | ||
252 | /* tell firmware how many SMP CPUs to present in inventory table */ | |
253 | cpu[0]->env.gr[21] = smp_cpus; | |
813dff13 HD |
254 | } |
255 | ||
a0628599 | 256 | static void hppa_machine_reset(MachineState *ms) |
a72bd606 | 257 | { |
33decbd2 | 258 | unsigned int smp_cpus = ms->smp.cpus; |
a72bd606 HD |
259 | int i; |
260 | ||
261 | qemu_devices_reset(); | |
262 | ||
263 | /* Start all CPUs at the firmware entry point. | |
264 | * Monarch CPU will initialize firmware, secondary CPUs | |
265 | * will enter a small idle look and wait for rendevouz. */ | |
266 | for (i = 0; i < smp_cpus; i++) { | |
267 | cpu_set_pc(CPU(cpu[i]), firmware_entry); | |
268 | cpu[i]->env.gr[5] = CPU_HPA + i * 0x1000; | |
269 | } | |
270 | ||
271 | /* already initialized by machine_hppa_init()? */ | |
272 | if (cpu[0]->env.gr[26] == ram_size) { | |
273 | return; | |
274 | } | |
275 | ||
276 | cpu[0]->env.gr[26] = ram_size; | |
277 | cpu[0]->env.gr[25] = 0; /* no firmware boot menu */ | |
278 | cpu[0]->env.gr[24] = 'c'; | |
279 | /* gr22/gr23 unused, no initrd while reboot. */ | |
280 | cpu[0]->env.gr[21] = smp_cpus; | |
281 | } | |
282 | ||
283 | ||
813dff13 HD |
284 | static void machine_hppa_machine_init(MachineClass *mc) |
285 | { | |
286 | mc->desc = "HPPA generic machine"; | |
a72bd606 | 287 | mc->default_cpu_type = TYPE_HPPA_CPU; |
813dff13 | 288 | mc->init = machine_hppa_init; |
a72bd606 | 289 | mc->reset = hppa_machine_reset; |
813dff13 | 290 | mc->block_default_type = IF_SCSI; |
a72bd606 HD |
291 | mc->max_cpus = HPPA_MAX_CPUS; |
292 | mc->default_cpus = 1; | |
ea0ac7f6 | 293 | mc->is_default = true; |
d23b6caa | 294 | mc->default_ram_size = 512 * MiB; |
813dff13 | 295 | mc->default_boot_order = "cd"; |
7c59c1e0 | 296 | mc->default_ram_id = "ram"; |
813dff13 HD |
297 | } |
298 | ||
299 | DEFINE_MACHINE("hppa", machine_hppa_machine_init) |