Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: Intel |
| 2 | /* |
| 3 | * Copyright (C) 2013, Intel Corporation |
| 4 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
| 5 | */ |
| 6 | |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 7 | #include <asm/hob.h> |
| 8 | |
| 9 | /** |
| 10 | * Returns the next instance of a HOB type from the starting HOB. |
| 11 | * |
| 12 | * @type: HOB type to search |
| 13 | * @hob_list: A pointer to the HOB list |
| 14 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 15 | * Return: A HOB object with matching type; Otherwise NULL. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 16 | */ |
| 17 | const struct hob_header *hob_get_next_hob(uint type, const void *hob_list) |
| 18 | { |
| 19 | const struct hob_header *hdr; |
| 20 | |
| 21 | hdr = hob_list; |
| 22 | |
| 23 | /* Parse the HOB list until end of list or matching type is found */ |
| 24 | while (!end_of_hob(hdr)) { |
| 25 | if (hdr->type == type) |
| 26 | return hdr; |
| 27 | |
| 28 | hdr = get_next_hob(hdr); |
| 29 | } |
| 30 | |
| 31 | return NULL; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Returns the next instance of the matched GUID HOB from the starting HOB. |
| 36 | * |
| 37 | * @guid: GUID to search |
| 38 | * @hob_list: A pointer to the HOB list |
| 39 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 40 | * Return: A HOB object with matching GUID; Otherwise NULL. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 41 | */ |
| 42 | const struct hob_header *hob_get_next_guid_hob(const efi_guid_t *guid, |
| 43 | const void *hob_list) |
| 44 | { |
| 45 | const struct hob_header *hdr; |
| 46 | struct hob_guid *guid_hob; |
| 47 | |
| 48 | hdr = hob_list; |
| 49 | while ((hdr = hob_get_next_hob(HOB_TYPE_GUID_EXT, hdr))) { |
| 50 | guid_hob = (struct hob_guid *)hdr; |
| 51 | if (!guidcmp(guid, &guid_hob->name)) |
| 52 | break; |
| 53 | hdr = get_next_hob(hdr); |
| 54 | } |
| 55 | |
| 56 | return hdr; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * This function retrieves a GUID HOB data buffer and size. |
| 61 | * |
| 62 | * @hob_list: A HOB list pointer. |
| 63 | * @len: A pointer to the GUID HOB data buffer length. |
| 64 | * If the GUID HOB is located, the length will be updated. |
| 65 | * @guid A pointer to HOB GUID. |
| 66 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 67 | * Return: NULL: Failed to find the GUID HOB. |
| 68 | * Return: others: GUID HOB data buffer pointer. |
Park, Aiden | 538aec9 | 2019-08-03 08:30:31 +0000 | [diff] [blame] | 69 | */ |
| 70 | void *hob_get_guid_hob_data(const void *hob_list, u32 *len, |
| 71 | const efi_guid_t *guid) |
| 72 | { |
| 73 | const struct hob_header *guid_hob; |
| 74 | |
| 75 | guid_hob = hob_get_next_guid_hob(guid, hob_list); |
| 76 | if (!guid_hob) |
| 77 | return NULL; |
| 78 | |
| 79 | if (len) |
| 80 | *len = get_guid_hob_data_size(guid_hob); |
| 81 | |
| 82 | return get_guid_hob_data(guid_hob); |
| 83 | } |