]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/SataControllerDxe/SataController.h
0352178baba7d658d81dfebbfd6536645e84eb8b
[mirror_edk2.git] / DuetPkg / SataControllerDxe / SataController.h
1 /** @file
2 Header file for Sata Controller driver.
3
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
9
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.
12
13 **/
14
15 #ifndef _SATA_CONTROLLER_H_
16 #define _SATA_CONTROLLER_H_
17
18 #include <Uefi.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>
31
32 //
33 // Global Variables definitions
34 //
35 extern EFI_DRIVER_BINDING_PROTOCOL gSataControllerDriverBinding;
36 extern EFI_COMPONENT_NAME_PROTOCOL gSataControllerComponentName;
37 extern EFI_COMPONENT_NAME2_PROTOCOL gSataControllerComponentName2;
38
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
43
44 ///
45 /// AHCI each channel can have up to 1 device
46 ///
47 #define AHCI_MAX_DEVICES 0x01
48
49 ///
50 /// AHCI each channel can have 15 devices in the presence of a multiplier
51 ///
52 #define AHCI_MULTI_MAX_DEVICES 0x0F
53
54 ///
55 /// IDE supports 2 channel max
56 ///
57 #define IDE_MAX_CHANNEL 0x02
58
59 ///
60 /// IDE supports 2 devices max
61 ///
62 #define IDE_MAX_DEVICES 0x02
63
64 #define SATA_ENUMER_ALL FALSE
65
66 //
67 // Sata Controller driver private data structure
68 //
69
70 #define SATA_CONTROLLER_SIGNATURE SIGNATURE_32('S','A','T','A')
71
72 typedef struct _EFI_SATA_CONTROLLER_PRIVATE_DATA {
73 //
74 // Standard signature used to identify Sata Controller private data
75 //
76 UINT32 Signature;
77
78 //
79 // Protocol instance of IDE_CONTROLLER_INIT produced by this driver
80 //
81 EFI_IDE_CONTROLLER_INIT_PROTOCOL IdeInit;
82
83 //
84 // Copy of protocol pointers used by this driver
85 //
86 EFI_PCI_IO_PROTOCOL *PciIo;
87
88 //
89 // The number of devices that are supported by this channel
90 //
91 UINT8 DeviceCount;
92
93 //
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
97 //
98 EFI_ATA_COLLECTIVE_MODE *DisqulifiedModes;
99
100 //
101 // A copy of EFI_IDENTIFY_DATA data for each attached SATA device and its flag
102 //
103 EFI_IDENTIFY_DATA *IdentifyData;
104 BOOLEAN *IdentifyValid;
105 } EFI_SATA_CONTROLLER_PRIVATE_DATA;
106
107 #define SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) CR(a, EFI_SATA_CONTROLLER_PRIVATE_DATA, IdeInit, SATA_CONTROLLER_SIGNATURE)
108
109 //
110 // Driver binding functions declaration
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 This function can be used to obtain information about a specified channel.
185 It's usually used by IDE Bus driver during enumeration process.
186
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.
196
197 @retval EFI_SUCCESS Success to get channel information.
198 @retval EFI_INVALID_PARAMETER Invalid channel id.
199 **/
200 EFI_STATUS
201 EFIAPI
202 IdeInitGetChannelInfo (
203 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
204 IN UINT8 Channel,
205 OUT BOOLEAN *Enabled,
206 OUT UINT8 *MaxDevices
207 )
208 ;
209
210 /**
211 This function is called by IdeBus driver before executing certain actions.
212 This allows IDE Controller Init to prepare for each action.
213
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.
217
218 @retval EFI_SUCCESS Success operation.
219 **/
220 EFI_STATUS
221 EFIAPI
222 IdeInitNotifyPhase (
223 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
224 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,
225 IN UINT8 Channel
226 )
227 ;
228
229 /**
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.
232
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.
237
238 @retval EFI_SUCCESS The information was accepted without any errors.
239 @retval EFI_INVALID_PARAMETER Invalid channel id or device id.
240 **/
241 EFI_STATUS
242 EFIAPI
243 IdeInitSubmitData (
244 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
245 IN UINT8 Channel,
246 IN UINT8 Device,
247 IN EFI_IDENTIFY_DATA *IdentifyData
248 )
249 ;
250
251 /**
252 This function is called by IdeBus driver to disqualify unsupported operation
253 mode on specfic IDE device.
254
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.
260
261 @retval EFI_SUCCESS The modes were accepted without any errors.
262 @retval EFI_INVALID_PARAMETER Invalid channel id or device id.
263 **/
264 EFI_STATUS
265 EFIAPI
266 IdeInitDisqualifyMode (
267 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
268 IN UINT8 Channel,
269 IN UINT8 Device,
270 IN EFI_ATA_COLLECTIVE_MODE *BadModes
271 )
272 ;
273
274 /**
275 This function is called by IdeBus driver to calculate the best operation mode
276 supported by specific IDE device.
277
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.
282
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.
286 **/
287 EFI_STATUS
288 EFIAPI
289 IdeInitCalculateMode (
290 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
291 IN UINT8 Channel,
292 IN UINT8 Device,
293 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes
294 )
295 ;
296
297 /**
298 This function is called by IdeBus driver to set appropriate timing on IDE
299 controller according supported operation mode.
300
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.
305
306 @retval EFI_SUCCESS Sucess operation.
307 **/
308 EFI_STATUS
309 EFIAPI
310 IdeInitSetTiming (
311 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
312 IN UINT8 Channel,
313 IN UINT8 Device,
314 IN EFI_ATA_COLLECTIVE_MODE *Modes
315 )
316 ;
317
318 //
319 // Forward reference declaration
320 //
321 /**
322 Retrieves a Unicode string that is the user readable name of the UEFI Driver.
323
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.
333
334 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
335 and the language specified by Language was returned
336 in DriverName.
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.
341 **/
342 EFI_STATUS
343 EFIAPI
344 SataControllerComponentNameGetDriverName (
345 IN EFI_COMPONENT_NAME_PROTOCOL *This,
346 IN CHAR8 *Language,
347 OUT CHAR16 **DriverName
348 )
349 ;
350
351 /**
352 Retrieves a Unicode string that is the user readable name of the controller
353 that is being managed by an UEFI Driver.
354
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
370 driver writer.
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.
376
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
382 EFI_HANDLE.
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.
390 **/
391 EFI_STATUS
392 EFIAPI
393 SataControllerComponentNameGetControllerName (
394 IN EFI_COMPONENT_NAME_PROTOCOL *This,
395 IN EFI_HANDLE ControllerHandle,
396 IN EFI_HANDLE ChildHandle OPTIONAL,
397 IN CHAR8 *Language,
398 OUT CHAR16 **ControllerName
399 )
400 ;
401
402 #endif