]>
Commit | Line | Data |
---|---|---|
27f30159 SZ |
1 | /** @file\r |
2 | Header file for Sata Controller driver.\r | |
3 | \r | |
4 | Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #ifndef _SATA_CONTROLLER_H_\r | |
16 | #define _SATA_CONTROLLER_H_\r | |
17 | \r | |
18 | #include <Uefi.h>\r | |
19 | #include <Protocol/ComponentName.h>\r | |
20 | #include <Protocol/DriverBinding.h>\r | |
21 | #include <Protocol/PciIo.h>\r | |
22 | #include <Protocol/IdeControllerInit.h>\r | |
23 | #include <Library/UefiDriverEntryPoint.h>\r | |
24 | #include <Library/DebugLib.h>\r | |
25 | #include <Library/UefiLib.h>\r | |
26 | #include <Library/BaseLib.h>\r | |
27 | #include <Library/BaseMemoryLib.h>\r | |
28 | #include <Library/MemoryAllocationLib.h>\r | |
29 | #include <Library/UefiBootServicesTableLib.h>\r | |
30 | #include <IndustryStandard/Pci.h>\r | |
31 | \r | |
32 | //\r | |
33 | // Global Variables definitions\r | |
34 | //\r | |
35 | extern EFI_DRIVER_BINDING_PROTOCOL gSataControllerDriverBinding;\r | |
36 | extern EFI_COMPONENT_NAME_PROTOCOL gSataControllerComponentName;\r | |
37 | extern EFI_COMPONENT_NAME2_PROTOCOL gSataControllerComponentName2;\r | |
38 | \r | |
39 | #define AHCI_BAR_INDEX 0x05\r | |
40 | #define R_AHCI_CAP 0x0\r | |
41 | #define B_AHCI_CAP_NPS (BIT4 | BIT3 | BIT2 | BIT1 | BIT0) // Number of Ports\r | |
42 | #define B_AHCI_CAP_SPM BIT17 // Supports Port Multiplier\r | |
43 | \r | |
44 | ///\r | |
45 | /// AHCI each channel can have up to 1 device\r | |
46 | ///\r | |
47 | #define AHCI_MAX_DEVICES 0x01\r | |
48 | \r | |
49 | ///\r | |
50 | /// AHCI each channel can have 15 devices in the presence of a multiplier\r | |
51 | ///\r | |
52 | #define AHCI_MULTI_MAX_DEVICES 0x0F\r | |
53 | \r | |
54 | ///\r | |
55 | /// IDE supports 2 channel max\r | |
56 | ///\r | |
57 | #define IDE_MAX_CHANNEL 0x02\r | |
58 | \r | |
59 | ///\r | |
60 | /// IDE supports 2 devices max\r | |
61 | ///\r | |
62 | #define IDE_MAX_DEVICES 0x02\r | |
63 | \r | |
64 | #define SATA_ENUMER_ALL FALSE\r | |
65 | \r | |
66 | //\r | |
67 | // Sata Controller driver private data structure\r | |
68 | //\r | |
69 | \r | |
70 | #define SATA_CONTROLLER_SIGNATURE SIGNATURE_32('S','A','T','A')\r | |
71 | \r | |
72 | typedef struct _EFI_SATA_CONTROLLER_PRIVATE_DATA {\r | |
73 | //\r | |
74 | // Standard signature used to identify Sata Controller private data\r | |
75 | //\r | |
76 | UINT32 Signature;\r | |
77 | \r | |
78 | //\r | |
79 | // Protocol instance of IDE_CONTROLLER_INIT produced by this driver\r | |
80 | //\r | |
81 | EFI_IDE_CONTROLLER_INIT_PROTOCOL IdeInit;\r | |
82 | \r | |
83 | //\r | |
84 | // Copy of protocol pointers used by this driver\r | |
85 | //\r | |
86 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
87 | \r | |
88 | //\r | |
89 | // The number of devices that are supported by this channel\r | |
90 | //\r | |
91 | UINT8 DeviceCount;\r | |
92 | \r | |
93 | //\r | |
94 | // The highest disqulified mode for each attached device,\r | |
95 | // From ATA/ATAPI spec, if a mode is not supported,\r | |
96 | // the modes higher than it is also not supported\r | |
97 | //\r | |
98 | EFI_ATA_COLLECTIVE_MODE *DisqulifiedModes;\r | |
99 | \r | |
100 | //\r | |
101 | // A copy of EFI_IDENTIFY_DATA data for each attached SATA device and its flag\r | |
102 | //\r | |
103 | EFI_IDENTIFY_DATA *IdentifyData;\r | |
104 | BOOLEAN *IdentifyValid;\r | |
105 | } EFI_SATA_CONTROLLER_PRIVATE_DATA;\r | |
106 | \r | |
107 | #define SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) CR(a, EFI_SATA_CONTROLLER_PRIVATE_DATA, IdeInit, SATA_CONTROLLER_SIGNATURE)\r | |
108 | \r | |
109 | //\r | |
110 | // Driver binding functions declaration\r | |
111 | //\r | |
112 | /**\r | |
113 | Supported function of Driver Binding protocol for this driver.\r | |
114 | Test to see if this driver supports ControllerHandle.\r | |
115 | \r | |
116 | @param This Protocol instance pointer.\r | |
117 | @param Controller Handle of device to test.\r | |
118 | @param RemainingDevicePath A pointer to the device path. Should be ignored by\r | |
119 | device driver.\r | |
120 | \r | |
121 | @retval EFI_SUCCESS This driver supports this device.\r | |
122 | @retval EFI_ALREADY_STARTED This driver is already running on this device.\r | |
123 | @retval other This driver does not support this device.\r | |
124 | \r | |
125 | **/\r | |
126 | EFI_STATUS\r | |
127 | EFIAPI\r | |
128 | SataControllerSupported (\r | |
129 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
130 | IN EFI_HANDLE Controller,\r | |
131 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
132 | )\r | |
133 | ;\r | |
134 | \r | |
135 | /**\r | |
136 | This routine is called right after the .Supported() called and \r | |
137 | Start this driver on ControllerHandle.\r | |
138 | \r | |
139 | @param This Protocol instance pointer.\r | |
140 | @param Controller Handle of device to bind driver to.\r | |
141 | @param RemainingDevicePath A pointer to the device path. Should be ignored by\r | |
142 | device driver.\r | |
143 | \r | |
144 | @retval EFI_SUCCESS This driver is added to this device.\r | |
145 | @retval EFI_ALREADY_STARTED This driver is already running on this device.\r | |
146 | @retval other Some error occurs when binding this driver to this device.\r | |
147 | \r | |
148 | **/\r | |
149 | EFI_STATUS\r | |
150 | EFIAPI\r | |
151 | SataControllerStart (\r | |
152 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
153 | IN EFI_HANDLE Controller,\r | |
154 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
155 | )\r | |
156 | ;\r | |
157 | \r | |
158 | /**\r | |
159 | Stop this driver on ControllerHandle.\r | |
160 | \r | |
161 | @param This Protocol instance pointer.\r | |
162 | @param Controller Handle of device to stop driver on.\r | |
163 | @param NumberOfChildren Not used.\r | |
164 | @param ChildHandleBuffer Not used.\r | |
165 | \r | |
166 | @retval EFI_SUCCESS This driver is removed from this device.\r | |
167 | @retval other Some error occurs when removing this driver from this device.\r | |
168 | \r | |
169 | **/\r | |
170 | EFI_STATUS\r | |
171 | EFIAPI\r | |
172 | SataControllerStop (\r | |
173 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
174 | IN EFI_HANDLE Controller,\r | |
175 | IN UINTN NumberOfChildren,\r | |
176 | IN EFI_HANDLE *ChildHandleBuffer\r | |
177 | )\r | |
178 | ;\r | |
179 | \r | |
180 | //\r | |
181 | // IDE controller init functions declaration\r | |
182 | //\r | |
183 | /**\r | |
184 | This function can be used to obtain information about a specified channel.\r | |
185 | It's usually used by IDE Bus driver during enumeration process.\r | |
186 | \r | |
187 | @param This the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r | |
188 | @param Channel Channel number. Parallel ATA (PATA) controllers can support up to two channels.\r | |
189 | Advanced Host Controller Interface (AHCI) Serial ATA (SATA) controllers\r | |
190 | can support up to 32 channels, each of which can have up to one device.\r | |
191 | In the presence of a multiplier, each channel can have 15 devices.\r | |
192 | @param Enabled TRUE if the channel is enabled. If the channel is disabled,\r | |
193 | then it will no be enumerated.\r | |
194 | @param MaxDevices For Parallel ATA (PATA) controllers, this number will either be 1 or 2.\r | |
195 | For Serial ATA (SATA) controllers with a port multiplier, this number can be as large as 15.\r | |
196 | \r | |
197 | @retval EFI_SUCCESS Success to get channel information.\r | |
198 | @retval EFI_INVALID_PARAMETER Invalid channel id.\r | |
199 | **/\r | |
200 | EFI_STATUS\r | |
201 | EFIAPI\r | |
202 | IdeInitGetChannelInfo (\r | |
203 | IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r | |
204 | IN UINT8 Channel,\r | |
205 | OUT BOOLEAN *Enabled,\r | |
206 | OUT UINT8 *MaxDevices\r | |
207 | )\r | |
208 | ;\r | |
209 | \r | |
210 | /**\r | |
211 | This function is called by IdeBus driver before executing certain actions.\r | |
212 | This allows IDE Controller Init to prepare for each action.\r | |
213 | \r | |
214 | @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r | |
215 | @param Phase Phase indicator defined by IDE_CONTROLLER_INIT protocol.\r | |
216 | @param Channel Channel number.\r | |
217 | \r | |
218 | @retval EFI_SUCCESS Success operation.\r | |
219 | **/\r | |
220 | EFI_STATUS\r | |
221 | EFIAPI\r | |
222 | IdeInitNotifyPhase (\r | |
223 | IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r | |
224 | IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,\r | |
225 | IN UINT8 Channel\r | |
226 | )\r | |
227 | ;\r | |
228 | \r | |
229 | /**\r | |
230 | This function is called by IdeBus driver to submit EFI_IDENTIFY_DATA data structure\r | |
231 | obtained from IDE deivce. This structure is used to set IDE timing.\r | |
232 | \r | |
233 | @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r | |
234 | @param Channel Channel number.\r | |
235 | @param Device Device number.\r | |
236 | @param IdentifyData A pointer to EFI_IDENTIFY_DATA data structure.\r | |
237 | \r | |
238 | @retval EFI_SUCCESS The information was accepted without any errors.\r | |
239 | @retval EFI_INVALID_PARAMETER Invalid channel id or device id.\r | |
240 | **/\r | |
241 | EFI_STATUS\r | |
242 | EFIAPI\r | |
243 | IdeInitSubmitData (\r | |
244 | IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r | |
245 | IN UINT8 Channel,\r | |
246 | IN UINT8 Device,\r | |
247 | IN EFI_IDENTIFY_DATA *IdentifyData\r | |
248 | )\r | |
249 | ;\r | |
250 | \r | |
251 | /**\r | |
252 | This function is called by IdeBus driver to disqualify unsupported operation\r | |
253 | mode on specfic IDE device.\r | |
254 | \r | |
255 | @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r | |
256 | @param Channel Channel number.\r | |
257 | @param Device Device number.\r | |
258 | @param BadModes The modes that the device does not support and that\r | |
259 | should be disqualified.\r | |
260 | \r | |
261 | @retval EFI_SUCCESS The modes were accepted without any errors.\r | |
262 | @retval EFI_INVALID_PARAMETER Invalid channel id or device id.\r | |
263 | **/\r | |
264 | EFI_STATUS\r | |
265 | EFIAPI\r | |
266 | IdeInitDisqualifyMode (\r | |
267 | IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r | |
268 | IN UINT8 Channel,\r | |
269 | IN UINT8 Device,\r | |
270 | IN EFI_ATA_COLLECTIVE_MODE *BadModes\r | |
271 | )\r | |
272 | ;\r | |
273 | \r | |
274 | /**\r | |
275 | This function is called by IdeBus driver to calculate the best operation mode\r | |
276 | supported by specific IDE device.\r | |
277 | \r | |
278 | @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r | |
279 | @param Channel Channel number.\r | |
280 | @param Device Device number.\r | |
281 | @param SupportedModes The optimum modes for the device.\r | |
282 | \r | |
283 | @retval EFI_SUCCESS SupportedModes was returned.\r | |
284 | @retval EFI_OUT_OF_RESOURCES Fail to allocate pool.\r | |
285 | @retval EFI_INVALID_PARAMETER Invalid channel id or device id.\r | |
286 | **/\r | |
287 | EFI_STATUS\r | |
288 | EFIAPI\r | |
289 | IdeInitCalculateMode (\r | |
290 | IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r | |
291 | IN UINT8 Channel,\r | |
292 | IN UINT8 Device,\r | |
293 | OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes\r | |
294 | )\r | |
295 | ;\r | |
296 | \r | |
297 | /**\r | |
298 | This function is called by IdeBus driver to set appropriate timing on IDE\r | |
299 | controller according supported operation mode.\r | |
300 | \r | |
301 | @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r | |
302 | @param Channel Channel number.\r | |
303 | @param Device Device number.\r | |
304 | @param Modes The modes to set.\r | |
305 | \r | |
306 | @retval EFI_SUCCESS Sucess operation.\r | |
307 | **/\r | |
308 | EFI_STATUS\r | |
309 | EFIAPI\r | |
310 | IdeInitSetTiming (\r | |
311 | IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r | |
312 | IN UINT8 Channel,\r | |
313 | IN UINT8 Device,\r | |
314 | IN EFI_ATA_COLLECTIVE_MODE *Modes\r | |
315 | )\r | |
316 | ;\r | |
317 | \r | |
318 | //\r | |
319 | // Forward reference declaration\r | |
320 | //\r | |
321 | /**\r | |
322 | Retrieves a Unicode string that is the user readable name of the UEFI Driver.\r | |
323 | \r | |
324 | @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
325 | @param Language A pointer to a three character ISO 639-2 language identifier.\r | |
326 | This is the language of the driver name that that the caller\r | |
327 | is requesting, and it must match one of the languages specified\r | |
328 | in SupportedLanguages. The number of languages supported by a\r | |
329 | driver is up to the driver writer.\r | |
330 | @param DriverName A pointer to the Unicode string to return. This Unicode string\r | |
331 | is the name of the driver specified by This in the language\r | |
332 | specified by Language.\r | |
333 | \r | |
334 | @retval EFI_SUCCESS The Unicode string for the Driver specified by This\r | |
335 | and the language specified by Language was returned\r | |
336 | in DriverName.\r | |
337 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
338 | @retval EFI_INVALID_PARAMETER DriverName is NULL.\r | |
339 | @retval EFI_UNSUPPORTED The driver specified by This does not support the\r | |
340 | language specified by Language.\r | |
341 | **/\r | |
342 | EFI_STATUS\r | |
343 | EFIAPI\r | |
344 | SataControllerComponentNameGetDriverName (\r | |
345 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
346 | IN CHAR8 *Language,\r | |
347 | OUT CHAR16 **DriverName\r | |
348 | )\r | |
349 | ;\r | |
350 | \r | |
351 | /**\r | |
352 | Retrieves a Unicode string that is the user readable name of the controller\r | |
353 | that is being managed by an UEFI Driver.\r | |
354 | \r | |
355 | @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r | |
356 | @param ControllerHandle The handle of a controller that the driver specified by\r | |
357 | This is managing. This handle specifies the controller\r | |
358 | whose name is to be returned.\r | |
359 | @param OPTIONAL ChildHandle The handle of the child controller to retrieve the name\r | |
360 | of. This is an optional parameter that may be NULL. It\r | |
361 | will be NULL for device drivers. It will also be NULL\r | |
362 | for a bus drivers that wish to retrieve the name of the\r | |
363 | bus controller. It will not be NULL for a bus driver\r | |
364 | that wishes to retrieve the name of a child controller.\r | |
365 | @param Language A pointer to a three character ISO 639-2 language\r | |
366 | identifier. This is the language of the controller name\r | |
367 | that that the caller is requesting, and it must match one\r | |
368 | of the languages specified in SupportedLanguages. The\r | |
369 | number of languages supported by a driver is up to the\r | |
370 | driver writer.\r | |
371 | @param ControllerName A pointer to the Unicode string to return. This Unicode\r | |
372 | string is the name of the controller specified by\r | |
373 | ControllerHandle and ChildHandle in the language\r | |
374 | specified by Language from the point of view of the\r | |
375 | driver specified by This.\r | |
376 | \r | |
377 | @retval EFI_SUCCESS The Unicode string for the user readable name in the\r | |
378 | language specified by Language for the driver\r | |
379 | specified by This was returned in DriverName.\r | |
380 | @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r | |
381 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r | |
382 | EFI_HANDLE.\r | |
383 | @retval EFI_INVALID_PARAMETER Language is NULL.\r | |
384 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r | |
385 | @retval EFI_UNSUPPORTED The driver specified by This is not currently\r | |
386 | managing the controller specified by\r | |
387 | ControllerHandle and ChildHandle.\r | |
388 | @retval EFI_UNSUPPORTED The driver specified by This does not support the\r | |
389 | language specified by Language.\r | |
390 | **/\r | |
391 | EFI_STATUS\r | |
392 | EFIAPI\r | |
393 | SataControllerComponentNameGetControllerName (\r | |
394 | IN EFI_COMPONENT_NAME_PROTOCOL *This,\r | |
395 | IN EFI_HANDLE ControllerHandle,\r | |
396 | IN EFI_HANDLE ChildHandle OPTIONAL,\r | |
397 | IN CHAR8 *Language,\r | |
398 | OUT CHAR16 **ControllerName\r | |
399 | )\r | |
400 | ;\r | |
401 | \r | |
402 | #endif\r |