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 efi_status_t
__get_map(efi_memory_desc_t
**map
, unsigned long *map_size
,
20 unsigned long *desc_size
)
22 efi_memory_desc_t
*m
= NULL
;
27 *map_size
= sizeof(*m
) * 32;
30 * Add an additional efi_memory_desc_t because we're doing an
31 * allocation which may be in a new descriptor region.
33 *map_size
+= sizeof(*m
);
34 status
= efi_call_phys3(sys_table
->boottime
->allocate_pool
,
35 EFI_LOADER_DATA
, *map_size
, (void **)&m
);
36 if (status
!= EFI_SUCCESS
)
39 status
= efi_call_phys5(sys_table
->boottime
->get_memory_map
, map_size
,
40 m
, &key
, desc_size
, &desc_version
);
41 if (status
== EFI_BUFFER_TOO_SMALL
) {
42 efi_call_phys1(sys_table
->boottime
->free_pool
, m
);
46 if (status
!= EFI_SUCCESS
)
47 efi_call_phys1(sys_table
->boottime
->free_pool
, m
);
55 * Allocate at the highest possible address that is not above 'max'.
57 static efi_status_t
high_alloc(unsigned long size
, unsigned long align
,
58 unsigned long *addr
, unsigned long max
)
60 unsigned long map_size
, desc_size
;
61 efi_memory_desc_t
*map
;
63 unsigned long nr_pages
;
67 status
= __get_map(&map
, &map_size
, &desc_size
);
68 if (status
!= EFI_SUCCESS
)
71 nr_pages
= round_up(size
, EFI_PAGE_SIZE
) / EFI_PAGE_SIZE
;
73 for (i
= 0; i
< map_size
/ desc_size
; i
++) {
74 efi_memory_desc_t
*desc
;
75 unsigned long m
= (unsigned long)map
;
78 desc
= (efi_memory_desc_t
*)(m
+ (i
* desc_size
));
79 if (desc
->type
!= EFI_CONVENTIONAL_MEMORY
)
82 if (desc
->num_pages
< nr_pages
)
85 start
= desc
->phys_addr
;
86 end
= start
+ desc
->num_pages
* (1UL << EFI_PAGE_SHIFT
);
88 if ((start
+ size
) > end
|| (start
+ size
) > max
)
94 if (round_down(end
- size
, align
) < start
)
97 start
= round_down(end
- size
, align
);
100 * Don't allocate at 0x0. It will confuse code that
101 * checks pointers against NULL.
106 if (start
> max_addr
)
111 status
= EFI_NOT_FOUND
;
113 status
= efi_call_phys4(sys_table
->boottime
->allocate_pages
,
114 EFI_ALLOCATE_ADDRESS
, EFI_LOADER_DATA
,
115 nr_pages
, &max_addr
);
116 if (status
!= EFI_SUCCESS
) {
126 efi_call_phys1(sys_table
->boottime
->free_pool
, map
);
133 * Allocate at the lowest possible address.
135 static efi_status_t
low_alloc(unsigned long size
, unsigned long align
,
138 unsigned long map_size
, desc_size
;
139 efi_memory_desc_t
*map
;
141 unsigned long nr_pages
;
144 status
= __get_map(&map
, &map_size
, &desc_size
);
145 if (status
!= EFI_SUCCESS
)
148 nr_pages
= round_up(size
, EFI_PAGE_SIZE
) / EFI_PAGE_SIZE
;
149 for (i
= 0; i
< map_size
/ desc_size
; i
++) {
150 efi_memory_desc_t
*desc
;
151 unsigned long m
= (unsigned long)map
;
154 desc
= (efi_memory_desc_t
*)(m
+ (i
* desc_size
));
156 if (desc
->type
!= EFI_CONVENTIONAL_MEMORY
)
159 if (desc
->num_pages
< nr_pages
)
162 start
= desc
->phys_addr
;
163 end
= start
+ desc
->num_pages
* (1UL << EFI_PAGE_SHIFT
);
166 * Don't allocate at 0x0. It will confuse code that
167 * checks pointers against NULL. Skip the first 8
168 * bytes so we start at a nice even number.
173 start
= round_up(start
, align
);
174 if ((start
+ size
) > end
)
177 status
= efi_call_phys4(sys_table
->boottime
->allocate_pages
,
178 EFI_ALLOCATE_ADDRESS
, EFI_LOADER_DATA
,
180 if (status
== EFI_SUCCESS
) {
186 if (i
== map_size
/ desc_size
)
187 status
= EFI_NOT_FOUND
;
190 efi_call_phys1(sys_table
->boottime
->free_pool
, map
);
195 static void low_free(unsigned long size
, unsigned long addr
)
197 unsigned long nr_pages
;
199 nr_pages
= round_up(size
, EFI_PAGE_SIZE
) / EFI_PAGE_SIZE
;
200 efi_call_phys2(sys_table
->boottime
->free_pages
, addr
, size
);
203 static void find_bits(unsigned long mask
, u8
*pos
, u8
*size
)
211 while (!(mask
& 0x1)) {
227 * See if we have Graphics Output Protocol
229 static efi_status_t
setup_gop(struct screen_info
*si
, efi_guid_t
*proto
,
232 struct efi_graphics_output_protocol
*gop
, *first_gop
;
233 struct efi_pixel_bitmask pixel_info
;
234 unsigned long nr_gops
;
238 u32 fb_base
, fb_size
;
239 u32 pixels_per_scan_line
;
243 status
= efi_call_phys3(sys_table
->boottime
->allocate_pool
,
244 EFI_LOADER_DATA
, size
, &gop_handle
);
245 if (status
!= EFI_SUCCESS
)
248 status
= efi_call_phys5(sys_table
->boottime
->locate_handle
,
249 EFI_LOCATE_BY_PROTOCOL
, proto
,
250 NULL
, &size
, gop_handle
);
251 if (status
!= EFI_SUCCESS
)
256 nr_gops
= size
/ sizeof(void *);
257 for (i
= 0; i
< nr_gops
; i
++) {
258 struct efi_graphics_output_mode_info
*info
;
259 efi_guid_t pciio_proto
= EFI_PCI_IO_PROTOCOL_GUID
;
261 void *h
= gop_handle
[i
];
263 status
= efi_call_phys3(sys_table
->boottime
->handle_protocol
,
265 if (status
!= EFI_SUCCESS
)
268 efi_call_phys3(sys_table
->boottime
->handle_protocol
,
269 h
, &pciio_proto
, &pciio
);
271 status
= efi_call_phys4(gop
->query_mode
, gop
,
272 gop
->mode
->mode
, &size
, &info
);
273 if (status
== EFI_SUCCESS
&& (!first_gop
|| pciio
)) {
275 * Apple provide GOPs that are not backed by
276 * real hardware (they're used to handle
277 * multiple displays). The workaround is to
278 * search for a GOP implementing the PCIIO
279 * protocol, and if one isn't found, to just
280 * fallback to the first GOP.
282 width
= info
->horizontal_resolution
;
283 height
= info
->vertical_resolution
;
284 fb_base
= gop
->mode
->frame_buffer_base
;
285 fb_size
= gop
->mode
->frame_buffer_size
;
286 pixel_format
= info
->pixel_format
;
287 pixel_info
= info
->pixel_information
;
288 pixels_per_scan_line
= info
->pixels_per_scan_line
;
291 * Once we've found a GOP supporting PCIIO,
292 * don't bother looking any further.
301 /* Did we find any GOPs? */
305 /* EFI framebuffer */
306 si
->orig_video_isVGA
= VIDEO_TYPE_EFI
;
308 si
->lfb_width
= width
;
309 si
->lfb_height
= height
;
310 si
->lfb_base
= fb_base
;
311 si
->lfb_size
= fb_size
;
314 if (pixel_format
== PIXEL_RGB_RESERVED_8BIT_PER_COLOR
) {
316 si
->lfb_linelength
= pixels_per_scan_line
* 4;
325 } else if (pixel_format
== PIXEL_BGR_RESERVED_8BIT_PER_COLOR
) {
327 si
->lfb_linelength
= pixels_per_scan_line
* 4;
336 } else if (pixel_format
== PIXEL_BIT_MASK
) {
337 find_bits(pixel_info
.red_mask
, &si
->red_pos
, &si
->red_size
);
338 find_bits(pixel_info
.green_mask
, &si
->green_pos
,
340 find_bits(pixel_info
.blue_mask
, &si
->blue_pos
, &si
->blue_size
);
341 find_bits(pixel_info
.reserved_mask
, &si
->rsvd_pos
,
343 si
->lfb_depth
= si
->red_size
+ si
->green_size
+
344 si
->blue_size
+ si
->rsvd_size
;
345 si
->lfb_linelength
= (pixels_per_scan_line
* si
->lfb_depth
) / 8;
348 si
->lfb_linelength
= si
->lfb_width
/ 2;
360 efi_call_phys1(sys_table
->boottime
->free_pool
, gop_handle
);
365 * See if we have Universal Graphics Adapter (UGA) protocol
367 static efi_status_t
setup_uga(struct screen_info
*si
, efi_guid_t
*uga_proto
,
370 struct efi_uga_draw_protocol
*uga
, *first_uga
;
371 unsigned long nr_ugas
;
374 void **uga_handle
= NULL
;
377 status
= efi_call_phys3(sys_table
->boottime
->allocate_pool
,
378 EFI_LOADER_DATA
, size
, &uga_handle
);
379 if (status
!= EFI_SUCCESS
)
382 status
= efi_call_phys5(sys_table
->boottime
->locate_handle
,
383 EFI_LOCATE_BY_PROTOCOL
, uga_proto
,
384 NULL
, &size
, uga_handle
);
385 if (status
!= EFI_SUCCESS
)
390 nr_ugas
= size
/ sizeof(void *);
391 for (i
= 0; i
< nr_ugas
; i
++) {
392 efi_guid_t pciio_proto
= EFI_PCI_IO_PROTOCOL_GUID
;
393 void *handle
= uga_handle
[i
];
394 u32 w
, h
, depth
, refresh
;
397 status
= efi_call_phys3(sys_table
->boottime
->handle_protocol
,
398 handle
, uga_proto
, &uga
);
399 if (status
!= EFI_SUCCESS
)
402 efi_call_phys3(sys_table
->boottime
->handle_protocol
,
403 handle
, &pciio_proto
, &pciio
);
405 status
= efi_call_phys5(uga
->get_mode
, uga
, &w
, &h
,
407 if (status
== EFI_SUCCESS
&& (!first_uga
|| pciio
)) {
412 * Once we've found a UGA supporting PCIIO,
413 * don't bother looking any further.
425 /* EFI framebuffer */
426 si
->orig_video_isVGA
= VIDEO_TYPE_EFI
;
429 si
->lfb_width
= width
;
430 si
->lfb_height
= height
;
443 efi_call_phys1(sys_table
->boottime
->free_pool
, uga_handle
);
447 void setup_graphics(struct boot_params
*boot_params
)
449 efi_guid_t graphics_proto
= EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
;
450 struct screen_info
*si
;
451 efi_guid_t uga_proto
= EFI_UGA_PROTOCOL_GUID
;
454 void **gop_handle
= NULL
;
455 void **uga_handle
= NULL
;
457 si
= &boot_params
->screen_info
;
458 memset(si
, 0, sizeof(*si
));
461 status
= efi_call_phys5(sys_table
->boottime
->locate_handle
,
462 EFI_LOCATE_BY_PROTOCOL
, &graphics_proto
,
463 NULL
, &size
, gop_handle
);
464 if (status
== EFI_BUFFER_TOO_SMALL
)
465 status
= setup_gop(si
, &graphics_proto
, size
);
467 if (status
!= EFI_SUCCESS
) {
469 status
= efi_call_phys5(sys_table
->boottime
->locate_handle
,
470 EFI_LOCATE_BY_PROTOCOL
, &uga_proto
,
471 NULL
, &size
, uga_handle
);
472 if (status
== EFI_BUFFER_TOO_SMALL
)
473 setup_uga(si
, &uga_proto
, size
);
478 efi_file_handle_t
*handle
;
483 * Check the cmdline for a LILO-style initrd= arguments.
485 * We only support loading an initrd from the same filesystem as the
488 static efi_status_t
handle_ramdisks(efi_loaded_image_t
*image
,
489 struct setup_header
*hdr
)
491 struct initrd
*initrds
;
492 unsigned long initrd_addr
;
493 efi_guid_t fs_proto
= EFI_FILE_SYSTEM_GUID
;
495 efi_file_io_interface_t
*io
;
496 efi_file_handle_t
*fh
;
505 str
= (char *)(unsigned long)hdr
->cmd_line_ptr
;
507 j
= 0; /* See close_handles */
512 for (nr_initrds
= 0; *str
; nr_initrds
++) {
513 str
= strstr(str
, "initrd=");
519 /* Skip any leading slashes */
520 while (*str
== '/' || *str
== '\\')
523 while (*str
&& *str
!= ' ' && *str
!= '\n')
530 status
= efi_call_phys3(sys_table
->boottime
->allocate_pool
,
532 nr_initrds
* sizeof(*initrds
),
534 if (status
!= EFI_SUCCESS
)
537 str
= (char *)(unsigned long)hdr
->cmd_line_ptr
;
538 for (i
= 0; i
< nr_initrds
; i
++) {
539 struct initrd
*initrd
;
540 efi_file_handle_t
*h
;
541 efi_file_info_t
*info
;
542 efi_char16_t filename_16
[256];
543 unsigned long info_sz
;
544 efi_guid_t info_guid
= EFI_FILE_INFO_ID
;
548 str
= strstr(str
, "initrd=");
554 initrd
= &initrds
[i
];
557 /* Skip any leading slashes */
558 while (*str
== '/' || *str
== '\\')
561 while (*str
&& *str
!= ' ' && *str
!= '\n') {
562 if ((u8
*)p
>= (u8
*)filename_16
+ sizeof(filename_16
))
570 /* Only open the volume once. */
572 efi_boot_services_t
*boottime
;
574 boottime
= sys_table
->boottime
;
576 status
= efi_call_phys3(boottime
->handle_protocol
,
577 image
->device_handle
, &fs_proto
, &io
);
578 if (status
!= EFI_SUCCESS
)
581 status
= efi_call_phys2(io
->open_volume
, io
, &fh
);
582 if (status
!= EFI_SUCCESS
)
586 status
= efi_call_phys5(fh
->open
, fh
, &h
, filename_16
,
587 EFI_FILE_MODE_READ
, (u64
)0);
588 if (status
!= EFI_SUCCESS
)
594 status
= efi_call_phys4(h
->get_info
, h
, &info_guid
,
596 if (status
!= EFI_BUFFER_TOO_SMALL
)
600 status
= efi_call_phys3(sys_table
->boottime
->allocate_pool
,
601 EFI_LOADER_DATA
, info_sz
, &info
);
602 if (status
!= EFI_SUCCESS
)
605 status
= efi_call_phys4(h
->get_info
, h
, &info_guid
,
607 if (status
== EFI_BUFFER_TOO_SMALL
) {
608 efi_call_phys1(sys_table
->boottime
->free_pool
, info
);
612 file_sz
= info
->file_size
;
613 efi_call_phys1(sys_table
->boottime
->free_pool
, info
);
615 if (status
!= EFI_SUCCESS
)
618 initrd
->size
= file_sz
;
619 initrd_total
+= file_sz
;
626 * Multiple initrd's need to be at consecutive
627 * addresses in memory, so allocate enough memory for
630 status
= high_alloc(initrd_total
, 0x1000,
631 &initrd_addr
, hdr
->initrd_addr_max
);
632 if (status
!= EFI_SUCCESS
)
635 /* We've run out of free low memory. */
636 if (initrd_addr
> hdr
->initrd_addr_max
) {
637 status
= EFI_INVALID_PARAMETER
;
638 goto free_initrd_total
;
642 for (j
= 0; j
< nr_initrds
; j
++) {
645 size
= initrds
[j
].size
;
648 if (size
> EFI_READ_CHUNK_SIZE
)
649 chunksize
= EFI_READ_CHUNK_SIZE
;
652 status
= efi_call_phys3(fh
->read
,
655 if (status
!= EFI_SUCCESS
)
656 goto free_initrd_total
;
661 efi_call_phys1(fh
->close
, initrds
[j
].handle
);
666 efi_call_phys1(sys_table
->boottime
->free_pool
, initrds
);
668 hdr
->ramdisk_image
= initrd_addr
;
669 hdr
->ramdisk_size
= initrd_total
;
674 low_free(initrd_total
, initrd_addr
);
677 for (k
= j
; k
< nr_initrds
; k
++)
678 efi_call_phys1(fh
->close
, initrds
[k
].handle
);
680 efi_call_phys1(sys_table
->boottime
->free_pool
, initrds
);
682 hdr
->ramdisk_image
= 0;
683 hdr
->ramdisk_size
= 0;
689 * Because the x86 boot code expects to be passed a boot_params we
690 * need to create one ourselves (usually the bootloader would create
693 static efi_status_t
make_boot_params(struct boot_params
*boot_params
,
694 efi_loaded_image_t
*image
,
697 struct efi_info
*efi
= &boot_params
->efi_info
;
698 struct apm_bios_info
*bi
= &boot_params
->apm_bios_info
;
699 struct sys_desc_table
*sdt
= &boot_params
->sys_desc_table
;
700 struct e820entry
*e820_map
= &boot_params
->e820_map
[0];
701 struct e820entry
*prev
= NULL
;
702 struct setup_header
*hdr
= &boot_params
->hdr
;
703 unsigned long size
, key
, desc_size
, _size
;
704 efi_memory_desc_t
*mem_map
;
705 void *options
= image
->load_options
;
706 u32 load_options_size
= image
->load_options_size
/ 2; /* ASCII */
707 int options_size
= 0;
710 unsigned long cmdline
;
716 hdr
->type_of_loader
= 0x21;
718 /* Convert unicode cmdline to ascii */
723 while (*s2
&& *s2
!= '\n' && options_size
< load_options_size
) {
729 if (options_size
> hdr
->cmdline_size
)
730 options_size
= hdr
->cmdline_size
;
732 options_size
++; /* NUL termination */
734 status
= low_alloc(options_size
, 1, &cmdline
);
735 if (status
!= EFI_SUCCESS
)
738 s1
= (u8
*)(unsigned long)cmdline
;
741 for (i
= 0; i
< options_size
- 1; i
++)
748 hdr
->cmd_line_ptr
= cmdline
;
750 hdr
->ramdisk_image
= 0;
751 hdr
->ramdisk_size
= 0;
753 status
= handle_ramdisks(image
, hdr
);
754 if (status
!= EFI_SUCCESS
)
757 setup_graphics(boot_params
);
759 /* Clear APM BIOS info */
760 memset(bi
, 0, sizeof(*bi
));
762 memset(sdt
, 0, sizeof(*sdt
));
764 memcpy(&efi
->efi_loader_signature
, EFI_LOADER_SIGNATURE
, sizeof(__u32
));
766 size
= sizeof(*mem_map
) * 32;
769 size
+= sizeof(*mem_map
);
771 status
= low_alloc(size
, 1, (unsigned long *)&mem_map
);
772 if (status
!= EFI_SUCCESS
)
775 status
= efi_call_phys5(sys_table
->boottime
->get_memory_map
, &size
,
776 mem_map
, &key
, &desc_size
, &desc_version
);
777 if (status
== EFI_BUFFER_TOO_SMALL
) {
778 low_free(_size
, (unsigned long)mem_map
);
782 if (status
!= EFI_SUCCESS
)
785 efi
->efi_systab
= (unsigned long)sys_table
;
786 efi
->efi_memdesc_size
= desc_size
;
787 efi
->efi_memdesc_version
= desc_version
;
788 efi
->efi_memmap
= (unsigned long)mem_map
;
789 efi
->efi_memmap_size
= size
;
792 efi
->efi_systab_hi
= (unsigned long)sys_table
>> 32;
793 efi
->efi_memmap_hi
= (unsigned long)mem_map
>> 32;
796 /* Might as well exit boot services now */
797 status
= efi_call_phys2(sys_table
->boottime
->exit_boot_services
,
799 if (status
!= EFI_SUCCESS
)
803 boot_params
->alt_mem_k
= 32 * 1024;
806 * Convert the EFI memory map to E820.
809 for (i
= 0; i
< size
/ desc_size
; i
++) {
810 efi_memory_desc_t
*d
;
811 unsigned int e820_type
= 0;
812 unsigned long m
= (unsigned long)mem_map
;
814 d
= (efi_memory_desc_t
*)(m
+ (i
* desc_size
));
816 case EFI_RESERVED_TYPE
:
817 case EFI_RUNTIME_SERVICES_CODE
:
818 case EFI_RUNTIME_SERVICES_DATA
:
819 case EFI_MEMORY_MAPPED_IO
:
820 case EFI_MEMORY_MAPPED_IO_PORT_SPACE
:
822 e820_type
= E820_RESERVED
;
825 case EFI_UNUSABLE_MEMORY
:
826 e820_type
= E820_UNUSABLE
;
829 case EFI_ACPI_RECLAIM_MEMORY
:
830 e820_type
= E820_ACPI
;
833 case EFI_LOADER_CODE
:
834 case EFI_LOADER_DATA
:
835 case EFI_BOOT_SERVICES_CODE
:
836 case EFI_BOOT_SERVICES_DATA
:
837 case EFI_CONVENTIONAL_MEMORY
:
838 e820_type
= E820_RAM
;
841 case EFI_ACPI_MEMORY_NVS
:
842 e820_type
= E820_NVS
;
849 /* Merge adjacent mappings */
850 if (prev
&& prev
->type
== e820_type
&&
851 (prev
->addr
+ prev
->size
) == d
->phys_addr
)
852 prev
->size
+= d
->num_pages
<< 12;
854 e820_map
->addr
= d
->phys_addr
;
855 e820_map
->size
= d
->num_pages
<< 12;
856 e820_map
->type
= e820_type
;
862 boot_params
->e820_entries
= nr_entries
;
867 low_free(_size
, (unsigned long)mem_map
);
870 low_free(options_size
, hdr
->cmd_line_ptr
);
876 * On success we return a pointer to a boot_params structure, and NULL
879 struct boot_params
*efi_main(void *handle
, efi_system_table_t
*_table
)
881 struct boot_params
*boot_params
;
882 unsigned long start
, nr_pages
;
883 struct desc_ptr
*gdt
, *idt
;
884 efi_loaded_image_t
*image
;
885 struct setup_header
*hdr
;
887 efi_guid_t proto
= LOADED_IMAGE_PROTOCOL_GUID
;
888 struct desc_struct
*desc
;
892 /* Check if we were booted by the EFI firmware */
893 if (sys_table
->hdr
.signature
!= EFI_SYSTEM_TABLE_SIGNATURE
)
896 status
= efi_call_phys3(sys_table
->boottime
->handle_protocol
,
897 handle
, &proto
, (void *)&image
);
898 if (status
!= EFI_SUCCESS
)
901 status
= low_alloc(0x4000, 1, (unsigned long *)&boot_params
);
902 if (status
!= EFI_SUCCESS
)
905 memset(boot_params
, 0x0, 0x4000);
907 /* Copy first two sectors to boot_params */
908 memcpy(boot_params
, image
->image_base
, 1024);
910 hdr
= &boot_params
->hdr
;
913 * The EFI firmware loader could have placed the kernel image
914 * anywhere in memory, but the kernel has various restrictions
915 * on the max physical address it can run at. Attempt to move
916 * the kernel to boot_params.pref_address, or as low as
919 start
= hdr
->pref_address
;
920 nr_pages
= round_up(hdr
->init_size
, EFI_PAGE_SIZE
) / EFI_PAGE_SIZE
;
922 status
= efi_call_phys4(sys_table
->boottime
->allocate_pages
,
923 EFI_ALLOCATE_ADDRESS
, EFI_LOADER_DATA
,
925 if (status
!= EFI_SUCCESS
) {
926 status
= low_alloc(hdr
->init_size
, hdr
->kernel_alignment
,
928 if (status
!= EFI_SUCCESS
)
932 hdr
->code32_start
= (__u32
)start
;
933 hdr
->pref_address
= (__u64
)(unsigned long)image
->image_base
;
935 memcpy((void *)start
, image
->image_base
, image
->image_size
);
937 status
= efi_call_phys3(sys_table
->boottime
->allocate_pool
,
938 EFI_LOADER_DATA
, sizeof(*gdt
),
940 if (status
!= EFI_SUCCESS
)
944 status
= low_alloc(gdt
->size
, 8, (unsigned long *)&gdt
->address
);
945 if (status
!= EFI_SUCCESS
)
948 status
= efi_call_phys3(sys_table
->boottime
->allocate_pool
,
949 EFI_LOADER_DATA
, sizeof(*idt
),
951 if (status
!= EFI_SUCCESS
)
957 status
= make_boot_params(boot_params
, image
, handle
);
958 if (status
!= EFI_SUCCESS
)
961 memset((char *)gdt
->address
, 0x0, gdt
->size
);
962 desc
= (struct desc_struct
*)gdt
->address
;
964 /* The first GDT is a dummy and the second is unused. */
967 desc
->limit0
= 0xffff;
968 desc
->base0
= 0x0000;
969 desc
->base1
= 0x0000;
970 desc
->type
= SEG_TYPE_CODE
| SEG_TYPE_EXEC_READ
;
971 desc
->s
= DESC_TYPE_CODE_DATA
;
977 desc
->d
= SEG_OP_SIZE_32BIT
;
978 desc
->g
= SEG_GRANULARITY_4KB
;
982 desc
->limit0
= 0xffff;
983 desc
->base0
= 0x0000;
984 desc
->base1
= 0x0000;
985 desc
->type
= SEG_TYPE_DATA
| SEG_TYPE_READ_WRITE
;
986 desc
->s
= DESC_TYPE_CODE_DATA
;
992 desc
->d
= SEG_OP_SIZE_32BIT
;
993 desc
->g
= SEG_GRANULARITY_4KB
;
997 /* Task segment value */
999 desc
->limit0
= 0x0000;
1000 desc
->base0
= 0x0000;
1001 desc
->base1
= 0x0000;
1002 desc
->type
= SEG_TYPE_TSS
;
1010 desc
->g
= SEG_GRANULARITY_4KB
;
1012 #endif /* CONFIG_X86_64 */
1014 asm volatile ("lidt %0" : : "m" (*idt
));
1015 asm volatile ("lgdt %0" : : "m" (*gdt
));
1017 asm volatile("cli");