Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame^] | 1 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 2 | /* ----------------------------------------------------------------------- |
| 3 | * |
| 4 | * Copyright 2011 Intel Corporation; author Matt Fleming |
| 5 | * |
| 6 | * This file is part of the Linux kernel, and is made available under |
| 7 | * the terms of the GNU General Public License version 2. |
| 8 | * |
| 9 | * ----------------------------------------------------------------------- */ |
| 10 | |
| 11 | #include <linux/efi.h> |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 12 | #include <linux/pci.h> |
Ingo Molnar | 5520b7e | 2017-01-27 11:59:46 +0100 | [diff] [blame] | 13 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 14 | #include <asm/efi.h> |
Ingo Molnar | 5520b7e | 2017-01-27 11:59:46 +0100 | [diff] [blame] | 15 | #include <asm/e820/types.h> |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 16 | #include <asm/setup.h> |
| 17 | #include <asm/desc.h> |
| 18 | |
Andrey Ryabinin | 393f203 | 2015-02-13 14:39:56 -0800 | [diff] [blame] | 19 | #include "../string.h" |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 20 | #include "eboot.h" |
| 21 | |
| 22 | static efi_system_table_t *sys_table; |
| 23 | |
Matt Fleming | 84be880 | 2014-09-23 10:37:43 +0100 | [diff] [blame] | 24 | static struct efi_config *efi_early; |
| 25 | |
Ard Biesheuvel | 243b675 | 2014-11-05 17:00:56 +0100 | [diff] [blame] | 26 | __pure const struct efi_config *__efi_early(void) |
| 27 | { |
| 28 | return efi_early; |
| 29 | } |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 30 | |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 31 | #define BOOT_SERVICES(bits) \ |
| 32 | static void setup_boot_services##bits(struct efi_config *c) \ |
| 33 | { \ |
| 34 | efi_system_table_##bits##_t *table; \ |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 35 | \ |
| 36 | table = (typeof(table))sys_table; \ |
| 37 | \ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 38 | c->runtime_services = table->runtime; \ |
| 39 | c->boot_services = table->boottime; \ |
| 40 | c->text_output = table->con_out; \ |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 41 | } |
| 42 | BOOT_SERVICES(32); |
| 43 | BOOT_SERVICES(64); |
| 44 | |
Ard Biesheuvel | bd66947 | 2014-07-02 14:54:42 +0200 | [diff] [blame] | 45 | void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 46 | { |
Lukas Wunner | db4545d | 2017-01-31 13:21:34 +0000 | [diff] [blame] | 47 | efi_call_proto(efi_simple_text_output_protocol, output_string, |
| 48 | efi_early->text_output, str); |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 49 | } |
Lee, Chun-Yi | deb9410 | 2012-12-20 19:33:22 +0800 | [diff] [blame] | 50 | |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 51 | static efi_status_t |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 52 | 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] | 53 | { |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 54 | struct pci_setup_rom *rom = NULL; |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 55 | efi_status_t status; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 56 | unsigned long size; |
Ard Biesheuvel | e296701 | 2018-07-11 11:02:35 +0200 | [diff] [blame] | 57 | uint64_t romsize; |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 58 | void *romimage; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 59 | |
Hans de Goede | 1de3a1b | 2018-05-04 08:00:01 +0200 | [diff] [blame] | 60 | /* |
Ard Biesheuvel | e296701 | 2018-07-11 11:02:35 +0200 | [diff] [blame] | 61 | * Some firmware images contain EFI function pointers at the place where |
| 62 | * 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] | 63 | * code is mapped at high addresses, translating to an unrealistically |
| 64 | * large romsize. The UEFI spec limits the size of option ROMs to 16 |
| 65 | * MiB so we reject any ROMs over 16 MiB in size to catch this. |
| 66 | */ |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 67 | romimage = (void *)(unsigned long)efi_table_attr(efi_pci_io_protocol, |
| 68 | romimage, pci); |
| 69 | romsize = efi_table_attr(efi_pci_io_protocol, romsize, pci); |
Hans de Goede | 1de3a1b | 2018-05-04 08:00:01 +0200 | [diff] [blame] | 70 | if (!romimage || !romsize || romsize > SZ_16M) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 71 | return EFI_INVALID_PARAMETER; |
| 72 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 73 | size = romsize + sizeof(*rom); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 74 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 75 | status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 76 | if (status != EFI_SUCCESS) { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 77 | efi_printk(sys_table, "Failed to allocate memory for 'rom'\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 78 | return status; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 79 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 80 | |
| 81 | memset(rom, 0, sizeof(*rom)); |
| 82 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 83 | rom->data.type = SETUP_PCI; |
| 84 | rom->data.len = size - sizeof(struct setup_data); |
| 85 | rom->data.next = 0; |
| 86 | rom->pcilen = pci->romsize; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 87 | *__rom = rom; |
| 88 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 89 | status = efi_call_proto(efi_pci_io_protocol, pci.read, pci, |
| 90 | EfiPciIoWidthUint16, PCI_VENDOR_ID, 1, |
| 91 | &rom->vendor); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 92 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 93 | if (status != EFI_SUCCESS) { |
| 94 | efi_printk(sys_table, "Failed to read rom->vendor\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 95 | goto free_struct; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 96 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 97 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 98 | status = efi_call_proto(efi_pci_io_protocol, pci.read, pci, |
| 99 | EfiPciIoWidthUint16, PCI_DEVICE_ID, 1, |
| 100 | &rom->devid); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 101 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 102 | if (status != EFI_SUCCESS) { |
| 103 | efi_printk(sys_table, "Failed to read rom->devid\n"); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 104 | goto free_struct; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 105 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 106 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 107 | status = efi_call_proto(efi_pci_io_protocol, get_location, pci, |
| 108 | &rom->segment, &rom->bus, &rom->device, |
| 109 | &rom->function); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 110 | |
| 111 | if (status != EFI_SUCCESS) |
| 112 | goto free_struct; |
| 113 | |
Ard Biesheuvel | 2c3625c | 2018-05-04 08:00:00 +0200 | [diff] [blame] | 114 | memcpy(rom->romdata, romimage, romsize); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 115 | return status; |
| 116 | |
| 117 | free_struct: |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 118 | efi_call_early(free_pool, rom); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 119 | return status; |
| 120 | } |
| 121 | |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 122 | /* |
| 123 | * There's no way to return an informative status from this function, |
| 124 | * because any analysis (and printing of error messages) needs to be |
| 125 | * done directly at the EFI function call-site. |
| 126 | * |
| 127 | * For example, EFI_INVALID_PARAMETER could indicate a bug or maybe we |
| 128 | * just didn't find any PCI devices, but there's no way to tell outside |
| 129 | * the context of the call. |
| 130 | */ |
| 131 | static void setup_efi_pci(struct boot_params *params) |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 132 | { |
| 133 | efi_status_t status; |
| 134 | void **pci_handle = NULL; |
| 135 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; |
| 136 | unsigned long size = 0; |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 137 | unsigned long nr_pci; |
| 138 | struct setup_data *data; |
| 139 | int i; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 140 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 141 | status = efi_call_early(locate_handle, |
| 142 | EFI_LOCATE_BY_PROTOCOL, |
| 143 | &pci_proto, NULL, &size, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 144 | |
| 145 | if (status == EFI_BUFFER_TOO_SMALL) { |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 146 | status = efi_call_early(allocate_pool, |
| 147 | EFI_LOADER_DATA, |
| 148 | size, (void **)&pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 149 | |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 150 | if (status != EFI_SUCCESS) { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 151 | efi_printk(sys_table, "Failed to allocate memory for 'pci_handle'\n"); |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 152 | return; |
Andre Müller | 77e21e8 | 2014-09-10 01:00:22 +0200 | [diff] [blame] | 153 | } |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 154 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 155 | status = efi_call_early(locate_handle, |
| 156 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, |
| 157 | NULL, &size, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | if (status != EFI_SUCCESS) |
| 161 | goto free_handle; |
| 162 | |
Ard Biesheuvel | 75c5a71 | 2018-07-20 10:47:19 +0900 | [diff] [blame] | 163 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; |
| 164 | |
| 165 | while (data && data->next) |
| 166 | data = (struct setup_data *)(unsigned long)data->next; |
| 167 | |
| 168 | nr_pci = size / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)); |
| 169 | for (i = 0; i < nr_pci; i++) { |
| 170 | efi_pci_io_protocol_t *pci = NULL; |
| 171 | struct pci_setup_rom *rom; |
| 172 | |
| 173 | status = efi_call_early(handle_protocol, |
| 174 | efi_is_64bit() ? ((u64 *)pci_handle)[i] |
| 175 | : ((u32 *)pci_handle)[i], |
| 176 | &pci_proto, (void **)&pci); |
| 177 | if (status != EFI_SUCCESS || !pci) |
| 178 | continue; |
| 179 | |
| 180 | status = preserve_pci_rom_image(pci, &rom); |
| 181 | if (status != EFI_SUCCESS) |
| 182 | continue; |
| 183 | |
| 184 | if (data) |
| 185 | data->next = (unsigned long)rom; |
| 186 | else |
| 187 | params->hdr.setup_data = (unsigned long)rom; |
| 188 | |
| 189 | data = (struct setup_data *)rom; |
| 190 | } |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 191 | |
| 192 | free_handle: |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 193 | efi_call_early(free_pool, pci_handle); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 196 | static void retrieve_apple_device_properties(struct boot_params *boot_params) |
| 197 | { |
| 198 | efi_guid_t guid = APPLE_PROPERTIES_PROTOCOL_GUID; |
| 199 | struct setup_data *data, *new; |
| 200 | efi_status_t status; |
| 201 | u32 size = 0; |
| 202 | void *p; |
| 203 | |
| 204 | status = efi_call_early(locate_protocol, &guid, NULL, &p); |
| 205 | if (status != EFI_SUCCESS) |
| 206 | return; |
| 207 | |
| 208 | if (efi_table_attr(apple_properties_protocol, version, p) != 0x10000) { |
| 209 | efi_printk(sys_table, "Unsupported properties proto version\n"); |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | efi_call_proto(apple_properties_protocol, get_all, p, NULL, &size); |
| 214 | if (!size) |
| 215 | return; |
| 216 | |
| 217 | do { |
| 218 | status = efi_call_early(allocate_pool, EFI_LOADER_DATA, |
| 219 | size + sizeof(struct setup_data), &new); |
| 220 | if (status != EFI_SUCCESS) { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 221 | efi_printk(sys_table, "Failed to allocate memory for 'properties'\n"); |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 222 | return; |
| 223 | } |
| 224 | |
| 225 | status = efi_call_proto(apple_properties_protocol, get_all, p, |
| 226 | new->data, &size); |
| 227 | |
| 228 | if (status == EFI_BUFFER_TOO_SMALL) |
| 229 | efi_call_early(free_pool, new); |
| 230 | } while (status == EFI_BUFFER_TOO_SMALL); |
| 231 | |
| 232 | new->type = SETUP_APPLE_PROPERTIES; |
| 233 | new->len = size; |
| 234 | new->next = 0; |
| 235 | |
| 236 | data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 237 | if (!data) { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 238 | boot_params->hdr.setup_data = (unsigned long)new; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 239 | } else { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 240 | while (data->next) |
| 241 | data = (struct setup_data *)(unsigned long)data->next; |
| 242 | data->next = (unsigned long)new; |
| 243 | } |
| 244 | } |
| 245 | |
Ard Biesheuvel | 36b6497 | 2018-03-12 08:45:00 +0000 | [diff] [blame] | 246 | static const efi_char16_t apple[] = L"Apple"; |
| 247 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 248 | static void setup_quirks(struct boot_params *boot_params) |
| 249 | { |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 250 | efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long) |
| 251 | efi_table_attr(efi_system_table, fw_vendor, sys_table); |
| 252 | |
| 253 | if (!memcmp(fw_vendor, apple, sizeof(apple))) { |
| 254 | if (IS_ENABLED(CONFIG_APPLE_PROPERTIES)) |
| 255 | retrieve_apple_device_properties(boot_params); |
| 256 | } |
| 257 | } |
| 258 | |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 259 | /* |
| 260 | * See if we have Universal Graphics Adapter (UGA) protocol |
| 261 | */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 262 | static efi_status_t |
| 263 | 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] | 264 | { |
| 265 | efi_status_t status; |
| 266 | u32 width, height; |
| 267 | void **uga_handle = NULL; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 268 | efi_uga_draw_protocol_t *uga = NULL, *first_uga; |
| 269 | unsigned long nr_ugas; |
| 270 | int i; |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 271 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 272 | status = efi_call_early(allocate_pool, EFI_LOADER_DATA, |
| 273 | size, (void **)&uga_handle); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 274 | if (status != EFI_SUCCESS) |
| 275 | return status; |
| 276 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 277 | status = efi_call_early(locate_handle, |
| 278 | EFI_LOCATE_BY_PROTOCOL, |
| 279 | uga_proto, NULL, &size, uga_handle); |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 280 | if (status != EFI_SUCCESS) |
| 281 | goto free_handle; |
| 282 | |
| 283 | height = 0; |
| 284 | width = 0; |
| 285 | |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 286 | first_uga = NULL; |
| 287 | nr_ugas = size / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)); |
| 288 | for (i = 0; i < nr_ugas; i++) { |
| 289 | efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; |
| 290 | u32 w, h, depth, refresh; |
| 291 | void *pciio; |
| 292 | unsigned long handle = efi_is_64bit() ? ((u64 *)uga_handle)[i] |
| 293 | : ((u32 *)uga_handle)[i]; |
| 294 | |
| 295 | status = efi_call_early(handle_protocol, handle, |
| 296 | uga_proto, (void **)&uga); |
| 297 | if (status != EFI_SUCCESS) |
| 298 | continue; |
| 299 | |
Ard Biesheuvel | 093174f | 2018-07-20 10:47:22 +0900 | [diff] [blame] | 300 | pciio = NULL; |
Ard Biesheuvel | 290084c | 2018-07-20 10:47:21 +0900 | [diff] [blame] | 301 | efi_call_early(handle_protocol, handle, &pciio_proto, &pciio); |
| 302 | |
| 303 | status = efi_call_proto(efi_uga_draw_protocol, get_mode, uga, |
| 304 | &w, &h, &depth, &refresh); |
| 305 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { |
| 306 | width = w; |
| 307 | height = h; |
| 308 | |
| 309 | /* |
| 310 | * Once we've found a UGA supporting PCIIO, |
| 311 | * don't bother looking any further. |
| 312 | */ |
| 313 | if (pciio) |
| 314 | break; |
| 315 | |
| 316 | first_uga = uga; |
| 317 | } |
| 318 | } |
Matt Fleming | c116e8d | 2014-01-16 11:35:43 +0000 | [diff] [blame] | 319 | |
| 320 | if (!width && !height) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 321 | goto free_handle; |
| 322 | |
| 323 | /* EFI framebuffer */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 324 | si->orig_video_isVGA = VIDEO_TYPE_EFI; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 325 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 326 | si->lfb_depth = 32; |
| 327 | si->lfb_width = width; |
| 328 | si->lfb_height = height; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 329 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 330 | si->red_size = 8; |
| 331 | si->red_pos = 16; |
| 332 | si->green_size = 8; |
| 333 | si->green_pos = 8; |
| 334 | si->blue_size = 8; |
| 335 | si->blue_pos = 0; |
| 336 | si->rsvd_size = 8; |
| 337 | si->rsvd_pos = 24; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 338 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 339 | free_handle: |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 340 | efi_call_early(free_pool, uga_handle); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 341 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 342 | return status; |
| 343 | } |
| 344 | |
| 345 | void setup_graphics(struct boot_params *boot_params) |
| 346 | { |
| 347 | efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; |
| 348 | struct screen_info *si; |
| 349 | efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; |
| 350 | efi_status_t status; |
| 351 | unsigned long size; |
| 352 | void **gop_handle = NULL; |
| 353 | void **uga_handle = NULL; |
| 354 | |
| 355 | si = &boot_params->screen_info; |
| 356 | memset(si, 0, sizeof(*si)); |
| 357 | |
| 358 | size = 0; |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 359 | status = efi_call_early(locate_handle, |
| 360 | EFI_LOCATE_BY_PROTOCOL, |
| 361 | &graphics_proto, NULL, &size, gop_handle); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 362 | if (status == EFI_BUFFER_TOO_SMALL) |
Ard Biesheuvel | 2c23b73 | 2016-04-25 21:06:48 +0100 | [diff] [blame] | 363 | status = efi_setup_gop(NULL, si, &graphics_proto, size); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 364 | |
| 365 | if (status != EFI_SUCCESS) { |
| 366 | size = 0; |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 367 | status = efi_call_early(locate_handle, |
| 368 | EFI_LOCATE_BY_PROTOCOL, |
| 369 | &uga_proto, NULL, &size, uga_handle); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 370 | if (status == EFI_BUFFER_TOO_SMALL) |
| 371 | setup_uga(si, &uga_proto, size); |
| 372 | } |
| 373 | } |
| 374 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 375 | /* |
| 376 | * Because the x86 boot code expects to be passed a boot_params we |
| 377 | * need to create one ourselves (usually the bootloader would create |
| 378 | * one for us). |
Matt Fleming | 7e8213c | 2014-04-08 13:14:00 +0100 | [diff] [blame] | 379 | * |
| 380 | * The caller is responsible for filling out ->code32_start in the |
| 381 | * returned boot_params. |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 382 | */ |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 383 | struct boot_params *make_boot_params(struct efi_config *c) |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 384 | { |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 385 | struct boot_params *boot_params; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 386 | struct apm_bios_info *bi; |
| 387 | struct setup_header *hdr; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 388 | efi_loaded_image_t *image; |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 389 | void *options, *handle; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 390 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 391 | int options_size = 0; |
| 392 | efi_status_t status; |
Roy Franz | 5fef387 | 2013-09-22 15:45:33 -0700 | [diff] [blame] | 393 | char *cmdline_ptr; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 394 | u16 *s2; |
| 395 | u8 *s1; |
| 396 | int i; |
Roy Franz | 46f4582 | 2013-09-22 15:45:39 -0700 | [diff] [blame] | 397 | unsigned long ramdisk_addr; |
| 398 | unsigned long ramdisk_size; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 399 | |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 400 | efi_early = c; |
| 401 | sys_table = (efi_system_table_t *)(unsigned long)efi_early->table; |
| 402 | handle = (void *)(unsigned long)efi_early->image_handle; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 403 | |
| 404 | /* Check if we were booted by the EFI firmware */ |
| 405 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
| 406 | return NULL; |
| 407 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 408 | if (efi_is_64bit()) |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 409 | setup_boot_services64(efi_early); |
| 410 | else |
| 411 | setup_boot_services32(efi_early); |
| 412 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 413 | status = efi_call_early(handle_protocol, handle, |
| 414 | &proto, (void *)&image); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 415 | if (status != EFI_SUCCESS) { |
Roy Franz | 876dc36 | 2013-09-22 15:45:28 -0700 | [diff] [blame] | 416 | efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 417 | return NULL; |
| 418 | } |
| 419 | |
Roy Franz | 40e4530 | 2013-09-22 15:45:29 -0700 | [diff] [blame] | 420 | status = efi_low_alloc(sys_table, 0x4000, 1, |
| 421 | (unsigned long *)&boot_params); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 422 | if (status != EFI_SUCCESS) { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 423 | efi_printk(sys_table, "Failed to allocate lowmem for boot params\n"); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 424 | return NULL; |
| 425 | } |
| 426 | |
| 427 | memset(boot_params, 0x0, 0x4000); |
| 428 | |
| 429 | hdr = &boot_params->hdr; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 430 | bi = &boot_params->apm_bios_info; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 431 | |
| 432 | /* Copy the second sector to boot_params */ |
| 433 | memcpy(&hdr->jump, image->image_base + 512, 512); |
| 434 | |
| 435 | /* |
| 436 | * Fill out some of the header fields ourselves because the |
| 437 | * EFI firmware loader doesn't load the first sector. |
| 438 | */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 439 | hdr->root_flags = 1; |
| 440 | hdr->vid_mode = 0xffff; |
| 441 | hdr->boot_flag = 0xAA55; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 442 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 443 | hdr->type_of_loader = 0x21; |
| 444 | |
| 445 | /* Convert unicode cmdline to ascii */ |
H. Peter Anvin | c625d1c | 2013-09-20 09:55:39 -0500 | [diff] [blame] | 446 | cmdline_ptr = efi_convert_cmdline(sys_table, image, &options_size); |
Roy Franz | 5fef387 | 2013-09-22 15:45:33 -0700 | [diff] [blame] | 447 | if (!cmdline_ptr) |
| 448 | goto fail; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 449 | |
Roy Franz | 5fef387 | 2013-09-22 15:45:33 -0700 | [diff] [blame] | 450 | hdr->cmd_line_ptr = (unsigned long)cmdline_ptr; |
Roy Franz | 98b228f | 2015-04-15 16:32:24 -0700 | [diff] [blame] | 451 | /* Fill in upper bits of command line address, NOP on 32 bit */ |
| 452 | boot_params->ext_cmd_line_ptr = (u64)(unsigned long)cmdline_ptr >> 32; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 453 | |
| 454 | hdr->ramdisk_image = 0; |
| 455 | hdr->ramdisk_size = 0; |
| 456 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 457 | /* Clear APM BIOS info */ |
| 458 | memset(bi, 0, sizeof(*bi)); |
| 459 | |
Matt Fleming | 5a17dae | 2014-08-05 11:52:11 +0100 | [diff] [blame] | 460 | status = efi_parse_options(cmdline_ptr); |
| 461 | if (status != EFI_SUCCESS) |
| 462 | goto fail2; |
| 463 | |
Roy Franz | 46f4582 | 2013-09-22 15:45:39 -0700 | [diff] [blame] | 464 | status = handle_cmdline_files(sys_table, image, |
| 465 | (char *)(unsigned long)hdr->cmd_line_ptr, |
Yinghai Lu | 47226ad | 2014-09-03 21:50:07 -0700 | [diff] [blame] | 466 | "initrd=", hdr->initrd_addr_max, |
Roy Franz | 46f4582 | 2013-09-22 15:45:39 -0700 | [diff] [blame] | 467 | &ramdisk_addr, &ramdisk_size); |
Yinghai Lu | 47226ad | 2014-09-03 21:50:07 -0700 | [diff] [blame] | 468 | |
| 469 | if (status != EFI_SUCCESS && |
| 470 | hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) { |
| 471 | efi_printk(sys_table, "Trying to load files to higher address\n"); |
| 472 | status = handle_cmdline_files(sys_table, image, |
| 473 | (char *)(unsigned long)hdr->cmd_line_ptr, |
| 474 | "initrd=", -1UL, |
| 475 | &ramdisk_addr, &ramdisk_size); |
| 476 | } |
| 477 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 478 | if (status != EFI_SUCCESS) |
| 479 | goto fail2; |
Yinghai Lu | 4bf7111 | 2014-06-14 12:23:41 -0700 | [diff] [blame] | 480 | hdr->ramdisk_image = ramdisk_addr & 0xffffffff; |
| 481 | hdr->ramdisk_size = ramdisk_size & 0xffffffff; |
| 482 | boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32; |
| 483 | boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 484 | |
| 485 | return boot_params; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 486 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 487 | fail2: |
Roy Franz | 0e1cadb | 2013-09-22 15:45:38 -0700 | [diff] [blame] | 488 | efi_free(sys_table, options_size, hdr->cmd_line_ptr); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 489 | fail: |
Roy Franz | 40e4530 | 2013-09-22 15:45:29 -0700 | [diff] [blame] | 490 | efi_free(sys_table, 0x4000, (unsigned long)boot_params); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 491 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 492 | return NULL; |
| 493 | } |
| 494 | |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 495 | static void add_e820ext(struct boot_params *params, |
| 496 | struct setup_data *e820ext, u32 nr_entries) |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 497 | { |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 498 | struct setup_data *data; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 499 | efi_status_t status; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 500 | unsigned long size; |
| 501 | |
| 502 | e820ext->type = SETUP_E820_EXT; |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 503 | e820ext->len = nr_entries * sizeof(struct boot_e820_entry); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 504 | e820ext->next = 0; |
| 505 | |
| 506 | data = (struct setup_data *)(unsigned long)params->hdr.setup_data; |
| 507 | |
| 508 | while (data && data->next) |
| 509 | data = (struct setup_data *)(unsigned long)data->next; |
| 510 | |
| 511 | if (data) |
| 512 | data->next = (unsigned long)e820ext; |
| 513 | else |
| 514 | params->hdr.setup_data = (unsigned long)e820ext; |
| 515 | } |
| 516 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 517 | static efi_status_t |
| 518 | 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] | 519 | { |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 520 | struct boot_e820_entry *entry = params->e820_table; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 521 | struct efi_info *efi = ¶ms->efi_info; |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 522 | struct boot_e820_entry *prev = NULL; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 523 | u32 nr_entries; |
| 524 | u32 nr_desc; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 525 | int i; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 526 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 527 | nr_entries = 0; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 528 | nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size; |
| 529 | |
| 530 | for (i = 0; i < nr_desc; i++) { |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 531 | efi_memory_desc_t *d; |
| 532 | unsigned int e820_type = 0; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 533 | unsigned long m = efi->efi_memmap; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 534 | |
Dmitry Skorodumov | 7cc03e4 | 2015-07-28 18:38:32 +0400 | [diff] [blame] | 535 | #ifdef CONFIG_X86_64 |
| 536 | m |= (u64)efi->efi_memmap_hi << 32; |
| 537 | #endif |
| 538 | |
Baoquan He | 02e43c2 | 2017-08-16 21:46:51 +0800 | [diff] [blame] | 539 | d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 540 | switch (d->type) { |
| 541 | case EFI_RESERVED_TYPE: |
| 542 | case EFI_RUNTIME_SERVICES_CODE: |
| 543 | case EFI_RUNTIME_SERVICES_DATA: |
| 544 | case EFI_MEMORY_MAPPED_IO: |
| 545 | case EFI_MEMORY_MAPPED_IO_PORT_SPACE: |
| 546 | case EFI_PAL_CODE: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 547 | e820_type = E820_TYPE_RESERVED; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 548 | break; |
| 549 | |
| 550 | case EFI_UNUSABLE_MEMORY: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 551 | e820_type = E820_TYPE_UNUSABLE; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 552 | break; |
| 553 | |
| 554 | case EFI_ACPI_RECLAIM_MEMORY: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 555 | e820_type = E820_TYPE_ACPI; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 556 | break; |
| 557 | |
| 558 | case EFI_LOADER_CODE: |
| 559 | case EFI_LOADER_DATA: |
| 560 | case EFI_BOOT_SERVICES_CODE: |
| 561 | case EFI_BOOT_SERVICES_DATA: |
| 562 | case EFI_CONVENTIONAL_MEMORY: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 563 | e820_type = E820_TYPE_RAM; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 564 | break; |
| 565 | |
| 566 | case EFI_ACPI_MEMORY_NVS: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 567 | e820_type = E820_TYPE_NVS; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 568 | break; |
| 569 | |
Dan Williams | ad5fb87 | 2015-04-03 12:05:28 -0400 | [diff] [blame] | 570 | case EFI_PERSISTENT_MEMORY: |
Ingo Molnar | 09821ff | 2017-01-28 17:09:33 +0100 | [diff] [blame] | 571 | e820_type = E820_TYPE_PMEM; |
Dan Williams | ad5fb87 | 2015-04-03 12:05:28 -0400 | [diff] [blame] | 572 | break; |
| 573 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 574 | default: |
| 575 | continue; |
| 576 | } |
| 577 | |
| 578 | /* Merge adjacent mappings */ |
| 579 | if (prev && prev->type == e820_type && |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 580 | (prev->addr + prev->size) == d->phys_addr) { |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 581 | prev->size += d->num_pages << 12; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 582 | continue; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 583 | } |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 584 | |
Ingo Molnar | 61a5010 | 2017-01-27 13:54:38 +0100 | [diff] [blame] | 585 | if (nr_entries == ARRAY_SIZE(params->e820_table)) { |
Ingo Molnar | 8ec67d9 | 2017-01-27 12:54:38 +0100 | [diff] [blame] | 586 | u32 need = (nr_desc - i) * sizeof(struct e820_entry) + |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 587 | sizeof(struct setup_data); |
| 588 | |
| 589 | if (!e820ext || e820ext_size < need) |
| 590 | return EFI_BUFFER_TOO_SMALL; |
| 591 | |
| 592 | /* boot_params map full, switch to e820 extended */ |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 593 | entry = (struct boot_e820_entry *)e820ext->data; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 594 | } |
| 595 | |
Ingo Molnar | 7410aa1 | 2017-01-29 12:56:13 +0100 | [diff] [blame] | 596 | entry->addr = d->phys_addr; |
| 597 | entry->size = d->num_pages << PAGE_SHIFT; |
| 598 | entry->type = e820_type; |
| 599 | prev = entry++; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 600 | nr_entries++; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Ingo Molnar | 61a5010 | 2017-01-27 13:54:38 +0100 | [diff] [blame] | 603 | if (nr_entries > ARRAY_SIZE(params->e820_table)) { |
| 604 | u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_table); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 605 | |
| 606 | add_e820ext(params, e820ext, nr_e820ext); |
| 607 | nr_entries -= nr_e820ext; |
| 608 | } |
| 609 | |
| 610 | params->e820_entries = (u8)nr_entries; |
| 611 | |
| 612 | return EFI_SUCCESS; |
| 613 | } |
| 614 | |
| 615 | static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, |
| 616 | u32 *e820ext_size) |
| 617 | { |
| 618 | efi_status_t status; |
| 619 | unsigned long size; |
| 620 | |
| 621 | size = sizeof(struct setup_data) + |
Ingo Molnar | 8ec67d9 | 2017-01-27 12:54:38 +0100 | [diff] [blame] | 622 | sizeof(struct e820_entry) * nr_desc; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 623 | |
| 624 | if (*e820ext) { |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 625 | efi_call_early(free_pool, *e820ext); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 626 | *e820ext = NULL; |
| 627 | *e820ext_size = 0; |
| 628 | } |
| 629 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 630 | status = efi_call_early(allocate_pool, EFI_LOADER_DATA, |
| 631 | size, (void **)e820ext); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 632 | if (status == EFI_SUCCESS) |
| 633 | *e820ext_size = size; |
| 634 | |
| 635 | return status; |
| 636 | } |
| 637 | |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame^] | 638 | static efi_status_t allocate_e820(struct boot_params *params, |
| 639 | struct setup_data **e820ext, |
| 640 | u32 *e820ext_size) |
| 641 | { |
| 642 | unsigned long map_size, desc_size, buff_size; |
| 643 | struct efi_boot_memmap boot_map; |
| 644 | efi_memory_desc_t *map; |
| 645 | efi_status_t status; |
| 646 | __u32 nr_desc; |
| 647 | |
| 648 | boot_map.map = ↦ |
| 649 | boot_map.map_size = &map_size; |
| 650 | boot_map.desc_size = &desc_size; |
| 651 | boot_map.desc_ver = NULL; |
| 652 | boot_map.key_ptr = NULL; |
| 653 | boot_map.buff_size = &buff_size; |
| 654 | |
| 655 | status = efi_get_memory_map(sys_table, &boot_map); |
| 656 | if (status != EFI_SUCCESS) |
| 657 | return status; |
| 658 | |
| 659 | nr_desc = buff_size / desc_size; |
| 660 | |
| 661 | if (nr_desc > ARRAY_SIZE(params->e820_table)) { |
| 662 | u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table); |
| 663 | |
| 664 | status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size); |
| 665 | if (status != EFI_SUCCESS) |
| 666 | return status; |
| 667 | } |
| 668 | |
| 669 | return EFI_SUCCESS; |
| 670 | } |
| 671 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 672 | struct exit_boot_struct { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 673 | struct boot_params *boot_params; |
| 674 | struct efi_info *efi; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 675 | }; |
| 676 | |
| 677 | static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg, |
| 678 | struct efi_boot_memmap *map, |
| 679 | void *priv) |
| 680 | { |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 681 | const char *signature; |
| 682 | __u32 nr_desc; |
| 683 | efi_status_t status; |
| 684 | struct exit_boot_struct *p = priv; |
| 685 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 686 | signature = efi_is_64bit() ? EFI64_LOADER_SIGNATURE |
| 687 | : EFI32_LOADER_SIGNATURE; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 688 | memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32)); |
| 689 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 690 | p->efi->efi_systab = (unsigned long)sys_table_arg; |
| 691 | p->efi->efi_memdesc_size = *map->desc_size; |
| 692 | p->efi->efi_memdesc_version = *map->desc_ver; |
| 693 | p->efi->efi_memmap = (unsigned long)*map->map; |
| 694 | p->efi->efi_memmap_size = *map->map_size; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 695 | |
| 696 | #ifdef CONFIG_X86_64 |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 697 | p->efi->efi_systab_hi = (unsigned long)sys_table_arg >> 32; |
| 698 | p->efi->efi_memmap_hi = (unsigned long)*map->map >> 32; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 699 | #endif |
| 700 | |
| 701 | return EFI_SUCCESS; |
| 702 | } |
| 703 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 704 | 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] | 705 | { |
Jeffrey Hugo | dadb57a | 2016-08-29 14:38:51 -0600 | [diff] [blame] | 706 | unsigned long map_sz, key, desc_size, buff_size; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 707 | efi_memory_desc_t *mem_map; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame^] | 708 | struct setup_data *e820ext = NULL; |
| 709 | __u32 e820ext_size = 0; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 710 | efi_status_t status; |
| 711 | __u32 desc_version; |
Jeffrey Hugo | dadb57a | 2016-08-29 14:38:51 -0600 | [diff] [blame] | 712 | struct efi_boot_memmap map; |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 713 | struct exit_boot_struct priv; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 714 | |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 715 | map.map = &mem_map; |
| 716 | map.map_size = &map_sz; |
| 717 | map.desc_size = &desc_size; |
| 718 | map.desc_ver = &desc_version; |
| 719 | map.key_ptr = &key; |
| 720 | map.buff_size = &buff_size; |
| 721 | priv.boot_params = boot_params; |
| 722 | priv.efi = &boot_params->efi_info; |
Eric Snowberg | b84a64f | 2018-11-29 18:12:20 +0100 | [diff] [blame^] | 723 | |
| 724 | status = allocate_e820(boot_params, &e820ext, &e820ext_size); |
| 725 | if (status != EFI_SUCCESS) |
| 726 | return status; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 727 | |
Jeffrey Hugo | d649340 | 2016-08-29 14:38:54 -0600 | [diff] [blame] | 728 | /* Might as well exit boot services now */ |
| 729 | status = efi_exit_boot_services(sys_table, handle, &map, &priv, |
| 730 | exit_boot_func); |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 731 | if (status != EFI_SUCCESS) |
| 732 | return status; |
| 733 | |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 734 | /* Historic? */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 735 | boot_params->alt_mem_k = 32 * 1024; |
Linn Crosetto | d2078d5 | 2013-09-22 19:59:08 -0600 | [diff] [blame] | 736 | |
| 737 | status = setup_e820(boot_params, e820ext, e820ext_size); |
| 738 | if (status != EFI_SUCCESS) |
| 739 | return status; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 740 | |
| 741 | return EFI_SUCCESS; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 744 | /* |
| 745 | * On success we return a pointer to a boot_params structure, and NULL |
| 746 | * on failure. |
| 747 | */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 748 | struct boot_params * |
| 749 | efi_main(struct efi_config *c, struct boot_params *boot_params) |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 750 | { |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 751 | struct desc_ptr *gdt = NULL; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 752 | efi_loaded_image_t *image; |
| 753 | struct setup_header *hdr = &boot_params->hdr; |
| 754 | efi_status_t status; |
| 755 | struct desc_struct *desc; |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 756 | void *handle; |
| 757 | efi_system_table_t *_table; |
Hans de Goede | c33ce98 | 2018-09-12 20:32:05 +0200 | [diff] [blame] | 758 | unsigned long cmdline_paddr; |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 759 | |
| 760 | efi_early = c; |
| 761 | |
| 762 | _table = (efi_system_table_t *)(unsigned long)efi_early->table; |
| 763 | handle = (void *)(unsigned long)efi_early->image_handle; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 764 | |
| 765 | sys_table = _table; |
| 766 | |
| 767 | /* Check if we were booted by the EFI firmware */ |
| 768 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
| 769 | goto fail; |
| 770 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 771 | if (efi_is_64bit()) |
Matt Fleming | 54b52d8 | 2014-01-10 15:27:14 +0000 | [diff] [blame] | 772 | setup_boot_services64(efi_early); |
| 773 | else |
| 774 | setup_boot_services32(efi_early); |
| 775 | |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 776 | /* |
Hans de Goede | c33ce98 | 2018-09-12 20:32:05 +0200 | [diff] [blame] | 777 | * make_boot_params() may have been called before efi_main(), in which |
| 778 | * case this is the second time we parse the cmdline. This is ok, |
| 779 | * parsing the cmdline multiple times does not have side-effects. |
| 780 | */ |
| 781 | cmdline_paddr = ((u64)hdr->cmd_line_ptr | |
| 782 | ((u64)boot_params->ext_cmd_line_ptr << 32)); |
| 783 | efi_parse_options((char *)cmdline_paddr); |
| 784 | |
| 785 | /* |
David Howells | de8cb45 | 2017-02-06 11:22:43 +0000 | [diff] [blame] | 786 | * If the boot loader gave us a value for secure_boot then we use that, |
| 787 | * otherwise we ask the BIOS. |
| 788 | */ |
| 789 | if (boot_params->secure_boot == efi_secureboot_mode_unset) |
| 790 | boot_params->secure_boot = efi_get_secureboot(sys_table); |
| 791 | |
Matthew Garrett | ccc829b | 2017-08-25 16:50:15 +0100 | [diff] [blame] | 792 | /* Ask the firmware to clear memory on unclean shutdown */ |
| 793 | efi_enable_reset_attack_mitigation(sys_table); |
Thiebaud Weksteen | 33b6d03 | 2017-09-20 10:13:39 +0200 | [diff] [blame] | 794 | efi_retrieve_tpm2_eventlog(sys_table); |
Matthew Garrett | ccc829b | 2017-08-25 16:50:15 +0100 | [diff] [blame] | 795 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 796 | setup_graphics(boot_params); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 797 | |
Matt Fleming | 56394ab | 2014-09-11 09:04:25 +0100 | [diff] [blame] | 798 | setup_efi_pci(boot_params); |
Matthew Garrett | dd5fc85 | 2012-12-05 14:33:26 -0700 | [diff] [blame] | 799 | |
Lukas Wunner | 58c5475 | 2016-11-12 21:32:36 +0000 | [diff] [blame] | 800 | setup_quirks(boot_params); |
| 801 | |
Matt Fleming | 204b0a1 | 2014-03-22 10:09:01 +0000 | [diff] [blame] | 802 | status = efi_call_early(allocate_pool, EFI_LOADER_DATA, |
| 803 | sizeof(*gdt), (void **)&gdt); |
Matt Fleming | 9fa7ded | 2012-02-20 13:20:59 +0000 | [diff] [blame] | 804 | if (status != EFI_SUCCESS) { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 805 | efi_printk(sys_table, "Failed to allocate memory for 'gdt' structure\n"); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 806 | goto fail; |
Matt Fleming | 9fa7ded | 2012-02-20 13:20:59 +0000 | [diff] [blame] | 807 | } |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 808 | |
| 809 | gdt->size = 0x800; |
Roy Franz | 40e4530 | 2013-09-22 15:45:29 -0700 | [diff] [blame] | 810 | status = efi_low_alloc(sys_table, gdt->size, 8, |
Roy Franz | 876dc36 | 2013-09-22 15:45:28 -0700 | [diff] [blame] | 811 | (unsigned long *)&gdt->address); |
Matt Fleming | 9fa7ded | 2012-02-20 13:20:59 +0000 | [diff] [blame] | 812 | if (status != EFI_SUCCESS) { |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 813 | efi_printk(sys_table, "Failed to allocate memory for 'gdt'\n"); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 814 | goto fail; |
Matt Fleming | 9fa7ded | 2012-02-20 13:20:59 +0000 | [diff] [blame] | 815 | } |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 816 | |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 817 | /* |
| 818 | * If the kernel isn't already loaded at the preferred load |
| 819 | * address, relocate it. |
| 820 | */ |
| 821 | if (hdr->pref_address != hdr->code32_start) { |
Roy Franz | 4a9f3a7 | 2013-09-22 15:45:32 -0700 | [diff] [blame] | 822 | unsigned long bzimage_addr = hdr->code32_start; |
| 823 | status = efi_relocate_kernel(sys_table, &bzimage_addr, |
| 824 | hdr->init_size, hdr->init_size, |
| 825 | hdr->pref_address, |
| 826 | hdr->kernel_alignment); |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 827 | if (status != EFI_SUCCESS) { |
| 828 | efi_printk(sys_table, "efi_relocate_kernel() failed!\n"); |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 829 | goto fail; |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 830 | } |
Roy Franz | 4a9f3a7 | 2013-09-22 15:45:32 -0700 | [diff] [blame] | 831 | |
| 832 | hdr->pref_address = hdr->code32_start; |
| 833 | hdr->code32_start = bzimage_addr; |
Matt Fleming | 9ca8f72 | 2012-07-19 10:23:48 +0100 | [diff] [blame] | 834 | } |
| 835 | |
Ard Biesheuvel | aab9593 | 2018-07-20 10:47:24 +0900 | [diff] [blame] | 836 | status = exit_boot(boot_params, handle); |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 837 | if (status != EFI_SUCCESS) { |
| 838 | efi_printk(sys_table, "exit_boot() failed!\n"); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 839 | goto fail; |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 840 | } |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 841 | |
| 842 | memset((char *)gdt->address, 0x0, gdt->size); |
| 843 | desc = (struct desc_struct *)gdt->address; |
| 844 | |
Kirill A. Shutemov | 919a02d | 2017-06-06 14:31:24 +0300 | [diff] [blame] | 845 | /* The first GDT is a dummy. */ |
| 846 | desc++; |
| 847 | |
| 848 | if (IS_ENABLED(CONFIG_X86_64)) { |
| 849 | /* __KERNEL32_CS */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 850 | desc->limit0 = 0xffff; |
| 851 | desc->base0 = 0x0000; |
| 852 | desc->base1 = 0x0000; |
| 853 | desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; |
| 854 | desc->s = DESC_TYPE_CODE_DATA; |
| 855 | desc->dpl = 0; |
| 856 | desc->p = 1; |
| 857 | desc->limit1 = 0xf; |
| 858 | desc->avl = 0; |
| 859 | desc->l = 0; |
| 860 | desc->d = SEG_OP_SIZE_32BIT; |
| 861 | desc->g = SEG_GRANULARITY_4KB; |
| 862 | desc->base2 = 0x00; |
| 863 | |
Kirill A. Shutemov | 919a02d | 2017-06-06 14:31:24 +0300 | [diff] [blame] | 864 | desc++; |
| 865 | } else { |
| 866 | /* Second entry is unused on 32-bit */ |
| 867 | desc++; |
| 868 | } |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 869 | |
Kirill A. Shutemov | f8fceac | 2017-06-06 14:31:22 +0300 | [diff] [blame] | 870 | /* __KERNEL_CS */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 871 | desc->limit0 = 0xffff; |
| 872 | desc->base0 = 0x0000; |
| 873 | desc->base1 = 0x0000; |
| 874 | desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ; |
| 875 | desc->s = DESC_TYPE_CODE_DATA; |
| 876 | desc->dpl = 0; |
| 877 | desc->p = 1; |
| 878 | desc->limit1 = 0xf; |
| 879 | desc->avl = 0; |
| 880 | |
Kirill A. Shutemov | 4c94117 | 2017-06-06 14:31:23 +0300 | [diff] [blame] | 881 | if (IS_ENABLED(CONFIG_X86_64)) { |
| 882 | desc->l = 1; |
| 883 | desc->d = 0; |
| 884 | } else { |
| 885 | desc->l = 0; |
| 886 | desc->d = SEG_OP_SIZE_32BIT; |
| 887 | } |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 888 | desc->g = SEG_GRANULARITY_4KB; |
| 889 | desc->base2 = 0x00; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 890 | desc++; |
Kirill A. Shutemov | f8fceac | 2017-06-06 14:31:22 +0300 | [diff] [blame] | 891 | |
| 892 | /* __KERNEL_DS */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 893 | desc->limit0 = 0xffff; |
| 894 | desc->base0 = 0x0000; |
| 895 | desc->base1 = 0x0000; |
| 896 | desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE; |
| 897 | desc->s = DESC_TYPE_CODE_DATA; |
| 898 | desc->dpl = 0; |
| 899 | desc->p = 1; |
| 900 | desc->limit1 = 0xf; |
| 901 | desc->avl = 0; |
| 902 | desc->l = 0; |
| 903 | desc->d = SEG_OP_SIZE_32BIT; |
| 904 | desc->g = SEG_GRANULARITY_4KB; |
| 905 | desc->base2 = 0x00; |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 906 | desc++; |
Kirill A. Shutemov | f8fceac | 2017-06-06 14:31:22 +0300 | [diff] [blame] | 907 | |
| 908 | if (IS_ENABLED(CONFIG_X86_64)) { |
| 909 | /* Task segment value */ |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 910 | desc->limit0 = 0x0000; |
| 911 | desc->base0 = 0x0000; |
| 912 | desc->base1 = 0x0000; |
| 913 | desc->type = SEG_TYPE_TSS; |
| 914 | desc->s = 0; |
| 915 | desc->dpl = 0; |
| 916 | desc->p = 1; |
| 917 | desc->limit1 = 0x0; |
| 918 | desc->avl = 0; |
| 919 | desc->l = 0; |
| 920 | desc->d = 0; |
| 921 | desc->g = SEG_GRANULARITY_4KB; |
| 922 | desc->base2 = 0x00; |
Kirill A. Shutemov | f8fceac | 2017-06-06 14:31:22 +0300 | [diff] [blame] | 923 | desc++; |
| 924 | } |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 925 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 926 | asm volatile("cli"); |
Bart Kuivenhoven | 0ce6cda | 2013-09-23 11:45:28 +0200 | [diff] [blame] | 927 | asm volatile ("lgdt %0" : : "m" (*gdt)); |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 928 | |
| 929 | return boot_params; |
| 930 | fail: |
Ulf Winkelvos | fb86b24 | 2014-07-10 02:12:41 +0200 | [diff] [blame] | 931 | efi_printk(sys_table, "efi_main() failed!\n"); |
Ingo Molnar | 90a2186 | 2018-07-11 11:40:33 +0200 | [diff] [blame] | 932 | |
Matt Fleming | 291f363 | 2011-12-12 21:27:52 +0000 | [diff] [blame] | 933 | return NULL; |
| 934 | } |