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