From 110d56cbf438a76ef37735cec8aa02518d0d1f4a Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Tue, 6 Aug 2019 19:27:27 +0000 Subject: [PATCH] loader.efi: replace HandleProtocol() with OpenProtocol() The HandleProtocol() is deprecated interface and we should use OpenProtocol() instead. Moreover, in some firmware implementation(s), the HandleProtocol() does return device path using static storage, so we can not keep the value returned there. With same firmware, the OpenProtocol() does return data we do not need to clone. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D21162 --- stand/efi/boot1/proto.c | 4 ++-- stand/efi/gptboot/proto.c | 4 ++-- stand/efi/libefi/devpath.c | 7 ++++--- stand/efi/libefi/efinet.c | 2 +- stand/efi/libefi/efipart.c | 16 ++++++++-------- stand/efi/loader/efi_main.c | 2 +- stand/efi/loader/framebuffer.c | 3 ++- stand/efi/loader/main.c | 9 +++++---- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/stand/efi/boot1/proto.c b/stand/efi/boot1/proto.c index 039ee0142d49..7511cc4cf416 100644 --- a/stand/efi/boot1/proto.c +++ b/stand/efi/boot1/proto.c @@ -61,7 +61,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath) int preferred; /* Figure out if we're dealing with an actual partition. */ - status = BS->HandleProtocol(h, &DevicePathGUID, (void **)&devpath); + status = OpenProtocolByHandle(h, &DevicePathGUID, (void **)&devpath); if (status == EFI_UNSUPPORTED) return (0); @@ -77,7 +77,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath) efi_free_devpath_name(text); } #endif - status = BS->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio); + status = OpenProtocolByHandle(h, &BlockIoProtocolGUID, (void **)&blkio); if (status == EFI_UNSUPPORTED) return (0); diff --git a/stand/efi/gptboot/proto.c b/stand/efi/gptboot/proto.c index 84888b496f83..e58313708409 100644 --- a/stand/efi/gptboot/proto.c +++ b/stand/efi/gptboot/proto.c @@ -146,7 +146,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath) EFI_STATUS status; /* Figure out if we're dealing with an actual partition. */ - status = BS->HandleProtocol(h, &DevicePathGUID, (void **)&devpath); + status = OpenProtocolByHandle(h, &DevicePathGUID, (void **)&devpath); if (status != EFI_SUCCESS) return; #ifdef EFI_DEBUG @@ -169,7 +169,7 @@ probe_handle(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath) return; } } - status = BS->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio); + status = OpenProtocolByHandle(h, &BlockIoProtocolGUID, (void **)&blkio); if (status != EFI_SUCCESS) { DPRINTF("Can't get the block I/O protocol block\n"); return; diff --git a/stand/efi/libefi/devpath.c b/stand/efi/libefi/devpath.c index a61a4add6827..c4c97a6f623d 100644 --- a/stand/efi/libefi/devpath.c +++ b/stand/efi/libefi/devpath.c @@ -44,8 +44,8 @@ efi_lookup_image_devpath(EFI_HANDLE handle) EFI_DEVICE_PATH *devpath; EFI_STATUS status; - status = BS->HandleProtocol(handle, &ImageDevicePathGUID, - (VOID **)&devpath); + status = OpenProtocolByHandle(handle, &ImageDevicePathGUID, + (void **)&devpath); if (EFI_ERROR(status)) devpath = NULL; return (devpath); @@ -57,7 +57,8 @@ efi_lookup_devpath(EFI_HANDLE handle) EFI_DEVICE_PATH *devpath; EFI_STATUS status; - status = BS->HandleProtocol(handle, &DevicePathGUID, (VOID **)&devpath); + status = OpenProtocolByHandle(handle, &DevicePathGUID, + (void **)&devpath); if (EFI_ERROR(status)) devpath = NULL; return (devpath); diff --git a/stand/efi/libefi/efinet.c b/stand/efi/libefi/efinet.c index 51b9687d6772..418790524e4a 100644 --- a/stand/efi/libefi/efinet.c +++ b/stand/efi/libefi/efinet.c @@ -286,7 +286,7 @@ efinet_init(struct iodesc *desc, void *machdep_hint) } h = nif->nif_driver->netif_ifs[nif->nif_unit].dif_private; - status = BS->HandleProtocol(h, &sn_guid, (VOID **)&nif->nif_devdata); + status = OpenProtocolByHandle(h, &sn_guid, (void **)&nif->nif_devdata); if (status != EFI_SUCCESS) { printf("net%d: cannot fetch interface data (status=%lu)\n", nif->nif_unit, EFI_ERROR_CODE(status)); diff --git a/stand/efi/libefi/efipart.c b/stand/efi/libefi/efipart.c index 63e3af4f097a..cc1bb754cbf5 100644 --- a/stand/efi/libefi/efipart.c +++ b/stand/efi/libefi/efipart.c @@ -297,8 +297,8 @@ efipart_hdd(EFI_DEVICE_PATH *dp) } /* Make sure we do have the media. */ - status = BS->HandleProtocol(efipart_handles[i], - &blkio_guid, (void **)&blkio); + status = OpenProtocolByHandle(efipart_handles[i], &blkio_guid, + (void **)&blkio); if (EFI_ERROR(status)) return (false); @@ -439,8 +439,8 @@ efipart_updatecd(void) if (efipart_hdd(devpath)) continue; - status = BS->HandleProtocol(efipart_handles[i], - &blkio_guid, (void **)&blkio); + status = OpenProtocolByHandle(efipart_handles[i], &blkio_guid, + (void **)&blkio); if (EFI_ERROR(status)) continue; /* @@ -691,8 +691,8 @@ efipart_updatehd(void) if (!efipart_hdd(devpath)) continue; - status = BS->HandleProtocol(efipart_handles[i], - &blkio_guid, (void **)&blkio); + status = OpenProtocolByHandle(efipart_handles[i], &blkio_guid, + (void **)&blkio); if (EFI_ERROR(status)) continue; @@ -779,7 +779,7 @@ efipart_print_common(struct devsw *dev, pdinfo_list_t *pdlist, int verbose) snprintf(line, sizeof(line), " %s%d", dev->dv_name, pd->pd_unit); printf("%s:", line); - status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio); + status = OpenProtocolByHandle(h, &blkio_guid, (void **)&blkio); if (!EFI_ERROR(status)) { printf(" %llu", blkio->Media->LastBlock == 0? 0: @@ -862,7 +862,7 @@ efipart_open(struct open_file *f, ...) return (EIO); if (pd->pd_blkio == NULL) { - status = BS->HandleProtocol(pd->pd_handle, &blkio_guid, + status = OpenProtocolByHandle(pd->pd_handle, &blkio_guid, (void **)&pd->pd_blkio); if (EFI_ERROR(status)) return (efi_status_to_errno(status)); diff --git a/stand/efi/loader/efi_main.c b/stand/efi/loader/efi_main.c index d6f8daf020d3..fa3c765c36ab 100644 --- a/stand/efi/loader/efi_main.c +++ b/stand/efi/loader/efi_main.c @@ -103,7 +103,7 @@ efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) /* Use efi_exit() from here on... */ - status = BS->HandleProtocol(IH, &image_protocol, (VOID**)&img); + status = OpenProtocolByHandle(IH, &image_protocol, (void**)&img); if (status != EFI_SUCCESS) efi_exit(status); diff --git a/stand/efi/loader/framebuffer.c b/stand/efi/loader/framebuffer.c index c012be92731a..3f7e5fcbabef 100644 --- a/stand/efi/loader/framebuffer.c +++ b/stand/efi/loader/framebuffer.c @@ -244,7 +244,8 @@ efifb_uga_get_pciio(void) /* Get the PCI I/O interface of the first handle that supports it. */ pciio = NULL; for (hp = buf; hp < buf + bufsz; hp++) { - status = BS->HandleProtocol(*hp, &pciio_guid, (void **)&pciio); + status = OpenProtocolByHandle(*hp, &pciio_guid, + (void **)&pciio); if (status == EFI_SUCCESS) { free(buf); return (pciio); diff --git a/stand/efi/loader/main.c b/stand/efi/loader/main.c index 60d8c1442518..171a86332728 100644 --- a/stand/efi/loader/main.c +++ b/stand/efi/loader/main.c @@ -128,7 +128,7 @@ has_keyboard(void) */ hin_end = &hin[sz / sizeof(*hin)]; for (walker = hin; walker < hin_end; walker++) { - status = BS->HandleProtocol(*walker, &devid, (VOID **)&path); + status = OpenProtocolByHandle(*walker, &devid, (void **)&path); if (EFI_ERROR(status)) continue; @@ -864,7 +864,7 @@ main(int argc, CHAR16 *argv[]) archsw.arch_zfs_probe = efi_zfs_probe; /* Get our loaded image protocol interface structure. */ - BS->HandleProtocol(IH, &imgid, (VOID**)&boot_img); + (void) OpenProtocolByHandle(IH, &imgid, (void **)&boot_img); /* * Chicken-and-egg problem; we want to have console output early, but @@ -1004,7 +1004,8 @@ main(int argc, CHAR16 *argv[]) efi_free_devpath_name(text); } - rv = BS->HandleProtocol(boot_img->DeviceHandle, &devid, (void **)&imgpath); + rv = OpenProtocolByHandle(boot_img->DeviceHandle, &devid, + (void **)&imgpath); if (rv == EFI_SUCCESS) { text = efi_devpath_name(imgpath); if (text != NULL) { @@ -1464,7 +1465,7 @@ command_chain(int argc, char *argv[]) command_errmsg = "LoadImage failed"; return (CMD_ERROR); } - status = BS->HandleProtocol(loaderhandle, &LoadedImageGUID, + status = OpenProtocolByHandle(loaderhandle, &LoadedImageGUID, (void **)&loaded_image); if (argc > 2) {