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