Add comments for all file tagged with "ToolCode="DUMMY"".
[mirror_edk2.git] / EdkModulePkg / Bus / Pci / IdeBus / Dxe / DriverDiagnostics.c
CommitLineData
ed72955c 1/** @file\r
2 Copyright (c) 2006, Intel Corporation \r
3 All rights reserved. This program and the accompanying materials \r
4 are licensed and made available under the terms and conditions of the BSD License \r
5 which accompanies this distribution. The full text of the license may be found at \r
6 http://opensource.org/licenses/bsd-license.php \r
878ddf1f 7\r
ed72955c 8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
878ddf1f 10\r
ed72955c 11**/\r
878ddf1f 12\r
f0ec738d 13#include "idebus.h"\r
878ddf1f 14\r
15#define IDE_BUS_DIAGNOSTIC_ERROR L"PCI IDE/ATAPI Driver Diagnostics Failed"\r
16\r
17//\r
18// EFI Driver Diagnostics Functions\r
19//\r
20EFI_STATUS\r
21IDEBusDriverDiagnosticsRunDiagnostics (\r
22 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
23 IN EFI_HANDLE ControllerHandle,\r
24 IN EFI_HANDLE ChildHandle OPTIONAL,\r
25 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
26 IN CHAR8 *Language,\r
27 OUT EFI_GUID **ErrorType,\r
28 OUT UINTN *BufferSize,\r
29 OUT CHAR16 **Buffer\r
30 );\r
31\r
32//\r
33// EFI Driver Diagnostics Protocol\r
34//\r
35EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics = {\r
36 IDEBusDriverDiagnosticsRunDiagnostics,\r
37 "eng"\r
38};\r
39\r
ed72955c 40/**\r
41 Runs diagnostics on a controller.\r
42\r
43 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL\r
44 instance.\r
45 @param ControllerHandle The handle of the controller to run diagnostics on.\r
46 @param ChildHandle The handle of the child controller to run diagnostics on\r
47 This is an optional parameter that may be NULL. It will\r
48 be NULL for device drivers. It will also be NULL for a\r
49 bus drivers that wish to run diagnostics on the bus\r
50 controller. It will not be NULL for a bus driver that\r
51 wishes to run diagnostics on one of its child\r
52 controllers.\r
53 @param DiagnosticType Indicates type of diagnostics to perform on the\r
54 controller specified by ControllerHandle and ChildHandle.\r
55 See "Related Definitions" for the list of supported\r
56 types.\r
57 @param Language A pointer to a three character ISO 639-2 language\r
58 identifier. This is the language in which the optional\r
59 error message should be returned in Buffer, and it must\r
60 match one of the languages specified in\r
61 SupportedLanguages. The number of languages supported by\r
62 a driver is up to the driver writer.\r
63 @param ErrorType A GUID that defines the format of the data returned in\r
64 Buffer.\r
65 @param BufferSize The size, in bytes, of the data returned in Buffer.\r
66 @param Buffer A buffer that contains a Null-terminated Unicode string\r
67 plus some additional data whose format is defined by\r
68 ErrorType. Buffer is allocated by this function with\r
69 AllocatePool(), and it is the caller's responsibility\r
70 to free it with a call to FreePool().\r
71\r
72 @retval EFI_SUCCESS The controller specified by ControllerHandle and\r
73 ChildHandle passed the diagnostic.\r
74 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
75 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
76 EFI_HANDLE.\r
77 @retval EFI_INVALID_PARAMETER Language is NULL.\r
78 @retval EFI_INVALID_PARAMETER ErrorType is NULL.\r
79 @retval EFI_INVALID_PARAMETER BufferType is NULL.\r
80 @retval EFI_INVALID_PARAMETER Buffer is NULL.\r
81 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
82 running diagnostics for the controller specified\r
83 by ControllerHandle and ChildHandle.\r
84 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
85 type of diagnostic specified by DiagnosticType.\r
86 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
87 language specified by Language.\r
88 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete\r
89 the diagnostics.\r
90 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return\r
91 the status information in ErrorType, BufferSize,\r
92 and Buffer.\r
93 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and\r
94 ChildHandle did not pass the diagnostic.\r
95\r
96**/\r
878ddf1f 97EFI_STATUS\r
98IDEBusDriverDiagnosticsRunDiagnostics (\r
99 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r
100 IN EFI_HANDLE ControllerHandle,\r
101 IN EFI_HANDLE ChildHandle OPTIONAL,\r
102 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r
103 IN CHAR8 *Language,\r
104 OUT EFI_GUID **ErrorType,\r
105 OUT UINTN *BufferSize,\r
106 OUT CHAR16 **Buffer\r
107 )\r
878ddf1f 108{\r
109 EFI_STATUS Status;\r
110 EFI_PCI_IO_PROTOCOL *PciIo;\r
111 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
112 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
113 UINT32 VendorDeviceId;\r
114 VOID *BlockBuffer;\r
115\r
116 *ErrorType = NULL;\r
117 *BufferSize = 0;\r
118\r
119 if (ChildHandle == NULL) {\r
120 Status = gBS->OpenProtocol (\r
121 ControllerHandle,\r
122 &gEfiCallerIdGuid,\r
123 NULL,\r
124 gIDEBusDriverBinding.DriverBindingHandle,\r
125 ControllerHandle,\r
126 EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
127 );\r
128 if (EFI_ERROR (Status)) {\r
129 return EFI_UNSUPPORTED;\r
130 }\r
131\r
132 Status = gBS->OpenProtocol (\r
133 ControllerHandle,\r
134 &gEfiPciIoProtocolGuid,\r
135 (VOID **) &PciIo,\r
136 gIDEBusDriverBinding.DriverBindingHandle,\r
137 ControllerHandle,\r
138 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
139 );\r
140 if (EFI_ERROR (Status)) {\r
141 return EFI_DEVICE_ERROR;\r
142 }\r
143\r
144 //\r
145 // Use services of PCI I/O Protocol to test the PCI IDE/ATAPI Controller\r
146 // The following test simply reads the Device ID and Vendor ID.\r
147 // It should never fail. A real test would perform more advanced\r
148 // diagnostics.\r
149 //\r
150\r
151 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0, 1, &VendorDeviceId);\r
152 if (EFI_ERROR (Status) || VendorDeviceId == 0xffffffff) {\r
153 return EFI_DEVICE_ERROR;\r
154 }\r
155\r
156 return EFI_SUCCESS;\r
157 }\r
158\r
159 Status = gBS->OpenProtocol (\r
160 ChildHandle,\r
161 &gEfiBlockIoProtocolGuid,\r
162 (VOID **) &BlkIo,\r
163 gIDEBusDriverBinding.DriverBindingHandle,\r
164 ChildHandle,\r
165 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
166 );\r
167 if (EFI_ERROR (Status)) {\r
168 return EFI_UNSUPPORTED;\r
169 }\r
170\r
171 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo);\r
172\r
173 //\r
174 // Use services available from IdeBlkIoDevice to test the IDE/ATAPI device\r
175 //\r
176 Status = gBS->AllocatePool (\r
177 EfiBootServicesData,\r
178 IdeBlkIoDevice->BlkMedia.BlockSize,\r
179 (VOID **) &BlockBuffer\r
180 );\r
181 if (EFI_ERROR (Status)) {\r
182 return Status;\r
183 }\r
184\r
185 Status = IdeBlkIoDevice->BlkIo.ReadBlocks (\r
186 &IdeBlkIoDevice->BlkIo,\r
187 IdeBlkIoDevice->BlkMedia.MediaId,\r
188 0,\r
189 IdeBlkIoDevice->BlkMedia.BlockSize,\r
190 BlockBuffer\r
191 );\r
192\r
193 if (EFI_ERROR (Status)) {\r
194 *ErrorType = &gEfiCallerIdGuid;\r
195 *BufferSize = sizeof (IDE_BUS_DIAGNOSTIC_ERROR);\r
196\r
197 Status = gBS->AllocatePool (\r
198 EfiBootServicesData,\r
199 (UINTN) (*BufferSize),\r
200 (VOID **) Buffer\r
201 );\r
202 if (EFI_ERROR (Status)) {\r
203 return Status;\r
204 }\r
205\r
f588bef0 206 CopyMem (*Buffer, IDE_BUS_DIAGNOSTIC_ERROR, *BufferSize);\r
878ddf1f 207\r
208 Status = EFI_DEVICE_ERROR;\r
209 }\r
210\r
211 gBS->FreePool (BlockBuffer);\r
212\r
213 return Status;\r
214}\r