From f2b3bf5c4d4a391648e5b2740e81bccb85752ae5 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Fri, 12 May 2023 18:41:14 +0300 Subject: [PATCH] libefi: add efi_devpath_next_instance() UEFI device path may be path to one device, or concatenated list of instances to different devices (textually represented as comma separated list). Provide generic function to get next instance from device path. Returns next instance or end node. The use case is like: EFI_DEVICE_PATH *node = (EFI_DEVICE_PATH *)buf; while (!IsDevicePathEnd(node)) { process(node); node = efi_devpath_next_instance(node); } Where buf is pointing to either single device path or concatenated list of device paths (such as from ConIn or ConOut). Reviewers: imp Differential Revision: https://reviews.freebsd.org/D40081 --- stand/efi/include/efilib.h | 1 + stand/efi/libefi/devpath.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/stand/efi/include/efilib.h b/stand/efi/include/efilib.h index 1673ac97fdf2..df4ae6503760 100644 --- a/stand/efi/include/efilib.h +++ b/stand/efi/include/efilib.h @@ -97,6 +97,7 @@ void efi_close_devpath(EFI_HANDLE); EFI_HANDLE efi_devpath_handle(EFI_DEVICE_PATH *); EFI_DEVICE_PATH *efi_devpath_last_node(EFI_DEVICE_PATH *); EFI_DEVICE_PATH *efi_devpath_trim(EFI_DEVICE_PATH *); +EFI_DEVICE_PATH *efi_devpath_next_instance(EFI_DEVICE_PATH *); bool efi_devpath_match(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *); bool efi_devpath_match_node(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *); bool efi_devpath_is_prefix(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *); diff --git a/stand/efi/libefi/devpath.c b/stand/efi/libefi/devpath.c index c25ae73e463c..94bb07540376 100644 --- a/stand/efi/libefi/devpath.c +++ b/stand/efi/libefi/devpath.c @@ -575,6 +575,23 @@ efi_devpath_last_node(EFI_DEVICE_PATH *devpath) return (devpath); } +/* + * Walk device path nodes, return next instance or end node. + */ +EFI_DEVICE_PATH * +efi_devpath_next_instance(EFI_DEVICE_PATH *devpath) +{ + while (!IsDevicePathEnd(devpath)) { + devpath = NextDevicePathNode(devpath); + if (IsDevicePathEndType(devpath) && + devpath->SubType == END_INSTANCE_DEVICE_PATH_SUBTYPE) { + devpath = NextDevicePathNode(devpath); + break; + } + } + return (devpath); +} + EFI_DEVICE_PATH * efi_devpath_trim(EFI_DEVICE_PATH *devpath) {