]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Dxe/EfiDriverLib/ReportStatusCode.c
Update EfiLibReportStatusCode in ECP EfiDriverLib and EfiRuntimeLib libraries to...
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / EfiDriverLib / ReportStatusCode.c
1 /*++
2
3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 ReportStatusCode.c
15
16 Abstract:
17
18 --*/
19
20 #include "Tiano.h"
21 #include "EfiDriverLib.h"
22 #include EFI_PROTOCOL_DEFINITION (DevicePath)
23 #include EFI_GUID_DEFINITION (StatusCodeDataTypeId)
24 #include EFI_ARCH_PROTOCOL_DEFINITION (StatusCode)
25
26 STATIC EFI_STATUS_CODE_PROTOCOL *gStatusCode = NULL;
27
28 EFI_STATUS
29 EfiLibReportStatusCode (
30 IN EFI_STATUS_CODE_TYPE Type,
31 IN EFI_STATUS_CODE_VALUE Value,
32 IN UINT32 Instance,
33 IN EFI_GUID *CallerId OPTIONAL,
34 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
35 )
36 /*++
37
38 Routine Description:
39
40 Report device path through status code.
41
42 Arguments:
43
44 Type - Code type
45 Value - Code value
46 Instance - Instance number
47 CallerId - Caller name
48 DevicePath - Device path that to be reported
49
50 Returns:
51
52 Status code.
53
54 EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
55
56 --*/
57 {
58 EFI_STATUS Status;
59
60 Status = EFI_UNSUPPORTED;
61
62 if (gRT->Hdr.Revision >= 0x00020000) {
63 if (gStatusCode == NULL) {
64 if (gBS == NULL) {
65 return EFI_UNSUPPORTED;
66 }
67 Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID **)&gStatusCode);
68 if (EFI_ERROR (Status) || gStatusCode == NULL) {
69 return EFI_UNSUPPORTED;
70 }
71 }
72 Status = gStatusCode->ReportStatusCode (Type, Value, Instance, CallerId, Data);
73 } else {
74 if (gRT == NULL) {
75 return EFI_UNSUPPORTED;
76 }
77 //
78 // Check whether EFI_RUNTIME_SERVICES has Tiano Extension
79 //
80 Status = EFI_UNSUPPORTED;
81 #if (EFI_SPECIFICATION_VERSION < 0x00020000)
82 if (gRT->Hdr.Revision == EFI_SPECIFICATION_VERSION &&
83 gRT->Hdr.HeaderSize == sizeof (EFI_RUNTIME_SERVICES) &&
84 gRT->ReportStatusCode != NULL) {
85 Status = gRT->ReportStatusCode (Type, Value, Instance, CallerId, Data);
86 #endif
87 }
88 }
89 return Status;
90 }
91
92 EFI_STATUS
93 ReportStatusCodeWithDevicePath (
94 IN EFI_STATUS_CODE_TYPE Type,
95 IN EFI_STATUS_CODE_VALUE Value,
96 IN UINT32 Instance,
97 IN EFI_GUID * CallerId OPTIONAL,
98 IN EFI_DEVICE_PATH_PROTOCOL * DevicePath
99 )
100 /*++
101
102 Routine Description:
103
104 Report device path through status code.
105
106 Arguments:
107
108 Type - Code type
109 Value - Code value
110 Instance - Instance number
111 CallerId - Caller name
112 DevicePath - Device path that to be reported
113
114 Returns:
115
116 Status code.
117
118 EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
119
120 --*/
121 {
122 UINT16 Size;
123 UINT16 DevicePathSize;
124 EFI_STATUS_CODE_DATA *ExtendedData;
125 EFI_DEVICE_PATH_PROTOCOL *ExtendedDevicePath;
126 EFI_STATUS Status;
127
128 DevicePathSize = (UINT16) EfiDevicePathSize (DevicePath);
129 Size = (UINT16) (DevicePathSize + sizeof (EFI_STATUS_CODE_DATA));
130 ExtendedData = (EFI_STATUS_CODE_DATA *) EfiLibAllocatePool (Size);
131 if (ExtendedData == NULL) {
132 return EFI_OUT_OF_RESOURCES;
133 }
134
135 ExtendedDevicePath = EfiConstructStatusCodeData (Size, &gEfiStatusCodeSpecificDataGuid, ExtendedData);
136 EfiCopyMem (ExtendedDevicePath, DevicePath, DevicePathSize);
137
138 Status = EfiLibReportStatusCode (Type, Value, Instance, CallerId, (EFI_STATUS_CODE_DATA *) ExtendedData);
139
140 gBS->FreePool (ExtendedData);
141 return Status;
142 }