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