2 Header file for Sata Controller driver.
4 Copyright (c) 2011, 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
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.
15 #ifndef _SATA_CONTROLLER_H_
16 #define _SATA_CONTROLLER_H_
19 #include <Protocol/ComponentName.h>
20 #include <Protocol/DriverBinding.h>
21 #include <Protocol/PciIo.h>
22 #include <Protocol/IdeControllerInit.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/DebugLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <IndustryStandard/Pci.h>
33 // Global Variables definitions
35 extern EFI_DRIVER_BINDING_PROTOCOL gSataControllerDriverBinding
;
36 extern EFI_COMPONENT_NAME_PROTOCOL gSataControllerComponentName
;
37 extern EFI_COMPONENT_NAME2_PROTOCOL gSataControllerComponentName2
;
39 #define AHCI_BAR_INDEX 0x05
40 #define R_AHCI_CAP 0x0
41 #define B_AHCI_CAP_NPS (BIT4 | BIT3 | BIT2 | BIT1 | BIT0) // Number of Ports
42 #define B_AHCI_CAP_SPM BIT17 // Supports Port Multiplier
45 /// AHCI each channel can have up to 1 device
47 #define AHCI_MAX_DEVICES 0x01
50 /// AHCI each channel can have 15 devices in the presence of a multiplier
52 #define AHCI_MULTI_MAX_DEVICES 0x0F
55 /// IDE supports 2 channel max
57 #define IDE_MAX_CHANNEL 0x02
60 /// IDE supports 2 devices max
62 #define IDE_MAX_DEVICES 0x02
64 #define SATA_ENUMER_ALL FALSE
67 // Sata Controller driver private data structure
70 #define SATA_CONTROLLER_SIGNATURE SIGNATURE_32('S','A','T','A')
72 typedef struct _EFI_SATA_CONTROLLER_PRIVATE_DATA
{
74 // Standard signature used to identify Sata Controller private data
79 // Protocol instance of IDE_CONTROLLER_INIT produced by this driver
81 EFI_IDE_CONTROLLER_INIT_PROTOCOL IdeInit
;
84 // Copy of protocol pointers used by this driver
86 EFI_PCI_IO_PROTOCOL
*PciIo
;
89 // The number of devices that are supported by this channel
94 // The highest disqulified mode for each attached device,
95 // From ATA/ATAPI spec, if a mode is not supported,
96 // the modes higher than it is also not supported
98 EFI_ATA_COLLECTIVE_MODE
*DisqulifiedModes
;
101 // A copy of EFI_IDENTIFY_DATA data for each attached SATA device and its flag
103 EFI_IDENTIFY_DATA
*IdentifyData
;
104 BOOLEAN
*IdentifyValid
;
105 } EFI_SATA_CONTROLLER_PRIVATE_DATA
;
107 #define SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) CR(a, EFI_SATA_CONTROLLER_PRIVATE_DATA, IdeInit, SATA_CONTROLLER_SIGNATURE)
110 // Driver binding functions declaration
113 Supported function of Driver Binding protocol for this driver.
114 Test to see if this driver supports ControllerHandle.
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
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.
128 SataControllerSupported (
129 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
130 IN EFI_HANDLE Controller
,
131 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
136 This routine is called right after the .Supported() called and
137 Start this driver on ControllerHandle.
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
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.
151 SataControllerStart (
152 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
153 IN EFI_HANDLE Controller
,
154 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
159 Stop this driver on ControllerHandle.
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.
166 @retval EFI_SUCCESS This driver is removed from this device.
167 @retval other Some error occurs when removing this driver from this device.
173 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
174 IN EFI_HANDLE Controller
,
175 IN UINTN NumberOfChildren
,
176 IN EFI_HANDLE
*ChildHandleBuffer
181 // IDE controller init functions declaration
184 This function can be used to obtain information about a specified channel.
185 It's usually used by IDE Bus driver during enumeration process.
187 @param This the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
188 @param Channel Channel number. Parallel ATA (PATA) controllers can support up to two channels.
189 Advanced Host Controller Interface (AHCI) Serial ATA (SATA) controllers
190 can support up to 32 channels, each of which can have up to one device.
191 In the presence of a multiplier, each channel can have 15 devices.
192 @param Enabled TRUE if the channel is enabled. If the channel is disabled,
193 then it will no be enumerated.
194 @param MaxDevices For Parallel ATA (PATA) controllers, this number will either be 1 or 2.
195 For Serial ATA (SATA) controllers with a port multiplier, this number can be as large as 15.
197 @retval EFI_SUCCESS Success to get channel information.
198 @retval EFI_INVALID_PARAMETER Invalid channel id.
202 IdeInitGetChannelInfo (
203 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
205 OUT BOOLEAN
*Enabled
,
206 OUT UINT8
*MaxDevices
211 This function is called by IdeBus driver before executing certain actions.
212 This allows IDE Controller Init to prepare for each action.
214 @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
215 @param Phase Phase indicator defined by IDE_CONTROLLER_INIT protocol.
216 @param Channel Channel number.
218 @retval EFI_SUCCESS Success operation.
223 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
224 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase
,
230 This function is called by IdeBus driver to submit EFI_IDENTIFY_DATA data structure
231 obtained from IDE deivce. This structure is used to set IDE timing.
233 @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
234 @param Channel Channel number.
235 @param Device Device number.
236 @param IdentifyData A pointer to EFI_IDENTIFY_DATA data structure.
238 @retval EFI_SUCCESS The information was accepted without any errors.
239 @retval EFI_INVALID_PARAMETER Invalid channel id or device id.
244 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
247 IN EFI_IDENTIFY_DATA
*IdentifyData
252 This function is called by IdeBus driver to disqualify unsupported operation
253 mode on specfic IDE device.
255 @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
256 @param Channel Channel number.
257 @param Device Device number.
258 @param BadModes The modes that the device does not support and that
259 should be disqualified.
261 @retval EFI_SUCCESS The modes were accepted without any errors.
262 @retval EFI_INVALID_PARAMETER Invalid channel id or device id.
266 IdeInitDisqualifyMode (
267 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
270 IN EFI_ATA_COLLECTIVE_MODE
*BadModes
275 This function is called by IdeBus driver to calculate the best operation mode
276 supported by specific IDE device.
278 @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
279 @param Channel Channel number.
280 @param Device Device number.
281 @param SupportedModes The optimum modes for the device.
283 @retval EFI_SUCCESS SupportedModes was returned.
284 @retval EFI_OUT_OF_RESOURCES Fail to allocate pool.
285 @retval EFI_INVALID_PARAMETER Invalid channel id or device id.
289 IdeInitCalculateMode (
290 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
293 OUT EFI_ATA_COLLECTIVE_MODE
**SupportedModes
298 This function is called by IdeBus driver to set appropriate timing on IDE
299 controller according supported operation mode.
301 @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
302 @param Channel Channel number.
303 @param Device Device number.
304 @param Modes The modes to set.
306 @retval EFI_SUCCESS Sucess operation.
311 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
314 IN EFI_ATA_COLLECTIVE_MODE
*Modes
319 // Forward reference declaration
322 Retrieves a Unicode string that is the user readable name of the UEFI Driver.
324 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
325 @param Language A pointer to a three character ISO 639-2 language identifier.
326 This is the language of the driver name that that the caller
327 is requesting, and it must match one of the languages specified
328 in SupportedLanguages. The number of languages supported by a
329 driver is up to the driver writer.
330 @param DriverName A pointer to the Unicode string to return. This Unicode string
331 is the name of the driver specified by This in the language
332 specified by Language.
334 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
335 and the language specified by Language was returned
337 @retval EFI_INVALID_PARAMETER Language is NULL.
338 @retval EFI_INVALID_PARAMETER DriverName is NULL.
339 @retval EFI_UNSUPPORTED The driver specified by This does not support the
340 language specified by Language.
344 SataControllerComponentNameGetDriverName (
345 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
347 OUT CHAR16
**DriverName
352 Retrieves a Unicode string that is the user readable name of the controller
353 that is being managed by an UEFI Driver.
355 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
356 @param ControllerHandle The handle of a controller that the driver specified by
357 This is managing. This handle specifies the controller
358 whose name is to be returned.
359 @param OPTIONAL ChildHandle The handle of the child controller to retrieve the name
360 of. This is an optional parameter that may be NULL. It
361 will be NULL for device drivers. It will also be NULL
362 for a bus drivers that wish to retrieve the name of the
363 bus controller. It will not be NULL for a bus driver
364 that wishes to retrieve the name of a child controller.
365 @param Language A pointer to a three character ISO 639-2 language
366 identifier. This is the language of the controller name
367 that that the caller is requesting, and it must match one
368 of the languages specified in SupportedLanguages. The
369 number of languages supported by a driver is up to the
371 @param ControllerName A pointer to the Unicode string to return. This Unicode
372 string is the name of the controller specified by
373 ControllerHandle and ChildHandle in the language
374 specified by Language from the point of view of the
375 driver specified by This.
377 @retval EFI_SUCCESS The Unicode string for the user readable name in the
378 language specified by Language for the driver
379 specified by This was returned in DriverName.
380 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
381 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
383 @retval EFI_INVALID_PARAMETER Language is NULL.
384 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
385 @retval EFI_UNSUPPORTED The driver specified by This is not currently
386 managing the controller specified by
387 ControllerHandle and ChildHandle.
388 @retval EFI_UNSUPPORTED The driver specified by This does not support the
389 language specified by Language.
393 SataControllerComponentNameGetControllerName (
394 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
395 IN EFI_HANDLE ControllerHandle
,
396 IN EFI_HANDLE ChildHandle OPTIONAL
,
398 OUT CHAR16
**ControllerName