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