]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/Dxe/EfiDriverLib/ReportStatusCode.c
Add in the 1st version of ECP.
[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 #if (EFI_SPECIFICATION_VERSION >= 0x00020000)
27 STATIC EFI_STATUS_CODE_PROTOCOL *gStatusCode = NULL;
28 #endif
29
30 EFI_STATUS
31 EfiLibReportStatusCode (
32 IN EFI_STATUS_CODE_TYPE Type,
33 IN EFI_STATUS_CODE_VALUE Value,
34 IN UINT32 Instance,
35 IN EFI_GUID *CallerId OPTIONAL,
36 IN EFI_STATUS_CODE_DATA *Data OPTIONAL
37 )
38 /*++
39
40 Routine Description:
41
42 Report device path through status code.
43
44 Arguments:
45
46 Type - Code type
47 Value - Code value
48 Instance - Instance number
49 CallerId - Caller name
50 DevicePath - Device path that to be reported
51
52 Returns:
53
54 Status code.
55
56 EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
57
58 --*/
59 {
60 EFI_STATUS Status;
61
62 #if (EFI_SPECIFICATION_VERSION >= 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 return Status;
74 #else
75 if (gRT == NULL) {
76 return EFI_UNSUPPORTED;
77 }
78 //
79 // Check whether EFI_RUNTIME_SERVICES has Tiano Extension
80 //
81 Status = EFI_UNSUPPORTED;
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 }
87 return Status;
88 #endif
89 }
90
91 EFI_STATUS
92 ReportStatusCodeWithDevicePath (
93 IN EFI_STATUS_CODE_TYPE Type,
94 IN EFI_STATUS_CODE_VALUE Value,
95 IN UINT32 Instance,
96 IN EFI_GUID * CallerId OPTIONAL,
97 IN EFI_DEVICE_PATH_PROTOCOL * DevicePath
98 )
99 /*++
100
101 Routine Description:
102
103 Report device path through status code.
104
105 Arguments:
106
107 Type - Code type
108 Value - Code value
109 Instance - Instance number
110 CallerId - Caller name
111 DevicePath - Device path that to be reported
112
113 Returns:
114
115 Status code.
116
117 EFI_OUT_OF_RESOURCES - No enough buffer could be allocated
118
119 --*/
120 {
121 UINT16 Size;
122 UINT16 DevicePathSize;
123 EFI_STATUS_CODE_DATA *ExtendedData;
124 EFI_DEVICE_PATH_PROTOCOL *ExtendedDevicePath;
125 EFI_STATUS Status;
126
127 DevicePathSize = (UINT16) EfiDevicePathSize (DevicePath);
128 Size = DevicePathSize + sizeof (EFI_STATUS_CODE_DATA);
129 ExtendedData = (EFI_STATUS_CODE_DATA *) EfiLibAllocatePool (Size);
130 if (ExtendedData == NULL) {
131 return EFI_OUT_OF_RESOURCES;
132 }
133
134 ExtendedDevicePath = EfiConstructStatusCodeData (Size, &gEfiStatusCodeSpecificDataGuid, ExtendedData);
135 EfiCopyMem (ExtendedDevicePath, DevicePath, DevicePathSize);
136
137 Status = EfiLibReportStatusCode (Type, Value, Instance, CallerId, (EFI_STATUS_CODE_DATA *) ExtendedData);
138
139 gBS->FreePool (ExtendedData);
140 return Status;
141 }