ConfigurationManagerHelper.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /** @file
  2. Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. @par Glossary:
  5. - Cm or CM - Configuration Manager
  6. - Obj or OBJ - Object
  7. **/
  8. #ifndef CONFIGURATION_MANAGER_HELPER_H_
  9. #define CONFIGURATION_MANAGER_HELPER_H_
  10. /** The GET_OBJECT_LIST macro expands to a function that is used to retrieve
  11. an object or an object list from the Configuration Manager using the
  12. Configuration Manager Protocol interface.
  13. The macro expands to a function which has the following prototype:
  14. STATIC
  15. EFI_STATUS
  16. EFIAPI
  17. Get<CmObjectId> (
  18. IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
  19. IN CONST CM_OBJECT_TOKEN Token OPTIONAL,
  20. OUT Type ** List,
  21. OUT UINT32 * Count OPTIONAL
  22. );
  23. Generated function parameters:
  24. @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol
  25. interface.
  26. @param [in] Token Reference token for the Object.
  27. @param [out] List Pointer to the Object list.
  28. @param [out] Count Count of the objects returned in the list.
  29. Macro Parameters:
  30. @param [in] CmObjectNameSpace The Object Namespace
  31. @param [in] CmObjectId Object Id.
  32. @param [in] Type Structure used to describe the Object.
  33. @retval EFI_SUCCESS Success.
  34. @retval EFI_INVALID_PARAMETER A parameter is invalid.
  35. @retval EFI_NOT_FOUND The required object information is not found.
  36. @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
  37. Manager is less than the Object size for the
  38. requested object.
  39. **/
  40. #define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type) \
  41. STATIC \
  42. EFI_STATUS \
  43. EFIAPI \
  44. Get##CmObjectId ( \
  45. IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, \
  46. IN CONST CM_OBJECT_TOKEN Token OPTIONAL, \
  47. OUT Type ** List, \
  48. OUT UINT32 * CONST Count OPTIONAL \
  49. ) \
  50. { \
  51. EFI_STATUS Status; \
  52. CM_OBJ_DESCRIPTOR CmObjectDesc; \
  53. UINT32 ObjCount = 0; \
  54. if (List == NULL) { \
  55. Status = EFI_INVALID_PARAMETER; \
  56. DEBUG (( \
  57. DEBUG_ERROR, \
  58. "ERROR: Get" #CmObjectId ": Invalid out parameter for" \
  59. " object list. Status = %r\n", \
  60. Status \
  61. )); \
  62. goto error_handler; \
  63. } \
  64. Status = CfgMgrProtocol->GetObject ( \
  65. CfgMgrProtocol, \
  66. CREATE_CM_OBJECT_ID ( \
  67. CmObjectNameSpace, \
  68. CmObjectId \
  69. ), \
  70. Token, \
  71. &CmObjectDesc \
  72. ); \
  73. if (EFI_ERROR (Status)) { \
  74. DEBUG (( \
  75. DEBUG_INFO, \
  76. "INFO: Get" #CmObjectId ": Platform does not implement " \
  77. #CmObjectId ". Status = %r\n", \
  78. Status \
  79. )); \
  80. *List = NULL; \
  81. goto error_handler; \
  82. } \
  83. if (CmObjectDesc.ObjectId != \
  84. CREATE_CM_OBJECT_ID (CmObjectNameSpace, CmObjectId)) { \
  85. DEBUG (( \
  86. DEBUG_ERROR, \
  87. "ERROR: Get" #CmObjectId ": " #CmObjectId \
  88. ": Invalid ObjectId = 0x%x\n, expected Id = 0x%x\n", \
  89. CmObjectDesc.ObjectId, \
  90. CREATE_CM_OBJECT_ID (CmObjectNameSpace, CmObjectId) \
  91. )); \
  92. ASSERT (FALSE); \
  93. Status = EFI_INVALID_PARAMETER; \
  94. goto error_handler; \
  95. } \
  96. if (CmObjectDesc.Size < (sizeof (Type) * CmObjectDesc.Count)) { \
  97. DEBUG (( \
  98. DEBUG_ERROR, \
  99. "ERROR: Get" #CmObjectId ": " #CmObjectId \
  100. ": Buffer too small, size = 0x%x\n", \
  101. CmObjectDesc.Size \
  102. )); \
  103. ASSERT (FALSE); \
  104. Status = EFI_BAD_BUFFER_SIZE; \
  105. goto error_handler; \
  106. } \
  107. ObjCount = CmObjectDesc.Count; \
  108. *List = (Type*)CmObjectDesc.Data; \
  109. error_handler: \
  110. if (Count != NULL) { \
  111. *Count = ObjCount; \
  112. } \
  113. return Status; \
  114. }
  115. #endif // CONFIGURATION_MANAGER_HELPER_H_