]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBus.h
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBusDxe / IdeBus.h
1 /** @file
2 Header file for IDE Bus Driver.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _IDE_BUS_H_
16 #define _IDE_BUS_H_
17
18
19
20 #include <FrameworkDxe.h>
21
22 #include <Protocol/IdeControllerInit.h>
23 #include <Protocol/BlockIo.h>
24 #include <Protocol/PciIo.h>
25 #include <Protocol/DiskInfo.h>
26 #include <Protocol/DevicePath.h>
27
28 #include <Library/DebugLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/BaseLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/ReportStatusCodeLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/PerformanceLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
39
40 #include <Guid/EventGroup.h>
41
42 #include <IndustryStandard/Pci.h>
43 #include "IdeData.h"
44
45 //
46 // Global Variables
47 //
48 extern EFI_DRIVER_BINDING_PROTOCOL gIDEBusDriverBinding;
49 extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics;
50 extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2;
51
52 //
53 // Extra Definition to porting
54 //
55 #define MAX_IDE_DEVICE 4
56 #define MAX_IDE_CHANNELS 2
57 #define MAX_IDE_DRIVES 2
58
59 #define INVALID_DEVICE_TYPE 0xff
60 #define ATA_DEVICE_TYPE 0x00
61 #define ATAPI_DEVICE_TYPE 0x01
62
63 typedef struct {
64 BOOLEAN HaveScannedDevice[MAX_IDE_DEVICE];
65 BOOLEAN DeviceFound[MAX_IDE_DEVICE];
66 BOOLEAN DeviceProcessed[MAX_IDE_DEVICE];
67 } IDE_BUS_DRIVER_PRIVATE_DATA;
68
69 #define IDE_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('i', 'b', 'i', 'd')
70
71 typedef struct {
72 UINT32 Signature;
73
74 EFI_HANDLE Handle;
75 EFI_BLOCK_IO_PROTOCOL BlkIo;
76 EFI_BLOCK_IO_MEDIA BlkMedia;
77 EFI_DISK_INFO_PROTOCOL DiskInfo;
78 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
79 EFI_PCI_IO_PROTOCOL *PciIo;
80 IDE_BUS_DRIVER_PRIVATE_DATA *IdeBusDriverPrivateData;
81
82 //
83 // Local Data for IDE interface goes here
84 //
85 EFI_IDE_CHANNEL Channel;
86 EFI_IDE_DEVICE Device;
87 UINT16 Lun;
88 IDE_DEVICE_TYPE Type;
89
90 IDE_BASE_REGISTERS *IoPort;
91 UINT16 AtapiError;
92
93 ATAPI_INQUIRY_DATA *InquiryData;
94 EFI_IDENTIFY_DATA *IdData;
95 ATA_PIO_MODE PioMode;
96 EFI_ATA_MODE UdmaMode;
97 CHAR8 ModelName[41];
98 ATAPI_REQUEST_SENSE_DATA *SenseData;
99 UINT8 SenseDataNumber;
100 UINT8 *Cache;
101
102 //
103 // ExitBootService Event, it is used to clear pending IDE interrupt
104 //
105 EFI_EVENT ExitBootServiceEvent;
106
107 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
108 } IDE_BLK_IO_DEV;
109
110 #include "ComponentName.h"
111
112 #define IDE_BLOCK_IO_DEV_FROM_THIS(a) CR (a, IDE_BLK_IO_DEV, BlkIo, IDE_BLK_IO_DEV_SIGNATURE)
113 #define IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS(a) CR (a, IDE_BLK_IO_DEV, DiskInfo, IDE_BLK_IO_DEV_SIGNATURE)
114
115 #include "Ide.h"
116
117
118 /**
119 Supported function of Driver Binding protocol for this driver.
120
121 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
122 @param ControllerHandle The handle of the controller to test.
123 @param RemainingDevicePath A pointer to the remaining portion of a device path.
124
125 @retval EFI_SUCCESS Driver loaded.
126 @retval other Driver not loaded.
127
128 **/
129 EFI_STATUS
130 EFIAPI
131 IDEBusDriverBindingSupported (
132 IN EFI_DRIVER_BINDING_PROTOCOL *This,
133 IN EFI_HANDLE Controller,
134 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
135 );
136
137 /**
138 Start function of Driver binding protocol which start this driver on Controller
139 by detecting all disks and installing BlockIo protocol on them.
140
141 @param This Protocol instance pointer.
142 @param Controller Handle of device to bind driver to.
143 @param RemainingDevicePath produce all possible children.
144
145 @retval EFI_SUCCESS This driver is added to ControllerHandle.
146 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
147 @retval other This driver does not support this device.
148
149 **/
150 EFI_STATUS
151 EFIAPI
152 IDEBusDriverBindingStart (
153 IN EFI_DRIVER_BINDING_PROTOCOL *This,
154 IN EFI_HANDLE Controller,
155 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
156 );
157
158 /**
159 Stop function of Driver Binding Protocol which is to stop the driver on Controller Handle and all
160 child handle attached to the controller handle if there are.
161
162 @param This Protocol instance pointer.
163 @param Controller Handle of device to stop driver on
164 @param NumberOfChildren Not used
165 @param ChildHandleBuffer Not used
166
167 @retval EFI_SUCCESS This driver is removed DeviceHandle
168 @retval other This driver was not removed from this device
169
170 **/
171 EFI_STATUS
172 EFIAPI
173 IDEBusDriverBindingStop (
174 IN EFI_DRIVER_BINDING_PROTOCOL *This,
175 IN EFI_HANDLE Controller,
176 IN UINTN NumberOfChildren,
177 IN EFI_HANDLE *ChildHandleBuffer
178 );
179
180 //
181 // EFI Driver Configuration Functions
182 //
183 /**
184 Allows the user to set controller specific options for a controller that a
185 driver is currently managing.
186
187 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
188 @param ControllerHandle The handle of the controller to set options on.
189 @param ChildHandle The handle of the child controller to set options on.
190 This is an optional parameter that may be NULL.
191 It will be NULL for device drivers, and for a bus drivers
192 that wish to set options for the bus controller.
193 It will not be NULL for a bus driver that wishes to set
194 options for one of its child controllers.
195 @param Language A pointer to a three character ISO 639-2 language identifier.
196 This is the language of the user interface that should be presented
197 to the user, and it must match one of the languages specified in
198 SupportedLanguages. The number of languages supported by a driver is up to
199 the driver writer.
200 @param ActionRequired A pointer to the action that the calling agent is required
201 to perform when this function returns.
202
203
204 @retval EFI_SUCCESS The driver specified by This successfully set the configuration
205 options for the controller specified by ControllerHandle..
206 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
207 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
208 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
209 @retval EFI_UNSUPPORTED The driver specified by This does not support setting configuration options for
210 the controller specified by ControllerHandle and ChildHandle.
211 @retval EFI_UNSUPPORTED The driver specified by This does not support the language specified by Language.
212 @retval EFI_DEVICE_ERROR A device error occurred while attempt to set the configuration options for the
213 controller specified by ControllerHandle and ChildHandle.
214 @retval EFI_OUT_RESOURCES There are not enough resources available to set the configuration options for the
215 controller specified by ControllerHandle and ChildHandle
216 **/
217 EFI_STATUS
218 EFIAPI
219 IDEBusDriverConfigurationSetOptions (
220 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
221 IN EFI_HANDLE ControllerHandle,
222 IN EFI_HANDLE ChildHandle OPTIONAL,
223 IN CHAR8 *Language,
224 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
225 );
226
227 /**
228 Tests to see if a controller's current configuration options are valid.
229
230 @param This A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
231 @param ControllerHandle The handle of the controller to test if it's current configuration options
232 are valid.
233 @param ChildHandle The handle of the child controller to test if it's current configuration
234 options are valid. This is an optional parameter that may be NULL. It will
235 be NULL for device drivers. It will also be NULL for a bus drivers that
236 wish to test the configuration options for the bus controller. It will
237 not be NULL for a bus driver that wishes to test configuration options for
238 one of its child controllers.
239 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle that is being
240 managed by the driver specified by This has a valid set of configuration
241 options.
242 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
243 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
244 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing the controller
245 specified by ControllerHandle and ChildHandle.
246 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle that is being
247 managed by the driver specified by This has an invalid set of configuration
248 options.
249 **/
250 EFI_STATUS
251 EFIAPI
252 IDEBusDriverConfigurationOptionsValid (
253 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
254 IN EFI_HANDLE ControllerHandle,
255 IN EFI_HANDLE ChildHandle OPTIONAL
256 );
257
258 /**
259 Forces a driver to set the default configuration options for a controller.
260
261 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
262 @param ControllerHandle The handle of the controller to force default configuration options on.
263 @param ChildHandle The handle of the child controller to force default configuration
264 options on This is an optional parameter that may be NULL. It
265 will be NULL for device drivers. It will also be NULL for a bus
266 drivers that wish to force default configuration options for the bus
267 controller. It will not be NULL for a bus driver that wishes to force
268 default configuration options for one of its child controllers.
269 @param DefaultType The type of default configuration options to force on the controller
270 specified by ControllerHandle and ChildHandle.
271 @param ActionRequired A pointer to the action that the calling agent is required to perform
272 when this function returns.
273
274 @retval EFI_SUCCESS The driver specified by This successfully forced the
275 default configuration options on the controller specified by
276 ControllerHandle and ChildHandle.
277 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
278 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
279 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
280 @retval EFI_UNSUPPORTED The driver specified by This does not support forcing the default
281 configuration options on the controller specified by ControllerHandle
282 and ChildHandle.
283 @retval EFI_UNSUPPORTED The driver specified by This does not support the configuration type
284 specified by DefaultType.
285 @retval EFI_DEVICE_ERROR A device error occurred while attempt to force the default configuration
286 options on the controller specified by ControllerHandle and ChildHandle.
287 @retval EFI_OUT_RESOURCES There are not enough resources available to force the default configuration
288 options on the controller specified by ControllerHandle and ChildHandle.
289 **/
290 EFI_STATUS
291 EFIAPI
292 IDEBusDriverConfigurationForceDefaults (
293 IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
294 IN EFI_HANDLE ControllerHandle,
295 IN EFI_HANDLE ChildHandle OPTIONAL,
296 IN UINT32 DefaultType,
297 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
298 );
299
300 //
301 // EFI Driver Diagnostics Functions
302 //
303 /**
304 Runs diagnostics on a controller.
305
306 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.
307 @param ControllerHandle The handle of the controller to run diagnostics on.
308 @param ChildHandle The handle of the child controller to run diagnostics on
309 This is an optional parameter that may be NULL. It will
310 be NULL for device drivers. It will also be NULL for a
311 bus drivers that wish to run diagnostics on the bus controller.
312 It will not be NULL for a bus driver that wishes to run
313 diagnostics on one of its child controllers.
314 @param DiagnosticType Indicates type of diagnostics to perform on the controller
315 specified by ControllerHandle and ChildHandle.
316 @param Language A pointer to a three character ISO 639-2 language identifier.
317 This is the language in which the optional error message should
318 be returned in Buffer, and it must match one of the languages
319 specified in SupportedLanguages. The number of languages supported by
320 a driver is up to the driver writer.
321 @param ErrorType A GUID that defines the format of the data returned in Buffer.
322 @param BufferSize The size, in bytes, of the data returned in Buffer.
323 @param Buffer A buffer that contains a Null-terminated Unicode string
324 plus some additional data whose format is defined by ErrorType.
325 Buffer is allocated by this function with AllocatePool(), and
326 it is the caller's responsibility to free it with a call to FreePool().
327
328 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed
329 the diagnostic.
330 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
331 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
332 @retval EFI_INVALID_PARAMETER Language is NULL.
333 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
334 @retval EFI_INVALID_PARAMETER BufferType is NULL.
335 @retval EFI_INVALID_PARAMETER Buffer is NULL.
336 @retval EFI_UNSUPPORTED The driver specified by This does not support running
337 diagnostics for the controller specified by ControllerHandle
338 and ChildHandle.
339 @retval EFI_UNSUPPORTED The driver specified by This does not support the
340 type of diagnostic specified by DiagnosticType.
341 @retval EFI_UNSUPPORTED The driver specified by This does not support the language
342 specified by Language.
343 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the
344 diagnostics.
345 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the
346 status information in ErrorType, BufferSize,and Buffer.
347 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle
348 did not pass the diagnostic.
349 **/
350 EFI_STATUS
351 EFIAPI
352 IDEBusDriverDiagnosticsRunDiagnostics (
353 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
354 IN EFI_HANDLE ControllerHandle,
355 IN EFI_HANDLE ChildHandle OPTIONAL,
356 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
357 IN CHAR8 *Language,
358 OUT EFI_GUID **ErrorType,
359 OUT UINTN *BufferSize,
360 OUT CHAR16 **Buffer
361 );
362
363 /**
364 issue ATA or ATAPI command to reset a block IO device.
365 @param This Block IO protocol instance pointer.
366 @param ExtendedVerification If FALSE,for ATAPI device, driver will only invoke ATAPI reset method
367 If TRUE, for ATAPI device, driver need invoke ATA reset method after
368 invoke ATAPI reset method
369
370 @retval EFI_DEVICE_ERROR When the device is neighther ATA device or ATAPI device.
371 @retval EFI_SUCCESS The device reset successfully
372
373 **/
374 EFI_STATUS
375 EFIAPI
376 IDEBlkIoReset (
377 IN EFI_BLOCK_IO_PROTOCOL *This,
378 IN BOOLEAN ExtendedVerification
379 );
380
381 /**
382 Read data from a block IO device.
383
384 @param This Block IO protocol instance pointer.
385 @param MediaId The media ID of the device
386 @param Lba Starting LBA address to read data
387 @param BufferSize The size of data to be read
388 @param Buffer Caller supplied buffer to save data
389
390 @retval EFI_DEVICE_ERROR unknown device type
391 @retval EFI_SUCCESS read the data successfully.
392
393 **/
394 EFI_STATUS
395 EFIAPI
396 IDEBlkIoReadBlocks (
397 IN EFI_BLOCK_IO_PROTOCOL *This,
398 IN UINT32 MediaId,
399 IN EFI_LBA Lba,
400 IN UINTN BufferSize,
401 OUT VOID *Buffer
402 );
403
404 /**
405 Write data to block io device
406
407 @param This Protocol instance pointer.
408 @param MediaId The media ID of the device
409 @param Lba Starting LBA address to write data
410 @param BufferSize The size of data to be written
411 @param Buffer Caller supplied buffer to save data
412
413 @retval EFI_DEVICE_ERROR unknown device type
414 @retval other write data status
415
416 **/
417 EFI_STATUS
418 EFIAPI
419 IDEBlkIoWriteBlocks (
420 IN EFI_BLOCK_IO_PROTOCOL *This,
421 IN UINT32 MediaId,
422 IN EFI_LBA Lba,
423 IN UINTN BufferSize,
424 IN VOID *Buffer
425 );
426
427 /**
428 Flushes all modified data to a physical block devices
429
430 @param This Indicates a pointer to the calling context which to sepcify a
431 sepcific block device
432
433 @retval EFI_SUCCESS Always return success.
434 **/
435 EFI_STATUS
436 EFIAPI
437 IDEBlkIoFlushBlocks (
438 IN EFI_BLOCK_IO_PROTOCOL *This
439 );
440 /**
441 This function is used by the IDE bus driver to get inquiry data.
442 Data format of Identify data is defined by the Interface GUID.
443
444 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
445 @param InquiryData Pointer to a buffer for the inquiry data.
446 @param InquiryDataSize Pointer to the value for the inquiry data size.
447
448 @retval EFI_SUCCESS The command was accepted without any errors.
449 @retval EFI_NOT_FOUND Device does not support this data class
450 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
451 @retval EFI_BUFFER_TOO_SMALL IntquiryDataSize not big enough
452
453 **/
454 EFI_STATUS
455 EFIAPI
456 IDEDiskInfoInquiry (
457 IN EFI_DISK_INFO_PROTOCOL *This,
458 IN OUT VOID *InquiryData,
459 IN OUT UINT32 *InquiryDataSize
460 );
461
462 /**
463 This function is used by the IDE bus driver to get identify data.
464 Data format of Identify data is defined by the Interface GUID.
465
466 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
467 @param IdentifyData Pointer to a buffer for the identify data.
468 @param IdentifyDataSize Pointer to the value for the identify data size.
469
470 @retval EFI_SUCCESS The command was accepted without any errors.
471 @retval EFI_NOT_FOUND Device does not support this data class
472 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
473 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
474
475 **/
476 EFI_STATUS
477 EFIAPI
478 IDEDiskInfoIdentify (
479 IN EFI_DISK_INFO_PROTOCOL *This,
480 IN OUT VOID *IdentifyData,
481 IN OUT UINT32 *IdentifyDataSize
482 );
483
484 /**
485 This function is used by the IDE bus driver to get sense data.
486 Data format of Sense data is defined by the Interface GUID.
487
488 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
489 @param SenseData Pointer to the SenseData.
490 @param SenseDataSize Size of SenseData in bytes.
491 @param SenseDataNumber Pointer to the value for the identify data size.
492
493 @retval EFI_SUCCESS The command was accepted without any errors.
494 @retval EFI_NOT_FOUND Device does not support this data class
495 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
496 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough
497
498 **/
499 EFI_STATUS
500 EFIAPI
501 IDEDiskInfoSenseData (
502 IN EFI_DISK_INFO_PROTOCOL *This,
503 IN OUT VOID *SenseData,
504 IN OUT UINT32 *SenseDataSize,
505 OUT UINT8 *SenseDataNumber
506 );
507
508 /**
509 This function is used by the IDE bus driver to get controller information.
510
511 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
512 @param IdeChannel Pointer to the Ide Channel number. Primary or secondary.
513 @param IdeDevice Pointer to the Ide Device number. Master or slave.
514
515 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid
516 @retval EFI_UNSUPPORTED This is not an IDE device
517
518 **/
519 EFI_STATUS
520 EFIAPI
521 IDEDiskInfoWhichIde (
522 IN EFI_DISK_INFO_PROTOCOL *This,
523 OUT UINT32 *IdeChannel,
524 OUT UINT32 *IdeDevice
525 );
526 /**
527 The is an event(generally the event is exitBootService event) call back function.
528 Clear pending IDE interrupt before OS loader/kernel take control of the IDE device.
529
530 @param Event Pointer to this event
531 @param Context Event handler private data
532
533 **/
534 VOID
535 EFIAPI
536 ClearInterrupt (
537 IN EFI_EVENT Event,
538 IN VOID *Context
539 );
540 #endif