916bbdd7dd28ab2fe334f1c4e3cd5455e89a0cbc
[deliverable/linux.git] / arch / x86 / boot / compressed / eboot.c
1 /* -----------------------------------------------------------------------
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>
11 #include <linux/pci.h>
12 #include <asm/efi.h>
13 #include <asm/setup.h>
14 #include <asm/desc.h>
15
16 #undef memcpy /* Use memcpy from misc.c */
17
18 #include "eboot.h"
19
20 static efi_system_table_t *sys_table;
21
22 struct efi_config *efi_early;
23
24 #define BOOT_SERVICES(bits) \
25 static void setup_boot_services##bits(struct efi_config *c) \
26 { \
27 efi_system_table_##bits##_t *table; \
28 efi_boot_services_##bits##_t *bt; \
29 \
30 table = (typeof(table))sys_table; \
31 \
32 c->text_output = table->con_out; \
33 \
34 bt = (typeof(bt))(unsigned long)(table->boottime); \
35 \
36 c->allocate_pool = bt->allocate_pool; \
37 c->allocate_pages = bt->allocate_pages; \
38 c->get_memory_map = bt->get_memory_map; \
39 c->free_pool = bt->free_pool; \
40 c->free_pages = bt->free_pages; \
41 c->locate_handle = bt->locate_handle; \
42 c->handle_protocol = bt->handle_protocol; \
43 c->exit_boot_services = bt->exit_boot_services; \
44 }
45 BOOT_SERVICES(32);
46 BOOT_SERVICES(64);
47
48 void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
49
50 static efi_status_t
51 __file_size32(void *__fh, efi_char16_t *filename_16,
52 void **handle, u64 *file_sz)
53 {
54 efi_file_handle_32_t *h, *fh = __fh;
55 efi_file_info_t *info;
56 efi_status_t status;
57 efi_guid_t info_guid = EFI_FILE_INFO_ID;
58 u32 info_sz;
59
60 status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
61 EFI_FILE_MODE_READ, (u64)0);
62 if (status != EFI_SUCCESS) {
63 efi_printk(sys_table, "Failed to open file: ");
64 efi_char16_printk(sys_table, filename_16);
65 efi_printk(sys_table, "\n");
66 return status;
67 }
68
69 *handle = h;
70
71 info_sz = 0;
72 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
73 &info_sz, NULL);
74 if (status != EFI_BUFFER_TOO_SMALL) {
75 efi_printk(sys_table, "Failed to get file info size\n");
76 return status;
77 }
78
79 grow:
80 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
81 info_sz, (void **)&info);
82 if (status != EFI_SUCCESS) {
83 efi_printk(sys_table, "Failed to alloc mem for file info\n");
84 return status;
85 }
86
87 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
88 &info_sz, info);
89 if (status == EFI_BUFFER_TOO_SMALL) {
90 efi_call_early(free_pool, info);
91 goto grow;
92 }
93
94 *file_sz = info->file_size;
95 efi_call_early(free_pool, info);
96
97 if (status != EFI_SUCCESS)
98 efi_printk(sys_table, "Failed to get initrd info\n");
99
100 return status;
101 }
102
103 static efi_status_t
104 __file_size64(void *__fh, efi_char16_t *filename_16,
105 void **handle, u64 *file_sz)
106 {
107 efi_file_handle_64_t *h, *fh = __fh;
108 efi_file_info_t *info;
109 efi_status_t status;
110 efi_guid_t info_guid = EFI_FILE_INFO_ID;
111 u64 info_sz;
112
113 status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
114 EFI_FILE_MODE_READ, (u64)0);
115 if (status != EFI_SUCCESS) {
116 efi_printk(sys_table, "Failed to open file: ");
117 efi_char16_printk(sys_table, filename_16);
118 efi_printk(sys_table, "\n");
119 return status;
120 }
121
122 *handle = h;
123
124 info_sz = 0;
125 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
126 &info_sz, NULL);
127 if (status != EFI_BUFFER_TOO_SMALL) {
128 efi_printk(sys_table, "Failed to get file info size\n");
129 return status;
130 }
131
132 grow:
133 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
134 info_sz, (void **)&info);
135 if (status != EFI_SUCCESS) {
136 efi_printk(sys_table, "Failed to alloc mem for file info\n");
137 return status;
138 }
139
140 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
141 &info_sz, info);
142 if (status == EFI_BUFFER_TOO_SMALL) {
143 efi_call_early(free_pool, info);
144 goto grow;
145 }
146
147 *file_sz = info->file_size;
148 efi_call_early(free_pool, info);
149
150 if (status != EFI_SUCCESS)
151 efi_printk(sys_table, "Failed to get initrd info\n");
152
153 return status;
154 }
155 efi_status_t
156 efi_file_size(efi_system_table_t *sys_table, void *__fh,
157 efi_char16_t *filename_16, void **handle, u64 *file_sz)
158 {
159 if (efi_early->is64)
160 return __file_size64(__fh, filename_16, handle, file_sz);
161
162 return __file_size32(__fh, filename_16, handle, file_sz);
163 }
164
165 efi_status_t
166 efi_file_read(void *handle, unsigned long *size, void *addr)
167 {
168 unsigned long func;
169
170 if (efi_early->is64) {
171 efi_file_handle_64_t *fh = handle;
172
173 func = (unsigned long)fh->read;
174 return efi_early->call(func, handle, size, addr);
175 } else {
176 efi_file_handle_32_t *fh = handle;
177
178 func = (unsigned long)fh->read;
179 return efi_early->call(func, handle, size, addr);
180 }
181 }
182
183 efi_status_t efi_file_close(void *handle)
184 {
185 if (efi_early->is64) {
186 efi_file_handle_64_t *fh = handle;
187
188 return efi_early->call((unsigned long)fh->close, handle);
189 } else {
190 efi_file_handle_32_t *fh = handle;
191
192 return efi_early->call((unsigned long)fh->close, handle);
193 }
194 }
195
196 static inline efi_status_t __open_volume32(void *__image, void **__fh)
197 {
198 efi_file_io_interface_t *io;
199 efi_loaded_image_32_t *image = __image;
200 efi_file_handle_32_t *fh;
201 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
202 efi_status_t status;
203 void *handle = (void *)(unsigned long)image->device_handle;
204 unsigned long func;
205
206 status = efi_call_early(handle_protocol, handle,
207 &fs_proto, (void **)&io);
208 if (status != EFI_SUCCESS) {
209 efi_printk(sys_table, "Failed to handle fs_proto\n");
210 return status;
211 }
212
213 func = (unsigned long)io->open_volume;
214 status = efi_early->call(func, io, &fh);
215 if (status != EFI_SUCCESS)
216 efi_printk(sys_table, "Failed to open volume\n");
217
218 *__fh = fh;
219 return status;
220 }
221
222 static inline efi_status_t __open_volume64(void *__image, void **__fh)
223 {
224 efi_file_io_interface_t *io;
225 efi_loaded_image_64_t *image = __image;
226 efi_file_handle_64_t *fh;
227 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
228 efi_status_t status;
229 void *handle = (void *)(unsigned long)image->device_handle;
230 unsigned long func;
231
232 status = efi_call_early(handle_protocol, handle,
233 &fs_proto, (void **)&io);
234 if (status != EFI_SUCCESS) {
235 efi_printk(sys_table, "Failed to handle fs_proto\n");
236 return status;
237 }
238
239 func = (unsigned long)io->open_volume;
240 status = efi_early->call(func, io, &fh);
241 if (status != EFI_SUCCESS)
242 efi_printk(sys_table, "Failed to open volume\n");
243
244 *__fh = fh;
245 return status;
246 }
247
248 efi_status_t
249 efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
250 {
251 if (efi_early->is64)
252 return __open_volume64(__image, __fh);
253
254 return __open_volume32(__image, __fh);
255 }
256
257 void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
258 {
259 unsigned long output_string;
260 size_t offset;
261
262 if (efi_early->is64) {
263 struct efi_simple_text_output_protocol_64 *out;
264 u64 *func;
265
266 offset = offsetof(typeof(*out), output_string);
267 output_string = efi_early->text_output + offset;
268 func = (u64 *)output_string;
269
270 efi_early->call(*func, efi_early->text_output, str);
271 } else {
272 struct efi_simple_text_output_protocol_32 *out;
273 u32 *func;
274
275 offset = offsetof(typeof(*out), output_string);
276 output_string = efi_early->text_output + offset;
277 func = (u32 *)output_string;
278
279 efi_early->call(*func, efi_early->text_output, str);
280 }
281 }
282
283 #include "../../../../drivers/firmware/efi/efi-stub-helper.c"
284
285 static void find_bits(unsigned long mask, u8 *pos, u8 *size)
286 {
287 u8 first, len;
288
289 first = 0;
290 len = 0;
291
292 if (mask) {
293 while (!(mask & 0x1)) {
294 mask = mask >> 1;
295 first++;
296 }
297
298 while (mask & 0x1) {
299 mask = mask >> 1;
300 len++;
301 }
302 }
303
304 *pos = first;
305 *size = len;
306 }
307
308 static efi_status_t
309 __setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom)
310 {
311 struct pci_setup_rom *rom = NULL;
312 efi_status_t status;
313 unsigned long size;
314 uint64_t attributes;
315
316 status = efi_early->call(pci->attributes, pci,
317 EfiPciIoAttributeOperationGet, 0, 0,
318 &attributes);
319 if (status != EFI_SUCCESS)
320 return status;
321
322 if (!pci->romimage || !pci->romsize)
323 return EFI_INVALID_PARAMETER;
324
325 size = pci->romsize + sizeof(*rom);
326
327 status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
328 if (status != EFI_SUCCESS)
329 return status;
330
331 memset(rom, 0, sizeof(*rom));
332
333 rom->data.type = SETUP_PCI;
334 rom->data.len = size - sizeof(struct setup_data);
335 rom->data.next = 0;
336 rom->pcilen = pci->romsize;
337 *__rom = rom;
338
339 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
340 PCI_VENDOR_ID, 1, &(rom->vendor));
341
342 if (status != EFI_SUCCESS)
343 goto free_struct;
344
345 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
346 PCI_DEVICE_ID, 1, &(rom->devid));
347
348 if (status != EFI_SUCCESS)
349 goto free_struct;
350
351 status = efi_early->call(pci->get_location, pci, &(rom->segment),
352 &(rom->bus), &(rom->device), &(rom->function));
353
354 if (status != EFI_SUCCESS)
355 goto free_struct;
356
357 memcpy(rom->romdata, pci->romimage, pci->romsize);
358 return status;
359
360 free_struct:
361 efi_call_early(free_pool, rom);
362 return status;
363 }
364
365 static efi_status_t
366 setup_efi_pci32(struct boot_params *params, void **pci_handle,
367 unsigned long size)
368 {
369 efi_pci_io_protocol_32 *pci = NULL;
370 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
371 u32 *handles = (u32 *)(unsigned long)pci_handle;
372 efi_status_t status;
373 unsigned long nr_pci;
374 struct setup_data *data;
375 int i;
376
377 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
378
379 while (data && data->next)
380 data = (struct setup_data *)(unsigned long)data->next;
381
382 nr_pci = size / sizeof(u32);
383 for (i = 0; i < nr_pci; i++) {
384 struct pci_setup_rom *rom = NULL;
385 u32 h = handles[i];
386
387 status = efi_call_early(handle_protocol, h,
388 &pci_proto, (void **)&pci);
389
390 if (status != EFI_SUCCESS)
391 continue;
392
393 if (!pci)
394 continue;
395
396 status = __setup_efi_pci32(pci, &rom);
397 if (status != EFI_SUCCESS)
398 continue;
399
400 if (data)
401 data->next = (unsigned long)rom;
402 else
403 params->hdr.setup_data = (unsigned long)rom;
404
405 data = (struct setup_data *)rom;
406
407 }
408
409 return status;
410 }
411
412 static efi_status_t
413 __setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom)
414 {
415 struct pci_setup_rom *rom;
416 efi_status_t status;
417 unsigned long size;
418 uint64_t attributes;
419
420 status = efi_early->call(pci->attributes, pci,
421 EfiPciIoAttributeOperationGet, 0,
422 &attributes);
423 if (status != EFI_SUCCESS)
424 return status;
425
426 if (!pci->romimage || !pci->romsize)
427 return EFI_INVALID_PARAMETER;
428
429 size = pci->romsize + sizeof(*rom);
430
431 status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
432 if (status != EFI_SUCCESS)
433 return status;
434
435 rom->data.type = SETUP_PCI;
436 rom->data.len = size - sizeof(struct setup_data);
437 rom->data.next = 0;
438 rom->pcilen = pci->romsize;
439 *__rom = rom;
440
441 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
442 PCI_VENDOR_ID, 1, &(rom->vendor));
443
444 if (status != EFI_SUCCESS)
445 goto free_struct;
446
447 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
448 PCI_DEVICE_ID, 1, &(rom->devid));
449
450 if (status != EFI_SUCCESS)
451 goto free_struct;
452
453 status = efi_early->call(pci->get_location, pci, &(rom->segment),
454 &(rom->bus), &(rom->device), &(rom->function));
455
456 if (status != EFI_SUCCESS)
457 goto free_struct;
458
459 memcpy(rom->romdata, pci->romimage, pci->romsize);
460 return status;
461
462 free_struct:
463 efi_call_early(free_pool, rom);
464 return status;
465
466 }
467
468 static efi_status_t
469 setup_efi_pci64(struct boot_params *params, void **pci_handle,
470 unsigned long size)
471 {
472 efi_pci_io_protocol_64 *pci = NULL;
473 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
474 u64 *handles = (u64 *)(unsigned long)pci_handle;
475 efi_status_t status;
476 unsigned long nr_pci;
477 struct setup_data *data;
478 int i;
479
480 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
481
482 while (data && data->next)
483 data = (struct setup_data *)(unsigned long)data->next;
484
485 nr_pci = size / sizeof(u64);
486 for (i = 0; i < nr_pci; i++) {
487 struct pci_setup_rom *rom = NULL;
488 u64 h = handles[i];
489
490 status = efi_call_early(handle_protocol, h,
491 &pci_proto, (void **)&pci);
492
493 if (status != EFI_SUCCESS)
494 continue;
495
496 if (!pci)
497 continue;
498
499 status = __setup_efi_pci64(pci, &rom);
500 if (status != EFI_SUCCESS)
501 continue;
502
503 if (data)
504 data->next = (unsigned long)rom;
505 else
506 params->hdr.setup_data = (unsigned long)rom;
507
508 data = (struct setup_data *)rom;
509
510 }
511
512 return status;
513 }
514
515 static efi_status_t setup_efi_pci(struct boot_params *params)
516 {
517 efi_status_t status;
518 void **pci_handle = NULL;
519 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
520 unsigned long size = 0;
521
522 status = efi_call_early(locate_handle,
523 EFI_LOCATE_BY_PROTOCOL,
524 &pci_proto, NULL, &size, pci_handle);
525
526 if (status == EFI_BUFFER_TOO_SMALL) {
527 status = efi_call_early(allocate_pool,
528 EFI_LOADER_DATA,
529 size, (void **)&pci_handle);
530
531 if (status != EFI_SUCCESS)
532 return status;
533
534 status = efi_call_early(locate_handle,
535 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
536 NULL, &size, pci_handle);
537 }
538
539 if (status != EFI_SUCCESS)
540 goto free_handle;
541
542 if (efi_early->is64)
543 status = setup_efi_pci64(params, pci_handle, size);
544 else
545 status = setup_efi_pci32(params, pci_handle, size);
546
547 free_handle:
548 efi_call_early(free_pool, pci_handle);
549 return status;
550 }
551
552 static void
553 setup_pixel_info(struct screen_info *si, u32 pixels_per_scan_line,
554 struct efi_pixel_bitmask pixel_info, int pixel_format)
555 {
556 if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) {
557 si->lfb_depth = 32;
558 si->lfb_linelength = pixels_per_scan_line * 4;
559 si->red_size = 8;
560 si->red_pos = 0;
561 si->green_size = 8;
562 si->green_pos = 8;
563 si->blue_size = 8;
564 si->blue_pos = 16;
565 si->rsvd_size = 8;
566 si->rsvd_pos = 24;
567 } else if (pixel_format == PIXEL_BGR_RESERVED_8BIT_PER_COLOR) {
568 si->lfb_depth = 32;
569 si->lfb_linelength = pixels_per_scan_line * 4;
570 si->red_size = 8;
571 si->red_pos = 16;
572 si->green_size = 8;
573 si->green_pos = 8;
574 si->blue_size = 8;
575 si->blue_pos = 0;
576 si->rsvd_size = 8;
577 si->rsvd_pos = 24;
578 } else if (pixel_format == PIXEL_BIT_MASK) {
579 find_bits(pixel_info.red_mask, &si->red_pos, &si->red_size);
580 find_bits(pixel_info.green_mask, &si->green_pos,
581 &si->green_size);
582 find_bits(pixel_info.blue_mask, &si->blue_pos, &si->blue_size);
583 find_bits(pixel_info.reserved_mask, &si->rsvd_pos,
584 &si->rsvd_size);
585 si->lfb_depth = si->red_size + si->green_size +
586 si->blue_size + si->rsvd_size;
587 si->lfb_linelength = (pixels_per_scan_line * si->lfb_depth) / 8;
588 } else {
589 si->lfb_depth = 4;
590 si->lfb_linelength = si->lfb_width / 2;
591 si->red_size = 0;
592 si->red_pos = 0;
593 si->green_size = 0;
594 si->green_pos = 0;
595 si->blue_size = 0;
596 si->blue_pos = 0;
597 si->rsvd_size = 0;
598 si->rsvd_pos = 0;
599 }
600 }
601
602 static efi_status_t
603 __gop_query32(struct efi_graphics_output_protocol_32 *gop32,
604 struct efi_graphics_output_mode_info **info,
605 unsigned long *size, u32 *fb_base)
606 {
607 struct efi_graphics_output_protocol_mode_32 *mode;
608 efi_status_t status;
609 unsigned long m;
610
611 m = gop32->mode;
612 mode = (struct efi_graphics_output_protocol_mode_32 *)m;
613
614 status = efi_early->call(gop32->query_mode, gop32,
615 mode->mode, size, info);
616 if (status != EFI_SUCCESS)
617 return status;
618
619 *fb_base = mode->frame_buffer_base;
620 return status;
621 }
622
623 static efi_status_t
624 setup_gop32(struct screen_info *si, efi_guid_t *proto,
625 unsigned long size, void **gop_handle)
626 {
627 struct efi_graphics_output_protocol_32 *gop32, *first_gop;
628 unsigned long nr_gops;
629 u16 width, height;
630 u32 pixels_per_scan_line;
631 u32 fb_base;
632 struct efi_pixel_bitmask pixel_info;
633 int pixel_format;
634 efi_status_t status;
635 u32 *handles = (u32 *)(unsigned long)gop_handle;
636 int i;
637
638 first_gop = NULL;
639 gop32 = NULL;
640
641 nr_gops = size / sizeof(u32);
642 for (i = 0; i < nr_gops; i++) {
643 struct efi_graphics_output_mode_info *info = NULL;
644 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
645 bool conout_found = false;
646 void *dummy = NULL;
647 u32 h = handles[i];
648
649 status = efi_call_early(handle_protocol, h,
650 proto, (void **)&gop32);
651 if (status != EFI_SUCCESS)
652 continue;
653
654 status = efi_call_early(handle_protocol, h,
655 &conout_proto, &dummy);
656 if (status == EFI_SUCCESS)
657 conout_found = true;
658
659 status = __gop_query32(gop32, &info, &size, &fb_base);
660 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
661 /*
662 * Systems that use the UEFI Console Splitter may
663 * provide multiple GOP devices, not all of which are
664 * backed by real hardware. The workaround is to search
665 * for a GOP implementing the ConOut protocol, and if
666 * one isn't found, to just fall back to the first GOP.
667 */
668 width = info->horizontal_resolution;
669 height = info->vertical_resolution;
670 pixel_format = info->pixel_format;
671 pixel_info = info->pixel_information;
672 pixels_per_scan_line = info->pixels_per_scan_line;
673
674 /*
675 * Once we've found a GOP supporting ConOut,
676 * don't bother looking any further.
677 */
678 first_gop = gop32;
679 if (conout_found)
680 break;
681 }
682 }
683
684 /* Did we find any GOPs? */
685 if (!first_gop)
686 goto out;
687
688 /* EFI framebuffer */
689 si->orig_video_isVGA = VIDEO_TYPE_EFI;
690
691 si->lfb_width = width;
692 si->lfb_height = height;
693 si->lfb_base = fb_base;
694 si->pages = 1;
695
696 setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format);
697
698 si->lfb_size = si->lfb_linelength * si->lfb_height;
699
700 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
701 out:
702 return status;
703 }
704
705 static efi_status_t
706 __gop_query64(struct efi_graphics_output_protocol_64 *gop64,
707 struct efi_graphics_output_mode_info **info,
708 unsigned long *size, u32 *fb_base)
709 {
710 struct efi_graphics_output_protocol_mode_64 *mode;
711 efi_status_t status;
712 unsigned long m;
713
714 m = gop64->mode;
715 mode = (struct efi_graphics_output_protocol_mode_64 *)m;
716
717 status = efi_early->call(gop64->query_mode, gop64,
718 mode->mode, size, info);
719 if (status != EFI_SUCCESS)
720 return status;
721
722 *fb_base = mode->frame_buffer_base;
723 return status;
724 }
725
726 static efi_status_t
727 setup_gop64(struct screen_info *si, efi_guid_t *proto,
728 unsigned long size, void **gop_handle)
729 {
730 struct efi_graphics_output_protocol_64 *gop64, *first_gop;
731 unsigned long nr_gops;
732 u16 width, height;
733 u32 pixels_per_scan_line;
734 u32 fb_base;
735 struct efi_pixel_bitmask pixel_info;
736 int pixel_format;
737 efi_status_t status;
738 u64 *handles = (u64 *)(unsigned long)gop_handle;
739 int i;
740
741 first_gop = NULL;
742 gop64 = NULL;
743
744 nr_gops = size / sizeof(u64);
745 for (i = 0; i < nr_gops; i++) {
746 struct efi_graphics_output_mode_info *info = NULL;
747 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
748 bool conout_found = false;
749 void *dummy = NULL;
750 u64 h = handles[i];
751
752 status = efi_call_early(handle_protocol, h,
753 proto, (void **)&gop64);
754 if (status != EFI_SUCCESS)
755 continue;
756
757 status = efi_call_early(handle_protocol, h,
758 &conout_proto, &dummy);
759 if (status == EFI_SUCCESS)
760 conout_found = true;
761
762 status = __gop_query64(gop64, &info, &size, &fb_base);
763 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
764 /*
765 * Systems that use the UEFI Console Splitter may
766 * provide multiple GOP devices, not all of which are
767 * backed by real hardware. The workaround is to search
768 * for a GOP implementing the ConOut protocol, and if
769 * one isn't found, to just fall back to the first GOP.
770 */
771 width = info->horizontal_resolution;
772 height = info->vertical_resolution;
773 pixel_format = info->pixel_format;
774 pixel_info = info->pixel_information;
775 pixels_per_scan_line = info->pixels_per_scan_line;
776
777 /*
778 * Once we've found a GOP supporting ConOut,
779 * don't bother looking any further.
780 */
781 first_gop = gop64;
782 if (conout_found)
783 break;
784 }
785 }
786
787 /* Did we find any GOPs? */
788 if (!first_gop)
789 goto out;
790
791 /* EFI framebuffer */
792 si->orig_video_isVGA = VIDEO_TYPE_EFI;
793
794 si->lfb_width = width;
795 si->lfb_height = height;
796 si->lfb_base = fb_base;
797 si->pages = 1;
798
799 setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format);
800
801 si->lfb_size = si->lfb_linelength * si->lfb_height;
802
803 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
804 out:
805 return status;
806 }
807
808 /*
809 * See if we have Graphics Output Protocol
810 */
811 static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
812 unsigned long size)
813 {
814 efi_status_t status;
815 void **gop_handle = NULL;
816
817 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
818 size, (void **)&gop_handle);
819 if (status != EFI_SUCCESS)
820 return status;
821
822 status = efi_call_early(locate_handle,
823 EFI_LOCATE_BY_PROTOCOL,
824 proto, NULL, &size, gop_handle);
825 if (status != EFI_SUCCESS)
826 goto free_handle;
827
828 if (efi_early->is64)
829 status = setup_gop64(si, proto, size, gop_handle);
830 else
831 status = setup_gop32(si, proto, size, gop_handle);
832
833 free_handle:
834 efi_call_early(free_pool, gop_handle);
835 return status;
836 }
837
838 static efi_status_t
839 setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height)
840 {
841 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
842 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
843 unsigned long nr_ugas;
844 u32 *handles = (u32 *)uga_handle;;
845 efi_status_t status;
846 int i;
847
848 first_uga = NULL;
849 nr_ugas = size / sizeof(u32);
850 for (i = 0; i < nr_ugas; i++) {
851 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
852 u32 w, h, depth, refresh;
853 void *pciio;
854 u32 handle = handles[i];
855
856 status = efi_call_early(handle_protocol, handle,
857 &uga_proto, (void **)&uga);
858 if (status != EFI_SUCCESS)
859 continue;
860
861 efi_call_early(handle_protocol, handle, &pciio_proto, &pciio);
862
863 status = efi_early->call((unsigned long)uga->get_mode, uga,
864 &w, &h, &depth, &refresh);
865 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
866 *width = w;
867 *height = h;
868
869 /*
870 * Once we've found a UGA supporting PCIIO,
871 * don't bother looking any further.
872 */
873 if (pciio)
874 break;
875
876 first_uga = uga;
877 }
878 }
879
880 return status;
881 }
882
883 static efi_status_t
884 setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height)
885 {
886 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
887 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
888 unsigned long nr_ugas;
889 u64 *handles = (u64 *)uga_handle;;
890 efi_status_t status;
891 int i;
892
893 first_uga = NULL;
894 nr_ugas = size / sizeof(u64);
895 for (i = 0; i < nr_ugas; i++) {
896 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
897 u32 w, h, depth, refresh;
898 void *pciio;
899 u64 handle = handles[i];
900
901 status = efi_call_early(handle_protocol, handle,
902 &uga_proto, (void **)&uga);
903 if (status != EFI_SUCCESS)
904 continue;
905
906 efi_call_early(handle_protocol, handle, &pciio_proto, &pciio);
907
908 status = efi_early->call((unsigned long)uga->get_mode, uga,
909 &w, &h, &depth, &refresh);
910 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
911 *width = w;
912 *height = h;
913
914 /*
915 * Once we've found a UGA supporting PCIIO,
916 * don't bother looking any further.
917 */
918 if (pciio)
919 break;
920
921 first_uga = uga;
922 }
923 }
924
925 return status;
926 }
927
928 /*
929 * See if we have Universal Graphics Adapter (UGA) protocol
930 */
931 static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
932 unsigned long size)
933 {
934 efi_status_t status;
935 u32 width, height;
936 void **uga_handle = NULL;
937
938 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
939 size, (void **)&uga_handle);
940 if (status != EFI_SUCCESS)
941 return status;
942
943 status = efi_call_early(locate_handle,
944 EFI_LOCATE_BY_PROTOCOL,
945 uga_proto, NULL, &size, uga_handle);
946 if (status != EFI_SUCCESS)
947 goto free_handle;
948
949 height = 0;
950 width = 0;
951
952 if (efi_early->is64)
953 status = setup_uga64(uga_handle, size, &width, &height);
954 else
955 status = setup_uga32(uga_handle, size, &width, &height);
956
957 if (!width && !height)
958 goto free_handle;
959
960 /* EFI framebuffer */
961 si->orig_video_isVGA = VIDEO_TYPE_EFI;
962
963 si->lfb_depth = 32;
964 si->lfb_width = width;
965 si->lfb_height = height;
966
967 si->red_size = 8;
968 si->red_pos = 16;
969 si->green_size = 8;
970 si->green_pos = 8;
971 si->blue_size = 8;
972 si->blue_pos = 0;
973 si->rsvd_size = 8;
974 si->rsvd_pos = 24;
975
976 free_handle:
977 efi_call_early(free_pool, uga_handle);
978 return status;
979 }
980
981 void setup_graphics(struct boot_params *boot_params)
982 {
983 efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
984 struct screen_info *si;
985 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
986 efi_status_t status;
987 unsigned long size;
988 void **gop_handle = NULL;
989 void **uga_handle = NULL;
990
991 si = &boot_params->screen_info;
992 memset(si, 0, sizeof(*si));
993
994 size = 0;
995 status = efi_call_early(locate_handle,
996 EFI_LOCATE_BY_PROTOCOL,
997 &graphics_proto, NULL, &size, gop_handle);
998 if (status == EFI_BUFFER_TOO_SMALL)
999 status = setup_gop(si, &graphics_proto, size);
1000
1001 if (status != EFI_SUCCESS) {
1002 size = 0;
1003 status = efi_call_early(locate_handle,
1004 EFI_LOCATE_BY_PROTOCOL,
1005 &uga_proto, NULL, &size, uga_handle);
1006 if (status == EFI_BUFFER_TOO_SMALL)
1007 setup_uga(si, &uga_proto, size);
1008 }
1009 }
1010
1011 /*
1012 * Because the x86 boot code expects to be passed a boot_params we
1013 * need to create one ourselves (usually the bootloader would create
1014 * one for us).
1015 *
1016 * The caller is responsible for filling out ->code32_start in the
1017 * returned boot_params.
1018 */
1019 struct boot_params *make_boot_params(struct efi_config *c)
1020 {
1021 struct boot_params *boot_params;
1022 struct sys_desc_table *sdt;
1023 struct apm_bios_info *bi;
1024 struct setup_header *hdr;
1025 struct efi_info *efi;
1026 efi_loaded_image_t *image;
1027 void *options, *handle;
1028 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
1029 int options_size = 0;
1030 efi_status_t status;
1031 char *cmdline_ptr;
1032 u16 *s2;
1033 u8 *s1;
1034 int i;
1035 unsigned long ramdisk_addr;
1036 unsigned long ramdisk_size;
1037 unsigned long initrd_addr_max;
1038
1039 efi_early = c;
1040 sys_table = (efi_system_table_t *)(unsigned long)efi_early->table;
1041 handle = (void *)(unsigned long)efi_early->image_handle;
1042
1043 /* Check if we were booted by the EFI firmware */
1044 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
1045 return NULL;
1046
1047 if (efi_early->is64)
1048 setup_boot_services64(efi_early);
1049 else
1050 setup_boot_services32(efi_early);
1051
1052 status = efi_call_early(handle_protocol, handle,
1053 &proto, (void *)&image);
1054 if (status != EFI_SUCCESS) {
1055 efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
1056 return NULL;
1057 }
1058
1059 status = efi_low_alloc(sys_table, 0x4000, 1,
1060 (unsigned long *)&boot_params);
1061 if (status != EFI_SUCCESS) {
1062 efi_printk(sys_table, "Failed to alloc lowmem for boot params\n");
1063 return NULL;
1064 }
1065
1066 memset(boot_params, 0x0, 0x4000);
1067
1068 hdr = &boot_params->hdr;
1069 efi = &boot_params->efi_info;
1070 bi = &boot_params->apm_bios_info;
1071 sdt = &boot_params->sys_desc_table;
1072
1073 /* Copy the second sector to boot_params */
1074 memcpy(&hdr->jump, image->image_base + 512, 512);
1075
1076 /*
1077 * Fill out some of the header fields ourselves because the
1078 * EFI firmware loader doesn't load the first sector.
1079 */
1080 hdr->root_flags = 1;
1081 hdr->vid_mode = 0xffff;
1082 hdr->boot_flag = 0xAA55;
1083
1084 hdr->type_of_loader = 0x21;
1085
1086 /* Convert unicode cmdline to ascii */
1087 cmdline_ptr = efi_convert_cmdline(sys_table, image, &options_size);
1088 if (!cmdline_ptr)
1089 goto fail;
1090 hdr->cmd_line_ptr = (unsigned long)cmdline_ptr;
1091
1092 hdr->ramdisk_image = 0;
1093 hdr->ramdisk_size = 0;
1094
1095 /* Clear APM BIOS info */
1096 memset(bi, 0, sizeof(*bi));
1097
1098 memset(sdt, 0, sizeof(*sdt));
1099
1100 if (hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G)
1101 initrd_addr_max = -1UL;
1102 else
1103 initrd_addr_max = hdr->initrd_addr_max;
1104
1105 status = handle_cmdline_files(sys_table, image,
1106 (char *)(unsigned long)hdr->cmd_line_ptr,
1107 "initrd=", initrd_addr_max,
1108 &ramdisk_addr, &ramdisk_size);
1109 if (status != EFI_SUCCESS)
1110 goto fail2;
1111 hdr->ramdisk_image = ramdisk_addr & 0xffffffff;
1112 hdr->ramdisk_size = ramdisk_size & 0xffffffff;
1113 boot_params->ext_ramdisk_image = (u64)ramdisk_addr >> 32;
1114 boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32;
1115
1116 return boot_params;
1117 fail2:
1118 efi_free(sys_table, options_size, hdr->cmd_line_ptr);
1119 fail:
1120 efi_free(sys_table, 0x4000, (unsigned long)boot_params);
1121 return NULL;
1122 }
1123
1124 static void add_e820ext(struct boot_params *params,
1125 struct setup_data *e820ext, u32 nr_entries)
1126 {
1127 struct setup_data *data;
1128 efi_status_t status;
1129 unsigned long size;
1130
1131 e820ext->type = SETUP_E820_EXT;
1132 e820ext->len = nr_entries * sizeof(struct e820entry);
1133 e820ext->next = 0;
1134
1135 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
1136
1137 while (data && data->next)
1138 data = (struct setup_data *)(unsigned long)data->next;
1139
1140 if (data)
1141 data->next = (unsigned long)e820ext;
1142 else
1143 params->hdr.setup_data = (unsigned long)e820ext;
1144 }
1145
1146 static efi_status_t setup_e820(struct boot_params *params,
1147 struct setup_data *e820ext, u32 e820ext_size)
1148 {
1149 struct e820entry *e820_map = &params->e820_map[0];
1150 struct efi_info *efi = &params->efi_info;
1151 struct e820entry *prev = NULL;
1152 u32 nr_entries;
1153 u32 nr_desc;
1154 int i;
1155
1156 nr_entries = 0;
1157 nr_desc = efi->efi_memmap_size / efi->efi_memdesc_size;
1158
1159 for (i = 0; i < nr_desc; i++) {
1160 efi_memory_desc_t *d;
1161 unsigned int e820_type = 0;
1162 unsigned long m = efi->efi_memmap;
1163
1164 d = (efi_memory_desc_t *)(m + (i * efi->efi_memdesc_size));
1165 switch (d->type) {
1166 case EFI_RESERVED_TYPE:
1167 case EFI_RUNTIME_SERVICES_CODE:
1168 case EFI_RUNTIME_SERVICES_DATA:
1169 case EFI_MEMORY_MAPPED_IO:
1170 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
1171 case EFI_PAL_CODE:
1172 e820_type = E820_RESERVED;
1173 break;
1174
1175 case EFI_UNUSABLE_MEMORY:
1176 e820_type = E820_UNUSABLE;
1177 break;
1178
1179 case EFI_ACPI_RECLAIM_MEMORY:
1180 e820_type = E820_ACPI;
1181 break;
1182
1183 case EFI_LOADER_CODE:
1184 case EFI_LOADER_DATA:
1185 case EFI_BOOT_SERVICES_CODE:
1186 case EFI_BOOT_SERVICES_DATA:
1187 case EFI_CONVENTIONAL_MEMORY:
1188 e820_type = E820_RAM;
1189 break;
1190
1191 case EFI_ACPI_MEMORY_NVS:
1192 e820_type = E820_NVS;
1193 break;
1194
1195 default:
1196 continue;
1197 }
1198
1199 /* Merge adjacent mappings */
1200 if (prev && prev->type == e820_type &&
1201 (prev->addr + prev->size) == d->phys_addr) {
1202 prev->size += d->num_pages << 12;
1203 continue;
1204 }
1205
1206 if (nr_entries == ARRAY_SIZE(params->e820_map)) {
1207 u32 need = (nr_desc - i) * sizeof(struct e820entry) +
1208 sizeof(struct setup_data);
1209
1210 if (!e820ext || e820ext_size < need)
1211 return EFI_BUFFER_TOO_SMALL;
1212
1213 /* boot_params map full, switch to e820 extended */
1214 e820_map = (struct e820entry *)e820ext->data;
1215 }
1216
1217 e820_map->addr = d->phys_addr;
1218 e820_map->size = d->num_pages << PAGE_SHIFT;
1219 e820_map->type = e820_type;
1220 prev = e820_map++;
1221 nr_entries++;
1222 }
1223
1224 if (nr_entries > ARRAY_SIZE(params->e820_map)) {
1225 u32 nr_e820ext = nr_entries - ARRAY_SIZE(params->e820_map);
1226
1227 add_e820ext(params, e820ext, nr_e820ext);
1228 nr_entries -= nr_e820ext;
1229 }
1230
1231 params->e820_entries = (u8)nr_entries;
1232
1233 return EFI_SUCCESS;
1234 }
1235
1236 static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
1237 u32 *e820ext_size)
1238 {
1239 efi_status_t status;
1240 unsigned long size;
1241
1242 size = sizeof(struct setup_data) +
1243 sizeof(struct e820entry) * nr_desc;
1244
1245 if (*e820ext) {
1246 efi_call_early(free_pool, *e820ext);
1247 *e820ext = NULL;
1248 *e820ext_size = 0;
1249 }
1250
1251 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
1252 size, (void **)e820ext);
1253 if (status == EFI_SUCCESS)
1254 *e820ext_size = size;
1255
1256 return status;
1257 }
1258
1259 static efi_status_t exit_boot(struct boot_params *boot_params,
1260 void *handle, bool is64)
1261 {
1262 struct efi_info *efi = &boot_params->efi_info;
1263 unsigned long map_sz, key, desc_size;
1264 efi_memory_desc_t *mem_map;
1265 struct setup_data *e820ext;
1266 const char *signature;
1267 __u32 e820ext_size;
1268 __u32 nr_desc, prev_nr_desc;
1269 efi_status_t status;
1270 __u32 desc_version;
1271 bool called_exit = false;
1272 u8 nr_entries;
1273 int i;
1274
1275 nr_desc = 0;
1276 e820ext = NULL;
1277 e820ext_size = 0;
1278
1279 get_map:
1280 status = efi_get_memory_map(sys_table, &mem_map, &map_sz, &desc_size,
1281 &desc_version, &key);
1282
1283 if (status != EFI_SUCCESS)
1284 return status;
1285
1286 prev_nr_desc = nr_desc;
1287 nr_desc = map_sz / desc_size;
1288 if (nr_desc > prev_nr_desc &&
1289 nr_desc > ARRAY_SIZE(boot_params->e820_map)) {
1290 u32 nr_e820ext = nr_desc - ARRAY_SIZE(boot_params->e820_map);
1291
1292 status = alloc_e820ext(nr_e820ext, &e820ext, &e820ext_size);
1293 if (status != EFI_SUCCESS)
1294 goto free_mem_map;
1295
1296 efi_call_early(free_pool, mem_map);
1297 goto get_map; /* Allocated memory, get map again */
1298 }
1299
1300 signature = is64 ? EFI64_LOADER_SIGNATURE : EFI32_LOADER_SIGNATURE;
1301 memcpy(&efi->efi_loader_signature, signature, sizeof(__u32));
1302
1303 efi->efi_systab = (unsigned long)sys_table;
1304 efi->efi_memdesc_size = desc_size;
1305 efi->efi_memdesc_version = desc_version;
1306 efi->efi_memmap = (unsigned long)mem_map;
1307 efi->efi_memmap_size = map_sz;
1308
1309 #ifdef CONFIG_X86_64
1310 efi->efi_systab_hi = (unsigned long)sys_table >> 32;
1311 efi->efi_memmap_hi = (unsigned long)mem_map >> 32;
1312 #endif
1313
1314 /* Might as well exit boot services now */
1315 status = efi_call_early(exit_boot_services, handle, key);
1316 if (status != EFI_SUCCESS) {
1317 /*
1318 * ExitBootServices() will fail if any of the event
1319 * handlers change the memory map. In which case, we
1320 * must be prepared to retry, but only once so that
1321 * we're guaranteed to exit on repeated failures instead
1322 * of spinning forever.
1323 */
1324 if (called_exit)
1325 goto free_mem_map;
1326
1327 called_exit = true;
1328 efi_call_early(free_pool, mem_map);
1329 goto get_map;
1330 }
1331
1332 /* Historic? */
1333 boot_params->alt_mem_k = 32 * 1024;
1334
1335 status = setup_e820(boot_params, e820ext, e820ext_size);
1336 if (status != EFI_SUCCESS)
1337 return status;
1338
1339 return EFI_SUCCESS;
1340
1341 free_mem_map:
1342 efi_call_early(free_pool, mem_map);
1343 return status;
1344 }
1345
1346 /*
1347 * On success we return a pointer to a boot_params structure, and NULL
1348 * on failure.
1349 */
1350 struct boot_params *efi_main(struct efi_config *c,
1351 struct boot_params *boot_params)
1352 {
1353 struct desc_ptr *gdt = NULL;
1354 efi_loaded_image_t *image;
1355 struct setup_header *hdr = &boot_params->hdr;
1356 efi_status_t status;
1357 struct desc_struct *desc;
1358 void *handle;
1359 efi_system_table_t *_table;
1360 bool is64;
1361
1362 efi_early = c;
1363
1364 _table = (efi_system_table_t *)(unsigned long)efi_early->table;
1365 handle = (void *)(unsigned long)efi_early->image_handle;
1366 is64 = efi_early->is64;
1367
1368 sys_table = _table;
1369
1370 /* Check if we were booted by the EFI firmware */
1371 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
1372 goto fail;
1373
1374 if (is64)
1375 setup_boot_services64(efi_early);
1376 else
1377 setup_boot_services32(efi_early);
1378
1379 setup_graphics(boot_params);
1380
1381 setup_efi_pci(boot_params);
1382
1383 status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
1384 sizeof(*gdt), (void **)&gdt);
1385 if (status != EFI_SUCCESS) {
1386 efi_printk(sys_table, "Failed to alloc mem for gdt structure\n");
1387 goto fail;
1388 }
1389
1390 gdt->size = 0x800;
1391 status = efi_low_alloc(sys_table, gdt->size, 8,
1392 (unsigned long *)&gdt->address);
1393 if (status != EFI_SUCCESS) {
1394 efi_printk(sys_table, "Failed to alloc mem for gdt\n");
1395 goto fail;
1396 }
1397
1398 /*
1399 * If the kernel isn't already loaded at the preferred load
1400 * address, relocate it.
1401 */
1402 if (hdr->pref_address != hdr->code32_start) {
1403 unsigned long bzimage_addr = hdr->code32_start;
1404 status = efi_relocate_kernel(sys_table, &bzimage_addr,
1405 hdr->init_size, hdr->init_size,
1406 hdr->pref_address,
1407 hdr->kernel_alignment);
1408 if (status != EFI_SUCCESS)
1409 goto fail;
1410
1411 hdr->pref_address = hdr->code32_start;
1412 hdr->code32_start = bzimage_addr;
1413 }
1414
1415 status = exit_boot(boot_params, handle, is64);
1416 if (status != EFI_SUCCESS)
1417 goto fail;
1418
1419 memset((char *)gdt->address, 0x0, gdt->size);
1420 desc = (struct desc_struct *)gdt->address;
1421
1422 /* The first GDT is a dummy and the second is unused. */
1423 desc += 2;
1424
1425 desc->limit0 = 0xffff;
1426 desc->base0 = 0x0000;
1427 desc->base1 = 0x0000;
1428 desc->type = SEG_TYPE_CODE | SEG_TYPE_EXEC_READ;
1429 desc->s = DESC_TYPE_CODE_DATA;
1430 desc->dpl = 0;
1431 desc->p = 1;
1432 desc->limit = 0xf;
1433 desc->avl = 0;
1434 desc->l = 0;
1435 desc->d = SEG_OP_SIZE_32BIT;
1436 desc->g = SEG_GRANULARITY_4KB;
1437 desc->base2 = 0x00;
1438
1439 desc++;
1440 desc->limit0 = 0xffff;
1441 desc->base0 = 0x0000;
1442 desc->base1 = 0x0000;
1443 desc->type = SEG_TYPE_DATA | SEG_TYPE_READ_WRITE;
1444 desc->s = DESC_TYPE_CODE_DATA;
1445 desc->dpl = 0;
1446 desc->p = 1;
1447 desc->limit = 0xf;
1448 desc->avl = 0;
1449 desc->l = 0;
1450 desc->d = SEG_OP_SIZE_32BIT;
1451 desc->g = SEG_GRANULARITY_4KB;
1452 desc->base2 = 0x00;
1453
1454 #ifdef CONFIG_X86_64
1455 /* Task segment value */
1456 desc++;
1457 desc->limit0 = 0x0000;
1458 desc->base0 = 0x0000;
1459 desc->base1 = 0x0000;
1460 desc->type = SEG_TYPE_TSS;
1461 desc->s = 0;
1462 desc->dpl = 0;
1463 desc->p = 1;
1464 desc->limit = 0x0;
1465 desc->avl = 0;
1466 desc->l = 0;
1467 desc->d = 0;
1468 desc->g = SEG_GRANULARITY_4KB;
1469 desc->base2 = 0x00;
1470 #endif /* CONFIG_X86_64 */
1471
1472 asm volatile("cli");
1473 asm volatile ("lgdt %0" : : "m" (*gdt));
1474
1475 return boot_params;
1476 fail:
1477 return NULL;
1478 }
This page took 0.059264 seconds and 4 git commands to generate.