efi: Drop all uses of efi_call_XX() wrappers

Now that GCC can generate function calls using the correct calling
convention for us, we can stop using the efi_call_XX() wrappers, and
just dereference the function pointers directly.

This avoids the untyped variadic wrapper routines, which means better
type checking for the method calls.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Ard Biesheuvel authored and Daniel Kiper committed 2023-05-25 16:48:00 +02:00
1 parent 6a080b9cde
commit bb4aa6e06e
23 files changed
+165 -170

No files matched your search

+5 -5
View File
@@ -50,9 +50,9 @@ grub_machine_init (void)
b = grub_efi_system_table->boot_services;
efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
GRUB_EFI_TPL_CALLBACK, increment_timer, NULL, &tmr_evt);
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000);
b->create_event (GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
GRUB_EFI_TPL_CALLBACK, increment_timer, NULL, &tmr_evt);
b->set_timer (tmr_evt, GRUB_EFI_TIMER_PERIODIC, 100000);
grub_install_get_time_ms (grub_efi_get_time_ms);
}
@@ -67,8 +67,8 @@ grub_machine_fini (int flags)
b = grub_efi_system_table->boot_services;
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
efi_call_1 (b->close_event, tmr_evt);
b->set_timer (tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
b->close_event (tmr_evt);
grub_efi_fini ();
+29 -27
View File
@@ -45,8 +45,9 @@ grub_efi_locate_protocol (grub_efi_guid_t *protocol, void *registration)
void *interface;
grub_efi_status_t status;
status = efi_call_3 (grub_efi_system_table->boot_services->locate_protocol,
protocol, registration, &interface);
status = grub_efi_system_table->boot_services->locate_protocol (protocol,
registration,
&interface);
if (status != GRUB_EFI_SUCCESS)
return 0;
@@ -72,7 +73,7 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
return 0;
b = grub_efi_system_table->boot_services;
status = efi_call_5 (b->locate_handle, search_type, protocol, search_key,
status = b->locate_handle (search_type, protocol, search_key,
&buffer_size, buffer);
if (status == GRUB_EFI_BUFFER_TOO_SMALL)
{
@@ -81,7 +82,7 @@ grub_efi_locate_handle (grub_efi_locate_search_type_t search_type,
if (! buffer)
return 0;
status = efi_call_5 (b->locate_handle, search_type, protocol, search_key,
status = b->locate_handle (search_type, protocol, search_key,
&buffer_size, buffer);
}
@@ -105,12 +106,12 @@ grub_efi_open_protocol (grub_efi_handle_t handle,
void *interface;
b = grub_efi_system_table->boot_services;
status = efi_call_6 (b->open_protocol, handle,
protocol,
&interface,
grub_efi_image_handle,
0,
attributes);
status = b->open_protocol (handle,
protocol,
&interface,
grub_efi_image_handle,
0,
attributes);
if (status != GRUB_EFI_SUCCESS)
return 0;
@@ -122,7 +123,7 @@ grub_efi_close_protocol (grub_efi_handle_t handle, grub_efi_guid_t *protocol)
{
grub_efi_boot_services_t *b = grub_efi_system_table->boot_services;
return efi_call_4 (b->close_protocol, handle, protocol, grub_efi_image_handle, NULL);
return b->close_protocol (handle, protocol, grub_efi_image_handle, NULL);
}
int
@@ -137,12 +138,12 @@ grub_efi_set_text_mode (int on)
already in text mode. */
return 1;
if (efi_call_4 (c->get_mode, c, &mode, 0, 0) != GRUB_EFI_SUCCESS)
if (c->get_mode (c, &mode, 0, 0) != GRUB_EFI_SUCCESS)
return 0;
new_mode = on ? GRUB_EFI_SCREEN_TEXT : GRUB_EFI_SCREEN_GRAPHICS;
if (mode != new_mode)
if (efi_call_2 (c->set_mode, c, new_mode) != GRUB_EFI_SUCCESS)
if (c->set_mode (c, new_mode) != GRUB_EFI_SUCCESS)
return 0;
return 1;
@@ -151,7 +152,7 @@ grub_efi_set_text_mode (int on)
void
grub_efi_stall (grub_efi_uintn_t microseconds)
{
efi_call_1 (grub_efi_system_table->boot_services->stall, microseconds);
grub_efi_system_table->boot_services->stall (microseconds);
}
grub_efi_loaded_image_t *
@@ -167,8 +168,9 @@ grub_reboot (void)
{
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN |
GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY);
efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
GRUB_EFI_RESET_COLD, GRUB_EFI_SUCCESS, 0, NULL);
grub_efi_system_table->runtime_services->reset_system (GRUB_EFI_RESET_COLD,
GRUB_EFI_SUCCESS, 0,
NULL);
for (;;) ;
}
@@ -176,8 +178,8 @@ void
grub_exit (void)
{
grub_machine_fini (GRUB_LOADER_FLAG_NORETURN);
efi_call_4 (grub_efi_system_table->boot_services->exit,
grub_efi_image_handle, GRUB_EFI_SUCCESS, 0, 0);
grub_efi_system_table->boot_services->exit (grub_efi_image_handle,
GRUB_EFI_SUCCESS, 0, 0);
for (;;) ;
}
@@ -191,8 +193,8 @@ grub_efi_set_virtual_address_map (grub_efi_uintn_t memory_map_size,
grub_efi_status_t status;
r = grub_efi_system_table->runtime_services;
status = efi_call_4 (r->set_virtual_address_map, memory_map_size,
descriptor_size, descriptor_version, virtual_map);
status = r->set_virtual_address_map (memory_map_size, descriptor_size,
descriptor_version, virtual_map);
if (status == GRUB_EFI_SUCCESS)
return GRUB_ERR_NONE;
@@ -219,11 +221,11 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid,
r = grub_efi_system_table->runtime_services;
status = efi_call_5 (r->set_variable, var16, guid,
(GRUB_EFI_VARIABLE_NON_VOLATILE
| GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
| GRUB_EFI_VARIABLE_RUNTIME_ACCESS),
datasize, data);
status = r->set_variable (var16, guid,
(GRUB_EFI_VARIABLE_NON_VOLATILE
| GRUB_EFI_VARIABLE_BOOTSERVICE_ACCESS
| GRUB_EFI_VARIABLE_RUNTIME_ACCESS),
datasize, data);
grub_free (var16);
if (status == GRUB_EFI_SUCCESS)
return GRUB_ERR_NONE;
@@ -258,7 +260,7 @@ grub_efi_get_variable_with_attributes (const char *var,
r = grub_efi_system_table->runtime_services;
status = efi_call_5 (r->get_variable, var16, guid, NULL, &datasize, NULL);
status = r->get_variable (var16, guid, NULL, &datasize, NULL);
if (status != GRUB_EFI_BUFFER_TOO_SMALL || !datasize)
{
@@ -273,7 +275,7 @@ grub_efi_get_variable_with_attributes (const char *var,
return GRUB_EFI_OUT_OF_RESOURCES;
}
status = efi_call_5 (r->get_variable, var16, guid, attributes, &datasize, data);
status = r->get_variable (var16, guid, attributes, &datasize, data);
grub_free (var16);
if (status == GRUB_EFI_SUCCESS)
+7 -8
View File
@@ -56,11 +56,11 @@ __stack_chk_fail (void)
* the serial console, at least on EDK2.
*/
o = grub_efi_system_table->con_out;
efi_call_2 (o->output_string, o, stack_chk_fail_msg);
o->output_string (o, stack_chk_fail_msg);
efi_call_1 (grub_efi_system_table->boot_services->stall, 5000000);
efi_call_4 (grub_efi_system_table->runtime_services->reset_system,
GRUB_EFI_RESET_SHUTDOWN, GRUB_EFI_ABORTED, 0, NULL);
grub_efi_system_table->boot_services->stall (5000000);
grub_efi_system_table->runtime_services->reset_system (GRUB_EFI_RESET_SHUTDOWN,
GRUB_EFI_ABORTED, 0, NULL);
/*
* We shouldn't get here. It's unsafe to return because the stack
@@ -86,8 +86,8 @@ stack_protector_init (void)
{
grub_efi_status_t status;
status = efi_call_4 (rng->get_rng, rng, NULL, sizeof (stack_chk_guard_buf),
stack_chk_guard_buf);
status = rng->get_rng (rng, NULL, sizeof (stack_chk_guard_buf),
stack_chk_guard_buf);
if (status == GRUB_EFI_SUCCESS)
grub_memcpy (&__stack_chk_guard, stack_chk_guard_buf, sizeof (__stack_chk_guard));
}
@@ -124,8 +124,7 @@ grub_efi_init (void)
grub_shim_lock_verifier_setup ();
}
efi_call_4 (grub_efi_system_table->boot_services->set_watchdog_timer,
0, 0, 0, NULL);
grub_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL);
grub_efidisk_init ();
}
+8 -9
View File
@@ -69,8 +69,8 @@ grub_efi_store_alloc (grub_efi_physical_address_t address,
grub_efi_status_t status;
b = grub_efi_system_table->boot_services;
status = efi_call_3 (b->allocate_pool, GRUB_EFI_LOADER_DATA,
sizeof(*alloc), (void**)&alloc);
status = b->allocate_pool (GRUB_EFI_LOADER_DATA,
sizeof(*alloc), (void**)&alloc);
if (status == GRUB_EFI_SUCCESS)
{
@@ -105,7 +105,7 @@ grub_efi_drop_alloc (grub_efi_physical_address_t address,
efi_allocated_memory = ea->next;
/* Then free the memory backing it. */
efi_call_1 (b->free_pool, ea);
b->free_pool (ea);
/* And leave, we're done. */
break;
@@ -137,7 +137,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
}
b = grub_efi_system_table->boot_services;
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
status = b->allocate_pages (alloctype, memtype, pages, &address);
if (status != GRUB_EFI_SUCCESS)
{
grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
@@ -149,7 +149,7 @@ grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
/* Uggh, the address 0 was allocated... This is too annoying,
so reallocate another one. */
address = GRUB_EFI_MAX_USABLE_ADDRESS;
status = efi_call_4 (b->allocate_pages, alloctype, memtype, pages, &address);
status = b->allocate_pages (alloctype, memtype, pages, &address);
grub_efi_free_pages (0, pages);
if (status != GRUB_EFI_SUCCESS)
{
@@ -188,7 +188,7 @@ grub_efi_free_pages (grub_efi_physical_address_t address,
grub_efi_boot_services_t *b;
b = grub_efi_system_table->boot_services;
efi_call_2 (b->free_pages, address, pages);
b->free_pages (address, pages);
grub_efi_drop_alloc (address, pages);
}
@@ -267,8 +267,7 @@ grub_efi_finish_boot_services (grub_efi_uintn_t *outbuf_size, void *outbuf,
}
b = grub_efi_system_table->boot_services;
status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle,
finish_key);
status = b->exit_boot_services (grub_efi_image_handle, finish_key);
if (status == GRUB_EFI_SUCCESS)
break;
@@ -381,7 +380,7 @@ grub_efi_get_memory_map (grub_efi_uintn_t *memory_map_size,
descriptor_size = &size;
b = grub_efi_system_table->boot_services;
status = efi_call_5 (b->get_memory_map, memory_map_size, memory_map, map_key,
status = b->get_memory_map (memory_map_size, memory_map, map_key,
descriptor_size, descriptor_version);
if (*descriptor_size == 0)
*descriptor_size = sizeof (grub_efi_memory_descriptor_t);
+1 -1
View File
@@ -33,7 +33,7 @@ grub_tsc_calibrate_from_efi (void)
grub_uint64_t start_tsc, end_tsc;
/* Use EFI Time Service to calibrate TSC */
start_tsc = grub_get_tsc ();
efi_call_1 (grub_efi_system_table->boot_services->stall, 1000);
grub_efi_system_table->boot_services->stall (1000);
end_tsc = grub_get_tsc ();
grub_tsc_rate = grub_divmod64 ((1ULL << 32), end_tsc - start_tsc, 0);
return 1;
+7 -7
View File
@@ -51,16 +51,16 @@ grub_machine_init (void)
grub_efi_uintn_t idx;
grub_efi_init ();
efi_call_5 (grub_efi_system_table->boot_services->create_event,
GRUB_EFI_EVT_TIMER, GRUB_EFI_TPL_CALLBACK, 0, 0, &event);
grub_efi_system_table->boot_services->create_event (GRUB_EFI_EVT_TIMER,
GRUB_EFI_TPL_CALLBACK,
0, 0, &event);
before = get_itc ();
efi_call_3 (grub_efi_system_table->boot_services->set_timer, event,
GRUB_EFI_TIMER_RELATIVE, 200000);
efi_call_3 (grub_efi_system_table->boot_services->wait_for_event, 1,
&event, &idx);
grub_efi_system_table->boot_services->set_timer (event, GRUB_EFI_TIMER_RELATIVE,
200000);
grub_efi_system_table->boot_services->wait_for_event (1, &event, &idx);
after = get_itc ();
efi_call_1 (grub_efi_system_table->boot_services->close_event, event);
grub_efi_system_table->boot_services->close_event (event);
divisor = (after - before + 5) / 20;
if (divisor == 0)
divisor = 800000;
+5 -5
View File
@@ -50,9 +50,9 @@ grub_machine_init (void)
grub_efi_init ();
b = grub_efi_system_table->boot_services;
efi_call_5 (b->create_event, GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
GRUB_EFI_TPL_CALLBACK, grub_loongson_increment_timer, NULL, &tmr_evt);
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_PERIODIC, EFI_TIMER_PERIOD_MILLISECONDS(10));
b->create_event (GRUB_EFI_EVT_TIMER | GRUB_EFI_EVT_NOTIFY_SIGNAL,
GRUB_EFI_TPL_CALLBACK, grub_loongson_increment_timer, NULL, &tmr_evt);
b->set_timer (tmr_evt, GRUB_EFI_TIMER_PERIODIC, EFI_TIMER_PERIOD_MILLISECONDS(10));
grub_install_get_time_ms (grub_efi_get_time_ms);
}
@@ -67,8 +67,8 @@ grub_machine_fini (int flags)
b = grub_efi_system_table->boot_services;
efi_call_3 (b->set_timer, tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
efi_call_1 (b->close_event, tmr_evt);
b->set_timer (tmr_evt, GRUB_EFI_TIMER_CANCEL, 0);
b->close_event (tmr_evt);
grub_efi_fini ();