]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.h
MdeModulePkg: Apply uncrustify changes
[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 /**
123 Supported function of Driver Binding protocol for this driver.
124 Test to see if this driver supports ControllerHandle.
125
126 @param This Protocol instance pointer.
127 @param Controller Handle of device to test.
128 @param RemainingDevicePath A pointer to the device path. Should be ignored by
129 device driver.
130
131 @retval EFI_SUCCESS This driver supports this device.
132 @retval EFI_ALREADY_STARTED This driver is already running on this device.
133 @retval other This driver does not support this device.
134
135 **/
136 EFI_STATUS
137 EFIAPI
138 SataControllerSupported (
139 IN EFI_DRIVER_BINDING_PROTOCOL *This,
140 IN EFI_HANDLE Controller,
141 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
142 );
143
144 /**
145 This routine is called right after the .Supported() called and
146 Start this driver on ControllerHandle.
147
148 @param This Protocol instance pointer.
149 @param Controller Handle of device to bind driver to.
150 @param RemainingDevicePath A pointer to the device path. Should be ignored by
151 device driver.
152
153 @retval EFI_SUCCESS This driver is added to this device.
154 @retval EFI_ALREADY_STARTED This driver is already running on this device.
155 @retval other Some error occurs when binding this driver to this device.
156
157 **/
158 EFI_STATUS
159 EFIAPI
160 SataControllerStart (
161 IN EFI_DRIVER_BINDING_PROTOCOL *This,
162 IN EFI_HANDLE Controller,
163 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
164 );
165
166 /**
167 Stop this driver on ControllerHandle.
168
169 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
170 @param Controller A handle to the device being stopped.
171 @param NumberOfChildren The number of child device handles in ChildHandleBuffer.
172 @param ChildHandleBuffer An array of child handles to be freed.
173
174 @retval EFI_SUCCESS This driver is removed from this device.
175 @retval other Some error occurs when removing this driver from this device.
176
177 **/
178 EFI_STATUS
179 EFIAPI
180 SataControllerStop (
181 IN EFI_DRIVER_BINDING_PROTOCOL *This,
182 IN EFI_HANDLE Controller,
183 IN UINTN NumberOfChildren,
184 IN EFI_HANDLE *ChildHandleBuffer
185 );
186
187 //
188 // IDE controller init functions declaration
189 //
190
191 /**
192 Returns the information about the specified IDE channel.
193
194 This function can be used to obtain information about a particular IDE channel.
195 The driver entity uses this information during the enumeration process.
196
197 If Enabled is set to FALSE, the driver entity will not scan the channel. Note
198 that it will not prevent an operating system driver from scanning the channel.
199
200 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
201 controllers, this value will always be 1. SATA configurations can contain SATA
202 port multipliers. SATA port multipliers behave like SATA bridges and can support
203 up to 16 devices on the other side. If a SATA port out of the IDE controller
204 is connected to a port multiplier, MaxDevices will be set to the number of SATA
205 devices that the port multiplier supports. Because today's port multipliers
206 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
207 bus driver is required to scan for the presence of port multipliers behind an SATA
208 controller and enumerate up to MaxDevices number of devices behind the port
209 multiplier.
210
211 In this context, the devices behind a port multiplier constitute a channel.
212
213 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
214 @param[in] Channel Zero-based channel number.
215 @param[out] Enabled TRUE if this channel is enabled. Disabled channels
216 are not scanned to see if any devices are present.
217 @param[out] MaxDevices The maximum number of IDE devices that the bus driver
218 can expect on this channel. For the ATA/ATAPI
219 specification, version 6, this number will either be
220 one or two. For Serial ATA (SATA) configurations with a
221 port multiplier, this number can be as large as fifteen.
222
223
224 @retval EFI_SUCCESS Information was returned without any errors.
225 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
226
227 **/
228 EFI_STATUS
229 EFIAPI
230 IdeInitGetChannelInfo (
231 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
232 IN UINT8 Channel,
233 OUT BOOLEAN *Enabled,
234 OUT UINT8 *MaxDevices
235 );
236
237 /**
238 The notifications from the driver entity that it is about to enter a certain
239 phase of the IDE channel enumeration process.
240
241 This function can be used to notify the IDE controller driver to perform
242 specific actions, including any chipset-specific initialization, so that the
243 chipset is ready to enter the next phase. Seven notification points are defined
244 at this time.
245
246 More synchronization points may be added as required in the future.
247
248 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL
249 instance.
250 @param[in] Phase The phase during enumeration.
251 @param[in] Channel Zero-based channel number.
252
253 @retval EFI_SUCCESS The notification was accepted without any errors.
254 @retval EFI_UNSUPPORTED Phase is not supported.
255 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
256 @retval EFI_NOT_READY This phase cannot be entered at this time; for
257 example, an attempt was made to enter a Phase
258 without having entered one or more previous
259 Phase.
260
261 **/
262 EFI_STATUS
263 EFIAPI
264 IdeInitNotifyPhase (
265 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
266 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,
267 IN UINT8 Channel
268 );
269
270 /**
271 Submits the device information to the IDE controller driver.
272
273 This function is used by the driver entity to pass detailed information about
274 a particular device to the IDE controller driver. The driver entity obtains
275 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
276 is the pointer to the response data buffer. The IdentifyData buffer is owned
277 by the driver entity, and the IDE controller driver must make a local copy
278 of the entire buffer or parts of the buffer as needed. The original IdentifyData
279 buffer pointer may not be valid when
280
281 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
282 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
283
284 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
285 compute the optimum mode for the device. These fields are not limited to the
286 timing information. For example, an implementation of the IDE controller driver
287 may examine the vendor and type/mode field to match known bad drives.
288
289 The driver entity may submit drive information in any order, as long as it
290 submits information for all the devices belonging to the enumeration group
291 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
292 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
293 should be called with IdentifyData set to NULL. The IDE controller driver may
294 not have any other mechanism to know whether a device is present or not. Therefore,
295 setting IdentifyData to NULL does not constitute an error condition.
296 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
297 given (Channel, Device) pair.
298
299 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
300 @param[in] Channel Zero-based channel number.
301 @param[in] Device Zero-based device number on the Channel.
302 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
303
304 @retval EFI_SUCCESS The information was accepted without any errors.
305 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
306 @retval EFI_INVALID_PARAMETER Device is invalid.
307
308 **/
309 EFI_STATUS
310 EFIAPI
311 IdeInitSubmitData (
312 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
313 IN UINT8 Channel,
314 IN UINT8 Device,
315 IN EFI_IDENTIFY_DATA *IdentifyData
316 );
317
318 /**
319 Disqualifies specific modes for an IDE device.
320
321 This function allows the driver entity or other drivers (such as platform
322 drivers) to reject certain timing modes and request the IDE controller driver
323 to recalculate modes. This function allows the driver entity and the IDE
324 controller driver to negotiate the timings on a per-device basis. This function
325 is useful in the case of drives that lie about their capabilities. An example
326 is when the IDE device fails to accept the timing modes that are calculated
327 by the IDE controller driver based on the response to the Identify Drive command.
328
329 If the driver entity does not want to limit the ATA timing modes and leave that
330 decision to the IDE controller driver, it can either not call this function for
331 the given device or call this function and set the Valid flag to FALSE for all
332 modes that are listed in EFI_ATA_COLLECTIVE_MODE.
333
334 The driver entity may disqualify modes for a device in any order and any number
335 of times.
336
337 This function can be called multiple times to invalidate multiple modes of the
338 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
339 specification for more information on PIO modes.
340
341 For Serial ATA (SATA) controllers, this member function can be used to disqualify
342 a higher transfer rate mode on a given channel. For example, a platform driver
343 may inform the IDE controller driver to not use second-generation (Gen2) speeds
344 for a certain SATA drive.
345
346 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
347 @param[in] Channel The zero-based channel number.
348 @param[in] Device The zero-based device number on the Channel.
349 @param[in] BadModes The modes that the device does not support and that
350 should be disqualified.
351
352 @retval EFI_SUCCESS The modes were accepted without any errors.
353 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
354 @retval EFI_INVALID_PARAMETER Device is invalid.
355 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
356
357 **/
358 EFI_STATUS
359 EFIAPI
360 IdeInitDisqualifyMode (
361 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
362 IN UINT8 Channel,
363 IN UINT8 Device,
364 IN EFI_ATA_COLLECTIVE_MODE *BadModes
365 );
366
367 /**
368 Returns the information about the optimum modes for the specified IDE device.
369
370 This function is used by the driver entity to obtain the optimum ATA modes for
371 a specific device. The IDE controller driver takes into account the following
372 while calculating the mode:
373 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
374 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
375
376 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
377 for all the devices that belong to an enumeration group before calling
378 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
379
380 The IDE controller driver will use controller- and possibly platform-specific
381 algorithms to arrive at SupportedModes. The IDE controller may base its
382 decision on user preferences and other considerations as well. This function
383 may be called multiple times because the driver entity may renegotiate the mode
384 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
385
386 The driver entity may collect timing information for various devices in any
387 order. The driver entity is responsible for making sure that all the dependencies
388 are satisfied. For example, the SupportedModes information for device A that
389 was previously returned may become stale after a call to
390 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
391
392 The buffer SupportedModes is allocated by the callee because the caller does
393 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
394 is defined in a way that allows for future extensibility and can be of variable
395 length. This memory pool should be deallocated by the caller when it is no
396 longer necessary.
397
398 The IDE controller driver for a Serial ATA (SATA) controller can use this
399 member function to force a lower speed (first-generation [Gen1] speeds on a
400 second-generation [Gen2]-capable hardware). The IDE controller driver can
401 also allow the driver entity to stay with the speed that has been negotiated
402 by the physical layer.
403
404 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
405 @param[in] Channel A zero-based channel number.
406 @param[in] Device A zero-based device number on the Channel.
407 @param[out] SupportedModes The optimum modes for the device.
408
409 @retval EFI_SUCCESS SupportedModes was returned.
410 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
411 @retval EFI_INVALID_PARAMETER Device is invalid.
412 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
413 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
414 data. This error may happen if
415 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
416 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
417 were not called for at least one drive in the
418 same enumeration group.
419
420 **/
421 EFI_STATUS
422 EFIAPI
423 IdeInitCalculateMode (
424 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
425 IN UINT8 Channel,
426 IN UINT8 Device,
427 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes
428 );
429
430 /**
431 Commands the IDE controller driver to program the IDE controller hardware
432 so that the specified device can operate at the specified mode.
433
434 This function is used by the driver entity to instruct the IDE controller
435 driver to program the IDE controller hardware to the specified modes. This
436 function can be called only once for a particular device. For a Serial ATA
437 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
438 specific programming may be required.
439
440 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
441 @param[in] Channel Zero-based channel number.
442 @param[in] Device Zero-based device number on the Channel.
443 @param[in] Modes The modes to set.
444
445 @retval EFI_SUCCESS The command was accepted without any errors.
446 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
447 @retval EFI_INVALID_PARAMETER Device is invalid.
448 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
449 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
450 The driver entity should not use this device.
451
452 **/
453 EFI_STATUS
454 EFIAPI
455 IdeInitSetTiming (
456 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
457 IN UINT8 Channel,
458 IN UINT8 Device,
459 IN EFI_ATA_COLLECTIVE_MODE *Modes
460 );
461
462 //
463 // Forward reference declaration
464 //
465
466 /**
467 Retrieves a Unicode string that is the user readable name of the UEFI Driver.
468
469 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
470 @param Language A pointer to a three character ISO 639-2 language identifier.
471 This is the language of the driver name that that the caller
472 is requesting, and it must match one of the languages specified
473 in SupportedLanguages. The number of languages supported by a
474 driver is up to the driver writer.
475 @param DriverName A pointer to the Unicode string to return. This Unicode string
476 is the name of the driver specified by This in the language
477 specified by Language.
478
479 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
480 and the language specified by Language was returned
481 in DriverName.
482 @retval EFI_INVALID_PARAMETER Language is NULL.
483 @retval EFI_INVALID_PARAMETER DriverName is NULL.
484 @retval EFI_UNSUPPORTED The driver specified by This does not support the
485 language specified by Language.
486 **/
487 EFI_STATUS
488 EFIAPI
489 SataControllerComponentNameGetDriverName (
490 IN EFI_COMPONENT_NAME_PROTOCOL *This,
491 IN CHAR8 *Language,
492 OUT CHAR16 **DriverName
493 );
494
495 /**
496 Retrieves a Unicode string that is the user readable name of the controller
497 that is being managed by an UEFI Driver.
498
499 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
500 @param ControllerHandle The handle of a controller that the driver specified by
501 This is managing. This handle specifies the controller
502 whose name is to be returned.
503 @param OPTIONAL ChildHandle The handle of the child controller to retrieve the name
504 of. This is an optional parameter that may be NULL. It
505 will be NULL for device drivers. It will also be NULL
506 for a bus drivers that wish to retrieve the name of the
507 bus controller. It will not be NULL for a bus driver
508 that wishes to retrieve the name of a child controller.
509 @param Language A pointer to a three character ISO 639-2 language
510 identifier. This is the language of the controller name
511 that that the caller is requesting, and it must match one
512 of the languages specified in SupportedLanguages. The
513 number of languages supported by a driver is up to the
514 driver writer.
515 @param ControllerName A pointer to the Unicode string to return. This Unicode
516 string is the name of the controller specified by
517 ControllerHandle and ChildHandle in the language
518 specified by Language from the point of view of the
519 driver specified by This.
520
521 @retval EFI_SUCCESS The Unicode string for the user readable name in the
522 language specified by Language for the driver
523 specified by This was returned in DriverName.
524 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
525 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
526 EFI_HANDLE.
527 @retval EFI_INVALID_PARAMETER Language is NULL.
528 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
529 @retval EFI_UNSUPPORTED The driver specified by This is not currently
530 managing the controller specified by
531 ControllerHandle and ChildHandle.
532 @retval EFI_UNSUPPORTED The driver specified by This does not support the
533 language specified by Language.
534 **/
535 EFI_STATUS
536 EFIAPI
537 SataControllerComponentNameGetControllerName (
538 IN EFI_COMPONENT_NAME_PROTOCOL *This,
539 IN EFI_HANDLE ControllerHandle,
540 IN EFI_HANDLE ChildHandle OPTIONAL,
541 IN CHAR8 *Language,
542 OUT CHAR16 **ControllerName
543 );
544
545 #endif