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> |
Arvind Sankar | 59476f80 | 2020-06-18 16:43:15 -0400 | [diff] [blame] | 11 | #include <linux/stddef.h> |
Ingo Molnar | 5520b7e | 2017-01-27 11:59:46 +0100 | [diff] [blame] | 12 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 13 | #include <asm/efi.h> |
Ingo Molnar | 5520b7e | 2017-01-27 11:59:46 +0100 | [diff] [blame] | 14 | #include <asm/e820/types.h> |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 15 | #include <asm/setup.h> |
| 16 | #include <asm/desc.h> |
Kairui Song | 220dd76 | 2019-10-29 18:37:54 +0100 | [diff] [blame] | 17 | #include <asm/boot.h> |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 18 | |
Ard Biesheuvel | c2d0b47 | 2020-02-10 17:02:36 +0100 | [diff] [blame] | 19 | #include "efistub.h" |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 20 | |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 21 | /* Maximum physical address for 64-bit kernel with 4-level paging */ |
| 22 | #define MAXMEM_X86_64_4LEVEL (1ull << 46) |
| 23 | |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 24 | const efi_system_table_t *efi_system_table; |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 25 | extern u32 image_offset; |
Arvind Sankar | 987053a | 2020-04-30 14:28:40 -0400 | [diff] [blame] | 26 | static efi_loaded_image_t *image = NULL; |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 27 | |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 28 | static efi_status_t |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 29 | 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] | 30 | { |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 31 | struct pci_setup_rom *rom = NULL; |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 32 | efi_status_t status; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 33 | unsigned long size; |
Ard Biesheuvel | e296701 | 2018-07-11 11:02:35 +0200 | [diff] [blame] | 34 | uint64_t romsize; |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 35 | void *romimage; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 36 | |
Hans de Goede | 1de3a1b | 2018-05-04 08:00:01 +0200 | [diff] [blame] | 37 | /* |
Ard Biesheuvel | e296701 | 2018-07-11 11:02:35 +0200 | [diff] [blame] | 38 | * Some firmware images contain EFI function pointers at the place where |
| 39 | * 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] | 40 | * code is mapped at high addresses, translating to an unrealistically |
| 41 | * large romsize. The UEFI spec limits the size of option ROMs to 16 |
| 42 | * MiB so we reject any ROMs over 16 MiB in size to catch this. |
| 43 | */ |
Ard Biesheuvel | 99ea8b1 | 2019-12-24 16:10:22 +0100 | [diff] [blame] | 44 | romimage = efi_table_attr(pci, romimage); |
| 45 | romsize = efi_table_attr(pci, romsize); |
Hans de Goede | 1de3a1b | 2018-05-04 08:00:01 +0200 | [diff] [blame] | 46 | if (!romimage || !romsize || romsize > SZ_16M) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 47 | return EFI_INVALID_PARAMETER; |
| 48 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 49 | size = romsize + sizeof(*rom); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 50 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 51 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, |
| 52 | (void **)&rom); |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 53 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 54 | efi_err("Failed to allocate memory for 'rom'\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 55 | return status; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 56 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 57 | |
| 58 | memset(rom, 0, sizeof(*rom)); |
| 59 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 60 | rom->data.type = SETUP_PCI; |
| 61 | rom->data.len = size - sizeof(struct setup_data); |
| 62 | rom->data.next = 0; |
| 63 | rom->pcilen = pci->romsize; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 64 | *__rom = rom; |
| 65 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 66 | status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, |
| 67 | PCI_VENDOR_ID, 1, &rom->vendor); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 68 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 69 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 70 | efi_err("Failed to read rom->vendor\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 71 | goto free_struct; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 72 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 73 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 74 | status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, |
| 75 | PCI_DEVICE_ID, 1, &rom->devid); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 76 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 77 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 78 | efi_err("Failed to read rom->devid\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 79 | goto free_struct; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 80 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 81 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 82 | status = efi_call_proto(pci, get_location, &rom->segment, &rom->bus, |
| 83 | &rom->device, &rom->function); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 84 | |
| 85 | if (status != EFI_SUCCESS) |
| 86 | goto free_struct; |
| 87 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 88 | memcpy(rom->romdata, romimage, romsize); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 89 | return status; |
| 90 | |
| 91 | free_struct: |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 92 | efi_bs_call(free_pool, rom); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 93 | return status; |
| 94 | } |
| 95 | |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 96 | /* |
| 97 | * There's no way to return an informative status from this function, |
| 98 | * because any analysis (and printing of error messages) needs to be |
| 99 | * done directly at the EFI function call-site. |
| 100 | * |
| 101 | * For example, EFI_INVALID_PARAMETER could indicate a bug or maybe we |
| 102 | * just didn't find any PCI devices, but there's no way to tell outside |
| 103 | * the context of the call. |
| 104 | */ |
| 105 | static void setup_efi_pci(struct boot_params *params) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 106 | { |
| 107 | efi_status_t status; |
| 108 | void **pci_handle = NULL; |
| 109 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; |
| 110 | unsigned long size = 0; |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 111 | struct setup_data *data; |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 112 | efi_handle_t h; |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 113 | int i; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 114 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 115 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 116 | &pci_proto, NULL, &size, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 117 | |
| 118 | if (status == EFI_BUFFER_TOO_SMALL) { |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 119 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, |
| 120 | (void **)&pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 121 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 122 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 123 | efi_err("Failed to allocate memory for 'pci_handle'\n"); |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 124 | return; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 125 | } |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 126 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 127 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 128 | &pci_proto, NULL, &size, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | if (status != EFI_SUCCESS) |
| 132 | goto free_handle; |
| 133 | |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 134 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; |
| 135 | |
| 136 | while (data && data->next) |
| 137 | data = (struct setup_data *)(unsigned long)data->next; |
| 138 | |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 139 | for_each_efi_handle(h, pci_handle, size, i) { |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 140 | efi_pci_io_protocol_t *pci = NULL; |
| 141 | struct pci_setup_rom *rom; |
| 142 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 143 | status = efi_bs_call(handle_protocol, h, &pci_proto, |
| 144 | (void **)&pci); |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 145 | if (status != EFI_SUCCESS || !pci) |
| 146 | continue; |
| 147 | |
| 148 | status = preserve_pci_rom_image(pci, &rom); |
| 149 | if (status != EFI_SUCCESS) |
| 150 | continue; |
| 151 | |
| 152 | if (data) |
| 153 | data->next = (unsigned long)rom; |
| 154 | else |
| 155 | params->hdr.setup_data = (unsigned long)rom; |
| 156 | |
| 157 | data = (struct setup_data *)rom; |
| 158 | } |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 159 | |
| 160 | free_handle: |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 161 | efi_bs_call(free_pool, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 164 | static void retrieve_apple_device_properties(struct boot_params *boot_params) |
| 165 | { |
| 166 | efi_guid_t guid = APPLE_PROPERTIES_PROTOCOL_GUID; |
| 167 | struct setup_data *data, *new; |
| 168 | efi_status_t status; |
| 169 | u32 size = 0; |
Ard Biesheuvel | 960a8d0 | 2019-12-24 16:10:11 +0100 | [diff] [blame] | 170 | apple_properties_protocol_t *p; |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 171 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 172 | status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&p); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 173 | if (status != EFI_SUCCESS) |
| 174 | return; |
| 175 | |
Ard Biesheuvel | 99ea8b1 | 2019-12-24 16:10:22 +0100 | [diff] [blame] | 176 | if (efi_table_attr(p, version) != 0x10000) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 177 | efi_err("Unsupported properties proto version\n"); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 181 | efi_call_proto(p, get_all, NULL, &size); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 182 | if (!size) |
| 183 | return; |
| 184 | |
| 185 | do { |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 186 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, |
| 187 | size + sizeof(struct setup_data), |
| 188 | (void **)&new); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 189 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 190 | efi_err("Failed to allocate memory for 'properties'\n"); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 194 | status = efi_call_proto(p, get_all, new->data, &size); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 195 | |
| 196 | if (status == EFI_BUFFER_TOO_SMALL) |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 197 | efi_bs_call(free_pool, new); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 198 | } while (status == EFI_BUFFER_TOO_SMALL); |
| 199 | |
| 200 | new->type = SETUP_APPLE_PROPERTIES; |
| 201 | new->len = size; |
| 202 | new->next = 0; |
| 203 | |
| 204 | data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 205 | if (!data) { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 206 | boot_params->hdr.setup_data = (unsigned long)new; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 207 | } else { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 208 | while (data->next) |
| 209 | data = (struct setup_data *)(unsigned long)data->next; |
| 210 | data->next = (unsigned long)new; |
| 211 | } |
| 212 | } |
| 213 | |
Ard Biesheuvel | 36b6497 | 2018-03-12 08:45:00 +0000 | [diff] [blame] | 214 | static const efi_char16_t apple[] = L"Apple"; |
| 215 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 216 | static void setup_quirks(struct boot_params *boot_params) |
| 217 | { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 218 | efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long) |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 219 | efi_table_attr(efi_system_table, fw_vendor); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 220 | |
| 221 | if (!memcmp(fw_vendor, apple, sizeof(apple))) { |
| 222 | if (IS_ENABLED(CONFIG_APPLE_PROPERTIES)) |
| 223 | retrieve_apple_device_properties(boot_params); |
| 224 | } |
| 225 | } |
| 226 | |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 227 | /* |
| 228 | * See if we have Universal Graphics Adapter (UGA) protocol |
| 229 | */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 230 | static efi_status_t |
| 231 | 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] | 232 | { |
| 233 | efi_status_t status; |
| 234 | u32 width, height; |
| 235 | void **uga_handle = NULL; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 236 | efi_uga_draw_protocol_t *uga = NULL, *first_uga; |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 237 | efi_handle_t handle; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 238 | int i; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 239 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 240 | status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, |
| 241 | (void **)&uga_handle); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 242 | if (status != EFI_SUCCESS) |
| 243 | return status; |
| 244 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 245 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 246 | uga_proto, NULL, &size, uga_handle); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 247 | if (status != EFI_SUCCESS) |
| 248 | goto free_handle; |
| 249 | |
| 250 | height = 0; |
| 251 | width = 0; |
| 252 | |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 253 | first_uga = NULL; |
Ard Biesheuvel | 2732ea0 | 2019-12-24 16:10:07 +0100 | [diff] [blame] | 254 | for_each_efi_handle(handle, uga_handle, size, i) { |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 255 | efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; |
| 256 | u32 w, h, depth, refresh; |
| 257 | void *pciio; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 258 | |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 259 | status = efi_bs_call(handle_protocol, handle, uga_proto, |
| 260 | (void **)&uga); |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 261 | if (status != EFI_SUCCESS) |
| 262 | continue; |
| 263 | |
Ard Biesheuvel | 093174f | 2018-07-20 10:47:22 +0900 | [diff] [blame] | 264 | pciio = NULL; |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 265 | efi_bs_call(handle_protocol, handle, &pciio_proto, &pciio); |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 266 | |
Ard Biesheuvel | 47c0fd3 | 2019-12-24 16:10:21 +0100 | [diff] [blame] | 267 | status = efi_call_proto(uga, get_mode, &w, &h, &depth, &refresh); |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 268 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { |
| 269 | width = w; |
| 270 | height = h; |
| 271 | |
| 272 | /* |
| 273 | * Once we've found a UGA supporting PCIIO, |
| 274 | * don't bother looking any further. |
| 275 | */ |
| 276 | if (pciio) |
| 277 | break; |
| 278 | |
| 279 | first_uga = uga; |
| 280 | } |
| 281 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 282 | |
| 283 | if (!width && !height) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 284 | goto free_handle; |
| 285 | |
| 286 | /* EFI framebuffer */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 287 | si->orig_video_isVGA = VIDEO_TYPE_EFI; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 288 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 289 | si->lfb_depth = 32; |
| 290 | si->lfb_width = width; |
| 291 | si->lfb_height = height; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 292 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 293 | si->red_size = 8; |
| 294 | si->red_pos = 16; |
| 295 | si->green_size = 8; |
| 296 | si->green_pos = 8; |
| 297 | si->blue_size = 8; |
| 298 | si->blue_pos = 0; |
| 299 | si->rsvd_size = 8; |
| 300 | si->rsvd_pos = 24; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 301 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 302 | free_handle: |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 303 | efi_bs_call(free_pool, uga_handle); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 304 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 305 | return status; |
| 306 | } |
| 307 | |
Arvind Sankar | f32ea1c | 2020-01-30 17:20:04 -0500 | [diff] [blame] | 308 | static void setup_graphics(struct boot_params *boot_params) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 309 | { |
| 310 | efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; |
| 311 | struct screen_info *si; |
| 312 | efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; |
| 313 | efi_status_t status; |
| 314 | unsigned long size; |
| 315 | void **gop_handle = NULL; |
| 316 | void **uga_handle = NULL; |
| 317 | |
| 318 | si = &boot_params->screen_info; |
| 319 | memset(si, 0, sizeof(*si)); |
| 320 | |
| 321 | size = 0; |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 322 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 323 | &graphics_proto, NULL, &size, gop_handle); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 324 | if (status == EFI_BUFFER_TOO_SMALL) |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 325 | status = efi_setup_gop(si, &graphics_proto, size); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 326 | |
| 327 | if (status != EFI_SUCCESS) { |
| 328 | size = 0; |
Ard Biesheuvel | 966291f | 2019-12-24 16:10:23 +0100 | [diff] [blame] | 329 | status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, |
| 330 | &uga_proto, NULL, &size, uga_handle); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 331 | if (status == EFI_BUFFER_TOO_SMALL) |
| 332 | setup_uga(si, &uga_proto, size); |
| 333 | } |
| 334 | } |
| 335 | |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 336 | |
| 337 | static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status) |
| 338 | { |
| 339 | efi_bs_call(exit, handle, status, 0, NULL); |
Ard Biesheuvel | f3fa0ef | 2020-03-08 09:08:45 +0100 | [diff] [blame] | 340 | for(;;) |
| 341 | asm("hlt"); |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Ard Biesheuvel | c3710de | 2019-12-24 16:10:17 +0100 | [diff] [blame] | 344 | void startup_32(struct boot_params *boot_params); |
| 345 | |
| 346 | void __noreturn efi_stub_entry(efi_handle_t handle, |
| 347 | efi_system_table_t *sys_table_arg, |
| 348 | struct boot_params *boot_params); |
| 349 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 350 | /* |
| 351 | * Because the x86 boot code expects to be passed a boot_params we |
| 352 | * need to create one ourselves (usually the bootloader would create |
| 353 | * one for us). |
| 354 | */ |
Ard Biesheuvel | c3710de | 2019-12-24 16:10:17 +0100 | [diff] [blame] | 355 | efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, |
| 356 | efi_system_table_t *sys_table_arg) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 357 | { |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 358 | struct boot_params *boot_params; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 359 | struct setup_header *hdr; |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 360 | void *image_base; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 361 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 362 | int options_size = 0; |
| 363 | efi_status_t status; |
Roy Franz | 5fef387 | 2013-09-22 15:45:33 -0700 | [diff] [blame] | 364 | char *cmdline_ptr; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 365 | |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 366 | efi_system_table = sys_table_arg; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 367 | |
| 368 | /* Check if we were booted by the EFI firmware */ |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 369 | if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 370 | efi_exit(handle, EFI_INVALID_PARAMETER); |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 371 | |
Arvind Sankar | 0347d8c2 | 2020-03-08 09:08:58 +0100 | [diff] [blame] | 372 | status = efi_bs_call(handle_protocol, handle, &proto, (void **)&image); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 373 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 374 | efi_err("Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 375 | efi_exit(handle, status); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 376 | } |
| 377 | |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 378 | image_base = efi_table_attr(image, image_base); |
| 379 | image_offset = (void *)startup_32 - image_base; |
| 380 | |
Arvind Sankar | 019512f | 2020-04-30 14:28:33 -0400 | [diff] [blame] | 381 | status = efi_allocate_pages(sizeof(struct boot_params), |
| 382 | (unsigned long *)&boot_params, ULONG_MAX); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 383 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 384 | efi_err("Failed to allocate lowmem for boot params\n"); |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 385 | efi_exit(handle, status); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Arvind Sankar | 019512f | 2020-04-30 14:28:33 -0400 | [diff] [blame] | 388 | memset(boot_params, 0x0, sizeof(struct boot_params)); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 389 | |
| 390 | hdr = &boot_params->hdr; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 391 | |
Arvind Sankar | 59476f80 | 2020-06-18 16:43:15 -0400 | [diff] [blame] | 392 | /* Copy the setup header from the second sector to boot_params */ |
| 393 | memcpy(&hdr->jump, image_base + 512, |
| 394 | sizeof(struct setup_header) - offsetof(struct setup_header, jump)); |
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 | { |
Lenny Szubowicz | fd62619 | 2020-05-07 14:33:32 -0400 | [diff] [blame] | 575 | unsigned long map_size, desc_size, map_key; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 576 | efi_status_t status; |
Lenny Szubowicz | fd62619 | 2020-05-07 14:33:32 -0400 | [diff] [blame] | 577 | __u32 nr_desc, desc_version; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 578 | |
Lenny Szubowicz | fd62619 | 2020-05-07 14:33:32 -0400 | [diff] [blame] | 579 | /* Only need the size of the mem map and size of each mem descriptor */ |
| 580 | map_size = 0; |
| 581 | status = efi_bs_call(get_memory_map, &map_size, NULL, &map_key, |
| 582 | &desc_size, &desc_version); |
| 583 | if (status != EFI_BUFFER_TOO_SMALL) |
| 584 | return (status != EFI_SUCCESS) ? status : EFI_UNSUPPORTED; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 585 | |
Lenny Szubowicz | fd62619 | 2020-05-07 14:33:32 -0400 | [diff] [blame] | 586 | nr_desc = map_size / desc_size + EFI_MMAP_NR_SLACK_SLOTS; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 587 | |
| 588 | if (nr_desc > ARRAY_SIZE(params->e820_table)) { |
| 589 | u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table); |
| 590 | |
| 591 | status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size); |
| 592 | if (status != EFI_SUCCESS) |
| 593 | return status; |
| 594 | } |
| 595 | |
| 596 | return EFI_SUCCESS; |
| 597 | } |
| 598 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 599 | struct exit_boot_struct { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 600 | struct boot_params *boot_params; |
| 601 | struct efi_info *efi; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 602 | }; |
| 603 | |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 604 | static efi_status_t exit_boot_func(struct efi_boot_memmap *map, |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 605 | void *priv) |
| 606 | { |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 607 | const char *signature; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 608 | struct exit_boot_struct *p = priv; |
| 609 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 610 | signature = efi_is_64bit() ? EFI64_LOADER_SIGNATURE |
| 611 | : EFI32_LOADER_SIGNATURE; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 612 | memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32)); |
| 613 | |
Arvind Sankar | eed4e01 | 2020-04-30 14:28:34 -0400 | [diff] [blame] | 614 | efi_set_u64_split((unsigned long)efi_system_table, |
| 615 | &p->efi->efi_systab, &p->efi->efi_systab_hi); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 616 | p->efi->efi_memdesc_size = *map->desc_size; |
| 617 | p->efi->efi_memdesc_version = *map->desc_ver; |
Arvind Sankar | eed4e01 | 2020-04-30 14:28:34 -0400 | [diff] [blame] | 618 | efi_set_u64_split((unsigned long)*map->map, |
| 619 | &p->efi->efi_memmap, &p->efi->efi_memmap_hi); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 620 | p->efi->efi_memmap_size = *map->map_size; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 621 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 622 | return EFI_SUCCESS; |
| 623 | } |
| 624 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 625 | 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] | 626 | { |
Jeffrey Hugo | dadb57a | 2016-08-29 14:38:51 -0600 | [diff] [blame] | 627 | unsigned long map_sz, key, desc_size, buff_size; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 628 | efi_memory_desc_t *mem_map; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 629 | struct setup_data *e820ext = NULL; |
| 630 | __u32 e820ext_size = 0; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 631 | efi_status_t status; |
| 632 | __u32 desc_version; |
Jeffrey Hugo | dadb57a | 2016-08-29 14:38:51 -0600 | [diff] [blame] | 633 | struct efi_boot_memmap map; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 634 | struct exit_boot_struct priv; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 635 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 636 | map.map = &mem_map; |
| 637 | map.map_size = &map_sz; |
| 638 | map.desc_size = &desc_size; |
| 639 | map.desc_ver = &desc_version; |
| 640 | map.key_ptr = &key; |
| 641 | map.buff_size = &buff_size; |
| 642 | priv.boot_params = boot_params; |
| 643 | priv.efi = &boot_params->efi_info; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame] | 644 | |
| 645 | status = allocate_e820(boot_params, &e820ext, &e820ext_size); |
| 646 | if (status != EFI_SUCCESS) |
| 647 | return status; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 648 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 649 | /* Might as well exit boot services now */ |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 650 | status = efi_exit_boot_services(handle, &map, &priv, exit_boot_func); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 651 | if (status != EFI_SUCCESS) |
| 652 | return status; |
| 653 | |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 654 | /* Historic? */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 655 | boot_params->alt_mem_k = 32 * 1024; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 656 | |
| 657 | status = setup_e820(boot_params, e820ext, e820ext_size); |
| 658 | if (status != EFI_SUCCESS) |
| 659 | return status; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 660 | |
| 661 | return EFI_SUCCESS; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 664 | /* |
Arvind Sankar | 8acf63e | 2020-03-08 09:08:43 +0100 | [diff] [blame] | 665 | * On success, we return the address of startup_32, which has potentially been |
| 666 | * relocated by efi_relocate_kernel. |
| 667 | * 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] | 668 | */ |
Arvind Sankar | 8acf63e | 2020-03-08 09:08:43 +0100 | [diff] [blame] | 669 | unsigned long efi_main(efi_handle_t handle, |
Ard Biesheuvel | c3710de | 2019-12-24 16:10:17 +0100 | [diff] [blame] | 670 | efi_system_table_t *sys_table_arg, |
Ard Biesheuvel | 796eb8d | 2020-01-13 18:22:33 +0100 | [diff] [blame] | 671 | struct boot_params *boot_params) |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 672 | { |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 673 | unsigned long bzimage_addr = (unsigned long)startup_32; |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 674 | unsigned long buffer_start, buffer_end; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 675 | struct setup_header *hdr = &boot_params->hdr; |
Ard Biesheuvel | 20287d5 | 2021-11-19 13:47:44 +0200 | [diff] [blame] | 676 | unsigned long addr, size; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 677 | efi_status_t status; |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 678 | |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 679 | efi_system_table = sys_table_arg; |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 680 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 681 | /* Check if we were booted by the EFI firmware */ |
Ard Biesheuvel | ccc27ae | 2020-04-16 18:38:06 +0200 | [diff] [blame] | 682 | if (efi_system_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 683 | efi_exit(handle, EFI_INVALID_PARAMETER); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 684 | |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 685 | /* |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 686 | * If the kernel isn't already loaded at a suitable address, |
| 687 | * relocate it. |
| 688 | * |
| 689 | * It must be loaded above LOAD_PHYSICAL_ADDR. |
| 690 | * |
| 691 | * The maximum address for 64-bit is 1 << 46 for 4-level paging. This |
| 692 | * is defined as the macro MAXMEM, but unfortunately that is not a |
| 693 | * compile-time constant if 5-level paging is configured, so we instead |
| 694 | * define our own macro for use here. |
| 695 | * |
| 696 | * For 32-bit, the maximum address is complicated to figure out, for |
| 697 | * now use KERNEL_IMAGE_SIZE, which will be 512MiB, the same as what |
| 698 | * KASLR uses. |
| 699 | * |
Arvind Sankar | 21cb9b4 | 2020-04-09 15:04:29 +0200 | [diff] [blame] | 700 | * Also relocate it if image_offset is zero, i.e. the kernel wasn't |
| 701 | * loaded by LoadImage, but rather by a bootloader that called the |
| 702 | * handover entry. The reason we must always relocate in this case is |
| 703 | * to handle the case of systemd-boot booting a unified kernel image, |
| 704 | * which is a PE executable that contains the bzImage and an initrd as |
| 705 | * COFF sections. The initrd section is placed after the bzImage |
| 706 | * without ensuring that there are at least init_size bytes available |
| 707 | * for the bzImage, and thus the compressed kernel's startup code may |
| 708 | * overwrite the initrd unless it is moved out of the way. |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 709 | */ |
Arvind Sankar | d5cdf4c | 2020-03-08 09:08:50 +0100 | [diff] [blame] | 710 | |
| 711 | buffer_start = ALIGN(bzimage_addr - image_offset, |
| 712 | hdr->kernel_alignment); |
| 713 | buffer_end = buffer_start + hdr->init_size; |
| 714 | |
| 715 | if ((buffer_start < LOAD_PHYSICAL_ADDR) || |
| 716 | (IS_ENABLED(CONFIG_X86_32) && buffer_end > KERNEL_IMAGE_SIZE) || |
| 717 | (IS_ENABLED(CONFIG_X86_64) && buffer_end > MAXMEM_X86_64_4LEVEL) || |
Arvind Sankar | 21cb9b4 | 2020-04-09 15:04:29 +0200 | [diff] [blame] | 718 | (image_offset == 0)) { |
Arvind Sankar | 688eb28 | 2020-10-11 10:20:12 -0400 | [diff] [blame] | 719 | extern char _bss[]; |
| 720 | |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 721 | status = efi_relocate_kernel(&bzimage_addr, |
Arvind Sankar | 688eb28 | 2020-10-11 10:20:12 -0400 | [diff] [blame] | 722 | (unsigned long)_bss - bzimage_addr, |
| 723 | hdr->init_size, |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 724 | hdr->pref_address, |
| 725 | hdr->kernel_alignment, |
| 726 | LOAD_PHYSICAL_ADDR); |
| 727 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 728 | efi_err("efi_relocate_kernel() failed!\n"); |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 729 | goto fail; |
| 730 | } |
Arvind Sankar | 1887c9b | 2020-03-08 09:08:47 +0100 | [diff] [blame] | 731 | /* |
| 732 | * Now that we've copied the kernel elsewhere, we no longer |
| 733 | * have a set up block before startup_32(), so reset image_offset |
| 734 | * to zero in case it was set earlier. |
| 735 | */ |
| 736 | image_offset = 0; |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 737 | } |
Ard Biesheuvel | 04a7d0e | 2020-02-10 17:02:31 +0100 | [diff] [blame] | 738 | |
Arvind Sankar | 7dde67f | 2020-04-30 14:28:42 -0400 | [diff] [blame] | 739 | #ifdef CONFIG_CMDLINE_BOOL |
Arvind Sankar | 055042b | 2020-04-30 14:28:43 -0400 | [diff] [blame] | 740 | status = efi_parse_options(CONFIG_CMDLINE); |
| 741 | if (status != EFI_SUCCESS) { |
| 742 | efi_err("Failed to parse options\n"); |
| 743 | goto fail; |
| 744 | } |
Arvind Sankar | 7dde67f | 2020-04-30 14:28:42 -0400 | [diff] [blame] | 745 | #endif |
| 746 | if (!IS_ENABLED(CONFIG_CMDLINE_OVERRIDE)) { |
| 747 | unsigned long cmdline_paddr = ((u64)hdr->cmd_line_ptr | |
| 748 | ((u64)boot_params->ext_cmd_line_ptr << 32)); |
Arvind Sankar | 055042b | 2020-04-30 14:28:43 -0400 | [diff] [blame] | 749 | status = efi_parse_options((char *)cmdline_paddr); |
| 750 | if (status != EFI_SUCCESS) { |
| 751 | efi_err("Failed to parse options\n"); |
| 752 | goto fail; |
| 753 | } |
Arvind Sankar | 7dde67f | 2020-04-30 14:28:42 -0400 | [diff] [blame] | 754 | } |
Hans de Goede | c33ce98 | 2018-09-12 20:32:05 +0200 | [diff] [blame] | 755 | |
| 756 | /* |
Arvind Sankar | 987053a | 2020-04-30 14:28:40 -0400 | [diff] [blame] | 757 | * At this point, an initrd may already have been loaded by the |
| 758 | * bootloader and passed via bootparams. We permit an initrd loaded |
| 759 | * from the LINUX_EFI_INITRD_MEDIA_GUID device path to supersede it. |
| 760 | * |
| 761 | * If the device path is not present, any command-line initrd= |
| 762 | * arguments will be processed only if image is not NULL, which will be |
| 763 | * the case only if we were loaded via the PE entry point. |
Ard Biesheuvel | ec93fc3 | 2020-02-03 23:45:14 +0000 | [diff] [blame] | 764 | */ |
Ard Biesheuvel | 20287d5 | 2021-11-19 13:47:44 +0200 | [diff] [blame] | 765 | status = efi_load_initrd(image, &addr, &size, hdr->initrd_addr_max, |
| 766 | ULONG_MAX); |
| 767 | if (status != EFI_SUCCESS) |
| 768 | goto fail; |
| 769 | if (size > 0) { |
| 770 | efi_set_u64_split(addr, &hdr->ramdisk_image, |
| 771 | &boot_params->ext_ramdisk_image); |
| 772 | efi_set_u64_split(size, &hdr->ramdisk_size, |
| 773 | &boot_params->ext_ramdisk_size); |
Ard Biesheuvel | ec93fc3 | 2020-02-03 23:45:14 +0000 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 777 | * If the boot loader gave us a value for secure_boot then we use that, |
| 778 | * otherwise we ask the BIOS. |
| 779 | */ |
| 780 | if (boot_params->secure_boot == efi_secureboot_mode_unset) |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 781 | boot_params->secure_boot = efi_get_secureboot(); |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 782 | |
Matthew Garrett | ccc829b | 2017-08-25 16:50:15 +0100 | [diff] [blame] | 783 | /* Ask the firmware to clear memory on unclean shutdown */ |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 784 | efi_enable_reset_attack_mitigation(); |
Dominik Brodowski | 0d95981 | 2019-11-06 08:06:13 +0100 | [diff] [blame] | 785 | |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 786 | efi_random_get_seed(); |
Dominik Brodowski | 0d95981 | 2019-11-06 08:06:13 +0100 | [diff] [blame] | 787 | |
Ard Biesheuvel | cd33a5c | 2019-12-24 16:10:19 +0100 | [diff] [blame] | 788 | efi_retrieve_tpm2_eventlog(); |
Matthew Garrett | ccc829b | 2017-08-25 16:50:15 +0100 | [diff] [blame] | 789 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 790 | setup_graphics(boot_params); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 791 | |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 792 | setup_efi_pci(boot_params); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 793 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 794 | setup_quirks(boot_params); |
| 795 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 796 | status = exit_boot(boot_params, handle); |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 797 | if (status != EFI_SUCCESS) { |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 798 | efi_err("exit_boot() failed!\n"); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 799 | goto fail; |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 800 | } |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 801 | |
Arvind Sankar | 8acf63e | 2020-03-08 09:08:43 +0100 | [diff] [blame] | 802 | return bzimage_addr; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 803 | fail: |
Arvind Sankar | 36bdd0a | 2020-04-30 14:28:36 -0400 | [diff] [blame] | 804 | efi_err("efi_main() failed!\n"); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 805 | |
Ard Biesheuvel | 3b8f44f | 2020-02-16 00:03:25 +0100 | [diff] [blame] | 806 | efi_exit(handle, status); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 807 | } |