efi_loader: eliminate handle member

A pointer to a struct efi_object is a handle. We do not need any handle
member in this structure. Let's eliminate it.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
This commit is contained in:
Heinrich Schuchardt 2018-09-26 05:27:55 +02:00 committed by Alexander Graf
parent faea104105
commit fae0118e7a
7 changed files with 68 additions and 61 deletions

View File

@ -167,20 +167,28 @@ struct efi_handler {
struct list_head open_infos; struct list_head open_infos;
}; };
/* /**
* UEFI has a poor man's OO model where one "object" can be polymorphic and have * struct efi_object - dereferenced EFI handle
* multiple different protocols (classes) attached to it.
* *
* This struct is the parent struct for all of our actual implementation objects * @link: pointers to put the handle into a linked list
* that can include it to make themselves an EFI object * @protocols: linked list with the protocol interfaces installed on this
* handle
*
* UEFI offers a flexible and expandable object model. The objects in the UEFI
* API are devices, drivers, and loaded images. struct efi_object is our storage
* structure for these objects.
*
* When including this structure into a larger structure always put it first so
* that when deleting a handle the whole encompassing structure can be freed.
*
* A pointer to this structure is referred to as a handle. Typedef efi_handle_t
* has been created for such pointers.
*/ */
struct efi_object { struct efi_object {
/* Every UEFI object is part of a global object list */ /* Every UEFI object is part of a global object list */
struct list_head link; struct list_head link;
/* The list of protocols */ /* The list of protocols */
struct list_head protocols; struct list_head protocols;
/* The object spawner can either use this for data or as identifier */
void *handle;
}; };
/** /**
@ -290,11 +298,11 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map);
/* Call this to set the current device name */ /* Call this to set the current device name */
void efi_set_bootdev(const char *dev, const char *devnr, const char *path); void efi_set_bootdev(const char *dev, const char *devnr, const char *path);
/* Add a new object to the object list. */ /* Add a new object to the object list. */
void efi_add_handle(struct efi_object *obj); void efi_add_handle(efi_handle_t obj);
/* Create handle */ /* Create handle */
efi_status_t efi_create_handle(efi_handle_t *handle); efi_status_t efi_create_handle(efi_handle_t *handle);
/* Delete handle */ /* Delete handle */
void efi_delete_handle(struct efi_object *obj); void efi_delete_handle(efi_handle_t obj);
/* Call this to validate a handle and find the EFI object for it */ /* Call this to validate a handle and find the EFI object for it */
struct efi_object *efi_search_obj(const efi_handle_t handle); struct efi_object *efi_search_obj(const efi_handle_t handle);
/* Find a protocol on a handle */ /* Find a protocol on a handle */

View File

@ -416,13 +416,12 @@ static efi_status_t EFIAPI efi_free_pool_ext(void *buffer)
* *
* The protocols list is initialized. The object handle is set. * The protocols list is initialized. The object handle is set.
*/ */
void efi_add_handle(struct efi_object *obj) void efi_add_handle(efi_handle_t handle)
{ {
if (!obj) if (!handle)
return; return;
INIT_LIST_HEAD(&obj->protocols); INIT_LIST_HEAD(&handle->protocols);
obj->handle = obj; list_add_tail(&handle->link, &efi_obj_list);
list_add_tail(&obj->link, &efi_obj_list);
} }
/** /**
@ -440,7 +439,7 @@ efi_status_t efi_create_handle(efi_handle_t *handle)
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
efi_add_handle(obj); efi_add_handle(obj);
*handle = obj->handle; *handle = obj;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -536,13 +535,13 @@ efi_status_t efi_remove_all_protocols(const efi_handle_t handle)
* *
* @obj: handle to delete * @obj: handle to delete
*/ */
void efi_delete_handle(struct efi_object *obj) void efi_delete_handle(efi_handle_t handle)
{ {
if (!obj) if (!handle)
return; return;
efi_remove_all_protocols(obj->handle); efi_remove_all_protocols(handle);
list_del(&obj->link); list_del(&handle->link);
free(obj); free(handle);
} }
/** /**
@ -927,7 +926,7 @@ struct efi_object *efi_search_obj(const efi_handle_t handle)
struct efi_object *efiobj; struct efi_object *efiobj;
list_for_each_entry(efiobj, &efi_obj_list, link) { list_for_each_entry(efiobj, &efi_obj_list, link) {
if (efiobj->handle == handle) if (efiobj == handle)
return efiobj; return efiobj;
} }
@ -1052,7 +1051,7 @@ out:
/** /**
* efi_get_drivers() - get all drivers associated to a controller * efi_get_drivers() - get all drivers associated to a controller
* @efiobj: handle of the controller * @handle: handle of the controller
* @protocol: protocol GUID (optional) * @protocol: protocol GUID (optional)
* @number_of_drivers: number of child controllers * @number_of_drivers: number of child controllers
* @driver_handle_buffer: handles of the the drivers * @driver_handle_buffer: handles of the the drivers
@ -1061,7 +1060,7 @@ out:
* *
* Return: status code * Return: status code
*/ */
static efi_status_t efi_get_drivers(struct efi_object *efiobj, static efi_status_t efi_get_drivers(efi_handle_t handle,
const efi_guid_t *protocol, const efi_guid_t *protocol,
efi_uintn_t *number_of_drivers, efi_uintn_t *number_of_drivers,
efi_handle_t **driver_handle_buffer) efi_handle_t **driver_handle_buffer)
@ -1072,7 +1071,7 @@ static efi_status_t efi_get_drivers(struct efi_object *efiobj,
bool duplicate; bool duplicate;
/* Count all driver associations */ /* Count all driver associations */
list_for_each_entry(handler, &efiobj->protocols, link) { list_for_each_entry(handler, &handle->protocols, link) {
if (protocol && guidcmp(handler->guid, protocol)) if (protocol && guidcmp(handler->guid, protocol))
continue; continue;
list_for_each_entry(item, &handler->open_infos, link) { list_for_each_entry(item, &handler->open_infos, link) {
@ -1090,7 +1089,7 @@ static efi_status_t efi_get_drivers(struct efi_object *efiobj,
if (!*driver_handle_buffer) if (!*driver_handle_buffer)
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
/* Collect unique driver handles */ /* Collect unique driver handles */
list_for_each_entry(handler, &efiobj->protocols, link) { list_for_each_entry(handler, &handle->protocols, link) {
if (protocol && guidcmp(handler->guid, protocol)) if (protocol && guidcmp(handler->guid, protocol))
continue; continue;
list_for_each_entry(item, &handler->open_infos, link) { list_for_each_entry(item, &handler->open_infos, link) {
@ -1117,7 +1116,7 @@ static efi_status_t efi_get_drivers(struct efi_object *efiobj,
/** /**
* efi_disconnect_all_drivers() - disconnect all drivers from a controller * efi_disconnect_all_drivers() - disconnect all drivers from a controller
* @efiobj: handle of the controller * @handle: handle of the controller
* @protocol: protocol GUID (optional) * @protocol: protocol GUID (optional)
* @child_handle: handle of the child to destroy * @child_handle: handle of the child to destroy
* *
@ -1128,16 +1127,16 @@ static efi_status_t efi_get_drivers(struct efi_object *efiobj,
* *
* Return: status code * Return: status code
*/ */
static efi_status_t efi_disconnect_all_drivers( static efi_status_t efi_disconnect_all_drivers
struct efi_object *efiobj, (efi_handle_t handle,
const efi_guid_t *protocol, const efi_guid_t *protocol,
efi_handle_t child_handle) efi_handle_t child_handle)
{ {
efi_uintn_t number_of_drivers; efi_uintn_t number_of_drivers;
efi_handle_t *driver_handle_buffer; efi_handle_t *driver_handle_buffer;
efi_status_t r, ret; efi_status_t r, ret;
ret = efi_get_drivers(efiobj, protocol, &number_of_drivers, ret = efi_get_drivers(handle, protocol, &number_of_drivers,
&driver_handle_buffer); &driver_handle_buffer);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
return ret; return ret;
@ -1145,7 +1144,7 @@ static efi_status_t efi_disconnect_all_drivers(
ret = EFI_NOT_FOUND; ret = EFI_NOT_FOUND;
while (number_of_drivers) { while (number_of_drivers) {
r = EFI_CALL(efi_disconnect_controller( r = EFI_CALL(efi_disconnect_controller(
efiobj->handle, handle,
driver_handle_buffer[--number_of_drivers], driver_handle_buffer[--number_of_drivers],
child_handle)); child_handle));
if (r == EFI_SUCCESS) if (r == EFI_SUCCESS)
@ -1270,7 +1269,7 @@ static efi_status_t EFIAPI efi_register_protocol_notify(
* @search_type: selection criterion * @search_type: selection criterion
* @protocol: GUID of the protocol * @protocol: GUID of the protocol
* @search_key: registration key * @search_key: registration key
* @efiobj: handle * @handle: handle
* *
* See the documentation of the LocateHandle service in the UEFI specification. * See the documentation of the LocateHandle service in the UEFI specification.
* *
@ -1278,7 +1277,7 @@ static efi_status_t EFIAPI efi_register_protocol_notify(
*/ */
static int efi_search(enum efi_locate_search_type search_type, static int efi_search(enum efi_locate_search_type search_type,
const efi_guid_t *protocol, void *search_key, const efi_guid_t *protocol, void *search_key,
struct efi_object *efiobj) efi_handle_t handle)
{ {
efi_status_t ret; efi_status_t ret;
@ -1289,7 +1288,7 @@ static int efi_search(enum efi_locate_search_type search_type,
/* TODO: RegisterProtocolNotify is not implemented yet */ /* TODO: RegisterProtocolNotify is not implemented yet */
return -1; return -1;
case BY_PROTOCOL: case BY_PROTOCOL:
ret = efi_search_protocol(efiobj->handle, protocol, NULL); ret = efi_search_protocol(handle, protocol, NULL);
return (ret != EFI_SUCCESS); return (ret != EFI_SUCCESS);
default: default:
/* Invalid search type */ /* Invalid search type */
@ -1361,7 +1360,7 @@ static efi_status_t efi_locate_handle(
/* Then fill the array */ /* Then fill the array */
list_for_each_entry(efiobj, &efi_obj_list, link) { list_for_each_entry(efiobj, &efi_obj_list, link) {
if (!efi_search(search_type, protocol, search_key, efiobj)) if (!efi_search(search_type, protocol, search_key, efiobj))
*buffer++ = efiobj->handle; *buffer++ = efiobj;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
@ -1536,7 +1535,7 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
* When asking for the device path interface, return * When asking for the device path interface, return
* bootefi_device_path * bootefi_device_path
*/ */
ret = efi_add_protocol(obj->parent.handle, ret = efi_add_protocol(&obj->parent,
&efi_guid_device_path, device_path); &efi_guid_device_path, device_path);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
goto failure; goto failure;
@ -1546,7 +1545,7 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path,
* When asking for the loaded_image interface, just * When asking for the loaded_image interface, just
* return handle which points to loaded_image_info * return handle which points to loaded_image_info
*/ */
ret = efi_add_protocol(obj->parent.handle, ret = efi_add_protocol(&obj->parent,
&efi_guid_loaded_image, info); &efi_guid_loaded_image, info);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
goto failure; goto failure;
@ -2206,7 +2205,7 @@ static efi_status_t EFIAPI efi_locate_protocol(const efi_guid_t *protocol,
efiobj = list_entry(lhandle, struct efi_object, link); efiobj = list_entry(lhandle, struct efi_object, link);
ret = efi_search_protocol(efiobj->handle, protocol, &handler); ret = efi_search_protocol(efiobj, protocol, &handler);
if (ret == EFI_SUCCESS) { if (ret == EFI_SUCCESS) {
*protocol_interface = handler->protocol_interface; *protocol_interface = handler->protocol_interface;
return EFI_EXIT(EFI_SUCCESS); return EFI_EXIT(EFI_SUCCESS);

View File

@ -1051,34 +1051,34 @@ static void EFIAPI efi_key_notify(struct efi_event *event, void *context)
efi_status_t efi_console_register(void) efi_status_t efi_console_register(void)
{ {
efi_status_t r; efi_status_t r;
struct efi_object *efi_console_output_obj; efi_handle_t console_output_handle;
struct efi_object *efi_console_input_obj; efi_handle_t console_input_handle;
/* Set up mode information */ /* Set up mode information */
query_console_size(); query_console_size();
/* Create handles */ /* Create handles */
r = efi_create_handle((efi_handle_t *)&efi_console_output_obj); r = efi_create_handle(&console_output_handle);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out_of_memory; goto out_of_memory;
r = efi_add_protocol(efi_console_output_obj->handle, r = efi_add_protocol(console_output_handle,
&efi_guid_text_output_protocol, &efi_con_out); &efi_guid_text_output_protocol, &efi_con_out);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out_of_memory; goto out_of_memory;
systab.con_out_handle = efi_console_output_obj->handle; systab.con_out_handle = console_output_handle;
systab.stderr_handle = efi_console_output_obj->handle; systab.stderr_handle = console_output_handle;
r = efi_create_handle((efi_handle_t *)&efi_console_input_obj); r = efi_create_handle(&console_input_handle);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out_of_memory; goto out_of_memory;
r = efi_add_protocol(efi_console_input_obj->handle, r = efi_add_protocol(console_input_handle,
&efi_guid_text_input_protocol, &efi_con_in); &efi_guid_text_input_protocol, &efi_con_in);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out_of_memory; goto out_of_memory;
systab.con_in_handle = efi_console_input_obj->handle; systab.con_in_handle = console_input_handle;
r = efi_add_protocol(efi_console_input_obj->handle, r = efi_add_protocol(console_input_handle,
&efi_guid_text_input_ex_protocol, &efi_con_in_ex); &efi_guid_text_input_ex_protocol, &efi_con_in_ex);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto out_of_memory; goto out_of_memory;

View File

@ -150,7 +150,7 @@ static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,
struct efi_device_path *obj_dp; struct efi_device_path *obj_dp;
efi_status_t ret; efi_status_t ret;
ret = efi_search_protocol(efiobj->handle, ret = efi_search_protocol(efiobj,
&efi_guid_device_path, &handler); &efi_guid_device_path, &handler);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
continue; continue;

View File

@ -258,18 +258,18 @@ static efi_status_t efi_disk_add_dev(
diskobj->dp = efi_dp_from_part(desc, part); diskobj->dp = efi_dp_from_part(desc, part);
} }
diskobj->part = part; diskobj->part = part;
ret = efi_add_protocol(diskobj->parent.handle, &efi_block_io_guid, ret = efi_add_protocol(&diskobj->parent, &efi_block_io_guid,
&diskobj->ops); &diskobj->ops);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
return ret; return ret;
ret = efi_add_protocol(diskobj->parent.handle, &efi_guid_device_path, ret = efi_add_protocol(&diskobj->parent, &efi_guid_device_path,
diskobj->dp); diskobj->dp);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
return ret; return ret;
if (part >= 1) { if (part >= 1) {
diskobj->volume = efi_simple_file_system(desc, part, diskobj->volume = efi_simple_file_system(desc, part,
diskobj->dp); diskobj->dp);
ret = efi_add_protocol(diskobj->parent.handle, ret = efi_add_protocol(&diskobj->parent,
&efi_simple_file_system_protocol_guid, &efi_simple_file_system_protocol_guid,
diskobj->volume); diskobj->volume);
if (ret != EFI_SUCCESS) if (ret != EFI_SUCCESS)
@ -381,7 +381,7 @@ efi_status_t efi_disk_register(void)
/* Partitions show up as block devices in EFI */ /* Partitions show up as block devices in EFI */
disks += efi_disk_create_partitions( disks += efi_disk_create_partitions(
disk->parent.handle, desc, if_typename, &disk->parent, desc, if_typename,
desc->devnum, dev->name); desc->devnum, dev->name);
} }
#else #else
@ -426,9 +426,9 @@ efi_status_t efi_disk_register(void)
disks++; disks++;
/* Partitions show up as block devices in EFI */ /* Partitions show up as block devices in EFI */
disks += efi_disk_create_partitions( disks += efi_disk_create_partitions
disk->parent.handle, desc, (&disk->parent, desc,
if_typename, i, devname); if_typename, i, devname);
} }
} }
#endif #endif

View File

@ -442,7 +442,7 @@ efi_status_t efi_gop_register(void)
efi_add_handle(&gopobj->parent); efi_add_handle(&gopobj->parent);
/* Fill in object data */ /* Fill in object data */
ret = efi_add_protocol(gopobj->parent.handle, &efi_gop_guid, ret = efi_add_protocol(&gopobj->parent, &efi_gop_guid,
&gopobj->ops); &gopobj->ops);
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
printf("ERROR: Failure adding gop protocol\n"); printf("ERROR: Failure adding gop protocol\n");

View File

@ -328,15 +328,15 @@ efi_status_t efi_net_register(void)
efi_add_handle(&netobj->parent); efi_add_handle(&netobj->parent);
/* Fill in object data */ /* Fill in object data */
r = efi_add_protocol(netobj->parent.handle, &efi_net_guid, r = efi_add_protocol(&netobj->parent, &efi_net_guid,
&netobj->net); &netobj->net);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto failure_to_add_protocol; goto failure_to_add_protocol;
r = efi_add_protocol(netobj->parent.handle, &efi_guid_device_path, r = efi_add_protocol(&netobj->parent, &efi_guid_device_path,
efi_dp_from_eth()); efi_dp_from_eth());
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto failure_to_add_protocol; goto failure_to_add_protocol;
r = efi_add_protocol(netobj->parent.handle, &efi_pxe_guid, r = efi_add_protocol(&netobj->parent, &efi_pxe_guid,
&netobj->pxe); &netobj->pxe);
if (r != EFI_SUCCESS) if (r != EFI_SUCCESS)
goto failure_to_add_protocol; goto failure_to_add_protocol;