--- zzzz-none-000/linux-5.15.111/drivers/firmware/efi/libstub/efi-stub-helper.c 2023-05-11 14:00:40.000000000 +0000 +++ puma7-atom-6670-761/linux-5.15.111/drivers/firmware/efi/libstub/efi-stub-helper.c 2024-02-07 10:22:41.000000000 +0000 @@ -702,3 +702,38 @@ return status; } + +efi_status_t avm_for_each_protocol_call(efi_guid_t *protocol_guid, + efi_status_t (*callback)(void *iface, void *arg), + void *arg) +{ + unsigned long nhandles, i; + efi_handle_t *handles; + efi_status_t status; + + status = efi_bs_call(locate_handle_buffer, EFI_LOCATE_BY_PROTOCOL, + protocol_guid, NULL, &nhandles, &handles); + if (status != EFI_SUCCESS) { + efi_err("[%s] locate_handle_buffer failed:(%lu)\n", __func__, status); + return status; + } + + for (i = 0; i < nhandles; ++i) { + efi_handle_t handle; + void *iface; + + handle = efi_get_handle_at(handles, i); + status = efi_bs_call(handle_protocol, handle, protocol_guid, &iface); + if (status != EFI_SUCCESS) { + efi_err("[%s] Failed to handle PCI protocol: %lu\n", __func__, status); + continue; + } + + status = callback(iface, arg); + if (status == EFI_AVM_LOOP_STOP) + break; + } + + efi_bs_call(free_pool, handles); + return status; +}