aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/boot
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2014-03-05 13:15:37 -0500
committerMatt Fleming <matt.fleming@intel.com>2014-03-05 13:15:37 -0500
commit994448f1afa6689bafbebaf7412b23b541b41ef5 (patch)
treeb7460c6a9bdadc6554ad7f0da52b5c60403164c1 /arch/x86/boot
parent4fd69331ad227a4d8de26592d017b73e00caca9f (diff)
parent18c46461d9e42d398536055f31f58cdcd2c6347e (diff)
Merge remote-tracking branch 'tip/x86/efi-mixed' into efi-for-mingo
Conflicts: arch/x86/kernel/setup.c arch/x86/platform/efi/efi.c arch/x86/platform/efi/efi_64.c
Diffstat (limited to 'arch/x86/boot')
-rw-r--r--arch/x86/boot/Makefile2
-rw-r--r--arch/x86/boot/compressed/eboot.c1018
-rw-r--r--arch/x86/boot/compressed/eboot.h60
-rw-r--r--arch/x86/boot/compressed/efi_stub_64.S29
-rw-r--r--arch/x86/boot/compressed/head_32.S50
-rw-r--r--arch/x86/boot/compressed/head_64.S108
-rw-r--r--arch/x86/boot/header.S23
-rw-r--r--arch/x86/boot/tools/build.c76
8 files changed, 1107 insertions, 259 deletions
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index 878df7e88cd4..abb9eba61b50 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -80,7 +80,7 @@ targets += voffset.h
80$(obj)/voffset.h: vmlinux FORCE 80$(obj)/voffset.h: vmlinux FORCE
81 $(call if_changed,voffset) 81 $(call if_changed,voffset)
82 82
83sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|startup_64\|efi_pe_entry\|efi_stub_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p' 83sed-zoffset := -e 's/^\([0-9a-fA-F]*\) . \(startup_32\|startup_64\|efi32_stub_entry\|efi64_stub_entry\|efi_pe_entry\|input_data\|_end\|z_.*\)$$/\#define ZO_\2 0x\1/p'
84 84
85quiet_cmd_zoffset = ZOFFSET $@ 85quiet_cmd_zoffset = ZOFFSET $@
86 cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@ 86 cmd_zoffset = $(NM) $< | sed -n $(sed-zoffset) > $@
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
index a7677babf946..5e1ba4fa3f79 100644
--- a/arch/x86/boot/compressed/eboot.c
+++ b/arch/x86/boot/compressed/eboot.c
@@ -19,10 +19,269 @@
19 19
20static efi_system_table_t *sys_table; 20static efi_system_table_t *sys_table;
21 21
22static struct efi_config *efi_early;
23
24#define BOOT_SERVICES(bits) \
25static 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}
45BOOT_SERVICES(32);
46BOOT_SERVICES(64);
22 47
23#include "../../../../drivers/firmware/efi/efi-stub-helper.c" 48static void efi_printk(efi_system_table_t *, char *);
49static void efi_char16_printk(efi_system_table_t *, efi_char16_t *);
50
51static efi_status_t
52__file_size32(void *__fh, efi_char16_t *filename_16,
53 void **handle, u64 *file_sz)
54{
55 efi_file_handle_32_t *h, *fh = __fh;
56 efi_file_info_t *info;
57 efi_status_t status;
58 efi_guid_t info_guid = EFI_FILE_INFO_ID;
59 u32 info_sz;
60
61 status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
62 EFI_FILE_MODE_READ, (u64)0);
63 if (status != EFI_SUCCESS) {
64 efi_printk(sys_table, "Failed to open file: ");
65 efi_char16_printk(sys_table, filename_16);
66 efi_printk(sys_table, "\n");
67 return status;
68 }
69
70 *handle = h;
71
72 info_sz = 0;
73 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
74 &info_sz, NULL);
75 if (status != EFI_BUFFER_TOO_SMALL) {
76 efi_printk(sys_table, "Failed to get file info size\n");
77 return status;
78 }
79
80grow:
81 status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
82 info_sz, (void **)&info);
83 if (status != EFI_SUCCESS) {
84 efi_printk(sys_table, "Failed to alloc mem for file info\n");
85 return status;
86 }
87
88 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
89 &info_sz, info);
90 if (status == EFI_BUFFER_TOO_SMALL) {
91 efi_early->call(efi_early->free_pool, info);
92 goto grow;
93 }
94
95 *file_sz = info->file_size;
96 efi_early->call(efi_early->free_pool, info);
97
98 if (status != EFI_SUCCESS)
99 efi_printk(sys_table, "Failed to get initrd info\n");
100
101 return status;
102}
103
104static efi_status_t
105__file_size64(void *__fh, efi_char16_t *filename_16,
106 void **handle, u64 *file_sz)
107{
108 efi_file_handle_64_t *h, *fh = __fh;
109 efi_file_info_t *info;
110 efi_status_t status;
111 efi_guid_t info_guid = EFI_FILE_INFO_ID;
112 u32 info_sz;
113
114 status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
115 EFI_FILE_MODE_READ, (u64)0);
116 if (status != EFI_SUCCESS) {
117 efi_printk(sys_table, "Failed to open file: ");
118 efi_char16_printk(sys_table, filename_16);
119 efi_printk(sys_table, "\n");
120 return status;
121 }
122
123 *handle = h;
124
125 info_sz = 0;
126 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
127 &info_sz, NULL);
128 if (status != EFI_BUFFER_TOO_SMALL) {
129 efi_printk(sys_table, "Failed to get file info size\n");
130 return status;
131 }
132
133grow:
134 status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
135 info_sz, (void **)&info);
136 if (status != EFI_SUCCESS) {
137 efi_printk(sys_table, "Failed to alloc mem for file info\n");
138 return status;
139 }
140
141 status = efi_early->call((unsigned long)h->get_info, h, &info_guid,
142 &info_sz, info);
143 if (status == EFI_BUFFER_TOO_SMALL) {
144 efi_early->call(efi_early->free_pool, info);
145 goto grow;
146 }
147
148 *file_sz = info->file_size;
149 efi_early->call(efi_early->free_pool, info);
150
151 if (status != EFI_SUCCESS)
152 efi_printk(sys_table, "Failed to get initrd info\n");
153
154 return status;
155}
156static efi_status_t
157efi_file_size(efi_system_table_t *sys_table, void *__fh,
158 efi_char16_t *filename_16, void **handle, u64 *file_sz)
159{
160 if (efi_early->is64)
161 return __file_size64(__fh, filename_16, handle, file_sz);
162
163 return __file_size32(__fh, filename_16, handle, file_sz);
164}
165
166static inline efi_status_t
167efi_file_read(void *__fh, void *handle, unsigned long *size, void *addr)
168{
169 unsigned long func;
170
171 if (efi_early->is64) {
172 efi_file_handle_64_t *fh = __fh;
173
174 func = (unsigned long)fh->read;
175 return efi_early->call(func, handle, size, addr);
176 } else {
177 efi_file_handle_32_t *fh = __fh;
178
179 func = (unsigned long)fh->read;
180 return efi_early->call(func, handle, size, addr);
181 }
182}
183
184static inline efi_status_t efi_file_close(void *__fh, void *handle)
185{
186 if (efi_early->is64) {
187 efi_file_handle_64_t *fh = __fh;
188
189 return efi_early->call((unsigned long)fh->close, handle);
190 } else {
191 efi_file_handle_32_t *fh = __fh;
192
193 return efi_early->call((unsigned long)fh->close, handle);
194 }
195}
196
197static inline efi_status_t __open_volume32(void *__image, void **__fh)
198{
199 efi_file_io_interface_t *io;
200 efi_loaded_image_32_t *image = __image;
201 efi_file_handle_32_t *fh;
202 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
203 efi_status_t status;
204 void *handle = (void *)(unsigned long)image->device_handle;
205 unsigned long func;
206
207 status = efi_early->call(efi_early->handle_protocol, handle,
208 &fs_proto, (void **)&io);
209 if (status != EFI_SUCCESS) {
210 efi_printk(sys_table, "Failed to handle fs_proto\n");
211 return status;
212 }
213
214 func = (unsigned long)io->open_volume;
215 status = efi_early->call(func, io, &fh);
216 if (status != EFI_SUCCESS)
217 efi_printk(sys_table, "Failed to open volume\n");
218
219 *__fh = fh;
220 return status;
221}
222
223static inline efi_status_t __open_volume64(void *__image, void **__fh)
224{
225 efi_file_io_interface_t *io;
226 efi_loaded_image_64_t *image = __image;
227 efi_file_handle_64_t *fh;
228 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
229 efi_status_t status;
230 void *handle = (void *)(unsigned long)image->device_handle;
231 unsigned long func;
232
233 status = efi_early->call(efi_early->handle_protocol, handle,
234 &fs_proto, (void **)&io);
235 if (status != EFI_SUCCESS) {
236 efi_printk(sys_table, "Failed to handle fs_proto\n");
237 return status;
238 }
239
240 func = (unsigned long)io->open_volume;
241 status = efi_early->call(func, io, &fh);
242 if (status != EFI_SUCCESS)
243 efi_printk(sys_table, "Failed to open volume\n");
244
245 *__fh = fh;
246 return status;
247}
248
249static inline efi_status_t
250efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh)
251{
252 if (efi_early->is64)
253 return __open_volume64(__image, __fh);
254
255 return __open_volume32(__image, __fh);
256}
257
258static void efi_char16_printk(efi_system_table_t *table, efi_char16_t *str)
259{
260 unsigned long output_string;
261 size_t offset;
262
263 if (efi_early->is64) {
264 struct efi_simple_text_output_protocol_64 *out;
265 u64 *func;
266
267 offset = offsetof(typeof(*out), output_string);
268 output_string = efi_early->text_output + offset;
269 func = (u64 *)output_string;
270
271 efi_early->call(*func, efi_early->text_output, str);
272 } else {
273 struct efi_simple_text_output_protocol_32 *out;
274 u32 *func;
275
276 offset = offsetof(typeof(*out), output_string);
277 output_string = efi_early->text_output + offset;
278 func = (u32 *)output_string;
24 279
280 efi_early->call(*func, efi_early->text_output, str);
281 }
282}
25 283
284#include "../../../../drivers/firmware/efi/efi-stub-helper.c"
26 285
27static void find_bits(unsigned long mask, u8 *pos, u8 *size) 286static void find_bits(unsigned long mask, u8 *pos, u8 *size)
28{ 287{
@@ -47,105 +306,99 @@ static void find_bits(unsigned long mask, u8 *pos, u8 *size)
47 *size = len; 306 *size = len;
48} 307}
49 308
50static efi_status_t setup_efi_pci(struct boot_params *params) 309static efi_status_t
310__setup_efi_pci32(efi_pci_io_protocol_32 *pci, struct pci_setup_rom **__rom)
51{ 311{
52 efi_pci_io_protocol *pci; 312 struct pci_setup_rom *rom = NULL;
53 efi_status_t status; 313 efi_status_t status;
54 void **pci_handle; 314 unsigned long size;
55 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; 315 uint64_t attributes;
56 unsigned long nr_pci, size = 0;
57 int i;
58 struct setup_data *data;
59 316
60 data = (struct setup_data *)(unsigned long)params->hdr.setup_data; 317 status = efi_early->call(pci->attributes, pci,
318 EfiPciIoAttributeOperationGet, 0, 0,
319 &attributes);
320 if (status != EFI_SUCCESS)
321 return status;
61 322
62 while (data && data->next) 323 if (!pci->romimage || !pci->romsize)
63 data = (struct setup_data *)(unsigned long)data->next; 324 return EFI_INVALID_PARAMETER;
64 325
65 status = efi_call_phys5(sys_table->boottime->locate_handle, 326 size = pci->romsize + sizeof(*rom);
66 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
67 NULL, &size, pci_handle);
68 327
69 if (status == EFI_BUFFER_TOO_SMALL) { 328 status = efi_early->call(efi_early->allocate_pool,
70 status = efi_call_phys3(sys_table->boottime->allocate_pool, 329 EFI_LOADER_DATA, size, &rom);
71 EFI_LOADER_DATA, size, &pci_handle);
72 330
73 if (status != EFI_SUCCESS) 331 if (status != EFI_SUCCESS)
74 return status; 332 return status;
75 333
76 status = efi_call_phys5(sys_table->boottime->locate_handle, 334 memset(rom, 0, sizeof(*rom));
77 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
78 NULL, &size, pci_handle);
79 }
80 335
81 if (status != EFI_SUCCESS) 336 rom->data.type = SETUP_PCI;
82 goto free_handle; 337 rom->data.len = size - sizeof(struct setup_data);
338 rom->data.next = 0;
339 rom->pcilen = pci->romsize;
340 *__rom = rom;
83 341
84 nr_pci = size / sizeof(void *); 342 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
85 for (i = 0; i < nr_pci; i++) { 343 PCI_VENDOR_ID, 1, &(rom->vendor));
86 void *h = pci_handle[i];
87 uint64_t attributes;
88 struct pci_setup_rom *rom;
89 344
90 status = efi_call_phys3(sys_table->boottime->handle_protocol, 345 if (status != EFI_SUCCESS)
91 h, &pci_proto, &pci); 346 goto free_struct;
92 347
93 if (status != EFI_SUCCESS) 348 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
94 continue; 349 PCI_DEVICE_ID, 1, &(rom->devid));
95 350
96 if (!pci) 351 if (status != EFI_SUCCESS)
97 continue; 352 goto free_struct;
98 353
99#ifdef CONFIG_X86_64 354 status = efi_early->call(pci->get_location, pci, &(rom->segment),
100 status = efi_call_phys4(pci->attributes, pci, 355 &(rom->bus), &(rom->device), &(rom->function));
101 EfiPciIoAttributeOperationGet, 0,
102 &attributes);
103#else
104 status = efi_call_phys5(pci->attributes, pci,
105 EfiPciIoAttributeOperationGet, 0, 0,
106 &attributes);
107#endif
108 if (status != EFI_SUCCESS)
109 continue;
110 356
111 if (!pci->romimage || !pci->romsize) 357 if (status != EFI_SUCCESS)
112 continue; 358 goto free_struct;
113 359
114 size = pci->romsize + sizeof(*rom); 360 memcpy(rom->romdata, pci->romimage, pci->romsize);
361 return status;
115 362
116 status = efi_call_phys3(sys_table->boottime->allocate_pool, 363free_struct:
117 EFI_LOADER_DATA, size, &rom); 364 efi_early->call(efi_early->free_pool, rom);
365 return status;
366}
118 367
119 if (status != EFI_SUCCESS) 368static efi_status_t
120 continue; 369setup_efi_pci32(struct boot_params *params, void **pci_handle,
370 unsigned long size)
371{
372 efi_pci_io_protocol_32 *pci = NULL;
373 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
374 u32 *handles = (u32 *)(unsigned long)pci_handle;
375 efi_status_t status;
376 unsigned long nr_pci;
377 struct setup_data *data;
378 int i;
121 379
122 rom->data.type = SETUP_PCI; 380 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
123 rom->data.len = size - sizeof(struct setup_data);
124 rom->data.next = 0;
125 rom->pcilen = pci->romsize;
126 381
127 status = efi_call_phys5(pci->pci.read, pci, 382 while (data && data->next)
128 EfiPciIoWidthUint16, PCI_VENDOR_ID, 383 data = (struct setup_data *)(unsigned long)data->next;
129 1, &(rom->vendor));
130 384
131 if (status != EFI_SUCCESS) 385 nr_pci = size / sizeof(u32);
132 goto free_struct; 386 for (i = 0; i < nr_pci; i++) {
387 struct pci_setup_rom *rom = NULL;
388 u32 h = handles[i];
133 389
134 status = efi_call_phys5(pci->pci.read, pci, 390 status = efi_early->call(efi_early->handle_protocol, h,
135 EfiPciIoWidthUint16, PCI_DEVICE_ID, 391 &pci_proto, (void **)&pci);
136 1, &(rom->devid));
137 392
138 if (status != EFI_SUCCESS) 393 if (status != EFI_SUCCESS)
139 goto free_struct; 394 continue;
140 395
141 status = efi_call_phys5(pci->get_location, pci, 396 if (!pci)
142 &(rom->segment), &(rom->bus), 397 continue;
143 &(rom->device), &(rom->function));
144 398
399 status = __setup_efi_pci32(pci, &rom);
145 if (status != EFI_SUCCESS) 400 if (status != EFI_SUCCESS)
146 goto free_struct; 401 continue;
147
148 memcpy(rom->romdata, pci->romimage, pci->romsize);
149 402
150 if (data) 403 if (data)
151 data->next = (unsigned long)rom; 404 data->next = (unsigned long)rom;
@@ -154,105 +407,157 @@ static efi_status_t setup_efi_pci(struct boot_params *params)
154 407
155 data = (struct setup_data *)rom; 408 data = (struct setup_data *)rom;
156 409
157 continue;
158 free_struct:
159 efi_call_phys1(sys_table->boottime->free_pool, rom);
160 } 410 }
161 411
162free_handle:
163 efi_call_phys1(sys_table->boottime->free_pool, pci_handle);
164 return status; 412 return status;
165} 413}
166 414
167/* 415static efi_status_t
168 * See if we have Graphics Output Protocol 416__setup_efi_pci64(efi_pci_io_protocol_64 *pci, struct pci_setup_rom **__rom)
169 */
170static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
171 unsigned long size)
172{ 417{
173 struct efi_graphics_output_protocol *gop, *first_gop; 418 struct pci_setup_rom *rom;
174 struct efi_pixel_bitmask pixel_info;
175 unsigned long nr_gops;
176 efi_status_t status; 419 efi_status_t status;
177 void **gop_handle; 420 unsigned long size;
178 u16 width, height; 421 uint64_t attributes;
179 u32 fb_base, fb_size;
180 u32 pixels_per_scan_line;
181 int pixel_format;
182 int i;
183 422
184 status = efi_call_phys3(sys_table->boottime->allocate_pool, 423 status = efi_early->call(pci->attributes, pci,
185 EFI_LOADER_DATA, size, &gop_handle); 424 EfiPciIoAttributeOperationGet, 0,
425 &attributes);
186 if (status != EFI_SUCCESS) 426 if (status != EFI_SUCCESS)
187 return status; 427 return status;
188 428
189 status = efi_call_phys5(sys_table->boottime->locate_handle, 429 if (!pci->romimage || !pci->romsize)
190 EFI_LOCATE_BY_PROTOCOL, proto, 430 return EFI_INVALID_PARAMETER;
191 NULL, &size, gop_handle); 431
432 size = pci->romsize + sizeof(*rom);
433
434 status = efi_early->call(efi_early->allocate_pool,
435 EFI_LOADER_DATA, size, &rom);
436
192 if (status != EFI_SUCCESS) 437 if (status != EFI_SUCCESS)
193 goto free_handle; 438 return status;
194 439
195 first_gop = NULL; 440 rom->data.type = SETUP_PCI;
441 rom->data.len = size - sizeof(struct setup_data);
442 rom->data.next = 0;
443 rom->pcilen = pci->romsize;
444 *__rom = rom;
196 445
197 nr_gops = size / sizeof(void *); 446 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
198 for (i = 0; i < nr_gops; i++) { 447 PCI_VENDOR_ID, 1, &(rom->vendor));
199 struct efi_graphics_output_mode_info *info; 448
200 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID; 449 if (status != EFI_SUCCESS)
201 bool conout_found = false; 450 goto free_struct;
202 void *dummy; 451
203 void *h = gop_handle[i]; 452 status = efi_early->call(pci->pci.read, pci, EfiPciIoWidthUint16,
453 PCI_DEVICE_ID, 1, &(rom->devid));
454
455 if (status != EFI_SUCCESS)
456 goto free_struct;
457
458 status = efi_early->call(pci->get_location, pci, &(rom->segment),
459 &(rom->bus), &(rom->device), &(rom->function));
460
461 if (status != EFI_SUCCESS)
462 goto free_struct;
463
464 memcpy(rom->romdata, pci->romimage, pci->romsize);
465 return status;
466
467free_struct:
468 efi_early->call(efi_early->free_pool, rom);
469 return status;
470
471}
472
473static efi_status_t
474setup_efi_pci64(struct boot_params *params, void **pci_handle,
475 unsigned long size)
476{
477 efi_pci_io_protocol_64 *pci = NULL;
478 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
479 u64 *handles = (u64 *)(unsigned long)pci_handle;
480 efi_status_t status;
481 unsigned long nr_pci;
482 struct setup_data *data;
483 int i;
484
485 data = (struct setup_data *)(unsigned long)params->hdr.setup_data;
486
487 while (data && data->next)
488 data = (struct setup_data *)(unsigned long)data->next;
489
490 nr_pci = size / sizeof(u64);
491 for (i = 0; i < nr_pci; i++) {
492 struct pci_setup_rom *rom = NULL;
493 u64 h = handles[i];
494
495 status = efi_early->call(efi_early->handle_protocol, h,
496 &pci_proto, (void **)&pci);
204 497
205 status = efi_call_phys3(sys_table->boottime->handle_protocol,
206 h, proto, &gop);
207 if (status != EFI_SUCCESS) 498 if (status != EFI_SUCCESS)
208 continue; 499 continue;
209 500
210 status = efi_call_phys3(sys_table->boottime->handle_protocol, 501 if (!pci)
211 h, &conout_proto, &dummy); 502 continue;
212 503
213 if (status == EFI_SUCCESS) 504 status = __setup_efi_pci64(pci, &rom);
214 conout_found = true; 505 if (status != EFI_SUCCESS)
506 continue;
215 507
216 status = efi_call_phys4(gop->query_mode, gop, 508 if (data)
217 gop->mode->mode, &size, &info); 509 data->next = (unsigned long)rom;
218 if (status == EFI_SUCCESS && (!first_gop || conout_found)) { 510 else
219 /* 511 params->hdr.setup_data = (unsigned long)rom;
220 * Systems that use the UEFI Console Splitter may 512
221 * provide multiple GOP devices, not all of which are 513 data = (struct setup_data *)rom;
222 * backed by real hardware. The workaround is to search
223 * for a GOP implementing the ConOut protocol, and if
224 * one isn't found, to just fall back to the first GOP.
225 */
226 width = info->horizontal_resolution;
227 height = info->vertical_resolution;
228 fb_base = gop->mode->frame_buffer_base;
229 fb_size = gop->mode->frame_buffer_size;
230 pixel_format = info->pixel_format;
231 pixel_info = info->pixel_information;
232 pixels_per_scan_line = info->pixels_per_scan_line;
233 514
234 /*
235 * Once we've found a GOP supporting ConOut,
236 * don't bother looking any further.
237 */
238 first_gop = gop;
239 if (conout_found)
240 break;
241 }
242 } 515 }
243 516
244 /* Did we find any GOPs? */ 517 return status;
245 if (!first_gop) 518}
519
520static efi_status_t setup_efi_pci(struct boot_params *params)
521{
522 efi_status_t status;
523 void **pci_handle = NULL;
524 efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
525 unsigned long size = 0;
526
527 status = efi_early->call(efi_early->locate_handle,
528 EFI_LOCATE_BY_PROTOCOL,
529 &pci_proto, NULL, &size, pci_handle);
530
531 if (status == EFI_BUFFER_TOO_SMALL) {
532 status = efi_early->call(efi_early->allocate_pool,
533 EFI_LOADER_DATA,
534 size, (void **)&pci_handle);
535
536 if (status != EFI_SUCCESS)
537 return status;
538
539 status = efi_early->call(efi_early->locate_handle,
540 EFI_LOCATE_BY_PROTOCOL, &pci_proto,
541 NULL, &size, pci_handle);
542 }
543
544 if (status != EFI_SUCCESS)
246 goto free_handle; 545 goto free_handle;
247 546
248 /* EFI framebuffer */ 547 if (efi_early->is64)
249 si->orig_video_isVGA = VIDEO_TYPE_EFI; 548 status = setup_efi_pci64(params, pci_handle, size);
549 else
550 status = setup_efi_pci32(params, pci_handle, size);
250 551
251 si->lfb_width = width; 552free_handle:
252 si->lfb_height = height; 553 efi_early->call(efi_early->free_pool, pci_handle);
253 si->lfb_base = fb_base; 554 return status;
254 si->pages = 1; 555}
255 556
557static void
558setup_pixel_info(struct screen_info *si, u32 pixels_per_scan_line,
559 struct efi_pixel_bitmask pixel_info, int pixel_format)
560{
256 if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) { 561 if (pixel_format == PIXEL_RGB_RESERVED_8BIT_PER_COLOR) {
257 si->lfb_depth = 32; 562 si->lfb_depth = 32;
258 si->lfb_linelength = pixels_per_scan_line * 4; 563 si->lfb_linelength = pixels_per_scan_line * 4;
@@ -297,62 +602,321 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
297 si->rsvd_size = 0; 602 si->rsvd_size = 0;
298 si->rsvd_pos = 0; 603 si->rsvd_pos = 0;
299 } 604 }
605}
606
607static efi_status_t
608__gop_query32(struct efi_graphics_output_protocol_32 *gop32,
609 struct efi_graphics_output_mode_info **info,
610 unsigned long *size, u32 *fb_base)
611{
612 struct efi_graphics_output_protocol_mode_32 *mode;
613 efi_status_t status;
614 unsigned long m;
615
616 m = gop32->mode;
617 mode = (struct efi_graphics_output_protocol_mode_32 *)m;
618
619 status = efi_early->call(gop32->query_mode, gop32,
620 mode->mode, size, info);
621 if (status != EFI_SUCCESS)
622 return status;
623
624 *fb_base = mode->frame_buffer_base;
625 return status;
626}
627
628static efi_status_t
629setup_gop32(struct screen_info *si, efi_guid_t *proto,
630 unsigned long size, void **gop_handle)
631{
632 struct efi_graphics_output_protocol_32 *gop32, *first_gop;
633 unsigned long nr_gops;
634 u16 width, height;
635 u32 pixels_per_scan_line;
636 u32 fb_base;
637 struct efi_pixel_bitmask pixel_info;
638 int pixel_format;
639 efi_status_t status;
640 u32 *handles = (u32 *)(unsigned long)gop_handle;
641 int i;
642
643 first_gop = NULL;
644 gop32 = NULL;
645
646 nr_gops = size / sizeof(u32);
647 for (i = 0; i < nr_gops; i++) {
648 struct efi_graphics_output_mode_info *info = NULL;
649 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
650 bool conout_found = false;
651 void *dummy = NULL;
652 u32 h = handles[i];
653
654 status = efi_early->call(efi_early->handle_protocol, h,
655 proto, (void **)&gop32);
656 if (status != EFI_SUCCESS)
657 continue;
658
659 status = efi_early->call(efi_early->handle_protocol, h,
660 &conout_proto, &dummy);
661 if (status == EFI_SUCCESS)
662 conout_found = true;
663
664 status = __gop_query32(gop32, &info, &size, &fb_base);
665 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
666 /*
667 * Systems that use the UEFI Console Splitter may
668 * provide multiple GOP devices, not all of which are
669 * backed by real hardware. The workaround is to search
670 * for a GOP implementing the ConOut protocol, and if
671 * one isn't found, to just fall back to the first GOP.
672 */
673 width = info->horizontal_resolution;
674 height = info->vertical_resolution;
675 pixel_format = info->pixel_format;
676 pixel_info = info->pixel_information;
677 pixels_per_scan_line = info->pixels_per_scan_line;
678
679 /*
680 * Once we've found a GOP supporting ConOut,
681 * don't bother looking any further.
682 */
683 first_gop = gop32;
684 if (conout_found)
685 break;
686 }
687 }
688
689 /* Did we find any GOPs? */
690 if (!first_gop)
691 goto out;
692
693 /* EFI framebuffer */
694 si->orig_video_isVGA = VIDEO_TYPE_EFI;
695
696 si->lfb_width = width;
697 si->lfb_height = height;
698 si->lfb_base = fb_base;
699 si->pages = 1;
700
701 setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format);
300 702
301 si->lfb_size = si->lfb_linelength * si->lfb_height; 703 si->lfb_size = si->lfb_linelength * si->lfb_height;
302 704
303 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; 705 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
706out:
707 return status;
708}
304 709
305free_handle: 710static efi_status_t
306 efi_call_phys1(sys_table->boottime->free_pool, gop_handle); 711__gop_query64(struct efi_graphics_output_protocol_64 *gop64,
712 struct efi_graphics_output_mode_info **info,
713 unsigned long *size, u32 *fb_base)
714{
715 struct efi_graphics_output_protocol_mode_64 *mode;
716 efi_status_t status;
717 unsigned long m;
718
719 m = gop64->mode;
720 mode = (struct efi_graphics_output_protocol_mode_64 *)m;
721
722 status = efi_early->call(gop64->query_mode, gop64,
723 mode->mode, size, info);
724 if (status != EFI_SUCCESS)
725 return status;
726
727 *fb_base = mode->frame_buffer_base;
728 return status;
729}
730
731static efi_status_t
732setup_gop64(struct screen_info *si, efi_guid_t *proto,
733 unsigned long size, void **gop_handle)
734{
735 struct efi_graphics_output_protocol_64 *gop64, *first_gop;
736 unsigned long nr_gops;
737 u16 width, height;
738 u32 pixels_per_scan_line;
739 u32 fb_base;
740 struct efi_pixel_bitmask pixel_info;
741 int pixel_format;
742 efi_status_t status;
743 u64 *handles = (u64 *)(unsigned long)gop_handle;
744 int i;
745
746 first_gop = NULL;
747 gop64 = NULL;
748
749 nr_gops = size / sizeof(u64);
750 for (i = 0; i < nr_gops; i++) {
751 struct efi_graphics_output_mode_info *info = NULL;
752 efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
753 bool conout_found = false;
754 void *dummy = NULL;
755 u64 h = handles[i];
756
757 status = efi_early->call(efi_early->handle_protocol, h,
758 proto, (void **)&gop64);
759 if (status != EFI_SUCCESS)
760 continue;
761
762 status = efi_early->call(efi_early->handle_protocol, h,
763 &conout_proto, &dummy);
764 if (status == EFI_SUCCESS)
765 conout_found = true;
766
767 status = __gop_query64(gop64, &info, &size, &fb_base);
768 if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
769 /*
770 * Systems that use the UEFI Console Splitter may
771 * provide multiple GOP devices, not all of which are
772 * backed by real hardware. The workaround is to search
773 * for a GOP implementing the ConOut protocol, and if
774 * one isn't found, to just fall back to the first GOP.
775 */
776 width = info->horizontal_resolution;
777 height = info->vertical_resolution;
778 pixel_format = info->pixel_format;
779 pixel_info = info->pixel_information;
780 pixels_per_scan_line = info->pixels_per_scan_line;
781
782 /*
783 * Once we've found a GOP supporting ConOut,
784 * don't bother looking any further.
785 */
786 first_gop = gop64;
787 if (conout_found)
788 break;
789 }
790 }
791
792 /* Did we find any GOPs? */
793 if (!first_gop)
794 goto out;
795
796 /* EFI framebuffer */
797 si->orig_video_isVGA = VIDEO_TYPE_EFI;
798
799 si->lfb_width = width;
800 si->lfb_height = height;
801 si->lfb_base = fb_base;
802 si->pages = 1;
803
804 setup_pixel_info(si, pixels_per_scan_line, pixel_info, pixel_format);
805
806 si->lfb_size = si->lfb_linelength * si->lfb_height;
807
808 si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS;
809out:
307 return status; 810 return status;
308} 811}
309 812
310/* 813/*
311 * See if we have Universal Graphics Adapter (UGA) protocol 814 * See if we have Graphics Output Protocol
312 */ 815 */
313static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, 816static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
314 unsigned long size) 817 unsigned long size)
315{ 818{
316 struct efi_uga_draw_protocol *uga, *first_uga;
317 unsigned long nr_ugas;
318 efi_status_t status; 819 efi_status_t status;
319 u32 width, height; 820 void **gop_handle = NULL;
320 void **uga_handle = NULL;
321 int i;
322 821
323 status = efi_call_phys3(sys_table->boottime->allocate_pool, 822 status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
324 EFI_LOADER_DATA, size, &uga_handle); 823 size, (void **)&gop_handle);
325 if (status != EFI_SUCCESS) 824 if (status != EFI_SUCCESS)
326 return status; 825 return status;
327 826
328 status = efi_call_phys5(sys_table->boottime->locate_handle, 827 status = efi_early->call(efi_early->locate_handle,
329 EFI_LOCATE_BY_PROTOCOL, uga_proto, 828 EFI_LOCATE_BY_PROTOCOL,
330 NULL, &size, uga_handle); 829 proto, NULL, &size, gop_handle);
331 if (status != EFI_SUCCESS) 830 if (status != EFI_SUCCESS)
332 goto free_handle; 831 goto free_handle;
333 832
833 if (efi_early->is64)
834 status = setup_gop64(si, proto, size, gop_handle);
835 else
836 status = setup_gop32(si, proto, size, gop_handle);
837
838free_handle:
839 efi_early->call(efi_early->free_pool, gop_handle);
840 return status;
841}
842
843static efi_status_t
844setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height)
845{
846 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
847 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
848 unsigned long nr_ugas;
849 u32 *handles = (u32 *)uga_handle;;
850 efi_status_t status;
851 int i;
852
334 first_uga = NULL; 853 first_uga = NULL;
854 nr_ugas = size / sizeof(u32);
855 for (i = 0; i < nr_ugas; i++) {
856 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
857 u32 w, h, depth, refresh;
858 void *pciio;
859 u32 handle = handles[i];
335 860
336 nr_ugas = size / sizeof(void *); 861 status = efi_early->call(efi_early->handle_protocol, handle,
862 &uga_proto, (void **)&uga);
863 if (status != EFI_SUCCESS)
864 continue;
865
866 efi_early->call(efi_early->handle_protocol, handle,
867 &pciio_proto, &pciio);
868
869 status = efi_early->call((unsigned long)uga->get_mode, uga,
870 &w, &h, &depth, &refresh);
871 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
872 *width = w;
873 *height = h;
874
875 /*
876 * Once we've found a UGA supporting PCIIO,
877 * don't bother looking any further.
878 */
879 if (pciio)
880 break;
881
882 first_uga = uga;
883 }
884 }
885
886 return status;
887}
888
889static efi_status_t
890setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height)
891{
892 struct efi_uga_draw_protocol *uga = NULL, *first_uga;
893 efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID;
894 unsigned long nr_ugas;
895 u64 *handles = (u64 *)uga_handle;;
896 efi_status_t status;
897 int i;
898
899 first_uga = NULL;
900 nr_ugas = size / sizeof(u64);
337 for (i = 0; i < nr_ugas; i++) { 901 for (i = 0; i < nr_ugas; i++) {
338 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; 902 efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID;
339 void *handle = uga_handle[i];
340 u32 w, h, depth, refresh; 903 u32 w, h, depth, refresh;
341 void *pciio; 904 void *pciio;
905 u64 handle = handles[i];
342 906
343 status = efi_call_phys3(sys_table->boottime->handle_protocol, 907 status = efi_early->call(efi_early->handle_protocol, handle,
344 handle, uga_proto, &uga); 908 &uga_proto, (void **)&uga);
345 if (status != EFI_SUCCESS) 909 if (status != EFI_SUCCESS)
346 continue; 910 continue;
347 911
348 efi_call_phys3(sys_table->boottime->handle_protocol, 912 efi_early->call(efi_early->handle_protocol, handle,
349 handle, &pciio_proto, &pciio); 913 &pciio_proto, &pciio);
350 914
351 status = efi_call_phys5(uga->get_mode, uga, &w, &h, 915 status = efi_early->call((unsigned long)uga->get_mode, uga,
352 &depth, &refresh); 916 &w, &h, &depth, &refresh);
353 if (status == EFI_SUCCESS && (!first_uga || pciio)) { 917 if (status == EFI_SUCCESS && (!first_uga || pciio)) {
354 width = w; 918 *width = w;
355 height = h; 919 *height = h;
356 920
357 /* 921 /*
358 * Once we've found a UGA supporting PCIIO, 922 * Once we've found a UGA supporting PCIIO,
@@ -365,7 +929,39 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
365 } 929 }
366 } 930 }
367 931
368 if (!first_uga) 932 return status;
933}
934
935/*
936 * See if we have Universal Graphics Adapter (UGA) protocol
937 */
938static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
939 unsigned long size)
940{
941 efi_status_t status;
942 u32 width, height;
943 void **uga_handle = NULL;
944
945 status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
946 size, (void **)&uga_handle);
947 if (status != EFI_SUCCESS)
948 return status;
949
950 status = efi_early->call(efi_early->locate_handle,
951 EFI_LOCATE_BY_PROTOCOL,
952 uga_proto, NULL, &size, uga_handle);
953 if (status != EFI_SUCCESS)
954 goto free_handle;
955
956 height = 0;
957 width = 0;
958
959 if (efi_early->is64)
960 status = setup_uga64(uga_handle, size, &width, &height);
961 else
962 status = setup_uga32(uga_handle, size, &width, &height);
963
964 if (!width && !height)
369 goto free_handle; 965 goto free_handle;
370 966
371 /* EFI framebuffer */ 967 /* EFI framebuffer */
@@ -384,9 +980,8 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
384 si->rsvd_size = 8; 980 si->rsvd_size = 8;
385 si->rsvd_pos = 24; 981 si->rsvd_pos = 24;
386 982
387
388free_handle: 983free_handle:
389 efi_call_phys1(sys_table->boottime->free_pool, uga_handle); 984 efi_early->call(efi_early->free_pool, uga_handle);
390 return status; 985 return status;
391} 986}
392 987
@@ -404,29 +999,28 @@ void setup_graphics(struct boot_params *boot_params)
404 memset(si, 0, sizeof(*si)); 999 memset(si, 0, sizeof(*si));
405 1000
406 size = 0; 1001 size = 0;
407 status = efi_call_phys5(sys_table->boottime->locate_handle, 1002 status = efi_early->call(efi_early->locate_handle,
408 EFI_LOCATE_BY_PROTOCOL, &graphics_proto, 1003 EFI_LOCATE_BY_PROTOCOL,
409 NULL, &size, gop_handle); 1004 &graphics_proto, NULL, &size, gop_handle);
410 if (status == EFI_BUFFER_TOO_SMALL) 1005 if (status == EFI_BUFFER_TOO_SMALL)
411 status = setup_gop(si, &graphics_proto, size); 1006 status = setup_gop(si, &graphics_proto, size);
412 1007
413 if (status != EFI_SUCCESS) { 1008 if (status != EFI_SUCCESS) {
414 size = 0; 1009 size = 0;
415 status = efi_call_phys5(sys_table->boottime->locate_handle, 1010 status = efi_early->call(efi_early->locate_handle,
416 EFI_LOCATE_BY_PROTOCOL, &uga_proto, 1011 EFI_LOCATE_BY_PROTOCOL,
417 NULL, &size, uga_handle); 1012 &uga_proto, NULL, &size, uga_handle);
418 if (status == EFI_BUFFER_TOO_SMALL) 1013 if (status == EFI_BUFFER_TOO_SMALL)
419 setup_uga(si, &uga_proto, size); 1014 setup_uga(si, &uga_proto, size);
420 } 1015 }
421} 1016}
422 1017
423
424/* 1018/*
425 * Because the x86 boot code expects to be passed a boot_params we 1019 * Because the x86 boot code expects to be passed a boot_params we
426 * need to create one ourselves (usually the bootloader would create 1020 * need to create one ourselves (usually the bootloader would create
427 * one for us). 1021 * one for us).
428 */ 1022 */
429struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) 1023struct boot_params *make_boot_params(struct efi_config *c)
430{ 1024{
431 struct boot_params *boot_params; 1025 struct boot_params *boot_params;
432 struct sys_desc_table *sdt; 1026 struct sys_desc_table *sdt;
@@ -434,7 +1028,7 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table)
434 struct setup_header *hdr; 1028 struct setup_header *hdr;
435 struct efi_info *efi; 1029 struct efi_info *efi;
436 efi_loaded_image_t *image; 1030 efi_loaded_image_t *image;
437 void *options; 1031 void *options, *handle;
438 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; 1032 efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID;
439 int options_size = 0; 1033 int options_size = 0;
440 efi_status_t status; 1034 efi_status_t status;
@@ -445,14 +1039,21 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table)
445 unsigned long ramdisk_addr; 1039 unsigned long ramdisk_addr;
446 unsigned long ramdisk_size; 1040 unsigned long ramdisk_size;
447 1041
448 sys_table = _table; 1042 efi_early = c;
1043 sys_table = (efi_system_table_t *)(unsigned long)efi_early->table;
1044 handle = (void *)(unsigned long)efi_early->image_handle;
449 1045
450 /* Check if we were booted by the EFI firmware */ 1046 /* Check if we were booted by the EFI firmware */
451 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 1047 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
452 return NULL; 1048 return NULL;
453 1049
454 status = efi_call_phys3(sys_table->boottime->handle_protocol, 1050 if (efi_early->is64)
455 handle, &proto, (void *)&image); 1051 setup_boot_services64(efi_early);
1052 else
1053 setup_boot_services32(efi_early);
1054
1055 status = efi_early->call(efi_early->handle_protocol, handle,
1056 &proto, (void *)&image);
456 if (status != EFI_SUCCESS) { 1057 if (status != EFI_SUCCESS) {
457 efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); 1058 efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
458 return NULL; 1059 return NULL;
@@ -641,14 +1242,13 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
641 sizeof(struct e820entry) * nr_desc; 1242 sizeof(struct e820entry) * nr_desc;
642 1243
643 if (*e820ext) { 1244 if (*e820ext) {
644 efi_call_phys1(sys_table->boottime->free_pool, *e820ext); 1245 efi_early->call(efi_early->free_pool, *e820ext);
645 *e820ext = NULL; 1246 *e820ext = NULL;
646 *e820ext_size = 0; 1247 *e820ext_size = 0;
647 } 1248 }
648 1249
649 status = efi_call_phys3(sys_table->boottime->allocate_pool, 1250 status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
650 EFI_LOADER_DATA, size, e820ext); 1251 size, (void **)e820ext);
651
652 if (status == EFI_SUCCESS) 1252 if (status == EFI_SUCCESS)
653 *e820ext_size = size; 1253 *e820ext_size = size;
654 1254
@@ -656,12 +1256,13 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
656} 1256}
657 1257
658static efi_status_t exit_boot(struct boot_params *boot_params, 1258static efi_status_t exit_boot(struct boot_params *boot_params,
659 void *handle) 1259 void *handle, bool is64)
660{ 1260{
661 struct efi_info *efi = &boot_params->efi_info; 1261 struct efi_info *efi = &boot_params->efi_info;
662 unsigned long map_sz, key, desc_size; 1262 unsigned long map_sz, key, desc_size;
663 efi_memory_desc_t *mem_map; 1263 efi_memory_desc_t *mem_map;
664 struct setup_data *e820ext; 1264 struct setup_data *e820ext;
1265 const char *signature;
665 __u32 e820ext_size; 1266 __u32 e820ext_size;
666 __u32 nr_desc, prev_nr_desc; 1267 __u32 nr_desc, prev_nr_desc;
667 efi_status_t status; 1268 efi_status_t status;
@@ -691,11 +1292,13 @@ get_map:
691 if (status != EFI_SUCCESS) 1292 if (status != EFI_SUCCESS)
692 goto free_mem_map; 1293 goto free_mem_map;
693 1294
694 efi_call_phys1(sys_table->boottime->free_pool, mem_map); 1295 efi_early->call(efi_early->free_pool, mem_map);
695 goto get_map; /* Allocated memory, get map again */ 1296 goto get_map; /* Allocated memory, get map again */
696 } 1297 }
697 1298
698 memcpy(&efi->efi_loader_signature, EFI_LOADER_SIGNATURE, sizeof(__u32)); 1299 signature = is64 ? EFI64_LOADER_SIGNATURE : EFI32_LOADER_SIGNATURE;
1300 memcpy(&efi->efi_loader_signature, signature, sizeof(__u32));
1301
699 efi->efi_systab = (unsigned long)sys_table; 1302 efi->efi_systab = (unsigned long)sys_table;
700 efi->efi_memdesc_size = desc_size; 1303 efi->efi_memdesc_size = desc_size;
701 efi->efi_memdesc_version = desc_version; 1304 efi->efi_memdesc_version = desc_version;
@@ -708,8 +1311,7 @@ get_map:
708#endif 1311#endif
709 1312
710 /* Might as well exit boot services now */ 1313 /* Might as well exit boot services now */
711 status = efi_call_phys2(sys_table->boottime->exit_boot_services, 1314 status = efi_early->call(efi_early->exit_boot_services, handle, key);
712 handle, key);
713 if (status != EFI_SUCCESS) { 1315 if (status != EFI_SUCCESS) {
714 /* 1316 /*
715 * ExitBootServices() will fail if any of the event 1317 * ExitBootServices() will fail if any of the event
@@ -722,7 +1324,7 @@ get_map:
722 goto free_mem_map; 1324 goto free_mem_map;
723 1325
724 called_exit = true; 1326 called_exit = true;
725 efi_call_phys1(sys_table->boottime->free_pool, mem_map); 1327 efi_early->call(efi_early->free_pool, mem_map);
726 goto get_map; 1328 goto get_map;
727 } 1329 }
728 1330
@@ -736,23 +1338,31 @@ get_map:
736 return EFI_SUCCESS; 1338 return EFI_SUCCESS;
737 1339
738free_mem_map: 1340free_mem_map:
739 efi_call_phys1(sys_table->boottime->free_pool, mem_map); 1341 efi_early->call(efi_early->free_pool, mem_map);
740 return status; 1342 return status;
741} 1343}
742 1344
743
744/* 1345/*
745 * On success we return a pointer to a boot_params structure, and NULL 1346 * On success we return a pointer to a boot_params structure, and NULL
746 * on failure. 1347 * on failure.
747 */ 1348 */
748struct boot_params *efi_main(void *handle, efi_system_table_t *_table, 1349struct boot_params *efi_main(struct efi_config *c,
749 struct boot_params *boot_params) 1350 struct boot_params *boot_params)
750{ 1351{
751 struct desc_ptr *gdt; 1352 struct desc_ptr *gdt = NULL;
752 efi_loaded_image_t *image; 1353 efi_loaded_image_t *image;
753 struct setup_header *hdr = &boot_params->hdr; 1354 struct setup_header *hdr = &boot_params->hdr;
754 efi_status_t status; 1355 efi_status_t status;
755 struct desc_struct *desc; 1356 struct desc_struct *desc;
1357 void *handle;
1358 efi_system_table_t *_table;
1359 bool is64;
1360
1361 efi_early = c;
1362
1363 _table = (efi_system_table_t *)(unsigned long)efi_early->table;
1364 handle = (void *)(unsigned long)efi_early->image_handle;
1365 is64 = efi_early->is64;
756 1366
757 sys_table = _table; 1367 sys_table = _table;
758 1368
@@ -760,13 +1370,17 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table,
760 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) 1370 if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE)
761 goto fail; 1371 goto fail;
762 1372
1373 if (is64)
1374 setup_boot_services64(efi_early);
1375 else
1376 setup_boot_services32(efi_early);
1377
763 setup_graphics(boot_params); 1378 setup_graphics(boot_params);
764 1379
765 setup_efi_pci(boot_params); 1380 setup_efi_pci(boot_params);
766 1381
767 status = efi_call_phys3(sys_table->boottime->allocate_pool, 1382 status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
768 EFI_LOADER_DATA, sizeof(*gdt), 1383 sizeof(*gdt), (void **)&gdt);
769 (void **)&gdt);
770 if (status != EFI_SUCCESS) { 1384 if (status != EFI_SUCCESS) {
771 efi_printk(sys_table, "Failed to alloc mem for gdt structure\n"); 1385 efi_printk(sys_table, "Failed to alloc mem for gdt structure\n");
772 goto fail; 1386 goto fail;
@@ -797,7 +1411,7 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table,
797 hdr->code32_start = bzimage_addr; 1411 hdr->code32_start = bzimage_addr;
798 } 1412 }
799 1413
800 status = exit_boot(boot_params, handle); 1414 status = exit_boot(boot_params, handle, is64);
801 if (status != EFI_SUCCESS) 1415 if (status != EFI_SUCCESS)
802 goto fail; 1416 goto fail;
803 1417
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h
index 81b6b652b46a..c88c31ecad12 100644
--- a/arch/x86/boot/compressed/eboot.h
+++ b/arch/x86/boot/compressed/eboot.h
@@ -37,6 +37,24 @@ struct efi_graphics_output_mode_info {
37 u32 pixels_per_scan_line; 37 u32 pixels_per_scan_line;
38} __packed; 38} __packed;
39 39
40struct efi_graphics_output_protocol_mode_32 {
41 u32 max_mode;
42 u32 mode;
43 u32 info;
44 u32 size_of_info;
45 u64 frame_buffer_base;
46 u32 frame_buffer_size;
47} __packed;
48
49struct efi_graphics_output_protocol_mode_64 {
50 u32 max_mode;
51 u32 mode;
52 u64 info;
53 u64 size_of_info;
54 u64 frame_buffer_base;
55 u64 frame_buffer_size;
56} __packed;
57
40struct efi_graphics_output_protocol_mode { 58struct efi_graphics_output_protocol_mode {
41 u32 max_mode; 59 u32 max_mode;
42 u32 mode; 60 u32 mode;
@@ -46,6 +64,20 @@ struct efi_graphics_output_protocol_mode {
46 unsigned long frame_buffer_size; 64 unsigned long frame_buffer_size;
47} __packed; 65} __packed;
48 66
67struct efi_graphics_output_protocol_32 {
68 u32 query_mode;
69 u32 set_mode;
70 u32 blt;
71 u32 mode;
72};
73
74struct efi_graphics_output_protocol_64 {
75 u64 query_mode;
76 u64 set_mode;
77 u64 blt;
78 u64 mode;
79};
80
49struct efi_graphics_output_protocol { 81struct efi_graphics_output_protocol {
50 void *query_mode; 82 void *query_mode;
51 unsigned long set_mode; 83 unsigned long set_mode;
@@ -53,10 +85,38 @@ struct efi_graphics_output_protocol {
53 struct efi_graphics_output_protocol_mode *mode; 85 struct efi_graphics_output_protocol_mode *mode;
54}; 86};
55 87
88struct efi_uga_draw_protocol_32 {
89 u32 get_mode;
90 u32 set_mode;
91 u32 blt;
92};
93
94struct efi_uga_draw_protocol_64 {
95 u64 get_mode;
96 u64 set_mode;
97 u64 blt;
98};
99
56struct efi_uga_draw_protocol { 100struct efi_uga_draw_protocol {
57 void *get_mode; 101 void *get_mode;
58 void *set_mode; 102 void *set_mode;
59 void *blt; 103 void *blt;
60}; 104};
61 105
106struct efi_config {
107 u64 image_handle;
108 u64 table;
109 u64 allocate_pool;
110 u64 allocate_pages;
111 u64 get_memory_map;
112 u64 free_pool;
113 u64 free_pages;
114 u64 locate_handle;
115 u64 handle_protocol;
116 u64 exit_boot_services;
117 u64 text_output;
118 efi_status_t (*call)(unsigned long, ...);
119 bool is64;
120} __packed;
121
62#endif /* BOOT_COMPRESSED_EBOOT_H */ 122#endif /* BOOT_COMPRESSED_EBOOT_H */
diff --git a/arch/x86/boot/compressed/efi_stub_64.S b/arch/x86/boot/compressed/efi_stub_64.S
index cedc60de86eb..7ff3632806b1 100644
--- a/arch/x86/boot/compressed/efi_stub_64.S
+++ b/arch/x86/boot/compressed/efi_stub_64.S
@@ -1 +1,30 @@
1#include <asm/segment.h>
2#include <asm/msr.h>
3#include <asm/processor-flags.h>
4
1#include "../../platform/efi/efi_stub_64.S" 5#include "../../platform/efi/efi_stub_64.S"
6
7#ifdef CONFIG_EFI_MIXED
8 .code64
9 .text
10ENTRY(efi64_thunk)
11 push %rbp
12 push %rbx
13
14 subq $16, %rsp
15 leaq efi_exit32(%rip), %rax
16 movl %eax, 8(%rsp)
17 leaq efi_gdt64(%rip), %rax
18 movl %eax, 4(%rsp)
19 movl %eax, 2(%rax) /* Fixup the gdt base address */
20 leaq efi32_boot_gdt(%rip), %rax
21 movl %eax, (%rsp)
22
23 call __efi64_thunk
24
25 addq $16, %rsp
26 pop %rbx
27 pop %rbp
28 ret
29ENDPROC(efi64_thunk)
30#endif /* CONFIG_EFI_MIXED */
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 9116aac232c7..cccc05f0681c 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -42,26 +42,53 @@ ENTRY(startup_32)
42ENTRY(efi_pe_entry) 42ENTRY(efi_pe_entry)
43 add $0x4, %esp 43 add $0x4, %esp
44 44
45 call 1f
461: popl %esi
47 subl $1b, %esi
48
49 popl %ecx
50 movl %ecx, efi32_config(%esi) /* Handle */
51 popl %ecx
52 movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */
53
54 /* Relocate efi_config->call() */
55 leal efi32_config(%esi), %eax
56 add %esi, 88(%eax)
57 pushl %eax
58
45 call make_boot_params 59 call make_boot_params
46 cmpl $0, %eax 60 cmpl $0, %eax
47 je 1f 61 je fail
48 movl 0x4(%esp), %esi 62 popl %ecx
49 movl (%esp), %ecx
50 pushl %eax 63 pushl %eax
51 pushl %esi
52 pushl %ecx 64 pushl %ecx
53 sub $0x4, %esp 65 jmp 2f /* Skip efi_config initialization */
54 66
55ENTRY(efi_stub_entry) 67ENTRY(efi32_stub_entry)
56 add $0x4, %esp 68 add $0x4, %esp
69 popl %ecx
70 popl %edx
71
72 call 1f
731: popl %esi
74 subl $1b, %esi
75
76 movl %ecx, efi32_config(%esi) /* Handle */
77 movl %edx, efi32_config+8(%esi) /* EFI System table pointer */
78
79 /* Relocate efi_config->call() */
80 leal efi32_config(%esi), %eax
81 add %esi, 88(%eax)
82 pushl %eax
832:
57 call efi_main 84 call efi_main
58 cmpl $0, %eax 85 cmpl $0, %eax
59 movl %eax, %esi 86 movl %eax, %esi
60 jne 2f 87 jne 2f
611: 88fail:
62 /* EFI init failed, so hang. */ 89 /* EFI init failed, so hang. */
63 hlt 90 hlt
64 jmp 1b 91 jmp fail
652: 922:
66 call 3f 93 call 3f
673: 943:
@@ -202,6 +229,13 @@ relocated:
202 xorl %ebx, %ebx 229 xorl %ebx, %ebx
203 jmp *%eax 230 jmp *%eax
204 231
232 .data
233efi32_config:
234 .fill 11,8,0
235 .long efi_call_phys
236 .long 0
237 .byte 0
238
205/* 239/*
206 * Stack and heap for uncompression 240 * Stack and heap for uncompression
207 */ 241 */
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index c5c1ae0997e7..4f40cddd025d 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -113,7 +113,8 @@ ENTRY(startup_32)
113 lgdt gdt(%ebp) 113 lgdt gdt(%ebp)
114 114
115 /* Enable PAE mode */ 115 /* Enable PAE mode */
116 movl $(X86_CR4_PAE), %eax 116 movl %cr4, %eax
117 orl $X86_CR4_PAE, %eax
117 movl %eax, %cr4 118 movl %eax, %cr4
118 119
119 /* 120 /*
@@ -178,6 +179,13 @@ ENTRY(startup_32)
178 */ 179 */
179 pushl $__KERNEL_CS 180 pushl $__KERNEL_CS
180 leal startup_64(%ebp), %eax 181 leal startup_64(%ebp), %eax
182#ifdef CONFIG_EFI_MIXED
183 movl efi32_config(%ebp), %ebx
184 cmp $0, %ebx
185 jz 1f
186 leal handover_entry(%ebp), %eax
1871:
188#endif
181 pushl %eax 189 pushl %eax
182 190
183 /* Enter paged protected Mode, activating Long Mode */ 191 /* Enter paged protected Mode, activating Long Mode */
@@ -188,6 +196,30 @@ ENTRY(startup_32)
188 lret 196 lret
189ENDPROC(startup_32) 197ENDPROC(startup_32)
190 198
199#ifdef CONFIG_EFI_MIXED
200 .org 0x190
201ENTRY(efi32_stub_entry)
202 add $0x4, %esp /* Discard return address */
203 popl %ecx
204 popl %edx
205 popl %esi
206
207 leal (BP_scratch+4)(%esi), %esp
208 call 1f
2091: pop %ebp
210 subl $1b, %ebp
211
212 movl %ecx, efi32_config(%ebp)
213 movl %edx, efi32_config+8(%ebp)
214 sgdtl efi32_boot_gdt(%ebp)
215
216 leal efi32_config(%ebp), %eax
217 movl %eax, efi_config(%ebp)
218
219 jmp startup_32
220ENDPROC(efi32_stub_entry)
221#endif
222
191 .code64 223 .code64
192 .org 0x200 224 .org 0x200
193ENTRY(startup_64) 225ENTRY(startup_64)
@@ -209,26 +241,48 @@ ENTRY(startup_64)
209 jmp preferred_addr 241 jmp preferred_addr
210 242
211ENTRY(efi_pe_entry) 243ENTRY(efi_pe_entry)
212 mov %rcx, %rdi 244 movq %rcx, efi64_config(%rip) /* Handle */
213 mov %rdx, %rsi 245 movq %rdx, efi64_config+8(%rip) /* EFI System table pointer */
214 pushq %rdi 246
215 pushq %rsi 247 leaq efi64_config(%rip), %rax
248 movq %rax, efi_config(%rip)
249
250 call 1f
2511: popq %rbp
252 subq $1b, %rbp
253
254 /*
255 * Relocate efi_config->call().
256 */
257 addq %rbp, efi64_config+88(%rip)
258
259 movq %rax, %rdi
216 call make_boot_params 260 call make_boot_params
217 cmpq $0,%rax 261 cmpq $0,%rax
218 je 1f 262 je fail
219 mov %rax, %rdx 263 mov %rax, %rsi
220 popq %rsi 264 jmp 2f /* Skip the relocation */
221 popq %rdi
222 265
223ENTRY(efi_stub_entry) 266handover_entry:
267 call 1f
2681: popq %rbp
269 subq $1b, %rbp
270
271 /*
272 * Relocate efi_config->call().
273 */
274 movq efi_config(%rip), %rax
275 addq %rbp, 88(%rax)
2762:
277 movq efi_config(%rip), %rdi
224 call efi_main 278 call efi_main
225 movq %rax,%rsi 279 movq %rax,%rsi
226 cmpq $0,%rax 280 cmpq $0,%rax
227 jne 2f 281 jne 2f
2281: 282fail:
229 /* EFI init failed, so hang. */ 283 /* EFI init failed, so hang. */
230 hlt 284 hlt
231 jmp 1b 285 jmp fail
2322: 2862:
233 call 3f 287 call 3f
2343: 2883:
@@ -307,6 +361,20 @@ preferred_addr:
307 leaq relocated(%rbx), %rax 361 leaq relocated(%rbx), %rax
308 jmp *%rax 362 jmp *%rax
309 363
364#ifdef CONFIG_EFI_STUB
365 .org 0x390
366ENTRY(efi64_stub_entry)
367 movq %rdi, efi64_config(%rip) /* Handle */
368 movq %rsi, efi64_config+8(%rip) /* EFI System table pointer */
369
370 leaq efi64_config(%rip), %rax
371 movq %rax, efi_config(%rip)
372
373 movq %rdx, %rsi
374 jmp handover_entry
375ENDPROC(efi64_stub_entry)
376#endif
377
310 .text 378 .text
311relocated: 379relocated:
312 380
@@ -372,6 +440,22 @@ gdt:
372 .quad 0x0000000000000000 /* TS continued */ 440 .quad 0x0000000000000000 /* TS continued */
373gdt_end: 441gdt_end:
374 442
443efi_config:
444 .quad 0
445
446#ifdef CONFIG_EFI_MIXED
447 .global efi32_config
448efi32_config:
449 .fill 11,8,0
450 .quad efi64_thunk
451 .byte 0
452#endif
453
454 .global efi64_config
455efi64_config:
456 .fill 11,8,0
457 .quad efi_call6
458 .byte 1
375/* 459/*
376 * Stack and heap for uncompression 460 * Stack and heap for uncompression
377 */ 461 */
diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
index ec3b8ba68096..256388260c88 100644
--- a/arch/x86/boot/header.S
+++ b/arch/x86/boot/header.S
@@ -283,7 +283,7 @@ _start:
283 # Part 2 of the header, from the old setup.S 283 # Part 2 of the header, from the old setup.S
284 284
285 .ascii "HdrS" # header signature 285 .ascii "HdrS" # header signature
286 .word 0x020c # header version number (>= 0x0105) 286 .word 0x020d # header version number (>= 0x0105)
287 # or else old loadlin-1.5 will fail) 287 # or else old loadlin-1.5 will fail)
288 .globl realmode_swtch 288 .globl realmode_swtch
289realmode_swtch: .word 0, 0 # default_switch, SETUPSEG 289realmode_swtch: .word 0, 0 # default_switch, SETUPSEG
@@ -375,7 +375,8 @@ xloadflags:
375# define XLF0 0 375# define XLF0 0
376#endif 376#endif
377 377
378#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64) 378#if defined(CONFIG_RELOCATABLE) && defined(CONFIG_X86_64) && \
379 !defined(CONFIG_EFI_MIXED)
379 /* kernel/boot_param/ramdisk could be loaded above 4g */ 380 /* kernel/boot_param/ramdisk could be loaded above 4g */
380# define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G 381# define XLF1 XLF_CAN_BE_LOADED_ABOVE_4G
381#else 382#else
@@ -383,10 +384,14 @@ xloadflags:
383#endif 384#endif
384 385
385#ifdef CONFIG_EFI_STUB 386#ifdef CONFIG_EFI_STUB
386# ifdef CONFIG_X86_64 387# ifdef CONFIG_EFI_MIXED
387# define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */ 388# define XLF23 (XLF_EFI_HANDOVER_32|XLF_EFI_HANDOVER_64)
388# else 389# else
389# define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */ 390# ifdef CONFIG_X86_64
391# define XLF23 XLF_EFI_HANDOVER_64 /* 64-bit EFI handover ok */
392# else
393# define XLF23 XLF_EFI_HANDOVER_32 /* 32-bit EFI handover ok */
394# endif
390# endif 395# endif
391#else 396#else
392# define XLF23 0 397# define XLF23 0
@@ -426,13 +431,7 @@ pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
426#define INIT_SIZE VO_INIT_SIZE 431#define INIT_SIZE VO_INIT_SIZE
427#endif 432#endif
428init_size: .long INIT_SIZE # kernel initialization size 433init_size: .long INIT_SIZE # kernel initialization size
429handover_offset: 434handover_offset: .long 0 # Filled in by build.c
430#ifdef CONFIG_EFI_STUB
431 .long 0x30 # offset to the handover
432 # protocol entry point
433#else
434 .long 0
435#endif
436 435
437# End of setup header ##################################################### 436# End of setup header #####################################################
438 437
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 8e15b22391fc..4f07df5ac5d9 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -53,7 +53,8 @@ int is_big_kernel;
53 53
54#define PECOFF_RELOC_RESERVE 0x20 54#define PECOFF_RELOC_RESERVE 0x20
55 55
56unsigned long efi_stub_entry; 56unsigned long efi32_stub_entry;
57unsigned long efi64_stub_entry;
57unsigned long efi_pe_entry; 58unsigned long efi_pe_entry;
58unsigned long startup_64; 59unsigned long startup_64;
59 60
@@ -219,6 +220,51 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz)
219 update_pecoff_section_header(".text", text_start, text_sz); 220 update_pecoff_section_header(".text", text_start, text_sz);
220} 221}
221 222
223static int reserve_pecoff_reloc_section(int c)
224{
225 /* Reserve 0x20 bytes for .reloc section */
226 memset(buf+c, 0, PECOFF_RELOC_RESERVE);
227 return PECOFF_RELOC_RESERVE;
228}
229
230static void efi_stub_defaults(void)
231{
232 /* Defaults for old kernel */
233#ifdef CONFIG_X86_32
234 efi_pe_entry = 0x10;
235#else
236 efi_pe_entry = 0x210;
237 startup_64 = 0x200;
238#endif
239}
240
241static void efi_stub_entry_update(void)
242{
243 unsigned long addr = efi32_stub_entry;
244
245#ifdef CONFIG_X86_64
246 /* Yes, this is really how we defined it :( */
247 addr = efi64_stub_entry - 0x200;
248#endif
249
250#ifdef CONFIG_EFI_MIXED
251 if (efi32_stub_entry != addr)
252 die("32-bit and 64-bit EFI entry points do not match\n");
253#endif
254 put_unaligned_le32(addr, &buf[0x264]);
255}
256
257#else
258
259static inline void update_pecoff_setup_and_reloc(unsigned int) {}
260static inline void update_pecoff_text(unsigned int, unsigned int) {}
261static inline void efi_stub_defaults(void) {}
262static inline void efi_stup_entry_update(void) {}
263
264static inline int reserve_pecoff_reloc_section(int c)
265{
266 return 0;
267}
222#endif /* CONFIG_EFI_STUB */ 268#endif /* CONFIG_EFI_STUB */
223 269
224 270
@@ -250,7 +296,8 @@ static void parse_zoffset(char *fname)
250 p = (char *)buf; 296 p = (char *)buf;
251 297
252 while (p && *p) { 298 while (p && *p) {
253 PARSE_ZOFS(p, efi_stub_entry); 299 PARSE_ZOFS(p, efi32_stub_entry);
300 PARSE_ZOFS(p, efi64_stub_entry);
254 PARSE_ZOFS(p, efi_pe_entry); 301 PARSE_ZOFS(p, efi_pe_entry);
255 PARSE_ZOFS(p, startup_64); 302 PARSE_ZOFS(p, startup_64);
256 303
@@ -271,15 +318,7 @@ int main(int argc, char ** argv)
271 void *kernel; 318 void *kernel;
272 u32 crc = 0xffffffffUL; 319 u32 crc = 0xffffffffUL;
273 320
274 /* Defaults for old kernel */ 321 efi_stub_defaults();
275#ifdef CONFIG_X86_32
276 efi_pe_entry = 0x10;
277 efi_stub_entry = 0x30;
278#else
279 efi_pe_entry = 0x210;
280 efi_stub_entry = 0x230;
281 startup_64 = 0x200;
282#endif
283 322
284 if (argc != 5) 323 if (argc != 5)
285 usage(); 324 usage();
@@ -302,11 +341,7 @@ int main(int argc, char ** argv)
302 die("Boot block hasn't got boot flag (0xAA55)"); 341 die("Boot block hasn't got boot flag (0xAA55)");
303 fclose(file); 342 fclose(file);
304 343
305#ifdef CONFIG_EFI_STUB 344 c += reserve_pecoff_reloc_section(c);
306 /* Reserve 0x20 bytes for .reloc section */
307 memset(buf+c, 0, PECOFF_RELOC_RESERVE);
308 c += PECOFF_RELOC_RESERVE;
309#endif
310 345
311 /* Pad unused space with zeros */ 346 /* Pad unused space with zeros */
312 setup_sectors = (c + 511) / 512; 347 setup_sectors = (c + 511) / 512;
@@ -315,9 +350,7 @@ int main(int argc, char ** argv)
315 i = setup_sectors*512; 350 i = setup_sectors*512;
316 memset(buf+c, 0, i-c); 351 memset(buf+c, 0, i-c);
317 352
318#ifdef CONFIG_EFI_STUB
319 update_pecoff_setup_and_reloc(i); 353 update_pecoff_setup_and_reloc(i);
320#endif
321 354
322 /* Set the default root device */ 355 /* Set the default root device */
323 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); 356 put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]);
@@ -342,14 +375,9 @@ int main(int argc, char ** argv)
342 buf[0x1f1] = setup_sectors-1; 375 buf[0x1f1] = setup_sectors-1;
343 put_unaligned_le32(sys_size, &buf[0x1f4]); 376 put_unaligned_le32(sys_size, &buf[0x1f4]);
344 377
345#ifdef CONFIG_EFI_STUB
346 update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz)); 378 update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz));
347 379
348#ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ 380 efi_stub_entry_update();
349 efi_stub_entry -= 0x200;
350#endif
351 put_unaligned_le32(efi_stub_entry, &buf[0x264]);
352#endif
353 381
354 crc = partial_crc32(buf, i, crc); 382 crc = partial_crc32(buf, i, crc);
355 if (fwrite(buf, 1, i, dest) != i) 383 if (fwrite(buf, 1, i, dest) != i)