diff options
-rw-r--r-- | arch/x86/boot/compressed/eboot.c | 319 | ||||
-rw-r--r-- | arch/x86/boot/compressed/eboot.h | 16 | ||||
-rw-r--r-- | arch/x86/boot/compressed/head_32.S | 48 | ||||
-rw-r--r-- | arch/x86/boot/compressed/head_64.S | 57 | ||||
-rw-r--r-- | drivers/firmware/efi/efi-stub-helper.c | 148 |
5 files changed, 377 insertions, 211 deletions
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index a7677babf946..42548168bdc3 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c | |||
@@ -19,10 +19,145 @@ | |||
19 | 19 | ||
20 | static efi_system_table_t *sys_table; | 20 | static efi_system_table_t *sys_table; |
21 | 21 | ||
22 | static 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); | ||
22 | 47 | ||
23 | #include "../../../../drivers/firmware/efi/efi-stub-helper.c" | 48 | static void efi_printk(efi_system_table_t *, char *); |
49 | static void efi_char16_printk(efi_system_table_t *, efi_char16_t *); | ||
50 | |||
51 | static efi_status_t | ||
52 | efi_file_size(efi_system_table_t *sys_table, void *__fh, | ||
53 | efi_char16_t *filename_16, void **handle, u64 *file_sz) | ||
54 | { | ||
55 | efi_file_handle_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 | |||
80 | grow: | ||
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 | |||
104 | static inline efi_status_t | ||
105 | efi_file_read(void *__fh, void *handle, unsigned long *size, void *addr) | ||
106 | { | ||
107 | efi_file_handle_t *fh = __fh; | ||
108 | return efi_early->call((unsigned long)fh->read, handle, size, addr); | ||
109 | } | ||
110 | |||
111 | static inline efi_status_t efi_file_close(void *__fh, void *handle) | ||
112 | { | ||
113 | efi_file_handle_t *fh = __fh; | ||
24 | 114 | ||
115 | return efi_early->call((unsigned long)fh->close, handle); | ||
116 | } | ||
117 | |||
118 | static inline efi_status_t | ||
119 | efi_open_volume(efi_system_table_t *sys_table, void *__image, void **__fh) | ||
120 | { | ||
121 | efi_file_io_interface_t *io; | ||
122 | efi_loaded_image_t *image = __image; | ||
123 | efi_file_handle_t *fh; | ||
124 | efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; | ||
125 | efi_status_t status; | ||
126 | void *handle = (void *)(unsigned long)image->device_handle; | ||
127 | u32 func; | ||
128 | |||
129 | status = efi_early->call(efi_early->handle_protocol, handle, | ||
130 | &fs_proto, (void **)&io); | ||
131 | if (status != EFI_SUCCESS) { | ||
132 | efi_printk(sys_table, "Failed to handle fs_proto\n"); | ||
133 | return status; | ||
134 | } | ||
25 | 135 | ||
136 | func = (unsigned long)io->open_volume; | ||
137 | status = efi_early->call(func, io, &fh); | ||
138 | if (status != EFI_SUCCESS) | ||
139 | efi_printk(sys_table, "Failed to open volume\n"); | ||
140 | |||
141 | *__fh = fh; | ||
142 | return status; | ||
143 | } | ||
144 | |||
145 | static inline void | ||
146 | efi_char16_printk(efi_system_table_t *table, efi_char16_t *str) | ||
147 | { | ||
148 | struct efi_simple_text_output_protocol *out; | ||
149 | unsigned long output_string; | ||
150 | size_t offset; | ||
151 | unsigned long *func; | ||
152 | |||
153 | offset = offsetof(typeof(*out), output_string); | ||
154 | output_string = efi_early->text_output + offset; | ||
155 | func = (unsigned long *)output_string; | ||
156 | |||
157 | efi_early->call(*func, efi_early->text_output, str); | ||
158 | } | ||
159 | |||
160 | #include "../../../../drivers/firmware/efi/efi-stub-helper.c" | ||
26 | 161 | ||
27 | static void find_bits(unsigned long mask, u8 *pos, u8 *size) | 162 | static void find_bits(unsigned long mask, u8 *pos, u8 *size) |
28 | { | 163 | { |
@@ -51,7 +186,7 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
51 | { | 186 | { |
52 | efi_pci_io_protocol *pci; | 187 | efi_pci_io_protocol *pci; |
53 | efi_status_t status; | 188 | efi_status_t status; |
54 | void **pci_handle; | 189 | void **pci_handle = NULL; |
55 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; | 190 | efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; |
56 | unsigned long nr_pci, size = 0; | 191 | unsigned long nr_pci, size = 0; |
57 | int i; | 192 | int i; |
@@ -62,20 +197,21 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
62 | while (data && data->next) | 197 | while (data && data->next) |
63 | data = (struct setup_data *)(unsigned long)data->next; | 198 | data = (struct setup_data *)(unsigned long)data->next; |
64 | 199 | ||
65 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 200 | status = efi_early->call(efi_early->locate_handle, |
66 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, | 201 | EFI_LOCATE_BY_PROTOCOL, |
67 | NULL, &size, pci_handle); | 202 | &pci_proto, NULL, &size, pci_handle); |
68 | 203 | ||
69 | if (status == EFI_BUFFER_TOO_SMALL) { | 204 | if (status == EFI_BUFFER_TOO_SMALL) { |
70 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 205 | status = efi_early->call(efi_early->allocate_pool, |
71 | EFI_LOADER_DATA, size, &pci_handle); | 206 | EFI_LOADER_DATA, |
207 | size, (void **)&pci_handle); | ||
72 | 208 | ||
73 | if (status != EFI_SUCCESS) | 209 | if (status != EFI_SUCCESS) |
74 | return status; | 210 | return status; |
75 | 211 | ||
76 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 212 | status = efi_early->call(efi_early->locate_handle, |
77 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, | 213 | EFI_LOCATE_BY_PROTOCOL, &pci_proto, |
78 | NULL, &size, pci_handle); | 214 | NULL, &size, pci_handle); |
79 | } | 215 | } |
80 | 216 | ||
81 | if (status != EFI_SUCCESS) | 217 | if (status != EFI_SUCCESS) |
@@ -87,8 +223,8 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
87 | uint64_t attributes; | 223 | uint64_t attributes; |
88 | struct pci_setup_rom *rom; | 224 | struct pci_setup_rom *rom; |
89 | 225 | ||
90 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 226 | status = efi_early->call(efi_early->handle_protocol, h, |
91 | h, &pci_proto, &pci); | 227 | &pci_proto, (void **)&pci); |
92 | 228 | ||
93 | if (status != EFI_SUCCESS) | 229 | if (status != EFI_SUCCESS) |
94 | continue; | 230 | continue; |
@@ -97,13 +233,13 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
97 | continue; | 233 | continue; |
98 | 234 | ||
99 | #ifdef CONFIG_X86_64 | 235 | #ifdef CONFIG_X86_64 |
100 | status = efi_call_phys4(pci->attributes, pci, | 236 | status = efi_early->call((unsigned long)pci->attributes, pci, |
101 | EfiPciIoAttributeOperationGet, 0, | 237 | EfiPciIoAttributeOperationGet, 0, |
102 | &attributes); | 238 | &attributes); |
103 | #else | 239 | #else |
104 | status = efi_call_phys5(pci->attributes, pci, | 240 | status = efi_early->call((unsigned long)pci->attributes, pci, |
105 | EfiPciIoAttributeOperationGet, 0, 0, | 241 | EfiPciIoAttributeOperationGet, 0, 0, |
106 | &attributes); | 242 | &attributes); |
107 | #endif | 243 | #endif |
108 | if (status != EFI_SUCCESS) | 244 | if (status != EFI_SUCCESS) |
109 | continue; | 245 | continue; |
@@ -113,8 +249,8 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
113 | 249 | ||
114 | size = pci->romsize + sizeof(*rom); | 250 | size = pci->romsize + sizeof(*rom); |
115 | 251 | ||
116 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 252 | status = efi_early->call(efi_early->allocate_pool, |
117 | EFI_LOADER_DATA, size, &rom); | 253 | EFI_LOADER_DATA, size, &rom); |
118 | 254 | ||
119 | if (status != EFI_SUCCESS) | 255 | if (status != EFI_SUCCESS) |
120 | continue; | 256 | continue; |
@@ -124,23 +260,23 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
124 | rom->data.next = 0; | 260 | rom->data.next = 0; |
125 | rom->pcilen = pci->romsize; | 261 | rom->pcilen = pci->romsize; |
126 | 262 | ||
127 | status = efi_call_phys5(pci->pci.read, pci, | 263 | status = efi_early->call((unsigned long)pci->pci.read, pci, |
128 | EfiPciIoWidthUint16, PCI_VENDOR_ID, | 264 | EfiPciIoWidthUint16, PCI_VENDOR_ID, |
129 | 1, &(rom->vendor)); | 265 | 1, &(rom->vendor)); |
130 | 266 | ||
131 | if (status != EFI_SUCCESS) | 267 | if (status != EFI_SUCCESS) |
132 | goto free_struct; | 268 | goto free_struct; |
133 | 269 | ||
134 | status = efi_call_phys5(pci->pci.read, pci, | 270 | status = efi_early->call((unsigned long)pci->pci.read, pci, |
135 | EfiPciIoWidthUint16, PCI_DEVICE_ID, | 271 | EfiPciIoWidthUint16, PCI_DEVICE_ID, |
136 | 1, &(rom->devid)); | 272 | 1, &(rom->devid)); |
137 | 273 | ||
138 | if (status != EFI_SUCCESS) | 274 | if (status != EFI_SUCCESS) |
139 | goto free_struct; | 275 | goto free_struct; |
140 | 276 | ||
141 | status = efi_call_phys5(pci->get_location, pci, | 277 | status = efi_early->call((unsigned long)pci->get_location, pci, |
142 | &(rom->segment), &(rom->bus), | 278 | &(rom->segment), &(rom->bus), |
143 | &(rom->device), &(rom->function)); | 279 | &(rom->device), &(rom->function)); |
144 | 280 | ||
145 | if (status != EFI_SUCCESS) | 281 | if (status != EFI_SUCCESS) |
146 | goto free_struct; | 282 | goto free_struct; |
@@ -156,11 +292,11 @@ static efi_status_t setup_efi_pci(struct boot_params *params) | |||
156 | 292 | ||
157 | continue; | 293 | continue; |
158 | free_struct: | 294 | free_struct: |
159 | efi_call_phys1(sys_table->boottime->free_pool, rom); | 295 | efi_early->call(efi_early->free_pool, rom); |
160 | } | 296 | } |
161 | 297 | ||
162 | free_handle: | 298 | free_handle: |
163 | efi_call_phys1(sys_table->boottime->free_pool, pci_handle); | 299 | efi_early->call(efi_early->free_pool, pci_handle); |
164 | return status; | 300 | return status; |
165 | } | 301 | } |
166 | 302 | ||
@@ -174,21 +310,21 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, | |||
174 | struct efi_pixel_bitmask pixel_info; | 310 | struct efi_pixel_bitmask pixel_info; |
175 | unsigned long nr_gops; | 311 | unsigned long nr_gops; |
176 | efi_status_t status; | 312 | efi_status_t status; |
177 | void **gop_handle; | 313 | void **gop_handle = NULL; |
178 | u16 width, height; | 314 | u16 width, height; |
179 | u32 fb_base, fb_size; | 315 | u32 fb_base, fb_size; |
180 | u32 pixels_per_scan_line; | 316 | u32 pixels_per_scan_line; |
181 | int pixel_format; | 317 | int pixel_format; |
182 | int i; | 318 | int i; |
183 | 319 | ||
184 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 320 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
185 | EFI_LOADER_DATA, size, &gop_handle); | 321 | size, (void **)&gop_handle); |
186 | if (status != EFI_SUCCESS) | 322 | if (status != EFI_SUCCESS) |
187 | return status; | 323 | return status; |
188 | 324 | ||
189 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 325 | status = efi_early->call(efi_early->locate_handle, |
190 | EFI_LOCATE_BY_PROTOCOL, proto, | 326 | EFI_LOCATE_BY_PROTOCOL, |
191 | NULL, &size, gop_handle); | 327 | proto, NULL, &size, gop_handle); |
192 | if (status != EFI_SUCCESS) | 328 | if (status != EFI_SUCCESS) |
193 | goto free_handle; | 329 | goto free_handle; |
194 | 330 | ||
@@ -202,19 +338,18 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, | |||
202 | void *dummy; | 338 | void *dummy; |
203 | void *h = gop_handle[i]; | 339 | void *h = gop_handle[i]; |
204 | 340 | ||
205 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 341 | status = efi_early->call(efi_early->handle_protocol, h, |
206 | h, proto, &gop); | 342 | proto, (void **)&gop); |
207 | if (status != EFI_SUCCESS) | 343 | if (status != EFI_SUCCESS) |
208 | continue; | 344 | continue; |
209 | 345 | ||
210 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 346 | status = efi_early->call(efi_early->handle_protocol, h, |
211 | h, &conout_proto, &dummy); | 347 | &conout_proto, &dummy); |
212 | |||
213 | if (status == EFI_SUCCESS) | 348 | if (status == EFI_SUCCESS) |
214 | conout_found = true; | 349 | conout_found = true; |
215 | 350 | ||
216 | status = efi_call_phys4(gop->query_mode, gop, | 351 | status = efi_early->call((unsigned long)gop->query_mode, gop, |
217 | gop->mode->mode, &size, &info); | 352 | gop->mode->mode, &size, &info); |
218 | if (status == EFI_SUCCESS && (!first_gop || conout_found)) { | 353 | if (status == EFI_SUCCESS && (!first_gop || conout_found)) { |
219 | /* | 354 | /* |
220 | * Systems that use the UEFI Console Splitter may | 355 | * Systems that use the UEFI Console Splitter may |
@@ -303,7 +438,7 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, | |||
303 | si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; | 438 | si->capabilities |= VIDEO_CAPABILITY_SKIP_QUIRKS; |
304 | 439 | ||
305 | free_handle: | 440 | free_handle: |
306 | efi_call_phys1(sys_table->boottime->free_pool, gop_handle); | 441 | efi_early->call(efi_early->free_pool, gop_handle); |
307 | return status; | 442 | return status; |
308 | } | 443 | } |
309 | 444 | ||
@@ -320,14 +455,14 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | |||
320 | void **uga_handle = NULL; | 455 | void **uga_handle = NULL; |
321 | int i; | 456 | int i; |
322 | 457 | ||
323 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 458 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
324 | EFI_LOADER_DATA, size, &uga_handle); | 459 | size, (void **)&uga_handle); |
325 | if (status != EFI_SUCCESS) | 460 | if (status != EFI_SUCCESS) |
326 | return status; | 461 | return status; |
327 | 462 | ||
328 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 463 | status = efi_early->call(efi_early->locate_handle, |
329 | EFI_LOCATE_BY_PROTOCOL, uga_proto, | 464 | EFI_LOCATE_BY_PROTOCOL, |
330 | NULL, &size, uga_handle); | 465 | uga_proto, NULL, &size, uga_handle); |
331 | if (status != EFI_SUCCESS) | 466 | if (status != EFI_SUCCESS) |
332 | goto free_handle; | 467 | goto free_handle; |
333 | 468 | ||
@@ -340,16 +475,16 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | |||
340 | u32 w, h, depth, refresh; | 475 | u32 w, h, depth, refresh; |
341 | void *pciio; | 476 | void *pciio; |
342 | 477 | ||
343 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 478 | status = efi_early->call(efi_early->handle_protocol, handle, |
344 | handle, uga_proto, &uga); | 479 | uga_proto, (void **)&uga); |
345 | if (status != EFI_SUCCESS) | 480 | if (status != EFI_SUCCESS) |
346 | continue; | 481 | continue; |
347 | 482 | ||
348 | efi_call_phys3(sys_table->boottime->handle_protocol, | 483 | efi_early->call(efi_early->handle_protocol, handle, |
349 | handle, &pciio_proto, &pciio); | 484 | &pciio_proto, &pciio); |
350 | 485 | ||
351 | status = efi_call_phys5(uga->get_mode, uga, &w, &h, | 486 | status = efi_early->call((unsigned long)uga->get_mode, uga, |
352 | &depth, &refresh); | 487 | &w, &h, &depth, &refresh); |
353 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { | 488 | if (status == EFI_SUCCESS && (!first_uga || pciio)) { |
354 | width = w; | 489 | width = w; |
355 | height = h; | 490 | height = h; |
@@ -386,7 +521,7 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, | |||
386 | 521 | ||
387 | 522 | ||
388 | free_handle: | 523 | free_handle: |
389 | efi_call_phys1(sys_table->boottime->free_pool, uga_handle); | 524 | efi_early->call(efi_early->free_pool, uga_handle); |
390 | return status; | 525 | return status; |
391 | } | 526 | } |
392 | 527 | ||
@@ -404,29 +539,28 @@ void setup_graphics(struct boot_params *boot_params) | |||
404 | memset(si, 0, sizeof(*si)); | 539 | memset(si, 0, sizeof(*si)); |
405 | 540 | ||
406 | size = 0; | 541 | size = 0; |
407 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 542 | status = efi_early->call(efi_early->locate_handle, |
408 | EFI_LOCATE_BY_PROTOCOL, &graphics_proto, | 543 | EFI_LOCATE_BY_PROTOCOL, |
409 | NULL, &size, gop_handle); | 544 | &graphics_proto, NULL, &size, gop_handle); |
410 | if (status == EFI_BUFFER_TOO_SMALL) | 545 | if (status == EFI_BUFFER_TOO_SMALL) |
411 | status = setup_gop(si, &graphics_proto, size); | 546 | status = setup_gop(si, &graphics_proto, size); |
412 | 547 | ||
413 | if (status != EFI_SUCCESS) { | 548 | if (status != EFI_SUCCESS) { |
414 | size = 0; | 549 | size = 0; |
415 | status = efi_call_phys5(sys_table->boottime->locate_handle, | 550 | status = efi_early->call(efi_early->locate_handle, |
416 | EFI_LOCATE_BY_PROTOCOL, &uga_proto, | 551 | EFI_LOCATE_BY_PROTOCOL, |
417 | NULL, &size, uga_handle); | 552 | &uga_proto, NULL, &size, uga_handle); |
418 | if (status == EFI_BUFFER_TOO_SMALL) | 553 | if (status == EFI_BUFFER_TOO_SMALL) |
419 | setup_uga(si, &uga_proto, size); | 554 | setup_uga(si, &uga_proto, size); |
420 | } | 555 | } |
421 | } | 556 | } |
422 | 557 | ||
423 | |||
424 | /* | 558 | /* |
425 | * Because the x86 boot code expects to be passed a boot_params we | 559 | * Because the x86 boot code expects to be passed a boot_params we |
426 | * need to create one ourselves (usually the bootloader would create | 560 | * need to create one ourselves (usually the bootloader would create |
427 | * one for us). | 561 | * one for us). |
428 | */ | 562 | */ |
429 | struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) | 563 | struct boot_params *make_boot_params(struct efi_config *c) |
430 | { | 564 | { |
431 | struct boot_params *boot_params; | 565 | struct boot_params *boot_params; |
432 | struct sys_desc_table *sdt; | 566 | struct sys_desc_table *sdt; |
@@ -434,7 +568,7 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) | |||
434 | struct setup_header *hdr; | 568 | struct setup_header *hdr; |
435 | struct efi_info *efi; | 569 | struct efi_info *efi; |
436 | efi_loaded_image_t *image; | 570 | efi_loaded_image_t *image; |
437 | void *options; | 571 | void *options, *handle; |
438 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; | 572 | efi_guid_t proto = LOADED_IMAGE_PROTOCOL_GUID; |
439 | int options_size = 0; | 573 | int options_size = 0; |
440 | efi_status_t status; | 574 | efi_status_t status; |
@@ -445,14 +579,21 @@ struct boot_params *make_boot_params(void *handle, efi_system_table_t *_table) | |||
445 | unsigned long ramdisk_addr; | 579 | unsigned long ramdisk_addr; |
446 | unsigned long ramdisk_size; | 580 | unsigned long ramdisk_size; |
447 | 581 | ||
448 | sys_table = _table; | 582 | efi_early = c; |
583 | sys_table = (efi_system_table_t *)(unsigned long)efi_early->table; | ||
584 | handle = (void *)(unsigned long)efi_early->image_handle; | ||
449 | 585 | ||
450 | /* Check if we were booted by the EFI firmware */ | 586 | /* Check if we were booted by the EFI firmware */ |
451 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) | 587 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
452 | return NULL; | 588 | return NULL; |
453 | 589 | ||
454 | status = efi_call_phys3(sys_table->boottime->handle_protocol, | 590 | if (efi_early->is64) |
455 | handle, &proto, (void *)&image); | 591 | setup_boot_services64(efi_early); |
592 | else | ||
593 | setup_boot_services32(efi_early); | ||
594 | |||
595 | status = efi_early->call(efi_early->handle_protocol, handle, | ||
596 | &proto, (void *)&image); | ||
456 | if (status != EFI_SUCCESS) { | 597 | if (status != EFI_SUCCESS) { |
457 | efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); | 598 | efi_printk(sys_table, "Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); |
458 | return NULL; | 599 | return NULL; |
@@ -641,14 +782,13 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext, | |||
641 | sizeof(struct e820entry) * nr_desc; | 782 | sizeof(struct e820entry) * nr_desc; |
642 | 783 | ||
643 | if (*e820ext) { | 784 | if (*e820ext) { |
644 | efi_call_phys1(sys_table->boottime->free_pool, *e820ext); | 785 | efi_early->call(efi_early->free_pool, *e820ext); |
645 | *e820ext = NULL; | 786 | *e820ext = NULL; |
646 | *e820ext_size = 0; | 787 | *e820ext_size = 0; |
647 | } | 788 | } |
648 | 789 | ||
649 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 790 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
650 | EFI_LOADER_DATA, size, e820ext); | 791 | size, (void **)e820ext); |
651 | |||
652 | if (status == EFI_SUCCESS) | 792 | if (status == EFI_SUCCESS) |
653 | *e820ext_size = size; | 793 | *e820ext_size = size; |
654 | 794 | ||
@@ -691,7 +831,7 @@ get_map: | |||
691 | if (status != EFI_SUCCESS) | 831 | if (status != EFI_SUCCESS) |
692 | goto free_mem_map; | 832 | goto free_mem_map; |
693 | 833 | ||
694 | efi_call_phys1(sys_table->boottime->free_pool, mem_map); | 834 | efi_early->call(efi_early->free_pool, mem_map); |
695 | goto get_map; /* Allocated memory, get map again */ | 835 | goto get_map; /* Allocated memory, get map again */ |
696 | } | 836 | } |
697 | 837 | ||
@@ -708,8 +848,7 @@ get_map: | |||
708 | #endif | 848 | #endif |
709 | 849 | ||
710 | /* Might as well exit boot services now */ | 850 | /* Might as well exit boot services now */ |
711 | status = efi_call_phys2(sys_table->boottime->exit_boot_services, | 851 | status = efi_early->call(efi_early->exit_boot_services, handle, key); |
712 | handle, key); | ||
713 | if (status != EFI_SUCCESS) { | 852 | if (status != EFI_SUCCESS) { |
714 | /* | 853 | /* |
715 | * ExitBootServices() will fail if any of the event | 854 | * ExitBootServices() will fail if any of the event |
@@ -722,7 +861,7 @@ get_map: | |||
722 | goto free_mem_map; | 861 | goto free_mem_map; |
723 | 862 | ||
724 | called_exit = true; | 863 | called_exit = true; |
725 | efi_call_phys1(sys_table->boottime->free_pool, mem_map); | 864 | efi_early->call(efi_early->free_pool, mem_map); |
726 | goto get_map; | 865 | goto get_map; |
727 | } | 866 | } |
728 | 867 | ||
@@ -736,23 +875,31 @@ get_map: | |||
736 | return EFI_SUCCESS; | 875 | return EFI_SUCCESS; |
737 | 876 | ||
738 | free_mem_map: | 877 | free_mem_map: |
739 | efi_call_phys1(sys_table->boottime->free_pool, mem_map); | 878 | efi_early->call(efi_early->free_pool, mem_map); |
740 | return status; | 879 | return status; |
741 | } | 880 | } |
742 | 881 | ||
743 | |||
744 | /* | 882 | /* |
745 | * On success we return a pointer to a boot_params structure, and NULL | 883 | * On success we return a pointer to a boot_params structure, and NULL |
746 | * on failure. | 884 | * on failure. |
747 | */ | 885 | */ |
748 | struct boot_params *efi_main(void *handle, efi_system_table_t *_table, | 886 | struct boot_params *efi_main(struct efi_config *c, |
749 | struct boot_params *boot_params) | 887 | struct boot_params *boot_params) |
750 | { | 888 | { |
751 | struct desc_ptr *gdt; | 889 | struct desc_ptr *gdt = NULL; |
752 | efi_loaded_image_t *image; | 890 | efi_loaded_image_t *image; |
753 | struct setup_header *hdr = &boot_params->hdr; | 891 | struct setup_header *hdr = &boot_params->hdr; |
754 | efi_status_t status; | 892 | efi_status_t status; |
755 | struct desc_struct *desc; | 893 | struct desc_struct *desc; |
894 | void *handle; | ||
895 | efi_system_table_t *_table; | ||
896 | bool is64; | ||
897 | |||
898 | efi_early = c; | ||
899 | |||
900 | _table = (efi_system_table_t *)(unsigned long)efi_early->table; | ||
901 | handle = (void *)(unsigned long)efi_early->image_handle; | ||
902 | is64 = efi_early->is64; | ||
756 | 903 | ||
757 | sys_table = _table; | 904 | sys_table = _table; |
758 | 905 | ||
@@ -760,13 +907,17 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table, | |||
760 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) | 907 | if (sys_table->hdr.signature != EFI_SYSTEM_TABLE_SIGNATURE) |
761 | goto fail; | 908 | goto fail; |
762 | 909 | ||
910 | if (is64) | ||
911 | setup_boot_services64(efi_early); | ||
912 | else | ||
913 | setup_boot_services32(efi_early); | ||
914 | |||
763 | setup_graphics(boot_params); | 915 | setup_graphics(boot_params); |
764 | 916 | ||
765 | setup_efi_pci(boot_params); | 917 | setup_efi_pci(boot_params); |
766 | 918 | ||
767 | status = efi_call_phys3(sys_table->boottime->allocate_pool, | 919 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
768 | EFI_LOADER_DATA, sizeof(*gdt), | 920 | sizeof(*gdt), (void **)&gdt); |
769 | (void **)&gdt); | ||
770 | if (status != EFI_SUCCESS) { | 921 | if (status != EFI_SUCCESS) { |
771 | efi_printk(sys_table, "Failed to alloc mem for gdt structure\n"); | 922 | efi_printk(sys_table, "Failed to alloc mem for gdt structure\n"); |
772 | goto fail; | 923 | goto fail; |
diff --git a/arch/x86/boot/compressed/eboot.h b/arch/x86/boot/compressed/eboot.h index d487e727f1ec..c88c31ecad12 100644 --- a/arch/x86/boot/compressed/eboot.h +++ b/arch/x86/boot/compressed/eboot.h | |||
@@ -103,4 +103,20 @@ struct efi_uga_draw_protocol { | |||
103 | void *blt; | 103 | void *blt; |
104 | }; | 104 | }; |
105 | 105 | ||
106 | struct 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 | |||
106 | #endif /* BOOT_COMPRESSED_EBOOT_H */ | 122 | #endif /* BOOT_COMPRESSED_EBOOT_H */ |
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S index 9116aac232c7..eed23c087d6c 100644 --- a/arch/x86/boot/compressed/head_32.S +++ b/arch/x86/boot/compressed/head_32.S | |||
@@ -42,26 +42,53 @@ ENTRY(startup_32) | |||
42 | ENTRY(efi_pe_entry) | 42 | ENTRY(efi_pe_entry) |
43 | add $0x4, %esp | 43 | add $0x4, %esp |
44 | 44 | ||
45 | call 1f | ||
46 | 1: 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 | ||
55 | ENTRY(efi_stub_entry) | 67 | ENTRY(efi_stub_entry) |
56 | add $0x4, %esp | 68 | add $0x4, %esp |
69 | popl %ecx | ||
70 | popl %edx | ||
71 | |||
72 | call 1f | ||
73 | 1: 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 | ||
83 | 2: | ||
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 |
61 | 1: | 88 | fail: |
62 | /* EFI init failed, so hang. */ | 89 | /* EFI init failed, so hang. */ |
63 | hlt | 90 | hlt |
64 | jmp 1b | 91 | jmp fail |
65 | 2: | 92 | 2: |
66 | call 3f | 93 | call 3f |
67 | 3: | 94 | 3: |
@@ -202,6 +229,13 @@ relocated: | |||
202 | xorl %ebx, %ebx | 229 | xorl %ebx, %ebx |
203 | jmp *%eax | 230 | jmp *%eax |
204 | 231 | ||
232 | .data | ||
233 | efi32_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..1bc206fa4bd0 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S | |||
@@ -209,26 +209,55 @@ ENTRY(startup_64) | |||
209 | jmp preferred_addr | 209 | jmp preferred_addr |
210 | 210 | ||
211 | ENTRY(efi_pe_entry) | 211 | ENTRY(efi_pe_entry) |
212 | mov %rcx, %rdi | 212 | movq %rcx, efi64_config(%rip) /* Handle */ |
213 | mov %rdx, %rsi | 213 | movq %rdx, efi64_config+8(%rip) /* EFI System table pointer */ |
214 | pushq %rdi | 214 | |
215 | pushq %rsi | 215 | leaq efi64_config(%rip), %rax |
216 | movq %rax, efi_config(%rip) | ||
217 | |||
218 | call 1f | ||
219 | 1: popq %rbp | ||
220 | subq $1b, %rbp | ||
221 | |||
222 | /* | ||
223 | * Relocate efi_config->call(). | ||
224 | */ | ||
225 | addq %rbp, efi64_config+88(%rip) | ||
226 | |||
227 | movq %rax, %rdi | ||
216 | call make_boot_params | 228 | call make_boot_params |
217 | cmpq $0,%rax | 229 | cmpq $0,%rax |
218 | je 1f | 230 | je fail |
219 | mov %rax, %rdx | 231 | mov %rax, %rsi |
220 | popq %rsi | 232 | jmp 2f /* Skip the relocation */ |
221 | popq %rdi | ||
222 | 233 | ||
223 | ENTRY(efi_stub_entry) | 234 | ENTRY(efi_stub_entry) |
235 | movq %rdi, efi64_config(%rip) /* Handle */ | ||
236 | movq %rsi, efi64_config+8(%rip) /* EFI System table pointer */ | ||
237 | |||
238 | leaq efi64_config(%rip), %rax | ||
239 | movq %rax, efi_config(%rip) | ||
240 | |||
241 | call 1f | ||
242 | 1: popq %rbp | ||
243 | subq $1b, %rbp | ||
244 | |||
245 | /* | ||
246 | * Relocate efi_config->call(). | ||
247 | */ | ||
248 | movq efi_config(%rip), %rax | ||
249 | addq %rbp, 88(%rax) | ||
250 | movq %rdx, %rsi | ||
251 | 2: | ||
252 | movq efi_config(%rip), %rdi | ||
224 | call efi_main | 253 | call efi_main |
225 | movq %rax,%rsi | 254 | movq %rax,%rsi |
226 | cmpq $0,%rax | 255 | cmpq $0,%rax |
227 | jne 2f | 256 | jne 2f |
228 | 1: | 257 | fail: |
229 | /* EFI init failed, so hang. */ | 258 | /* EFI init failed, so hang. */ |
230 | hlt | 259 | hlt |
231 | jmp 1b | 260 | jmp fail |
232 | 2: | 261 | 2: |
233 | call 3f | 262 | call 3f |
234 | 3: | 263 | 3: |
@@ -372,6 +401,14 @@ gdt: | |||
372 | .quad 0x0000000000000000 /* TS continued */ | 401 | .quad 0x0000000000000000 /* TS continued */ |
373 | gdt_end: | 402 | gdt_end: |
374 | 403 | ||
404 | efi_config: | ||
405 | .quad 0 | ||
406 | |||
407 | .global efi64_config | ||
408 | efi64_config: | ||
409 | .fill 11,8,0 | ||
410 | .quad efi_call6 | ||
411 | .byte 1 | ||
375 | /* | 412 | /* |
376 | * Stack and heap for uncompression | 413 | * Stack and heap for uncompression |
377 | */ | 414 | */ |
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c index b6bffbfd3be7..a0282872d97d 100644 --- a/drivers/firmware/efi/efi-stub-helper.c +++ b/drivers/firmware/efi/efi-stub-helper.c | |||
@@ -16,18 +16,6 @@ struct file_info { | |||
16 | u64 size; | 16 | u64 size; |
17 | }; | 17 | }; |
18 | 18 | ||
19 | |||
20 | |||
21 | |||
22 | static void efi_char16_printk(efi_system_table_t *sys_table_arg, | ||
23 | efi_char16_t *str) | ||
24 | { | ||
25 | struct efi_simple_text_output_protocol *out; | ||
26 | |||
27 | out = (struct efi_simple_text_output_protocol *)sys_table_arg->con_out; | ||
28 | efi_call_phys2(out->output_string, out, str); | ||
29 | } | ||
30 | |||
31 | static void efi_printk(efi_system_table_t *sys_table_arg, char *str) | 19 | static void efi_printk(efi_system_table_t *sys_table_arg, char *str) |
32 | { | 20 | { |
33 | char *s8; | 21 | char *s8; |
@@ -65,20 +53,23 @@ again: | |||
65 | * allocation which may be in a new descriptor region. | 53 | * allocation which may be in a new descriptor region. |
66 | */ | 54 | */ |
67 | *map_size += sizeof(*m); | 55 | *map_size += sizeof(*m); |
68 | status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, | 56 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
69 | EFI_LOADER_DATA, *map_size, (void **)&m); | 57 | *map_size, (void **)&m); |
70 | if (status != EFI_SUCCESS) | 58 | if (status != EFI_SUCCESS) |
71 | goto fail; | 59 | goto fail; |
72 | 60 | ||
73 | status = efi_call_phys5(sys_table_arg->boottime->get_memory_map, | 61 | *desc_size = 0; |
74 | map_size, m, &key, desc_size, &desc_version); | 62 | key = 0; |
63 | status = efi_early->call(efi_early->get_memory_map, map_size, m, | ||
64 | &key, desc_size, &desc_version); | ||
75 | if (status == EFI_BUFFER_TOO_SMALL) { | 65 | if (status == EFI_BUFFER_TOO_SMALL) { |
76 | efi_call_phys1(sys_table_arg->boottime->free_pool, m); | 66 | efi_early->call(efi_early->free_pool, m); |
77 | goto again; | 67 | goto again; |
78 | } | 68 | } |
79 | 69 | ||
80 | if (status != EFI_SUCCESS) | 70 | if (status != EFI_SUCCESS) |
81 | efi_call_phys1(sys_table_arg->boottime->free_pool, m); | 71 | efi_early->call(efi_early->free_pool, m); |
72 | |||
82 | if (key_ptr && status == EFI_SUCCESS) | 73 | if (key_ptr && status == EFI_SUCCESS) |
83 | *key_ptr = key; | 74 | *key_ptr = key; |
84 | if (desc_ver && status == EFI_SUCCESS) | 75 | if (desc_ver && status == EFI_SUCCESS) |
@@ -158,9 +149,9 @@ again: | |||
158 | if (!max_addr) | 149 | if (!max_addr) |
159 | status = EFI_NOT_FOUND; | 150 | status = EFI_NOT_FOUND; |
160 | else { | 151 | else { |
161 | status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, | 152 | status = efi_early->call(efi_early->allocate_pages, |
162 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | 153 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, |
163 | nr_pages, &max_addr); | 154 | nr_pages, &max_addr); |
164 | if (status != EFI_SUCCESS) { | 155 | if (status != EFI_SUCCESS) { |
165 | max = max_addr; | 156 | max = max_addr; |
166 | max_addr = 0; | 157 | max_addr = 0; |
@@ -170,8 +161,7 @@ again: | |||
170 | *addr = max_addr; | 161 | *addr = max_addr; |
171 | } | 162 | } |
172 | 163 | ||
173 | efi_call_phys1(sys_table_arg->boottime->free_pool, map); | 164 | efi_early->call(efi_early->free_pool, map); |
174 | |||
175 | fail: | 165 | fail: |
176 | return status; | 166 | return status; |
177 | } | 167 | } |
@@ -231,9 +221,9 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, | |||
231 | if ((start + size) > end) | 221 | if ((start + size) > end) |
232 | continue; | 222 | continue; |
233 | 223 | ||
234 | status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, | 224 | status = efi_early->call(efi_early->allocate_pages, |
235 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | 225 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, |
236 | nr_pages, &start); | 226 | nr_pages, &start); |
237 | if (status == EFI_SUCCESS) { | 227 | if (status == EFI_SUCCESS) { |
238 | *addr = start; | 228 | *addr = start; |
239 | break; | 229 | break; |
@@ -243,7 +233,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, | |||
243 | if (i == map_size / desc_size) | 233 | if (i == map_size / desc_size) |
244 | status = EFI_NOT_FOUND; | 234 | status = EFI_NOT_FOUND; |
245 | 235 | ||
246 | efi_call_phys1(sys_table_arg->boottime->free_pool, map); | 236 | efi_early->call(efi_early->free_pool, map); |
247 | fail: | 237 | fail: |
248 | return status; | 238 | return status; |
249 | } | 239 | } |
@@ -257,7 +247,7 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, | |||
257 | return; | 247 | return; |
258 | 248 | ||
259 | nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | 249 | nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; |
260 | efi_call_phys2(sys_table_arg->boottime->free_pages, addr, nr_pages); | 250 | efi_early->call(efi_early->free_pages, addr, nr_pages); |
261 | } | 251 | } |
262 | 252 | ||
263 | 253 | ||
@@ -276,9 +266,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
276 | { | 266 | { |
277 | struct file_info *files; | 267 | struct file_info *files; |
278 | unsigned long file_addr; | 268 | unsigned long file_addr; |
279 | efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; | ||
280 | u64 file_size_total; | 269 | u64 file_size_total; |
281 | efi_file_io_interface_t *io; | ||
282 | efi_file_handle_t *fh; | 270 | efi_file_handle_t *fh; |
283 | efi_status_t status; | 271 | efi_status_t status; |
284 | int nr_files; | 272 | int nr_files; |
@@ -319,10 +307,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
319 | if (!nr_files) | 307 | if (!nr_files) |
320 | return EFI_SUCCESS; | 308 | return EFI_SUCCESS; |
321 | 309 | ||
322 | status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, | 310 | status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA, |
323 | EFI_LOADER_DATA, | 311 | nr_files * sizeof(*files), (void **)&files); |
324 | nr_files * sizeof(*files), | ||
325 | (void **)&files); | ||
326 | if (status != EFI_SUCCESS) { | 312 | if (status != EFI_SUCCESS) { |
327 | efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n"); | 313 | efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n"); |
328 | goto fail; | 314 | goto fail; |
@@ -331,13 +317,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
331 | str = cmd_line; | 317 | str = cmd_line; |
332 | for (i = 0; i < nr_files; i++) { | 318 | for (i = 0; i < nr_files; i++) { |
333 | struct file_info *file; | 319 | struct file_info *file; |
334 | efi_file_handle_t *h; | ||
335 | efi_file_info_t *info; | ||
336 | efi_char16_t filename_16[256]; | 320 | efi_char16_t filename_16[256]; |
337 | unsigned long info_sz; | ||
338 | efi_guid_t info_guid = EFI_FILE_INFO_ID; | ||
339 | efi_char16_t *p; | 321 | efi_char16_t *p; |
340 | u64 file_sz; | ||
341 | 322 | ||
342 | str = strstr(str, option_string); | 323 | str = strstr(str, option_string); |
343 | if (!str) | 324 | if (!str) |
@@ -368,71 +349,18 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg, | |||
368 | 349 | ||
369 | /* Only open the volume once. */ | 350 | /* Only open the volume once. */ |
370 | if (!i) { | 351 | if (!i) { |
371 | efi_boot_services_t *boottime; | 352 | status = efi_open_volume(sys_table_arg, image, |
372 | 353 | (void **)&fh); | |
373 | boottime = sys_table_arg->boottime; | 354 | if (status != EFI_SUCCESS) |
374 | |||
375 | status = efi_call_phys3(boottime->handle_protocol, | ||
376 | image->device_handle, &fs_proto, | ||
377 | (void **)&io); | ||
378 | if (status != EFI_SUCCESS) { | ||
379 | efi_printk(sys_table_arg, "Failed to handle fs_proto\n"); | ||
380 | goto free_files; | ||
381 | } | ||
382 | |||
383 | status = efi_call_phys2(io->open_volume, io, &fh); | ||
384 | if (status != EFI_SUCCESS) { | ||
385 | efi_printk(sys_table_arg, "Failed to open volume\n"); | ||
386 | goto free_files; | 355 | goto free_files; |
387 | } | ||
388 | } | 356 | } |
389 | 357 | ||
390 | status = efi_call_phys5(fh->open, fh, &h, filename_16, | 358 | status = efi_file_size(sys_table_arg, fh, filename_16, |
391 | EFI_FILE_MODE_READ, (u64)0); | 359 | (void **)&file->handle, &file->size); |
392 | if (status != EFI_SUCCESS) { | 360 | if (status != EFI_SUCCESS) |
393 | efi_printk(sys_table_arg, "Failed to open file: "); | ||
394 | efi_char16_printk(sys_table_arg, filename_16); | ||
395 | efi_printk(sys_table_arg, "\n"); | ||
396 | goto close_handles; | 361 | goto close_handles; |
397 | } | ||
398 | 362 | ||
399 | file->handle = h; | 363 | file_size_total += file->size; |
400 | |||
401 | info_sz = 0; | ||
402 | status = efi_call_phys4(h->get_info, h, &info_guid, | ||
403 | &info_sz, NULL); | ||
404 | if (status != EFI_BUFFER_TOO_SMALL) { | ||
405 | efi_printk(sys_table_arg, "Failed to get file info size\n"); | ||
406 | goto close_handles; | ||
407 | } | ||
408 | |||
409 | grow: | ||
410 | status = efi_call_phys3(sys_table_arg->boottime->allocate_pool, | ||
411 | EFI_LOADER_DATA, info_sz, | ||
412 | (void **)&info); | ||
413 | if (status != EFI_SUCCESS) { | ||
414 | efi_printk(sys_table_arg, "Failed to alloc mem for file info\n"); | ||
415 | goto close_handles; | ||
416 | } | ||
417 | |||
418 | status = efi_call_phys4(h->get_info, h, &info_guid, | ||
419 | &info_sz, info); | ||
420 | if (status == EFI_BUFFER_TOO_SMALL) { | ||
421 | efi_call_phys1(sys_table_arg->boottime->free_pool, | ||
422 | info); | ||
423 | goto grow; | ||
424 | } | ||
425 | |||
426 | file_sz = info->file_size; | ||
427 | efi_call_phys1(sys_table_arg->boottime->free_pool, info); | ||
428 | |||
429 | if (status != EFI_SUCCESS) { | ||
430 | efi_printk(sys_table_arg, "Failed to get file info\n"); | ||
431 | goto close_handles; | ||
432 | } | ||
433 | |||
434 | file->size = file_sz; | ||
435 | file_size_total += file_sz; | ||
436 | } | 364 | } |
437 | 365 | ||
438 | if (file_size_total) { | 366 | if (file_size_total) { |
@@ -468,10 +396,10 @@ grow: | |||
468 | chunksize = EFI_READ_CHUNK_SIZE; | 396 | chunksize = EFI_READ_CHUNK_SIZE; |
469 | else | 397 | else |
470 | chunksize = size; | 398 | chunksize = size; |
471 | status = efi_call_phys3(fh->read, | 399 | |
472 | files[j].handle, | 400 | status = efi_file_read(fh, files[j].handle, |
473 | &chunksize, | 401 | &chunksize, |
474 | (void *)addr); | 402 | (void *)addr); |
475 | if (status != EFI_SUCCESS) { | 403 | if (status != EFI_SUCCESS) { |
476 | efi_printk(sys_table_arg, "Failed to read file\n"); | 404 | efi_printk(sys_table_arg, "Failed to read file\n"); |
477 | goto free_file_total; | 405 | goto free_file_total; |
@@ -480,12 +408,12 @@ grow: | |||
480 | size -= chunksize; | 408 | size -= chunksize; |
481 | } | 409 | } |
482 | 410 | ||
483 | efi_call_phys1(fh->close, files[j].handle); | 411 | efi_file_close(fh, files[j].handle); |
484 | } | 412 | } |
485 | 413 | ||
486 | } | 414 | } |
487 | 415 | ||
488 | efi_call_phys1(sys_table_arg->boottime->free_pool, files); | 416 | efi_early->call(efi_early->free_pool, files); |
489 | 417 | ||
490 | *load_addr = file_addr; | 418 | *load_addr = file_addr; |
491 | *load_size = file_size_total; | 419 | *load_size = file_size_total; |
@@ -497,9 +425,9 @@ free_file_total: | |||
497 | 425 | ||
498 | close_handles: | 426 | close_handles: |
499 | for (k = j; k < i; k++) | 427 | for (k = j; k < i; k++) |
500 | efi_call_phys1(fh->close, files[k].handle); | 428 | efi_file_close(fh, files[k].handle); |
501 | free_files: | 429 | free_files: |
502 | efi_call_phys1(sys_table_arg->boottime->free_pool, files); | 430 | efi_early->call(efi_early->free_pool, files); |
503 | fail: | 431 | fail: |
504 | *load_addr = 0; | 432 | *load_addr = 0; |
505 | *load_size = 0; | 433 | *load_size = 0; |
@@ -545,9 +473,9 @@ static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, | |||
545 | * as possible while respecting the required alignment. | 473 | * as possible while respecting the required alignment. |
546 | */ | 474 | */ |
547 | nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; | 475 | nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; |
548 | status = efi_call_phys4(sys_table_arg->boottime->allocate_pages, | 476 | status = efi_early->call(efi_early->allocate_pages, |
549 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, | 477 | EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, |
550 | nr_pages, &efi_addr); | 478 | nr_pages, &efi_addr); |
551 | new_addr = efi_addr; | 479 | new_addr = efi_addr; |
552 | /* | 480 | /* |
553 | * If preferred address allocation failed allocate as low as | 481 | * If preferred address allocation failed allocate as low as |