]> git.proxmox.com Git - mirror_edk2.git/blame - DuetPkg/Library/DxeCoreReportStatusCodeLibFromHob/DxeSupport.c
BaseTools/CommonLib: drop definition of MAX_UINTN
[mirror_edk2.git] / DuetPkg / Library / DxeCoreReportStatusCodeLibFromHob / DxeSupport.c
CommitLineData
6dacb8cd 1/** @file\r
2 Report Status Code Library that depends on a GUIDed HOB for report status\r
3 code functionality.\r
4\r
b1f700a8
HT
5 Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>\r
6 This program and the accompanying materials\r
6dacb8cd 7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "ReportStatusCodeLibInternal.h"\r
17\r
18//\r
19// Handle to install report status code protocol interface\r
20//\r
21EFI_HANDLE mHandle = NULL;\r
22\r
23//\r
24// Report status protocol interface.\r
25//\r
26EFI_STATUS_CODE_PROTOCOL mStatusProtocol = {\r
27 NULL\r
28};\r
29\r
30/**\r
31 Initializes report status code infrastructure for DXE phase.\r
32\r
33 The constructor function assumes the PEI phase has published the GUIDed HOB\r
34 tagged by gEfiStatusCodeRuntimeProtocolGuid and publish status code runtime\r
35 protocol based on the GUID data. It will ASSERT() if one of these operations\r
36 fails and it will always return EFI_SUCCESS.\r
37\r
38 @param ImageHandle The firmware allocated handle for the EFI image.\r
39 @param SystemTable A pointer to the EFI System Table.\r
40\r
41 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
42\r
43**/\r
44EFI_STATUS\r
45EFIAPI\r
46DxeCoreReportStatusCodeFromHobLibConstructor (\r
47 IN EFI_HANDLE ImageHandle,\r
48 IN EFI_SYSTEM_TABLE *SystemTable\r
49 )\r
50{\r
51 EFI_STATUS Status;\r
52 EFI_HOB_GUID_TYPE *GuidHob;\r
53\r
54 GuidHob = GetFirstGuidHob(&gEfiStatusCodeRuntimeProtocolGuid);\r
55 ASSERT (GuidHob != NULL);\r
56 \r
57 mStatusProtocol.ReportStatusCode = (EFI_REPORT_STATUS_CODE) (*(UINTN *) GET_GUID_HOB_DATA (GuidHob));\r
58 ASSERT (mStatusProtocol.ReportStatusCode != NULL);\r
59\r
60 //\r
61 // Install report status protocol interface so that later DXE phase drivers can retrieve the protocol\r
62 // interface to report status code.\r
63 //\r
64 Status = gBS->InstallProtocolInterface (\r
65 &mHandle,\r
66 &gEfiStatusCodeRuntimeProtocolGuid,\r
67 EFI_NATIVE_INTERFACE,\r
68 &mStatusProtocol\r
69 );\r
70 ASSERT_EFI_ERROR (Status);\r
71\r
72 return Status;\r
73}\r
74\r
75/**\r
76 Reports a status code with full parameters.\r
77\r
78 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize\r
79 is 0, then an extended data buffer is not reported. If ExtendedData is not\r
80 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
81 ExtendedData is assumed not have the standard status code header, so this function\r
82 is responsible for allocating a buffer large enough for the standard header and\r
83 the extended data passed into this function. The standard header is filled in\r
84 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a\r
85 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with\r
86 an instance specified by Instance and a caller ID specified by CallerId. If\r
87 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
88\r
89 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()\r
90 is called while processing another any other Report Status Code Library function,\r
91 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
92\r
93 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
94 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
95\r
96 @param Type Status code type.\r
97 @param Value Status code value.\r
98 @param Instance Status code instance number.\r
99 @param CallerId Pointer to a GUID that identifies the caller of this\r
100 function. If this parameter is NULL, then a caller\r
101 ID of gEfiCallerIdGuid is used.\r
102 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.\r
103 If this parameter is NULL, then a the status code\r
104 standard header is filled in with\r
105 gEfiStatusCodeSpecificDataGuid.\r
106 @param ExtendedData Pointer to the extended data buffer. This is an\r
107 optional parameter that may be NULL.\r
108 @param ExtendedDataSize The size, in bytes, of the extended data buffer.\r
109\r
110 @retval EFI_SUCCESS The status code was reported.\r
111 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate\r
112 the extended data section if it was specified.\r
113 @retval EFI_UNSUPPORTED Report status code is not supported\r
114\r
115**/\r
116EFI_STATUS\r
117EFIAPI\r
118InternalReportStatusCodeEx (\r
119 IN EFI_STATUS_CODE_TYPE Type,\r
120 IN EFI_STATUS_CODE_VALUE Value,\r
121 IN UINT32 Instance,\r
122 IN CONST EFI_GUID *CallerId OPTIONAL,\r
123 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,\r
124 IN CONST VOID *ExtendedData OPTIONAL,\r
125 IN UINTN ExtendedDataSize\r
126 )\r
127{\r
128 EFI_STATUS Status;\r
129 EFI_STATUS_CODE_DATA *StatusCodeData;\r
130\r
131 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
132 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
133\r
134 if (gBS == NULL) {\r
135 return EFI_UNSUPPORTED;\r
136 }\r
137\r
138 //\r
139 // Allocate space for the Status Code Header and its buffer\r
140 //\r
141 StatusCodeData = NULL;\r
142 gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
143 if (StatusCodeData == NULL) {\r
144 return EFI_OUT_OF_RESOURCES;\r
145 }\r
146\r
147 //\r
148 // Fill in the extended data header\r
149 //\r
150 StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
151 StatusCodeData->Size = (UINT16)ExtendedDataSize;\r
152 if (ExtendedDataGuid == NULL) {\r
153 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
154 }\r
155 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);\r
156\r
157 //\r
158 // Fill in the extended data buffer\r
159 //\r
160 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
161\r
162 //\r
163 // Report the status code\r
164 //\r
165 if (CallerId == NULL) {\r
166 CallerId = &gEfiCallerIdGuid;\r
167 }\r
168 Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);\r
169\r
170 //\r
171 // Free the allocated buffer\r
172 //\r
173 gBS->FreePool (StatusCodeData);\r
174\r
175 return Status;\r
176}\r
177\r