1 /* -----------------------------------------------------------------------
3 * Copyright 2011 Intel Corporation; author Matt Fleming
5 * This file is part of the Linux kernel, and is made available under
6 * the terms of the GNU General Public License version 2.
8 * ----------------------------------------------------------------------- */
10 #include <linux/efi.h>
12 #include <asm/setup.h>
17 static efi_system_table_t *sys_table;
19 static void efi_printk(char *str)
23 for (s8 = str; *s8; s8++) {
24 struct efi_simple_text_output_protocol *out;
25 efi_char16_t ch[2] = { 0 };
28 out = (struct efi_simple_text_output_protocol *)sys_table->con_out;
31 efi_char16_t nl[2] = { '\r', 0 };
32 efi_call_phys2(out->output_string, out, nl);
35 efi_call_phys2(out->output_string, out, ch);
39 static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size,
40 unsigned long *desc_size)
42 efi_memory_desc_t *m = NULL;
47 *map_size = sizeof(*m) * 32;
50 * Add an additional efi_memory_desc_t because we're doing an
51 * allocation which may be in a new descriptor region.
53 *map_size += sizeof(*m);
54 status = efi_call_phys3(sys_table->boottime->allocate_pool,
55 EFI_LOADER_DATA, *map_size, (void **)&m);
56 if (status != EFI_SUCCESS)
59 status = efi_call_phys5(sys_table->boottime->get_memory_map, map_size,
60 m, &key, desc_size, &desc_version);
61 if (status == EFI_BUFFER_TOO_SMALL) {
62 efi_call_phys1(sys_table->boottime->free_pool, m);
66 if (status != EFI_SUCCESS)
67 efi_call_phys1(sys_table->boottime->free_pool, m);
75 * Allocate at the highest possible address that is not above 'max'.
77 static efi_status_t high_alloc(unsigned long size, unsigned long align,
78 unsigned long *addr, unsigned long max)
80 unsigned long map_size, desc_size;
81 efi_memory_desc_t *map;
83 unsigned long nr_pages;
87 status = __get_map(&map, &map_size, &desc_size);
88 if (status != EFI_SUCCESS)
91 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
93 for (i = 0; i < map_size / desc_size; i++) {
94 efi_memory_desc_t *desc;
95 unsigned long m = (unsigned long)map;
98 desc = (efi_memory_desc_t *)(m + (i * desc_size));
99 if (desc->type != EFI_CONVENTIONAL_MEMORY)
102 if (desc->num_pages < nr_pages)
105 start = desc->phys_addr;
106 end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT);
108 if ((start + size) > end || (start + size) > max)
111 if (end - size > max)
114 if (round_down(end - size, align) < start)
117 start = round_down(end - size, align);
120 * Don't allocate at 0x0. It will confuse code that
121 * checks pointers against NULL.
126 if (start > max_addr)
131 status = EFI_NOT_FOUND;
133 status = efi_call_phys4(sys_table->boottime->allocate_pages,
134 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
135 nr_pages, &max_addr);
136 if (status != EFI_SUCCESS) {
146 efi_call_phys1(sys_table->boottime->free_pool, map);
153 * Allocate at the lowest possible address.
155 static efi_status_t low_alloc(unsigned long size, unsigned long align,
158 unsigned long map_size, desc_size;
159 efi_memory_desc_t *map;
161 unsigned long nr_pages;
164 status = __get_map(&map, &map_size, &desc_size);
165 if (status != EFI_SUCCESS)
168 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
169 for (i = 0; i < map_size / desc_size; i++) {
170 efi_memory_desc_t *desc;
171 unsigned long m = (unsigned long)map;
174 desc = (efi_memory_desc_t *)(m + (i * desc_size));
176 if (desc->type != EFI_CONVENTIONAL_MEMORY)
179 if (desc->num_pages < nr_pages)
182 start = desc->phys_addr;
183 end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT);
186 * Don't allocate at 0x0. It will confuse code that
187 * checks pointers against NULL. Skip the first 8
188 * bytes so we start at a nice even number.
193 start = round_up(start, align);
194 if ((start + size) > end)
197 status = efi_call_phys4(sys_table->boottime->allocate_pages,
198 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
200 if (status == EFI_SUCCESS) {
206 if (i == map_size / desc_size)
207 status = EFI_NOT_FOUND;
210 efi_call_phys1(sys_table->boottime->free_pool, map);
215 static void low_free(unsigned long size, unsigned long addr)
217 unsigned long nr_pages;
219 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
220 efi_call_phys2(sys_table->boottime->free_pages, addr, size);
223 static void find_bits(unsigned long mask, u8 *pos, u8 *size)
231 while (!(mask & 0x1)) {
247 * See if we have Graphics Output Protocol
249 static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
252 struct efi_graphics_output_protocol *gop, *first_gop;
253 struct efi_pixel_bitmask pixel_info;
254 unsigned long nr_gops;
258 u32 fb_base, fb_size;
259 u32 pixels_per_scan_line;
263 status = efi_call_phys3(sys_table->boottime->allocate_pool,
264 EFI_LOADER_DATA, size, &gop_handle);
265 if (status != EFI_SUCCESS)
268 status = efi_call_phys5(sys_table->boottime->locate_handle,
269 EFI_LOCATE_BY_PROTOCOL, proto,
270 NULL, &size, gop_handle);
271 if (status != EFI_SUCCESS)
276 nr_gops = size / sizeof(void *);
277 for (i = 0; i < nr_gops; i++) {
278 struct efi_graphics_output_mode_info *info;
279 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
280 bool conout_found = false;
282 void *h = gop_handle[i];
284 status = efi_call_phys3(sys_table->boottime->handle_protocol,
286 if (status != EFI_SUCCESS)
289 status = efi_call_phys3(sys_table->boottime->handle_protocol,
290 h, &conout_proto, &dummy);
292 if (status == EFI_SUCCESS)
295 status = efi_call_phys4(gop->query_mode, gop,
296 gop->mode->mode, &size, &info);
297 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
299 * Systems that use the UEFI Console Splitter may
300 * provide multiple GOP devices, not all of which are
301 * backed by real hardware. The workaround is to search
302 * for a GOP implementing the ConOut protocol, and if
303 * one isn't found, to just fall back to the first GOP.
305 width = info->horizontal_resolution;
306 height = info->vertical_resolution;
307 fb_base = gop->mode->frame_buffer_base;
308 fb_size = gop->mode->frame_buffer_size;
309 pixel_format = info->pixel_format;
310 pixel_info = info->pixel_information;
311 pixels_per_scan_line = info->pixels_per_scan_line;
314 * Once we've found a GOP supporting ConOut,
315 * don't bother looking any further.
324 /* Did we find any GOPs? */
328 /* EFI framebuffer */
329 si->orig_video_isVGA = VIDEO_TYPE_EFI;
331 si->lfb_width = width;
332 si->lfb_height = height;
333 si->lfb_base = fb_base;
336 if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) {
338 si->lfb_linelength = pixels_per_scan_line * 4;
347 } else if (pixel_format == PIXEL_BGR_RESERVED_8BIT_PER_COLOR) {
349 si->lfb_linelength = pixels_per_scan_line * 4;
358 } else if (pixel_format == PIXEL_BIT_MASK) {
359 find_bits(pixel_info.red_mask, &si->red_pos, &si->red_size);
360 find_bits(pixel_info.green_mask, &si->green_pos,
362 find_bits(pixel_info.blue_mask, &si->blue_pos, &si->blue_size);
363 find_bits(pixel_info.reserved_mask, &si->rsvd_pos,
365 si->lfb_depth = si->red_size + si->green_size +
366 si->blue_size + si->rsvd_size;
367 si->lfb_linelength = (pixels_per_scan_line * si->lfb_depth) / 8;
370 si->lfb_linelength = si->lfb_width / 2;
381 si->lfb_size = si->lfb_linelength * si->lfb_height;
383 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
386 efi_call_phys1(sys_table->boottime->free_pool, gop_handle);
391 * See if we have Universal Graphics Adapter (UGA) protocol
393 static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
396 struct efi_uga_draw_protocol *uga, *first_uga;
397 unsigned long nr_ugas;
400 void **uga_handle = NULL;
403 status = efi_call_phys3(sys_table->boottime->allocate_pool,
404 EFI_LOADER_DATA, size, &uga_handle);
405 if (status != EFI_SUCCESS)
408 status = efi_call_phys5(sys_table->boottime->locate_handle,
409 EFI_LOCATE_BY_PROTOCOL, uga_proto,
410 NULL, &size, uga_handle);
411 if (status != EFI_SUCCESS)
416 nr_ugas = size / sizeof(void *);
417 for (i = 0; i < nr_ugas; i++) {
418 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
419 void *handle = uga_handle[i];
420 u32 w, h, depth, refresh;
423 status = efi_call_phys3(sys_table->boottime->handle_protocol,
424 handle, uga_proto, &uga);
425 if (status != EFI_SUCCESS)
428 efi_call_phys3(sys_table->boottime->handle_protocol,
429 handle, &pciio_proto, &pciio);
431 status = efi_call_phys5(uga->get_mode, uga, &w, &h,
433 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
438 * Once we've found a UGA supporting PCIIO,
439 * don't bother looking any further.
451 /* EFI framebuffer */
452 si->orig_video_isVGA = VIDEO_TYPE_EFI;
455 si->lfb_width = width;
456 si->lfb_height = height;
469 efi_call_phys1(sys_table->boottime->free_pool, uga_handle);
473 void setup_graphics(struct boot_params *boot_params)
475 efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
476 struct screen_info *si;
477 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
480 void **gop_handle = NULL;
481 void **uga_handle = NULL;
483 si = &boot_params->screen_info;
484 memset(si, 0, sizeof(*si));
487 status = efi_call_phys5(sys_table->boottime->locate_handle,
488 EFI_LOCATE_BY_PROTOCOL, &graphics_proto,
489 NULL, &size, gop_handle);
490 if (status == EFI_BUFFER_TOO_SMALL)
491 status = setup_gop(si, &graphics_proto, size);
493 if (status != EFI_SUCCESS) {
495 status = efi_call_phys5(sys_table->boottime->locate_handle,
496 EFI_LOCATE_BY_PROTOCOL, &uga_proto,
497 NULL, &size, uga_handle);
498 if (status == EFI_BUFFER_TOO_SMALL)
499 setup_uga(si, &uga_proto, size);
504 efi_file_handle_t *handle;
509 * Check the cmdline for a LILO-style initrd= arguments.
511 * We only support loading an initrd from the same filesystem as the
514 static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
515 struct setup_header *hdr)
517 struct initrd *initrds;
518 unsigned long initrd_addr;
519 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
521 efi_file_io_interface_t *io;
522 efi_file_handle_t *fh;
531 str = (char *)(unsigned long)hdr->cmd_line_ptr;
533 j = 0; /* See close_handles */
538 for (nr_initrds = 0; *str; nr_initrds++) {
539 str = strstr(str, "initrd=");
545 /* Skip any leading slashes */
546 while (*str == '/' || *str == '\\')
549 while (*str && *str != ' ' && *str != '\n')
556 status = efi_call_phys3(sys_table->boottime->allocate_pool,
558 nr_initrds * sizeof(*initrds),
560 if (status != EFI_SUCCESS) {
561 efi_printk("Failed to alloc mem for initrds\n");
565 str = (char *)(unsigned long)hdr->cmd_line_ptr;
566 for (i = 0; i < nr_initrds; i++) {
567 struct initrd *initrd;
568 efi_file_handle_t *h;
569 efi_file_info_t *info;
570 efi_char16_t filename_16[256];
571 unsigned long info_sz;
572 efi_guid_t info_guid = EFI_FILE_INFO_ID;
576 str = strstr(str, "initrd=");
582 initrd = &initrds[i];
585 /* Skip any leading slashes */
586 while (*str == '/' || *str == '\\')
589 while (*str && *str != ' ' && *str != '\n') {
590 if ((u8 *)p >= (u8 *)filename_16 + sizeof(filename_16))
598 /* Only open the volume once. */
600 efi_boot_services_t *boottime;
602 boottime = sys_table->boottime;
604 status = efi_call_phys3(boottime->handle_protocol,
605 image->device_handle, &fs_proto, &io);
606 if (status != EFI_SUCCESS) {
607 efi_printk("Failed to handle fs_proto\n");
611 status = efi_call_phys2(io->open_volume, io, &fh);
612 if (status != EFI_SUCCESS) {
613 efi_printk("Failed to open volume\n");
618 status = efi_call_phys5(fh->open, fh, &h, filename_16,
619 EFI_FILE_MODE_READ, (u64)0);
620 if (status != EFI_SUCCESS) {
621 efi_printk("Failed to open initrd file\n");
628 status = efi_call_phys4(h->get_info, h, &info_guid,
630 if (status != EFI_BUFFER_TOO_SMALL) {
631 efi_printk("Failed to get initrd info size\n");
636 status = efi_call_phys3(sys_table->boottime->allocate_pool,
637 EFI_LOADER_DATA, info_sz, &info);
638 if (status != EFI_SUCCESS) {
639 efi_printk("Failed to alloc mem for initrd info\n");
643 status = efi_call_phys4(h->get_info, h, &info_guid,
645 if (status == EFI_BUFFER_TOO_SMALL) {
646 efi_call_phys1(sys_table->boottime->free_pool, info);
650 file_sz = info->file_size;
651 efi_call_phys1(sys_table->boottime->free_pool, info);
653 if (status != EFI_SUCCESS) {
654 efi_printk("Failed to get initrd info\n");
658 initrd->size = file_sz;
659 initrd_total += file_sz;
666 * Multiple initrd's need to be at consecutive
667 * addresses in memory, so allocate enough memory for
670 status = high_alloc(initrd_total, 0x1000,
671 &initrd_addr, hdr->initrd_addr_max);
672 if (status != EFI_SUCCESS) {
673 efi_printk("Failed to alloc highmem for initrds\n");
677 /* We've run out of free low memory. */
678 if (initrd_addr > hdr->initrd_addr_max) {
679 efi_printk("We've run out of free low memory\n");
680 status = EFI_INVALID_PARAMETER;
681 goto free_initrd_total;
685 for (j = 0; j < nr_initrds; j++) {
688 size = initrds[j].size;
691 if (size > EFI_READ_CHUNK_SIZE)
692 chunksize = EFI_READ_CHUNK_SIZE;
695 status = efi_call_phys3(fh->read,
698 if (status != EFI_SUCCESS) {
699 efi_printk("Failed to read initrd\n");
700 goto free_initrd_total;
706 efi_call_phys1(fh->close, initrds[j].handle);
711 efi_call_phys1(sys_table->boottime->free_pool, initrds);
713 hdr->ramdisk_image = initrd_addr;
714 hdr->ramdisk_size = initrd_total;
719 low_free(initrd_total, initrd_addr);
722 for (k = j; k < i; k++)
723 efi_call_phys1(fh->close, initrds[k].handle);
725 efi_call_phys1(sys_table->boottime->free_pool, initrds);
727 hdr->ramdisk_image = 0;
728 hdr->ramdisk_size = 0;
734 * Because the x86 boot code expects to be passed a boot_params we
735 * need to create one ourselves (usually the bootloader would create
738 struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table)
740 struct boot_params *boot_params;
741 struct sys_desc_table *sdt;
742 struct apm_bios_info *bi;
743 struct setup_header *hdr;
744 struct efi_info *efi;
745 efi_loaded_image_t *image;
747 u32 load_options_size;
748 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
749 int options_size = 0;
751 unsigned long cmdline;
758 /* Check if we were booted by the EFI firmware */
759 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
762 status = efi_call_phys3(sys_table->boottime->handle_protocol,
763 handle, &proto, (void *)&image);
764 if (status != EFI_SUCCESS) {
765 efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
769 status = low_alloc(0x4000, 1, (unsigned long *)&boot_params);
770 if (status != EFI_SUCCESS) {
771 efi_printk("Failed to alloc lowmem for boot params\n");
775 memset(boot_params, 0x0, 0x4000);
777 hdr = &boot_params->hdr;
778 efi = &boot_params->efi_info;
779 bi = &boot_params->apm_bios_info;
780 sdt = &boot_params->sys_desc_table;
782 /* Copy the second sector to boot_params */
783 memcpy(&hdr->jump, image->image_base + 512, 512);
786 * Fill out some of the header fields ourselves because the
787 * EFI firmware loader doesn't load the first sector.
790 hdr->vid_mode = 0xffff;
791 hdr->boot_flag = 0xAA55;
793 hdr->code32_start = (__u64)(unsigned long)image->image_base;
795 hdr->type_of_loader = 0x21;
797 /* Convert unicode cmdline to ascii */
798 options = image->load_options;
799 load_options_size = image->load_options_size / 2; /* ASCII */
804 while (*s2 && *s2 != '\n' && options_size < load_options_size) {
810 if (options_size > hdr->cmdline_size)
811 options_size = hdr->cmdline_size;
813 options_size++; /* NUL termination */
815 status = low_alloc(options_size, 1, &cmdline);
816 if (status != EFI_SUCCESS) {
817 efi_printk("Failed to alloc mem for cmdline\n");
821 s1 = (u8 *)(unsigned long)cmdline;
824 for (i = 0; i < options_size - 1; i++)
831 hdr->cmd_line_ptr = cmdline;
833 hdr->ramdisk_image = 0;
834 hdr->ramdisk_size = 0;
836 /* Clear APM BIOS info */
837 memset(bi, 0, sizeof(*bi));
839 memset(sdt, 0, sizeof(*sdt));
841 status = handle_ramdisks(image, hdr);
842 if (status != EFI_SUCCESS)
848 low_free(options_size, hdr->cmd_line_ptr);
850 low_free(0x4000, (unsigned long)boot_params);
854 static efi_status_t exit_boot(struct boot_params *boot_params,
857 struct efi_info *efi = &boot_params->efi_info;
858 struct e820entry *e820_map = &boot_params->e820_map[0];
859 struct e820entry *prev = NULL;
860 unsigned long size, key, desc_size, _size;
861 efi_memory_desc_t *mem_map;
867 size = sizeof(*mem_map) * 32;
870 size += sizeof(*mem_map);
872 status = low_alloc(size, 1, (unsigned long *)&mem_map);
873 if (status != EFI_SUCCESS)
876 status = efi_call_phys5(sys_table->boottime->get_memory_map, &size,
877 mem_map, &key, &desc_size, &desc_version);
878 if (status == EFI_BUFFER_TOO_SMALL) {
879 low_free(_size, (unsigned long)mem_map);
883 if (status != EFI_SUCCESS)
886 memcpy(&efi->efi_loader_signature, EFI_LOADER_SIGNATURE, sizeof(__u32));
887 efi->efi_systab = (unsigned long)sys_table;
888 efi->efi_memdesc_size = desc_size;
889 efi->efi_memdesc_version = desc_version;
890 efi->efi_memmap = (unsigned long)mem_map;
891 efi->efi_memmap_size = size;
894 efi->efi_systab_hi = (unsigned long)sys_table >> 32;
895 efi->efi_memmap_hi = (unsigned long)mem_map >> 32;
898 /* Might as well exit boot services now */
899 status = efi_call_phys2(sys_table->boottime->exit_boot_services,
901 if (status != EFI_SUCCESS)
905 boot_params->alt_mem_k = 32 * 1024;
908 * Convert the EFI memory map to E820.
911 for (i = 0; i < size / desc_size; i++) {
912 efi_memory_desc_t *d;
913 unsigned int e820_type = 0;
914 unsigned long m = (unsigned long)mem_map;
916 d = (efi_memory_desc_t *)(m + (i * desc_size));
918 case EFI_RESERVED_TYPE:
919 case EFI_RUNTIME_SERVICES_CODE:
920 case EFI_RUNTIME_SERVICES_DATA:
921 case EFI_MEMORY_MAPPED_IO:
922 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
924 e820_type = E820_RESERVED;
927 case EFI_UNUSABLE_MEMORY:
928 e820_type = E820_UNUSABLE;
931 case EFI_ACPI_RECLAIM_MEMORY:
932 e820_type = E820_ACPI;
935 case EFI_LOADER_CODE:
936 case EFI_LOADER_DATA:
937 case EFI_BOOT_SERVICES_CODE:
938 case EFI_BOOT_SERVICES_DATA:
939 case EFI_CONVENTIONAL_MEMORY:
940 e820_type = E820_RAM;
943 case EFI_ACPI_MEMORY_NVS:
944 e820_type = E820_NVS;
951 /* Merge adjacent mappings */
952 if (prev && prev->type == e820_type &&
953 (prev->addr + prev->size) == d->phys_addr)
954 prev->size += d->num_pages << 12;
956 e820_map->addr = d->phys_addr;
957 e820_map->size = d->num_pages << 12;
958 e820_map->type = e820_type;
964 boot_params->e820_entries = nr_entries;
969 low_free(_size, (unsigned long)mem_map);
973 static efi_status_t relocate_kernel(struct setup_header *hdr)
975 unsigned long start, nr_pages;
979 * The EFI firmware loader could have placed the kernel image
980 * anywhere in memory, but the kernel has various restrictions
981 * on the max physical address it can run at. Attempt to move
982 * the kernel to boot_params.pref_address, or as low as
985 start = hdr->pref_address;
986 nr_pages = round_up(hdr->init_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
988 status = efi_call_phys4(sys_table->boottime->allocate_pages,
989 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
991 if (status != EFI_SUCCESS) {
992 status = low_alloc(hdr->init_size, hdr->kernel_alignment,
994 if (status != EFI_SUCCESS)
995 efi_printk("Failed to alloc mem for kernel\n");
998 if (status == EFI_SUCCESS)
999 memcpy((void *)start, (void *)(unsigned long)hdr->code32_start,
1002 hdr->pref_address = hdr->code32_start;
1003 hdr->code32_start = (__u32)start;
1009 * On success we return a pointer to a boot_params structure, and NULL
1012 struct boot_params *efi_main(void *handle, efi_system_table_t *_table,
1013 struct boot_params *boot_params)
1015 struct desc_ptr *gdt, *idt;
1016 efi_loaded_image_t *image;
1017 struct setup_header *hdr = &boot_params->hdr;
1018 efi_status_t status;
1019 struct desc_struct *desc;
1023 /* Check if we were booted by the EFI firmware */
1024 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
1027 setup_graphics(boot_params);
1029 status = efi_call_phys3(sys_table->boottime->allocate_pool,
1030 EFI_LOADER_DATA, sizeof(*gdt),
1032 if (status != EFI_SUCCESS) {
1033 efi_printk("Failed to alloc mem for gdt structure\n");
1038 status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address);
1039 if (status != EFI_SUCCESS) {
1040 efi_printk("Failed to alloc mem for gdt\n");
1044 status = efi_call_phys3(sys_table->boottime->allocate_pool,
1045 EFI_LOADER_DATA, sizeof(*idt),
1047 if (status != EFI_SUCCESS) {
1048 efi_printk("Failed to alloc mem for idt structure\n");
1056 * If the kernel isn't already loaded at the preferred load
1057 * address, relocate it.
1059 if (hdr->pref_address != hdr->code32_start) {
1060 status = relocate_kernel(hdr);
1062 if (status != EFI_SUCCESS)
1066 status = exit_boot(boot_params, handle);
1067 if (status != EFI_SUCCESS)
1070 memset((char *)gdt->address, 0x0, gdt->size);
1071 desc = (struct desc_struct *)gdt->address;
1073 /* The first GDT is a dummy and the second is unused. */
1076 desc->limit0 = 0xffff;
1077 desc->base0 = 0x0000;
1078 desc->base1 = 0x0000;
1079 desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ;
1080 desc->s = DESC_TYPE_CODE_DATA;
1086 desc->d = SEG_OP_SIZE_32BIT;
1087 desc->g = SEG_GRANULARITY_4KB;
1091 desc->limit0 = 0xffff;
1092 desc->base0 = 0x0000;
1093 desc->base1 = 0x0000;
1094 desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE;
1095 desc->s = DESC_TYPE_CODE_DATA;
1101 desc->d = SEG_OP_SIZE_32BIT;
1102 desc->g = SEG_GRANULARITY_4KB;
1105 #ifdef CONFIG_X86_64
1106 /* Task segment value */
1108 desc->limit0 = 0x0000;
1109 desc->base0 = 0x0000;
1110 desc->base1 = 0x0000;
1111 desc->type = SEG_TYPE_TSS;
1119 desc->g = SEG_GRANULARITY_4KB;
1121 #endif /* CONFIG_X86_64 */
1123 asm volatile ("lidt %0" : : "m" (*idt));
1124 asm volatile ("lgdt %0" : : "m" (*gdt));
1126 asm volatile("cli");