]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeSupport.c
42f7699e225b4b9d2e71b2fb2a4c7e6c4e6c8642
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / DxeReportStatusCodeLibFramework / DxeSupport.c
1 /** @file
2 Report Status Code Library for DXE Phase.
3
4 Copyright (c) 2006 - 2007, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "ReportStatusCodeLibInternal.h"
16
17 /**
18 Locate he report status code service.
19
20 @return EFI_REPORT_STATUS_CODE function point to
21 ReportStatusCode.
22 **/
23 EFI_REPORT_STATUS_CODE
24 InternalGetReportStatusCode (
25 VOID
26 )
27 {
28 EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;
29 EFI_STATUS Status;
30
31 if (gRT->Hdr.Revision < 0x20000) {
32 return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)gRT)->ReportStatusCode;
33 } else if (gBS != NULL) {
34 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);
35 if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {
36 return StatusCodeProtocol->ReportStatusCode;
37 }
38 }
39
40 return NULL;
41 }
42
43 /**
44 Reports a status code with full parameters.
45
46 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
47 is 0, then an extended data buffer is not reported. If ExtendedData is not
48 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
49 ExtendedData is assumed not have the standard status code header, so this function
50 is responsible for allocating a buffer large enough for the standard header and
51 the extended data passed into this function. The standard header is filled in
52 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
53 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
54 an instance specified by Instance and a caller ID specified by CallerId. If
55 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
56
57 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
58 is called while processing another any other Report Status Code Library function,
59 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
60
61 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
62 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
63
64 @param Type Status code type.
65 @param Value Status code value.
66 @param Instance Status code instance number.
67 @param CallerId Pointer to a GUID that identifies the caller of this
68 function. If this parameter is NULL, then a caller
69 ID of gEfiCallerIdGuid is used.
70 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
71 If this parameter is NULL, then a the status code
72 standard header is filled in with
73 gEfiStatusCodeSpecificDataGuid.
74 @param ExtendedData Pointer to the extended data buffer. This is an
75 optional parameter that may be NULL.
76 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
77
78 @retval EFI_SUCCESS The status code was reported.
79 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
80 the extended data section if it was specified.
81 @retval EFI_UNSUPPORTED Report status code is not supported
82
83 **/
84 EFI_STATUS
85 EFIAPI
86 InternalReportStatusCodeEx (
87 IN EFI_STATUS_CODE_TYPE Type,
88 IN EFI_STATUS_CODE_VALUE Value,
89 IN UINT32 Instance,
90 IN CONST EFI_GUID *CallerId OPTIONAL,
91 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,
92 IN CONST VOID *ExtendedData OPTIONAL,
93 IN UINTN ExtendedDataSize
94 )
95 {
96 EFI_STATUS Status;
97 EFI_STATUS_CODE_DATA *StatusCodeData;
98
99 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
100 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
101
102 if (gBS == NULL) {
103 return EFI_UNSUPPORTED;
104 }
105
106 //
107 // Allocate space for the Status Code Header and its buffer
108 //
109 StatusCodeData = NULL;
110 gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
111 if (StatusCodeData == NULL) {
112 return EFI_OUT_OF_RESOURCES;
113 }
114
115 //
116 // Fill in the extended data header
117 //
118 StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);
119 StatusCodeData->Size = (UINT16)ExtendedDataSize;
120 if (ExtendedDataGuid == NULL) {
121 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;
122 }
123 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);
124
125 //
126 // Fill in the extended data buffer
127 //
128 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);
129
130 //
131 // Report the status code
132 //
133 if (CallerId == NULL) {
134 CallerId = &gEfiCallerIdGuid;
135 }
136 Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);
137
138 //
139 // Free the allocated buffer
140 //
141 gBS->FreePool (StatusCodeData);
142
143 return Status;
144 }
145