2 /* -----------------------------------------------------------------------
4 * Copyright 2011 Intel Corporation; author Matt Fleming
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.
9 * ----------------------------------------------------------------------- */
11 #include <linux/efi.h>
12 #include <linux/pci.h>
15 #include <asm/e820/types.h>
16 #include <asm/setup.h>
19 #include "../string.h"
22 static efi_system_table_t *sys_table;
24 static struct efi_config *efi_early;
26 __pure const struct efi_config *__efi_early(void)
31 #define BOOT_SERVICES(bits) \
32 static void setup_boot_services##bits(struct efi_config *c) \
34 efi_system_table_##bits##_t *table; \
36 table = (typeof(table))sys_table; \
38 c->runtime_services = table->runtime; \
39 c->boot_services = table->boottime; \
40 c->text_output = table->con_out; \
45 void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
47 efi_call_proto(efi_simple_text_output_protocol, output_string,
48 efi_early->text_output, str);
52 preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
54 struct pci_setup_rom *rom = NULL;
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
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.
67 romimage = (void *)(unsigned long)efi_table_attr(efi_pci_io_protocol,
69 romsize = efi_table_attr(efi_pci_io_protocol, romsize, pci);
70 if (!romimage || !romsize || romsize > SZ_16M)
71 return EFI_INVALID_PARAMETER;
73 size = romsize + sizeof(*rom);
75 status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
76 if (status != EFI_SUCCESS) {
77 efi_printk(sys_table, "Failed to allocate memory for 'rom'\n");
81 memset(rom, 0, sizeof(*rom));
83 rom->data.type = SETUP_PCI;
84 rom->data.len = size - sizeof(struct setup_data);
86 rom->pcilen = pci->romsize;
89 status = efi_call_proto(efi_pci_io_protocol, pci.read, pci,
90 EfiPciIoWidthUint16, PCI_VENDOR_ID, 1,
93 if (status != EFI_SUCCESS) {
94 efi_printk(sys_table, "Failed to read rom->vendor\n");
98 status = efi_call_proto(efi_pci_io_protocol, pci.read, pci,
99 EfiPciIoWidthUint16, PCI_DEVICE_ID, 1,
102 if (status != EFI_SUCCESS) {
103 efi_printk(sys_table, "Failed to read rom->devid\n");
107 status = efi_call_proto(efi_pci_io_protocol, get_location, pci,
108 &rom->segment, &rom->bus, &rom->device,
111 if (status != EFI_SUCCESS)
114 memcpy(rom->romdata, romimage, romsize);
118 efi_call_early(free_pool, rom);
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.
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.
131 static void setup_efi_pci(struct boot_params *params)
134 void **pci_handle = NULL;
135 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
136 unsigned long size = 0;
137 unsigned long nr_pci;
138 struct setup_data *data;
141 status = efi_call_early(locate_handle,
142 EFI_LOCATE_BY_PROTOCOL,
143 &pci_proto, NULL, &size, pci_handle);
145 if (status == EFI_BUFFER_TOO_SMALL) {
146 status = efi_call_early(allocate_pool,
148 size, (void **)&pci_handle);
150 if (status != EFI_SUCCESS) {
151 efi_printk(sys_table, "Failed to allocate memory for 'pci_handle'\n");
155 status = efi_call_early(locate_handle,
156 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
157 NULL, &size, pci_handle);
160 if (status != EFI_SUCCESS)
163 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
165 while (data && data->next)
166 data = (struct setup_data *)(unsigned long)data->next;
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;
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)
180 status = preserve_pci_rom_image(pci, &rom);
181 if (status != EFI_SUCCESS)
185 data->next = (unsigned long)rom;
187 params->hdr.setup_data = (unsigned long)rom;
189 data = (struct setup_data *)rom;
193 efi_call_early(free_pool, pci_handle);
196 static void retrieve_apple_device_properties(struct boot_params *boot_params)
198 efi_guid_t guid = APPLE_PROPERTIES_PROTOCOL_GUID;
199 struct setup_data *data, *new;
204 status = efi_call_early(locate_protocol, &guid, NULL, &p);
205 if (status != EFI_SUCCESS)
208 if (efi_table_attr(apple_properties_protocol, version, p) != 0x10000) {
209 efi_printk(sys_table, "Unsupported properties proto version\n");
213 efi_call_proto(apple_properties_protocol, get_all, p, NULL, &size);
218 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
219 size + sizeof(struct setup_data), &new);
220 if (status != EFI_SUCCESS) {
221 efi_printk(sys_table, "Failed to allocate memory for 'properties'\n");
225 status = efi_call_proto(apple_properties_protocol, get_all, p,
228 if (status == EFI_BUFFER_TOO_SMALL)
229 efi_call_early(free_pool, new);
230 } while (status == EFI_BUFFER_TOO_SMALL);
232 new->type = SETUP_APPLE_PROPERTIES;
236 data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data;
238 boot_params->hdr.setup_data = (unsigned long)new;
241 data = (struct setup_data *)(unsigned long)data->next;
242 data->next = (unsigned long)new;
246 static const efi_char16_t apple[] = L"Apple";
248 static void setup_quirks(struct boot_params *boot_params)
250 efi_char16_t *fw_vendor = (efi_char16_t *)(unsigned long)
251 efi_table_attr(efi_system_table, fw_vendor, sys_table);
253 if (!memcmp(fw_vendor, apple, sizeof(apple))) {
254 if (IS_ENABLED(CONFIG_APPLE_PROPERTIES))
255 retrieve_apple_device_properties(boot_params);
260 * See if we have Universal Graphics Adapter (UGA) protocol
263 setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size)
267 void **uga_handle = NULL;
268 efi_uga_draw_protocol_t *uga = NULL, *first_uga;
269 unsigned long nr_ugas;
272 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
273 size, (void **)&uga_handle);
274 if (status != EFI_SUCCESS)
277 status = efi_call_early(locate_handle,
278 EFI_LOCATE_BY_PROTOCOL,
279 uga_proto, NULL, &size, uga_handle);
280 if (status != EFI_SUCCESS)
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;
292 unsigned long handle = efi_is_64bit() ? ((u64 *)uga_handle)[i]
293 : ((u32 *)uga_handle)[i];
295 status = efi_call_early(handle_protocol, handle,
296 uga_proto, (void **)&uga);
297 if (status != EFI_SUCCESS)
301 efi_call_early(handle_protocol, handle, &pciio_proto, &pciio);
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)) {
310 * Once we've found a UGA supporting PCIIO,
311 * don't bother looking any further.
320 if (!width && !height)
323 /* EFI framebuffer */
324 si->orig_video_isVGA = VIDEO_TYPE_EFI;
327 si->lfb_width = width;
328 si->lfb_height = height;
340 efi_call_early(free_pool, uga_handle);
345 void setup_graphics(struct boot_params *boot_params)
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;
352 void **gop_handle = NULL;
353 void **uga_handle = NULL;
355 si = &boot_params->screen_info;
356 memset(si, 0, sizeof(*si));
359 status = efi_call_early(locate_handle,
360 EFI_LOCATE_BY_PROTOCOL,
361 &graphics_proto, NULL, &size, gop_handle);
362 if (status == EFI_BUFFER_TOO_SMALL)
363 status = efi_setup_gop(NULL, si, &graphics_proto, size);
365 if (status != EFI_SUCCESS) {
367 status = efi_call_early(locate_handle,
368 EFI_LOCATE_BY_PROTOCOL,
369 &uga_proto, NULL, &size, uga_handle);
370 if (status == EFI_BUFFER_TOO_SMALL)
371 setup_uga(si, &uga_proto, size);
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
380 * The caller is responsible for filling out ->code32_start in the
381 * returned boot_params.
383 struct boot_params *make_boot_params(struct efi_config *c)
385 struct boot_params *boot_params;
386 struct apm_bios_info *bi;
387 struct setup_header *hdr;
388 efi_loaded_image_t *image;
389 void *options, *handle;
390 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
391 int options_size = 0;
397 unsigned long ramdisk_addr;
398 unsigned long ramdisk_size;
401 sys_table = (efi_system_table_t *)(unsigned long)efi_early->table;
402 handle = (void *)(unsigned long)efi_early->image_handle;
404 /* Check if we were booted by the EFI firmware */
405 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
409 setup_boot_services64(efi_early);
411 setup_boot_services32(efi_early);
413 status = efi_call_early(handle_protocol, handle,
414 &proto, (void *)&image);
415 if (status != EFI_SUCCESS) {
416 efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
420 status = efi_low_alloc(sys_table, 0x4000, 1,
421 (unsigned long *)&boot_params);
422 if (status != EFI_SUCCESS) {
423 efi_printk(sys_table, "Failed to allocate lowmem for boot params\n");
427 memset(boot_params, 0x0, 0x4000);
429 hdr = &boot_params->hdr;
430 bi = &boot_params->apm_bios_info;
432 /* Copy the second sector to boot_params */
433 memcpy(&hdr->jump, image->image_base + 512, 512);
436 * Fill out some of the header fields ourselves because the
437 * EFI firmware loader doesn't load the first sector.
440 hdr->vid_mode = 0xffff;
441 hdr->boot_flag = 0xAA55;
443 hdr->type_of_loader = 0x21;
445 /* Convert unicode cmdline to ascii */
446 cmdline_ptr = efi_convert_cmdline(sys_table, image, &options_size);
450 hdr->cmd_line_ptr = (unsigned long)cmdline_ptr;
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;
454 hdr->ramdisk_image = 0;
455 hdr->ramdisk_size = 0;
457 /* Clear APM BIOS info */
458 memset(bi, 0, sizeof(*bi));
460 status = efi_parse_options(cmdline_ptr);
461 if (status != EFI_SUCCESS)
464 status = handle_cmdline_files(sys_table, image,
465 (char *)(unsigned long)hdr->cmd_line_ptr,
466 "initrd=", hdr->initrd_addr_max,
467 &ramdisk_addr, &ramdisk_size);
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,
475 &ramdisk_addr, &ramdisk_size);
478 if (status != EFI_SUCCESS)
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;
488 efi_free(sys_table, options_size, hdr->cmd_line_ptr);
490 efi_free(sys_table, 0x4000, (unsigned long)boot_params);
495 static void add_e820ext(struct boot_params *params,
496 struct setup_data *e820ext, u32 nr_entries)
498 struct setup_data *data;
502 e820ext->type = SETUP_E820_EXT;
503 e820ext->len = nr_entries * sizeof(struct boot_e820_entry);
506 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
508 while (data && data->next)
509 data = (struct setup_data *)(unsigned long)data->next;
512 data->next = (unsigned long)e820ext;
514 params->hdr.setup_data = (unsigned long)e820ext;
518 setup_e820(struct boot_params *params, struct setup_data *e820ext, u32 e820ext_size)
520 struct boot_e820_entry *entry = params->e820_table;
521 struct efi_info *efi = ¶ms->efi_info;
522 struct boot_e820_entry *prev = NULL;
528 nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size;
530 for (i = 0; i < nr_desc; i++) {
531 efi_memory_desc_t *d;
532 unsigned int e820_type = 0;
533 unsigned long m = efi->efi_memmap;
536 m |= (u64)efi->efi_memmap_hi << 32;
539 d = efi_early_memdesc_ptr(m, efi->efi_memdesc_size, i);
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:
547 e820_type = E820_TYPE_RESERVED;
550 case EFI_UNUSABLE_MEMORY:
551 e820_type = E820_TYPE_UNUSABLE;
554 case EFI_ACPI_RECLAIM_MEMORY:
555 e820_type = E820_TYPE_ACPI;
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:
563 e820_type = E820_TYPE_RAM;
566 case EFI_ACPI_MEMORY_NVS:
567 e820_type = E820_TYPE_NVS;
570 case EFI_PERSISTENT_MEMORY:
571 e820_type = E820_TYPE_PMEM;
578 /* Merge adjacent mappings */
579 if (prev && prev->type == e820_type &&
580 (prev->addr + prev->size) == d->phys_addr) {
581 prev->size += d->num_pages << 12;
585 if (nr_entries == ARRAY_SIZE(params->e820_table)) {
586 u32 need = (nr_desc - i) * sizeof(struct e820_entry) +
587 sizeof(struct setup_data);
589 if (!e820ext || e820ext_size < need)
590 return EFI_BUFFER_TOO_SMALL;
592 /* boot_params map full, switch to e820 extended */
593 entry = (struct boot_e820_entry *)e820ext->data;
596 entry->addr = d->phys_addr;
597 entry->size = d->num_pages << PAGE_SHIFT;
598 entry->type = e820_type;
603 if (nr_entries > ARRAY_SIZE(params->e820_table)) {
604 u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_table);
606 add_e820ext(params, e820ext, nr_e820ext);
607 nr_entries -= nr_e820ext;
610 params->e820_entries = (u8)nr_entries;
615 static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
621 size = sizeof(struct setup_data) +
622 sizeof(struct e820_entry) * nr_desc;
625 efi_call_early(free_pool, *e820ext);
630 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
631 size, (void **)e820ext);
632 if (status == EFI_SUCCESS)
633 *e820ext_size = size;
638 static efi_status_t allocate_e820(struct boot_params *params,
639 struct setup_data **e820ext,
642 unsigned long map_size, desc_size, buff_size;
643 struct efi_boot_memmap boot_map;
644 efi_memory_desc_t *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;
655 status = efi_get_memory_map(sys_table, &boot_map);
656 if (status != EFI_SUCCESS)
659 nr_desc = buff_size / desc_size;
661 if (nr_desc > ARRAY_SIZE(params->e820_table)) {
662 u32 nr_e820ext = nr_desc - ARRAY_SIZE(params->e820_table);
664 status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size);
665 if (status != EFI_SUCCESS)
672 struct exit_boot_struct {
673 struct boot_params *boot_params;
674 struct efi_info *efi;
677 static efi_status_t exit_boot_func(efi_system_table_t *sys_table_arg,
678 struct efi_boot_memmap *map,
681 const char *signature;
684 struct exit_boot_struct *p = priv;
686 signature = efi_is_64bit() ? EFI64_LOADER_SIGNATURE
687 : EFI32_LOADER_SIGNATURE;
688 memcpy(&p->efi->efi_loader_signature, signature, sizeof(__u32));
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;
697 p->efi->efi_systab_hi = (unsigned long)sys_table_arg >> 32;
698 p->efi->efi_memmap_hi = (unsigned long)*map->map >> 32;
704 static efi_status_t exit_boot(struct boot_params *boot_params, void *handle)
706 unsigned long map_sz, key, desc_size, buff_size;
707 efi_memory_desc_t *mem_map;
708 struct setup_data *e820ext = NULL;
709 __u32 e820ext_size = 0;
712 struct efi_boot_memmap map;
713 struct exit_boot_struct priv;
716 map.map_size = &map_sz;
717 map.desc_size = &desc_size;
718 map.desc_ver = &desc_version;
720 map.buff_size = &buff_size;
721 priv.boot_params = boot_params;
722 priv.efi = &boot_params->efi_info;
724 status = allocate_e820(boot_params, &e820ext, &e820ext_size);
725 if (status != EFI_SUCCESS)
728 /* Might as well exit boot services now */
729 status = efi_exit_boot_services(sys_table, handle, &map, &priv,
731 if (status != EFI_SUCCESS)
735 boot_params->alt_mem_k = 32 * 1024;
737 status = setup_e820(boot_params, e820ext, e820ext_size);
738 if (status != EFI_SUCCESS)
745 * On success we return a pointer to a boot_params structure, and NULL
749 efi_main(struct efi_config *c, struct boot_params *boot_params)
751 struct desc_ptr *gdt = NULL;
752 efi_loaded_image_t *image;
753 struct setup_header *hdr = &boot_params->hdr;
755 struct desc_struct *desc;
757 efi_system_table_t *_table;
758 unsigned long cmdline_paddr;
762 _table = (efi_system_table_t *)(unsigned long)efi_early->table;
763 handle = (void *)(unsigned long)efi_early->image_handle;
767 /* Check if we were booted by the EFI firmware */
768 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
772 setup_boot_services64(efi_early);
774 setup_boot_services32(efi_early);
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.
781 cmdline_paddr = ((u64)hdr->cmd_line_ptr |
782 ((u64)boot_params->ext_cmd_line_ptr << 32));
783 efi_parse_options((char *)cmdline_paddr);
786 * If the boot loader gave us a value for secure_boot then we use that,
787 * otherwise we ask the BIOS.
789 if (boot_params->secure_boot == efi_secureboot_mode_unset)
790 boot_params->secure_boot = efi_get_secureboot(sys_table);
792 /* Ask the firmware to clear memory on unclean shutdown */
793 efi_enable_reset_attack_mitigation(sys_table);
794 efi_retrieve_tpm2_eventlog(sys_table);
796 setup_graphics(boot_params);
798 setup_efi_pci(boot_params);
800 setup_quirks(boot_params);
802 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
803 sizeof(*gdt), (void **)&gdt);
804 if (status != EFI_SUCCESS) {
805 efi_printk(sys_table, "Failed to allocate memory for 'gdt' structure\n");
810 status = efi_low_alloc(sys_table, gdt->size, 8,
811 (unsigned long *)&gdt->address);
812 if (status != EFI_SUCCESS) {
813 efi_printk(sys_table, "Failed to allocate memory for 'gdt'\n");
818 * If the kernel isn't already loaded at the preferred load
819 * address, relocate it.
821 if (hdr->pref_address != hdr->code32_start) {
822 unsigned long bzimage_addr = hdr->code32_start;
823 status = efi_relocate_kernel(sys_table, &bzimage_addr,
824 hdr->init_size, hdr->init_size,
826 hdr->kernel_alignment);
827 if (status != EFI_SUCCESS) {
828 efi_printk(sys_table, "efi_relocate_kernel() failed!\n");
832 hdr->pref_address = hdr->code32_start;
833 hdr->code32_start = bzimage_addr;
836 status = exit_boot(boot_params, handle);
837 if (status != EFI_SUCCESS) {
838 efi_printk(sys_table, "exit_boot() failed!\n");
842 memset((char *)gdt->address, 0x0, gdt->size);
843 desc = (struct desc_struct *)gdt->address;
845 /* The first GDT is a dummy. */
848 if (IS_ENABLED(CONFIG_X86_64)) {
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;
860 desc->d = SEG_OP_SIZE_32BIT;
861 desc->g = SEG_GRANULARITY_4KB;
866 /* Second entry is unused on 32-bit */
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;
881 if (IS_ENABLED(CONFIG_X86_64)) {
886 desc->d = SEG_OP_SIZE_32BIT;
888 desc->g = SEG_GRANULARITY_4KB;
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;
903 desc->d = SEG_OP_SIZE_32BIT;
904 desc->g = SEG_GRANULARITY_4KB;
908 if (IS_ENABLED(CONFIG_X86_64)) {
909 /* Task segment value */
910 desc->limit0 = 0x0000;
911 desc->base0 = 0x0000;
912 desc->base1 = 0x0000;
913 desc->type = SEG_TYPE_TSS;
921 desc->g = SEG_GRANULARITY_4KB;
927 asm volatile ("lgdt %0" : : "m" (*gdt));
931 efi_printk(sys_table, "efi_main() failed!\n");