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