Abstract out efi_devpath_to_handle to search for a handle that matches

the desired devpath.
This commit is contained in:
Warner Losh 2019-05-06 18:39:27 +00:00
parent f28eb4856d
commit b9e19b077e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=347195
3 changed files with 26 additions and 14 deletions

View File

@ -95,6 +95,7 @@ UINTN efi_devpath_length(EFI_DEVICE_PATH *);
EFI_DEVICE_PATH *efi_name_to_devpath(const char *path);
EFI_DEVICE_PATH *efi_name_to_devpath16(CHAR16 *path);
void efi_devpath_free(EFI_DEVICE_PATH *dp);
EFI_HANDLE efi_devpath_to_handle(EFI_DEVICE_PATH *path, EFI_HANDLE *handles, unsigned nhandles);
int efi_status_to_errno(EFI_STATUS);
EFI_STATUS errno_to_efi_status(int errno);

View File

@ -269,3 +269,25 @@ efi_devpath_length(EFI_DEVICE_PATH *path)
path = NextDevicePathNode(path);
return ((UINTN)path - (UINTN)start) + DevicePathNodeLength(path);
}
EFI_HANDLE
efi_devpath_to_handle(EFI_DEVICE_PATH *path, EFI_HANDLE *handles, unsigned nhandles)
{
unsigned i;
EFI_DEVICE_PATH *media, *devpath;
EFI_HANDLE h;
media = efi_devpath_to_media_path(path);
if (media == NULL)
return (NULL);
for (i = 0; i < nhandles; i++) {
h = handles[i];
devpath = efi_lookup_devpath(h);
if (devpath == NULL)
continue;
if (!efi_devpath_match_node(media, efi_devpath_to_media_path(devpath)))
continue;
return (h);
}
return (NULL);
}

View File

@ -140,23 +140,12 @@ efiblk_get_pdinfo(struct devdesc *dev)
pdinfo_t *
efiblk_get_pdinfo_by_device_path(EFI_DEVICE_PATH *path)
{
unsigned i;
EFI_DEVICE_PATH *media, *devpath;
EFI_HANDLE h;
media = efi_devpath_to_media_path(path);
if (media == NULL)
h = efi_devpath_to_handle(path, efipart_handles, efipart_nhandles);
if (h == NULL)
return (NULL);
for (i = 0; i < efipart_nhandles; i++) {
h = efipart_handles[i];
devpath = efi_lookup_devpath(h);
if (devpath == NULL)
continue;
if (!efi_devpath_match_node(media, efi_devpath_to_media_path(devpath)))
continue;
return (efiblk_get_pdinfo_by_handle(h));
}
return (NULL);
return (efiblk_get_pdinfo_by_handle(h));
}
static bool