]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SataControllerDxe/SataController.h
cb1abacfdc0fda6d698badb95e68f12276c13a16
[mirror_edk2.git] / OvmfPkg / SataControllerDxe / SataController.h
1 /** @file
2 Header file for Sata Controller driver.
3
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _SATA_CONTROLLER_H_
10 #define _SATA_CONTROLLER_H_
11
12 #include <Uefi.h>
13 #include <Protocol/ComponentName.h>
14 #include <Protocol/DriverBinding.h>
15 #include <Protocol/PciIo.h>
16 #include <Protocol/IdeControllerInit.h>
17 #include <Library/UefiDriverEntryPoint.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <IndustryStandard/Pci.h>
25
26 //
27 // Global Variables definitions
28 //
29 extern EFI_DRIVER_BINDING_PROTOCOL gSataControllerDriverBinding;
30 extern EFI_COMPONENT_NAME_PROTOCOL gSataControllerComponentName;
31 extern EFI_COMPONENT_NAME2_PROTOCOL gSataControllerComponentName2;
32
33 #define AHCI_BAR_INDEX 0x05
34 #define R_AHCI_CAP 0x0
35 #define B_AHCI_CAP_NPS (BIT4 | BIT3 | BIT2 | BIT1 | BIT0) // Number of Ports
36 #define B_AHCI_CAP_SPM BIT17 // Supports Port Multiplier
37
38 ///
39 /// AHCI each channel can have up to 1 device
40 ///
41 #define AHCI_MAX_DEVICES 0x01
42
43 ///
44 /// AHCI each channel can have 15 devices in the presence of a multiplier
45 ///
46 #define AHCI_MULTI_MAX_DEVICES 0x0F
47
48 ///
49 /// IDE supports 2 channel max
50 ///
51 #define IDE_MAX_CHANNEL 0x02
52
53 ///
54 /// IDE supports 2 devices max
55 ///
56 #define IDE_MAX_DEVICES 0x02
57
58 #define SATA_ENUMER_ALL FALSE
59
60 //
61 // Sata Controller driver private data structure
62 //
63
64 #define SATA_CONTROLLER_SIGNATURE SIGNATURE_32('S','A','T','A')
65
66 typedef struct _EFI_SATA_CONTROLLER_PRIVATE_DATA {
67 //
68 // Standard signature used to identify Sata Controller private data
69 //
70 UINT32 Signature;
71
72 //
73 // Protocol instance of IDE_CONTROLLER_INIT produced by this driver
74 //
75 EFI_IDE_CONTROLLER_INIT_PROTOCOL IdeInit;
76
77 //
78 // Copy of protocol pointers used by this driver
79 //
80 EFI_PCI_IO_PROTOCOL *PciIo;
81
82 //
83 // Original PCI attributes
84 //
85 UINT64 OriginalPciAttributes;
86
87 //
88 // The number of devices that are supported by this channel
89 //
90 UINT8 DeviceCount;
91
92 //
93 // The highest disqulified mode for each attached device,
94 // From ATA/ATAPI spec, if a mode is not supported,
95 // the modes higher than it is also not supported
96 //
97 EFI_ATA_COLLECTIVE_MODE *DisqualifiedModes;
98
99 //
100 // A copy of EFI_IDENTIFY_DATA data for each attached SATA device and its flag
101 //
102 EFI_IDENTIFY_DATA *IdentifyData;
103 BOOLEAN *IdentifyValid;
104 } EFI_SATA_CONTROLLER_PRIVATE_DATA;
105
106 #define SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) CR(a, EFI_SATA_CONTROLLER_PRIVATE_DATA, IdeInit, SATA_CONTROLLER_SIGNATURE)
107
108 //
109 // Driver binding functions declaration
110 //
111
112 /**
113 Supported function of Driver Binding protocol for this driver.
114 Test to see if this driver supports ControllerHandle.
115
116 @param This Protocol instance pointer.
117 @param Controller Handle of device to test.
118 @param RemainingDevicePath A pointer to the device path. Should be ignored by
119 device driver.
120
121 @retval EFI_SUCCESS This driver supports this device.
122 @retval EFI_ALREADY_STARTED This driver is already running on this device.
123 @retval other This driver does not support this device.
124
125 **/
126 EFI_STATUS
127 EFIAPI
128 SataControllerSupported (
129 IN EFI_DRIVER_BINDING_PROTOCOL *This,
130 IN EFI_HANDLE Controller,
131 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
132 )
133 ;
134
135 /**
136 This routine is called right after the .Supported() called and
137 Start this driver on ControllerHandle.
138
139 @param This Protocol instance pointer.
140 @param Controller Handle of device to bind driver to.
141 @param RemainingDevicePath A pointer to the device path. Should be ignored by
142 device driver.
143
144 @retval EFI_SUCCESS This driver is added to this device.
145 @retval EFI_ALREADY_STARTED This driver is already running on this device.
146 @retval other Some error occurs when binding this driver to this device.
147
148 **/
149 EFI_STATUS
150 EFIAPI
151 SataControllerStart (
152 IN EFI_DRIVER_BINDING_PROTOCOL *This,
153 IN EFI_HANDLE Controller,
154 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
155 )
156 ;
157
158 /**
159 Stop this driver on ControllerHandle.
160
161 @param This Protocol instance pointer.
162 @param Controller Handle of device to stop driver on.
163 @param NumberOfChildren Not used.
164 @param ChildHandleBuffer Not used.
165
166 @retval EFI_SUCCESS This driver is removed from this device.
167 @retval other Some error occurs when removing this driver from this device.
168
169 **/
170 EFI_STATUS
171 EFIAPI
172 SataControllerStop (
173 IN EFI_DRIVER_BINDING_PROTOCOL *This,
174 IN EFI_HANDLE Controller,
175 IN UINTN NumberOfChildren,
176 IN EFI_HANDLE *ChildHandleBuffer
177 )
178 ;
179
180 //
181 // IDE controller init functions declaration
182 //
183
184 /**
185 Returns the information about the specified IDE channel.
186
187 This function can be used to obtain information about a particular IDE channel.
188 The driver entity uses this information during the enumeration process.
189
190 If Enabled is set to FALSE, the driver entity will not scan the channel. Note
191 that it will not prevent an operating system driver from scanning the channel.
192
193 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
194 controllers, this value will always be 1. SATA configurations can contain SATA
195 port multipliers. SATA port multipliers behave like SATA bridges and can support
196 up to 16 devices on the other side. If a SATA port out of the IDE controller
197 is connected to a port multiplier, MaxDevices will be set to the number of SATA
198 devices that the port multiplier supports. Because today's port multipliers
199 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
200 bus driver is required to scan for the presence of port multipliers behind an SATA
201 controller and enumerate up to MaxDevices number of devices behind the port
202 multiplier.
203
204 In this context, the devices behind a port multiplier constitute a channel.
205
206 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
207 @param[in] Channel Zero-based channel number.
208 @param[out] Enabled TRUE if this channel is enabled. Disabled channels
209 are not scanned to see if any devices are present.
210 @param[out] MaxDevices The maximum number of IDE devices that the bus driver
211 can expect on this channel. For the ATA/ATAPI
212 specification, version 6, this number will either be
213 one or two. For Serial ATA (SATA) configurations with a
214 port multiplier, this number can be as large as fifteen.
215
216 @retval EFI_SUCCESS Information was returned without any errors.
217 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
218
219 **/
220 EFI_STATUS
221 EFIAPI
222 IdeInitGetChannelInfo (
223 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
224 IN UINT8 Channel,
225 OUT BOOLEAN *Enabled,
226 OUT UINT8 *MaxDevices
227 )
228 ;
229
230 /**
231 The notifications from the driver entity that it is about to enter a certain
232 phase of the IDE channel enumeration process.
233
234 This function can be used to notify the IDE controller driver to perform
235 specific actions, including any chipset-specific initialization, so that the
236 chipset is ready to enter the next phase. Seven notification points are defined
237 at this time.
238
239 More synchronization points may be added as required in the future.
240
241 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
242 @param[in] Phase The phase during enumeration.
243 @param[in] Channel Zero-based channel number.
244
245 @retval EFI_SUCCESS The notification was accepted without any errors.
246 @retval EFI_UNSUPPORTED Phase is not supported.
247 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
248 @retval EFI_NOT_READY This phase cannot be entered at this time; for
249 example, an attempt was made to enter a Phase
250 without having entered one or more previous
251 Phase.
252
253 **/
254 EFI_STATUS
255 EFIAPI
256 IdeInitNotifyPhase (
257 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
258 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,
259 IN UINT8 Channel
260 )
261 ;
262
263 /**
264 Submits the device information to the IDE controller driver.
265
266 This function is used by the driver entity to pass detailed information about
267 a particular device to the IDE controller driver. The driver entity obtains
268 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
269 is the pointer to the response data buffer. The IdentifyData buffer is owned
270 by the driver entity, and the IDE controller driver must make a local copy
271 of the entire buffer or parts of the buffer as needed. The original IdentifyData
272 buffer pointer may not be valid when
273
274 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
275 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
276
277 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
278 compute the optimum mode for the device. These fields are not limited to the
279 timing information. For example, an implementation of the IDE controller driver
280 may examine the vendor and type/mode field to match known bad drives.
281
282 The driver entity may submit drive information in any order, as long as it
283 submits information for all the devices belonging to the enumeration group
284 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
285 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
286 should be called with IdentifyData set to NULL. The IDE controller driver may
287 not have any other mechanism to know whether a device is present or not. Therefore,
288 setting IdentifyData to NULL does not constitute an error condition.
289 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
290 given (Channel, Device) pair.
291
292 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
293 @param[in] Channel Zero-based channel number.
294 @param[in] Device Zero-based device number on the Channel.
295 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
296
297 @retval EFI_SUCCESS The information was accepted without any errors.
298 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
299 @retval EFI_INVALID_PARAMETER Device is invalid.
300
301 **/
302 EFI_STATUS
303 EFIAPI
304 IdeInitSubmitData (
305 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
306 IN UINT8 Channel,
307 IN UINT8 Device,
308 IN EFI_IDENTIFY_DATA *IdentifyData
309 )
310 ;
311
312 /**
313 Disqualifies specific modes for an IDE device.
314
315 This function allows the driver entity or other drivers (such as platform
316 drivers) to reject certain timing modes and request the IDE controller driver
317 to recalculate modes. This function allows the driver entity and the IDE
318 controller driver to negotiate the timings on a per-device basis. This function
319 is useful in the case of drives that lie about their capabilities. An example
320 is when the IDE device fails to accept the timing modes that are calculated
321 by the IDE controller driver based on the response to the Identify Drive command.
322
323 If the driver entity does not want to limit the ATA timing modes and leave that
324 decision to the IDE controller driver, it can either not call this function for
325 the given device or call this function and set the Valid flag to FALSE for all
326 modes that are listed in EFI_ATA_COLLECTIVE_MODE.
327
328 The driver entity may disqualify modes for a device in any order and any number
329 of times.
330
331 This function can be called multiple times to invalidate multiple modes of the
332 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
333 specification for more information on PIO modes.
334
335 For Serial ATA (SATA) controllers, this member function can be used to disqualify
336 a higher transfer rate mode on a given channel. For example, a platform driver
337 may inform the IDE controller driver to not use second-generation (Gen2) speeds
338 for a certain SATA drive.
339
340 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
341 @param[in] Channel The zero-based channel number.
342 @param[in] Device The zero-based device number on the Channel.
343 @param[in] BadModes The modes that the device does not support and that
344 should be disqualified.
345
346 @retval EFI_SUCCESS The modes were accepted without any errors.
347 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
348 @retval EFI_INVALID_PARAMETER Device is invalid.
349 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
350
351 **/
352 EFI_STATUS
353 EFIAPI
354 IdeInitDisqualifyMode (
355 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
356 IN UINT8 Channel,
357 IN UINT8 Device,
358 IN EFI_ATA_COLLECTIVE_MODE *BadModes
359 )
360 ;
361
362 /**
363 Returns the information about the optimum modes for the specified IDE device.
364
365 This function is used by the driver entity to obtain the optimum ATA modes for
366 a specific device. The IDE controller driver takes into account the following
367 while calculating the mode:
368 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
369 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
370
371 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
372 for all the devices that belong to an enumeration group before calling
373 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
374
375 The IDE controller driver will use controller- and possibly platform-specific
376 algorithms to arrive at SupportedModes. The IDE controller may base its
377 decision on user preferences and other considerations as well. This function
378 may be called multiple times because the driver entity may renegotiate the mode
379 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
380
381 The driver entity may collect timing information for various devices in any
382 order. The driver entity is responsible for making sure that all the dependencies
383 are satisfied. For example, the SupportedModes information for device A that
384 was previously returned may become stale after a call to
385 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
386
387 The buffer SupportedModes is allocated by the callee because the caller does
388 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
389 is defined in a way that allows for future extensibility and can be of variable
390 length. This memory pool should be deallocated by the caller when it is no
391 longer necessary.
392
393 The IDE controller driver for a Serial ATA (SATA) controller can use this
394 member function to force a lower speed (first-generation [Gen1] speeds on a
395 second-generation [Gen2]-capable hardware). The IDE controller driver can
396 also allow the driver entity to stay with the speed that has been negotiated
397 by the physical layer.
398
399 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
400 @param[in] Channel A zero-based channel number.
401 @param[in] Device A zero-based device number on the Channel.
402 @param[out] SupportedModes The optimum modes for the device.
403
404 @retval EFI_SUCCESS SupportedModes was returned.
405 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
406 @retval EFI_INVALID_PARAMETER Device is invalid.
407 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
408 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
409 data. This error may happen if
410 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
411 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
412 were not called for at least one drive in the
413 same enumeration group.
414
415 **/
416 EFI_STATUS
417 EFIAPI
418 IdeInitCalculateMode (
419 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
420 IN UINT8 Channel,
421 IN UINT8 Device,
422 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes
423 )
424 ;
425
426 /**
427 Commands the IDE controller driver to program the IDE controller hardware
428 so that the specified device can operate at the specified mode.
429
430 This function is used by the driver entity to instruct the IDE controller
431 driver to program the IDE controller hardware to the specified modes. This
432 function can be called only once for a particular device. For a Serial ATA
433 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
434 specific programming may be required.
435
436 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
437 @param[in] Channel Zero-based channel number.
438 @param[in] Device Zero-based device number on the Channel.
439 @param[in] Modes The modes to set.
440
441 @retval EFI_SUCCESS The command was accepted without any errors.
442 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
443 @retval EFI_INVALID_PARAMETER Device is invalid.
444 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
445 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
446 The driver entity should not use this device.
447
448 **/
449 EFI_STATUS
450 EFIAPI
451 IdeInitSetTiming (
452 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
453 IN UINT8 Channel,
454 IN UINT8 Device,
455 IN EFI_ATA_COLLECTIVE_MODE *Modes
456 )
457 ;
458
459 //
460 // Forward reference declaration
461 //
462
463 /**
464 Retrieves a Unicode string that is the user readable name of the UEFI Driver.
465
466 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
467 @param Language A pointer to a three character ISO 639-2 language identifier.
468 This is the language of the driver name that the caller
469 is requesting, and it must match one of the languages specified
470 in SupportedLanguages. The number of languages supported by a
471 driver is up to the driver writer.
472 @param DriverName A pointer to the Unicode string to return. This Unicode string
473 is the name of the driver specified by This in the language
474 specified by Language.
475
476 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
477 and the language specified by Language was returned
478 in DriverName.
479 @retval EFI_INVALID_PARAMETER Language is NULL.
480 @retval EFI_INVALID_PARAMETER DriverName is NULL.
481 @retval EFI_UNSUPPORTED The driver specified by This does not support the
482 language specified by Language.
483 **/
484 EFI_STATUS
485 EFIAPI
486 SataControllerComponentNameGetDriverName (
487 IN EFI_COMPONENT_NAME_PROTOCOL *This,
488 IN CHAR8 *Language,
489 OUT CHAR16 **DriverName
490 )
491 ;
492
493 /**
494 Retrieves a Unicode string that is the user readable name of the controller
495 that is being managed by an UEFI Driver.
496
497 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
498 @param ControllerHandle The handle of a controller that the driver specified by
499 This is managing. This handle specifies the controller
500 whose name is to be returned.
501 @param OPTIONAL ChildHandle The handle of the child controller to retrieve the name
502 of. This is an optional parameter that may be NULL. It
503 will be NULL for device drivers. It will also be NULL
504 for a bus drivers that wish to retrieve the name of the
505 bus controller. It will not be NULL for a bus driver
506 that wishes to retrieve the name of a child controller.
507 @param Language A pointer to a three character ISO 639-2 language
508 identifier. This is the language of the controller name
509 that the caller is requesting, and it must match one
510 of the languages specified in SupportedLanguages. The
511 number of languages supported by a driver is up to the
512 driver writer.
513 @param ControllerName A pointer to the Unicode string to return. This Unicode
514 string is the name of the controller specified by
515 ControllerHandle and ChildHandle in the language
516 specified by Language from the point of view of the
517 driver specified by This.
518
519 @retval EFI_SUCCESS The Unicode string for the user readable name in the
520 language specified by Language for the driver
521 specified by This was returned in DriverName.
522 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
523 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
524 EFI_HANDLE.
525 @retval EFI_INVALID_PARAMETER Language is NULL.
526 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
527 @retval EFI_UNSUPPORTED The driver specified by This is not currently
528 managing the controller specified by
529 ControllerHandle and ChildHandle.
530 @retval EFI_UNSUPPORTED The driver specified by This does not support the
531 language specified by Language.
532 **/
533 EFI_STATUS
534 EFIAPI
535 SataControllerComponentNameGetControllerName (
536 IN EFI_COMPONENT_NAME_PROTOCOL *This,
537 IN EFI_HANDLE ControllerHandle,
538 IN EFI_HANDLE ChildHandle OPTIONAL,
539 IN CHAR8 *Language,
540 OUT CHAR16 **ControllerName
541 )
542 ;
543
544 #endif