blob: b7f220877294a45e6aa63d83ac0ab8656b3533f7 [file] [log] [blame]
Matt Fleming291f3632011-12-12 21:27:52 +00001/* -----------------------------------------------------------------------
2 *
3 * Copyright 2011 Intel Corporation; author Matt Fleming
4 *
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.
7 *
8 * ----------------------------------------------------------------------- */
9
10#include <linux/efi.h>
Matthew Garrettdd5fc852012-12-05 14:33:26 -070011#include <linux/pci.h>
Matt Fleming291f3632011-12-12 21:27:52 +000012#include <asm/efi.h>
13#include <asm/setup.h>
14#include <asm/desc.h>
15
Matt Fleming0f905a42012-11-20 13:07:46 +000016#undef memcpy /* Use memcpy from misc.c */
17
Matt Fleming291f3632011-12-12 21:27:52 +000018#include "eboot.h"
19
20static efi_system_table_t *sys_table;
21
Matt Fleming9fa7ded2012-02-20 13:20:59 +000022static void efi_printk(char *str)
23{
24 char *s8;
25
26 for (s8 = str; *s8; s8++) {
27 struct efi_simple_text_output_protocol *out;
28 efi_char16_t ch[2] = { 0 };
29
30 ch[0] = *s8;
31 out = (struct efi_simple_text_output_protocol *)sys_table->con_out;
32
33 if (*s8 == '\n') {
34 efi_char16_t nl[2] = { '\r', 0 };
35 efi_call_phys2(out->output_string, out, nl);
36 }
37
38 efi_call_phys2(out->output_string, out, ch);
39 }
40}
41
Matt Fleming291f3632011-12-12 21:27:52 +000042static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size,
43 unsigned long *desc_size)
44{
45 efi_memory_desc_t *m = NULL;
46 efi_status_t status;
47 unsigned long key;
48 u32 desc_version;
49
50 *map_size = sizeof(*m) * 32;
51again:
52 /*
53 * Add an additional efi_memory_desc_t because we're doing an
54 * allocation which may be in a new descriptor region.
55 */
56 *map_size += sizeof(*m);
57 status = efi_call_phys3(sys_table->boottime->allocate_pool,
58 EFI_LOADER_DATA, *map_size, (void **)&m);
59 if (status != EFI_SUCCESS)
60 goto fail;
61
62 status = efi_call_phys5(sys_table->boottime->get_memory_map, map_size,
63 m, &key, desc_size, &desc_version);
64 if (status == EFI_BUFFER_TOO_SMALL) {
65 efi_call_phys1(sys_table->boottime->free_pool, m);
66 goto again;
67 }
68
69 if (status != EFI_SUCCESS)
70 efi_call_phys1(sys_table->boottime->free_pool, m);
71
72fail:
73 *map = m;
74 return status;
75}
76
77/*
78 * Allocate at the highest possible address that is not above 'max'.
79 */
80static efi_status_t high_alloc(unsigned long size, unsigned long align,
81 unsigned long *addr, unsigned long max)
82{
83 unsigned long map_size, desc_size;
84 efi_memory_desc_t *map;
85 efi_status_t status;
86 unsigned long nr_pages;
87 u64 max_addr = 0;
88 int i;
89
90 status = __get_map(&map, &map_size, &desc_size);
91 if (status != EFI_SUCCESS)
92 goto fail;
93
94 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
95again:
96 for (i = 0; i < map_size / desc_size; i++) {
97 efi_memory_desc_t *desc;
98 unsigned long m = (unsigned long)map;
99 u64 start, end;
100
101 desc = (efi_memory_desc_t *)(m + (i * desc_size));
102 if (desc->type != EFI_CONVENTIONAL_MEMORY)
103 continue;
104
105 if (desc->num_pages < nr_pages)
106 continue;
107
108 start = desc->phys_addr;
109 end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT);
110
111 if ((start + size) > end || (start + size) > max)
112 continue;
113
114 if (end - size > max)
115 end = max;
116
117 if (round_down(end - size, align) < start)
118 continue;
119
120 start = round_down(end - size, align);
121
122 /*
123 * Don't allocate at 0x0. It will confuse code that
124 * checks pointers against NULL.
125 */
126 if (start == 0x0)
127 continue;
128
129 if (start > max_addr)
130 max_addr = start;
131 }
132
133 if (!max_addr)
134 status = EFI_NOT_FOUND;
135 else {
136 status = efi_call_phys4(sys_table->boottime->allocate_pages,
137 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
138 nr_pages, &max_addr);
139 if (status != EFI_SUCCESS) {
140 max = max_addr;
141 max_addr = 0;
142 goto again;
143 }
144
145 *addr = max_addr;
146 }
147
148free_pool:
149 efi_call_phys1(sys_table->boottime->free_pool, map);
150
151fail:
152 return status;
153}
154
155/*
156 * Allocate at the lowest possible address.
157 */
158static efi_status_t low_alloc(unsigned long size, unsigned long align,
159 unsigned long *addr)
160{
161 unsigned long map_size, desc_size;
162 efi_memory_desc_t *map;
163 efi_status_t status;
164 unsigned long nr_pages;
165 int i;
166
167 status = __get_map(&map, &map_size, &desc_size);
168 if (status != EFI_SUCCESS)
169 goto fail;
170
171 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
172 for (i = 0; i < map_size / desc_size; i++) {
173 efi_memory_desc_t *desc;
174 unsigned long m = (unsigned long)map;
175 u64 start, end;
176
177 desc = (efi_memory_desc_t *)(m + (i * desc_size));
178
179 if (desc->type != EFI_CONVENTIONAL_MEMORY)
180 continue;
181
182 if (desc->num_pages < nr_pages)
183 continue;
184
185 start = desc->phys_addr;
186 end = start + desc->num_pages * (1UL << EFI_PAGE_SHIFT);
187
188 /*
189 * Don't allocate at 0x0. It will confuse code that
190 * checks pointers against NULL. Skip the first 8
191 * bytes so we start at a nice even number.
192 */
193 if (start == 0x0)
194 start += 8;
195
196 start = round_up(start, align);
197 if ((start + size) > end)
198 continue;
199
200 status = efi_call_phys4(sys_table->boottime->allocate_pages,
201 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
202 nr_pages, &start);
203 if (status == EFI_SUCCESS) {
204 *addr = start;
205 break;
206 }
207 }
208
209 if (i == map_size / desc_size)
210 status = EFI_NOT_FOUND;
211
212free_pool:
213 efi_call_phys1(sys_table->boottime->free_pool, map);
214fail:
215 return status;
216}
217
218static void low_free(unsigned long size, unsigned long addr)
219{
220 unsigned long nr_pages;
221
222 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
223 efi_call_phys2(sys_table->boottime->free_pages, addr, size);
224}
225
226static void find_bits(unsigned long mask, u8 *pos, u8 *size)
227{
228 u8 first, len;
229
230 first = 0;
231 len = 0;
232
233 if (mask) {
234 while (!(mask & 0x1)) {
235 mask = mask >> 1;
236 first++;
237 }
238
239 while (mask & 0x1) {
240 mask = mask >> 1;
241 len++;
242 }
243 }
244
245 *pos = first;
246 *size = len;
247}
248
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700249static efi_status_t setup_efi_pci(struct boot_params *params)
250{
251 efi_pci_io_protocol *pci;
252 efi_status_t status;
253 void **pci_handle;
254 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
255 unsigned long nr_pci, size = 0;
256 int i;
257 struct setup_data *data;
258
259 data = (struct setup_data *)params->hdr.setup_data;
260
261 while (data && data->next)
262 data = (struct setup_data *)data->next;
263
264 status = efi_call_phys5(sys_table->boottime->locate_handle,
265 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
266 NULL, &size, pci_handle);
267
268 if (status == EFI_BUFFER_TOO_SMALL) {
269 status = efi_call_phys3(sys_table->boottime->allocate_pool,
270 EFI_LOADER_DATA, size, &pci_handle);
271
272 if (status != EFI_SUCCESS)
273 return status;
274
275 status = efi_call_phys5(sys_table->boottime->locate_handle,
276 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
277 NULL, &size, pci_handle);
278 }
279
280 if (status != EFI_SUCCESS)
281 goto free_handle;
282
283 nr_pci = size / sizeof(void *);
284 for (i = 0; i < nr_pci; i++) {
285 void *h = pci_handle[i];
286 uint64_t attributes;
287 struct pci_setup_rom *rom;
288
289 status = efi_call_phys3(sys_table->boottime->handle_protocol,
290 h, &pci_proto, &pci);
291
292 if (status != EFI_SUCCESS)
293 continue;
294
295 if (!pci)
296 continue;
297
David Woodhouseb607e212013-01-07 22:09:49 +0000298#ifdef CONFIG_X86_64
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700299 status = efi_call_phys4(pci->attributes, pci,
300 EfiPciIoAttributeOperationGet, 0,
301 &attributes);
David Woodhouseb607e212013-01-07 22:09:49 +0000302#else
303 status = efi_call_phys5(pci->attributes, pci,
304 EfiPciIoAttributeOperationGet, 0, 0,
305 &attributes);
306#endif
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700307 if (status != EFI_SUCCESS)
308 continue;
309
Sasha Levin886d7512012-12-20 14:11:33 -0500310 if (!(attributes & EFI_PCI_IO_ATTRIBUTE_EMBEDDED_ROM))
Matthew Garrettdd5fc852012-12-05 14:33:26 -0700311 continue;
312
313 if (!pci->romimage || !pci->romsize)
314 continue;
315
316 size = pci->romsize + sizeof(*rom);
317
318 status = efi_call_phys3(sys_table->boottime->allocate_pool,
319 EFI_LOADER_DATA, size, &rom);
320
321 if (status != EFI_SUCCESS)
322 continue;
323
324 rom->data.type = SETUP_PCI;
325 rom->data.len = size - sizeof(struct setup_data);
326 rom->data.next = 0;
327 rom->pcilen = pci->romsize;
328
329 status = efi_call_phys5(pci->pci.read, pci,
330 EfiPciIoWidthUint16, PCI_VENDOR_ID,
331 1, &(rom->vendor));
332
333 if (status != EFI_SUCCESS)
334 goto free_struct;
335
336 status = efi_call_phys5(pci->pci.read, pci,
337 EfiPciIoWidthUint16, PCI_DEVICE_ID,
338 1, &(rom->devid));
339
340 if (status != EFI_SUCCESS)
341 goto free_struct;
342
343 status = efi_call_phys5(pci->get_location, pci,
344 &(rom->segment), &(rom->bus),
345 &(rom->device), &(rom->function));
346
347 if (status != EFI_SUCCESS)
348 goto free_struct;
349
350 memcpy(rom->romdata, pci->romimage, pci->romsize);
351
352 if (data)
353 data->next = (uint64_t)rom;
354 else
355 params->hdr.setup_data = (uint64_t)rom;
356
357 data = (struct setup_data *)rom;
358
359 continue;
360 free_struct:
361 efi_call_phys1(sys_table->boottime->free_pool, rom);
362 }
363
364free_handle:
365 efi_call_phys1(sys_table->boottime->free_pool, pci_handle);
366 return status;
367}
368
Matt Fleming291f3632011-12-12 21:27:52 +0000369/*
370 * See if we have Graphics Output Protocol
371 */
372static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
373 unsigned long size)
374{
375 struct efi_graphics_output_protocol *gop, *first_gop;
376 struct efi_pixel_bitmask pixel_info;
377 unsigned long nr_gops;
378 efi_status_t status;
379 void **gop_handle;
380 u16 width, height;
381 u32 fb_base, fb_size;
382 u32 pixels_per_scan_line;
383 int pixel_format;
384 int i;
385
386 status = efi_call_phys3(sys_table->boottime->allocate_pool,
387 EFI_LOADER_DATA, size, &gop_handle);
388 if (status != EFI_SUCCESS)
389 return status;
390
391 status = efi_call_phys5(sys_table->boottime->locate_handle,
392 EFI_LOCATE_BY_PROTOCOL, proto,
393 NULL, &size, gop_handle);
394 if (status != EFI_SUCCESS)
395 goto free_handle;
396
397 first_gop = NULL;
398
399 nr_gops = size / sizeof(void *);
400 for (i = 0; i < nr_gops; i++) {
401 struct efi_graphics_output_mode_info *info;
Matthew Garrett38cb5ef2012-07-26 18:00:27 -0400402 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
403 bool conout_found = false;
404 void *dummy;
Matt Fleming291f3632011-12-12 21:27:52 +0000405 void *h = gop_handle[i];
406
407 status = efi_call_phys3(sys_table->boottime->handle_protocol,
408 h, proto, &gop);
409 if (status != EFI_SUCCESS)
410 continue;
411
Matthew Garrett38cb5ef2012-07-26 18:00:27 -0400412 status = efi_call_phys3(sys_table->boottime->handle_protocol,
413 h, &conout_proto, &dummy);
414
415 if (status == EFI_SUCCESS)
416 conout_found = true;
Matt Fleming291f3632011-12-12 21:27:52 +0000417
418 status = efi_call_phys4(gop->query_mode, gop,
419 gop->mode->mode, &size, &info);
Matthew Garrett38cb5ef2012-07-26 18:00:27 -0400420 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
Matt Fleming291f3632011-12-12 21:27:52 +0000421 /*
Matthew Garrett38cb5ef2012-07-26 18:00:27 -0400422 * Systems that use the UEFI Console Splitter may
423 * provide multiple GOP devices, not all of which are
424 * backed by real hardware. The workaround is to search
425 * for a GOP implementing the ConOut protocol, and if
426 * one isn't found, to just fall back to the first GOP.
Matt Fleming291f3632011-12-12 21:27:52 +0000427 */
428 width = info->horizontal_resolution;
429 height = info->vertical_resolution;
430 fb_base = gop->mode->frame_buffer_base;
431 fb_size = gop->mode->frame_buffer_size;
432 pixel_format = info->pixel_format;
433 pixel_info = info->pixel_information;
434 pixels_per_scan_line = info->pixels_per_scan_line;
435
436 /*
Matthew Garrett38cb5ef2012-07-26 18:00:27 -0400437 * Once we've found a GOP supporting ConOut,
Matt Fleming291f3632011-12-12 21:27:52 +0000438 * don't bother looking any further.
439 */
David Woodhouse70a479c2013-01-07 21:52:16 +0000440 first_gop = gop;
Matthew Garrett38cb5ef2012-07-26 18:00:27 -0400441 if (conout_found)
Matt Fleming291f3632011-12-12 21:27:52 +0000442 break;
Matt Fleming291f3632011-12-12 21:27:52 +0000443 }
444 }
445
446 /* Did we find any GOPs? */
447 if (!first_gop)
448 goto free_handle;
449
450 /* EFI framebuffer */
451 si->orig_video_isVGA = VIDEO_TYPE_EFI;
452
453 si->lfb_width = width;
454 si->lfb_height = height;
455 si->lfb_base = fb_base;
Matt Fleming291f3632011-12-12 21:27:52 +0000456 si->pages = 1;
457
458 if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) {
459 si->lfb_depth = 32;
460 si->lfb_linelength = pixels_per_scan_line * 4;
461 si->red_size = 8;
462 si->red_pos = 0;
463 si->green_size = 8;
464 si->green_pos = 8;
465 si->blue_size = 8;
466 si->blue_pos = 16;
467 si->rsvd_size = 8;
468 si->rsvd_pos = 24;
469 } else if (pixel_format == PIXEL_BGR_RESERVED_8BIT_PER_COLOR) {
470 si->lfb_depth = 32;
471 si->lfb_linelength = pixels_per_scan_line * 4;
472 si->red_size = 8;
473 si->red_pos = 16;
474 si->green_size = 8;
475 si->green_pos = 8;
476 si->blue_size = 8;
477 si->blue_pos = 0;
478 si->rsvd_size = 8;
479 si->rsvd_pos = 24;
480 } else if (pixel_format == PIXEL_BIT_MASK) {
481 find_bits(pixel_info.red_mask, &si->red_pos, &si->red_size);
482 find_bits(pixel_info.green_mask, &si->green_pos,
483 &si->green_size);
484 find_bits(pixel_info.blue_mask, &si->blue_pos, &si->blue_size);
485 find_bits(pixel_info.reserved_mask, &si->rsvd_pos,
486 &si->rsvd_size);
487 si->lfb_depth = si->red_size + si->green_size +
488 si->blue_size + si->rsvd_size;
489 si->lfb_linelength = (pixels_per_scan_line * si->lfb_depth) / 8;
490 } else {
491 si->lfb_depth = 4;
492 si->lfb_linelength = si->lfb_width / 2;
493 si->red_size = 0;
494 si->red_pos = 0;
495 si->green_size = 0;
496 si->green_pos = 0;
497 si->blue_size = 0;
498 si->blue_pos = 0;
499 si->rsvd_size = 0;
500 si->rsvd_pos = 0;
501 }
502
Matthew Garrette9b10952012-07-27 17:20:49 -0400503 si->lfb_size = si->lfb_linelength * si->lfb_height;
504
Matthew Garrettf462ed92012-07-27 12:58:53 -0400505 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
506
Matt Fleming291f3632011-12-12 21:27:52 +0000507free_handle:
508 efi_call_phys1(sys_table->boottime->free_pool, gop_handle);
509 return status;
510}
511
512/*
513 * See if we have Universal Graphics Adapter (UGA) protocol
514 */
515static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
516 unsigned long size)
517{
518 struct efi_uga_draw_protocol *uga, *first_uga;
519 unsigned long nr_ugas;
520 efi_status_t status;
521 u32 width, height;
522 void **uga_handle = NULL;
523 int i;
524
525 status = efi_call_phys3(sys_table->boottime->allocate_pool,
526 EFI_LOADER_DATA, size, &uga_handle);
527 if (status != EFI_SUCCESS)
528 return status;
529
530 status = efi_call_phys5(sys_table->boottime->locate_handle,
531 EFI_LOCATE_BY_PROTOCOL, uga_proto,
532 NULL, &size, uga_handle);
533 if (status != EFI_SUCCESS)
534 goto free_handle;
535
536 first_uga = NULL;
537
538 nr_ugas = size / sizeof(void *);
539 for (i = 0; i < nr_ugas; i++) {
540 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
541 void *handle = uga_handle[i];
542 u32 w, h, depth, refresh;
543 void *pciio;
544
545 status = efi_call_phys3(sys_table->boottime->handle_protocol,
546 handle, uga_proto, &uga);
547 if (status != EFI_SUCCESS)
548 continue;
549
550 efi_call_phys3(sys_table->boottime->handle_protocol,
551 handle, &pciio_proto, &pciio);
552
553 status = efi_call_phys5(uga->get_mode, uga, &w, &h,
554 &depth, &refresh);
555 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
556 width = w;
557 height = h;
558
559 /*
560 * Once we've found a UGA supporting PCIIO,
561 * don't bother looking any further.
562 */
563 if (pciio)
564 break;
565
566 first_uga = uga;
567 }
568 }
569
570 if (!first_uga)
571 goto free_handle;
572
573 /* EFI framebuffer */
574 si->orig_video_isVGA = VIDEO_TYPE_EFI;
575
576 si->lfb_depth = 32;
577 si->lfb_width = width;
578 si->lfb_height = height;
579
580 si->red_size = 8;
581 si->red_pos = 16;
582 si->green_size = 8;
583 si->green_pos = 8;
584 si->blue_size = 8;
585 si->blue_pos = 0;
586 si->rsvd_size = 8;
587 si->rsvd_pos = 24;
588
589
590free_handle:
591 efi_call_phys1(sys_table->boottime->free_pool, uga_handle);
592 return status;
593}
594
595void setup_graphics(struct boot_params *boot_params)
596{
597 efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
598 struct screen_info *si;
599 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
600 efi_status_t status;
601 unsigned long size;
602 void **gop_handle = NULL;
603 void **uga_handle = NULL;
604
605 si = &boot_params->screen_info;
606 memset(si, 0, sizeof(*si));
607
608 size = 0;
609 status = efi_call_phys5(sys_table->boottime->locate_handle,
610 EFI_LOCATE_BY_PROTOCOL, &graphics_proto,
611 NULL, &size, gop_handle);
612 if (status == EFI_BUFFER_TOO_SMALL)
613 status = setup_gop(si, &graphics_proto, size);
614
615 if (status != EFI_SUCCESS) {
616 size = 0;
617 status = efi_call_phys5(sys_table->boottime->locate_handle,
618 EFI_LOCATE_BY_PROTOCOL, &uga_proto,
619 NULL, &size, uga_handle);
620 if (status == EFI_BUFFER_TOO_SMALL)
621 setup_uga(si, &uga_proto, size);
622 }
623}
624
625struct initrd {
626 efi_file_handle_t *handle;
627 u64 size;
628};
629
630/*
631 * Check the cmdline for a LILO-style initrd= arguments.
632 *
633 * We only support loading an initrd from the same filesystem as the
634 * kernel image.
635 */
636static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
637 struct setup_header *hdr)
638{
639 struct initrd *initrds;
640 unsigned long initrd_addr;
641 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
642 u64 initrd_total;
643 efi_file_io_interface_t *io;
644 efi_file_handle_t *fh;
645 efi_status_t status;
646 int nr_initrds;
647 char *str;
648 int i, j, k;
649
650 initrd_addr = 0;
651 initrd_total = 0;
652
653 str = (char *)(unsigned long)hdr->cmd_line_ptr;
654
655 j = 0; /* See close_handles */
656
657 if (!str || !*str)
658 return EFI_SUCCESS;
659
660 for (nr_initrds = 0; *str; nr_initrds++) {
661 str = strstr(str, "initrd=");
662 if (!str)
663 break;
664
665 str += 7;
666
667 /* Skip any leading slashes */
668 while (*str == '/' || *str == '\\')
669 str++;
670
671 while (*str && *str != ' ' && *str != '\n')
672 str++;
673 }
674
675 if (!nr_initrds)
676 return EFI_SUCCESS;
677
678 status = efi_call_phys3(sys_table->boottime->allocate_pool,
679 EFI_LOADER_DATA,
680 nr_initrds * sizeof(*initrds),
681 &initrds);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000682 if (status != EFI_SUCCESS) {
683 efi_printk("Failed to alloc mem for initrds\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000684 goto fail;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000685 }
Matt Fleming291f3632011-12-12 21:27:52 +0000686
687 str = (char *)(unsigned long)hdr->cmd_line_ptr;
688 for (i = 0; i < nr_initrds; i++) {
689 struct initrd *initrd;
690 efi_file_handle_t *h;
691 efi_file_info_t *info;
Dan Carpenterc7b73832012-03-05 21:06:14 +0300692 efi_char16_t filename_16[256];
Matt Fleming291f3632011-12-12 21:27:52 +0000693 unsigned long info_sz;
694 efi_guid_t info_guid = EFI_FILE_INFO_ID;
695 efi_char16_t *p;
696 u64 file_sz;
697
698 str = strstr(str, "initrd=");
699 if (!str)
700 break;
701
702 str += 7;
703
704 initrd = &initrds[i];
Dan Carpenterc7b73832012-03-05 21:06:14 +0300705 p = filename_16;
Matt Fleming291f3632011-12-12 21:27:52 +0000706
707 /* Skip any leading slashes */
708 while (*str == '/' || *str == '\\')
709 str++;
710
711 while (*str && *str != ' ' && *str != '\n') {
Dan Carpenterc7b73832012-03-05 21:06:14 +0300712 if ((u8 *)p >= (u8 *)filename_16 + sizeof(filename_16))
Matt Fleming291f3632011-12-12 21:27:52 +0000713 break;
714
715 *p++ = *str++;
716 }
717
718 *p = '\0';
719
720 /* Only open the volume once. */
721 if (!i) {
722 efi_boot_services_t *boottime;
723
724 boottime = sys_table->boottime;
725
726 status = efi_call_phys3(boottime->handle_protocol,
727 image->device_handle, &fs_proto, &io);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000728 if (status != EFI_SUCCESS) {
729 efi_printk("Failed to handle fs_proto\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000730 goto free_initrds;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000731 }
Matt Fleming291f3632011-12-12 21:27:52 +0000732
733 status = efi_call_phys2(io->open_volume, io, &fh);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000734 if (status != EFI_SUCCESS) {
735 efi_printk("Failed to open volume\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000736 goto free_initrds;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000737 }
Matt Fleming291f3632011-12-12 21:27:52 +0000738 }
739
Dan Carpenterc7b73832012-03-05 21:06:14 +0300740 status = efi_call_phys5(fh->open, fh, &h, filename_16,
Matt Fleming291f3632011-12-12 21:27:52 +0000741 EFI_FILE_MODE_READ, (u64)0);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000742 if (status != EFI_SUCCESS) {
743 efi_printk("Failed to open initrd file\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000744 goto close_handles;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000745 }
Matt Fleming291f3632011-12-12 21:27:52 +0000746
747 initrd->handle = h;
748
749 info_sz = 0;
750 status = efi_call_phys4(h->get_info, h, &info_guid,
751 &info_sz, NULL);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000752 if (status != EFI_BUFFER_TOO_SMALL) {
753 efi_printk("Failed to get initrd info size\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000754 goto close_handles;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000755 }
Matt Fleming291f3632011-12-12 21:27:52 +0000756
757grow:
758 status = efi_call_phys3(sys_table->boottime->allocate_pool,
759 EFI_LOADER_DATA, info_sz, &info);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000760 if (status != EFI_SUCCESS) {
761 efi_printk("Failed to alloc mem for initrd info\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000762 goto close_handles;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000763 }
Matt Fleming291f3632011-12-12 21:27:52 +0000764
765 status = efi_call_phys4(h->get_info, h, &info_guid,
766 &info_sz, info);
767 if (status == EFI_BUFFER_TOO_SMALL) {
768 efi_call_phys1(sys_table->boottime->free_pool, info);
769 goto grow;
770 }
771
772 file_sz = info->file_size;
773 efi_call_phys1(sys_table->boottime->free_pool, info);
774
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000775 if (status != EFI_SUCCESS) {
776 efi_printk("Failed to get initrd info\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000777 goto close_handles;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000778 }
Matt Fleming291f3632011-12-12 21:27:52 +0000779
780 initrd->size = file_sz;
781 initrd_total += file_sz;
782 }
783
784 if (initrd_total) {
785 unsigned long addr;
786
787 /*
788 * Multiple initrd's need to be at consecutive
789 * addresses in memory, so allocate enough memory for
790 * all the initrd's.
791 */
792 status = high_alloc(initrd_total, 0x1000,
793 &initrd_addr, hdr->initrd_addr_max);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000794 if (status != EFI_SUCCESS) {
795 efi_printk("Failed to alloc highmem for initrds\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000796 goto close_handles;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000797 }
Matt Fleming291f3632011-12-12 21:27:52 +0000798
799 /* We've run out of free low memory. */
800 if (initrd_addr > hdr->initrd_addr_max) {
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000801 efi_printk("We've run out of free low memory\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000802 status = EFI_INVALID_PARAMETER;
803 goto free_initrd_total;
804 }
805
806 addr = initrd_addr;
807 for (j = 0; j < nr_initrds; j++) {
808 u64 size;
809
810 size = initrds[j].size;
Maarten Lankhorst2d2da60f2011-12-16 13:30:58 +0100811 while (size) {
812 u64 chunksize;
813 if (size > EFI_READ_CHUNK_SIZE)
814 chunksize = EFI_READ_CHUNK_SIZE;
815 else
816 chunksize = size;
817 status = efi_call_phys3(fh->read,
818 initrds[j].handle,
819 &chunksize, addr);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000820 if (status != EFI_SUCCESS) {
821 efi_printk("Failed to read initrd\n");
Maarten Lankhorst2d2da60f2011-12-16 13:30:58 +0100822 goto free_initrd_total;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000823 }
Maarten Lankhorst2d2da60f2011-12-16 13:30:58 +0100824 addr += chunksize;
825 size -= chunksize;
826 }
Matt Fleming291f3632011-12-12 21:27:52 +0000827
828 efi_call_phys1(fh->close, initrds[j].handle);
Matt Fleming291f3632011-12-12 21:27:52 +0000829 }
830
831 }
832
833 efi_call_phys1(sys_table->boottime->free_pool, initrds);
834
835 hdr->ramdisk_image = initrd_addr;
836 hdr->ramdisk_size = initrd_total;
837
838 return status;
839
840free_initrd_total:
841 low_free(initrd_total, initrd_addr);
842
843close_handles:
Matt Fleming30dc0d02012-03-15 19:13:25 +0000844 for (k = j; k < i; k++)
Matt Fleming291f3632011-12-12 21:27:52 +0000845 efi_call_phys1(fh->close, initrds[k].handle);
846free_initrds:
847 efi_call_phys1(sys_table->boottime->free_pool, initrds);
848fail:
849 hdr->ramdisk_image = 0;
850 hdr->ramdisk_size = 0;
851
852 return status;
853}
854
855/*
856 * Because the x86 boot code expects to be passed a boot_params we
857 * need to create one ourselves (usually the bootloader would create
858 * one for us).
859 */
Matt Fleming9ca8f722012-07-19 10:23:48 +0100860struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table)
Matt Fleming291f3632011-12-12 21:27:52 +0000861{
Matt Fleming9ca8f722012-07-19 10:23:48 +0100862 struct boot_params *boot_params;
863 struct sys_desc_table *sdt;
864 struct apm_bios_info *bi;
865 struct setup_header *hdr;
866 struct efi_info *efi;
867 efi_loaded_image_t *image;
868 void *options;
869 u32 load_options_size;
870 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
Matt Fleming291f3632011-12-12 21:27:52 +0000871 int options_size = 0;
872 efi_status_t status;
Matt Fleming291f3632011-12-12 21:27:52 +0000873 unsigned long cmdline;
Matt Fleming291f3632011-12-12 21:27:52 +0000874 u16 *s2;
875 u8 *s1;
876 int i;
877
Matt Fleming9ca8f722012-07-19 10:23:48 +0100878 sys_table = _table;
879
880 /* Check if we were booted by the EFI firmware */
881 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
882 return NULL;
883
884 status = efi_call_phys3(sys_table->boottime->handle_protocol,
885 handle, &proto, (void *)&image);
886 if (status != EFI_SUCCESS) {
887 efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
888 return NULL;
889 }
890
891 status = low_alloc(0x4000, 1, (unsigned long *)&boot_params);
892 if (status != EFI_SUCCESS) {
893 efi_printk("Failed to alloc lowmem for boot params\n");
894 return NULL;
895 }
896
897 memset(boot_params, 0x0, 0x4000);
898
899 hdr = &boot_params->hdr;
900 efi = &boot_params->efi_info;
901 bi = &boot_params->apm_bios_info;
902 sdt = &boot_params->sys_desc_table;
903
904 /* Copy the second sector to boot_params */
905 memcpy(&hdr->jump, image->image_base + 512, 512);
906
907 /*
908 * Fill out some of the header fields ourselves because the
909 * EFI firmware loader doesn't load the first sector.
910 */
911 hdr->root_flags = 1;
912 hdr->vid_mode = 0xffff;
913 hdr->boot_flag = 0xAA55;
914
915 hdr->code32_start = (__u64)(unsigned long)image->image_base;
916
Matt Fleming291f3632011-12-12 21:27:52 +0000917 hdr->type_of_loader = 0x21;
918
919 /* Convert unicode cmdline to ascii */
Matt Fleming9ca8f722012-07-19 10:23:48 +0100920 options = image->load_options;
921 load_options_size = image->load_options_size / 2; /* ASCII */
Matt Fleming291f3632011-12-12 21:27:52 +0000922 cmdline = 0;
923 s2 = (u16 *)options;
924
925 if (s2) {
926 while (*s2 && *s2 != '\n' && options_size < load_options_size) {
927 s2++;
928 options_size++;
929 }
930
931 if (options_size) {
932 if (options_size > hdr->cmdline_size)
933 options_size = hdr->cmdline_size;
934
935 options_size++; /* NUL termination */
936
937 status = low_alloc(options_size, 1, &cmdline);
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000938 if (status != EFI_SUCCESS) {
939 efi_printk("Failed to alloc mem for cmdline\n");
Matt Fleming291f3632011-12-12 21:27:52 +0000940 goto fail;
Matt Fleming9fa7ded2012-02-20 13:20:59 +0000941 }
Matt Fleming291f3632011-12-12 21:27:52 +0000942
943 s1 = (u8 *)(unsigned long)cmdline;
944 s2 = (u16 *)options;
945
946 for (i = 0; i < options_size - 1; i++)
947 *s1++ = *s2++;
948
949 *s1 = '\0';
950 }
951 }
952
953 hdr->cmd_line_ptr = cmdline;
954
955 hdr->ramdisk_image = 0;
956 hdr->ramdisk_size = 0;
957
Matt Fleming291f3632011-12-12 21:27:52 +0000958 /* Clear APM BIOS info */
959 memset(bi, 0, sizeof(*bi));
960
961 memset(sdt, 0, sizeof(*sdt));
962
Matt Fleming9ca8f722012-07-19 10:23:48 +0100963 status = handle_ramdisks(image, hdr);
964 if (status != EFI_SUCCESS)
965 goto fail2;
966
967 return boot_params;
968fail2:
969 if (options_size)
970 low_free(options_size, hdr->cmd_line_ptr);
971fail:
972 low_free(0x4000, (unsigned long)boot_params);
973 return NULL;
974}
975
976static efi_status_t exit_boot(struct boot_params *boot_params,
977 void *handle)
978{
979 struct efi_info *efi = &boot_params->efi_info;
980 struct e820entry *e820_map = &boot_params->e820_map[0];
981 struct e820entry *prev = NULL;
982 unsigned long size, key, desc_size, _size;
983 efi_memory_desc_t *mem_map;
984 efi_status_t status;
985 __u32 desc_version;
986 u8 nr_entries;
987 int i;
Matt Fleming291f3632011-12-12 21:27:52 +0000988
989 size = sizeof(*mem_map) * 32;
990
991again:
992 size += sizeof(*mem_map);
993 _size = size;
994 status = low_alloc(size, 1, (unsigned long *)&mem_map);
995 if (status != EFI_SUCCESS)
Matt Fleming9ca8f722012-07-19 10:23:48 +0100996 return status;
Matt Fleming291f3632011-12-12 21:27:52 +0000997
998 status = efi_call_phys5(sys_table->boottime->get_memory_map, &size,
999 mem_map, &key, &desc_size, &desc_version);
1000 if (status == EFI_BUFFER_TOO_SMALL) {
1001 low_free(_size, (unsigned long)mem_map);
1002 goto again;
1003 }
1004
1005 if (status != EFI_SUCCESS)
1006 goto free_mem_map;
1007
Matt Fleming9ca8f722012-07-19 10:23:48 +01001008 memcpy(&efi->efi_loader_signature, EFI_LOADER_SIGNATURE, sizeof(__u32));
Matt Fleming291f3632011-12-12 21:27:52 +00001009 efi->efi_systab = (unsigned long)sys_table;
1010 efi->efi_memdesc_size = desc_size;
1011 efi->efi_memdesc_version = desc_version;
1012 efi->efi_memmap = (unsigned long)mem_map;
1013 efi->efi_memmap_size = size;
1014
1015#ifdef CONFIG_X86_64
1016 efi->efi_systab_hi = (unsigned long)sys_table >> 32;
1017 efi->efi_memmap_hi = (unsigned long)mem_map >> 32;
1018#endif
1019
1020 /* Might as well exit boot services now */
1021 status = efi_call_phys2(sys_table->boottime->exit_boot_services,
1022 handle, key);
1023 if (status != EFI_SUCCESS)
1024 goto free_mem_map;
1025
1026 /* Historic? */
1027 boot_params->alt_mem_k = 32 * 1024;
1028
1029 /*
1030 * Convert the EFI memory map to E820.
1031 */
1032 nr_entries = 0;
1033 for (i = 0; i < size / desc_size; i++) {
1034 efi_memory_desc_t *d;
1035 unsigned int e820_type = 0;
1036 unsigned long m = (unsigned long)mem_map;
1037
1038 d = (efi_memory_desc_t *)(m + (i * desc_size));
1039 switch (d->type) {
1040 case EFI_RESERVED_TYPE:
1041 case EFI_RUNTIME_SERVICES_CODE:
1042 case EFI_RUNTIME_SERVICES_DATA:
1043 case EFI_MEMORY_MAPPED_IO:
1044 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
1045 case EFI_PAL_CODE:
1046 e820_type = E820_RESERVED;
1047 break;
1048
1049 case EFI_UNUSABLE_MEMORY:
1050 e820_type = E820_UNUSABLE;
1051 break;
1052
1053 case EFI_ACPI_RECLAIM_MEMORY:
1054 e820_type = E820_ACPI;
1055 break;
1056
1057 case EFI_LOADER_CODE:
1058 case EFI_LOADER_DATA:
1059 case EFI_BOOT_SERVICES_CODE:
1060 case EFI_BOOT_SERVICES_DATA:
1061 case EFI_CONVENTIONAL_MEMORY:
1062 e820_type = E820_RAM;
1063 break;
1064
1065 case EFI_ACPI_MEMORY_NVS:
1066 e820_type = E820_NVS;
1067 break;
1068
1069 default:
1070 continue;
1071 }
1072
1073 /* Merge adjacent mappings */
1074 if (prev && prev->type == e820_type &&
1075 (prev->addr + prev->size) == d->phys_addr)
1076 prev->size += d->num_pages << 12;
1077 else {
1078 e820_map->addr = d->phys_addr;
1079 e820_map->size = d->num_pages << 12;
1080 e820_map->type = e820_type;
1081 prev = e820_map++;
1082 nr_entries++;
1083 }
1084 }
1085
1086 boot_params->e820_entries = nr_entries;
1087
1088 return EFI_SUCCESS;
1089
1090free_mem_map:
1091 low_free(_size, (unsigned long)mem_map);
Matt Fleming291f3632011-12-12 21:27:52 +00001092 return status;
1093}
1094
Matt Fleming9ca8f722012-07-19 10:23:48 +01001095static efi_status_t relocate_kernel(struct setup_header *hdr)
Matt Fleming291f3632011-12-12 21:27:52 +00001096{
Matt Fleming291f3632011-12-12 21:27:52 +00001097 unsigned long start, nr_pages;
Matt Fleming291f3632011-12-12 21:27:52 +00001098 efi_status_t status;
Matt Fleminge31be362012-03-23 09:35:05 -07001099
Matt Fleming291f3632011-12-12 21:27:52 +00001100 /*
1101 * The EFI firmware loader could have placed the kernel image
1102 * anywhere in memory, but the kernel has various restrictions
1103 * on the max physical address it can run at. Attempt to move
1104 * the kernel to boot_params.pref_address, or as low as
1105 * possible.
1106 */
1107 start = hdr->pref_address;
1108 nr_pages = round_up(hdr->init_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
1109
1110 status = efi_call_phys4(sys_table->boottime->allocate_pages,
1111 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
1112 nr_pages, &start);
1113 if (status != EFI_SUCCESS) {
1114 status = low_alloc(hdr->init_size, hdr->kernel_alignment,
1115 &start);
Matt Fleming9ca8f722012-07-19 10:23:48 +01001116 if (status != EFI_SUCCESS)
Matt Fleming9fa7ded2012-02-20 13:20:59 +00001117 efi_printk("Failed to alloc mem for kernel\n");
Matt Fleming291f3632011-12-12 21:27:52 +00001118 }
1119
Matt Fleming9ca8f722012-07-19 10:23:48 +01001120 if (status == EFI_SUCCESS)
1121 memcpy((void *)start, (void *)(unsigned long)hdr->code32_start,
1122 hdr->init_size);
Matt Fleming291f3632011-12-12 21:27:52 +00001123
Matt Fleming9ca8f722012-07-19 10:23:48 +01001124 hdr->pref_address = hdr->code32_start;
1125 hdr->code32_start = (__u32)start;
1126
1127 return status;
1128}
1129
1130/*
1131 * On success we return a pointer to a boot_params structure, and NULL
1132 * on failure.
1133 */
1134struct boot_params *efi_main(void *handle, efi_system_table_t *_table,
1135 struct boot_params *boot_params)
1136{
1137 struct desc_ptr *gdt, *idt;
1138 efi_loaded_image_t *image;
1139 struct setup_header *hdr = &boot_params->hdr;
1140 efi_status_t status;
1141 struct desc_struct *desc;
1142
1143 sys_table = _table;
1144
1145 /* Check if we were booted by the EFI firmware */
1146 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
1147 goto fail;
1148
1149 setup_graphics(boot_params);
Matt Fleming291f3632011-12-12 21:27:52 +00001150
Matthew Garrettdd5fc852012-12-05 14:33:26 -07001151 setup_efi_pci(boot_params);
1152
Matt Fleming291f3632011-12-12 21:27:52 +00001153 status = efi_call_phys3(sys_table->boottime->allocate_pool,
1154 EFI_LOADER_DATA, sizeof(*gdt),
1155 (void **)&gdt);
Matt Fleming9fa7ded2012-02-20 13:20:59 +00001156 if (status != EFI_SUCCESS) {
1157 efi_printk("Failed to alloc mem for gdt structure\n");
Matt Fleming291f3632011-12-12 21:27:52 +00001158 goto fail;
Matt Fleming9fa7ded2012-02-20 13:20:59 +00001159 }
Matt Fleming291f3632011-12-12 21:27:52 +00001160
1161 gdt->size = 0x800;
1162 status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address);
Matt Fleming9fa7ded2012-02-20 13:20:59 +00001163 if (status != EFI_SUCCESS) {
1164 efi_printk("Failed to alloc mem for gdt\n");
Matt Fleming291f3632011-12-12 21:27:52 +00001165 goto fail;
Matt Fleming9fa7ded2012-02-20 13:20:59 +00001166 }
Matt Fleming291f3632011-12-12 21:27:52 +00001167
1168 status = efi_call_phys3(sys_table->boottime->allocate_pool,
1169 EFI_LOADER_DATA, sizeof(*idt),
1170 (void **)&idt);
Matt Fleming9fa7ded2012-02-20 13:20:59 +00001171 if (status != EFI_SUCCESS) {
1172 efi_printk("Failed to alloc mem for idt structure\n");
Matt Fleming291f3632011-12-12 21:27:52 +00001173 goto fail;
Matt Fleming9fa7ded2012-02-20 13:20:59 +00001174 }
Matt Fleming291f3632011-12-12 21:27:52 +00001175
1176 idt->size = 0;
1177 idt->address = 0;
1178
Matt Fleming9ca8f722012-07-19 10:23:48 +01001179 /*
1180 * If the kernel isn't already loaded at the preferred load
1181 * address, relocate it.
1182 */
1183 if (hdr->pref_address != hdr->code32_start) {
1184 status = relocate_kernel(hdr);
1185
1186 if (status != EFI_SUCCESS)
1187 goto fail;
1188 }
1189
1190 status = exit_boot(boot_params, handle);
Matt Fleming291f3632011-12-12 21:27:52 +00001191 if (status != EFI_SUCCESS)
1192 goto fail;
1193
1194 memset((char *)gdt->address, 0x0, gdt->size);
1195 desc = (struct desc_struct *)gdt->address;
1196
1197 /* The first GDT is a dummy and the second is unused. */
1198 desc += 2;
1199
1200 desc->limit0 = 0xffff;
1201 desc->base0 = 0x0000;
1202 desc->base1 = 0x0000;
1203 desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ;
1204 desc->s = DESC_TYPE_CODE_DATA;
1205 desc->dpl = 0;
1206 desc->p = 1;
1207 desc->limit = 0xf;
1208 desc->avl = 0;
1209 desc->l = 0;
1210 desc->d = SEG_OP_SIZE_32BIT;
1211 desc->g = SEG_GRANULARITY_4KB;
1212 desc->base2 = 0x00;
1213
1214 desc++;
1215 desc->limit0 = 0xffff;
1216 desc->base0 = 0x0000;
1217 desc->base1 = 0x0000;
1218 desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE;
1219 desc->s = DESC_TYPE_CODE_DATA;
1220 desc->dpl = 0;
1221 desc->p = 1;
1222 desc->limit = 0xf;
1223 desc->avl = 0;
1224 desc->l = 0;
1225 desc->d = SEG_OP_SIZE_32BIT;
1226 desc->g = SEG_GRANULARITY_4KB;
1227 desc->base2 = 0x00;
1228
1229#ifdef CONFIG_X86_64
1230 /* Task segment value */
1231 desc++;
1232 desc->limit0 = 0x0000;
1233 desc->base0 = 0x0000;
1234 desc->base1 = 0x0000;
1235 desc->type = SEG_TYPE_TSS;
1236 desc->s = 0;
1237 desc->dpl = 0;
1238 desc->p = 1;
1239 desc->limit = 0x0;
1240 desc->avl = 0;
1241 desc->l = 0;
1242 desc->d = 0;
1243 desc->g = SEG_GRANULARITY_4KB;
1244 desc->base2 = 0x00;
1245#endif /* CONFIG_X86_64 */
1246
1247 asm volatile ("lidt %0" : : "m" (*idt));
1248 asm volatile ("lgdt %0" : : "m" (*gdt));
1249
1250 asm volatile("cli");
1251
1252 return boot_params;
1253fail:
1254 return NULL;
1255}