hob.c 2.0 KB

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