diff options
| -rw-r--r-- | arch/x86/Kconfig | 14 | ||||
| -rw-r--r-- | arch/x86/boot/Makefile | 2 | ||||
| -rw-r--r-- | arch/x86/boot/compressed/eboot.c | 1018 | ||||
| -rw-r--r-- | arch/x86/boot/compressed/eboot.h | 60 | ||||
| -rw-r--r-- | arch/x86/boot/compressed/efi_stub_64.S | 29 | ||||
| -rw-r--r-- | arch/x86/boot/compressed/head_32.S | 50 | ||||
| -rw-r--r-- | arch/x86/boot/compressed/head_64.S | 108 | ||||
| -rw-r--r-- | arch/x86/boot/header.S | 23 | ||||
| -rw-r--r-- | arch/x86/boot/tools/build.c | 76 | ||||
| -rw-r--r-- | arch/x86/include/asm/efi.h | 38 | ||||
| -rw-r--r-- | arch/x86/include/asm/pgtable_types.h | 2 | ||||
| -rw-r--r-- | arch/x86/mm/fault.c | 7 | ||||
| -rw-r--r-- | arch/x86/mm/pageattr.c | 12 | ||||
| -rw-r--r-- | arch/x86/platform/efi/Makefile | 1 | ||||
| -rw-r--r-- | arch/x86/platform/efi/efi.c | 158 | ||||
| -rw-r--r-- | arch/x86/platform/efi/efi_64.c | 327 | ||||
| -rw-r--r-- | arch/x86/platform/efi/efi_stub_64.S | 157 | ||||
| -rw-r--r-- | arch/x86/platform/efi/efi_thunk_64.S | 65 | ||||
| -rw-r--r-- | drivers/firmware/efi/efi-stub-helper.c | 148 | ||||
| -rw-r--r-- | include/linux/efi.h | 252 |
20 files changed, 2113 insertions, 434 deletions
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 0af5250d914f..8453fe1342ea 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig | |||
| @@ -1585,6 +1585,20 @@ config EFI_STUB | |||
| 1585 | 1585 | ||
| 1586 | See Documentation/efi-stub.txt for more information. | 1586 | See Documentation/efi-stub.txt for more information. |
| 1587 | 1587 | ||
| 1588 | config EFI_MIXED | ||
| 1589 | bool "EFI mixed-mode support" | ||
| 1590 | depends on EFI_STUB && X86_64 | ||
| 1591 | ---help--- | ||
| 1592 | Enabling this feature allows a 64-bit kernel to be booted | ||
| 1593 | on a 32-bit firmware, provided that your CPU supports 64-bit | ||
| 1594 | mode. | ||
| 1595 | |||
| 1596 | Note that it is not possible to boot a mixed-mode enabled | ||
| 1597 | kernel via the EFI boot stub - a bootloader that supports | ||
| 1598 | the EFI handover protocol must be used. | ||
| 1599 | |||
| 1600 | If unsure, say N. | ||
| 1601 | |||
| 1588 | config SECCOMP | 1602 | config SECCOMP |
| 1589 | def_bool y | 1603 | def_bool y |
| 1590 | prompt "Enable seccomp to safely compute untrusted bytecode" | 1604 | prompt "Enable seccomp to safely compute untrusted bytecode" |
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile index 878df7e88cd4..abb9eba61b50 100644 --- a/arch/x86/boot/Makefile +++ b/arch/x86/boot/Makefile | |||
| @@ -80,7 +80,7 @@ targets += voffset.h | |||
| 80 | $(obj)/voffset.h: vmlinux FORCE | 80 | $(obj)/voffset.h: vmlinux FORCE |
| 81 | $(call if_changed,voffset) | 81 | $(call if_changed,voffset) |
| 82 | 82 | ||
| 83 | sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|startup_64\|efi_pe_entry\|efi_stub_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p' | 83 | sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p' |
| 84 | 84 | ||
| 85 | quiet_cmd_zoffset = ZOFFSET $@ | 85 | quiet_cmd_zoffset = ZOFFSET $@ |
| 86 | cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@ | 86 | cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@ |
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index a7677babf946..5e1ba4fa3f79 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c | |||
| @@ -19,10 +19,269 @@ | |||
| 19 | 19 | ||
| 20 | static efi_system_table_t *sys_table; | 20 | static efi_system_table_t *sys_table; |
| 21 | 21 | ||
| 22 | static struct efi_config *efi_early; | ||
| 23 | |||
| 24 | #define BOOT_SERVICES(bits) \ | ||
| 25 | static void setup_boot_services##bits(struct efi_config *c) \ | ||
| 26 | { \ | ||
| 27 | efi_system_table_##bits##_t *table; \ | ||
| 28 | efi_boot_services_##bits##_t *bt; \ | ||
| 29 | \ | ||
| 30 | table = (typeof(table))sys_table; \ | ||
| 31 | \ | ||
| 32 | c->text_output = table->con_out; \ | ||
| 33 | \ | ||
| 34 | bt = (typeof(bt))(unsigned long)(table->boottime); \ | ||
| 35 | \ | ||
| 36 | c->allocate_pool = bt->allocate_pool; \ | ||
| 37 | c->allocate_pages = bt->allocate_pages; \ | ||
| 38 | c->get_memory_map = bt->get_memory_map; \ | ||
| 39 | c->free_pool = bt->free_pool; \ | ||
| 40 | c->free_pages = bt->free_pages; \ | ||
| 41 | c->locate_handle = bt->locate_handle; \ | ||
| 42 | c->handle_protocol = bt->handle_protocol; \ | ||
| 43 | c->exit_boot_services = bt->exit_boot_services; \ | ||
| 44 | } | ||
| 45 | BOOT_SERVICES(32); | ||
| 46 | BOOT_SERVICES(64); | ||
| 22 | 47 | ||
| 23 | #include "../../../../drivers/firmware/efi/efi-stub-helper.c" | 48 | static void efi_printk(efi_system_table_t *, char *); |
| 49 | static void efi_char16_printk(efi_system_table_t *, efi_char16_t *); | ||
| 50 | |||
| 51 | static efi_status_t | ||
| 52 | __file_size32(void *__fh, efi_char16_t *filename_16, | ||
| 53 | void **handle, u64 *file_sz) | ||
| 54 | { | ||
| 55 | efi_file_handle_32_t *h, *fh = __fh; | ||
| 56 | efi_file_info_t *info; | ||
| 57 | efi_status_t status; | ||
| 58 | efi_guid_t info_guid = EFI_FILE_INFO_ID; | ||
| 59 | u32 info_sz; | ||
| 60 | |||
| 61 | status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16, | ||
| 62 | EFI_FILE_MODE_READ, (u64)0); | ||
| 63 | if (status != EFI_SUCCESS) { | ||
| 64 | efi_printk(sys_table, "Failed to open file: "); | ||
| 65 | efi_char16_printk(sys_table, filename_16); | ||
| 66 | efi_printk(sys_table, "\n"); | ||
| 67 | return status; | ||
| 68 | } | ||
| 69 | |||
| 70 | *handle = h; | ||
| 71 | |||
| 72 | info_sz = 0; | ||
| 73 | status = efi_early->call((unsigned long)h->get_info, h, &info_guid, | ||
| 74 | &info_sz, NULL); | ||
| 75 | if (status != EFI_BUFFER_TOO_SMALL) { | ||
| 76 | efi_printk(sys_table, "Failed to get file info size\n"); | ||
| 77 | return status; | ||
| 78 | } | ||
| 79 | |||
| 80 | grow: | ||
| 81 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, | ||
| 82 | info_sz, (void **)&info); | ||
| 83 | if (status != EFI_SUCCESS) { | ||
| 84 | efi_printk(sys_table, "Failed to alloc mem for file info\n"); | ||
| 85 | return status; | ||
| 86 | } | ||
| 87 | |||
| 88 | status = efi_early->call((unsigned long)h->get_info, h, &info_guid, | ||
| 89 | &info_sz, info); | ||
| 90 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
| 91 | efi_early->call(efi_early->free_pool, info); | ||
| 92 | goto grow; | ||
| 93 | } | ||
| 94 | |||
| 95 | *file_sz = info->file_size; | ||
| 96 | efi_early->call(efi_early->free_pool, info); | ||
| 97 | |||
| 98 | if (status != EFI_SUCCESS) | ||
| 99 | efi_printk(sys_table, "Failed to get initrd info\n"); | ||
| 100 | |||
| 101 | return status; | ||
| 102 | } | ||
| 103 | |||
| 104 | static efi_status_t | ||
| 105 | __file_size64(void *__fh, efi_char16_t *filename_16, | ||
| 106 | void **handle, u64 *file_sz) | ||
| 107 | { | ||
| 108 | efi_file_handle_64_t *h, *fh = __fh; | ||
| 109 | efi_file_info_t *info; | ||
| 110 | efi_status_t status; | ||
| 111 | efi_guid_t info_guid = EFI_FILE_INFO_ID; | ||
| 112 | u32 info_sz; | ||
| 113 | |||
| 114 | status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16, | ||
| 115 | EFI_FILE_MODE_READ, (u64)0); | ||
| 116 | if (status != EFI_SUCCESS) { | ||
| 117 | efi_printk(sys_table, "Failed to open file: "); | ||
| 118 | efi_char16_printk(sys_table, filename_16); | ||
| 119 | efi_printk(sys_table, "\n"); | ||
| 120 | return status; | ||
| 121 | } | ||
| 122 | |||
| 123 | *handle = h; | ||
| 124 | |||
| 125 | info_sz = 0; | ||
| 126 | status = efi_early->call((unsigned long)h->get_info, h, &info_guid, | ||
| 127 | &info_sz, NULL); | ||
| 128 | if (status != EFI_BUFFER_TOO_SMALL) { | ||
| 129 | efi_printk(sys_table, "Failed to get file info size\n"); | ||
| 130 | return status; | ||
| 131 | } | ||
| 132 | |||
| 133 | grow: | ||
| 134 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, | ||
| 135 | info_sz, (void **)&info); | ||
| 136 | if (status != EFI_SUCCESS) { | ||
| 137 | efi_printk(sys_table, "Failed to alloc mem for file info\n"); | ||
| 138 | return status; | ||
| 139 | } | ||
| 140 | |||
| 141 | status = efi_early->call((unsigned long)h->get_info, h, &info_guid, | ||
| 142 | &info_sz, info); | ||
| 143 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
| 144 | efi_early->call(efi_early->free_pool, info); | ||
| 145 | goto grow; | ||
| 146 | } | ||
| 147 | |||
| 148 | *file_sz = info->file_size; | ||
| 149 | efi_early->call(efi_early->free_pool, info); | ||
| 150 | |||
| 151 | if (status != EFI_SUCCESS) | ||
| 152 | efi_printk(sys_table, "Failed to get initrd info\n"); | ||
| 153 | |||
| 154 | return status; | ||
| 155 | } | ||
| 156 | static efi_status_t | ||
| 157 | efi_file_size(efi_system_table_t *sys_table, void *__fh, | ||
| 158 | efi_char16_t *filename_16, void **handle, u64 *file_sz) | ||
| 159 | { | ||
| 160 | if (efi_early->is64) | ||
| 161 | return __file_size64(__fh, filename_16, handle, file_sz); | ||
| 162 | |||
| 163 | return __file_size32(__fh, filename_16, handle, file_sz); | ||
| 164 | } | ||
| 165 | |||
| 166 | static inline efi_status_t | ||
| 167 | efi_file_read(void *__fh, void *handle, unsigned long *size, void *addr) | ||
| 168 | { | ||
| 169 | unsigned long func; | ||
| 170 | |||
| 171 | if (efi_early->is64) { | ||
| 172 | efi_file_handle_64_t *fh = __fh; | ||
| 173 | |||
| 174 | func = (unsigned long)fh->read; | ||
| 175 | return efi_early->call(func, handle, size, addr); | ||
| 176 | } else { | ||
| 177 | efi_file_handle_32_t *fh = __fh; | ||
| 178 | |||
| 179 | func = (unsigned long)fh->read; | ||
| 180 | return efi_early->call(func, handle, size, addr); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | static inline efi_status_t efi_file_close(void *__fh, void *handle) | ||
| 185 | { | ||
| 186 | if (efi_early->is64) { | ||
| 187 | efi_file_handle_64_t *fh = __fh; | ||
| 188 | |||
| 189 | return efi_early->call((unsigned long)fh->close, handle); | ||
| 190 | } else { | ||
| 191 | efi_file_handle_32_t *fh = __fh; | ||
| 192 | |||
| 193 | return efi_early->call((unsigned long)fh->close, handle); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | static inline efi_status_t __open_volume32(void *__image, void **__fh) | ||
| 198 | { | ||
| 199 | efi_file_io_interface_t *io; | ||
| 200 | efi_loaded_image_32_t *image = __image; | ||
| 201 | efi_file_handle_32_t *fh; | ||
| 202 | efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; | ||
| 203 | efi_status_t status; | ||
| 204 | void *handle = (void *)(unsigned long)image->device_handle; | ||
| 205 | unsigned long func; | ||
| 206 | |||
| 207 | status = efi_early->call(efi_early->handle_protocol, handle, | ||
| 208 | &fs_proto, (void **)&io); | ||
| 209 | if (status != EFI_SUCCESS) { | ||
| 210 | efi_printk(sys_table, "Failed to handle fs_proto\n"); | ||
| 211 | return status; | ||
| 212 | } | ||
| 213 | |||
| 214 | func = (unsigned long)io->open_volume; | ||
| 215 | status = efi_early->call(func, io, &fh); | ||
| 216 | if (status != EFI_SUCCESS) | ||
| 217 | efi_printk(sys_table, "Failed to open volume\n"); | ||
| 218 | |||
| 219 | *__fh = fh; | ||
| 220 | return status; | ||
| 221 | } | ||
| 222 | |||
| 223 | static inline efi_status_t __open_volume64(void *__image, void **__fh) | ||
| 224 | { | ||
| 225 | efi_file_io_interface_t *io; | ||
| 226 | efi_loaded_image_64_t *image = __image; | ||
| 227 | efi_file_handle_64_t *fh; | ||
| 228 | efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; | ||
| 229 | efi_status_t status; | ||
| 230 | void *handle = (void *)(unsigned long)image->device_handle; | ||
| 231 | unsigned long func; | ||
| 232 | |||
| 233 | status = efi_early->call(efi_early->handle_protocol, handle, | ||
| 234 | &fs_proto, (void **)&io); | ||
| 235 | if (status != EFI_SUCCESS) { | ||
| 236 | efi_printk(sys_table, "Failed to handle fs_proto\n"); | ||
| 237 | return status; | ||
| 238 | } | ||
| 239 | |||
| 240 | func = (unsigned long)io->open_volume; | ||
| 241 | status = efi_early->call(func, io, &fh); | ||
| 242 | if (status != EFI_SUCCESS) | ||
| 243 | efi_printk(sys_table, "Failed to open volume\n"); | ||
| 244 | |||
| 245 | *__fh = fh; | ||
| 246 | return status; | ||
| 247 | } | ||
| 248 | |||
| 249 | static inline efi_status_t | ||
| 250 | efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh) | ||
| 251 | { | ||
| 252 | if (efi_early->is64) | ||
| 253 | return __open_volume64(__image, __fh); | ||
| 254 | |||
| 255 | return __open_volume32(__image, __fh); | ||
| 256 | } | ||
| 257 | |||
| 258 | static void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) | ||
| 259 | { | ||
| 260 | unsigned long output_string; | ||
| 261 | size_t offset; | ||
| 262 | |||
| 263 | if (efi_early->is64) { | ||
| 264 | struct efi_simple_text_output_protocol_64 *out; | ||
| 265 | u64 *func; | ||
| 266 | |||
| 267 | offset = offsetof(typeof(*out), output_string); | ||
| 268 | output_string = efi_early->text_output + offset; | ||
| 269 | func = (u64 *)output_string; | ||
| 270 | |||
| 271 | efi_early->call(*func, efi_early->text_output, str); | ||
| 272 | } else { | ||
| 273 | struct efi_simple_text_output_protocol_32 *out; | ||
| 274 | u32 *func; | ||
| 275 | |||
| 276 | offset = offsetof(typeof(*out), output_string); | ||
| 277 | output_string = efi_early->text_output + offset; | ||
| 278 | func = (u32 *)output_string; | ||
| 24 | 279 | ||
| 280 | efi_early->call(*func, efi_early->text_output, str); | ||
| 281 | } | ||
| 282 | } | ||
| 25 | 283 | ||
| 284 | #include "../../../../drivers/firmware/efi/efi-stub-helper.c" | ||
| 26 | 285 | ||
| 27 | static void find_bits(unsigned long mask, u8 *pos, u8 *size) | 286 | static void find_bits(unsigned long mask, u8 *pos, u8 *size) |
| 28 | { | 287 | { |
| @@ -47,105 +306,99 @@ static void find_bits(unsigned long mask, u8 *pos, u8 *size) | |||
| 47 | *size = len; | 306 | *size = len; |
| 48 | } | 307 | } |
| 49 | 308 | ||
| 50 | static efi_status_t setup_efi_pci(struct boot_params *params) | 309 | static efi_status_t |
| 310 | __setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom) | ||
| 51 | { | 311 | { |
| 52 | efi_pci_io_protocol *pci; | 312 | struct pci_setup_rom *rom = NULL; |
| 53 | efi_status_t status; | 313 | efi_status_t status; |
| 54 | void **pci_handle; | 314 | unsigned long size; |
| 55 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; | 315 | uint64_t attributes; |
| 56 | unsigned long nr_pci, size = 0; | ||
| 57 | int i; | ||
| 58 | struct setup_data *data; | ||
| 59 | 316 | ||
| 60 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; | 317 | status = efi_early->call(pci->attributes, pci, |
| 318 | EfiPciIoAttributeOperationGet, 0, 0, | ||
| 319 | &attributes); | ||
| 320 | if (status != EFI_SUCCESS) | ||
| 321 | return status; | ||
| 61 | 322 | ||
| 62 | while (data && data->next) | 323 | if (!pci->romimage || !pci->romsize) |
| 63 | data = (struct setup_data *)(unsigned long)data->next; | 324 | return EFI_INVALID_PARAMETER; |
| 64 | 325 | ||
| 65 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 326 | size = pci->romsize + sizeof(*rom); |
| 66 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, | ||
| 67 | NULL, &size, pci_handle); | ||
| 68 | 327 | ||
| 69 | if (status == EFI_BUFFER_TOO_SMALL) { | 328 | status = efi_early->call(efi_early->allocate_pool, |
| 70 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 329 | EFI_LOADER_DATA, size, &rom); |
| 71 | EFI_LOADER_DATA, size, &pci_handle); | ||
| 72 | 330 | ||
| 73 | if (status != EFI_SUCCESS) | 331 | if (status != EFI_SUCCESS) |
| 74 | return status; | 332 | return status; |
| 75 | 333 | ||
| 76 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 334 | memset(rom, 0, sizeof(*rom)); |
| 77 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, | ||
| 78 | NULL, &size, pci_handle); | ||
| 79 | } | ||
| 80 | 335 | ||
| 81 | if (status != EFI_SUCCESS) | 336 | rom->data.type = SETUP_PCI; |
| 82 | goto free_handle; | 337 | rom->data.len = size - sizeof(struct setup_data); |
| 338 | rom->data.next = 0; | ||
| 339 | rom->pcilen = pci->romsize; | ||
| 340 | *__rom = rom; | ||
| 83 | 341 | ||
| 84 | nr_pci = size / sizeof(void *); | 342 | status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, |
| 85 | for (i = 0; i < nr_pci; i++) { | 343 | PCI_VENDOR_ID, 1, &(rom->vendor)); |
| 86 | void *h = pci_handle[i]; | ||
| 87 | uint64_t attributes; | ||
| 88 | struct pci_setup_rom *rom; | ||
| 89 | 344 | ||
| 90 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 345 | if (status != EFI_SUCCESS) |
| 91 | h, &pci_proto, &pci); | 346 | goto free_struct; |
| 92 | 347 | ||
| 93 | if (status != EFI_SUCCESS) | 348 | status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, |
| 94 | continue; | 349 | PCI_DEVICE_ID, 1, &(rom->devid)); |
| 95 | 350 | ||
| 96 | if (!pci) | 351 | if (status != EFI_SUCCESS) |
| 97 | continue; | 352 | goto free_struct; |
| 98 | 353 | ||
| 99 | #ifdef CONFIG_X86_64 | 354 | status = efi_early->call(pci->get_location, pci, &(rom->segment), |
| 100 | status = efi_call_phys4(pci->attributes, pci, | 355 | &(rom->bus), &(rom->device), &(rom->function)); |
| 101 | EfiPciIoAttributeOperationGet, 0, | ||
| 102 | &attributes); | ||
| 103 | #else | ||
| 104 | status = efi_call_phys5(pci->attributes, pci, | ||
| 105 | EfiPciIoAttributeOperationGet, 0, 0, | ||
| 106 | &attributes); | ||
| 107 | #endif | ||
| 108 | if (status != EFI_SUCCESS) | ||
| 109 | continue; | ||
| 110 | 356 | ||
| 111 | if (!pci->romimage || !pci->romsize) | 357 | if (status != EFI_SUCCESS) |
| 112 | continue; | 358 | goto free_struct; |
| 113 | 359 | ||
| 114 | size = pci->romsize + sizeof(*rom); | 360 | memcpy(rom->romdata, pci->romimage, pci->romsize); |
| 361 | return status; | ||
| 115 | 362 | ||
| 116 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 363 | free_struct: |
| 117 | EFI_LOADER_DATA, size, &rom); | 364 | efi_early->call(efi_early->free_pool, rom); |
| 365 | return status; | ||
| 366 | } | ||
| 118 | 367 | ||
| 119 | if (status != EFI_SUCCESS) | 368 | static efi_status_t |
| 120 | continue; | 369 | setup_efi_pci32(struct boot_params *params, void **pci_handle, |
| 370 | unsigned long size) | ||
| 371 | { | ||
| 372 | efi_pci_io_protocol_32 *pci = NULL; | ||
| 373 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; | ||
| 374 | u32 *handles = (u32 *)(unsigned long)pci_handle; | ||
| 375 | efi_status_t status; | ||
| 376 | unsigned long nr_pci; | ||
| 377 | struct setup_data *data; | ||
| 378 | int i; | ||
| 121 | 379 | ||
| 122 | rom->data.type = SETUP_PCI; | 380 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; |
| 123 | rom->data.len = size - sizeof(struct setup_data); | ||
| 124 | rom->data.next = 0; | ||
| 125 | rom->pcilen = pci->romsize; | ||
| 126 | 381 | ||
| 127 | status = efi_call_phys5(pci->pci.read, pci, | 382 | while (data && data->next) |
| 128 | EfiPciIoWidthUint16, PCI_VENDOR_ID, | 383 | data = (struct setup_data *)(unsigned long)data->next; |
| 129 | 1, &(rom->vendor)); | ||
| 130 | 384 | ||
| 131 | if (status != EFI_SUCCESS) | 385 | nr_pci = size / sizeof(u32); |
| 132 | goto free_struct; | 386 | for (i = 0; i < nr_pci; i++) { |
| 387 | struct pci_setup_rom *rom = NULL; | ||
| 388 | u32 h = handles[i]; | ||
| 133 | 389 | ||
| 134 | status = efi_call_phys5(pci->pci.read, pci, | 390 | status = efi_early->call(efi_early->handle_protocol, h, |
| 135 | EfiPciIoWidthUint16, PCI_DEVICE_ID, | 391 | &pci_proto, (void **)&pci); |
| 136 | 1, &(rom->devid)); | ||
| 137 | 392 | ||
| 138 | if (status != EFI_SUCCESS) | 393 | if (status != EFI_SUCCESS) |
| 139 | goto free_struct; | 394 | continue; |
| 140 | 395 | ||
| 141 | status = efi_call_phys5(pci->get_location, pci, | 396 | if (!pci) |
| 142 | &(rom->segment), &(rom->bus), | 397 | continue; |
| 143 | &(rom->device), &(rom->function)); | ||
| 144 | 398 | ||
| 399 | status = __setup_efi_pci32(pci, &rom); | ||
| 145 | if (status != EFI_SUCCESS) | 400 | if (status != EFI_SUCCESS) |
| 146 | goto free_struct; | 401 | continue; |
| 147 | |||
| 148 | memcpy(rom->romdata, pci->romimage, pci->romsize); | ||
| 149 | 402 | ||
| 150 | if (data) | 403 | if (data) |
| 151 | data->next = (unsigned long)rom; | 404 | data->next = (unsigned long)rom; |
| @@ -154,105 +407,157 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
| 154 | 407 | ||
| 155 | data = (struct setup_data *)rom; | 408 | data = (struct setup_data *)rom; |
| 156 | 409 | ||
| 157 | continue; | ||
| 158 | free_struct: | ||
| 159 | efi_call_phys1(sys_table->boottime->free_pool, rom); | ||
| 160 | } | 410 | } |
| 161 | 411 | ||
| 162 | free_handle: | ||
| 163 | efi_call_phys1(sys_table->boottime->free_pool, pci_handle); | ||
| 164 | return status; | 412 | return status; |
| 165 | } | 413 | } |
| 166 | 414 | ||
| 167 | /* | 415 | static efi_status_t |
| 168 | * See if we have Graphics Output Protocol | 416 | __setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom) |
| 169 | */ | ||
| 170 | static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, | ||
| 171 | unsigned long size) | ||
| 172 | { | 417 | { |
| 173 | struct efi_graphics_output_protocol *gop, *first_gop; | 418 | struct pci_setup_rom *rom; |
| 174 | struct efi_pixel_bitmask pixel_info; | ||
| 175 | unsigned long nr_gops; | ||
| 176 | efi_status_t status; | 419 | efi_status_t status; |
| 177 | void **gop_handle; | 420 | unsigned long size; |
| 178 | u16 width, height; | 421 | uint64_t attributes; |
| 179 | u32 fb_base, fb_size; | ||
| 180 | u32 pixels_per_scan_line; | ||
| 181 | int pixel_format; | ||
| 182 | int i; | ||
| 183 | 422 | ||
| 184 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 423 | status = efi_early->call(pci->attributes, pci, |
| 185 | EFI_LOADER_DATA, size, &gop_handle); | 424 | EfiPciIoAttributeOperationGet, 0, |
| 425 | &attributes); | ||
| 186 | if (status != EFI_SUCCESS) | 426 | if (status != EFI_SUCCESS) |
| 187 | return status; | 427 | return status; |
| 188 | 428 | ||
| 189 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 429 | if (!pci->romimage || !pci->romsize) |
| 190 | EFI_LOCATE_BY_PROTOCOL, proto, | 430 | return EFI_INVALID_PARAMETER; |
| 191 | NULL, &size, gop_handle); | 431 | |
| 432 | size = pci->romsize + sizeof(*rom); | ||
| 433 | |||
| 434 | status = efi_early->call(efi_early->allocate_pool, | ||
| 435 | EFI_LOADER_DATA, size, &rom); | ||
| 436 | |||
| 192 | if (status != EFI_SUCCESS) | 437 | if (status != EFI_SUCCESS) |
| 193 | goto free_handle; | 438 | return status; |
| 194 | 439 | ||
| 195 | first_gop = NULL; | 440 | rom->data.type = SETUP_PCI; |
| 441 | rom->data.len = size - sizeof(struct setup_data); | ||
| 442 | rom->data.next = 0; | ||
| 443 | rom->pcilen = pci->romsize; | ||
| 444 | *__rom = rom; | ||
| 196 | 445 | ||
| 197 | nr_gops = size / sizeof(void *); | 446 | status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, |
| 198 | for (i = 0; i < nr_gops; i++) { | 447 | PCI_VENDOR_ID, 1, &(rom->vendor)); |
| 199 | struct efi_graphics_output_mode_info *info; | 448 | |
| 200 | efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID; | 449 | if (status != EFI_SUCCESS) |
| 201 | bool conout_found = false; | 450 | goto free_struct; |
| 202 | void *dummy; | 451 | |
| 203 | void *h = gop_handle[i]; | 452 | status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16, |
| 453 | PCI_DEVICE_ID, 1, &(rom->devid)); | ||
| 454 | |||
| 455 | if (status != EFI_SUCCESS) | ||
| 456 | goto free_struct; | ||
| 457 | |||
| 458 | status = efi_early->call(pci->get_location, pci, &(rom->segment), | ||
| 459 | &(rom->bus), &(rom->device), &(rom->function)); | ||
| 460 | |||
| 461 | if (status != EFI_SUCCESS) | ||
| 462 | goto free_struct; | ||
| 463 | |||
| 464 | memcpy(rom->romdata, pci->romimage, pci->romsize); | ||
| 465 | return status; | ||
| 466 | |||
| 467 | free_struct: | ||
| 468 | efi_early->call(efi_early->free_pool, rom); | ||
| 469 | return status; | ||
| 470 | |||
| 471 | } | ||
| 472 | |||
| 473 | static efi_status_t | ||
| 474 | setup_efi_pci64(struct boot_params *params, void **pci_handle, | ||
| 475 | unsigned long size) | ||
| 476 | { | ||
| 477 | efi_pci_io_protocol_64 *pci = NULL; | ||
| 478 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; | ||
| 479 | u64 *handles = (u64 *)(unsigned long)pci_handle; | ||
| 480 | efi_status_t status; | ||
| 481 | unsigned long nr_pci; | ||
| 482 | struct setup_data *data; | ||
| 483 | int i; | ||
| 484 | |||
| 485 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; | ||
| 486 | |||
| 487 | while (data && data->next) | ||
| 488 | data = (struct setup_data *)(unsigned long)data->next; | ||
| 489 | |||
| 490 | nr_pci = size / sizeof(u64); | ||
| 491 | for (i = 0; i < nr_pci; i++) { | ||
| 492 | struct pci_setup_rom *rom = NULL; | ||
| 493 | u64 h = handles[i]; | ||
| 494 | |||
| 495 | status = efi_early->call(efi_early->handle_protocol, h, | ||
| 496 | &pci_proto, (void **)&pci); | ||
| 204 | 497 | ||
| 205 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | ||
| 206 | h, proto, &gop); | ||
| 207 | if (status != EFI_SUCCESS) | 498 | if (status != EFI_SUCCESS) |
| 208 | continue; | 499 | continue; |
| 209 | 500 | ||
| 210 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 501 | if (!pci) |
| 211 | h, &conout_proto, &dummy); | 502 | continue; |
| 212 | 503 | ||
| 213 | if (status == EFI_SUCCESS) | 504 | status = __setup_efi_pci64(pci, &rom); |
| 214 | conout_found = true; | 505 | if (status != EFI_SUCCESS) |
| 506 | continue; | ||
| 215 | 507 | ||
| 216 | status = efi_call_phys4(gop->query_mode, gop, | 508 | if (data) |
| 217 | gop->mode->mode, &size, &info); | 509 | data->next = (unsigned long)rom; |
| 218 | if (status == EFI_SUCCESS && (!first_gop || conout_found)) { | 510 | else |
| 219 | /* | 511 | params->hdr.setup_data = (unsigned long)rom; |
| 220 | * Systems that use the UEFI Console Splitter may | 512 | |
| 221 | * provide multiple GOP devices, not all of which are | 513 | data = (struct setup_data *)rom; |
| 222 | * backed by real hardware. The workaround is to search | ||
| 223 | * for a GOP implementing the ConOut protocol, and if | ||
| 224 | * one isn't found, to just fall back to the first GOP. | ||
| 225 | */ | ||
| 226 | width = info->horizontal_resolution; | ||
| 227 | height = info->vertical_resolution; | ||
| 228 | fb_base = gop->mode->frame_buffer_base; | ||
| 229 | fb_size = gop->mode->frame_buffer_size; | ||
| 230 | pixel_format = info->pixel_format; | ||
| 231 | pixel_info = info->pixel_information; | ||
| 232 | pixels_per_scan_line = info->pixels_per_scan_line; | ||
| 233 | 514 | ||
| 234 | /* | ||
| 235 | * Once we've found a GOP supporting ConOut, | ||
| 236 | * don't bother looking any further. | ||
| 237 | */ | ||
| 238 | first_gop = gop; | ||
| 239 | if (conout_found) | ||
| 240 | break; | ||
| 241 | } | ||
| 242 | } | 515 | } |
| 243 | 516 | ||
| 244 | /* Did we find any GOPs? */ | 517 | return status; |
| 245 | if (!first_gop) | 518 | } |
| 519 | |||
| 520 | static efi_status_t setup_efi_pci(struct boot_params *params) | ||
| 521 | { | ||
| 522 | efi_status_t status; | ||
| 523 | void **pci_handle = NULL; | ||
| 524 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; | ||
| 525 | unsigned long size = 0; | ||
| 526 | |||
| 527 | status = efi_early->call(efi_early->locate_handle, | ||
| 528 | EFI_LOCATE_BY_PROTOCOL, | ||
| 529 | &pci_proto, NULL, &size, pci_handle); | ||
| 530 | |||
| 531 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
| 532 | status = efi_early->call(efi_early->allocate_pool, | ||
| 533 | EFI_LOADER_DATA, | ||
| 534 | size, (void **)&pci_handle); | ||
| 535 | |||
| 536 | if (status != EFI_SUCCESS) | ||
| 537 | return status; | ||
| 538 | |||
| 539 | status = efi_early->call(efi_early->locate_handle, | ||
| 540 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, | ||
| 541 | NULL, &size, pci_handle); | ||
| 542 | } | ||
| 543 | |||
| 544 | if (status != EFI_SUCCESS) | ||
| 246 | goto free_handle; | 545 | goto free_handle; |
| 247 | 546 | ||
| 248 | /* EFI framebuffer */ | 547 | if (efi_early->is64) |
| 249 | si->orig_video_isVGA = VIDEO_TYPE_EFI; | 548 | status = setup_efi_pci64(params, pci_handle, size); |
| 549 | else | ||
| 550 | status = setup_efi_pci32(params, pci_handle, size); | ||
| 250 | 551 | ||
| 251 | si->lfb_width = width; | 552 | free_handle: |
| 252 | si->lfb_height = height; | 553 | efi_early->call(efi_early->free_pool, pci_handle); |
| 253 | si->lfb_base = fb_base; | 554 | return status; |
| 254 | si->pages = 1; | 555 | } |
| 255 | 556 | ||
| 557 | static void | ||
| 558 | setup_pixel_info(struct screen_info *si, u32 pixels_per_scan_line, | ||
| 559 | struct efi_pixel_bitmask pixel_info, int pixel_format) | ||
| 560 | { | ||
| 256 | if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) { | 561 | if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) { |
| 257 | si->lfb_depth = 32; | 562 | si->lfb_depth = 32; |
| 258 | si->lfb_linelength = pixels_per_scan_line * 4; | 563 | si->lfb_linelength = pixels_per_scan_line * 4; |
| @@ -297,62 +602,321 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, | |||
| 297 | si->rsvd_size = 0; | 602 | si->rsvd_size = 0; |
| 298 | si->rsvd_pos = 0; | 603 | si->rsvd_pos = 0; |
| 299 | } | 604 | } |
| 605 | } | ||
| 606 | |||
| 607 | static efi_status_t | ||
| 608 | __gop_query32(struct efi_graphics_output_protocol_32 *gop32, | ||
| 609 | struct efi_graphics_output_mode_info **info, | ||
| 610 | unsigned long *size, u32 *fb_base) | ||
| 611 | { | ||
| 612 | struct efi_graphics_output_protocol_mode_32 *mode; | ||
| 613 | efi_status_t status; | ||
| 614 | unsigned long m; | ||
| 615 | |||
| 616 | m = gop32->mode; | ||
| 617 | mode = (struct efi_graphics_output_protocol_mode_32 *)m; | ||
| 618 | |||
| 619 | status = efi_early->call(gop32->query_mode, gop32, | ||
| 620 | mode->mode, size, info); | ||
| 621 | if (status != EFI_SUCCESS) | ||
| 622 | return status; | ||
| 623 | |||
| 624 | *fb_base = mode->frame_buffer_base; | ||
| 625 | return status; | ||
| 626 | } | ||
| 627 | |||
| 628 | static efi_status_t | ||
| 629 | setup_gop32(struct screen_info *si, efi_guid_t *proto, | ||
| 630 | unsigned long size, void **gop_handle) | ||
| 631 | { | ||
| 632 | struct efi_graphics_output_protocol_32 *gop32, *first_gop; | ||
| 633 | unsigned long nr_gops; | ||
| 634 | u16 width, height; | ||
| 635 | u32 pixels_per_scan_line; | ||
| 636 | u32 fb_base; | ||
| 637 | struct efi_pixel_bitmask pixel_info; | ||
| 638 | int pixel_format; | ||
| 639 | efi_status_t status; | ||
| 640 | u32 *handles = (u32 *)(unsigned long)gop_handle; | ||
| 641 | int i; | ||
| 642 | |||
| 643 | first_gop = NULL; | ||
| 644 | gop32 = NULL; | ||
| 645 | |||
| 646 | nr_gops = size / sizeof(u32); | ||
| 647 | for (i = 0; i < nr_gops; i++) { | ||
| 648 | struct efi_graphics_output_mode_info *info = NULL; | ||
| 649 | efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID; | ||
| 650 | bool conout_found = false; | ||
| 651 | void *dummy = NULL; | ||
| 652 | u32 h = handles[i]; | ||
| 653 | |||
| 654 | status = efi_early->call(efi_early->handle_protocol, h, | ||
| 655 | proto, (void **)&gop32); | ||
| 656 | if (status != EFI_SUCCESS) | ||
| 657 | continue; | ||
| 658 | |||
| 659 | status = efi_early->call(efi_early->handle_protocol, h, | ||
| 660 | &conout_proto, &dummy); | ||
| 661 | if (status == EFI_SUCCESS) | ||
| 662 | conout_found = true; | ||
| 663 | |||
| 664 | status = __gop_query32(gop32, &info, &size, &fb_base); | ||
| 665 | if (status == EFI_SUCCESS && (!first_gop || conout_found)) { | ||
| 666 | /* | ||
| 667 | * Systems that use the UEFI Console Splitter may | ||
| 668 | * provide multiple GOP devices, not all of which are | ||
| 669 | * backed by real hardware. The workaround is to search | ||
| 670 | * for a GOP implementing the ConOut protocol, and if | ||
| 671 | * one isn't found, to just fall back to the first GOP. | ||
| 672 | */ | ||
| 673 | width = info->horizontal_resolution; | ||
| 674 | height = info->vertical_resolution; | ||
| 675 | pixel_format = info->pixel_format; | ||
| 676 | pixel_info = info->pixel_information; | ||
| 677 | pixels_per_scan_line = info->pixels_per_scan_line; | ||
| 678 | |||
| 679 | /* | ||
| 680 | * Once we've found a GOP supporting ConOut, | ||
| 681 | * don't bother looking any further. | ||
| 682 | */ | ||
| 683 | first_gop = gop32; | ||
| 684 | if (conout_found) | ||
| 685 | break; | ||
| 686 | } | ||
| 687 | } | ||
| 688 | |||
| 689 | /* Did we find any GOPs? */ | ||
| 690 | if (!first_gop) | ||
| 691 | goto out; | ||
| 692 | |||
| 693 | /* EFI framebuffer */ | ||
| 694 | si->orig_video_isVGA = VIDEO_TYPE_EFI; | ||
| 695 | |||
| 696 | si->lfb_width = width; | ||
| 697 | si->lfb_height = height; | ||
| 698 | si->lfb_base = fb_base; | ||
| 699 | si->pages = 1; | ||
| 700 | |||
| 701 | setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format); | ||
| 300 | 702 | ||
| 301 | si->lfb_size = si->lfb_linelength * si->lfb_height; | 703 | si->lfb_size = si->lfb_linelength * si->lfb_height; |
| 302 | 704 | ||
| 303 | si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; | 705 | si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; |
| 706 | out: | ||
| 707 | return status; | ||
| 708 | } | ||
| 304 | 709 | ||
| 305 | free_handle: | 710 | static efi_status_t |
| 306 | efi_call_phys1(sys_table->boottime->free_pool, gop_handle); | 711 | __gop_query64(struct efi_graphics_output_protocol_64 *gop64, |
| 712 | struct efi_graphics_output_mode_info **info, | ||
| 713 | unsigned long *size, u32 *fb_base) | ||
| 714 | { | ||
| 715 | struct efi_graphics_output_protocol_mode_64 *mode; | ||
| 716 | efi_status_t status; | ||
| 717 | unsigned long m; | ||
| 718 | |||
| 719 | m = gop64->mode; | ||
| 720 | mode = (struct efi_graphics_output_protocol_mode_64 *)m; | ||
| 721 | |||
| 722 | status = efi_early->call(gop64->query_mode, gop64, | ||
| 723 | mode->mode, size, info); | ||
| 724 | if (status != EFI_SUCCESS) | ||
| 725 | return status; | ||
| 726 | |||
| 727 | *fb_base = mode->frame_buffer_base; | ||
| 728 | return status; | ||
| 729 | } | ||
| 730 | |||
| 731 | static efi_status_t | ||
| 732 | setup_gop64(struct screen_info *si, efi_guid_t *proto, | ||
| 733 | unsigned long size, void **gop_handle) | ||
| 734 | { | ||
| 735 | struct efi_graphics_output_protocol_64 *gop64, *first_gop; | ||
| 736 | unsigned long nr_gops; | ||
| 737 | u16 width, height; | ||
| 738 | u32 pixels_per_scan_line; | ||
| 739 | u32 fb_base; | ||
| 740 | struct efi_pixel_bitmask pixel_info; | ||
| 741 | int pixel_format; | ||
| 742 | efi_status_t status; | ||
| 743 | u64 *handles = (u64 *)(unsigned long)gop_handle; | ||
| 744 | int i; | ||
| 745 | |||
| 746 | first_gop = NULL; | ||
| 747 | gop64 = NULL; | ||
| 748 | |||
| 749 | nr_gops = size / sizeof(u64); | ||
| 750 | for (i = 0; i < nr_gops; i++) { | ||
| 751 | struct efi_graphics_output_mode_info *info = NULL; | ||
| 752 | efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID; | ||
| 753 | bool conout_found = false; | ||
| 754 | void *dummy = NULL; | ||
| 755 | u64 h = handles[i]; | ||
| 756 | |||
| 757 | status = efi_early->call(efi_early->handle_protocol, h, | ||
| 758 | proto, (void **)&gop64); | ||
| 759 | if (status != EFI_SUCCESS) | ||
| 760 | continue; | ||
| 761 | |||
| 762 | status = efi_early->call(efi_early->handle_protocol, h, | ||
| 763 | &conout_proto, &dummy); | ||
| 764 | if (status == EFI_SUCCESS) | ||
| 765 | conout_found = true; | ||
| 766 | |||
| 767 | status = __gop_query64(gop64, &info, &size, &fb_base); | ||
| 768 | if (status == EFI_SUCCESS && (!first_gop || conout_found)) { | ||
| 769 | /* | ||
| 770 | * Systems that use the UEFI Console Splitter may | ||
| 771 | * provide multiple GOP devices, not all of which are | ||
| 772 | * backed by real hardware. The workaround is to search | ||
| 773 | * for a GOP implementing the ConOut protocol, and if | ||
| 774 | * one isn't found, to just fall back to the first GOP. | ||
| 775 | */ | ||
| 776 | width = info->horizontal_resolution; | ||
| 777 | height = info->vertical_resolution; | ||
| 778 | pixel_format = info->pixel_format; | ||
| 779 | pixel_info = info->pixel_information; | ||
| 780 | pixels_per_scan_line = info->pixels_per_scan_line; | ||
| 781 | |||
| 782 | /* | ||
| 783 | * Once we've found a GOP supporting ConOut, | ||
| 784 | * don't bother looking any further. | ||
| 785 | */ | ||
| 786 | first_gop = gop64; | ||
| 787 | if (conout_found) | ||
| 788 | break; | ||
| 789 | } | ||
| 790 | } | ||
| 791 | |||
| 792 | /* Did we find any GOPs? */ | ||
| 793 | if (!first_gop) | ||
| 794 | goto out; | ||
| 795 | |||
| 796 | /* EFI framebuffer */ | ||
| 797 | si->orig_video_isVGA = VIDEO_TYPE_EFI; | ||
| 798 | |||
| 799 | si->lfb_width = width; | ||
| 800 | si->lfb_height = height; | ||
| 801 | si->lfb_base = fb_base; | ||
| 802 | si->pages = 1; | ||
| 803 | |||
| 804 | setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format); | ||
| 805 | |||
| 806 | si->lfb_size = si->lfb_linelength * si->lfb_height; | ||
| 807 | |||
| 808 | si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; | ||
| 809 | out: | ||
| 307 | return status; | 810 | return status; |
| 308 | } | 811 | } |
| 309 | 812 | ||
| 310 | /* | 813 | /* |
| 311 | * See if we have Universal Graphics Adapter (UGA) protocol | 814 | * See if we have Graphics Output Protocol |
| 312 | */ | 815 | */ |
| 313 | static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | 816 | static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, |
| 314 | unsigned long size) | 817 | unsigned long size) |
| 315 | { | 818 | { |
| 316 | struct efi_uga_draw_protocol *uga, *first_uga; | ||
| 317 | unsigned long nr_ugas; | ||
| 318 | efi_status_t status; | 819 | efi_status_t status; |
| 319 | u32 width, height; | 820 | void **gop_handle = NULL; |
| 320 | void **uga_handle = NULL; | ||
| 321 | int i; | ||
| 322 | 821 | ||
| 323 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 822 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
| 324 | EFI_LOADER_DATA, size, &uga_handle); | 823 | size, (void **)&gop_handle); |
| 325 | if (status != EFI_SUCCESS) | 824 | if (status != EFI_SUCCESS) |
| 326 | return status; | 825 | return status; |
| 327 | 826 | ||
| 328 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 827 | status = efi_early->call(efi_early->locate_handle, |
| 329 | EFI_LOCATE_BY_PROTOCOL, uga_proto, | 828 | EFI_LOCATE_BY_PROTOCOL, |
| 330 | NULL, &size, uga_handle); | 829 | proto, NULL, &size, gop_handle); |
| 331 | if (status != EFI_SUCCESS) | 830 | if (status != EFI_SUCCESS) |
| 332 | goto free_handle; | 831 | goto free_handle; |
| 333 | 832 | ||
| 833 | if (efi_early->is64) | ||
| 834 | status = setup_gop64(si, proto, size, gop_handle); | ||
| 835 | else | ||
| 836 | status = setup_gop32(si, proto, size, gop_handle); | ||
| 837 | |||
| 838 | free_handle: | ||
| 839 | efi_early->call(efi_early->free_pool, gop_handle); | ||
| 840 | return status; | ||
| 841 | } | ||
| 842 | |||
| 843 | static efi_status_t | ||
| 844 | setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height) | ||
| 845 | { | ||
| 846 | struct efi_uga_draw_protocol *uga = NULL, *first_uga; | ||
| 847 | efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; | ||
| 848 | unsigned long nr_ugas; | ||
| 849 | u32 *handles = (u32 *)uga_handle;; | ||
| 850 | efi_status_t status; | ||
| 851 | int i; | ||
| 852 | |||
| 334 | first_uga = NULL; | 853 | first_uga = NULL; |
| 854 | nr_ugas = size / sizeof(u32); | ||
| 855 | for (i = 0; i < nr_ugas; i++) { | ||
| 856 | efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; | ||
| 857 | u32 w, h, depth, refresh; | ||
| 858 | void *pciio; | ||
| 859 | u32 handle = handles[i]; | ||
| 335 | 860 | ||
| 336 | nr_ugas = size / sizeof(void *); | 861 | status = efi_early->call(efi_early->handle_protocol, handle, |
| 862 | &uga_proto, (void **)&uga); | ||
| 863 | if (status != EFI_SUCCESS) | ||
| 864 | continue; | ||
| 865 | |||
| 866 | efi_early->call(efi_early->handle_protocol, handle, | ||
| 867 | &pciio_proto, &pciio); | ||
| 868 | |||
| 869 | status = efi_early->call((unsigned long)uga->get_mode, uga, | ||
| 870 | &w, &h, &depth, &refresh); | ||
| 871 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { | ||
| 872 | *width = w; | ||
| 873 | *height = h; | ||
| 874 | |||
| 875 | /* | ||
| 876 | * Once we've found a UGA supporting PCIIO, | ||
| 877 | * don't bother looking any further. | ||
| 878 | */ | ||
| 879 | if (pciio) | ||
| 880 | break; | ||
| 881 | |||
| 882 | first_uga = uga; | ||
| 883 | } | ||
| 884 | } | ||
| 885 | |||
| 886 | return status; | ||
| 887 | } | ||
| 888 | |||
| 889 | static efi_status_t | ||
| 890 | setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height) | ||
| 891 | { | ||
| 892 | struct efi_uga_draw_protocol *uga = NULL, *first_uga; | ||
| 893 | efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; | ||
| 894 | unsigned long nr_ugas; | ||
| 895 | u64 *handles = (u64 *)uga_handle;; | ||
| 896 | efi_status_t status; | ||
| 897 | int i; | ||
| 898 | |||
| 899 | first_uga = NULL; | ||
| 900 | nr_ugas = size / sizeof(u64); | ||
| 337 | for (i = 0; i < nr_ugas; i++) { | 901 | for (i = 0; i < nr_ugas; i++) { |
| 338 | efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; | 902 | efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; |
| 339 | void *handle = uga_handle[i]; | ||
| 340 | u32 w, h, depth, refresh; | 903 | u32 w, h, depth, refresh; |
| 341 | void *pciio; | 904 | void *pciio; |
| 905 | u64 handle = handles[i]; | ||
| 342 | 906 | ||
| 343 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 907 | status = efi_early->call(efi_early->handle_protocol, handle, |
| 344 | handle, uga_proto, &uga); | 908 | &uga_proto, (void **)&uga); |
| 345 | if (status != EFI_SUCCESS) | 909 | if (status != EFI_SUCCESS) |
| 346 | continue; | 910 | continue; |
| 347 | 911 | ||
| 348 | efi_call_phys3(sys_table->boottime->handle_protocol, | 912 | efi_early->call(efi_early->handle_protocol, handle, |
| 349 | handle, &pciio_proto, &pciio); | 913 | &pciio_proto, &pciio); |
| 350 | 914 | ||
| 351 | status = efi_call_phys5(uga->get_mode, uga, &w, &h, | 915 | status = efi_early->call((unsigned long)uga->get_mode, uga, |
| 352 | &depth, &refresh); | 916 | &w, &h, &depth, &refresh); |
| 353 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { | 917 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { |
| 354 | width = w; | 918 | *width = w; |
| 355 | height = h; | 919 | *height = h; |
| 356 | 920 | ||
| 357 | /* | 921 | /* |
| 358 | * Once we've found a UGA supporting PCIIO, | 922 | * Once we've found a UGA supporting PCIIO, |
| @@ -365,7 +929,39 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | |||
| 365 | } | 929 | } |
| 366 | } | 930 | } |
| 367 | 931 | ||
| 368 | if (!first_uga) | 932 | return status; |
| 933 | } | ||
| 934 | |||
| 935 | /* | ||
| 936 | * See if we have Universal Graphics Adapter (UGA) protocol | ||
| 937 | */ | ||
| 938 | static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | ||
| 939 | unsigned long size) | ||
| 940 | { | ||
| 941 | efi_status_t status; | ||
| 942 | u32 width, height; | ||
| 943 | void **uga_handle = NULL; | ||
| 944 | |||
| 945 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, | ||
| 946 | size, (void **)&uga_handle); | ||
| 947 | if (status != EFI_SUCCESS) | ||
| 948 | return status; | ||
| 949 | |||
| 950 | status = efi_early->call(efi_early->locate_handle, | ||
| 951 | EFI_LOCATE_BY_PROTOCOL, | ||
| 952 | uga_proto, NULL, &size, uga_handle); | ||
| 953 | if (status != EFI_SUCCESS) | ||
| 954 | goto free_handle; | ||
| 955 | |||
| 956 | height = 0; | ||
| 957 | width = 0; | ||
| 958 | |||
| 959 | if (efi_early->is64) | ||
| 960 | status = setup_uga64(uga_handle, size, &width, &height); | ||
| 961 | else | ||
| 962 | status = setup_uga32(uga_handle, size, &width, &height); | ||
| 963 | |||
| 964 | if (!width && !height) | ||
| 369 | goto free_handle; | 965 | goto free_handle; |
| 370 | 966 | ||
| 371 | /* EFI framebuffer */ | 967 | /* EFI framebuffer */ |
| @@ -384,9 +980,8 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | |||
| 384 | si->rsvd_size = 8; | 980 | si->rsvd_size = 8; |
| 385 | si->rsvd_pos = 24; | 981 | si->rsvd_pos = 24; |
| 386 | 982 | ||
| 387 | |||
| 388 | free_handle: | 983 | free_handle: |
| 389 | efi_call_phys1(sys_table->boottime->free_pool, uga_handle); | 984 | efi_early->call(efi_early->free_pool, uga_handle); |
| 390 | return status; | 985 | return status; |
| 391 | } | 986 | } |
| 392 | 987 | ||
| @@ -404,29 +999,28 @@ void setup_graphics(struct boot_params *boot_params) | |||
| 404 | memset(si, 0, sizeof(*si)); | 999 | memset(si, 0, sizeof(*si)); |
| 405 | 1000 | ||
| 406 | size = 0; | 1001 | size = 0; |
| 407 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 1002 | status = efi_early->call(efi_early->locate_handle, |
| 408 | EFI_LOCATE_BY_PROTOCOL, &graphics_proto, | 1003 | EFI_LOCATE_BY_PROTOCOL, |
| 409 | NULL, &size, gop_handle); | 1004 | &graphics_proto, NULL, &size, gop_handle); |
| 410 | if (status == EFI_BUFFER_TOO_SMALL) | 1005 | if (status == EFI_BUFFER_TOO_SMALL) |
| 411 | status = setup_gop(si, &graphics_proto, size); | 1006 | status = setup_gop(si, &graphics_proto, size); |
| 412 | 1007 | ||
| 413 | if (status != EFI_SUCCESS) { | 1008 | if (status != EFI_SUCCESS) { |
| 414 | size = 0; | 1009 | size = 0; |
| 415 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 1010 | status = efi_early->call(efi_early->locate_handle, |
| 416 | EFI_LOCATE_BY_PROTOCOL, &uga_proto, | 1011 | EFI_LOCATE_BY_PROTOCOL, |
| 417 | NULL, &size, uga_handle); | 1012 | &uga_proto, NULL, &size, uga_handle); |
| 418 | if (status == EFI_BUFFER_TOO_SMALL) | 1013 | if (status == EFI_BUFFER_TOO_SMALL) |
| 419 | setup_uga(si, &uga_proto, size); | 1014 | setup_uga(si, &uga_proto, size); |
| 420 | } | 1015 | } |
| 421 | } | 1016 | } |
| 422 | 1017 | ||
| 423 | |||
| 424 | /* | 1018 | /* |
| 425 | * Because the x86 boot code expects to be passed a boot_params we | 1019 | * Because the x86 boot code expects to be passed a boot_params we |
| 426 | * need to create one ourselves (usually the bootloader would create | 1020 | * need to create one ourselves (usually the bootloader would create |
| 427 | * one for us). | 1021 | * one for us). |
| 428 | */ | 1022 | */ |
| 429 | struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) | 1023 | struct boot_params *make_boot_params(struct efi_config *c) |
| 430 | { | 1024 | { |
| 431 | struct boot_params *boot_params; | 1025 | struct boot_params *boot_params; |
| 432 | struct sys_desc_table *sdt; | 1026 | struct sys_desc_table *sdt; |
| @@ -434,7 +1028,7 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) | |||
| 434 | struct setup_header *hdr; | 1028 | struct setup_header *hdr; |
| 435 | struct efi_info *efi; | 1029 | struct efi_info *efi; |
| 436 | efi_loaded_image_t *image; | 1030 | efi_loaded_image_t *image; |
| 437 | void *options; | 1031 | void *options, *handle; |
| 438 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; | 1032 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; |
| 439 | int options_size = 0; | 1033 | int options_size = 0; |
| 440 | efi_status_t status; | 1034 | efi_status_t status; |
| @@ -445,14 +1039,21 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) | |||
| 445 | unsigned long ramdisk_addr; | 1039 | unsigned long ramdisk_addr; |
| 446 | unsigned long ramdisk_size; | 1040 | unsigned long ramdisk_size; |
| 447 | 1041 | ||
| 448 | sys_table = _table; | 1042 | efi_early = c; |
| 1043 | sys_table = (efi_system_table_t *)(unsigned long)efi_early->table; | ||
| 1044 | handle = (void *)(unsigned long)efi_early->image_handle; | ||
| 449 | 1045 | ||
| 450 | /* Check if we were booted by the EFI firmware */ | 1046 | /* Check if we were booted by the EFI firmware */ |
| 451 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) | 1047 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
| 452 | return NULL; | 1048 | return NULL; |
| 453 | 1049 | ||
| 454 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 1050 | if (efi_early->is64) |
| 455 | handle, &proto, (void *)&image); | 1051 | setup_boot_services64(efi_early); |
| 1052 | else | ||
| 1053 | setup_boot_services32(efi_early); | ||
| 1054 | |||
| 1055 | status = efi_early->call(efi_early->handle_protocol, handle, | ||
| 1056 | &proto, (void *)&image); | ||
| 456 | if (status != EFI_SUCCESS) { | 1057 | if (status != EFI_SUCCESS) { |
| 457 | efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); | 1058 | efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); |
| 458 | return NULL; | 1059 | return NULL; |
| @@ -641,14 +1242,13 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, | |||
| 641 | sizeof(struct e820entry) * nr_desc; | 1242 | sizeof(struct e820entry) * nr_desc; |
| 642 | 1243 | ||
| 643 | if (*e820ext) { | 1244 | if (*e820ext) { |
| 644 | efi_call_phys1(sys_table->boottime->free_pool, *e820ext); | 1245 | efi_early->call(efi_early->free_pool, *e820ext); |
| 645 | *e820ext = NULL; | 1246 | *e820ext = NULL; |
| 646 | *e820ext_size = 0; | 1247 | *e820ext_size = 0; |
| 647 | } | 1248 | } |
| 648 | 1249 | ||
| 649 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 1250 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
| 650 | EFI_LOADER_DATA, size, e820ext); | 1251 | size, (void **)e820ext); |
| 651 | |||
| 652 | if (status == EFI_SUCCESS) | 1252 | if (status == EFI_SUCCESS) |
| 653 | *e820ext_size = size; | 1253 | *e820ext_size = size; |
| 654 | 1254 | ||
| @@ -656,12 +1256,13 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, | |||
| 656 | } | 1256 | } |
| 657 | 1257 | ||
| 658 | static efi_status_t exit_boot(struct boot_params *boot_params, | 1258 | static efi_status_t exit_boot(struct boot_params *boot_params, |
| 659 | void *handle) | 1259 | void *handle, bool is64) |
| 660 | { | 1260 | { |
| 661 | struct efi_info *efi = &boot_params->efi_info; | 1261 | struct efi_info *efi = &boot_params->efi_info; |
| 662 | unsigned long map_sz, key, desc_size; | 1262 | unsigned long map_sz, key, desc_size; |
| 663 | efi_memory_desc_t *mem_map; | 1263 | efi_memory_desc_t *mem_map; |
| 664 | struct setup_data *e820ext; | 1264 | struct setup_data *e820ext; |
| 1265 | const char *signature; | ||
| 665 | __u32 e820ext_size; | 1266 | __u32 e820ext_size; |
| 666 | __u32 nr_desc, prev_nr_desc; | 1267 | __u32 nr_desc, prev_nr_desc; |
| 667 | efi_status_t status; | 1268 | efi_status_t status; |
| @@ -691,11 +1292,13 @@ get_map: | |||
| 691 | if (status != EFI_SUCCESS) | 1292 | if (status != EFI_SUCCESS) |
| 692 | goto free_mem_map; | 1293 | goto free_mem_map; |
| 693 | 1294 | ||
| 694 | efi_call_phys1(sys_table->boottime->free_pool, mem_map); | 1295 | efi_early->call(efi_early->free_pool, mem_map); |
| 695 | goto get_map; /* Allocated memory, get map again */ | 1296 | goto get_map; /* Allocated memory, get map again */ |
| 696 | } | 1297 | } |
| 697 | 1298 | ||
| 698 | memcpy(&efi->efi_loader_signature, EFI_LOADER_SIGNATURE, sizeof(__u32)); | 1299 | signature = is64 ? EFI64_LOADER_SIGNATURE : EFI32_LOADER_SIGNATURE; |
| 1300 | memcpy(&efi->efi_loader_signature, signature, sizeof(__u32)); | ||
| 1301 | |||
| 699 | efi->efi_systab = (unsigned long)sys_table; | 1302 | efi->efi_systab = (unsigned long)sys_table; |
| 700 | efi->efi_memdesc_size = desc_size; | 1303 | efi->efi_memdesc_size = desc_size; |
| 701 | efi->efi_memdesc_version = desc_version; | 1304 | efi->efi_memdesc_version = desc_version; |
| @@ -708,8 +1311,7 @@ get_map: | |||
| 708 | #endif | 1311 | #endif |
| 709 | 1312 | ||
| 710 | /* Might as well exit boot services now */ | 1313 | /* Might as well exit boot services now */ |
| 711 | status = efi_call_phys2(sys_table->boottime->exit_boot_services, | 1314 | status = efi_early->call(efi_early->exit_boot_services, handle, key); |
| 712 | handle, key); | ||
| 713 | if (status != EFI_SUCCESS) { | 1315 | if (status != EFI_SUCCESS) { |
| 714 | /* | 1316 | /* |
| 715 | * ExitBootServices() will fail if any of the event | 1317 | * ExitBootServices() will fail if any of the event |
| @@ -722,7 +1324,7 @@ get_map: | |||
| 722 | goto free_mem_map; | 1324 | goto free_mem_map; |
| 723 | 1325 | ||
| 724 | called_exit = true; | 1326 | called_exit = true; |
| 725 | efi_call_phys1(sys_table->boottime->free_pool, mem_map); | 1327 | efi_early->call(efi_early->free_pool, mem_map); |
| 726 | goto get_map; | 1328 | goto get_map; |
| 727 | } | 1329 | } |
| 728 | 1330 | ||
| @@ -736,23 +1338,31 @@ get_map: | |||
| 736 | return EFI_SUCCESS; | 1338 | return EFI_SUCCESS; |
| 737 | 1339 | ||
| 738 | free_mem_map: | 1340 | free_mem_map: |
| 739 | efi_call_phys1(sys_table->boottime->free_pool, mem_map); | 1341 | efi_early->call(efi_early->free_pool, mem_map); |
| 740 | return status; | 1342 | return status; |
| 741 | } | 1343 | } |
| 742 | 1344 | ||
| 743 | |||
| 744 | /* | 1345 | /* |
| 745 | * On success we return a pointer to a boot_params structure, and NULL | 1346 | * On success we return a pointer to a boot_params structure, and NULL |
| 746 | * on failure. | 1347 | * on failure. |
| 747 | */ | 1348 | */ |
| 748 | struct boot_params *efi_main(void *handle, efi_system_table_t *_table, | 1349 | struct boot_params *efi_main(struct efi_config *c, |
| 749 | struct boot_params *boot_params) | 1350 | struct boot_params *boot_params) |
| 750 | { | 1351 | { |
| 751 | struct desc_ptr *gdt; | 1352 | struct desc_ptr *gdt = NULL; |
| 752 | efi_loaded_image_t *image; | 1353 | efi_loaded_image_t *image; |
| 753 | struct setup_header *hdr = &boot_params->hdr; | 1354 | struct setup_header *hdr = &boot_params->hdr; |
| 754 | efi_status_t status; | 1355 | efi_status_t status; |
| 755 | struct desc_struct *desc; | 1356 | struct desc_struct *desc; |
| 1357 | void *handle; | ||
| 1358 | efi_system_table_t *_table; | ||
| 1359 | bool is64; | ||
| 1360 | |||
| 1361 | efi_early = c; | ||
| 1362 | |||
| 1363 | _table = (efi_system_table_t *)(unsigned long)efi_early->table; | ||
| 1364 | handle = (void *)(unsigned long)efi_early->image_handle; | ||
| 1365 | is64 = efi_early->is64; | ||
| 756 | 1366 | ||
| 757 | sys_table = _table; | 1367 | sys_table = _table; |
| 758 | 1368 | ||
| @@ -760,13 +1370,17 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table, | |||
| 760 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) | 1370 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
| 761 | goto fail; | 1371 | goto fail; |
| 762 | 1372 | ||
| 1373 | if (is64) | ||
| 1374 | setup_boot_services64(efi_early); | ||
| 1375 | else | ||
| 1376 | setup_boot_services32(efi_early); | ||
| 1377 | |||
| 763 | setup_graphics(boot_params); | 1378 | setup_graphics(boot_params); |
| 764 | 1379 | ||
| 765 | setup_efi_pci(boot_params); | 1380 | setup_efi_pci(boot_params); |
| 766 | 1381 | ||
| 767 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 1382 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
| 768 | EFI_LOADER_DATA, sizeof(*gdt), | 1383 | sizeof(*gdt), (void **)&gdt); |
| 769 | (void **)&gdt); | ||
| 770 | if (status != EFI_SUCCESS) { | 1384 | if (status != EFI_SUCCESS) { |
| 771 | efi_printk(sys_table, "Failed to alloc mem for gdt structure\n"); | 1385 | efi_printk(sys_table, "Failed to alloc mem for gdt structure\n"); |
| 772 | goto fail; | 1386 | goto fail; |
| @@ -797,7 +1411,7 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table, | |||
| 797 | hdr->code32_start = bzimage_addr; | 1411 | hdr->code32_start = bzimage_addr; |
| 798 | } | 1412 | } |
| 799 | 1413 | ||
| 800 | status = exit_boot(boot_params, handle); | 1414 | status = exit_boot(boot_params, handle, is64); |
| 801 | if (status != EFI_SUCCESS) | 1415 | if (status != EFI_SUCCESS) |
| 802 | goto fail; | 1416 | goto fail; |
| 803 | 1417 | ||
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h index 81b6b652b46a..c88c31ecad12 100644 --- a/arch/x86/boot/compressed/eboot.h +++ b/arch/x86/boot/compressed/eboot.h | |||
| @@ -37,6 +37,24 @@ struct efi_graphics_output_mode_info { | |||
| 37 | u32 pixels_per_scan_line; | 37 | u32 pixels_per_scan_line; |
| 38 | } __packed; | 38 | } __packed; |
| 39 | 39 | ||
| 40 | struct efi_graphics_output_protocol_mode_32 { | ||
| 41 | u32 max_mode; | ||
| 42 | u32 mode; | ||
| 43 | u32 info; | ||
| 44 | u32 size_of_info; | ||
| 45 | u64 frame_buffer_base; | ||
| 46 | u32 frame_buffer_size; | ||
| 47 | } __packed; | ||
| 48 | |||
| 49 | struct efi_graphics_output_protocol_mode_64 { | ||
| 50 | u32 max_mode; | ||
| 51 | u32 mode; | ||
| 52 | u64 info; | ||
| 53 | u64 size_of_info; | ||
| 54 | u64 frame_buffer_base; | ||
| 55 | u64 frame_buffer_size; | ||
| 56 | } __packed; | ||
| 57 | |||
| 40 | struct efi_graphics_output_protocol_mode { | 58 | struct efi_graphics_output_protocol_mode { |
| 41 | u32 max_mode; | 59 | u32 max_mode; |
| 42 | u32 mode; | 60 | u32 mode; |
| @@ -46,6 +64,20 @@ struct efi_graphics_output_protocol_mode { | |||
| 46 | unsigned long frame_buffer_size; | 64 | unsigned long frame_buffer_size; |
| 47 | } __packed; | 65 | } __packed; |
| 48 | 66 | ||
| 67 | struct efi_graphics_output_protocol_32 { | ||
| 68 | u32 query_mode; | ||
| 69 | u32 set_mode; | ||
| 70 | u32 blt; | ||
| 71 | u32 mode; | ||
| 72 | }; | ||
| 73 | |||
| 74 | struct efi_graphics_output_protocol_64 { | ||
| 75 | u64 query_mode; | ||
| 76 | u64 set_mode; | ||
| 77 | u64 blt; | ||
| 78 | u64 mode; | ||
| 79 | }; | ||
| 80 | |||
| 49 | struct efi_graphics_output_protocol { | 81 | struct efi_graphics_output_protocol { |
| 50 | void *query_mode; | 82 | void *query_mode; |
| 51 | unsigned long set_mode; | 83 | unsigned long set_mode; |
| @@ -53,10 +85,38 @@ struct efi_graphics_output_protocol { | |||
| 53 | struct efi_graphics_output_protocol_mode *mode; | 85 | struct efi_graphics_output_protocol_mode *mode; |
| 54 | }; | 86 | }; |
| 55 | 87 | ||
| 88 | struct efi_uga_draw_protocol_32 { | ||
| 89 | u32 get_mode; | ||
| 90 | u32 set_mode; | ||
| 91 | u32 blt; | ||
| 92 | }; | ||
| 93 | |||
| 94 | struct efi_uga_draw_protocol_64 { | ||
| 95 | u64 get_mode; | ||
| 96 | u64 set_mode; | ||
| 97 | u64 blt; | ||
| 98 | }; | ||
| 99 | |||
| 56 | struct efi_uga_draw_protocol { | 100 | struct efi_uga_draw_protocol { |
| 57 | void *get_mode; | 101 | void *get_mode; |
| 58 | void *set_mode; | 102 | void *set_mode; |
| 59 | void *blt; | 103 | void *blt; |
| 60 | }; | 104 | }; |
| 61 | 105 | ||
| 106 | struct efi_config { | ||
| 107 | u64 image_handle; | ||
| 108 | u64 table; | ||
| 109 | u64 allocate_pool; | ||
| 110 | u64 allocate_pages; | ||
| 111 | u64 get_memory_map; | ||
| 112 | u64 free_pool; | ||
| 113 | u64 free_pages; | ||
| 114 | u64 locate_handle; | ||
| 115 | u64 handle_protocol; | ||
| 116 | u64 exit_boot_services; | ||
| 117 | u64 text_output; | ||
| 118 | efi_status_t (*call)(unsigned long, ...); | ||
| 119 | bool is64; | ||
| 120 | } __packed; | ||
| 121 | |||
| 62 | #endif /* BOOT_COMPRESSED_EBOOT_H */ | 122 | #endif /* BOOT_COMPRESSED_EBOOT_H */ |
diff --git a/arch/x86/boot/compressed/efi_stub_64.S b/arch/x86/boot/compressed/efi_stub_64.S index cedc60de86eb..7ff3632806b1 100644 --- a/arch/x86/boot/compressed/efi_stub_64.S +++ b/arch/x86/boot/compressed/efi_stub_64.S | |||
| @@ -1 +1,30 @@ | |||
| 1 | #include <asm/segment.h> | ||
| 2 | #include <asm/msr.h> | ||
| 3 | #include <asm/processor-flags.h> | ||
| 4 | |||
| 1 | #include "../../platform/efi/efi_stub_64.S" | 5 | #include "../../platform/efi/efi_stub_64.S" |
| 6 | |||
| 7 | #ifdef CONFIG_EFI_MIXED | ||
| 8 | .code64 | ||
| 9 | .text | ||
| 10 | ENTRY(efi64_thunk) | ||
| 11 | push %rbp | ||
| 12 | push %rbx | ||
| 13 | |||
| 14 | subq $16, %rsp | ||
| 15 | leaq efi_exit32(%rip), %rax | ||
| 16 | movl %eax, 8(%rsp) | ||
| 17 | leaq efi_gdt64(%rip), %rax | ||
| 18 | movl %eax, 4(%rsp) | ||
| 19 | movl %eax, 2(%rax) /* Fixup the gdt base address */ | ||
| 20 | leaq efi32_boot_gdt(%rip), %rax | ||
| 21 | movl %eax, (%rsp) | ||
| 22 | |||
| 23 | call __efi64_thunk | ||
| 24 | |||
| 25 | addq $16, %rsp | ||
| 26 | pop %rbx | ||
| 27 | pop %rbp | ||
| 28 | ret | ||
| 29 | ENDPROC(efi64_thunk) | ||
| 30 | #endif /* CONFIG_EFI_MIXED */ | ||
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 9116aac232c7..cccc05f0681c 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S | |||
| @@ -42,26 +42,53 @@ ENTRY(startup_32) | |||
| 42 | ENTRY(efi_pe_entry) | 42 | ENTRY(efi_pe_entry) |
| 43 | add $0x4, %esp | 43 | add $0x4, %esp |
| 44 | 44 | ||
| 45 | call 1f | ||
| 46 | 1: popl %esi | ||
| 47 | subl $1b, %esi | ||
| 48 | |||
| 49 | popl %ecx | ||
| 50 | movl %ecx, efi32_config(%esi) /* Handle */ | ||
| 51 | popl %ecx | ||
| 52 | movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */ | ||
| 53 | |||
| 54 | /* Relocate efi_config->call() */ | ||
| 55 | leal efi32_config(%esi), %eax | ||
| 56 | add %esi, 88(%eax) | ||
| 57 | pushl %eax | ||
| 58 | |||
| 45 | call make_boot_params | 59 | call make_boot_params |
| 46 | cmpl $0, %eax | 60 | cmpl $0, %eax |
| 47 | je 1f | 61 | je fail |
| 48 | movl 0x4(%esp), %esi | 62 | popl %ecx |
| 49 | movl (%esp), %ecx | ||
| 50 | pushl %eax | 63 | pushl %eax |
| 51 | pushl %esi | ||
| 52 | pushl %ecx | 64 | pushl %ecx |
| 53 | sub $0x4, %esp | 65 | jmp 2f /* Skip efi_config initialization */ |
| 54 | 66 | ||
| 55 | ENTRY(efi_stub_entry) | 67 | ENTRY(efi32_stub_entry) |
| 56 | add $0x4, %esp | 68 | add $0x4, %esp |
| 69 | popl %ecx | ||
| 70 | popl %edx | ||
| 71 | |||
| 72 | call 1f | ||
| 73 | 1: popl %esi | ||
| 74 | subl $1b, %esi | ||
| 75 | |||
| 76 | movl %ecx, efi32_config(%esi) /* Handle */ | ||
| 77 | movl %edx, efi32_config+8(%esi) /* EFI System table pointer */ | ||
| 78 | |||
| 79 | /* Relocate efi_config->call() */ | ||
| 80 | leal efi32_config(%esi), %eax | ||
| 81 | add %esi, 88(%eax) | ||
| 82 | pushl %eax | ||
| 83 | 2: | ||
| 57 | call efi_main | 84 | call efi_main |
| 58 | cmpl $0, %eax | 85 | cmpl $0, %eax |
| 59 | movl %eax, %esi | 86 | movl %eax, %esi |
| 60 | jne 2f | 87 | jne 2f |
| 61 | 1: | 88 | fail: |
| 62 | /* EFI init failed, so hang. */ | 89 | /* EFI init failed, so hang. */ |
| 63 | hlt | 90 | hlt |
| 64 | jmp 1b | 91 | jmp fail |
| 65 | 2: | 92 | 2: |
| 66 | call 3f | 93 | call 3f |
| 67 | 3: | 94 | 3: |
| @@ -202,6 +229,13 @@ relocated: | |||
| 202 | xorl %ebx, %ebx | 229 | xorl %ebx, %ebx |
| 203 | jmp *%eax | 230 | jmp *%eax |
| 204 | 231 | ||
| 232 | .data | ||
| 233 | efi32_config: | ||
| 234 | .fill 11,8,0 | ||
| 235 | .long efi_call_phys | ||
| 236 | .long 0 | ||
| 237 | .byte 0 | ||
| 238 | |||
| 205 | /* | 239 | /* |
| 206 | * Stack and heap for uncompression | 240 | * Stack and heap for uncompression |
| 207 | */ | 241 | */ |
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index c5c1ae0997e7..4f40cddd025d 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S | |||
| @@ -113,7 +113,8 @@ ENTRY(startup_32) | |||
| 113 | lgdt gdt(%ebp) | 113 | lgdt gdt(%ebp) |
| 114 | 114 | ||
| 115 | /* Enable PAE mode */ | 115 | /* Enable PAE mode */ |
| 116 | movl $(X86_CR4_PAE), %eax | 116 | movl %cr4, %eax |
| 117 | orl $X86_CR4_PAE, %eax | ||
| 117 | movl %eax, %cr4 | 118 | movl %eax, %cr4 |
| 118 | 119 | ||
| 119 | /* | 120 | /* |
| @@ -178,6 +179,13 @@ ENTRY(startup_32) | |||
| 178 | */ | 179 | */ |
| 179 | pushl $__KERNEL_CS | 180 | pushl $__KERNEL_CS |
| 180 | leal startup_64(%ebp), %eax | 181 | leal startup_64(%ebp), %eax |
| 182 | #ifdef CONFIG_EFI_MIXED | ||
| 183 | movl efi32_config(%ebp), %ebx | ||
| 184 | cmp $0, %ebx | ||
| 185 | jz 1f | ||
| 186 | leal handover_entry(%ebp), %eax | ||
| 187 | 1: | ||
| 188 | #endif | ||
| 181 | pushl %eax | 189 | pushl %eax |
| 182 | 190 | ||
| 183 | /* Enter paged protected Mode, activating Long Mode */ | 191 | /* Enter paged protected Mode, activating Long Mode */ |
| @@ -188,6 +196,30 @@ ENTRY(startup_32) | |||
| 188 | lret | 196 | lret |
| 189 | ENDPROC(startup_32) | 197 | ENDPROC(startup_32) |
| 190 | 198 | ||
| 199 | #ifdef CONFIG_EFI_MIXED | ||
| 200 | .org 0x190 | ||
| 201 | ENTRY(efi32_stub_entry) | ||
| 202 | add $0x4, %esp /* Discard return address */ | ||
| 203 | popl %ecx | ||
| 204 | popl %edx | ||
| 205 | popl %esi | ||
| 206 | |||
| 207 | leal (BP_scratch+4)(%esi), %esp | ||
| 208 | call 1f | ||
| 209 | 1: pop %ebp | ||
| 210 | subl $1b, %ebp | ||
| 211 | |||
| 212 | movl %ecx, efi32_config(%ebp) | ||
| 213 | movl %edx, efi32_config+8(%ebp) | ||
| 214 | sgdtl efi32_boot_gdt(%ebp) | ||
| 215 | |||
| 216 | leal efi32_config(%ebp), %eax | ||
| 217 | movl %eax, efi_config(%ebp) | ||
| 218 | |||
| 219 | jmp startup_32 | ||
| 220 | ENDPROC(efi32_stub_entry) | ||
| 221 | #endif | ||
| 222 | |||
| 191 | .code64 | 223 | .code64 |
| 192 | .org 0x200 | 224 | .org 0x200 |
| 193 | ENTRY(startup_64) | 225 | ENTRY(startup_64) |
| @@ -209,26 +241,48 @@ ENTRY(startup_64) | |||
| 209 | jmp preferred_addr | 241 | jmp preferred_addr |
| 210 | 242 | ||
| 211 | ENTRY(efi_pe_entry) | 243 | ENTRY(efi_pe_entry) |
| 212 | mov %rcx, %rdi | 244 | movq %rcx, efi64_config(%rip) /* Handle */ |
| 213 | mov %rdx, %rsi | 245 | movq %rdx, efi64_config+8(%rip) /* EFI System table pointer */ |
| 214 | pushq %rdi | 246 | |
| 215 | pushq %rsi | 247 | leaq efi64_config(%rip), %rax |
| 248 | movq %rax, efi_config(%rip) | ||
| 249 | |||
| 250 | call 1f | ||
| 251 | 1: popq %rbp | ||
| 252 | subq $1b, %rbp | ||
| 253 | |||
| 254 | /* | ||
| 255 | * Relocate efi_config->call(). | ||
| 256 | */ | ||
| 257 | addq %rbp, efi64_config+88(%rip) | ||
| 258 | |||
| 259 | movq %rax, %rdi | ||
| 216 | call make_boot_params | 260 | call make_boot_params |
| 217 | cmpq $0,%rax | 261 | cmpq $0,%rax |
| 218 | je 1f | 262 | je fail |
| 219 | mov %rax, %rdx | 263 | mov %rax, %rsi |
| 220 | popq %rsi | 264 | jmp 2f /* Skip the relocation */ |
| 221 | popq %rdi | ||
| 222 | 265 | ||
| 223 | ENTRY(efi_stub_entry) | 266 | handover_entry: |
| 267 | call 1f | ||
| 268 | 1: popq %rbp | ||
| 269 | subq $1b, %rbp | ||
| 270 | |||
| 271 | /* | ||
| 272 | * Relocate efi_config->call(). | ||
| 273 | */ | ||
| 274 | movq efi_config(%rip), %rax | ||
| 275 | addq %rbp, 88(%rax) | ||
| 276 | 2: | ||
| 277 | movq efi_config(%rip), %rdi | ||
| 224 | call efi_main | 278 | call efi_main |
| 225 | movq %rax,%rsi | 279 | movq %rax,%rsi |
| 226 | cmpq $0,%rax | 280 | cmpq $0,%rax |
| 227 | jne 2f | 281 | jne 2f |
| 228 | 1: | 282 | fail: |
| 229 | /* EFI init failed, so hang. */ | 283 | /* EFI init failed, so hang. */ |
| 230 | hlt | 284 | hlt |
| 231 | jmp 1b | 285 | jmp fail |
| 232 | 2: | 286 | 2: |
| 233 | call 3f | 287 | call 3f |
| 234 | 3: | 288 | 3: |
| @@ -307,6 +361,20 @@ preferred_addr: | |||
| 307 | leaq relocated(%rbx), %rax | 361 | leaq relocated(%rbx), %rax |
| 308 | jmp *%rax | 362 | jmp *%rax |
| 309 | 363 | ||
| 364 | #ifdef CONFIG_EFI_STUB | ||
| 365 | .org 0x390 | ||
| 366 | ENTRY(efi64_stub_entry) | ||
| 367 | movq %rdi, efi64_config(%rip) /* Handle */ | ||
| 368 | movq %rsi, efi64_config+8(%rip) /* EFI System table pointer */ | ||
| 369 | |||
| 370 | leaq efi64_config(%rip), %rax | ||
| 371 | movq %rax, efi_config(%rip) | ||
| 372 | |||
| 373 | movq %rdx, %rsi | ||
| 374 | jmp handover_entry | ||
| 375 | ENDPROC(efi64_stub_entry) | ||
| 376 | #endif | ||
| 377 | |||
| 310 | .text | 378 | .text |
| 311 | relocated: | 379 | relocated: |
| 312 | 380 | ||
| @@ -372,6 +440,22 @@ gdt: | |||
| 372 | .quad 0x0000000000000000 /* TS continued */ | 440 | .quad 0x0000000000000000 /* TS continued */ |
| 373 | gdt_end: | 441 | gdt_end: |
| 374 | 442 | ||
| 443 | efi_config: | ||
| 444 | .quad 0 | ||
| 445 | |||
| 446 | #ifdef CONFIG_EFI_MIXED | ||
| 447 | .global efi32_config | ||
| 448 | efi32_config: | ||
| 449 | .fill 11,8,0 | ||
| 450 | .quad efi64_thunk | ||
| 451 | .byte 0 | ||
| 452 | #endif | ||
| 453 | |||
| 454 | .global efi64_config | ||
| 455 | efi64_config: | ||
| 456 | .fill 11,8,0 | ||
| 457 | .quad efi_call6 | ||
| 458 | .byte 1 | ||
| 375 | /* | 459 | /* |
| 376 | * Stack and heap for uncompression | 460 | * Stack and heap for uncompression |
| 377 | */ | 461 | */ |
diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index ec3b8ba68096..256388260c88 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S | |||
| @@ -283,7 +283,7 @@ _start: | |||
| 283 | # Part 2 of the header, from the old setup.S | 283 | # Part 2 of the header, from the old setup.S |
| 284 | 284 | ||
| 285 | .ascii "HdrS" # header signature | 285 | .ascii "HdrS" # header signature |
| 286 | .word 0x020c # header version number (>= 0x0105) | 286 | .word 0x020d # header version number (>= 0x0105) |
| 287 | # or else old loadlin-1.5 will fail) | 287 | # or else old loadlin-1.5 will fail) |
| 288 | .globl realmode_swtch | 288 | .globl realmode_swtch |
| 289 | realmode_swtch: .word 0, 0 # default_switch, SETUPSEG | 289 | realmode_swtch: .word 0, 0 # default_switch, SETUPSEG |
| @@ -375,7 +375,8 @@ xloadflags: | |||
| 375 | # define XLF0 0 | 375 | # define XLF0 0 |
| 376 | #endif | 376 | #endif |
| 377 | 377 | ||
| 378 | #if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64) | 378 | #if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64) && \ |
| 379 | !defined(CONFIG_EFI_MIXED) | ||
| 379 | /* kernel/boot_param/ramdisk could be loaded above 4g */ | 380 | /* kernel/boot_param/ramdisk could be loaded above 4g */ |
| 380 | # define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G | 381 | # define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G |
| 381 | #else | 382 | #else |
| @@ -383,10 +384,14 @@ xloadflags: | |||
| 383 | #endif | 384 | #endif |
| 384 | 385 | ||
| 385 | #ifdef CONFIG_EFI_STUB | 386 | #ifdef CONFIG_EFI_STUB |
| 386 | # ifdef CONFIG_X86_64 | 387 | # ifdef CONFIG_EFI_MIXED |
| 387 | # define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */ | 388 | # define XLF23 (XLF_EFI_HANDOVER_32|XLF_EFI_HANDOVER_64) |
| 388 | # else | 389 | # else |
| 389 | # define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */ | 390 | # ifdef CONFIG_X86_64 |
| 391 | # define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */ | ||
| 392 | # else | ||
| 393 | # define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */ | ||
| 394 | # endif | ||
| 390 | # endif | 395 | # endif |
| 391 | #else | 396 | #else |
| 392 | # define XLF23 0 | 397 | # define XLF23 0 |
| @@ -426,13 +431,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr | |||
| 426 | #define INIT_SIZE VO_INIT_SIZE | 431 | #define INIT_SIZE VO_INIT_SIZE |
| 427 | #endif | 432 | #endif |
| 428 | init_size: .long INIT_SIZE # kernel initialization size | 433 | init_size: .long INIT_SIZE # kernel initialization size |
| 429 | handover_offset: | 434 | handover_offset: .long 0 # Filled in by build.c |
| 430 | #ifdef CONFIG_EFI_STUB | ||
| 431 | .long 0x30 # offset to the handover | ||
| 432 | # protocol entry point | ||
| 433 | #else | ||
| 434 | .long 0 | ||
| 435 | #endif | ||
| 436 | 435 | ||
| 437 | # End of setup header ##################################################### | 436 | # End of setup header ##################################################### |
| 438 | 437 | ||
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 8e15b22391fc..4f07df5ac5d9 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c | |||
| @@ -53,7 +53,8 @@ int is_big_kernel; | |||
| 53 | 53 | ||
| 54 | #define PECOFF_RELOC_RESERVE 0x20 | 54 | #define PECOFF_RELOC_RESERVE 0x20 |
| 55 | 55 | ||
| 56 | unsigned long efi_stub_entry; | 56 | unsigned long efi32_stub_entry; |
| 57 | unsigned long efi64_stub_entry; | ||
| 57 | unsigned long efi_pe_entry; | 58 | unsigned long efi_pe_entry; |
| 58 | unsigned long startup_64; | 59 | unsigned long startup_64; |
| 59 | 60 | ||
| @@ -219,6 +220,51 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz) | |||
| 219 | update_pecoff_section_header(".text", text_start, text_sz); | 220 | update_pecoff_section_header(".text", text_start, text_sz); |
| 220 | } | 221 | } |
| 221 | 222 | ||
| 223 | static int reserve_pecoff_reloc_section(int c) | ||
| 224 | { | ||
| 225 | /* Reserve 0x20 bytes for .reloc section */ | ||
| 226 | memset(buf+c, 0, PECOFF_RELOC_RESERVE); | ||
| 227 | return PECOFF_RELOC_RESERVE; | ||
| 228 | } | ||
| 229 | |||
| 230 | static void efi_stub_defaults(void) | ||
| 231 | { | ||
| 232 | /* Defaults for old kernel */ | ||
| 233 | #ifdef CONFIG_X86_32 | ||
| 234 | efi_pe_entry = 0x10; | ||
| 235 | #else | ||
| 236 | efi_pe_entry = 0x210; | ||
| 237 | startup_64 = 0x200; | ||
| 238 | #endif | ||
| 239 | } | ||
| 240 | |||
| 241 | static void efi_stub_entry_update(void) | ||
| 242 | { | ||
| 243 | unsigned long addr = efi32_stub_entry; | ||
| 244 | |||
| 245 | #ifdef CONFIG_X86_64 | ||
| 246 | /* Yes, this is really how we defined it :( */ | ||
| 247 | addr = efi64_stub_entry - 0x200; | ||
| 248 | #endif | ||
| 249 | |||
| 250 | #ifdef CONFIG_EFI_MIXED | ||
| 251 | if (efi32_stub_entry != addr) | ||
| 252 | die("32-bit and 64-bit EFI entry points do not match\n"); | ||
| 253 | #endif | ||
| 254 | put_unaligned_le32(addr, &buf[0x264]); | ||
| 255 | } | ||
| 256 | |||
| 257 | #else | ||
| 258 | |||
| 259 | static inline void update_pecoff_setup_and_reloc(unsigned int) {} | ||
| 260 | static inline void update_pecoff_text(unsigned int, unsigned int) {} | ||
| 261 | static inline void efi_stub_defaults(void) {} | ||
| 262 | static inline void efi_stup_entry_update(void) {} | ||
| 263 | |||
| 264 | static inline int reserve_pecoff_reloc_section(int c) | ||
| 265 | { | ||
| 266 | return 0; | ||
| 267 | } | ||
| 222 | #endif /* CONFIG_EFI_STUB */ | 268 | #endif /* CONFIG_EFI_STUB */ |
| 223 | 269 | ||
| 224 | 270 | ||
| @@ -250,7 +296,8 @@ static void parse_zoffset(char *fname) | |||
| 250 | p = (char *)buf; | 296 | p = (char *)buf; |
| 251 | 297 | ||
| 252 | while (p && *p) { | 298 | while (p && *p) { |
| 253 | PARSE_ZOFS(p, efi_stub_entry); | 299 | PARSE_ZOFS(p, efi32_stub_entry); |
| 300 | PARSE_ZOFS(p, efi64_stub_entry); | ||
| 254 | PARSE_ZOFS(p, efi_pe_entry); | 301 | PARSE_ZOFS(p, efi_pe_entry); |
| 255 | PARSE_ZOFS(p, startup_64); | 302 | PARSE_ZOFS(p, startup_64); |
| 256 | 303 | ||
| @@ -271,15 +318,7 @@ int main(int argc, char ** argv) | |||
| 271 | void *kernel; | 318 | void *kernel; |
| 272 | u32 crc = 0xffffffffUL; | 319 | u32 crc = 0xffffffffUL; |
| 273 | 320 | ||
| 274 | /* Defaults for old kernel */ | 321 | efi_stub_defaults(); |
| 275 | #ifdef CONFIG_X86_32 | ||
| 276 | efi_pe_entry = 0x10; | ||
| 277 | efi_stub_entry = 0x30; | ||
| 278 | #else | ||
| 279 | efi_pe_entry = 0x210; | ||
| 280 | efi_stub_entry = 0x230; | ||
| 281 | startup_64 = 0x200; | ||
| 282 | #endif | ||
| 283 | 322 | ||
| 284 | if (argc != 5) | 323 | if (argc != 5) |
| 285 | usage(); | 324 | usage(); |
| @@ -302,11 +341,7 @@ int main(int argc, char ** argv) | |||
| 302 | die("Boot block hasn't got boot flag (0xAA55)"); | 341 | die("Boot block hasn't got boot flag (0xAA55)"); |
| 303 | fclose(file); | 342 | fclose(file); |
| 304 | 343 | ||
| 305 | #ifdef CONFIG_EFI_STUB | 344 | c += reserve_pecoff_reloc_section(c); |
| 306 | /* Reserve 0x20 bytes for .reloc section */ | ||
| 307 | memset(buf+c, 0, PECOFF_RELOC_RESERVE); | ||
| 308 | c += PECOFF_RELOC_RESERVE; | ||
| 309 | #endif | ||
| 310 | 345 | ||
| 311 | /* Pad unused space with zeros */ | 346 | /* Pad unused space with zeros */ |
| 312 | setup_sectors = (c + 511) / 512; | 347 | setup_sectors = (c + 511) / 512; |
| @@ -315,9 +350,7 @@ int main(int argc, char ** argv) | |||
| 315 | i = setup_sectors*512; | 350 | i = setup_sectors*512; |
| 316 | memset(buf+c, 0, i-c); | 351 | memset(buf+c, 0, i-c); |
| 317 | 352 | ||
| 318 | #ifdef CONFIG_EFI_STUB | ||
| 319 | update_pecoff_setup_and_reloc(i); | 353 | update_pecoff_setup_and_reloc(i); |
| 320 | #endif | ||
| 321 | 354 | ||
| 322 | /* Set the default root device */ | 355 | /* Set the default root device */ |
| 323 | put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); | 356 | put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); |
| @@ -342,14 +375,9 @@ int main(int argc, char ** argv) | |||
| 342 | buf[0x1f1] = setup_sectors-1; | 375 | buf[0x1f1] = setup_sectors-1; |
| 343 | put_unaligned_le32(sys_size, &buf[0x1f4]); | 376 | put_unaligned_le32(sys_size, &buf[0x1f4]); |
| 344 | 377 | ||
| 345 | #ifdef CONFIG_EFI_STUB | ||
| 346 | update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz)); | 378 | update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz)); |
| 347 | 379 | ||
| 348 | #ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ | 380 | efi_stub_entry_update(); |
| 349 | efi_stub_entry -= 0x200; | ||
| 350 | #endif | ||
| 351 | put_unaligned_le32(efi_stub_entry, &buf[0x264]); | ||
| 352 | #endif | ||
| 353 | 381 | ||
| 354 | crc = partial_crc32(buf, i, crc); | 382 | crc = partial_crc32(buf, i, crc); |
| 355 | if (fwrite(buf, 1, i, dest) != i) | 383 | if (fwrite(buf, 1, i, dest) != i) |
diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 86d1fd4bf24c..0869434eaf72 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h | |||
| @@ -19,9 +19,11 @@ | |||
| 19 | */ | 19 | */ |
| 20 | #define EFI_OLD_MEMMAP EFI_ARCH_1 | 20 | #define EFI_OLD_MEMMAP EFI_ARCH_1 |
| 21 | 21 | ||
| 22 | #define EFI32_LOADER_SIGNATURE "EL32" | ||
| 23 | #define EFI64_LOADER_SIGNATURE "EL64" | ||
| 24 | |||
| 22 | #ifdef CONFIG_X86_32 | 25 | #ifdef CONFIG_X86_32 |
| 23 | 26 | ||
| 24 | #define EFI_LOADER_SIGNATURE "EL32" | ||
| 25 | 27 | ||
| 26 | extern unsigned long asmlinkage efi_call_phys(void *, ...); | 28 | extern unsigned long asmlinkage efi_call_phys(void *, ...); |
| 27 | 29 | ||
| @@ -57,8 +59,6 @@ extern unsigned long asmlinkage efi_call_phys(void *, ...); | |||
| 57 | 59 | ||
| 58 | #else /* !CONFIG_X86_32 */ | 60 | #else /* !CONFIG_X86_32 */ |
| 59 | 61 | ||
| 60 | #define EFI_LOADER_SIGNATURE "EL64" | ||
| 61 | |||
| 62 | extern u64 efi_call0(void *fp); | 62 | extern u64 efi_call0(void *fp); |
| 63 | extern u64 efi_call1(void *fp, u64 arg1); | 63 | extern u64 efi_call1(void *fp, u64 arg1); |
| 64 | extern u64 efi_call2(void *fp, u64 arg1, u64 arg2); | 64 | extern u64 efi_call2(void *fp, u64 arg1, u64 arg2); |
| @@ -154,8 +154,40 @@ static inline bool efi_is_native(void) | |||
| 154 | return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT); | 154 | return IS_ENABLED(CONFIG_X86_64) == efi_enabled(EFI_64BIT); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | static inline bool efi_runtime_supported(void) | ||
| 158 | { | ||
| 159 | if (efi_is_native()) | ||
| 160 | return true; | ||
| 161 | |||
| 162 | if (IS_ENABLED(CONFIG_EFI_MIXED) && !efi_enabled(EFI_OLD_MEMMAP)) | ||
| 163 | return true; | ||
| 164 | |||
| 165 | return false; | ||
| 166 | } | ||
| 167 | |||
| 157 | extern struct console early_efi_console; | 168 | extern struct console early_efi_console; |
| 158 | extern void parse_efi_setup(u64 phys_addr, u32 data_len); | 169 | extern void parse_efi_setup(u64 phys_addr, u32 data_len); |
| 170 | |||
| 171 | #ifdef CONFIG_EFI_MIXED | ||
| 172 | extern void efi_thunk_runtime_setup(void); | ||
| 173 | extern efi_status_t efi_thunk_set_virtual_address_map( | ||
| 174 | void *phys_set_virtual_address_map, | ||
| 175 | unsigned long memory_map_size, | ||
| 176 | unsigned long descriptor_size, | ||
| 177 | u32 descriptor_version, | ||
| 178 | efi_memory_desc_t *virtual_map); | ||
| 179 | #else | ||
| 180 | static inline void efi_thunk_runtime_setup(void) {} | ||
| 181 | static inline efi_status_t efi_thunk_set_virtual_address_map( | ||
| 182 | void *phys_set_virtual_address_map, | ||
| 183 | unsigned long memory_map_size, | ||
| 184 | unsigned long descriptor_size, | ||
| 185 | u32 descriptor_version, | ||
| 186 | efi_memory_desc_t *virtual_map) | ||
| 187 | { | ||
| 188 | return EFI_SUCCESS; | ||
| 189 | } | ||
| 190 | #endif /* CONFIG_EFI_MIXED */ | ||
| 159 | #else | 191 | #else |
| 160 | /* | 192 | /* |
| 161 | * IF EFI is not configured, have the EFI calls return -ENOSYS. | 193 | * IF EFI is not configured, have the EFI calls return -ENOSYS. |
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 94e40f1efdfd..708f19fb4fc7 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h | |||
| @@ -382,6 +382,8 @@ static inline void update_page_count(int level, unsigned long pages) { } | |||
| 382 | * as a pte too. | 382 | * as a pte too. |
| 383 | */ | 383 | */ |
| 384 | extern pte_t *lookup_address(unsigned long address, unsigned int *level); | 384 | extern pte_t *lookup_address(unsigned long address, unsigned int *level); |
| 385 | extern pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, | ||
| 386 | unsigned int *level); | ||
| 385 | extern phys_addr_t slow_virt_to_phys(void *__address); | 387 | extern phys_addr_t slow_virt_to_phys(void *__address); |
| 386 | extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address, | 388 | extern int kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address, |
| 387 | unsigned numpages, unsigned long page_flags); | 389 | unsigned numpages, unsigned long page_flags); |
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index e7fa28bf3262..a92c4c999787 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c | |||
| @@ -584,8 +584,13 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code, | |||
| 584 | 584 | ||
| 585 | if (error_code & PF_INSTR) { | 585 | if (error_code & PF_INSTR) { |
| 586 | unsigned int level; | 586 | unsigned int level; |
| 587 | pgd_t *pgd; | ||
| 588 | pte_t *pte; | ||
| 587 | 589 | ||
| 588 | pte_t *pte = lookup_address(address, &level); | 590 | pgd = __va(read_cr3() & PHYSICAL_PAGE_MASK); |
| 591 | pgd += pgd_index(address); | ||
| 592 | |||
| 593 | pte = lookup_address_in_pgd(pgd, address, &level); | ||
| 589 | 594 | ||
| 590 | if (pte && pte_present(*pte) && !pte_exec(*pte)) | 595 | if (pte && pte_present(*pte) && !pte_exec(*pte)) |
| 591 | printk(nx_warning, from_kuid(&init_user_ns, current_uid())); | 596 | printk(nx_warning, from_kuid(&init_user_ns, current_uid())); |
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c index a3488689e301..1585da3b9b85 100644 --- a/arch/x86/mm/pageattr.c +++ b/arch/x86/mm/pageattr.c | |||
| @@ -323,8 +323,12 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address, | |||
| 323 | return prot; | 323 | return prot; |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | static pte_t *__lookup_address_in_pgd(pgd_t *pgd, unsigned long address, | 326 | /* |
| 327 | unsigned int *level) | 327 | * Lookup the page table entry for a virtual address in a specific pgd. |
| 328 | * Return a pointer to the entry and the level of the mapping. | ||
| 329 | */ | ||
| 330 | pte_t *lookup_address_in_pgd(pgd_t *pgd, unsigned long address, | ||
| 331 | unsigned int *level) | ||
| 328 | { | 332 | { |
| 329 | pud_t *pud; | 333 | pud_t *pud; |
| 330 | pmd_t *pmd; | 334 | pmd_t *pmd; |
| @@ -365,7 +369,7 @@ static pte_t *__lookup_address_in_pgd(pgd_t *pgd, unsigned long address, | |||
| 365 | */ | 369 | */ |
| 366 | pte_t *lookup_address(unsigned long address, unsigned int *level) | 370 | pte_t *lookup_address(unsigned long address, unsigned int *level) |
| 367 | { | 371 | { |
| 368 | return __lookup_address_in_pgd(pgd_offset_k(address), address, level); | 372 | return lookup_address_in_pgd(pgd_offset_k(address), address, level); |
| 369 | } | 373 | } |
| 370 | EXPORT_SYMBOL_GPL(lookup_address); | 374 | EXPORT_SYMBOL_GPL(lookup_address); |
| 371 | 375 | ||
| @@ -373,7 +377,7 @@ static pte_t *_lookup_address_cpa(struct cpa_data *cpa, unsigned long address, | |||
| 373 | unsigned int *level) | 377 | unsigned int *level) |
| 374 | { | 378 | { |
| 375 | if (cpa->pgd) | 379 | if (cpa->pgd) |
| 376 | return __lookup_address_in_pgd(cpa->pgd + pgd_index(address), | 380 | return lookup_address_in_pgd(cpa->pgd + pgd_index(address), |
| 377 | address, level); | 381 | address, level); |
| 378 | 382 | ||
| 379 | return lookup_address(address, level); | 383 | return lookup_address(address, level); |
diff --git a/arch/x86/platform/efi/Makefile b/arch/x86/platform/efi/Makefile index b7b0b35c1981..d51045afcaaf 100644 --- a/arch/x86/platform/efi/Makefile +++ b/arch/x86/platform/efi/Makefile | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o | 1 | obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o |
| 2 | obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o | 2 | obj-$(CONFIG_ACPI_BGRT) += efi-bgrt.o |
| 3 | obj-$(CONFIG_EARLY_PRINTK_EFI) += early_printk.o | 3 | obj-$(CONFIG_EARLY_PRINTK_EFI) += early_printk.o |
| 4 | obj-$(CONFIG_EFI_MIXED) += efi_thunk_$(BITS).o | ||
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index 45d4f7674678..43e7cf6c6111 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c | |||
| @@ -453,9 +453,6 @@ void __init efi_free_boot_services(void) | |||
| 453 | { | 453 | { |
| 454 | void *p; | 454 | void *p; |
| 455 | 455 | ||
| 456 | if (!efi_is_native()) | ||
| 457 | return; | ||
| 458 | |||
| 459 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { | 456 | for (p = memmap.map; p < memmap.map_end; p += memmap.desc_size) { |
| 460 | efi_memory_desc_t *md = p; | 457 | efi_memory_desc_t *md = p; |
| 461 | unsigned long long start = md->phys_addr; | 458 | unsigned long long start = md->phys_addr; |
| @@ -579,37 +576,85 @@ static int __init efi_systab_init(void *phys) | |||
| 579 | return 0; | 576 | return 0; |
| 580 | } | 577 | } |
| 581 | 578 | ||
| 582 | static int __init efi_runtime_init(void) | 579 | static int __init efi_runtime_init32(void) |
| 583 | { | 580 | { |
| 584 | efi_runtime_services_t *runtime; | 581 | efi_runtime_services_32_t *runtime; |
| 582 | |||
| 583 | runtime = early_ioremap((unsigned long)efi.systab->runtime, | ||
| 584 | sizeof(efi_runtime_services_32_t)); | ||
| 585 | if (!runtime) { | ||
| 586 | pr_err("Could not map the runtime service table!\n"); | ||
| 587 | return -ENOMEM; | ||
| 588 | } | ||
| 585 | 589 | ||
| 586 | /* | 590 | /* |
| 587 | * Check out the runtime services table. We need to map | 591 | * We will only need *early* access to the following two |
| 588 | * the runtime services table so that we can grab the physical | 592 | * EFI runtime services before set_virtual_address_map |
| 589 | * address of several of the EFI runtime functions, needed to | 593 | * is invoked. |
| 590 | * set the firmware into virtual mode. | 594 | */ |
| 595 | efi_phys.get_time = (efi_get_time_t *) | ||
| 596 | (unsigned long)runtime->get_time; | ||
| 597 | efi_phys.set_virtual_address_map = | ||
| 598 | (efi_set_virtual_address_map_t *) | ||
| 599 | (unsigned long)runtime->set_virtual_address_map; | ||
| 600 | /* | ||
| 601 | * Make efi_get_time can be called before entering | ||
| 602 | * virtual mode. | ||
| 591 | */ | 603 | */ |
| 604 | efi.get_time = phys_efi_get_time; | ||
| 605 | early_iounmap(runtime, sizeof(efi_runtime_services_32_t)); | ||
| 606 | |||
| 607 | return 0; | ||
| 608 | } | ||
| 609 | |||
| 610 | static int __init efi_runtime_init64(void) | ||
| 611 | { | ||
| 612 | efi_runtime_services_64_t *runtime; | ||
| 613 | |||
| 592 | runtime = early_ioremap((unsigned long)efi.systab->runtime, | 614 | runtime = early_ioremap((unsigned long)efi.systab->runtime, |
| 593 | sizeof(efi_runtime_services_t)); | 615 | sizeof(efi_runtime_services_64_t)); |
| 594 | if (!runtime) { | 616 | if (!runtime) { |
| 595 | pr_err("Could not map the runtime service table!\n"); | 617 | pr_err("Could not map the runtime service table!\n"); |
| 596 | return -ENOMEM; | 618 | return -ENOMEM; |
| 597 | } | 619 | } |
| 620 | |||
| 598 | /* | 621 | /* |
| 599 | * We will only need *early* access to the following | 622 | * We will only need *early* access to the following two |
| 600 | * two EFI runtime services before set_virtual_address_map | 623 | * EFI runtime services before set_virtual_address_map |
| 601 | * is invoked. | 624 | * is invoked. |
| 602 | */ | 625 | */ |
| 603 | efi_phys.get_time = (efi_get_time_t *)runtime->get_time; | 626 | efi_phys.get_time = (efi_get_time_t *) |
| 627 | (unsigned long)runtime->get_time; | ||
| 604 | efi_phys.set_virtual_address_map = | 628 | efi_phys.set_virtual_address_map = |
| 605 | (efi_set_virtual_address_map_t *) | 629 | (efi_set_virtual_address_map_t *) |
| 606 | runtime->set_virtual_address_map; | 630 | (unsigned long)runtime->set_virtual_address_map; |
| 607 | /* | 631 | /* |
| 608 | * Make efi_get_time can be called before entering | 632 | * Make efi_get_time can be called before entering |
| 609 | * virtual mode. | 633 | * virtual mode. |
| 610 | */ | 634 | */ |
| 611 | efi.get_time = phys_efi_get_time; | 635 | efi.get_time = phys_efi_get_time; |
| 612 | early_iounmap(runtime, sizeof(efi_runtime_services_t)); | 636 | early_iounmap(runtime, sizeof(efi_runtime_services_64_t)); |
| 637 | |||
| 638 | return 0; | ||
| 639 | } | ||
| 640 | |||
| 641 | static int __init efi_runtime_init(void) | ||
| 642 | { | ||
| 643 | int rv; | ||
| 644 | |||
| 645 | /* | ||
| 646 | * Check out the runtime services table. We need to map | ||
| 647 | * the runtime services table so that we can grab the physical | ||
| 648 | * address of several of the EFI runtime functions, needed to | ||
| 649 | * set the firmware into virtual mode. | ||
| 650 | */ | ||
| 651 | if (efi_enabled(EFI_64BIT)) | ||
| 652 | rv = efi_runtime_init64(); | ||
| 653 | else | ||
| 654 | rv = efi_runtime_init32(); | ||
| 655 | |||
| 656 | if (rv) | ||
| 657 | return rv; | ||
| 613 | 658 | ||
| 614 | set_bit(EFI_RUNTIME_SERVICES, &efi.flags); | 659 | set_bit(EFI_RUNTIME_SERVICES, &efi.flags); |
| 615 | 660 | ||
| @@ -747,7 +792,7 @@ void __init efi_init(void) | |||
| 747 | * that doesn't match the kernel 32/64-bit mode. | 792 | * that doesn't match the kernel 32/64-bit mode. |
| 748 | */ | 793 | */ |
| 749 | 794 | ||
| 750 | if (!efi_is_native()) | 795 | if (!efi_runtime_supported()) |
| 751 | pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n"); | 796 | pr_info("No EFI runtime due to 32/64-bit mismatch with kernel\n"); |
| 752 | else { | 797 | else { |
| 753 | if (disable_runtime || efi_runtime_init()) | 798 | if (disable_runtime || efi_runtime_init()) |
| @@ -833,6 +878,22 @@ void __init old_map_region(efi_memory_desc_t *md) | |||
| 833 | (unsigned long long)md->phys_addr); | 878 | (unsigned long long)md->phys_addr); |
| 834 | } | 879 | } |
| 835 | 880 | ||
| 881 | static void native_runtime_setup(void) | ||
| 882 | { | ||
| 883 | efi.get_time = virt_efi_get_time; | ||
| 884 | efi.set_time = virt_efi_set_time; | ||
| 885 | efi.get_wakeup_time = virt_efi_get_wakeup_time; | ||
| 886 | efi.set_wakeup_time = virt_efi_set_wakeup_time; | ||
| 887 | efi.get_variable = virt_efi_get_variable; | ||
| 888 | efi.get_next_variable = virt_efi_get_next_variable; | ||
| 889 | efi.set_variable = virt_efi_set_variable; | ||
| 890 | efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; | ||
| 891 | efi.reset_system = virt_efi_reset_system; | ||
| 892 | efi.query_variable_info = virt_efi_query_variable_info; | ||
| 893 | efi.update_capsule = virt_efi_update_capsule; | ||
| 894 | efi.query_capsule_caps = virt_efi_query_capsule_caps; | ||
| 895 | } | ||
| 896 | |||
| 836 | /* Merge contiguous regions of the same type and attribute */ | 897 | /* Merge contiguous regions of the same type and attribute */ |
| 837 | static void __init efi_merge_regions(void) | 898 | static void __init efi_merge_regions(void) |
| 838 | { | 899 | { |
| @@ -1015,19 +1076,10 @@ static void __init kexec_enter_virtual_mode(void) | |||
| 1015 | * Call EFI services through wrapper functions. | 1076 | * Call EFI services through wrapper functions. |
| 1016 | */ | 1077 | */ |
| 1017 | efi.runtime_version = efi_systab.hdr.revision; | 1078 | efi.runtime_version = efi_systab.hdr.revision; |
| 1018 | efi.get_time = virt_efi_get_time; | 1079 | |
| 1019 | efi.set_time = virt_efi_set_time; | 1080 | native_runtime_setup(); |
| 1020 | efi.get_wakeup_time = virt_efi_get_wakeup_time; | 1081 | |
| 1021 | efi.set_wakeup_time = virt_efi_set_wakeup_time; | ||
| 1022 | efi.get_variable = virt_efi_get_variable; | ||
| 1023 | efi.get_next_variable = virt_efi_get_next_variable; | ||
| 1024 | efi.set_variable = virt_efi_set_variable; | ||
| 1025 | efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; | ||
| 1026 | efi.reset_system = virt_efi_reset_system; | ||
| 1027 | efi.set_virtual_address_map = NULL; | 1082 | efi.set_virtual_address_map = NULL; |
| 1028 | efi.query_variable_info = virt_efi_query_variable_info; | ||
| 1029 | efi.update_capsule = virt_efi_update_capsule; | ||
| 1030 | efi.query_capsule_caps = virt_efi_query_capsule_caps; | ||
| 1031 | 1083 | ||
| 1032 | if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX)) | 1084 | if (efi_enabled(EFI_OLD_MEMMAP) && (__supported_pte_mask & _PAGE_NX)) |
| 1033 | runtime_code_page_mkexec(); | 1085 | runtime_code_page_mkexec(); |
| @@ -1071,15 +1123,6 @@ static void __init __efi_enter_virtual_mode(void) | |||
| 1071 | 1123 | ||
| 1072 | efi.systab = NULL; | 1124 | efi.systab = NULL; |
| 1073 | 1125 | ||
| 1074 | /* | ||
| 1075 | * We don't do virtual mode, since we don't do runtime services, on | ||
| 1076 | * non-native EFI | ||
| 1077 | */ | ||
| 1078 | if (!efi_is_native()) { | ||
| 1079 | efi_unmap_memmap(); | ||
| 1080 | return; | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | efi_merge_regions(); | 1126 | efi_merge_regions(); |
| 1084 | new_memmap = efi_map_regions(&count, &pg_shift); | 1127 | new_memmap = efi_map_regions(&count, &pg_shift); |
| 1085 | if (!new_memmap) { | 1128 | if (!new_memmap) { |
| @@ -1097,11 +1140,20 @@ static void __init __efi_enter_virtual_mode(void) | |||
| 1097 | efi_sync_low_kernel_mappings(); | 1140 | efi_sync_low_kernel_mappings(); |
| 1098 | efi_dump_pagetable(); | 1141 | efi_dump_pagetable(); |
| 1099 | 1142 | ||
| 1100 | status = phys_efi_set_virtual_address_map( | 1143 | if (efi_is_native()) { |
| 1101 | memmap.desc_size * count, | 1144 | status = phys_efi_set_virtual_address_map( |
| 1102 | memmap.desc_size, | 1145 | memmap.desc_size * count, |
| 1103 | memmap.desc_version, | 1146 | memmap.desc_size, |
| 1104 | (efi_memory_desc_t *)__pa(new_memmap)); | 1147 | memmap.desc_version, |
| 1148 | (efi_memory_desc_t *)__pa(new_memmap)); | ||
| 1149 | } else { | ||
| 1150 | status = efi_thunk_set_virtual_address_map( | ||
| 1151 | efi_phys.set_virtual_address_map, | ||
| 1152 | memmap.desc_size * count, | ||
| 1153 | memmap.desc_size, | ||
| 1154 | memmap.desc_version, | ||
| 1155 | (efi_memory_desc_t *)__pa(new_memmap)); | ||
| 1156 | } | ||
| 1105 | 1157 | ||
| 1106 | if (status != EFI_SUCCESS) { | 1158 | if (status != EFI_SUCCESS) { |
| 1107 | pr_alert("Unable to switch EFI into virtual mode (status=%lx)!\n", | 1159 | pr_alert("Unable to switch EFI into virtual mode (status=%lx)!\n", |
| @@ -1116,19 +1168,13 @@ static void __init __efi_enter_virtual_mode(void) | |||
| 1116 | * Call EFI services through wrapper functions. | 1168 | * Call EFI services through wrapper functions. |
| 1117 | */ | 1169 | */ |
| 1118 | efi.runtime_version = efi_systab.hdr.revision; | 1170 | efi.runtime_version = efi_systab.hdr.revision; |
| 1119 | efi.get_time = virt_efi_get_time; | 1171 | |
| 1120 | efi.set_time = virt_efi_set_time; | 1172 | if (efi_is_native()) |
| 1121 | efi.get_wakeup_time = virt_efi_get_wakeup_time; | 1173 | native_runtime_setup(); |
| 1122 | efi.set_wakeup_time = virt_efi_set_wakeup_time; | 1174 | else |
| 1123 | efi.get_variable = virt_efi_get_variable; | 1175 | efi_thunk_runtime_setup(); |
| 1124 | efi.get_next_variable = virt_efi_get_next_variable; | 1176 | |
| 1125 | efi.set_variable = virt_efi_set_variable; | ||
| 1126 | efi.get_next_high_mono_count = virt_efi_get_next_high_mono_count; | ||
| 1127 | efi.reset_system = virt_efi_reset_system; | ||
| 1128 | efi.set_virtual_address_map = NULL; | 1177 | efi.set_virtual_address_map = NULL; |
| 1129 | efi.query_variable_info = virt_efi_query_variable_info; | ||
| 1130 | efi.update_capsule = virt_efi_update_capsule; | ||
| 1131 | efi.query_capsule_caps = virt_efi_query_capsule_caps; | ||
| 1132 | 1178 | ||
| 1133 | efi_runtime_mkexec(); | 1179 | efi_runtime_mkexec(); |
| 1134 | 1180 | ||
| @@ -1311,7 +1357,7 @@ void __init efi_apply_memmap_quirks(void) | |||
| 1311 | * firmware/kernel architectures since there is no support for runtime | 1357 | * firmware/kernel architectures since there is no support for runtime |
| 1312 | * services. | 1358 | * services. |
| 1313 | */ | 1359 | */ |
| 1314 | if (!efi_is_native()) { | 1360 | if (!efi_runtime_supported()) { |
| 1315 | pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n"); | 1361 | pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n"); |
| 1316 | efi_unmap_memmap(); | 1362 | efi_unmap_memmap(); |
| 1317 | } | 1363 | } |
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index 19280900ec25..7e7f195aa5cf 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c | |||
| @@ -39,6 +39,7 @@ | |||
| 39 | #include <asm/cacheflush.h> | 39 | #include <asm/cacheflush.h> |
| 40 | #include <asm/fixmap.h> | 40 | #include <asm/fixmap.h> |
| 41 | #include <asm/realmode.h> | 41 | #include <asm/realmode.h> |
| 42 | #include <asm/time.h> | ||
| 42 | 43 | ||
| 43 | static pgd_t *save_pgd __initdata; | 44 | static pgd_t *save_pgd __initdata; |
| 44 | static unsigned long efi_flags __initdata; | 45 | static unsigned long efi_flags __initdata; |
| @@ -58,7 +59,8 @@ struct efi_scratch { | |||
| 58 | u64 prev_cr3; | 59 | u64 prev_cr3; |
| 59 | pgd_t *efi_pgt; | 60 | pgd_t *efi_pgt; |
| 60 | bool use_pgd; | 61 | bool use_pgd; |
| 61 | }; | 62 | u64 phys_stack; |
| 63 | } __packed; | ||
| 62 | 64 | ||
| 63 | static void __init early_code_mapping_set_exec(int executable) | 65 | static void __init early_code_mapping_set_exec(int executable) |
| 64 | { | 66 | { |
| @@ -139,6 +141,9 @@ void efi_sync_low_kernel_mappings(void) | |||
| 139 | 141 | ||
| 140 | int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) | 142 | int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) |
| 141 | { | 143 | { |
| 144 | unsigned long text; | ||
| 145 | struct page *page; | ||
| 146 | unsigned npages; | ||
| 142 | pgd_t *pgd; | 147 | pgd_t *pgd; |
| 143 | 148 | ||
| 144 | if (efi_enabled(EFI_OLD_MEMMAP)) | 149 | if (efi_enabled(EFI_OLD_MEMMAP)) |
| @@ -160,6 +165,29 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) | |||
| 160 | 165 | ||
| 161 | efi_scratch.use_pgd = true; | 166 | efi_scratch.use_pgd = true; |
| 162 | 167 | ||
| 168 | /* | ||
| 169 | * When making calls to the firmware everything needs to be 1:1 | ||
| 170 | * mapped and addressable with 32-bit pointers. Map the kernel | ||
| 171 | * text and allocate a new stack because we can't rely on the | ||
| 172 | * stack pointer being < 4GB. | ||
| 173 | */ | ||
| 174 | if (!IS_ENABLED(CONFIG_EFI_MIXED)) | ||
| 175 | return 0; | ||
| 176 | |||
| 177 | page = alloc_page(GFP_KERNEL|__GFP_DMA32); | ||
| 178 | if (!page) | ||
| 179 | panic("Unable to allocate EFI runtime stack < 4GB\n"); | ||
| 180 | |||
| 181 | efi_scratch.phys_stack = virt_to_phys(page_address(page)); | ||
| 182 | efi_scratch.phys_stack += PAGE_SIZE; /* stack grows down */ | ||
| 183 | |||
| 184 | npages = (_end - _text) >> PAGE_SHIFT; | ||
| 185 | text = __pa(_text); | ||
| 186 | |||
| 187 | if (kernel_map_pages_in_pgd(pgd, text >> PAGE_SHIFT, text, npages, 0)) { | ||
| 188 | pr_err("Failed to map kernel text 1:1\n"); | ||
| 189 | return 1; | ||
| 190 | } | ||
| 163 | 191 | ||
| 164 | return 0; | 192 | return 0; |
| 165 | } | 193 | } |
| @@ -199,6 +227,16 @@ void __init efi_map_region(efi_memory_desc_t *md) | |||
| 199 | */ | 227 | */ |
| 200 | __map_region(md, md->phys_addr); | 228 | __map_region(md, md->phys_addr); |
| 201 | 229 | ||
| 230 | /* | ||
| 231 | * Enforce the 1:1 mapping as the default virtual address when | ||
| 232 | * booting in EFI mixed mode, because even though we may be | ||
| 233 | * running a 64-bit kernel, the firmware may only be 32-bit. | ||
| 234 | */ | ||
| 235 | if (!efi_is_native () && IS_ENABLED(CONFIG_EFI_MIXED)) { | ||
| 236 | md->virt_addr = md->phys_addr; | ||
| 237 | return; | ||
| 238 | } | ||
| 239 | |||
| 202 | efi_va -= size; | 240 | efi_va -= size; |
| 203 | 241 | ||
| 204 | /* Is PA 2M-aligned? */ | 242 | /* Is PA 2M-aligned? */ |
| @@ -277,3 +315,290 @@ void __init efi_dump_pagetable(void) | |||
| 277 | ptdump_walk_pgd_level(NULL, pgd); | 315 | ptdump_walk_pgd_level(NULL, pgd); |
| 278 | #endif | 316 | #endif |
| 279 | } | 317 | } |
| 318 | |||
| 319 | #ifdef CONFIG_EFI_MIXED | ||
| 320 | extern efi_status_t efi64_thunk(u32, ...); | ||
| 321 | |||
| 322 | #define runtime_service32(func) \ | ||
| 323 | ({ \ | ||
| 324 | u32 table = (u32)(unsigned long)efi.systab; \ | ||
| 325 | u32 *rt, *___f; \ | ||
| 326 | \ | ||
| 327 | rt = (u32 *)(table + offsetof(efi_system_table_32_t, runtime)); \ | ||
| 328 | ___f = (u32 *)(*rt + offsetof(efi_runtime_services_32_t, func)); \ | ||
| 329 | *___f; \ | ||
| 330 | }) | ||
| 331 | |||
| 332 | /* | ||
| 333 | * Switch to the EFI page tables early so that we can access the 1:1 | ||
| 334 | * runtime services mappings which are not mapped in any other page | ||
| 335 | * tables. This function must be called before runtime_service32(). | ||
| 336 | * | ||
| 337 | * Also, disable interrupts because the IDT points to 64-bit handlers, | ||
| 338 | * which aren't going to function correctly when we switch to 32-bit. | ||
| 339 | */ | ||
| 340 | #define efi_thunk(f, ...) \ | ||
| 341 | ({ \ | ||
| 342 | efi_status_t __s; \ | ||
| 343 | unsigned long flags; \ | ||
| 344 | u32 func; \ | ||
| 345 | \ | ||
| 346 | efi_sync_low_kernel_mappings(); \ | ||
| 347 | local_irq_save(flags); \ | ||
| 348 | \ | ||
| 349 | efi_scratch.prev_cr3 = read_cr3(); \ | ||
| 350 | write_cr3((unsigned long)efi_scratch.efi_pgt); \ | ||
| 351 | __flush_tlb_all(); \ | ||
| 352 | \ | ||
| 353 | func = runtime_service32(f); \ | ||
| 354 | __s = efi64_thunk(func, __VA_ARGS__); \ | ||
| 355 | \ | ||
| 356 | write_cr3(efi_scratch.prev_cr3); \ | ||
| 357 | __flush_tlb_all(); \ | ||
| 358 | local_irq_restore(flags); \ | ||
| 359 | \ | ||
| 360 | __s; \ | ||
| 361 | }) | ||
| 362 | |||
| 363 | efi_status_t efi_thunk_set_virtual_address_map( | ||
| 364 | void *phys_set_virtual_address_map, | ||
| 365 | unsigned long memory_map_size, | ||
| 366 | unsigned long descriptor_size, | ||
| 367 | u32 descriptor_version, | ||
| 368 | efi_memory_desc_t *virtual_map) | ||
| 369 | { | ||
| 370 | efi_status_t status; | ||
| 371 | unsigned long flags; | ||
| 372 | u32 func; | ||
| 373 | |||
| 374 | efi_sync_low_kernel_mappings(); | ||
| 375 | local_irq_save(flags); | ||
| 376 | |||
| 377 | efi_scratch.prev_cr3 = read_cr3(); | ||
| 378 | write_cr3((unsigned long)efi_scratch.efi_pgt); | ||
| 379 | __flush_tlb_all(); | ||
| 380 | |||
| 381 | func = (u32)(unsigned long)phys_set_virtual_address_map; | ||
| 382 | status = efi64_thunk(func, memory_map_size, descriptor_size, | ||
| 383 | descriptor_version, virtual_map); | ||
| 384 | |||
| 385 | write_cr3(efi_scratch.prev_cr3); | ||
| 386 | __flush_tlb_all(); | ||
| 387 | local_irq_restore(flags); | ||
| 388 | |||
| 389 | return status; | ||
| 390 | } | ||
| 391 | |||
| 392 | static efi_status_t efi_thunk_get_time(efi_time_t *tm, efi_time_cap_t *tc) | ||
| 393 | { | ||
| 394 | efi_status_t status; | ||
| 395 | u32 phys_tm, phys_tc; | ||
| 396 | |||
| 397 | spin_lock(&rtc_lock); | ||
| 398 | |||
| 399 | phys_tm = virt_to_phys(tm); | ||
| 400 | phys_tc = virt_to_phys(tc); | ||
| 401 | |||
| 402 | status = efi_thunk(get_time, phys_tm, phys_tc); | ||
| 403 | |||
| 404 | spin_unlock(&rtc_lock); | ||
| 405 | |||
| 406 | return status; | ||
| 407 | } | ||
| 408 | |||
| 409 | static efi_status_t efi_thunk_set_time(efi_time_t *tm) | ||
| 410 | { | ||
| 411 | efi_status_t status; | ||
| 412 | u32 phys_tm; | ||
| 413 | |||
| 414 | spin_lock(&rtc_lock); | ||
| 415 | |||
| 416 | phys_tm = virt_to_phys(tm); | ||
| 417 | |||
| 418 | status = efi_thunk(set_time, phys_tm); | ||
| 419 | |||
| 420 | spin_unlock(&rtc_lock); | ||
| 421 | |||
| 422 | return status; | ||
| 423 | } | ||
| 424 | |||
| 425 | static efi_status_t | ||
| 426 | efi_thunk_get_wakeup_time(efi_bool_t *enabled, efi_bool_t *pending, | ||
| 427 | efi_time_t *tm) | ||
| 428 | { | ||
| 429 | efi_status_t status; | ||
| 430 | u32 phys_enabled, phys_pending, phys_tm; | ||
| 431 | |||
| 432 | spin_lock(&rtc_lock); | ||
| 433 | |||
| 434 | phys_enabled = virt_to_phys(enabled); | ||
| 435 | phys_pending = virt_to_phys(pending); | ||
| 436 | phys_tm = virt_to_phys(tm); | ||
| 437 | |||
| 438 | status = efi_thunk(get_wakeup_time, phys_enabled, | ||
| 439 | phys_pending, phys_tm); | ||
| 440 | |||
| 441 | spin_unlock(&rtc_lock); | ||
| 442 | |||
| 443 | return status; | ||
| 444 | } | ||
| 445 | |||
| 446 | static efi_status_t | ||
| 447 | efi_thunk_set_wakeup_time(efi_bool_t enabled, efi_time_t *tm) | ||
| 448 | { | ||
| 449 | efi_status_t status; | ||
| 450 | u32 phys_tm; | ||
| 451 | |||
| 452 | spin_lock(&rtc_lock); | ||
| 453 | |||
| 454 | phys_tm = virt_to_phys(tm); | ||
| 455 | |||
| 456 | status = efi_thunk(set_wakeup_time, enabled, phys_tm); | ||
| 457 | |||
| 458 | spin_unlock(&rtc_lock); | ||
| 459 | |||
| 460 | return status; | ||
| 461 | } | ||
| 462 | |||
| 463 | |||
| 464 | static efi_status_t | ||
| 465 | efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor, | ||
| 466 | u32 *attr, unsigned long *data_size, void *data) | ||
| 467 | { | ||
| 468 | efi_status_t status; | ||
| 469 | u32 phys_name, phys_vendor, phys_attr; | ||
| 470 | u32 phys_data_size, phys_data; | ||
| 471 | |||
| 472 | phys_data_size = virt_to_phys(data_size); | ||
| 473 | phys_vendor = virt_to_phys(vendor); | ||
| 474 | phys_name = virt_to_phys(name); | ||
| 475 | phys_attr = virt_to_phys(attr); | ||
| 476 | phys_data = virt_to_phys(data); | ||
| 477 | |||
| 478 | status = efi_thunk(get_variable, phys_name, phys_vendor, | ||
| 479 | phys_attr, phys_data_size, phys_data); | ||
| 480 | |||
| 481 | return status; | ||
| 482 | } | ||
| 483 | |||
| 484 | static efi_status_t | ||
| 485 | efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor, | ||
| 486 | u32 attr, unsigned long data_size, void *data) | ||
| 487 | { | ||
| 488 | u32 phys_name, phys_vendor, phys_data; | ||
| 489 | efi_status_t status; | ||
| 490 | |||
| 491 | phys_name = virt_to_phys(name); | ||
| 492 | phys_vendor = virt_to_phys(vendor); | ||
| 493 | phys_data = virt_to_phys(data); | ||
| 494 | |||
| 495 | /* If data_size is > sizeof(u32) we've got problems */ | ||
| 496 | status = efi_thunk(set_variable, phys_name, phys_vendor, | ||
| 497 | attr, data_size, phys_data); | ||
| 498 | |||
| 499 | return status; | ||
| 500 | } | ||
| 501 | |||
| 502 | static efi_status_t | ||
| 503 | efi_thunk_get_next_variable(unsigned long *name_size, | ||
| 504 | efi_char16_t *name, | ||
| 505 | efi_guid_t *vendor) | ||
| 506 | { | ||
| 507 | efi_status_t status; | ||
| 508 | u32 phys_name_size, phys_name, phys_vendor; | ||
| 509 | |||
| 510 | phys_name_size = virt_to_phys(name_size); | ||
| 511 | phys_vendor = virt_to_phys(vendor); | ||
| 512 | phys_name = virt_to_phys(name); | ||
| 513 | |||
| 514 | status = efi_thunk(get_next_variable, phys_name_size, | ||
| 515 | phys_name, phys_vendor); | ||
| 516 | |||
| 517 | return status; | ||
| 518 | } | ||
| 519 | |||
| 520 | static efi_status_t | ||
| 521 | efi_thunk_get_next_high_mono_count(u32 *count) | ||
| 522 | { | ||
| 523 | efi_status_t status; | ||
| 524 | u32 phys_count; | ||
| 525 | |||
| 526 | phys_count = virt_to_phys(count); | ||
| 527 | status = efi_thunk(get_next_high_mono_count, phys_count); | ||
| 528 | |||
| 529 | return status; | ||
| 530 | } | ||
| 531 | |||
| 532 | static void | ||
| 533 | efi_thunk_reset_system(int reset_type, efi_status_t status, | ||
| 534 | unsigned long data_size, efi_char16_t *data) | ||
| 535 | { | ||
| 536 | u32 phys_data; | ||
| 537 | |||
| 538 | phys_data = virt_to_phys(data); | ||
| 539 | |||
| 540 | efi_thunk(reset_system, reset_type, status, data_size, phys_data); | ||
| 541 | } | ||
| 542 | |||
| 543 | static efi_status_t | ||
| 544 | efi_thunk_update_capsule(efi_capsule_header_t **capsules, | ||
| 545 | unsigned long count, unsigned long sg_list) | ||
| 546 | { | ||
| 547 | /* | ||
| 548 | * To properly support this function we would need to repackage | ||
| 549 | * 'capsules' because the firmware doesn't understand 64-bit | ||
| 550 | * pointers. | ||
| 551 | */ | ||
| 552 | return EFI_UNSUPPORTED; | ||
| 553 | } | ||
| 554 | |||
| 555 | static efi_status_t | ||
| 556 | efi_thunk_query_variable_info(u32 attr, u64 *storage_space, | ||
| 557 | u64 *remaining_space, | ||
| 558 | u64 *max_variable_size) | ||
| 559 | { | ||
| 560 | efi_status_t status; | ||
| 561 | u32 phys_storage, phys_remaining, phys_max; | ||
| 562 | |||
| 563 | if (efi.runtime_version < EFI_2_00_SYSTEM_TABLE_REVISION) | ||
| 564 | return EFI_UNSUPPORTED; | ||
| 565 | |||
| 566 | phys_storage = virt_to_phys(storage_space); | ||
| 567 | phys_remaining = virt_to_phys(remaining_space); | ||
| 568 | phys_max = virt_to_phys(max_variable_size); | ||
| 569 | |||
| 570 | status = efi_thunk(query_variable_info, phys_storage, | ||
| 571 | phys_remaining, phys_max); | ||
| 572 | |||
| 573 | return status; | ||
| 574 | } | ||
| 575 | |||
| 576 | static efi_status_t | ||
| 577 | efi_thunk_query_capsule_caps(efi_capsule_header_t **capsules, | ||
| 578 | unsigned long count, u64 *max_size, | ||
| 579 | int *reset_type) | ||
| 580 | { | ||
| 581 | /* | ||
| 582 | * To properly support this function we would need to repackage | ||
| 583 | * 'capsules' because the firmware doesn't understand 64-bit | ||
| 584 | * pointers. | ||
| 585 | */ | ||
| 586 | return EFI_UNSUPPORTED; | ||
| 587 | } | ||
| 588 | |||
| 589 | void efi_thunk_runtime_setup(void) | ||
| 590 | { | ||
| 591 | efi.get_time = efi_thunk_get_time; | ||
| 592 | efi.set_time = efi_thunk_set_time; | ||
| 593 | efi.get_wakeup_time = efi_thunk_get_wakeup_time; | ||
| 594 | efi.set_wakeup_time = efi_thunk_set_wakeup_time; | ||
| 595 | efi.get_variable = efi_thunk_get_variable; | ||
| 596 | efi.get_next_variable = efi_thunk_get_next_variable; | ||
| 597 | efi.set_variable = efi_thunk_set_variable; | ||
| 598 | efi.get_next_high_mono_count = efi_thunk_get_next_high_mono_count; | ||
| 599 | efi.reset_system = efi_thunk_reset_system; | ||
| 600 | efi.query_variable_info = efi_thunk_query_variable_info; | ||
| 601 | efi.update_capsule = efi_thunk_update_capsule; | ||
| 602 | efi.query_capsule_caps = efi_thunk_query_capsule_caps; | ||
| 603 | } | ||
| 604 | #endif /* CONFIG_EFI_MIXED */ | ||
diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S index 88073b140298..65b787a9fc4e 100644 --- a/arch/x86/platform/efi/efi_stub_64.S +++ b/arch/x86/platform/efi/efi_stub_64.S | |||
| @@ -7,6 +7,10 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include <linux/linkage.h> | 9 | #include <linux/linkage.h> |
| 10 | #include <asm/segment.h> | ||
| 11 | #include <asm/msr.h> | ||
| 12 | #include <asm/processor-flags.h> | ||
| 13 | #include <asm/page_types.h> | ||
| 10 | 14 | ||
| 11 | #define SAVE_XMM \ | 15 | #define SAVE_XMM \ |
| 12 | mov %rsp, %rax; \ | 16 | mov %rsp, %rax; \ |
| @@ -164,7 +168,160 @@ ENTRY(efi_call6) | |||
| 164 | ret | 168 | ret |
| 165 | ENDPROC(efi_call6) | 169 | ENDPROC(efi_call6) |
| 166 | 170 | ||
| 171 | #ifdef CONFIG_EFI_MIXED | ||
| 172 | |||
| 173 | /* | ||
| 174 | * We run this function from the 1:1 mapping. | ||
| 175 | * | ||
| 176 | * This function must be invoked with a 1:1 mapped stack. | ||
| 177 | */ | ||
| 178 | ENTRY(__efi64_thunk) | ||
| 179 | subq $32, %rsp | ||
| 180 | movl %esi, 0x0(%rsp) | ||
| 181 | movl %edx, 0x4(%rsp) | ||
| 182 | movl %ecx, 0x8(%rsp) | ||
| 183 | movq %r8, %rsi | ||
| 184 | movl %esi, 0xc(%rsp) | ||
| 185 | movq %r9, %rsi | ||
| 186 | movl %esi, 0x10(%rsp) | ||
| 187 | |||
| 188 | sgdt save_gdt(%rip) | ||
| 189 | |||
| 190 | leaq 1f(%rip), %rbx | ||
| 191 | movq %rbx, func_rt_ptr(%rip) | ||
| 192 | |||
| 193 | /* Switch to gdt with 32-bit segments */ | ||
| 194 | movl 40(%rsp), %eax | ||
| 195 | lgdt (%rax) | ||
| 196 | |||
| 197 | leaq efi_enter32(%rip), %rax | ||
| 198 | pushq $__KERNEL_CS | ||
| 199 | pushq %rax | ||
| 200 | lretq | ||
| 201 | |||
| 202 | 1: addq $32, %rsp | ||
| 203 | |||
| 204 | lgdt save_gdt(%rip) | ||
| 205 | |||
| 206 | /* | ||
| 207 | * Convert 32-bit status code into 64-bit. | ||
| 208 | */ | ||
| 209 | test %rax, %rax | ||
| 210 | jz 1f | ||
| 211 | movl %eax, %ecx | ||
| 212 | andl $0x0fffffff, %ecx | ||
| 213 | andl $0xf0000000, %eax | ||
| 214 | shl $32, %rax | ||
| 215 | or %rcx, %rax | ||
| 216 | 1: | ||
| 217 | ret | ||
| 218 | ENDPROC(__efi64_thunk) | ||
| 219 | |||
| 220 | ENTRY(efi_exit32) | ||
| 221 | xorq %rax, %rax | ||
| 222 | movl %eax, %ds | ||
| 223 | movl %eax, %es | ||
| 224 | movl %eax, %ss | ||
| 225 | |||
| 226 | movq func_rt_ptr(%rip), %rax | ||
| 227 | push %rax | ||
| 228 | mov %rdi, %rax | ||
| 229 | ret | ||
| 230 | ENDPROC(efi_exit32) | ||
| 231 | |||
| 232 | .code32 | ||
| 233 | /* | ||
| 234 | * EFI service pointer must be in %edi. | ||
| 235 | * | ||
| 236 | * The stack should represent the 32-bit calling convention. | ||
| 237 | */ | ||
| 238 | ENTRY(efi_enter32) | ||
| 239 | movl $__KERNEL_DS, %eax | ||
| 240 | movl %eax, %ds | ||
| 241 | movl %eax, %es | ||
| 242 | movl %eax, %ss | ||
| 243 | |||
| 244 | /* Reload pgtables */ | ||
| 245 | movl %cr3, %eax | ||
| 246 | movl %eax, %cr3 | ||
| 247 | |||
| 248 | /* Disable paging */ | ||
| 249 | movl %cr0, %eax | ||
| 250 | btrl $X86_CR0_PG_BIT, %eax | ||
| 251 | movl %eax, %cr0 | ||
| 252 | |||
| 253 | /* Disable long mode via EFER */ | ||
| 254 | movl $MSR_EFER, %ecx | ||
| 255 | rdmsr | ||
| 256 | btrl $_EFER_LME, %eax | ||
| 257 | wrmsr | ||
| 258 | |||
| 259 | call *%edi | ||
| 260 | |||
| 261 | /* We must preserve return value */ | ||
| 262 | movl %eax, %edi | ||
| 263 | |||
| 264 | /* | ||
| 265 | * Some firmware will return with interrupts enabled. Be sure to | ||
| 266 | * disable them before we switch GDTs. | ||
| 267 | */ | ||
| 268 | cli | ||
| 269 | |||
| 270 | movl 44(%esp), %eax | ||
| 271 | movl %eax, 2(%eax) | ||
| 272 | lgdtl (%eax) | ||
| 273 | |||
| 274 | movl %cr4, %eax | ||
| 275 | btsl $(X86_CR4_PAE_BIT), %eax | ||
| 276 | movl %eax, %cr4 | ||
| 277 | |||
| 278 | movl %cr3, %eax | ||
| 279 | movl %eax, %cr3 | ||
| 280 | |||
| 281 | movl $MSR_EFER, %ecx | ||
| 282 | rdmsr | ||
| 283 | btsl $_EFER_LME, %eax | ||
| 284 | wrmsr | ||
| 285 | |||
| 286 | xorl %eax, %eax | ||
| 287 | lldt %ax | ||
| 288 | |||
| 289 | movl 48(%esp), %eax | ||
| 290 | pushl $__KERNEL_CS | ||
| 291 | pushl %eax | ||
| 292 | |||
| 293 | /* Enable paging */ | ||
| 294 | movl %cr0, %eax | ||
| 295 | btsl $X86_CR0_PG_BIT, %eax | ||
| 296 | movl %eax, %cr0 | ||
| 297 | lret | ||
| 298 | ENDPROC(efi_enter32) | ||
| 299 | |||
| 300 | .data | ||
| 301 | .balign 8 | ||
| 302 | .global efi32_boot_gdt | ||
| 303 | efi32_boot_gdt: .word 0 | ||
| 304 | .quad 0 | ||
| 305 | |||
| 306 | save_gdt: .word 0 | ||
| 307 | .quad 0 | ||
| 308 | func_rt_ptr: .quad 0 | ||
| 309 | |||
| 310 | .global efi_gdt64 | ||
| 311 | efi_gdt64: | ||
| 312 | .word efi_gdt64_end - efi_gdt64 | ||
| 313 | .long 0 /* Filled out by user */ | ||
| 314 | .word 0 | ||
| 315 | .quad 0x0000000000000000 /* NULL descriptor */ | ||
| 316 | .quad 0x00af9a000000ffff /* __KERNEL_CS */ | ||
| 317 | .quad 0x00cf92000000ffff /* __KERNEL_DS */ | ||
| 318 | .quad 0x0080890000000000 /* TS descriptor */ | ||
| 319 | .quad 0x0000000000000000 /* TS continued */ | ||
| 320 | efi_gdt64_end: | ||
| 321 | #endif /* CONFIG_EFI_MIXED */ | ||
| 322 | |||
| 167 | .data | 323 | .data |
| 168 | ENTRY(efi_scratch) | 324 | ENTRY(efi_scratch) |
| 169 | .fill 3,8,0 | 325 | .fill 3,8,0 |
| 170 | .byte 0 | 326 | .byte 0 |
| 327 | .quad 0 | ||
diff --git a/arch/x86/platform/efi/efi_thunk_64.S b/arch/x86/platform/efi/efi_thunk_64.S new file mode 100644 index 000000000000..8806fa73e6e6 --- /dev/null +++ b/arch/x86/platform/efi/efi_thunk_64.S | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2014 Intel Corporation; author Matt Fleming | ||
| 3 | */ | ||
| 4 | |||
| 5 | #include <linux/linkage.h> | ||
| 6 | #include <asm/page_types.h> | ||
| 7 | |||
| 8 | .text | ||
| 9 | .code64 | ||
| 10 | ENTRY(efi64_thunk) | ||
| 11 | push %rbp | ||
| 12 | push %rbx | ||
| 13 | |||
| 14 | /* | ||
| 15 | * Switch to 1:1 mapped 32-bit stack pointer. | ||
| 16 | */ | ||
| 17 | movq %rsp, efi_saved_sp(%rip) | ||
| 18 | movq efi_scratch+25(%rip), %rsp | ||
| 19 | |||
| 20 | /* | ||
| 21 | * Calculate the physical address of the kernel text. | ||
| 22 | */ | ||
| 23 | movq $__START_KERNEL_map, %rax | ||
| 24 | subq phys_base(%rip), %rax | ||
| 25 | |||
| 26 | /* | ||
| 27 | * Push some physical addresses onto the stack. This is easier | ||
| 28 | * to do now in a code64 section while the assembler can address | ||
| 29 | * 64-bit values. Note that all the addresses on the stack are | ||
| 30 | * 32-bit. | ||
| 31 | */ | ||
| 32 | subq $16, %rsp | ||
| 33 | leaq efi_exit32(%rip), %rbx | ||
| 34 | subq %rax, %rbx | ||
| 35 | movl %ebx, 8(%rsp) | ||
| 36 | leaq efi_gdt64(%rip), %rbx | ||
| 37 | subq %rax, %rbx | ||
| 38 | movl %ebx, 2(%ebx) | ||
| 39 | movl %ebx, 4(%rsp) | ||
| 40 | leaq efi_gdt32(%rip), %rbx | ||
| 41 | subq %rax, %rbx | ||
| 42 | movl %ebx, 2(%ebx) | ||
| 43 | movl %ebx, (%rsp) | ||
| 44 | |||
| 45 | leaq __efi64_thunk(%rip), %rbx | ||
| 46 | subq %rax, %rbx | ||
| 47 | call *%rbx | ||
| 48 | |||
| 49 | movq efi_saved_sp(%rip), %rsp | ||
| 50 | pop %rbx | ||
| 51 | pop %rbp | ||
| 52 | retq | ||
| 53 | ENDPROC(efi64_thunk) | ||
| 54 | |||
| 55 | .data | ||
| 56 | efi_gdt32: | ||
| 57 | .word efi_gdt32_end - efi_gdt32 | ||
| 58 | .long 0 /* Filled out above */ | ||
| 59 | .word 0 | ||
| 60 | .quad 0x0000000000000000 /* NULL descriptor */ | ||
| 61 | .quad 0x00cf9a000000ffff /* __KERNEL_CS */ | ||
| 62 | .quad 0x00cf93000000ffff /* __KERNEL_DS */ | ||
| 63 | efi_gdt32_end: | ||
| 64 | |||
| 65 | efi_saved_sp: .quad 0 | ||
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c index b6bffbfd3be7..a0282872d97d 100644 --- a/drivers/firmware/efi/efi-stub-helper.c +++ b/drivers/firmware/efi/efi-stub-helper.c | |||
| @@ -16,18 +16,6 @@ struct file_info { | |||
| 16 | u64 size; | 16 | u64 size; |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | static void efi_char16_printk(efi_system_table_t *sys_table_arg, | ||
| 23 | efi_char16_t *str) | ||
| 24 | { | ||
| 25 | struct efi_simple_text_output_protocol *out; | ||
| 26 | |||
| 27 | out = (struct efi_simple_text_output_protocol *)sys_table_arg->con_out; | ||
| 28 | efi_call_phys2(out->output_string, out, str); | ||
| 29 | } | ||
| 30 | |||
| 31 | static void efi_printk(efi_system_table_t *sys_table_arg, char *str) | 19 | static void efi_printk(efi_system_table_t *sys_table_arg, char *str) |
| 32 | { | 20 | { |
| 33 | char *s8; | 21 | char *s8; |
| @@ -65,20 +53,23 @@ again: | |||
| 65 | * allocation which may be in a new descriptor region. | 53 | * allocation which may be in a new descriptor region. |
| 66 | */ | 54 | */ |
| 67 | *map_size += sizeof(*m); | 55 | *map_size += sizeof(*m); |
| 68 | status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, | 56 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
| 69 | EFI_LOADER_DATA, *map_size, (void **)&m); | 57 | *map_size, (void **)&m); |
| 70 | if (status != EFI_SUCCESS) | 58 | if (status != EFI_SUCCESS) |
| 71 | goto fail; | 59 | goto fail; |
| 72 | 60 | ||
| 73 | status = efi_call_phys5(sys_table_arg->boottime->get_memory_map, | 61 | *desc_size = 0; |
| 74 | map_size, m, &key, desc_size, &desc_version); | 62 | key = 0; |
| 63 | status = efi_early->call(efi_early->get_memory_map, map_size, m, | ||
| 64 | &key, desc_size, &desc_version); | ||
| 75 | if (status == EFI_BUFFER_TOO_SMALL) { | 65 | if (status == EFI_BUFFER_TOO_SMALL) { |
| 76 | efi_call_phys1(sys_table_arg->boottime->free_pool, m); | 66 | efi_early->call(efi_early->free_pool, m); |
| 77 | goto again; | 67 | goto again; |
| 78 | } | 68 | } |
| 79 | 69 | ||
| 80 | if (status != EFI_SUCCESS) | 70 | if (status != EFI_SUCCESS) |
| 81 | efi_call_phys1(sys_table_arg->boottime->free_pool, m); | 71 | efi_early->call(efi_early->free_pool, m); |
| 72 | |||
| 82 | if (key_ptr && status == EFI_SUCCESS) | 73 | if (key_ptr && status == EFI_SUCCESS) |
| 83 | *key_ptr = key; | 74 | *key_ptr = key; |
| 84 | if (desc_ver && status == EFI_SUCCESS) | 75 | if (desc_ver && status == EFI_SUCCESS) |
| @@ -158,9 +149,9 @@ again: | |||
| 158 | if (!max_addr) | 149 | if (!max_addr) |
| 159 | status = EFI_NOT_FOUND; | 150 | status = EFI_NOT_FOUND; |
| 160 | else { | 151 | else { |
| 161 | status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, | 152 | status = efi_early->call(efi_early->allocate_pages, |
| 162 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | 153 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, |
| 163 | nr_pages, &max_addr); | 154 | nr_pages, &max_addr); |
| 164 | if (status != EFI_SUCCESS) { | 155 | if (status != EFI_SUCCESS) { |
| 165 | max = max_addr; | 156 | max = max_addr; |
| 166 | max_addr = 0; | 157 | max_addr = 0; |
| @@ -170,8 +161,7 @@ again: | |||
| 170 | *addr = max_addr; | 161 | *addr = max_addr; |
| 171 | } | 162 | } |
| 172 | 163 | ||
| 173 | efi_call_phys1(sys_table_arg->boottime->free_pool, map); | 164 | efi_early->call(efi_early->free_pool, map); |
| 174 | |||
| 175 | fail: | 165 | fail: |
| 176 | return status; | 166 | return status; |
| 177 | } | 167 | } |
| @@ -231,9 +221,9 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, | |||
| 231 | if ((start + size) > end) | 221 | if ((start + size) > end) |
| 232 | continue; | 222 | continue; |
| 233 | 223 | ||
| 234 | status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, | 224 | status = efi_early->call(efi_early->allocate_pages, |
| 235 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | 225 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, |
| 236 | nr_pages, &start); | 226 | nr_pages, &start); |
| 237 | if (status == EFI_SUCCESS) { | 227 | if (status == EFI_SUCCESS) { |
| 238 | *addr = start; | 228 | *addr = start; |
| 239 | break; | 229 | break; |
| @@ -243,7 +233,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, | |||
| 243 | if (i == map_size / desc_size) | 233 | if (i == map_size / desc_size) |
| 244 | status = EFI_NOT_FOUND; | 234 | status = EFI_NOT_FOUND; |
| 245 | 235 | ||
| 246 | efi_call_phys1(sys_table_arg->boottime->free_pool, map); | 236 | efi_early->call(efi_early->free_pool, map); |
| 247 | fail: | 237 | fail: |
| 248 | return status; | 238 | return status; |
| 249 | } | 239 | } |
| @@ -257,7 +247,7 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, | |||
| 257 | return; | 247 | return; |
| 258 | 248 | ||
| 259 | nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | 249 | nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; |
| 260 | efi_call_phys2(sys_table_arg->boottime->free_pages, addr, nr_pages); | 250 | efi_early->call(efi_early->free_pages, addr, nr_pages); |
| 261 | } | 251 | } |
| 262 | 252 | ||
| 263 | 253 | ||
| @@ -276,9 +266,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
| 276 | { | 266 | { |
| 277 | struct file_info *files; | 267 | struct file_info *files; |
| 278 | unsigned long file_addr; | 268 | unsigned long file_addr; |
| 279 | efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; | ||
| 280 | u64 file_size_total; | 269 | u64 file_size_total; |
| 281 | efi_file_io_interface_t *io; | ||
| 282 | efi_file_handle_t *fh; | 270 | efi_file_handle_t *fh; |
| 283 | efi_status_t status; | 271 | efi_status_t status; |
| 284 | int nr_files; | 272 | int nr_files; |
| @@ -319,10 +307,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
| 319 | if (!nr_files) | 307 | if (!nr_files) |
| 320 | return EFI_SUCCESS; | 308 | return EFI_SUCCESS; |
| 321 | 309 | ||
| 322 | status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, | 310 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
| 323 | EFI_LOADER_DATA, | 311 | nr_files * sizeof(*files), (void **)&files); |
| 324 | nr_files * sizeof(*files), | ||
| 325 | (void **)&files); | ||
| 326 | if (status != EFI_SUCCESS) { | 312 | if (status != EFI_SUCCESS) { |
| 327 | efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n"); | 313 | efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n"); |
| 328 | goto fail; | 314 | goto fail; |
| @@ -331,13 +317,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
| 331 | str = cmd_line; | 317 | str = cmd_line; |
| 332 | for (i = 0; i < nr_files; i++) { | 318 | for (i = 0; i < nr_files; i++) { |
| 333 | struct file_info *file; | 319 | struct file_info *file; |
| 334 | efi_file_handle_t *h; | ||
| 335 | efi_file_info_t *info; | ||
| 336 | efi_char16_t filename_16[256]; | 320 | efi_char16_t filename_16[256]; |
| 337 | unsigned long info_sz; | ||
| 338 | efi_guid_t info_guid = EFI_FILE_INFO_ID; | ||
| 339 | efi_char16_t *p; | 321 | efi_char16_t *p; |
| 340 | u64 file_sz; | ||
| 341 | 322 | ||
| 342 | str = strstr(str, option_string); | 323 | str = strstr(str, option_string); |
| 343 | if (!str) | 324 | if (!str) |
| @@ -368,71 +349,18 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
| 368 | 349 | ||
| 369 | /* Only open the volume once. */ | 350 | /* Only open the volume once. */ |
| 370 | if (!i) { | 351 | if (!i) { |
| 371 | efi_boot_services_t *boottime; | 352 | status = efi_open_volume(sys_table_arg, image, |
| 372 | 353 | (void **)&fh); | |
| 373 | boottime = sys_table_arg->boottime; | 354 | if (status != EFI_SUCCESS) |
| 374 | |||
| 375 | status = efi_call_phys3(boottime->handle_protocol, | ||
| 376 | image->device_handle, &fs_proto, | ||
| 377 | (void **)&io); | ||
| 378 | if (status != EFI_SUCCESS) { | ||
| 379 | efi_printk(sys_table_arg, "Failed to handle fs_proto\n"); | ||
| 380 | goto free_files; | ||
| 381 | } | ||
| 382 | |||
| 383 | status = efi_call_phys2(io->open_volume, io, &fh); | ||
| 384 | if (status != EFI_SUCCESS) { | ||
| 385 | efi_printk(sys_table_arg, "Failed to open volume\n"); | ||
| 386 | goto free_files; | 355 | goto free_files; |
| 387 | } | ||
| 388 | } | 356 | } |
| 389 | 357 | ||
| 390 | status = efi_call_phys5(fh->open, fh, &h, filename_16, | 358 | status = efi_file_size(sys_table_arg, fh, filename_16, |
| 391 | EFI_FILE_MODE_READ, (u64)0); | 359 | (void **)&file->handle, &file->size); |
| 392 | if (status != EFI_SUCCESS) { | 360 | if (status != EFI_SUCCESS) |
| 393 | efi_printk(sys_table_arg, "Failed to open file: "); | ||
| 394 | efi_char16_printk(sys_table_arg, filename_16); | ||
| 395 | efi_printk(sys_table_arg, "\n"); | ||
| 396 | goto close_handles; | 361 | goto close_handles; |
| 397 | } | ||
| 398 | 362 | ||
| 399 | file->handle = h; | 363 | file_size_total += file->size; |
| 400 | |||
| 401 | info_sz = 0; | ||
| 402 | status = efi_call_phys4(h->get_info, h, &info_guid, | ||
| 403 | &info_sz, NULL); | ||
| 404 | if (status != EFI_BUFFER_TOO_SMALL) { | ||
| 405 | efi_printk(sys_table_arg, "Failed to get file info size\n"); | ||
| 406 | goto close_handles; | ||
| 407 | } | ||
| 408 | |||
| 409 | grow: | ||
| 410 | status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, | ||
| 411 | EFI_LOADER_DATA, info_sz, | ||
| 412 | (void **)&info); | ||
| 413 | if (status != EFI_SUCCESS) { | ||
| 414 | efi_printk(sys_table_arg, "Failed to alloc mem for file info\n"); | ||
| 415 | goto close_handles; | ||
| 416 | } | ||
| 417 | |||
| 418 | status = efi_call_phys4(h->get_info, h, &info_guid, | ||
| 419 | &info_sz, info); | ||
| 420 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
| 421 | efi_call_phys1(sys_table_arg->boottime->free_pool, | ||
| 422 | info); | ||
| 423 | goto grow; | ||
| 424 | } | ||
| 425 | |||
| 426 | file_sz = info->file_size; | ||
| 427 | efi_call_phys1(sys_table_arg->boottime->free_pool, info); | ||
| 428 | |||
| 429 | if (status != EFI_SUCCESS) { | ||
| 430 | efi_printk(sys_table_arg, "Failed to get file info\n"); | ||
| 431 | goto close_handles; | ||
| 432 | } | ||
| 433 | |||
| 434 | file->size = file_sz; | ||
| 435 | file_size_total += file_sz; | ||
| 436 | } | 364 | } |
| 437 | 365 | ||
| 438 | if (file_size_total) { | 366 | if (file_size_total) { |
| @@ -468,10 +396,10 @@ grow: | |||
| 468 | chunksize = EFI_READ_CHUNK_SIZE; | 396 | chunksize = EFI_READ_CHUNK_SIZE; |
| 469 | else | 397 | else |
| 470 | chunksize = size; | 398 | chunksize = size; |
| 471 | status = efi_call_phys3(fh->read, | 399 | |
| 472 | files[j].handle, | 400 | status = efi_file_read(fh, files[j].handle, |
| 473 | &chunksize, | 401 | &chunksize, |
| 474 | (void *)addr); | 402 | (void *)addr); |
| 475 | if (status != EFI_SUCCESS) { | 403 | if (status != EFI_SUCCESS) { |
| 476 | efi_printk(sys_table_arg, "Failed to read file\n"); | 404 | efi_printk(sys_table_arg, "Failed to read file\n"); |
| 477 | goto free_file_total; | 405 | goto free_file_total; |
| @@ -480,12 +408,12 @@ grow: | |||
| 480 | size -= chunksize; | 408 | size -= chunksize; |
| 481 | } | 409 | } |
| 482 | 410 | ||
| 483 | efi_call_phys1(fh->close, files[j].handle); | 411 | efi_file_close(fh, files[j].handle); |
| 484 | } | 412 | } |
| 485 | 413 | ||
| 486 | } | 414 | } |
| 487 | 415 | ||
| 488 | efi_call_phys1(sys_table_arg->boottime->free_pool, files); | 416 | efi_early->call(efi_early->free_pool, files); |
| 489 | 417 | ||
| 490 | *load_addr = file_addr; | 418 | *load_addr = file_addr; |
| 491 | *load_size = file_size_total; | 419 | *load_size = file_size_total; |
| @@ -497,9 +425,9 @@ free_file_total: | |||
| 497 | 425 | ||
| 498 | close_handles: | 426 | close_handles: |
| 499 | for (k = j; k < i; k++) | 427 | for (k = j; k < i; k++) |
| 500 | efi_call_phys1(fh->close, files[k].handle); | 428 | efi_file_close(fh, files[k].handle); |
| 501 | free_files: | 429 | free_files: |
| 502 | efi_call_phys1(sys_table_arg->boottime->free_pool, files); | 430 | efi_early->call(efi_early->free_pool, files); |
| 503 | fail: | 431 | fail: |
| 504 | *load_addr = 0; | 432 | *load_addr = 0; |
| 505 | *load_size = 0; | 433 | *load_size = 0; |
| @@ -545,9 +473,9 @@ static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, | |||
| 545 | * as possible while respecting the required alignment. | 473 | * as possible while respecting the required alignment. |
| 546 | */ | 474 | */ |
| 547 | nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | 475 | nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; |
| 548 | status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, | 476 | status = efi_early->call(efi_early->allocate_pages, |
| 549 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | 477 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, |
| 550 | nr_pages, &efi_addr); | 478 | nr_pages, &efi_addr); |
| 551 | new_addr = efi_addr; | 479 | new_addr = efi_addr; |
| 552 | /* | 480 | /* |
| 553 | * If preferred address allocation failed allocate as low as | 481 | * If preferred address allocation failed allocate as low as |
diff --git a/include/linux/efi.h b/include/linux/efi.h index 64d532ca890a..6c100ff0cae4 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h | |||
| @@ -153,6 +153,102 @@ typedef struct { | |||
| 153 | u8 sets_to_zero; | 153 | u8 sets_to_zero; |
| 154 | } efi_time_cap_t; | 154 | } efi_time_cap_t; |
| 155 | 155 | ||
| 156 | typedef struct { | ||
| 157 | efi_table_hdr_t hdr; | ||
| 158 | u32 raise_tpl; | ||
| 159 | u32 restore_tpl; | ||
| 160 | u32 allocate_pages; | ||
| 161 | u32 free_pages; | ||
| 162 | u32 get_memory_map; | ||
| 163 | u32 allocate_pool; | ||
| 164 | u32 free_pool; | ||
| 165 | u32 create_event; | ||
| 166 | u32 set_timer; | ||
| 167 | u32 wait_for_event; | ||
| 168 | u32 signal_event; | ||
| 169 | u32 close_event; | ||
| 170 | u32 check_event; | ||
| 171 | u32 install_protocol_interface; | ||
| 172 | u32 reinstall_protocol_interface; | ||
| 173 | u32 uninstall_protocol_interface; | ||
| 174 | u32 handle_protocol; | ||
| 175 | u32 __reserved; | ||
| 176 | u32 register_protocol_notify; | ||
| 177 | u32 locate_handle; | ||
| 178 | u32 locate_device_path; | ||
| 179 | u32 install_configuration_table; | ||
| 180 | u32 load_image; | ||
| 181 | u32 start_image; | ||
| 182 | u32 exit; | ||
| 183 | u32 unload_image; | ||
| 184 | u32 exit_boot_services; | ||
| 185 | u32 get_next_monotonic_count; | ||
| 186 | u32 stall; | ||
| 187 | u32 set_watchdog_timer; | ||
| 188 | u32 connect_controller; | ||
| 189 | u32 disconnect_controller; | ||
| 190 | u32 open_protocol; | ||
| 191 | u32 close_protocol; | ||
| 192 | u32 open_protocol_information; | ||
| 193 | u32 protocols_per_handle; | ||
| 194 | u32 locate_handle_buffer; | ||
| 195 | u32 locate_protocol; | ||
| 196 | u32 install_multiple_protocol_interfaces; | ||
| 197 | u32 uninstall_multiple_protocol_interfaces; | ||
| 198 | u32 calculate_crc32; | ||
| 199 | u32 copy_mem; | ||
| 200 | u32 set_mem; | ||
| 201 | u32 create_event_ex; | ||
| 202 | } __packed efi_boot_services_32_t; | ||
| 203 | |||
| 204 | typedef struct { | ||
| 205 | efi_table_hdr_t hdr; | ||
| 206 | u64 raise_tpl; | ||
| 207 | u64 restore_tpl; | ||
| 208 | u64 allocate_pages; | ||
| 209 | u64 free_pages; | ||
| 210 | u64 get_memory_map; | ||
| 211 | u64 allocate_pool; | ||
| 212 | u64 free_pool; | ||
| 213 | u64 create_event; | ||
| 214 | u64 set_timer; | ||
| 215 | u64 wait_for_event; | ||
| 216 | u64 signal_event; | ||
| 217 | u64 close_event; | ||
| 218 | u64 check_event; | ||
| 219 | u64 install_protocol_interface; | ||
| 220 | u64 reinstall_protocol_interface; | ||
| 221 | u64 uninstall_protocol_interface; | ||
| 222 | u64 handle_protocol; | ||
| 223 | u64 __reserved; | ||
| 224 | u64 register_protocol_notify; | ||
| 225 | u64 locate_handle; | ||
| 226 | u64 locate_device_path; | ||
| 227 | u64 install_configuration_table; | ||
| 228 | u64 load_image; | ||
| 229 | u64 start_image; | ||
| 230 | u64 exit; | ||
| 231 | u64 unload_image; | ||
| 232 | u64 exit_boot_services; | ||
| 233 | u64 get_next_monotonic_count; | ||
| 234 | u64 stall; | ||
| 235 | u64 set_watchdog_timer; | ||
| 236 | u64 connect_controller; | ||
| 237 | u64 disconnect_controller; | ||
| 238 | u64 open_protocol; | ||
| 239 | u64 close_protocol; | ||
| 240 | u64 open_protocol_information; | ||
| 241 | u64 protocols_per_handle; | ||
| 242 | u64 locate_handle_buffer; | ||
| 243 | u64 locate_protocol; | ||
| 244 | u64 install_multiple_protocol_interfaces; | ||
| 245 | u64 uninstall_multiple_protocol_interfaces; | ||
| 246 | u64 calculate_crc32; | ||
| 247 | u64 copy_mem; | ||
| 248 | u64 set_mem; | ||
| 249 | u64 create_event_ex; | ||
| 250 | } __packed efi_boot_services_64_t; | ||
| 251 | |||
| 156 | /* | 252 | /* |
| 157 | * EFI Boot Services table | 253 | * EFI Boot Services table |
| 158 | */ | 254 | */ |
| @@ -231,6 +327,15 @@ typedef enum { | |||
| 231 | EfiPciIoAttributeOperationMaximum | 327 | EfiPciIoAttributeOperationMaximum |
| 232 | } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION; | 328 | } EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION; |
| 233 | 329 | ||
| 330 | typedef struct { | ||
| 331 | u32 read; | ||
| 332 | u32 write; | ||
| 333 | } efi_pci_io_protocol_access_32_t; | ||
| 334 | |||
| 335 | typedef struct { | ||
| 336 | u64 read; | ||
| 337 | u64 write; | ||
| 338 | } efi_pci_io_protocol_access_64_t; | ||
| 234 | 339 | ||
| 235 | typedef struct { | 340 | typedef struct { |
| 236 | void *read; | 341 | void *read; |
| @@ -238,6 +343,46 @@ typedef struct { | |||
| 238 | } efi_pci_io_protocol_access_t; | 343 | } efi_pci_io_protocol_access_t; |
| 239 | 344 | ||
| 240 | typedef struct { | 345 | typedef struct { |
| 346 | u32 poll_mem; | ||
| 347 | u32 poll_io; | ||
| 348 | efi_pci_io_protocol_access_32_t mem; | ||
| 349 | efi_pci_io_protocol_access_32_t io; | ||
| 350 | efi_pci_io_protocol_access_32_t pci; | ||
| 351 | u32 copy_mem; | ||
| 352 | u32 map; | ||
| 353 | u32 unmap; | ||
| 354 | u32 allocate_buffer; | ||
| 355 | u32 free_buffer; | ||
| 356 | u32 flush; | ||
| 357 | u32 get_location; | ||
| 358 | u32 attributes; | ||
| 359 | u32 get_bar_attributes; | ||
| 360 | u32 set_bar_attributes; | ||
| 361 | uint64_t romsize; | ||
| 362 | void *romimage; | ||
| 363 | } efi_pci_io_protocol_32; | ||
| 364 | |||
| 365 | typedef struct { | ||
| 366 | u64 poll_mem; | ||
| 367 | u64 poll_io; | ||
| 368 | efi_pci_io_protocol_access_64_t mem; | ||
| 369 | efi_pci_io_protocol_access_64_t io; | ||
| 370 | efi_pci_io_protocol_access_64_t pci; | ||
| 371 | u64 copy_mem; | ||
| 372 | u64 map; | ||
| 373 | u64 unmap; | ||
| 374 | u64 allocate_buffer; | ||
| 375 | u64 free_buffer; | ||
| 376 | u64 flush; | ||
| 377 | u64 get_location; | ||
| 378 | u64 attributes; | ||
| 379 | u64 get_bar_attributes; | ||
| 380 | u64 set_bar_attributes; | ||
| 381 | uint64_t romsize; | ||
| 382 | void *romimage; | ||
| 383 | } efi_pci_io_protocol_64; | ||
| 384 | |||
| 385 | typedef struct { | ||
| 241 | void *poll_mem; | 386 | void *poll_mem; |
| 242 | void *poll_io; | 387 | void *poll_io; |
| 243 | efi_pci_io_protocol_access_t mem; | 388 | efi_pci_io_protocol_access_t mem; |
| @@ -292,6 +437,42 @@ typedef struct { | |||
| 292 | 437 | ||
| 293 | typedef struct { | 438 | typedef struct { |
| 294 | efi_table_hdr_t hdr; | 439 | efi_table_hdr_t hdr; |
| 440 | u32 get_time; | ||
| 441 | u32 set_time; | ||
| 442 | u32 get_wakeup_time; | ||
| 443 | u32 set_wakeup_time; | ||
| 444 | u32 set_virtual_address_map; | ||
| 445 | u32 convert_pointer; | ||
| 446 | u32 get_variable; | ||
| 447 | u32 get_next_variable; | ||
| 448 | u32 set_variable; | ||
| 449 | u32 get_next_high_mono_count; | ||
| 450 | u32 reset_system; | ||
| 451 | u32 update_capsule; | ||
| 452 | u32 query_capsule_caps; | ||
| 453 | u32 query_variable_info; | ||
| 454 | } efi_runtime_services_32_t; | ||
| 455 | |||
| 456 | typedef struct { | ||
| 457 | efi_table_hdr_t hdr; | ||
| 458 | u64 get_time; | ||
| 459 | u64 set_time; | ||
| 460 | u64 get_wakeup_time; | ||
| 461 | u64 set_wakeup_time; | ||
| 462 | u64 set_virtual_address_map; | ||
| 463 | u64 convert_pointer; | ||
| 464 | u64 get_variable; | ||
| 465 | u64 get_next_variable; | ||
| 466 | u64 set_variable; | ||
| 467 | u64 get_next_high_mono_count; | ||
| 468 | u64 reset_system; | ||
| 469 | u64 update_capsule; | ||
| 470 | u64 query_capsule_caps; | ||
| 471 | u64 query_variable_info; | ||
| 472 | } efi_runtime_services_64_t; | ||
| 473 | |||
| 474 | typedef struct { | ||
| 475 | efi_table_hdr_t hdr; | ||
| 295 | void *get_time; | 476 | void *get_time; |
| 296 | void *set_time; | 477 | void *set_time; |
| 297 | void *get_wakeup_time; | 478 | void *get_wakeup_time; |
| @@ -485,6 +666,38 @@ struct efi_memory_map { | |||
| 485 | 666 | ||
| 486 | typedef struct { | 667 | typedef struct { |
| 487 | u32 revision; | 668 | u32 revision; |
| 669 | u32 parent_handle; | ||
| 670 | u32 system_table; | ||
| 671 | u32 device_handle; | ||
| 672 | u32 file_path; | ||
| 673 | u32 reserved; | ||
| 674 | u32 load_options_size; | ||
| 675 | u32 load_options; | ||
| 676 | u32 image_base; | ||
| 677 | __aligned_u64 image_size; | ||
| 678 | unsigned int image_code_type; | ||
| 679 | unsigned int image_data_type; | ||
| 680 | unsigned long unload; | ||
| 681 | } efi_loaded_image_32_t; | ||
| 682 | |||
| 683 | typedef struct { | ||
| 684 | u32 revision; | ||
| 685 | u64 parent_handle; | ||
| 686 | u64 system_table; | ||
| 687 | u64 device_handle; | ||
| 688 | u64 file_path; | ||
| 689 | u64 reserved; | ||
| 690 | u32 load_options_size; | ||
| 691 | u64 load_options; | ||
| 692 | u64 image_base; | ||
| 693 | __aligned_u64 image_size; | ||
| 694 | unsigned int image_code_type; | ||
| 695 | unsigned int image_data_type; | ||
| 696 | unsigned long unload; | ||
| 697 | } efi_loaded_image_64_t; | ||
| 698 | |||
| 699 | typedef struct { | ||
| 700 | u32 revision; | ||
| 488 | void *parent_handle; | 701 | void *parent_handle; |
| 489 | efi_system_table_t *system_table; | 702 | efi_system_table_t *system_table; |
| 490 | void *device_handle; | 703 | void *device_handle; |
| @@ -511,6 +724,34 @@ typedef struct { | |||
| 511 | efi_char16_t filename[1]; | 724 | efi_char16_t filename[1]; |
| 512 | } efi_file_info_t; | 725 | } efi_file_info_t; |
| 513 | 726 | ||
| 727 | typedef struct { | ||
| 728 | u64 revision; | ||
| 729 | u32 open; | ||
| 730 | u32 close; | ||
| 731 | u32 delete; | ||
| 732 | u32 read; | ||
| 733 | u32 write; | ||
| 734 | u32 get_position; | ||
| 735 | u32 set_position; | ||
| 736 | u32 get_info; | ||
| 737 | u32 set_info; | ||
| 738 | u32 flush; | ||
| 739 | } efi_file_handle_32_t; | ||
| 740 | |||
| 741 | typedef struct { | ||
| 742 | u64 revision; | ||
| 743 | u64 open; | ||
| 744 | u64 close; | ||
| 745 | u64 delete; | ||
| 746 | u64 read; | ||
| 747 | u64 write; | ||
| 748 | u64 get_position; | ||
| 749 | u64 set_position; | ||
| 750 | u64 get_info; | ||
| 751 | u64 set_info; | ||
| 752 | u64 flush; | ||
| 753 | } efi_file_handle_64_t; | ||
| 754 | |||
| 514 | typedef struct _efi_file_handle { | 755 | typedef struct _efi_file_handle { |
| 515 | u64 revision; | 756 | u64 revision; |
| 516 | efi_status_t (*open)(struct _efi_file_handle *, | 757 | efi_status_t (*open)(struct _efi_file_handle *, |
| @@ -809,6 +1050,17 @@ struct efivar_entry { | |||
| 809 | bool deleting; | 1050 | bool deleting; |
| 810 | }; | 1051 | }; |
| 811 | 1052 | ||
| 1053 | struct efi_simple_text_output_protocol_32 { | ||
| 1054 | u32 reset; | ||
| 1055 | u32 output_string; | ||
| 1056 | u32 test_string; | ||
| 1057 | }; | ||
| 1058 | |||
| 1059 | struct efi_simple_text_output_protocol_64 { | ||
| 1060 | u64 reset; | ||
| 1061 | u64 output_string; | ||
| 1062 | u64 test_string; | ||
| 1063 | }; | ||
| 812 | 1064 | ||
| 813 | struct efi_simple_text_output_protocol { | 1065 | struct efi_simple_text_output_protocol { |
| 814 | void *reset; | 1066 | void *reset; |
