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