]>
Commit | Line | Data |
---|---|---|
ead42efc | 1 | /** @file\r |
2 | Header file for IDE Bus Driver.\r | |
3 | \r | |
0a6f4824 | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
c0a00b14 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ead42efc | 6 | \r |
7 | **/\r | |
8 | \r | |
eeefcb9d | 9 | #ifndef _IDE_BUS_H_\r |
10 | #define _IDE_BUS_H_\r | |
ead42efc | 11 | \r |
12 | \r | |
ed7748fe | 13 | \r |
694b922c | 14 | #include <FrameworkDxe.h>\r |
ed7748fe | 15 | \r |
ead42efc | 16 | #include <Protocol/IdeControllerInit.h>\r |
17 | #include <Protocol/BlockIo.h>\r | |
18 | #include <Protocol/PciIo.h>\r | |
19 | #include <Protocol/DiskInfo.h>\r | |
20 | #include <Protocol/DevicePath.h>\r | |
ed7748fe | 21 | \r |
ead42efc | 22 | #include <Library/DebugLib.h>\r |
23 | #include <Library/UefiDriverEntryPoint.h>\r | |
24 | #include <Library/BaseLib.h>\r | |
25 | #include <Library/UefiLib.h>\r | |
26 | #include <Library/BaseMemoryLib.h>\r | |
27 | #include <Library/ReportStatusCodeLib.h>\r | |
28 | #include <Library/MemoryAllocationLib.h>\r | |
29 | #include <Library/PerformanceLib.h>\r | |
30 | #include <Library/UefiBootServicesTableLib.h>\r | |
31 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
32 | #include <Library/DevicePathLib.h>\r | |
33 | \r | |
6a27a4eb | 34 | #include <Guid/EventGroup.h>\r |
35 | \r | |
7d1aa703 | 36 | #include <IndustryStandard/Pci.h>\r |
e89cde87 | 37 | #include "IdeData.h"\r |
ead42efc | 38 | \r |
9f6531d1 | 39 | //\r |
40 | // Global Variables\r | |
41 | //\r | |
42 | extern EFI_DRIVER_BINDING_PROTOCOL gIDEBusDriverBinding;\r | |
43 | extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics;\r | |
44 | extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2;\r | |
45 | \r | |
ead42efc | 46 | //\r |
47 | // Extra Definition to porting\r | |
48 | //\r | |
ead42efc | 49 | #define MAX_IDE_DEVICE 4\r |
50 | #define MAX_IDE_CHANNELS 2\r | |
51 | #define MAX_IDE_DRIVES 2\r | |
52 | \r | |
53 | #define INVALID_DEVICE_TYPE 0xff\r | |
54 | #define ATA_DEVICE_TYPE 0x00\r | |
55 | #define ATAPI_DEVICE_TYPE 0x01\r | |
56 | \r | |
57 | typedef struct {\r | |
58 | BOOLEAN HaveScannedDevice[MAX_IDE_DEVICE];\r | |
59 | BOOLEAN DeviceFound[MAX_IDE_DEVICE];\r | |
60 | BOOLEAN DeviceProcessed[MAX_IDE_DEVICE];\r | |
61 | } IDE_BUS_DRIVER_PRIVATE_DATA;\r | |
62 | \r | |
f02bd376 | 63 | #define IDE_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('i', 'b', 'i', 'd')\r |
ead42efc | 64 | \r |
65 | typedef struct {\r | |
66 | UINT32 Signature;\r | |
67 | \r | |
68 | EFI_HANDLE Handle;\r | |
69 | EFI_BLOCK_IO_PROTOCOL BlkIo;\r | |
70 | EFI_BLOCK_IO_MEDIA BlkMedia;\r | |
71 | EFI_DISK_INFO_PROTOCOL DiskInfo;\r | |
72 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
73 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
74 | IDE_BUS_DRIVER_PRIVATE_DATA *IdeBusDriverPrivateData;\r | |
75 | \r | |
76 | //\r | |
77 | // Local Data for IDE interface goes here\r | |
78 | //\r | |
79 | EFI_IDE_CHANNEL Channel;\r | |
80 | EFI_IDE_DEVICE Device;\r | |
81 | UINT16 Lun;\r | |
82 | IDE_DEVICE_TYPE Type;\r | |
83 | \r | |
84 | IDE_BASE_REGISTERS *IoPort;\r | |
85 | UINT16 AtapiError;\r | |
86 | \r | |
e72ca438 | 87 | ATAPI_INQUIRY_DATA *InquiryData;\r |
88 | EFI_IDENTIFY_DATA *IdData;\r | |
ead42efc | 89 | ATA_PIO_MODE PioMode;\r |
90 | EFI_ATA_MODE UdmaMode;\r | |
91 | CHAR8 ModelName[41];\r | |
1e23bd8d | 92 | ATAPI_REQUEST_SENSE_DATA *SenseData;\r |
ead42efc | 93 | UINT8 SenseDataNumber;\r |
94 | UINT8 *Cache;\r | |
95 | \r | |
96 | //\r | |
97 | // ExitBootService Event, it is used to clear pending IDE interrupt\r | |
98 | //\r | |
99 | EFI_EVENT ExitBootServiceEvent;\r | |
100 | \r | |
101 | EFI_UNICODE_STRING_TABLE *ControllerNameTable;\r | |
102 | } IDE_BLK_IO_DEV;\r | |
103 | \r | |
104 | #include "ComponentName.h"\r | |
105 | \r | |
106 | #define IDE_BLOCK_IO_DEV_FROM_THIS(a) CR (a, IDE_BLK_IO_DEV, BlkIo, IDE_BLK_IO_DEV_SIGNATURE)\r | |
107 | #define IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS(a) CR (a, IDE_BLK_IO_DEV, DiskInfo, IDE_BLK_IO_DEV_SIGNATURE)\r | |
108 | \r | |
e89cde87 | 109 | #include "Ide.h"\r |
ead42efc | 110 | \r |
ead42efc | 111 | \r |
112 | /**\r | |
630d580d | 113 | Supported function of Driver Binding protocol for this driver.\r |
ead42efc | 114 | \r |
630d580d | 115 | @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
116 | @param ControllerHandle The handle of the controller to test.\r | |
117 | @param RemainingDevicePath A pointer to the remaining portion of a device path.\r | |
ead42efc | 118 | \r |
630d580d | 119 | @retval EFI_SUCCESS Driver loaded.\r |
120 | @retval other Driver not loaded.\r | |
ead42efc | 121 | \r |
122 | **/\r | |
123 | EFI_STATUS\r | |
124 | EFIAPI\r | |
125 | IDEBusDriverBindingSupported (\r | |
126 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
127 | IN EFI_HANDLE Controller,\r | |
128 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
ed66e1bc | 129 | );\r |
ead42efc | 130 | \r |
131 | /**\r | |
630d580d | 132 | Start function of Driver binding protocol which start this driver on Controller\r |
133 | by detecting all disks and installing BlockIo protocol on them.\r | |
ead42efc | 134 | \r |
630d580d | 135 | @param This Protocol instance pointer.\r |
136 | @param Controller Handle of device to bind driver to.\r | |
137 | @param RemainingDevicePath produce all possible children.\r | |
ead42efc | 138 | \r |
630d580d | 139 | @retval EFI_SUCCESS This driver is added to ControllerHandle.\r |
140 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r | |
141 | @retval other This driver does not support this device.\r | |
ead42efc | 142 | \r |
143 | **/\r | |
144 | EFI_STATUS\r | |
145 | EFIAPI\r | |
146 | IDEBusDriverBindingStart (\r | |
147 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
148 | IN EFI_HANDLE Controller,\r | |
149 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
ed66e1bc | 150 | );\r |
ead42efc | 151 | \r |
152 | /**\r | |
630d580d | 153 | Stop function of Driver Binding Protocol which is to stop the driver on Controller Handle and all\r |
154 | child handle attached to the controller handle if there are.\r | |
ead42efc | 155 | \r |
630d580d | 156 | @param This Protocol instance pointer.\r |
157 | @param Controller Handle of device to stop driver on\r | |
158 | @param NumberOfChildren Not used\r | |
159 | @param ChildHandleBuffer Not used\r | |
ead42efc | 160 | \r |
630d580d | 161 | @retval EFI_SUCCESS This driver is removed DeviceHandle\r |
162 | @retval other This driver was not removed from this device\r | |
ead42efc | 163 | \r |
164 | **/\r | |
165 | EFI_STATUS\r | |
166 | EFIAPI\r | |
167 | IDEBusDriverBindingStop (\r | |
168 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
169 | IN EFI_HANDLE Controller,\r | |
170 | IN UINTN NumberOfChildren,\r | |
171 | IN EFI_HANDLE *ChildHandleBuffer\r | |
ed66e1bc | 172 | );\r |
ead42efc | 173 | \r |
174 | //\r | |
175 | // EFI Driver Configuration Functions\r | |
176 | //\r | |
ead42efc | 177 | \r |
ead42efc | 178 | \r |
ef3b352c | 179 | \r |
ead42efc | 180 | \r |
181 | //\r | |
182 | // EFI Driver Diagnostics Functions\r | |
183 | //\r | |
eeefcb9d | 184 | /**\r |
630d580d | 185 | Runs diagnostics on a controller.\r |
186 | \r | |
187 | @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.\r | |
188 | @param ControllerHandle The handle of the controller to run diagnostics on.\r | |
189 | @param ChildHandle The handle of the child controller to run diagnostics on\r | |
190 | This is an optional parameter that may be NULL. It will\r | |
191 | be NULL for device drivers. It will also be NULL for a\r | |
0a6f4824 LG |
192 | bus drivers that wish to run diagnostics on the bus controller.\r |
193 | It will not be NULL for a bus driver that wishes to run\r | |
630d580d | 194 | diagnostics on one of its child controllers.\r |
195 | @param DiagnosticType Indicates type of diagnostics to perform on the controller\r | |
196 | specified by ControllerHandle and ChildHandle.\r | |
0a6f4824 LG |
197 | @param Language A pointer to a three character ISO 639-2 language identifier.\r |
198 | This is the language in which the optional error message should\r | |
199 | be returned in Buffer, and it must match one of the languages\r | |
630d580d | 200 | specified in SupportedLanguages. The number of languages supported by\r |
201 | a driver is up to the driver writer.\r | |
202 | @param ErrorType A GUID that defines the format of the data returned in Buffer.\r | |
203 | @param BufferSize The size, in bytes, of the data returned in Buffer.\r | |
204 | @param Buffer A buffer that contains a Null-terminated Unicode string\r | |
0a6f4824 LG |
205 | plus some additional data whose format is defined by ErrorType.\r |
206 | Buffer is allocated by this function with AllocatePool(), and\r | |
630d580d | 207 | it is the caller's responsibility to free it with a call to FreePool().\r |
208 | \r | |
0a6f4824 | 209 | @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed\r |
630d580d | 210 | the diagnostic.\r |
c2d9a4d2 | 211 | @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r |
630d580d | 212 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r |
213 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
214 | @retval EFI_INVALID_PARAMETER ErrorType is NULL.\r | |
215 | @retval EFI_INVALID_PARAMETER BufferType is NULL.\r | |
216 | @retval EFI_INVALID_PARAMETER Buffer is NULL.\r | |
0a6f4824 LG |
217 | @retval EFI_UNSUPPORTED The driver specified by This does not support running\r |
218 | diagnostics for the controller specified by ControllerHandle\r | |
630d580d | 219 | and ChildHandle.\r |
220 | @retval EFI_UNSUPPORTED The driver specified by This does not support the\r | |
221 | type of diagnostic specified by DiagnosticType.\r | |
0a6f4824 | 222 | @retval EFI_UNSUPPORTED The driver specified by This does not support the language\r |
630d580d | 223 | specified by Language.\r |
0a6f4824 | 224 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the\r |
630d580d | 225 | diagnostics.\r |
0a6f4824 | 226 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the\r |
630d580d | 227 | status information in ErrorType, BufferSize,and Buffer.\r |
0a6f4824 | 228 | @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle\r |
630d580d | 229 | did not pass the diagnostic.\r |
eeefcb9d | 230 | **/\r |
ead42efc | 231 | EFI_STATUS\r |
6ba0bc7c | 232 | EFIAPI\r |
ead42efc | 233 | IDEBusDriverDiagnosticsRunDiagnostics (\r |
234 | IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,\r | |
235 | IN EFI_HANDLE ControllerHandle,\r | |
236 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
237 | IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,\r | |
238 | IN CHAR8 *Language,\r | |
239 | OUT EFI_GUID **ErrorType,\r | |
240 | OUT UINTN *BufferSize,\r | |
241 | OUT CHAR16 **Buffer\r | |
242 | );\r | |
243 | \r | |
ead42efc | 244 | /**\r |
630d580d | 245 | issue ATA or ATAPI command to reset a block IO device.\r |
246 | @param This Block IO protocol instance pointer.\r | |
247 | @param ExtendedVerification If FALSE,for ATAPI device, driver will only invoke ATAPI reset method\r | |
248 | If TRUE, for ATAPI device, driver need invoke ATA reset method after\r | |
249 | invoke ATAPI reset method\r | |
ead42efc | 250 | \r |
630d580d | 251 | @retval EFI_DEVICE_ERROR When the device is neighther ATA device or ATAPI device.\r |
252 | @retval EFI_SUCCESS The device reset successfully\r | |
ead42efc | 253 | \r |
254 | **/\r | |
255 | EFI_STATUS\r | |
256 | EFIAPI\r | |
257 | IDEBlkIoReset (\r | |
258 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
259 | IN BOOLEAN ExtendedVerification\r | |
ed66e1bc | 260 | );\r |
ead42efc | 261 | \r |
262 | /**\r | |
cd57e888 | 263 | Read data from a block IO device.\r |
ead42efc | 264 | \r |
630d580d | 265 | @param This Block IO protocol instance pointer.\r |
266 | @param MediaId The media ID of the device\r | |
cd57e888 | 267 | @param Lba Starting LBA address to read data\r |
630d580d | 268 | @param BufferSize The size of data to be read\r |
269 | @param Buffer Caller supplied buffer to save data\r | |
ead42efc | 270 | \r |
630d580d | 271 | @retval EFI_DEVICE_ERROR unknown device type\r |
272 | @retval EFI_SUCCESS read the data successfully.\r | |
ead42efc | 273 | \r |
274 | **/\r | |
275 | EFI_STATUS\r | |
276 | EFIAPI\r | |
277 | IDEBlkIoReadBlocks (\r | |
278 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
279 | IN UINT32 MediaId,\r | |
e72ca438 | 280 | IN EFI_LBA Lba,\r |
ead42efc | 281 | IN UINTN BufferSize,\r |
282 | OUT VOID *Buffer\r | |
ed66e1bc | 283 | );\r |
ead42efc | 284 | \r |
285 | /**\r | |
630d580d | 286 | Write data to block io device\r |
ead42efc | 287 | \r |
630d580d | 288 | @param This Protocol instance pointer.\r |
289 | @param MediaId The media ID of the device\r | |
cd57e888 | 290 | @param Lba Starting LBA address to write data\r |
630d580d | 291 | @param BufferSize The size of data to be written\r |
292 | @param Buffer Caller supplied buffer to save data\r | |
ead42efc | 293 | \r |
630d580d | 294 | @retval EFI_DEVICE_ERROR unknown device type\r |
295 | @retval other write data status\r | |
ead42efc | 296 | \r |
297 | **/\r | |
298 | EFI_STATUS\r | |
299 | EFIAPI\r | |
300 | IDEBlkIoWriteBlocks (\r | |
301 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
302 | IN UINT32 MediaId,\r | |
e72ca438 | 303 | IN EFI_LBA Lba,\r |
ead42efc | 304 | IN UINTN BufferSize,\r |
305 | IN VOID *Buffer\r | |
ed66e1bc | 306 | );\r |
ead42efc | 307 | \r |
308 | /**\r | |
630d580d | 309 | Flushes all modified data to a physical block devices\r |
ead42efc | 310 | \r |
0a6f4824 | 311 | @param This Indicates a pointer to the calling context which to sepcify a\r |
630d580d | 312 | sepcific block device\r |
ead42efc | 313 | \r |
630d580d | 314 | @retval EFI_SUCCESS Always return success.\r |
ead42efc | 315 | **/\r |
316 | EFI_STATUS\r | |
317 | EFIAPI\r | |
318 | IDEBlkIoFlushBlocks (\r | |
319 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
ed66e1bc | 320 | );\r |
ead42efc | 321 | /**\r |
0a6f4824 | 322 | This function is used by the IDE bus driver to get inquiry data.\r |
bab0c17a | 323 | Data format of Identify data is defined by the Interface GUID.\r |
ead42efc | 324 | \r |
bab0c17a | 325 | @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
326 | @param InquiryData Pointer to a buffer for the inquiry data.\r | |
327 | @param InquiryDataSize Pointer to the value for the inquiry data size.\r | |
ead42efc | 328 | \r |
bab0c17a | 329 | @retval EFI_SUCCESS The command was accepted without any errors.\r |
0a6f4824 LG |
330 | @retval EFI_NOT_FOUND Device does not support this data class\r |
331 | @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r | |
332 | @retval EFI_BUFFER_TOO_SMALL IntquiryDataSize not big enough\r | |
ead42efc | 333 | \r |
334 | **/\r | |
335 | EFI_STATUS\r | |
336 | EFIAPI\r | |
337 | IDEDiskInfoInquiry (\r | |
338 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
339 | IN OUT VOID *InquiryData,\r | |
cd57e888 | 340 | IN OUT UINT32 *InquiryDataSize\r |
ed66e1bc | 341 | );\r |
ead42efc | 342 | \r |
343 | /**\r | |
0a6f4824 | 344 | This function is used by the IDE bus driver to get identify data.\r |
630d580d | 345 | Data format of Identify data is defined by the Interface GUID.\r |
ead42efc | 346 | \r |
bab0c17a | 347 | @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
348 | @param IdentifyData Pointer to a buffer for the identify data.\r | |
349 | @param IdentifyDataSize Pointer to the value for the identify data size.\r | |
ead42efc | 350 | \r |
bab0c17a | 351 | @retval EFI_SUCCESS The command was accepted without any errors.\r |
0a6f4824 LG |
352 | @retval EFI_NOT_FOUND Device does not support this data class\r |
353 | @retval EFI_DEVICE_ERROR Error reading IdentifyData from device\r | |
354 | @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough\r | |
ead42efc | 355 | \r |
356 | **/\r | |
357 | EFI_STATUS\r | |
358 | EFIAPI\r | |
359 | IDEDiskInfoIdentify (\r | |
360 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
361 | IN OUT VOID *IdentifyData,\r | |
362 | IN OUT UINT32 *IdentifyDataSize\r | |
ed66e1bc | 363 | );\r |
ead42efc | 364 | \r |
365 | /**\r | |
0a6f4824 | 366 | This function is used by the IDE bus driver to get sense data.\r |
630d580d | 367 | Data format of Sense data is defined by the Interface GUID.\r |
ead42efc | 368 | \r |
0a6f4824 LG |
369 | @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
370 | @param SenseData Pointer to the SenseData.\r | |
371 | @param SenseDataSize Size of SenseData in bytes.\r | |
bab0c17a | 372 | @param SenseDataNumber Pointer to the value for the identify data size.\r |
ead42efc | 373 | \r |
bab0c17a | 374 | @retval EFI_SUCCESS The command was accepted without any errors.\r |
0a6f4824 LG |
375 | @retval EFI_NOT_FOUND Device does not support this data class\r |
376 | @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r | |
377 | @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough\r | |
ead42efc | 378 | \r |
379 | **/\r | |
380 | EFI_STATUS\r | |
381 | EFIAPI\r | |
382 | IDEDiskInfoSenseData (\r | |
383 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
384 | IN OUT VOID *SenseData,\r | |
385 | IN OUT UINT32 *SenseDataSize,\r | |
386 | OUT UINT8 *SenseDataNumber\r | |
ed66e1bc | 387 | );\r |
ead42efc | 388 | \r |
389 | /**\r | |
bab0c17a | 390 | This function is used by the IDE bus driver to get controller information.\r |
ead42efc | 391 | \r |
0a6f4824 | 392 | @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
bab0c17a | 393 | @param IdeChannel Pointer to the Ide Channel number. Primary or secondary.\r |
394 | @param IdeDevice Pointer to the Ide Device number. Master or slave.\r | |
ead42efc | 395 | \r |
0a6f4824 LG |
396 | @retval EFI_SUCCESS IdeChannel and IdeDevice are valid\r |
397 | @retval EFI_UNSUPPORTED This is not an IDE device\r | |
ead42efc | 398 | \r |
399 | **/\r | |
400 | EFI_STATUS\r | |
401 | EFIAPI\r | |
402 | IDEDiskInfoWhichIde (\r | |
403 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
404 | OUT UINT32 *IdeChannel,\r | |
405 | OUT UINT32 *IdeDevice\r | |
ed66e1bc | 406 | );\r |
630d580d | 407 | /**\r |
0a6f4824 | 408 | The is an event(generally the event is exitBootService event) call back function.\r |
630d580d | 409 | Clear pending IDE interrupt before OS loader/kernel take control of the IDE device.\r |
410 | \r | |
411 | @param Event Pointer to this event\r | |
e3644786 | 412 | @param Context Event handler private data\r |
ead42efc | 413 | \r |
630d580d | 414 | **/\r |
415 | VOID\r | |
416 | EFIAPI\r | |
417 | ClearInterrupt (\r | |
418 | IN EFI_EVENT Event,\r | |
419 | IN VOID *Context\r | |
420 | );\r | |
ead42efc | 421 | #endif\r |