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