12 #include <asm/setup.h>
21 static void efi_printk(
char *
str)
25 for (s8 = str; *
s8; s8++) {
42 unsigned long *desc_size)
49 *map_size =
sizeof(*m) * 32;
55 *map_size +=
sizeof(*m);
62 m, &key, desc_size, &desc_version);
80 unsigned long *
addr,
unsigned long max)
82 unsigned long map_size, desc_size;
85 unsigned long nr_pages;
89 status = __get_map(&map, &map_size, &desc_size);
95 for (i = 0; i < map_size / desc_size; i++) {
97 unsigned long m = (
unsigned long)map;
110 if ((start + size) > end || (start +
size) > max)
113 if (end - size > max)
128 if (start > max_addr)
137 nr_pages, &max_addr);
157 static efi_status_t low_alloc(
unsigned long size,
unsigned long align,
160 unsigned long map_size, desc_size;
163 unsigned long nr_pages;
166 status = __get_map(&map, &map_size, &desc_size);
171 for (i = 0; i < map_size / desc_size; i++) {
173 unsigned long m = (
unsigned long)map;
196 if ((start + size) > end)
208 if (i == map_size / desc_size)
217 static void low_free(
unsigned long size,
unsigned long addr)
219 unsigned long nr_pages;
225 static void find_bits(
unsigned long mask,
u8 *
pos,
u8 *size)
233 while (!(mask & 0x1)) {
256 unsigned long nr_gops;
260 u32 fb_base, fb_size;
261 u32 pixels_per_scan_line;
272 NULL, &size, gop_handle);
278 nr_gops = size /
sizeof(
void *);
279 for (i = 0; i < nr_gops; i++) {
282 bool conout_found =
false;
284 void *
h = gop_handle[
i];
292 h, &conout_proto, &dummy);
298 gop->
mode->mode, &size, &info);
299 if (status ==
EFI_SUCCESS && (!first_gop || conout_found)) {
309 fb_base = gop->
mode->frame_buffer_base;
310 fb_size = gop->
mode->frame_buffer_size;
362 find_bits(pixel_info.green_mask, &si->
green_pos,
365 find_bits(pixel_info.reserved_mask, &si->
rsvd_pos,
399 unsigned long nr_ugas;
402 void **uga_handle =
NULL;
412 NULL, &size, uga_handle);
418 nr_ugas = size /
sizeof(
void *);
419 for (i = 0; i < nr_ugas; i++) {
426 handle, uga_proto, &uga);
431 handle, &pciio_proto, &pciio);
435 if (status ==
EFI_SUCCESS && (!first_uga || pciio)) {
482 void **gop_handle =
NULL;
483 void **uga_handle =
NULL;
486 memset(si, 0,
sizeof(*si));
491 NULL, &size, gop_handle);
493 status = setup_gop(si, &graphics_proto, size);
499 NULL, &size, uga_handle);
501 setup_uga(si, &uga_proto, size);
520 unsigned long initrd_addr;
540 for (nr_initrds = 0; *
str; nr_initrds++) {
541 str =
strstr(str,
"initrd=");
548 while (*str ==
'/' || *str ==
'\\')
551 while (*str && *str !=
' ' && *str !=
'\n')
560 nr_initrds *
sizeof(*initrds),
563 efi_printk(
"Failed to alloc mem for initrds\n");
568 for (i = 0; i < nr_initrds; i++) {
573 unsigned long info_sz;
578 str =
strstr(str,
"initrd=");
584 initrd = &initrds[
i];
588 while (*str ==
'/' || *str ==
'\\')
591 while (*str && *str !=
' ' && *str !=
'\n') {
592 if ((
u8 *)p >= (
u8 *)filename_16 +
sizeof(filename_16))
609 efi_printk(
"Failed to handle fs_proto\n");
615 efi_printk(
"Failed to open volume\n");
623 efi_printk(
"Failed to open initrd file\n");
633 efi_printk(
"Failed to get initrd info size\n");
641 efi_printk(
"Failed to alloc mem for initrd info\n");
656 efi_printk(
"Failed to get initrd info\n");
660 initrd->
size = file_sz;
661 initrd_total += file_sz;
672 status = high_alloc(initrd_total, 0x1000,
675 efi_printk(
"Failed to alloc highmem for initrds\n");
681 efi_printk(
"We've run out of free low memory\n");
683 goto free_initrd_total;
687 for (j = 0; j < nr_initrds; j++) {
690 size = initrds[
j].
size;
701 efi_printk(
"Failed to read initrd\n");
702 goto free_initrd_total;
721 low_free(initrd_total, initrd_addr);
724 for (k = j; k <
i; k++)
749 u32 load_options_size;
751 int options_size = 0;
765 handle, &proto, (
void *)&image);
767 efi_printk(
"Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
771 status = low_alloc(0x4000, 1, (
unsigned long *)&boot_params);
773 efi_printk(
"Failed to alloc lowmem for boot params\n");
777 memset(boot_params, 0x0, 0x4000);
779 hdr = &boot_params->
hdr;
806 while (*s2 && *s2 !=
'\n' && options_size < load_options_size) {
817 status = low_alloc(options_size, 1, &cmdline);
819 efi_printk(
"Failed to alloc mem for cmdline\n");
823 s1 = (
u8 *)(
unsigned long)cmdline;
826 for (i = 0; i < options_size - 1; i++)
839 memset(bi, 0,
sizeof(*bi));
841 memset(sdt, 0,
sizeof(*sdt));
843 status = handle_ramdisks(image, hdr);
852 low_free(0x4000, (
unsigned long)boot_params);
869 size =
sizeof(*mem_map) * 32;
872 size +=
sizeof(*mem_map);
874 status = low_alloc(size, 1, (
unsigned long *)&mem_map);
879 mem_map, &key, &desc_size, &desc_version);
881 low_free(_size, (
unsigned long)mem_map);
913 for (i = 0; i < size / desc_size; i++) {
915 unsigned int e820_type = 0;
916 unsigned long m = (
unsigned long)mem_map;
954 if (prev && prev->
type == e820_type &&
960 e820_map->
type = e820_type;
971 low_free(_size, (
unsigned long)mem_map);
977 unsigned long start, nr_pages;
997 efi_printk(
"Failed to alloc mem for kernel\n");
1015 struct boot_params *boot_params)
1035 efi_printk(
"Failed to alloc mem for gdt structure\n");
1040 status = low_alloc(gdt->
size, 8, (
unsigned long *)&gdt->
address);
1042 efi_printk(
"Failed to alloc mem for gdt\n");
1050 efi_printk(
"Failed to alloc mem for idt structure\n");
1068 status = exit_boot(boot_params, handle);
1079 desc->
base0 = 0x0000;
1080 desc->
base1 = 0x0000;
1094 desc->
base0 = 0x0000;
1095 desc->
base1 = 0x0000;
1107 #ifdef CONFIG_X86_64
1111 desc->
base0 = 0x0000;
1112 desc->
base1 = 0x0000;
1125 asm volatile (
"lidt %0" : :
"m" (*idt));
1126 asm volatile (
"lgdt %0" : :
"m" (*gdt));
1128 asm volatile(
"cli");