blob: 46e83aa395ab103ba24ab22dcb337cafc6202365 [file] [log] [blame]
Park, Aiden538aec92019-08-03 08:30:31 +00001// SPDX-License-Identifier: Intel
2/*
3 * Copyright (C) 2013, Intel Corporation
4 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
5 */
6
Park, Aiden538aec92019-08-03 08:30:31 +00007#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 Schuchardt47b4c022022-01-19 18:05:50 +010015 * Return: A HOB object with matching type; Otherwise NULL.
Park, Aiden538aec92019-08-03 08:30:31 +000016 */
17const 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 Schuchardt47b4c022022-01-19 18:05:50 +010040 * Return: A HOB object with matching GUID; Otherwise NULL.
Park, Aiden538aec92019-08-03 08:30:31 +000041 */
42const 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 Schuchardt47b4c022022-01-19 18:05:50 +010067 * Return: NULL: Failed to find the GUID HOB.
68 * Return: others: GUID HOB data buffer pointer.
Park, Aiden538aec92019-08-03 08:30:31 +000069 */
70void *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}