Kevin O'Connor | e7cc764 | 2009-10-04 10:05:16 -0400 | [diff] [blame] | 1 | // Paravirtualization support. |
| 2 | // |
Kevin O'Connor | b840ba9 | 2013-02-09 20:09:22 -0500 | [diff] [blame] | 3 | // Copyright (C) 2013 Kevin O'Connor <kevin@koconnor.net> |
Kevin O'Connor | e7cc764 | 2009-10-04 10:05:16 -0400 | [diff] [blame] | 4 | // Copyright (C) 2009 Red Hat Inc. |
| 5 | // |
| 6 | // Authors: |
| 7 | // Gleb Natapov <gnatapov@redhat.com> |
| 8 | // |
| 9 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
| 10 | |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 11 | #include "byteorder.h" // be32_to_cpu |
| 12 | #include "config.h" // CONFIG_QEMU |
Kevin O'Connor | 5d369d8 | 2013-09-02 20:48:46 -0400 | [diff] [blame] | 13 | #include "hw/pci.h" // create_pirtable |
Gerd Hoffmann | ebfece8 | 2013-09-03 11:41:01 +0200 | [diff] [blame] | 14 | #include "hw/pci_regs.h" // PCI_DEVICE_ID |
Kevin O'Connor | 8b7861c | 2013-09-15 02:29:06 -0400 | [diff] [blame^] | 15 | #include "hw/rtc.h" // CMOS_* |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 16 | #include "ioport.h" // outw |
Kevin O'Connor | 9dea590 | 2013-09-14 20:23:54 -0400 | [diff] [blame] | 17 | #include "malloc.h" // malloc_tmp |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 18 | #include "memmap.h" // add_e820 |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 19 | #include "output.h" // dprintf |
| 20 | #include "paravirt.h" // qemu_cfg_preinit |
Kevin O'Connor | 41639f8 | 2013-09-14 19:37:36 -0400 | [diff] [blame] | 21 | #include "romfile.h" // romfile_loadint |
Kevin O'Connor | fa9c66a | 2013-09-14 19:10:40 -0400 | [diff] [blame] | 22 | #include "string.h" // memset |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 23 | #include "util.h" // pci_setup |
Kevin O'Connor | b9c6a96 | 2013-09-14 13:01:30 -0400 | [diff] [blame] | 24 | #include "x86.h" // cpuid |
Kevin O'Connor | 2d2fa31 | 2013-09-14 21:55:26 -0400 | [diff] [blame] | 25 | #include "xen.h" // xen_biostable_setup |
Kevin O'Connor | e7cc764 | 2009-10-04 10:05:16 -0400 | [diff] [blame] | 26 | |
Kevin O'Connor | f85e4bc | 2013-02-19 01:33:45 -0500 | [diff] [blame] | 27 | // Amount of continuous ram under 4Gig |
| 28 | u32 RamSize; |
| 29 | // Amount of continuous ram >4Gig |
| 30 | u64 RamSizeOver4G; |
Kevin O'Connor | 89a2f96 | 2013-02-18 23:36:03 -0500 | [diff] [blame] | 31 | // Type of emulator platform. |
| 32 | int PlatformRunningOn VARFSEG; |
| 33 | |
Kevin O'Connor | 7b5bc50 | 2013-02-09 13:07:23 -0500 | [diff] [blame] | 34 | /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It |
| 35 | * should be used to determine that a VM is running under KVM. |
| 36 | */ |
| 37 | #define KVM_CPUID_SIGNATURE 0x40000000 |
| 38 | |
Gerd Hoffmann | ebfece8 | 2013-09-03 11:41:01 +0200 | [diff] [blame] | 39 | static void kvm_detect(void) |
Kevin O'Connor | 7b5bc50 | 2013-02-09 13:07:23 -0500 | [diff] [blame] | 40 | { |
Kevin O'Connor | 7b5bc50 | 2013-02-09 13:07:23 -0500 | [diff] [blame] | 41 | unsigned int eax, ebx, ecx, edx; |
| 42 | char signature[13]; |
| 43 | |
| 44 | cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx); |
| 45 | memcpy(signature + 0, &ebx, 4); |
| 46 | memcpy(signature + 4, &ecx, 4); |
| 47 | memcpy(signature + 8, &edx, 4); |
| 48 | signature[12] = 0; |
| 49 | |
| 50 | if (strcmp(signature, "KVMKVMKVM") == 0) { |
| 51 | dprintf(1, "Running on KVM\n"); |
| 52 | PlatformRunningOn |= PF_KVM; |
| 53 | } |
| 54 | } |
| 55 | |
Gerd Hoffmann | ebfece8 | 2013-09-03 11:41:01 +0200 | [diff] [blame] | 56 | static void qemu_detect(void) |
| 57 | { |
| 58 | if (!CONFIG_QEMU_HARDWARE) |
| 59 | return; |
| 60 | |
| 61 | // check northbridge @ 00:00.0 |
| 62 | u16 v = pci_config_readw(0, PCI_VENDOR_ID); |
| 63 | if (v == 0x0000 || v == 0xffff) |
| 64 | return; |
| 65 | u16 d = pci_config_readw(0, PCI_DEVICE_ID); |
| 66 | u16 sv = pci_config_readw(0, PCI_SUBSYSTEM_VENDOR_ID); |
| 67 | u16 sd = pci_config_readw(0, PCI_SUBSYSTEM_ID); |
| 68 | |
| 69 | if (sv != 0x1af4 || /* Red Hat, Inc */ |
| 70 | sd != 0x1100) /* Qemu virtual machine */ |
| 71 | return; |
| 72 | |
| 73 | PlatformRunningOn |= PF_QEMU; |
| 74 | switch (d) { |
| 75 | case 0x1237: |
| 76 | dprintf(1, "Running on QEMU (i440fx)\n"); |
| 77 | break; |
| 78 | case 0x29c0: |
| 79 | dprintf(1, "Running on QEMU (q35)\n"); |
| 80 | break; |
| 81 | default: |
| 82 | dprintf(1, "Running on QEMU (unknown nb: %04x:%04x)\n", v, d); |
| 83 | break; |
| 84 | } |
| 85 | kvm_detect(); |
| 86 | } |
| 87 | |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 88 | void |
Kevin O'Connor | a2a86e2 | 2013-02-13 19:35:12 -0500 | [diff] [blame] | 89 | qemu_preinit(void) |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 90 | { |
Gerd Hoffmann | ebfece8 | 2013-09-03 11:41:01 +0200 | [diff] [blame] | 91 | qemu_detect(); |
| 92 | |
Kevin O'Connor | 02313b2 | 2013-02-07 22:42:25 -0500 | [diff] [blame] | 93 | if (!CONFIG_QEMU) |
| 94 | return; |
| 95 | |
Kevin O'Connor | a2a86e2 | 2013-02-13 19:35:12 -0500 | [diff] [blame] | 96 | if (runningOnXen()) { |
| 97 | xen_ramsize_preinit(); |
| 98 | return; |
| 99 | } |
| 100 | |
Gerd Hoffmann | ebfece8 | 2013-09-03 11:41:01 +0200 | [diff] [blame] | 101 | if (!runningOnQEMU()) { |
| 102 | dprintf(1, "Warning: No QEMU Northbridge found (isapc?)\n"); |
| 103 | PlatformRunningOn |= PF_QEMU; |
| 104 | kvm_detect(); |
| 105 | } |
Kevin O'Connor | 02313b2 | 2013-02-07 22:42:25 -0500 | [diff] [blame] | 106 | |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 107 | // On emulators, get memory size from nvram. |
Kevin O'Connor | 8b7861c | 2013-09-15 02:29:06 -0400 | [diff] [blame^] | 108 | u32 rs = ((rtc_read(CMOS_MEM_EXTMEM2_LOW) << 16) |
| 109 | | (rtc_read(CMOS_MEM_EXTMEM2_HIGH) << 24)); |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 110 | if (rs) |
| 111 | rs += 16 * 1024 * 1024; |
| 112 | else |
Kevin O'Connor | 8b7861c | 2013-09-15 02:29:06 -0400 | [diff] [blame^] | 113 | rs = (((rtc_read(CMOS_MEM_EXTMEM_LOW) << 10) |
| 114 | | (rtc_read(CMOS_MEM_EXTMEM_HIGH) << 18)) |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 115 | + 1 * 1024 * 1024); |
| 116 | RamSize = rs; |
| 117 | add_e820(0, rs, E820_RAM); |
| 118 | |
| 119 | // Check for memory over 4Gig |
Kevin O'Connor | 8b7861c | 2013-09-15 02:29:06 -0400 | [diff] [blame^] | 120 | u64 high = ((rtc_read(CMOS_MEM_HIGHMEM_LOW) << 16) |
| 121 | | ((u32)rtc_read(CMOS_MEM_HIGHMEM_MID) << 24) |
| 122 | | ((u64)rtc_read(CMOS_MEM_HIGHMEM_HIGH) << 32)); |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 123 | RamSizeOver4G = high; |
| 124 | add_e820(0x100000000ull, high, E820_RAM); |
| 125 | |
| 126 | /* reserve 256KB BIOS area at the end of 4 GB */ |
| 127 | add_e820(0xfffc0000, 256*1024, E820_RESERVED); |
Kevin O'Connor | f85e4bc | 2013-02-19 01:33:45 -0500 | [diff] [blame] | 128 | |
| 129 | dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G); |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void |
Kevin O'Connor | a2a86e2 | 2013-02-13 19:35:12 -0500 | [diff] [blame] | 133 | qemu_platform_setup(void) |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 134 | { |
Kevin O'Connor | a2a86e2 | 2013-02-13 19:35:12 -0500 | [diff] [blame] | 135 | if (!CONFIG_QEMU) |
| 136 | return; |
| 137 | |
| 138 | if (runningOnXen()) { |
| 139 | pci_probe_devices(); |
| 140 | xen_hypercall_setup(); |
| 141 | xen_biostable_setup(); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | // Initialize pci |
| 146 | pci_setup(); |
Kevin O'Connor | cdbac7f | 2013-03-08 19:33:39 -0500 | [diff] [blame] | 147 | smm_device_setup(); |
Kevin O'Connor | a2a86e2 | 2013-02-13 19:35:12 -0500 | [diff] [blame] | 148 | smm_setup(); |
| 149 | |
| 150 | // Initialize mtrr and smp |
| 151 | mtrr_setup(); |
| 152 | smp_setup(); |
| 153 | |
| 154 | // Create bios tables |
Kevin O'Connor | 8ed2e53 | 2013-01-21 02:32:48 -0500 | [diff] [blame] | 155 | pirtable_setup(); |
| 156 | mptable_setup(); |
| 157 | smbios_setup(); |
| 158 | acpi_setup(); |
| 159 | } |
| 160 | |
Kevin O'Connor | 4edda08 | 2013-02-09 13:21:08 -0500 | [diff] [blame] | 161 | |
| 162 | /**************************************************************** |
| 163 | * QEMU firmware config (fw_cfg) interface |
| 164 | ****************************************************************/ |
| 165 | |
Kevin O'Connor | b840ba9 | 2013-02-09 20:09:22 -0500 | [diff] [blame] | 166 | // List of QEMU fw_cfg entries. DO NOT ADD MORE. (All new content |
| 167 | // should be passed via the fw_cfg "file" interface.) |
Kevin O'Connor | 4edda08 | 2013-02-09 13:21:08 -0500 | [diff] [blame] | 168 | #define QEMU_CFG_SIGNATURE 0x00 |
| 169 | #define QEMU_CFG_ID 0x01 |
| 170 | #define QEMU_CFG_UUID 0x02 |
| 171 | #define QEMU_CFG_NUMA 0x0d |
| 172 | #define QEMU_CFG_BOOT_MENU 0x0e |
| 173 | #define QEMU_CFG_MAX_CPUS 0x0f |
| 174 | #define QEMU_CFG_FILE_DIR 0x19 |
| 175 | #define QEMU_CFG_ARCH_LOCAL 0x8000 |
| 176 | #define QEMU_CFG_ACPI_TABLES (QEMU_CFG_ARCH_LOCAL + 0) |
| 177 | #define QEMU_CFG_SMBIOS_ENTRIES (QEMU_CFG_ARCH_LOCAL + 1) |
| 178 | #define QEMU_CFG_IRQ0_OVERRIDE (QEMU_CFG_ARCH_LOCAL + 2) |
| 179 | #define QEMU_CFG_E820_TABLE (QEMU_CFG_ARCH_LOCAL + 3) |
| 180 | |
Kevin O'Connor | e7cc764 | 2009-10-04 10:05:16 -0400 | [diff] [blame] | 181 | static void |
| 182 | qemu_cfg_select(u16 f) |
| 183 | { |
| 184 | outw(f, PORT_QEMU_CFG_CTL); |
| 185 | } |
| 186 | |
| 187 | static void |
Kevin O'Connor | c40e3fa | 2013-02-09 14:55:30 -0500 | [diff] [blame] | 188 | qemu_cfg_read(void *buf, int len) |
Kevin O'Connor | e7cc764 | 2009-10-04 10:05:16 -0400 | [diff] [blame] | 189 | { |
Kevin O'Connor | 6039fc5 | 2010-08-25 21:43:19 -0400 | [diff] [blame] | 190 | insb(PORT_QEMU_CFG_DATA, buf, len); |
Kevin O'Connor | e7cc764 | 2009-10-04 10:05:16 -0400 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static void |
Kevin O'Connor | 4e4b410 | 2009-10-08 21:21:59 -0400 | [diff] [blame] | 194 | qemu_cfg_skip(int len) |
| 195 | { |
| 196 | while (len--) |
| 197 | inb(PORT_QEMU_CFG_DATA); |
| 198 | } |
| 199 | |
| 200 | static void |
Kevin O'Connor | e7cc764 | 2009-10-04 10:05:16 -0400 | [diff] [blame] | 201 | qemu_cfg_read_entry(void *buf, int e, int len) |
| 202 | { |
| 203 | qemu_cfg_select(e); |
| 204 | qemu_cfg_read(buf, len); |
| 205 | } |
| 206 | |
Kevin O'Connor | 4158c8c | 2013-03-30 09:12:11 -0400 | [diff] [blame] | 207 | struct qemu_romfile_s { |
| 208 | struct romfile_s file; |
| 209 | int select, skip; |
| 210 | }; |
| 211 | |
Kevin O'Connor | c40e3fa | 2013-02-09 14:55:30 -0500 | [diff] [blame] | 212 | static int |
| 213 | qemu_cfg_read_file(struct romfile_s *file, void *dst, u32 maxlen) |
Gerd Hoffmann | c4c9fae | 2009-12-18 12:16:04 +0100 | [diff] [blame] | 214 | { |
Kevin O'Connor | 59d6ca5 | 2012-05-31 00:20:55 -0400 | [diff] [blame] | 215 | if (file->size > maxlen) |
| 216 | return -1; |
Kevin O'Connor | 4158c8c | 2013-03-30 09:12:11 -0400 | [diff] [blame] | 217 | struct qemu_romfile_s *qfile; |
| 218 | qfile = container_of(file, struct qemu_romfile_s, file); |
| 219 | qemu_cfg_select(qfile->select); |
| 220 | qemu_cfg_skip(qfile->skip); |
Kevin O'Connor | c40e3fa | 2013-02-09 14:55:30 -0500 | [diff] [blame] | 221 | qemu_cfg_read(dst, file->size); |
Kevin O'Connor | 59d6ca5 | 2012-05-31 00:20:55 -0400 | [diff] [blame] | 222 | return file->size; |
| 223 | } |
| 224 | |
Kevin O'Connor | c40e3fa | 2013-02-09 14:55:30 -0500 | [diff] [blame] | 225 | static void |
| 226 | qemu_romfile_add(char *name, int select, int skip, int size) |
| 227 | { |
Kevin O'Connor | 4158c8c | 2013-03-30 09:12:11 -0400 | [diff] [blame] | 228 | struct qemu_romfile_s *qfile = malloc_tmp(sizeof(*qfile)); |
| 229 | if (!qfile) { |
Kevin O'Connor | c40e3fa | 2013-02-09 14:55:30 -0500 | [diff] [blame] | 230 | warn_noalloc(); |
| 231 | return; |
| 232 | } |
Kevin O'Connor | 4158c8c | 2013-03-30 09:12:11 -0400 | [diff] [blame] | 233 | memset(qfile, 0, sizeof(*qfile)); |
| 234 | strtcpy(qfile->file.name, name, sizeof(qfile->file.name)); |
| 235 | qfile->file.size = size; |
| 236 | qfile->select = select; |
| 237 | qfile->skip = skip; |
| 238 | qfile->file.copy = qemu_cfg_read_file; |
| 239 | romfile_add(&qfile->file); |
Kevin O'Connor | c40e3fa | 2013-02-09 14:55:30 -0500 | [diff] [blame] | 240 | } |
| 241 | |
Kevin O'Connor | fe09030 | 2013-02-09 20:00:06 -0500 | [diff] [blame] | 242 | struct e820_reservation { |
| 243 | u64 address; |
| 244 | u64 length; |
| 245 | u32 type; |
| 246 | }; |
| 247 | |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 248 | #define SMBIOS_FIELD_ENTRY 0 |
| 249 | #define SMBIOS_TABLE_ENTRY 1 |
| 250 | |
| 251 | struct qemu_smbios_header { |
| 252 | u16 length; |
| 253 | u8 headertype; |
| 254 | u8 tabletype; |
| 255 | u16 fieldoffset; |
| 256 | } PACKED; |
| 257 | |
Kevin O'Connor | 188d994 | 2013-02-09 15:24:08 -0500 | [diff] [blame] | 258 | // Populate romfile entries for legacy fw_cfg ports (that predate the |
| 259 | // "file" interface). |
| 260 | static void |
| 261 | qemu_cfg_legacy(void) |
| 262 | { |
Kevin O'Connor | 7507ce2 | 2013-06-13 20:04:31 -0400 | [diff] [blame] | 263 | if (!CONFIG_QEMU) |
| 264 | return; |
| 265 | |
Kevin O'Connor | 56c5089 | 2013-02-09 19:25:51 -0500 | [diff] [blame] | 266 | // Misc config items. |
| 267 | qemu_romfile_add("etc/show-boot-menu", QEMU_CFG_BOOT_MENU, 0, 2); |
| 268 | qemu_romfile_add("etc/irq0-override", QEMU_CFG_IRQ0_OVERRIDE, 0, 1); |
| 269 | qemu_romfile_add("etc/max-cpus", QEMU_CFG_MAX_CPUS, 0, 2); |
| 270 | |
Kevin O'Connor | f9e4e37 | 2013-02-09 19:45:45 -0500 | [diff] [blame] | 271 | // NUMA data |
| 272 | u64 numacount; |
| 273 | qemu_cfg_read_entry(&numacount, QEMU_CFG_NUMA, sizeof(numacount)); |
Kevin O'Connor | fb76cff | 2013-03-23 11:38:45 -0400 | [diff] [blame] | 274 | int max_cpu = romfile_loadint("etc/max-cpus", 0); |
| 275 | qemu_romfile_add("etc/numa-cpu-map", QEMU_CFG_NUMA, sizeof(numacount) |
| 276 | , max_cpu*sizeof(u64)); |
| 277 | qemu_romfile_add("etc/numa-nodes", QEMU_CFG_NUMA |
| 278 | , sizeof(numacount) + max_cpu*sizeof(u64) |
Kevin O'Connor | f9e4e37 | 2013-02-09 19:45:45 -0500 | [diff] [blame] | 279 | , numacount*sizeof(u64)); |
| 280 | |
Kevin O'Connor | fe09030 | 2013-02-09 20:00:06 -0500 | [diff] [blame] | 281 | // e820 data |
| 282 | u32 count32; |
| 283 | qemu_cfg_read_entry(&count32, QEMU_CFG_E820_TABLE, sizeof(count32)); |
| 284 | if (count32) { |
| 285 | struct e820_reservation entry; |
| 286 | int i; |
| 287 | for (i = 0; i < count32; i++) { |
| 288 | qemu_cfg_read(&entry, sizeof(entry)); |
| 289 | add_e820(entry.address, entry.length, entry.type); |
| 290 | } |
| 291 | } else if (runningOnKVM()) { |
| 292 | // Backwards compatibility - provide hard coded range. |
| 293 | // 4 pages before the bios, 3 pages for vmx tss pages, the |
| 294 | // other page for EPT real mode pagetable |
| 295 | add_e820(0xfffbc000, 4*4096, E820_RESERVED); |
| 296 | } |
| 297 | |
Kevin O'Connor | 188d994 | 2013-02-09 15:24:08 -0500 | [diff] [blame] | 298 | // ACPI tables |
| 299 | char name[128]; |
| 300 | u16 cnt; |
| 301 | qemu_cfg_read_entry(&cnt, QEMU_CFG_ACPI_TABLES, sizeof(cnt)); |
| 302 | int i, offset = sizeof(cnt); |
| 303 | for (i = 0; i < cnt; i++) { |
| 304 | u16 len; |
| 305 | qemu_cfg_read(&len, sizeof(len)); |
| 306 | offset += sizeof(len); |
| 307 | snprintf(name, sizeof(name), "acpi/table%d", i); |
| 308 | qemu_romfile_add(name, QEMU_CFG_ACPI_TABLES, offset, len); |
| 309 | qemu_cfg_skip(len); |
| 310 | offset += len; |
| 311 | } |
Kevin O'Connor | de9e705 | 2013-02-09 19:09:20 -0500 | [diff] [blame] | 312 | |
| 313 | // SMBIOS info |
| 314 | qemu_cfg_read_entry(&cnt, QEMU_CFG_SMBIOS_ENTRIES, sizeof(cnt)); |
| 315 | offset = sizeof(cnt); |
| 316 | for (i = 0; i < cnt; i++) { |
| 317 | struct qemu_smbios_header header; |
| 318 | qemu_cfg_read(&header, sizeof(header)); |
| 319 | if (header.headertype == SMBIOS_FIELD_ENTRY) { |
| 320 | snprintf(name, sizeof(name), "smbios/field%d-%d" |
| 321 | , header.tabletype, header.fieldoffset); |
| 322 | qemu_romfile_add(name, QEMU_CFG_SMBIOS_ENTRIES |
| 323 | , offset + sizeof(header) |
| 324 | , header.length - sizeof(header)); |
| 325 | } else { |
| 326 | snprintf(name, sizeof(name), "smbios/table%d-%d" |
| 327 | , header.tabletype, i); |
| 328 | qemu_romfile_add(name, QEMU_CFG_SMBIOS_ENTRIES |
| 329 | , offset + 3, header.length - 3); |
| 330 | } |
| 331 | qemu_cfg_skip(header.length - sizeof(header)); |
| 332 | offset += header.length; |
| 333 | } |
Kevin O'Connor | 188d994 | 2013-02-09 15:24:08 -0500 | [diff] [blame] | 334 | } |
| 335 | |
Kevin O'Connor | 59d6ca5 | 2012-05-31 00:20:55 -0400 | [diff] [blame] | 336 | struct QemuCfgFile { |
| 337 | u32 size; /* file size */ |
| 338 | u16 select; /* write this to 0x510 to read it */ |
| 339 | u16 reserved; |
| 340 | char name[56]; |
| 341 | }; |
| 342 | |
Kevin O'Connor | b840ba9 | 2013-02-09 20:09:22 -0500 | [diff] [blame] | 343 | void qemu_cfg_init(void) |
Kevin O'Connor | 59d6ca5 | 2012-05-31 00:20:55 -0400 | [diff] [blame] | 344 | { |
Kevin O'Connor | 7507ce2 | 2013-06-13 20:04:31 -0400 | [diff] [blame] | 345 | if (!runningOnQEMU()) |
Kevin O'Connor | 59d6ca5 | 2012-05-31 00:20:55 -0400 | [diff] [blame] | 346 | return; |
Gerd Hoffmann | c4c9fae | 2009-12-18 12:16:04 +0100 | [diff] [blame] | 347 | |
Kevin O'Connor | b840ba9 | 2013-02-09 20:09:22 -0500 | [diff] [blame] | 348 | // Detect fw_cfg interface. |
| 349 | qemu_cfg_select(QEMU_CFG_SIGNATURE); |
| 350 | char *sig = "QEMU"; |
| 351 | int i; |
| 352 | for (i = 0; i < 4; i++) |
| 353 | if (inb(PORT_QEMU_CFG_DATA) != sig[i]) |
| 354 | return; |
| 355 | dprintf(1, "Found QEMU fw_cfg\n"); |
| 356 | |
Kevin O'Connor | 188d994 | 2013-02-09 15:24:08 -0500 | [diff] [blame] | 357 | // Populate romfiles for legacy fw_cfg entries |
| 358 | qemu_cfg_legacy(); |
| 359 | |
| 360 | // Load files found in the fw_cfg file directory |
Kevin O'Connor | e230426 | 2010-06-13 16:05:17 -0400 | [diff] [blame] | 361 | u32 count; |
Gerd Hoffmann | c4c9fae | 2009-12-18 12:16:04 +0100 | [diff] [blame] | 362 | qemu_cfg_read_entry(&count, QEMU_CFG_FILE_DIR, sizeof(count)); |
Kevin O'Connor | b306459 | 2012-08-14 21:20:10 -0400 | [diff] [blame] | 363 | count = be32_to_cpu(count); |
Kevin O'Connor | e230426 | 2010-06-13 16:05:17 -0400 | [diff] [blame] | 364 | u32 e; |
| 365 | for (e = 0; e < count; e++) { |
Kevin O'Connor | 59d6ca5 | 2012-05-31 00:20:55 -0400 | [diff] [blame] | 366 | struct QemuCfgFile qfile; |
Kevin O'Connor | c40e3fa | 2013-02-09 14:55:30 -0500 | [diff] [blame] | 367 | qemu_cfg_read(&qfile, sizeof(qfile)); |
| 368 | qemu_romfile_add(qfile.name, be16_to_cpu(qfile.select) |
| 369 | , 0, be32_to_cpu(qfile.size)); |
Gerd Hoffmann | c4c9fae | 2009-12-18 12:16:04 +0100 | [diff] [blame] | 370 | } |
Kevin O'Connor | 8b56578 | 2011-07-05 20:32:44 -0400 | [diff] [blame] | 371 | } |