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