mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
efi_loader: disk: a helper function to delete efi_disk objects
This function is expected to be called, in particular from dm's pre_remove hook, when associated block devices no longer exist. Add efi_disk_remove() function. This function removes an efi_disk object for a raw disk device (UCLASS_BLK) and related objects for its partitions (UCLASS_PARTITION). So this function is expected to be called through driver model's "remove" interface every time a raw disk device is to be disconnected. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
3c809dfed7
commit
b406eb04c3
1 changed files with 88 additions and 0 deletions
|
@ -635,6 +635,87 @@ static int efi_disk_probe(void *ctx, struct event *event)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete an efi_disk object for a whole raw disk
|
||||
*
|
||||
* @dev uclass device (UCLASS_BLK)
|
||||
*
|
||||
* Delete an efi_disk object which is associated with @dev.
|
||||
* The type of @dev must be UCLASS_BLK.
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
static int efi_disk_delete_raw(struct udevice *dev)
|
||||
{
|
||||
efi_handle_t handle;
|
||||
struct efi_disk_obj *diskobj;
|
||||
|
||||
if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle))
|
||||
return -1;
|
||||
|
||||
diskobj = container_of(handle, struct efi_disk_obj, header);
|
||||
efi_free_pool(diskobj->dp);
|
||||
|
||||
efi_delete_handle(handle);
|
||||
dev_tag_del(dev, DM_TAG_EFI);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete an efi_disk object for a disk partition
|
||||
*
|
||||
* @dev uclass device (UCLASS_PARTITION)
|
||||
*
|
||||
* Delete an efi_disk object which is associated with @dev.
|
||||
* The type of @dev must be UCLASS_PARTITION.
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
static int efi_disk_delete_part(struct udevice *dev)
|
||||
{
|
||||
efi_handle_t handle;
|
||||
struct efi_disk_obj *diskobj;
|
||||
|
||||
if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle))
|
||||
return -1;
|
||||
|
||||
diskobj = container_of(handle, struct efi_disk_obj, header);
|
||||
|
||||
efi_free_pool(diskobj->dp);
|
||||
efi_delete_handle(handle);
|
||||
dev_tag_del(dev, DM_TAG_EFI);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete an efi_disk object for a block device
|
||||
*
|
||||
* @dev uclass device (UCLASS_BLK or UCLASS_PARTITION)
|
||||
*
|
||||
* Delete an efi_disk object which is associated with @dev.
|
||||
* The type of @dev must be either UCLASS_BLK or UCLASS_PARTITION.
|
||||
* This function is expected to be called at EV_PM_PRE_REMOVE.
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
static int efi_disk_remove(void *ctx, struct event *event)
|
||||
{
|
||||
enum uclass_id id;
|
||||
struct udevice *dev;
|
||||
|
||||
dev = event->data.dm.dev;
|
||||
id = device_get_uclass_id(dev);
|
||||
|
||||
if (id == UCLASS_BLK)
|
||||
return efi_disk_delete_raw(dev);
|
||||
else if (id == UCLASS_PARTITION)
|
||||
return efi_disk_delete_part(dev);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
efi_status_t efi_disk_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
@ -646,5 +727,12 @@ efi_status_t efi_disk_init(void)
|
|||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
ret = event_register("efi_disk del", EVT_DM_PRE_REMOVE,
|
||||
efi_disk_remove, NULL);
|
||||
if (ret) {
|
||||
log_err("Event registration for efi_disk del failed\n");
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue