]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/Library/DuetDxeReportStatusCodeLib/DxeSupport.c
12cca204524114462360f25d5eb862f959a9f764
[mirror_edk2.git] / DuetPkg / Library / DuetDxeReportStatusCodeLib / 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 EFI_PEI_HOB_POINTERS GuidHob;
31
32 if (gRT->Hdr.Revision < 0x20000) {
33 return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)gRT)->ReportStatusCode;
34 } else if (gBS != NULL) {
35 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);
36 if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {
37 return StatusCodeProtocol->ReportStatusCode;
38 } else {
39 GuidHob.Raw = GetFirstGuidHob(&gEfiStatusCodeRuntimeProtocolGuid);
40 if (GuidHob.Raw != NULL) {
41 return (EFI_REPORT_STATUS_CODE) (*(UINTN *) GET_GUID_HOB_DATA (GuidHob.Guid));
42 }
43 }
44 }
45
46 return NULL;
47 }
48
49 /**
50 Reports a status code with full parameters.
51
52 The function reports a status code. If ExtendedData is NULL and ExtendedDataSize
53 is 0, then an extended data buffer is not reported. If ExtendedData is not
54 NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.
55 ExtendedData is assumed not have the standard status code header, so this function
56 is responsible for allocating a buffer large enough for the standard header and
57 the extended data passed into this function. The standard header is filled in
58 with a GUID specified by ExtendedDataGuid. If ExtendedDataGuid is NULL, then a
59 GUID of gEfiStatusCodeSpecificDatauid is used. The status code is reported with
60 an instance specified by Instance and a caller ID specified by CallerId. If
61 CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.
62
63 ReportStatusCodeEx()must actively prevent recursion. If ReportStatusCodeEx()
64 is called while processing another any other Report Status Code Library function,
65 then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.
66
67 If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().
68 If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().
69
70 @param Type Status code type.
71 @param Value Status code value.
72 @param Instance Status code instance number.
73 @param CallerId Pointer to a GUID that identifies the caller of this
74 function. If this parameter is NULL, then a caller
75 ID of gEfiCallerIdGuid is used.
76 @param ExtendedDataGuid Pointer to the GUID for the extended data buffer.
77 If this parameter is NULL, then a the status code
78 standard header is filled in with
79 gEfiStatusCodeSpecificDataGuid.
80 @param ExtendedData Pointer to the extended data buffer. This is an
81 optional parameter that may be NULL.
82 @param ExtendedDataSize The size, in bytes, of the extended data buffer.
83
84 @retval EFI_SUCCESS The status code was reported.
85 @retval EFI_OUT_OF_RESOURCES There were not enough resources to allocate
86 the extended data section if it was specified.
87 @retval EFI_UNSUPPORTED Report status code is not supported
88
89 **/
90 EFI_STATUS
91 EFIAPI
92 InternalReportStatusCodeEx (
93 IN EFI_STATUS_CODE_TYPE Type,
94 IN EFI_STATUS_CODE_VALUE Value,
95 IN UINT32 Instance,
96 IN CONST EFI_GUID *CallerId OPTIONAL,
97 IN CONST EFI_GUID *ExtendedDataGuid OPTIONAL,
98 IN CONST VOID *ExtendedData OPTIONAL,
99 IN UINTN ExtendedDataSize
100 )
101 {
102 EFI_STATUS Status;
103 EFI_STATUS_CODE_DATA *StatusCodeData;
104
105 ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
106 ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
107
108 if (gBS == NULL) {
109 return EFI_UNSUPPORTED;
110 }
111
112 //
113 // Allocate space for the Status Code Header and its buffer
114 //
115 StatusCodeData = NULL;
116 gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
117 if (StatusCodeData == NULL) {
118 return EFI_OUT_OF_RESOURCES;
119 }
120
121 //
122 // Fill in the extended data header
123 //
124 StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);
125 StatusCodeData->Size = (UINT16)ExtendedDataSize;
126 if (ExtendedDataGuid == NULL) {
127 ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;
128 }
129 CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);
130
131 //
132 // Fill in the extended data buffer
133 //
134 CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);
135
136 //
137 // Report the status code
138 //
139 if (CallerId == NULL) {
140 CallerId = &gEfiCallerIdGuid;
141 }
142 Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);
143
144 //
145 // Free the allocated buffer
146 //
147 gBS->FreePool (StatusCodeData);
148
149 return Status;
150 }
151