aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firmware/efi
diff options
context:
space:
mode:
authorRoy Franz <roy.franz@linaro.org>2013-09-22 18:45:28 -0400
committerMatt Fleming <matt.fleming@intel.com>2013-09-25 07:34:35 -0400
commit876dc36aceb1682cb01426f507f369aec4f68c76 (patch)
tree6c53f373b8e39a2c4b50a1a1c24a1aaed205c6c8 /drivers/firmware/efi
parent7721da4c1ebf96ff815987011c1a0edef596b50a (diff)
efi: Add system table pointer argument to shared functions.
Add system table pointer argument to shared EFI stub related functions so they no longer use a global system table pointer as they did when part of eboot.c. For the ARM EFI stub this allows us to avoid global variables completely and thereby not have to deal with GOT fixups. Not having the EFI stub fixup its GOT, which is shared with the decompressor, simplifies the relocating of the zImage to a bootable address. Signed-off-by: Roy Franz <roy.franz@linaro.org> Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'drivers/firmware/efi')
-rw-r--r--drivers/firmware/efi/efi-stub-helper.c96
1 files changed, 52 insertions, 44 deletions
diff --git a/drivers/firmware/efi/efi-stub-helper.c b/drivers/firmware/efi/efi-stub-helper.c
index 8a83387fef92..05c539e9a3c8 100644
--- a/drivers/firmware/efi/efi-stub-helper.c
+++ b/drivers/firmware/efi/efi-stub-helper.c
@@ -19,15 +19,16 @@ struct initrd {
19 19
20 20
21 21
22static void efi_char16_printk(efi_char16_t *str) 22static void efi_char16_printk(efi_system_table_t *sys_table_arg,
23 efi_char16_t *str)
23{ 24{
24 struct efi_simple_text_output_protocol *out; 25 struct efi_simple_text_output_protocol *out;
25 26
26 out = (struct efi_simple_text_output_protocol *)sys_table->con_out; 27 out = (struct efi_simple_text_output_protocol *)sys_table_arg->con_out;
27 efi_call_phys2(out->output_string, out, str); 28 efi_call_phys2(out->output_string, out, str);
28} 29}
29 30
30static void efi_printk(char *str) 31static void efi_printk(efi_system_table_t *sys_table_arg, char *str)
31{ 32{
32 char *s8; 33 char *s8;
33 34
@@ -37,15 +38,17 @@ static void efi_printk(char *str)
37 ch[0] = *s8; 38 ch[0] = *s8;
38 if (*s8 == '\n') { 39 if (*s8 == '\n') {
39 efi_char16_t nl[2] = { '\r', 0 }; 40 efi_char16_t nl[2] = { '\r', 0 };
40 efi_char16_printk(nl); 41 efi_char16_printk(sys_table_arg, nl);
41 } 42 }
42 43
43 efi_char16_printk(ch); 44 efi_char16_printk(sys_table_arg, ch);
44 } 45 }
45} 46}
46 47
47 48
48static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size, 49static efi_status_t __get_map(efi_system_table_t *sys_table_arg,
50 efi_memory_desc_t **map,
51 unsigned long *map_size,
49 unsigned long *desc_size) 52 unsigned long *desc_size)
50{ 53{
51 efi_memory_desc_t *m = NULL; 54 efi_memory_desc_t *m = NULL;
@@ -60,20 +63,20 @@ again:
60 * allocation which may be in a new descriptor region. 63 * allocation which may be in a new descriptor region.
61 */ 64 */
62 *map_size += sizeof(*m); 65 *map_size += sizeof(*m);
63 status = efi_call_phys3(sys_table->boottime->allocate_pool, 66 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
64 EFI_LOADER_DATA, *map_size, (void **)&m); 67 EFI_LOADER_DATA, *map_size, (void **)&m);
65 if (status != EFI_SUCCESS) 68 if (status != EFI_SUCCESS)
66 goto fail; 69 goto fail;
67 70
68 status = efi_call_phys5(sys_table->boottime->get_memory_map, map_size, 71 status = efi_call_phys5(sys_table_arg->boottime->get_memory_map,
69 m, &key, desc_size, &desc_version); 72 map_size, m, &key, desc_size, &desc_version);
70 if (status == EFI_BUFFER_TOO_SMALL) { 73 if (status == EFI_BUFFER_TOO_SMALL) {
71 efi_call_phys1(sys_table->boottime->free_pool, m); 74 efi_call_phys1(sys_table_arg->boottime->free_pool, m);
72 goto again; 75 goto again;
73 } 76 }
74 77
75 if (status != EFI_SUCCESS) 78 if (status != EFI_SUCCESS)
76 efi_call_phys1(sys_table->boottime->free_pool, m); 79 efi_call_phys1(sys_table_arg->boottime->free_pool, m);
77 80
78fail: 81fail:
79 *map = m; 82 *map = m;
@@ -83,8 +86,9 @@ fail:
83/* 86/*
84 * Allocate at the highest possible address that is not above 'max'. 87 * Allocate at the highest possible address that is not above 'max'.
85 */ 88 */
86static efi_status_t high_alloc(unsigned long size, unsigned long align, 89static efi_status_t high_alloc(efi_system_table_t *sys_table_arg,
87 unsigned long *addr, unsigned long max) 90 unsigned long size, unsigned long align,
91 unsigned long *addr, unsigned long max)
88{ 92{
89 unsigned long map_size, desc_size; 93 unsigned long map_size, desc_size;
90 efi_memory_desc_t *map; 94 efi_memory_desc_t *map;
@@ -93,7 +97,7 @@ static efi_status_t high_alloc(unsigned long size, unsigned long align,
93 u64 max_addr = 0; 97 u64 max_addr = 0;
94 int i; 98 int i;
95 99
96 status = __get_map(&map, &map_size, &desc_size); 100 status = __get_map(sys_table_arg, &map, &map_size, &desc_size);
97 if (status != EFI_SUCCESS) 101 if (status != EFI_SUCCESS)
98 goto fail; 102 goto fail;
99 103
@@ -139,7 +143,7 @@ again:
139 if (!max_addr) 143 if (!max_addr)
140 status = EFI_NOT_FOUND; 144 status = EFI_NOT_FOUND;
141 else { 145 else {
142 status = efi_call_phys4(sys_table->boottime->allocate_pages, 146 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages,
143 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 147 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
144 nr_pages, &max_addr); 148 nr_pages, &max_addr);
145 if (status != EFI_SUCCESS) { 149 if (status != EFI_SUCCESS) {
@@ -152,7 +156,7 @@ again:
152 } 156 }
153 157
154free_pool: 158free_pool:
155 efi_call_phys1(sys_table->boottime->free_pool, map); 159 efi_call_phys1(sys_table_arg->boottime->free_pool, map);
156 160
157fail: 161fail:
158 return status; 162 return status;
@@ -161,7 +165,8 @@ fail:
161/* 165/*
162 * Allocate at the lowest possible address. 166 * Allocate at the lowest possible address.
163 */ 167 */
164static efi_status_t low_alloc(unsigned long size, unsigned long align, 168static efi_status_t low_alloc(efi_system_table_t *sys_table_arg,
169 unsigned long size, unsigned long align,
165 unsigned long *addr) 170 unsigned long *addr)
166{ 171{
167 unsigned long map_size, desc_size; 172 unsigned long map_size, desc_size;
@@ -170,7 +175,7 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
170 unsigned long nr_pages; 175 unsigned long nr_pages;
171 int i; 176 int i;
172 177
173 status = __get_map(&map, &map_size, &desc_size); 178 status = __get_map(sys_table_arg, &map, &map_size, &desc_size);
174 if (status != EFI_SUCCESS) 179 if (status != EFI_SUCCESS)
175 goto fail; 180 goto fail;
176 181
@@ -203,7 +208,7 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
203 if ((start + size) > end) 208 if ((start + size) > end)
204 continue; 209 continue;
205 210
206 status = efi_call_phys4(sys_table->boottime->allocate_pages, 211 status = efi_call_phys4(sys_table_arg->boottime->allocate_pages,
207 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, 212 EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
208 nr_pages, &start); 213 nr_pages, &start);
209 if (status == EFI_SUCCESS) { 214 if (status == EFI_SUCCESS) {
@@ -216,17 +221,18 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
216 status = EFI_NOT_FOUND; 221 status = EFI_NOT_FOUND;
217 222
218free_pool: 223free_pool:
219 efi_call_phys1(sys_table->boottime->free_pool, map); 224 efi_call_phys1(sys_table_arg->boottime->free_pool, map);
220fail: 225fail:
221 return status; 226 return status;
222} 227}
223 228
224static void low_free(unsigned long size, unsigned long addr) 229static void low_free(efi_system_table_t *sys_table_arg, unsigned long size,
230 unsigned long addr)
225{ 231{
226 unsigned long nr_pages; 232 unsigned long nr_pages;
227 233
228 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; 234 nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
229 efi_call_phys2(sys_table->boottime->free_pages, addr, nr_pages); 235 efi_call_phys2(sys_table_arg->boottime->free_pages, addr, nr_pages);
230} 236}
231 237
232 238
@@ -236,7 +242,8 @@ static void low_free(unsigned long size, unsigned long addr)
236 * We only support loading an initrd from the same filesystem as the 242 * We only support loading an initrd from the same filesystem as the
237 * kernel image. 243 * kernel image.
238 */ 244 */
239static efi_status_t handle_ramdisks(efi_loaded_image_t *image, 245static efi_status_t handle_ramdisks(efi_system_table_t *sys_table_arg,
246 efi_loaded_image_t *image,
240 struct setup_header *hdr) 247 struct setup_header *hdr)
241{ 248{
242 struct initrd *initrds; 249 struct initrd *initrds;
@@ -278,12 +285,12 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
278 if (!nr_initrds) 285 if (!nr_initrds)
279 return EFI_SUCCESS; 286 return EFI_SUCCESS;
280 287
281 status = efi_call_phys3(sys_table->boottime->allocate_pool, 288 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
282 EFI_LOADER_DATA, 289 EFI_LOADER_DATA,
283 nr_initrds * sizeof(*initrds), 290 nr_initrds * sizeof(*initrds),
284 &initrds); 291 &initrds);
285 if (status != EFI_SUCCESS) { 292 if (status != EFI_SUCCESS) {
286 efi_printk("Failed to alloc mem for initrds\n"); 293 efi_printk(sys_table_arg, "Failed to alloc mem for initrds\n");
287 goto fail; 294 goto fail;
288 } 295 }
289 296
@@ -329,18 +336,18 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
329 if (!i) { 336 if (!i) {
330 efi_boot_services_t *boottime; 337 efi_boot_services_t *boottime;
331 338
332 boottime = sys_table->boottime; 339 boottime = sys_table_arg->boottime;
333 340
334 status = efi_call_phys3(boottime->handle_protocol, 341 status = efi_call_phys3(boottime->handle_protocol,
335 image->device_handle, &fs_proto, &io); 342 image->device_handle, &fs_proto, &io);
336 if (status != EFI_SUCCESS) { 343 if (status != EFI_SUCCESS) {
337 efi_printk("Failed to handle fs_proto\n"); 344 efi_printk(sys_table_arg, "Failed to handle fs_proto\n");
338 goto free_initrds; 345 goto free_initrds;
339 } 346 }
340 347
341 status = efi_call_phys2(io->open_volume, io, &fh); 348 status = efi_call_phys2(io->open_volume, io, &fh);
342 if (status != EFI_SUCCESS) { 349 if (status != EFI_SUCCESS) {
343 efi_printk("Failed to open volume\n"); 350 efi_printk(sys_table_arg, "Failed to open volume\n");
344 goto free_initrds; 351 goto free_initrds;
345 } 352 }
346 } 353 }
@@ -348,9 +355,9 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
348 status = efi_call_phys5(fh->open, fh, &h, filename_16, 355 status = efi_call_phys5(fh->open, fh, &h, filename_16,
349 EFI_FILE_MODE_READ, (u64)0); 356 EFI_FILE_MODE_READ, (u64)0);
350 if (status != EFI_SUCCESS) { 357 if (status != EFI_SUCCESS) {
351 efi_printk("Failed to open initrd file: "); 358 efi_printk(sys_table_arg, "Failed to open initrd file: ");
352 efi_char16_printk(filename_16); 359 efi_char16_printk(sys_table_arg, filename_16);
353 efi_printk("\n"); 360 efi_printk(sys_table_arg, "\n");
354 goto close_handles; 361 goto close_handles;
355 } 362 }
356 363
@@ -360,30 +367,31 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
360 status = efi_call_phys4(h->get_info, h, &info_guid, 367 status = efi_call_phys4(h->get_info, h, &info_guid,
361 &info_sz, NULL); 368 &info_sz, NULL);
362 if (status != EFI_BUFFER_TOO_SMALL) { 369 if (status != EFI_BUFFER_TOO_SMALL) {
363 efi_printk("Failed to get initrd info size\n"); 370 efi_printk(sys_table_arg, "Failed to get initrd info size\n");
364 goto close_handles; 371 goto close_handles;
365 } 372 }
366 373
367grow: 374grow:
368 status = efi_call_phys3(sys_table->boottime->allocate_pool, 375 status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
369 EFI_LOADER_DATA, info_sz, &info); 376 EFI_LOADER_DATA, info_sz, &info);
370 if (status != EFI_SUCCESS) { 377 if (status != EFI_SUCCESS) {
371 efi_printk("Failed to alloc mem for initrd info\n"); 378 efi_printk(sys_table_arg, "Failed to alloc mem for initrd info\n");
372 goto close_handles; 379 goto close_handles;
373 } 380 }
374 381
375 status = efi_call_phys4(h->get_info, h, &info_guid, 382 status = efi_call_phys4(h->get_info, h, &info_guid,
376 &info_sz, info); 383 &info_sz, info);
377 if (status == EFI_BUFFER_TOO_SMALL) { 384 if (status == EFI_BUFFER_TOO_SMALL) {
378 efi_call_phys1(sys_table->boottime->free_pool, info); 385 efi_call_phys1(sys_table_arg->boottime->free_pool,
386 info);
379 goto grow; 387 goto grow;
380 } 388 }
381 389
382 file_sz = info->file_size; 390 file_sz = info->file_size;
383 efi_call_phys1(sys_table->boottime->free_pool, info); 391 efi_call_phys1(sys_table_arg->boottime->free_pool, info);
384 392
385 if (status != EFI_SUCCESS) { 393 if (status != EFI_SUCCESS) {
386 efi_printk("Failed to get initrd info\n"); 394 efi_printk(sys_table_arg, "Failed to get initrd info\n");
387 goto close_handles; 395 goto close_handles;
388 } 396 }
389 397
@@ -399,16 +407,16 @@ grow:
399 * addresses in memory, so allocate enough memory for 407 * addresses in memory, so allocate enough memory for
400 * all the initrd's. 408 * all the initrd's.
401 */ 409 */
402 status = high_alloc(initrd_total, 0x1000, 410 status = high_alloc(sys_table_arg, initrd_total, 0x1000,
403 &initrd_addr, hdr->initrd_addr_max); 411 &initrd_addr, hdr->initrd_addr_max);
404 if (status != EFI_SUCCESS) { 412 if (status != EFI_SUCCESS) {
405 efi_printk("Failed to alloc highmem for initrds\n"); 413 efi_printk(sys_table_arg, "Failed to alloc highmem for initrds\n");
406 goto close_handles; 414 goto close_handles;
407 } 415 }
408 416
409 /* We've run out of free low memory. */ 417 /* We've run out of free low memory. */
410 if (initrd_addr > hdr->initrd_addr_max) { 418 if (initrd_addr > hdr->initrd_addr_max) {
411 efi_printk("We've run out of free low memory\n"); 419 efi_printk(sys_table_arg, "We've run out of free low memory\n");
412 status = EFI_INVALID_PARAMETER; 420 status = EFI_INVALID_PARAMETER;
413 goto free_initrd_total; 421 goto free_initrd_total;
414 } 422 }
@@ -428,7 +436,7 @@ grow:
428 initrds[j].handle, 436 initrds[j].handle,
429 &chunksize, addr); 437 &chunksize, addr);
430 if (status != EFI_SUCCESS) { 438 if (status != EFI_SUCCESS) {
431 efi_printk("Failed to read initrd\n"); 439 efi_printk(sys_table_arg, "Failed to read initrd\n");
432 goto free_initrd_total; 440 goto free_initrd_total;
433 } 441 }
434 addr += chunksize; 442 addr += chunksize;
@@ -440,7 +448,7 @@ grow:
440 448
441 } 449 }
442 450
443 efi_call_phys1(sys_table->boottime->free_pool, initrds); 451 efi_call_phys1(sys_table_arg->boottime->free_pool, initrds);
444 452
445 hdr->ramdisk_image = initrd_addr; 453 hdr->ramdisk_image = initrd_addr;
446 hdr->ramdisk_size = initrd_total; 454 hdr->ramdisk_size = initrd_total;
@@ -448,13 +456,13 @@ grow:
448 return status; 456 return status;
449 457
450free_initrd_total: 458free_initrd_total:
451 low_free(initrd_total, initrd_addr); 459 low_free(sys_table_arg, initrd_total, initrd_addr);
452 460
453close_handles: 461close_handles:
454 for (k = j; k < i; k++) 462 for (k = j; k < i; k++)
455 efi_call_phys1(fh->close, initrds[k].handle); 463 efi_call_phys1(fh->close, initrds[k].handle);
456free_initrds: 464free_initrds:
457 efi_call_phys1(sys_table->boottime->free_pool, initrds); 465 efi_call_phys1(sys_table_arg->boottime->free_pool, initrds);
458fail: 466fail:
459 hdr->ramdisk_image = 0; 467 hdr->ramdisk_image = 0;
460 hdr->ramdisk_size = 0; 468 hdr->ramdisk_size = 0;