Thomas Gleixner | 97873a3 | 2019-06-04 10:11:30 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 2 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 3 | /* ----------------------------------------------------------------------- |
| 4 | * |
| 5 | * Copyright 2011 Intel Corporation; author Matt Fleming |
| 6 | * |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 7 | * ----------------------------------------------------------------------- */ |
| 8 | |
| 9 | #include <linux/efi.h> |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 10 | #include <linux/pci.h> |
Ingo Molnar | 5520b7e | 2017-01-27 11:59:46 +0100 | [diff] [blame] | 11 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 12 | #include <asm/efi.h> |
Ingo Molnar | 5520b7e | 2017-01-27 11:59:46 +0100 | [diff] [blame] | 13 | #include <asm/e820/types.h> |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 14 | #include <asm/setup.h> |
| 15 | #include <asm/desc.h> |
Kairui Song | 220dd76 | 2019-10-29 18:37:54 +0100 | [diff] [blame] | 16 | #include <asm/boot.h> |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 17 | |
Ard Biesheuvel | c2d0b47 | 2020-02-10 17:02:36 +0100 | [diff] [blame] | 18 | #include "efistub.h" |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 19 | |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 20 | /* Maximum physical address for 64-bit kernel with 4-level paging */ |
| 21 | #define MAXMEM_X86_64_4LEVEL (1ull << 46) |
| 22 | |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 23 | const efi_system_table_t *efi_system_table; |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 24 | extern u32 image_offset; |
Arvind Sankar | 987053a | 2020-04-30 14:28:40 -0400 | [diff] [blame] | 25 | static efi_loaded_image_t *image = NULL; |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 26 | |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 27 | static efi_status_t |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 28 | preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 29 | { |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 30 | struct pci_setup_rom *rom = NULL; |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 31 | efi_status_t status; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 32 | unsigned long size; |
Ard Biesheuvel | e296701 | 2018-07-11 11:02:35 +0200 | [diff] [blame] | 33 | uint64_t romsize; |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 34 | void *romimage; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 35 | |
Hans de Goede | 1de3a1b | 2018-05-04 08:00:01 +0200 | [diff] [blame] | 36 | /* |
Ard Biesheuvel | e296701 | 2018-07-11 11:02:35 +0200 | [diff] [blame] | 37 | * Some firmware images contain EFI function pointers at the place where |
| 38 | * the romimage and romsize fields are supposed to be. Typically the EFI |
Hans de Goede | 1de3a1b | 2018-05-04 08:00:01 +0200 | [diff] [blame] | 39 | * code is mapped at high addresses, translating to an unrealistically |
| 40 | * large romsize. The UEFI spec limits the size of option ROMs to 16 |
| 41 | * MiB so we reject any ROMs over 16 MiB in size to catch this. |
| 42 | */ |
Ard Biesheuvel | 99ea8b1 | 2019-12-24 16:10:22 +0100 | [diff] [blame] | 43 | romimage = efi_table_attr(pci, romimage); |
| 44 | romsize = efi_table_attr(pci, romsize); |
Hans de Goede | 1de3a1b | 2018-05-04 08:00:01 +0200 | [diff] [blame] | 45 | if (!romimage || !romsize || romsize > SZ_16M) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 46 | return EFI_INVALID_PARAMETER; |
| 47 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 48 | size = romsize + sizeof(*rom); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 49 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 50 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, |
| 51 | (void **)&rom); |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 52 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 53 | efi_err("Failed to allocate memory for 'rom'\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 54 | return status; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 55 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 56 | |
| 57 | memset(rom, 0, sizeof(*rom)); |
| 58 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 59 | rom->data.type = SETUP_PCI; |
| 60 | rom->data.len = size - sizeof(struct setup_data); |
| 61 | rom->data.next = 0; |
| 62 | rom->pcilen = pci->romsize; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 63 | *__rom = rom; |
| 64 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 65 | status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, |
| 66 | PCI_VENDOR_ID, 1, &rom->vendor); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 67 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 68 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 69 | efi_err("Failed to read rom->vendor\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 70 | goto free_struct; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 71 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 72 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 73 | status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, |
| 74 | PCI_DEVICE_ID, 1, &rom->devid); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 75 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 76 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 77 | efi_err("Failed to read rom->devid\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 78 | goto free_struct; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 79 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 80 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 81 | status = efi_call_proto(pci, get_location, &rom->segment, &rom->bus, |
| 82 | &rom->device, &rom->function); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 83 | |
| 84 | if (status != EFI_SUCCESS) |
| 85 | goto free_struct; |
| 86 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 87 | memcpy(rom->romdata, romimage, romsize); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 88 | return status; |
| 89 | |
| 90 | free_struct: |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 91 | efi_bs_call(free_pool, rom); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 92 | return status; |
| 93 | } |
| 94 | |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 95 | /* |
| 96 | * There's no way to return an informative status from this function, |
| 97 | * because any analysis (and printing of error messages) needs to be |
| 98 | * done directly at the EFI function call-site. |
| 99 | * |
| 100 | * For example, EFI_INVALID_PARAMETER could indicate a bug or maybe we |
| 101 | * just didn't find any PCI devices, but there's no way to tell outside |
| 102 | * the context of the call. |
| 103 | */ |
| 104 | static void setup_efi_pci(struct boot_params *params) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 105 | { |
| 106 | efi_status_t status; |
| 107 | void **pci_handle = NULL; |
| 108 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; |
| 109 | unsigned long size = 0; |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 110 | struct setup_data *data; |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 111 | efi_handle_t h; |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 112 | int i; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 113 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 114 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 115 | &pci_proto, NULL, &size, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 116 | |
| 117 | if (status == EFI_BUFFER_TOO_SMALL) { |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 118 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, |
| 119 | (void **)&pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 120 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 121 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 122 | efi_err("Failed to allocate memory for 'pci_handle'\n"); |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 123 | return; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 124 | } |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 125 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 126 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 127 | &pci_proto, NULL, &size, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | if (status != EFI_SUCCESS) |
| 131 | goto free_handle; |
| 132 | |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 133 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; |
| 134 | |
| 135 | while (data && data->next) |
| 136 | data = (struct setup_data *)(unsigned long)data->next; |
| 137 | |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 138 | for_each_efi_handle(h, pci_handle, size, i) { |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 139 | efi_pci_io_protocol_t *pci = NULL; |
| 140 | struct pci_setup_rom *rom; |
| 141 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 142 | status = efi_bs_call(handle_protocol, h, &pci_proto, |
| 143 | (void **)&pci); |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 144 | if (status != EFI_SUCCESS || !pci) |
| 145 | continue; |
| 146 | |
| 147 | status = preserve_pci_rom_image(pci, &rom); |
| 148 | if (status != EFI_SUCCESS) |
| 149 | continue; |
| 150 | |
| 151 | if (data) |
| 152 | data->next = (unsigned long)rom; |
| 153 | else |
| 154 | params->hdr.setup_data = (unsigned long)rom; |
| 155 | |
| 156 | data = (struct setup_data *)rom; |
| 157 | } |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 158 | |
| 159 | free_handle: |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 160 | efi_bs_call(free_pool, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 163 | static void retrieve_apple_device_properties(struct boot_params *boot_params) |
| 164 | { |
| 165 | efi_guid_t guid = APPLE_PROPERTIES_PROTOCOL_GUID; |
| 166 | struct setup_data *data, *new; |
| 167 | efi_status_t status; |
| 168 | u32 size = 0; |
Ard Biesheuvel | 960a8d0 | 2019-12-24 16:10:11 +0100 | [diff] [blame] | 169 | apple_properties_protocol_t *p; |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 170 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 171 | status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&p); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 172 | if (status != EFI_SUCCESS) |
| 173 | return; |
| 174 | |
Ard Biesheuvel | 99ea8b1 | 2019-12-24 16:10:22 +0100 | [diff] [blame] | 175 | if (efi_table_attr(p, version) != 0x10000) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 176 | efi_err("Unsupported properties proto version\n"); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 177 | return; |
| 178 | } |
| 179 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 180 | efi_call_proto(p, get_all, NULL, &size); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 181 | if (!size) |
| 182 | return; |
| 183 | |
| 184 | do { |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 185 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, |
| 186 | size + sizeof(struct setup_data), |
| 187 | (void **)&new); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 188 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 189 | efi_err("Failed to allocate memory for 'properties'\n"); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 190 | return; |
| 191 | } |
| 192 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 193 | status = efi_call_proto(p, get_all, new->data, &size); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 194 | |
| 195 | if (status == EFI_BUFFER_TOO_SMALL) |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 196 | efi_bs_call(free_pool, new); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 197 | } while (status == EFI_BUFFER_TOO_SMALL); |
| 198 | |
| 199 | new->type = SETUP_APPLE_PROPERTIES; |
| 200 | new->len = size; |
| 201 | new->next = 0; |
| 202 | |
| 203 | data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 204 | if (!data) { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 205 | boot_params->hdr.setup_data = (unsigned long)new; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 206 | } else { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 207 | while (data->next) |
| 208 | data = (struct setup_data *)(unsigned long)data->next; |
| 209 | data->next = (unsigned long)new; |
| 210 | } |
| 211 | } |
| 212 | |
Ard Biesheuvel | 36b6497 | 2018-03-12 08:45:00 +0000 | [diff] [blame] | 213 | static const efi_char16_t apple[] = L"Apple"; |
| 214 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 215 | static void setup_quirks(struct boot_params *boot_params) |
| 216 | { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 217 | efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long) |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 218 | efi_table_attr(efi_system_table, fw_vendor); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 219 | |
| 220 | if (!memcmp(fw_vendor, apple, sizeof(apple))) { |
| 221 | if (IS_ENABLED(CONFIG_APPLE_PROPERTIES)) |
| 222 | retrieve_apple_device_properties(boot_params); |
| 223 | } |
| 224 | } |
| 225 | |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 226 | /* |
| 227 | * See if we have Universal Graphics Adapter (UGA) protocol |
| 228 | */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 229 | static efi_status_t |
| 230 | setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 231 | { |
| 232 | efi_status_t status; |
| 233 | u32 width, height; |
| 234 | void **uga_handle = NULL; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 235 | efi_uga_draw_protocol_t *uga = NULL, *first_uga; |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 236 | efi_handle_t handle; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 237 | int i; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 238 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 239 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, |
| 240 | (void **)&uga_handle); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 241 | if (status != EFI_SUCCESS) |
| 242 | return status; |
| 243 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 244 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 245 | uga_proto, NULL, &size, uga_handle); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 246 | if (status != EFI_SUCCESS) |
| 247 | goto free_handle; |
| 248 | |
| 249 | height = 0; |
| 250 | width = 0; |
| 251 | |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 252 | first_uga = NULL; |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 253 | for_each_efi_handle(handle, uga_handle, size, i) { |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 254 | efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; |
| 255 | u32 w, h, depth, refresh; |
| 256 | void *pciio; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 257 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 258 | status = efi_bs_call(handle_protocol, handle, uga_proto, |
| 259 | (void **)&uga); |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 260 | if (status != EFI_SUCCESS) |
| 261 | continue; |
| 262 | |
Ard Biesheuvel | 093174f | 2018-07-20 10:47:22 +0900 | [diff] [blame] | 263 | pciio = NULL; |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 264 | efi_bs_call(handle_protocol, handle, &pciio_proto, &pciio); |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 265 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 266 | status = efi_call_proto(uga, get_mode, &w, &h, &depth, &refresh); |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 267 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { |
| 268 | width = w; |
| 269 | height = h; |
| 270 | |
| 271 | /* |
| 272 | * Once we've found a UGA supporting PCIIO, |
| 273 | * don't bother looking any further. |
| 274 | */ |
| 275 | if (pciio) |
| 276 | break; |
| 277 | |
| 278 | first_uga = uga; |
| 279 | } |
| 280 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 281 | |
| 282 | if (!width && !height) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 283 | goto free_handle; |
| 284 | |
| 285 | /* EFI framebuffer */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 286 | si->orig_video_isVGA = VIDEO_TYPE_EFI; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 287 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 288 | si->lfb_depth = 32; |
| 289 | si->lfb_width = width; |
| 290 | si->lfb_height = height; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 291 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 292 | si->red_size = 8; |
| 293 | si->red_pos = 16; |
| 294 | si->green_size = 8; |
| 295 | si->green_pos = 8; |
| 296 | si->blue_size = 8; |
| 297 | si->blue_pos = 0; |
| 298 | si->rsvd_size = 8; |
| 299 | si->rsvd_pos = 24; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 300 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 301 | free_handle: |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 302 | efi_bs_call(free_pool, uga_handle); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 303 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 304 | return status; |
| 305 | } |
| 306 | |
Arvind Sankar | f32ea1c | 2020-01-30 17:20:04 -0500 | [diff] [blame] | 307 | static void setup_graphics(struct boot_params *boot_params) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 308 | { |
| 309 | efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; |
| 310 | struct screen_info *si; |
| 311 | efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; |
| 312 | efi_status_t status; |
| 313 | unsigned long size; |
| 314 | void **gop_handle = NULL; |
| 315 | void **uga_handle = NULL; |
| 316 | |
| 317 | si = &boot_params->screen_info; |
| 318 | memset(si, 0, sizeof(*si)); |
| 319 | |
| 320 | size = 0; |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 321 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 322 | &graphics_proto, NULL, &size, gop_handle); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 323 | if (status == EFI_BUFFER_TOO_SMALL) |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 324 | status = efi_setup_gop(si, &graphics_proto, size); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 325 | |
| 326 | if (status != EFI_SUCCESS) { |
| 327 | size = 0; |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 328 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 329 | &uga_proto, NULL, &size, uga_handle); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 330 | if (status == EFI_BUFFER_TOO_SMALL) |
| 331 | setup_uga(si, &uga_proto, size); |
| 332 | } |
| 333 | } |
| 334 | |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 335 | |
| 336 | static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status) |
| 337 | { |
| 338 | efi_bs_call(exit, handle, status, 0, NULL); |
Ard Biesheuvel | f3fa0ef | 2020-03-08 09:08:45 +0100 | [diff] [blame] | 339 | for(;;) |
| 340 | asm("hlt"); |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 341 | } |
| 342 | |
Ard Biesheuvel | c3710de | 2019-12-24 16:10:17 +0100 | [diff] [blame] | 343 | void startup_32(struct boot_params *boot_params); |
| 344 | |
| 345 | void __noreturn efi_stub_entry(efi_handle_t handle, |
| 346 | efi_system_table_t *sys_table_arg, |
| 347 | struct boot_params *boot_params); |
| 348 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 349 | /* |
| 350 | * Because the x86 boot code expects to be passed a boot_params we |
| 351 | * need to create one ourselves (usually the bootloader would create |
| 352 | * one for us). |
| 353 | */ |
Ard Biesheuvel | c3710de | 2019-12-24 16:10:17 +0100 | [diff] [blame] | 354 | efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, |
| 355 | efi_system_table_t *sys_table_arg) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 356 | { |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 357 | struct boot_params *boot_params; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 358 | struct setup_header *hdr; |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 359 | void *image_base; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 360 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 361 | int options_size = 0; |
| 362 | efi_status_t status; |
Roy Franz | 5fef387 | 2013-09-22 15:45:33 -0700 | [diff] [blame] | 363 | char *cmdline_ptr; |
Roy Franz | 46f4582 | 2013-09-22 15:45:39 -0700 | [diff] [blame] | 364 | unsigned long ramdisk_addr; |
| 365 | unsigned long ramdisk_size; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 366 | |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 367 | efi_system_table = sys_table_arg; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 368 | |
| 369 | /* Check if we were booted by the EFI firmware */ |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 370 | if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 371 | efi_exit(handle, EFI_INVALID_PARAMETER); |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 372 | |
Arvind Sankar | 0347d8c2 | 2020-03-08 09:08:58 +0100 | [diff] [blame] | 373 | status = efi_bs_call(handle_protocol, handle, &proto, (void **)&image); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 374 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 375 | efi_err("Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 376 | efi_exit(handle, status); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 379 | image_base = efi_table_attr(image, image_base); |
| 380 | image_offset = (void *)startup_32 - image_base; |
| 381 | |
Arvind Sankar | 019512f | 2020-04-30 14:28:33 -0400 | [diff] [blame] | 382 | status = efi_allocate_pages(sizeof(struct boot_params), |
| 383 | (unsigned long *)&boot_params, ULONG_MAX); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 384 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 385 | efi_err("Failed to allocate lowmem for boot params\n"); |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 386 | efi_exit(handle, status); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Arvind Sankar | 019512f | 2020-04-30 14:28:33 -0400 | [diff] [blame] | 389 | memset(boot_params, 0x0, sizeof(struct boot_params)); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 390 | |
| 391 | hdr = &boot_params->hdr; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 392 | |
| 393 | /* Copy the second sector to boot_params */ |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 394 | memcpy(&hdr->jump, image_base + 512, 512); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 395 | |
| 396 | /* |
| 397 | * Fill out some of the header fields ourselves because the |
| 398 | * EFI firmware loader doesn't load the first sector. |
| 399 | */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 400 | hdr->root_flags = 1; |
| 401 | hdr->vid_mode = 0xffff; |
| 402 | hdr->boot_flag = 0xAA55; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 403 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 404 | hdr->type_of_loader = 0x21; |
| 405 | |
| 406 | /* Convert unicode cmdline to ascii */ |
Ard Biesheuvel | 27cd551 | 2020-05-19 10:43:01 +0200 | [diff] [blame^] | 407 | cmdline_ptr = efi_convert_cmdline(image, &options_size); |
Roy Franz | 5fef387 | 2013-09-22 15:45:33 -0700 | [diff] [blame] | 408 | if (!cmdline_ptr) |
| 409 | goto fail; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 410 | |
Arvind Sankar | eed4e01 | 2020-04-30 14:28:34 -0400 | [diff] [blame] | 411 | efi_set_u64_split((unsigned long)cmdline_ptr, |
| 412 | &hdr->cmd_line_ptr, &boot_params->ext_cmd_line_ptr); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 413 | |
| 414 | hdr->ramdisk_image = 0; |
| 415 | hdr->ramdisk_size = 0; |
| 416 | |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 417 | efi_stub_entry(handle, sys_table_arg, boot_params); |
Ard Biesheuvel | c3710de | 2019-12-24 16:10:17 +0100 | [diff] [blame] | 418 | /* not reached */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 419 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 420 | fail: |
Arvind Sankar | 019512f | 2020-04-30 14:28:33 -0400 | [diff] [blame] | 421 | efi_free(sizeof(struct boot_params), (unsigned long)boot_params); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 422 | |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 423 | efi_exit(handle, status); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 426 | static void add_e820ext(struct boot_params *params, |
| 427 | struct setup_data *e820ext, u32 nr_entries) |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 428 | { |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 429 | struct setup_data *data; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 430 | |
| 431 | e820ext->type = SETUP_E820_EXT; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 432 | e820ext->len = nr_entries * sizeof(struct boot_e820_entry); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 433 | e820ext->next = 0; |
| 434 | |
| 435 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; |
| 436 | |
| 437 | while (data && data->next) |
| 438 | data = (struct setup_data *)(unsigned long)data->next; |
| 439 | |
| 440 | if (data) |
| 441 | data->next = (unsigned long)e820ext; |
| 442 | else |
| 443 | params->hdr.setup_data = (unsigned long)e820ext; |
| 444 | } |
| 445 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 446 | static efi_status_t |
| 447 | setup_e820(struct boot_params *params, struct setup_data *e820ext, u32 e820ext_size) |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 448 | { |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 449 | struct boot_e820_entry *entry = params->e820_table; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 450 | struct efi_info *efi = ¶ms->efi_info; |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 451 | struct boot_e820_entry *prev = NULL; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 452 | u32 nr_entries; |
| 453 | u32 nr_desc; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 454 | int i; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 455 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 456 | nr_entries = 0; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 457 | nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size; |
| 458 | |
| 459 | for (i = 0; i < nr_desc; i++) { |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 460 | efi_memory_desc_t *d; |
| 461 | unsigned int e820_type = 0; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 462 | unsigned long m = efi->efi_memmap; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 463 | |
Dmitry Skorodumov | 7cc03e4 | 2015-07-28 18:38:32 +0400 | [diff] [blame] | 464 | #ifdef CONFIG_X86_64 |
| 465 | m |= (u64)efi->efi_memmap_hi << 32; |
| 466 | #endif |
| 467 | |
Baoquan He | 02e43c2 | 2017-08-16 21:46:51 +0800 | [diff] [blame] | 468 | d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 469 | switch (d->type) { |
| 470 | case EFI_RESERVED_TYPE: |
| 471 | case EFI_RUNTIME_SERVICES_CODE: |
| 472 | case EFI_RUNTIME_SERVICES_DATA: |
| 473 | case EFI_MEMORY_MAPPED_IO: |
| 474 | case EFI_MEMORY_MAPPED_IO_PORT_SPACE: |
| 475 | case EFI_PAL_CODE: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 476 | e820_type = E820_TYPE_RESERVED; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 477 | break; |
| 478 | |
| 479 | case EFI_UNUSABLE_MEMORY: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 480 | e820_type = E820_TYPE_UNUSABLE; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 481 | break; |
| 482 | |
| 483 | case EFI_ACPI_RECLAIM_MEMORY: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 484 | e820_type = E820_TYPE_ACPI; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 485 | break; |
| 486 | |
| 487 | case EFI_LOADER_CODE: |
| 488 | case EFI_LOADER_DATA: |
| 489 | case EFI_BOOT_SERVICES_CODE: |
| 490 | case EFI_BOOT_SERVICES_DATA: |
| 491 | case EFI_CONVENTIONAL_MEMORY: |
Dan Williams | 262b45a | 2019-11-06 17:43:16 -0800 | [diff] [blame] | 492 | if (efi_soft_reserve_enabled() && |
| 493 | (d->attribute & EFI_MEMORY_SP)) |
| 494 | e820_type = E820_TYPE_SOFT_RESERVED; |
| 495 | else |
| 496 | e820_type = E820_TYPE_RAM; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 497 | break; |
| 498 | |
| 499 | case EFI_ACPI_MEMORY_NVS: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 500 | e820_type = E820_TYPE_NVS; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 501 | break; |
| 502 | |
Dan Williams | ad5fb87 | 2015-04-03 12:05:28 -0400 | [diff] [blame] | 503 | case EFI_PERSISTENT_MEMORY: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 504 | e820_type = E820_TYPE_PMEM; |
Dan Williams | ad5fb87 | 2015-04-03 12:05:28 -0400 | [diff] [blame] | 505 | break; |
| 506 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 507 | default: |
| 508 | continue; |
| 509 | } |
| 510 | |
| 511 | /* Merge adjacent mappings */ |
| 512 | if (prev && prev->type == e820_type && |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 513 | (prev->addr + prev->size) == d->phys_addr) { |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 514 | prev->size += d->num_pages << 12; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 515 | continue; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 516 | } |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 517 | |
Ingo Molnar | 61a5010 | 2017-01-27 13:54:38 +0100 | [diff] [blame] | 518 | if (nr_entries == ARRAY_SIZE(params->e820_table)) { |
Ingo Molnar | 8ec67d9 | 2017-01-27 12:54:38 +0100 | [diff] [blame] | 519 | u32 need = (nr_desc - i) * sizeof(struct e820_entry) + |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 520 | sizeof(struct setup_data); |
| 521 | |
| 522 | if (!e820ext || e820ext_size < need) |
| 523 | return EFI_BUFFER_TOO_SMALL; |
| 524 | |
| 525 | /* boot_params map full, switch to e820 extended */ |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 526 | entry = (struct boot_e820_entry *)e820ext->data; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 527 | } |
| 528 | |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 529 | entry->addr = d->phys_addr; |
| 530 | entry->size = d->num_pages << PAGE_SHIFT; |
| 531 | entry->type = e820_type; |
| 532 | prev = entry++; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 533 | nr_entries++; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 534 | } |
| 535 | |
Ingo Molnar | 61a5010 | 2017-01-27 13:54:38 +0100 | [diff] [blame] | 536 | if (nr_entries > ARRAY_SIZE(params->e820_table)) { |
| 537 | u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_table); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 538 | |
| 539 | add_e820ext(params, e820ext, nr_e820ext); |
| 540 | nr_entries -= nr_e820ext; |
| 541 | } |
| 542 | |
| 543 | params->e820_entries = (u8)nr_entries; |
| 544 | |
| 545 | return EFI_SUCCESS; |
| 546 | } |
| 547 | |
| 548 | static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, |
| 549 | u32 *e820ext_size) |
| 550 | { |
| 551 | efi_status_t status; |
| 552 | unsigned long size; |
| 553 | |
| 554 | size = sizeof(struct setup_data) + |
Ingo Molnar | 8ec67d9 | 2017-01-27 12:54:38 +0100 | [diff] [blame] | 555 | sizeof(struct e820_entry) * nr_desc; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 556 | |
| 557 | if (*e820ext) { |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 558 | efi_bs_call(free_pool, *e820ext); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 559 | *e820ext = NULL; |
| 560 | *e820ext_size = 0; |
| 561 | } |
| 562 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 563 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, |
| 564 | (void **)e820ext); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 565 | if (status == EFI_SUCCESS) |
| 566 | *e820ext_size = size; |
| 567 | |
| 568 | return status; |
| 569 | } |
| 570 | |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 571 | static efi_status_t allocate_e820(struct boot_params *params, |
| 572 | struct setup_data **e820ext, |
| 573 | u32 *e820ext_size) |
| 574 | { |
| 575 | unsigned long map_size, desc_size, buff_size; |
| 576 | struct efi_boot_memmap boot_map; |
| 577 | efi_memory_desc_t *map; |
| 578 | efi_status_t status; |
| 579 | __u32 nr_desc; |
| 580 | |
| 581 | boot_map.map = ↦ |
| 582 | boot_map.map_size = &map_size; |
| 583 | boot_map.desc_size = &desc_size; |
| 584 | boot_map.desc_ver = NULL; |
| 585 | boot_map.key_ptr = NULL; |
| 586 | boot_map.buff_size = &buff_size; |
| 587 | |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 588 | status = efi_get_memory_map(&boot_map); |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 589 | if (status != EFI_SUCCESS) |
| 590 | return status; |
| 591 | |
| 592 | nr_desc = buff_size / desc_size; |
| 593 | |
| 594 | if (nr_desc > ARRAY_SIZE(params->e820_table)) { |
| 595 | u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table); |
| 596 | |
| 597 | status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size); |
| 598 | if (status != EFI_SUCCESS) |
| 599 | return status; |
| 600 | } |
| 601 | |
| 602 | return EFI_SUCCESS; |
| 603 | } |
| 604 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 605 | struct exit_boot_struct { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 606 | struct boot_params *boot_params; |
| 607 | struct efi_info *efi; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 608 | }; |
| 609 | |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 610 | static efi_status_t exit_boot_func(struct efi_boot_memmap *map, |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 611 | void *priv) |
| 612 | { |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 613 | const char *signature; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 614 | struct exit_boot_struct *p = priv; |
| 615 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 616 | signature = efi_is_64bit() ? EFI64_LOADER_SIGNATURE |
| 617 | : EFI32_LOADER_SIGNATURE; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 618 | memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32)); |
| 619 | |
Arvind Sankar | eed4e01 | 2020-04-30 14:28:34 -0400 | [diff] [blame] | 620 | efi_set_u64_split((unsigned long)efi_system_table, |
| 621 | &p->efi->efi_systab, &p->efi->efi_systab_hi); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 622 | p->efi->efi_memdesc_size = *map->desc_size; |
| 623 | p->efi->efi_memdesc_version = *map->desc_ver; |
Arvind Sankar | eed4e01 | 2020-04-30 14:28:34 -0400 | [diff] [blame] | 624 | efi_set_u64_split((unsigned long)*map->map, |
| 625 | &p->efi->efi_memmap, &p->efi->efi_memmap_hi); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 626 | p->efi->efi_memmap_size = *map->map_size; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 627 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 628 | return EFI_SUCCESS; |
| 629 | } |
| 630 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 631 | static efi_status_t exit_boot(struct boot_params *boot_params, void *handle) |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 632 | { |
Jeffrey Hugo | dadb57a | 2016-08-29 14:38:51 -0600 | [diff] [blame] | 633 | unsigned long map_sz, key, desc_size, buff_size; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 634 | efi_memory_desc_t *mem_map; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 635 | struct setup_data *e820ext = NULL; |
| 636 | __u32 e820ext_size = 0; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 637 | efi_status_t status; |
| 638 | __u32 desc_version; |
Jeffrey Hugo | dadb57a | 2016-08-29 14:38:51 -0600 | [diff] [blame] | 639 | struct efi_boot_memmap map; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 640 | struct exit_boot_struct priv; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 641 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 642 | map.map = &mem_map; |
| 643 | map.map_size = &map_sz; |
| 644 | map.desc_size = &desc_size; |
| 645 | map.desc_ver = &desc_version; |
| 646 | map.key_ptr = &key; |
| 647 | map.buff_size = &buff_size; |
| 648 | priv.boot_params = boot_params; |
| 649 | priv.efi = &boot_params->efi_info; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 650 | |
| 651 | status = allocate_e820(boot_params, &e820ext, &e820ext_size); |
| 652 | if (status != EFI_SUCCESS) |
| 653 | return status; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 654 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 655 | /* Might as well exit boot services now */ |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 656 | status = efi_exit_boot_services(handle, &map, &priv, exit_boot_func); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 657 | if (status != EFI_SUCCESS) |
| 658 | return status; |
| 659 | |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 660 | /* Historic? */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 661 | boot_params->alt_mem_k = 32 * 1024; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 662 | |
| 663 | status = setup_e820(boot_params, e820ext, e820ext_size); |
| 664 | if (status != EFI_SUCCESS) |
| 665 | return status; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 666 | |
| 667 | return EFI_SUCCESS; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 670 | /* |
Arvind Sankar | 8acf63e | 2020-03-08 09:08:43 +0100 | [diff] [blame] | 671 | * On success, we return the address of startup_32, which has potentially been |
| 672 | * relocated by efi_relocate_kernel. |
| 673 | * On failure, we exit to the firmware via efi_exit instead of returning. |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 674 | */ |
Arvind Sankar | 8acf63e | 2020-03-08 09:08:43 +0100 | [diff] [blame] | 675 | unsigned long efi_main(efi_handle_t handle, |
Ard Biesheuvel | c3710de | 2019-12-24 16:10:17 +0100 | [diff] [blame] | 676 | efi_system_table_t *sys_table_arg, |
Ard Biesheuvel | 796eb8d | 2020-01-13 18:22:33 +0100 | [diff] [blame] | 677 | struct boot_params *boot_params) |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 678 | { |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 679 | unsigned long bzimage_addr = (unsigned long)startup_32; |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 680 | unsigned long buffer_start, buffer_end; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 681 | struct setup_header *hdr = &boot_params->hdr; |
| 682 | efi_status_t status; |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 683 | |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 684 | efi_system_table = sys_table_arg; |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 685 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 686 | /* Check if we were booted by the EFI firmware */ |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 687 | if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 688 | efi_exit(handle, EFI_INVALID_PARAMETER); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 689 | |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 690 | /* |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 691 | * If the kernel isn't already loaded at a suitable address, |
| 692 | * relocate it. |
| 693 | * |
| 694 | * It must be loaded above LOAD_PHYSICAL_ADDR. |
| 695 | * |
| 696 | * The maximum address for 64-bit is 1 << 46 for 4-level paging. This |
| 697 | * is defined as the macro MAXMEM, but unfortunately that is not a |
| 698 | * compile-time constant if 5-level paging is configured, so we instead |
| 699 | * define our own macro for use here. |
| 700 | * |
| 701 | * For 32-bit, the maximum address is complicated to figure out, for |
| 702 | * now use KERNEL_IMAGE_SIZE, which will be 512MiB, the same as what |
| 703 | * KASLR uses. |
| 704 | * |
Arvind Sankar | 21cb9b4 | 2020-04-09 15:04:29 +0200 | [diff] [blame] | 705 | * Also relocate it if image_offset is zero, i.e. the kernel wasn't |
| 706 | * loaded by LoadImage, but rather by a bootloader that called the |
| 707 | * handover entry. The reason we must always relocate in this case is |
| 708 | * to handle the case of systemd-boot booting a unified kernel image, |
| 709 | * which is a PE executable that contains the bzImage and an initrd as |
| 710 | * COFF sections. The initrd section is placed after the bzImage |
| 711 | * without ensuring that there are at least init_size bytes available |
| 712 | * for the bzImage, and thus the compressed kernel's startup code may |
| 713 | * overwrite the initrd unless it is moved out of the way. |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 714 | */ |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 715 | |
| 716 | buffer_start = ALIGN(bzimage_addr - image_offset, |
| 717 | hdr->kernel_alignment); |
| 718 | buffer_end = buffer_start + hdr->init_size; |
| 719 | |
| 720 | if ((buffer_start < LOAD_PHYSICAL_ADDR) || |
| 721 | (IS_ENABLED(CONFIG_X86_32) && buffer_end > KERNEL_IMAGE_SIZE) || |
| 722 | (IS_ENABLED(CONFIG_X86_64) && buffer_end > MAXMEM_X86_64_4LEVEL) || |
Arvind Sankar | 21cb9b4 | 2020-04-09 15:04:29 +0200 | [diff] [blame] | 723 | (image_offset == 0)) { |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 724 | status = efi_relocate_kernel(&bzimage_addr, |
| 725 | hdr->init_size, hdr->init_size, |
| 726 | hdr->pref_address, |
| 727 | hdr->kernel_alignment, |
| 728 | LOAD_PHYSICAL_ADDR); |
| 729 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 730 | efi_err("efi_relocate_kernel() failed!\n"); |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 731 | goto fail; |
| 732 | } |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 733 | /* |
| 734 | * Now that we've copied the kernel elsewhere, we no longer |
| 735 | * have a set up block before startup_32(), so reset image_offset |
| 736 | * to zero in case it was set earlier. |
| 737 | */ |
| 738 | image_offset = 0; |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 739 | } |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 740 | |
Arvind Sankar | 7dde67f | 2020-04-30 14:28:42 -0400 | [diff] [blame] | 741 | #ifdef CONFIG_CMDLINE_BOOL |
Arvind Sankar | 055042b | 2020-04-30 14:28:43 -0400 | [diff] [blame] | 742 | status = efi_parse_options(CONFIG_CMDLINE); |
| 743 | if (status != EFI_SUCCESS) { |
| 744 | efi_err("Failed to parse options\n"); |
| 745 | goto fail; |
| 746 | } |
Arvind Sankar | 7dde67f | 2020-04-30 14:28:42 -0400 | [diff] [blame] | 747 | #endif |
| 748 | if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) { |
| 749 | unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr | |
| 750 | ((u64)boot_params->ext_cmd_line_ptr << 32)); |
Arvind Sankar | 055042b | 2020-04-30 14:28:43 -0400 | [diff] [blame] | 751 | status = efi_parse_options((char *)cmdline_paddr); |
| 752 | if (status != EFI_SUCCESS) { |
| 753 | efi_err("Failed to parse options\n"); |
| 754 | goto fail; |
| 755 | } |
Arvind Sankar | 7dde67f | 2020-04-30 14:28:42 -0400 | [diff] [blame] | 756 | } |
Hans de Goede | c33ce98 | 2018-09-12 20:32:05 +0200 | [diff] [blame] | 757 | |
| 758 | /* |
Arvind Sankar | 987053a | 2020-04-30 14:28:40 -0400 | [diff] [blame] | 759 | * At this point, an initrd may already have been loaded by the |
| 760 | * bootloader and passed via bootparams. We permit an initrd loaded |
| 761 | * from the LINUX_EFI_INITRD_MEDIA_GUID device path to supersede it. |
| 762 | * |
| 763 | * If the device path is not present, any command-line initrd= |
| 764 | * arguments will be processed only if image is not NULL, which will be |
| 765 | * the case only if we were loaded via the PE entry point. |
Ard Biesheuvel | ec93fc3 | 2020-02-03 23:45:14 +0000 | [diff] [blame] | 766 | */ |
Ard Biesheuvel | 980771f | 2020-04-16 18:45:24 +0200 | [diff] [blame] | 767 | if (!efi_noinitrd) { |
Ard Biesheuvel | 79d3219 | 2020-02-04 22:01:22 +0000 | [diff] [blame] | 768 | unsigned long addr, size; |
Ard Biesheuvel | 79d3219 | 2020-02-04 22:01:22 +0000 | [diff] [blame] | 769 | |
Arvind Sankar | f61900f | 2020-04-30 14:28:41 -0400 | [diff] [blame] | 770 | status = efi_load_initrd(image, &addr, &size, |
| 771 | hdr->initrd_addr_max, ULONG_MAX); |
Arvind Sankar | 987053a | 2020-04-30 14:28:40 -0400 | [diff] [blame] | 772 | |
| 773 | if (status != EFI_SUCCESS) { |
| 774 | efi_err("Failed to load initrd!\n"); |
Ard Biesheuvel | 79d3219 | 2020-02-04 22:01:22 +0000 | [diff] [blame] | 775 | goto fail; |
| 776 | } |
Arvind Sankar | 987053a | 2020-04-30 14:28:40 -0400 | [diff] [blame] | 777 | efi_set_u64_split(addr, &hdr->ramdisk_image, |
| 778 | &boot_params->ext_ramdisk_image); |
| 779 | efi_set_u64_split(size, &hdr->ramdisk_size, |
| 780 | &boot_params->ext_ramdisk_size); |
Ard Biesheuvel | ec93fc3 | 2020-02-03 23:45:14 +0000 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | /* |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 784 | * If the boot loader gave us a value for secure_boot then we use that, |
| 785 | * otherwise we ask the BIOS. |
| 786 | */ |
| 787 | if (boot_params->secure_boot == efi_secureboot_mode_unset) |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 788 | boot_params->secure_boot = efi_get_secureboot(); |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 789 | |
Matthew Garrett | ccc829b | 2017-08-25 16:50:15 +0100 | [diff] [blame] | 790 | /* Ask the firmware to clear memory on unclean shutdown */ |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 791 | efi_enable_reset_attack_mitigation(); |
Dominik Brodowski | 0d95981 | 2019-11-06 08:06:13 +0100 | [diff] [blame] | 792 | |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 793 | efi_random_get_seed(); |
Dominik Brodowski | 0d95981 | 2019-11-06 08:06:13 +0100 | [diff] [blame] | 794 | |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 795 | efi_retrieve_tpm2_eventlog(); |
Matthew Garrett | ccc829b | 2017-08-25 16:50:15 +0100 | [diff] [blame] | 796 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 797 | setup_graphics(boot_params); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 798 | |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 799 | setup_efi_pci(boot_params); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 800 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 801 | setup_quirks(boot_params); |
| 802 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 803 | status = exit_boot(boot_params, handle); |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 804 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 805 | efi_err("exit_boot() failed!\n"); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 806 | goto fail; |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 807 | } |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 808 | |
Arvind Sankar | 8acf63e | 2020-03-08 09:08:43 +0100 | [diff] [blame] | 809 | return bzimage_addr; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 810 | fail: |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 811 | efi_err("efi_main() failed!\n"); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 812 | |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 813 | efi_exit(handle, status); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 814 | } |