]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Bus/Pci/IdeControllerDxe/IdeController.c
Refine function comment to follow doxygen format.
[mirror_edk2.git] / PcAtChipsetPkg / Bus / Pci / IdeControllerDxe / IdeController.c
CommitLineData
a1f11f75 1/** @file\r
2 This driver module produces IDE_CONTROLLER_INIT protocol and will be used by \r
3 IDE Bus driver to support platform dependent timing information. This driver\r
4 is responsible for early initialization of IDE controller.\r
5\r
20c1e33f 6 Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
95d48e82 7 This program and the accompanying materials \r
a1f11f75 8 are licensed and made available under the terms and conditions of the BSD License \r
9 which accompanies this distribution. The full text of the license may be found at \r
10 http://opensource.org/licenses/bsd-license.php \r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
14\r
15**/\r
16\r
17#include "IdeController.h"\r
18\r
19//\r
20// EFI_DRIVER_BINDING_PROTOCOL instance\r
21//\r
22EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding = {\r
23 IdeControllerSupported,\r
24 IdeControllerStart,\r
25 IdeControllerStop,\r
26 0xa,\r
27 NULL,\r
28 NULL\r
29};\r
30\r
20c1e33f 31///\r
32/// EFI_IDE_CONTROLLER_PROVATE_DATA Template\r
33///\r
a1f11f75 34EFI_IDE_CONTROLLER_INIT_PROTOCOL gEfiIdeControllerInit = {\r
35 IdeInitGetChannelInfo,\r
36 IdeInitNotifyPhase,\r
37 IdeInitSubmitData,\r
38 IdeInitDisqualifyMode,\r
39 IdeInitCalculateMode,\r
40 IdeInitSetTiming,\r
41 ICH_IDE_ENUMER_ALL,\r
42 ICH_IDE_MAX_CHANNEL\r
43};\r
44\r
20c1e33f 45///\r
46/// EFI_ATA_COLLECTIVE_MODE Template\r
47///\r
a1f11f75 48EFI_ATA_COLLECTIVE_MODE gEfiAtaCollectiveModeTemplate = {\r
49 { \r
50 TRUE, // PioMode.Valid\r
51 0 // PioMode.Mode\r
52 },\r
53 {\r
54 TRUE, // SingleWordDmaMode.Valid\r
55 0\r
56 },\r
57 {\r
58 FALSE, // MultiWordDmaMode.Valid\r
59 0\r
60 },\r
61 {\r
62 TRUE, // UdmaMode.Valid\r
63 0 // UdmaMode.Mode\r
64 }\r
65};\r
66\r
20c1e33f 67/**\r
68 Chipset Ide Driver EntryPoint function. It follows the standard EFI driver model. \r
69 It's called by StartImage() of DXE Core.\r
70\r
71 @param ImageHandle While the driver image loaded be the ImageLoader(), \r
72 an image handle is assigned to this driver binary, \r
73 all activities of the driver is tied to this ImageHandle\r
74 @param SystemTable A pointer to the system table, for all BS(Boo Services) and\r
75 RT(Runtime Services)\r
76 \r
77 @return EFI_STATUS Status of EfiLibInstallDriverBindingComponentName2().\r
78**/\r
a1f11f75 79EFI_STATUS\r
80EFIAPI\r
81InitializeIdeControllerDriver (\r
82 IN EFI_HANDLE ImageHandle,\r
83 IN EFI_SYSTEM_TABLE *SystemTable\r
84 )\r
a1f11f75 85{\r
86 EFI_STATUS Status;\r
87\r
88 //\r
89 // Install driver model protocol(s).\r
90 //\r
91 Status = EfiLibInstallDriverBindingComponentName2 (\r
92 ImageHandle,\r
93 SystemTable,\r
94 &gIdeControllerDriverBinding,\r
95 ImageHandle,\r
96 &gIdeControllerComponentName,\r
97 &gIdeControllerComponentName2\r
98 );\r
99 ASSERT_EFI_ERROR (Status);\r
100\r
101 return Status;\r
102}\r
103\r
20c1e33f 104/**\r
105 Register Driver Binding protocol for this driver.\r
106\r
107 @param This A pointer points to the Binding Protocol instance\r
108 @param Controller The handle of controller to be tested. \r
109 @param RemainingDevicePath A pointer to the device path. Ignored by device\r
110 driver but used by bus driver\r
111 \r
112 @retval EFI_SUCCESS Driver loaded. \r
113 @retval !EFI_SUCESS Driver not loaded. \r
114**/\r
a1f11f75 115EFI_STATUS\r
116EFIAPI\r
117IdeControllerSupported (\r
118 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
119 IN EFI_HANDLE Controller,\r
120 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
121 )\r
a1f11f75 122{\r
123 EFI_STATUS Status;\r
124 EFI_PCI_IO_PROTOCOL *PciIo;\r
125 UINT8 PciClass;\r
126 UINT8 PciSubClass;\r
127\r
128 //\r
129 // Attempt to Open PCI I/O Protocol\r
130 //\r
131 Status = gBS->OpenProtocol (\r
132 Controller,\r
133 &gEfiPciIoProtocolGuid,\r
134 (VOID **) &PciIo,\r
135 This->DriverBindingHandle,\r
136 Controller,\r
137 EFI_OPEN_PROTOCOL_BY_DRIVER\r
138 );\r
139 if (EFI_ERROR (Status)) {\r
140 return Status;\r
141 }\r
142\r
143 //\r
144 // Now further check the PCI header: Base class (offset 0x0B) and\r
145 // Sub Class (offset 0x0A). This controller should be an Ide controller\r
146 //\r
147 Status = PciIo->Pci.Read (\r
148 PciIo,\r
149 EfiPciIoWidthUint8,\r
150 PCI_CLASSCODE_OFFSET + 2,\r
151 1,\r
152 &PciClass\r
153 );\r
154 if (EFI_ERROR (Status)) {\r
155 goto Done;\r
156 }\r
157\r
158 Status = PciIo->Pci.Read (\r
159 PciIo,\r
160 EfiPciIoWidthUint8,\r
161 PCI_CLASSCODE_OFFSET + 1,\r
162 1,\r
163 &PciSubClass\r
164 );\r
165 if (EFI_ERROR (Status)) {\r
166 goto Done;\r
167 }\r
168\r
169 //\r
170 // Examine Ide PCI Configuration table fields\r
171 //\r
172 if ((PciClass != PCI_CLASS_MASS_STORAGE) || (PciSubClass != PCI_CLASS_MASS_STORAGE_IDE)) {\r
173 Status = EFI_UNSUPPORTED;\r
174 }\r
175\r
176Done:\r
177 gBS->CloseProtocol (\r
178 Controller,\r
179 &gEfiPciIoProtocolGuid,\r
180 This->DriverBindingHandle,\r
181 Controller\r
182 );\r
183\r
184 return Status;\r
185}\r
186\r
20c1e33f 187/**\r
188 This routine is called right after the .Supported() called and return \r
189 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols\r
190 are closed. \r
191\r
192 @param This A pointer points to the Binding Protocol instance\r
193 @param Controller The handle of controller to be tested. Parameter\r
194 passed by the caller\r
195 @param RemainingDevicePath A pointer to the device path. Should be ignored by\r
196 device driver\r
197 \r
198 @return EFI_STATUS Status of InstallMultipleProtocolInterfaces()\r
199**/\r
a1f11f75 200EFI_STATUS\r
201EFIAPI\r
202IdeControllerStart (\r
203 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
204 IN EFI_HANDLE Controller,\r
205 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
206 )\r
a1f11f75 207{\r
208 EFI_STATUS Status;\r
209 EFI_PCI_IO_PROTOCOL *PciIo;\r
210\r
211 //\r
212 // Now test and open the EfiPciIoProtocol\r
213 //\r
214 Status = gBS->OpenProtocol (\r
215 Controller,\r
216 &gEfiPciIoProtocolGuid,\r
217 (VOID **) &PciIo,\r
218 This->DriverBindingHandle,\r
219 Controller,\r
220 EFI_OPEN_PROTOCOL_BY_DRIVER\r
221 );\r
222 //\r
223 // Status == EFI_SUCCESS - A normal execution flow, SUCCESS and the program proceeds.\r
224 // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates\r
225 // that the protocol has been opened and should be treated as a\r
226 // normal condition and the program proceeds. The Protocol will not\r
227 // opened 'again' by this call.\r
228 // Status != ALREADY_STARTED - Error status, terminate program execution\r
229 //\r
230 if (EFI_ERROR (Status)) {\r
231 return Status;\r
232 }\r
233\r
234 //\r
235 // Install IDE_CONTROLLER_INIT protocol \r
236 //\r
237 return gBS->InstallMultipleProtocolInterfaces (\r
238 &Controller,\r
239 &gEfiIdeControllerInitProtocolGuid, &gEfiIdeControllerInit,\r
240 NULL\r
241 );\r
242}\r
243\r
20c1e33f 244/**\r
245 Stop this driver on Controller Handle. \r
246\r
247 @param This Protocol instance pointer.\r
248 @param Controller Handle of device to stop driver on \r
249 @param NumberOfChildren Not used\r
250 @param ChildHandleBuffer Not used\r
251 \r
252 @retval EFI_SUCESS This driver is removed DeviceHandle \r
253 @retval !EFI_SUCCESS This driver was not removed from this device \r
254**/\r
a1f11f75 255EFI_STATUS\r
256EFIAPI\r
257IdeControllerStop (\r
258 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
259 IN EFI_HANDLE Controller,\r
260 IN UINTN NumberOfChildren,\r
261 IN EFI_HANDLE *ChildHandleBuffer\r
262 )\r
a1f11f75 263{\r
264 EFI_STATUS Status;\r
265 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeControllerInit;\r
266\r
267 //\r
268 // Open the produced protocol\r
269 //\r
270 Status = gBS->OpenProtocol (\r
271 Controller,\r
272 &gEfiIdeControllerInitProtocolGuid,\r
273 (VOID **) &IdeControllerInit,\r
274 This->DriverBindingHandle,\r
275 Controller,\r
276 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
277 );\r
278 if (EFI_ERROR (Status)) {\r
279 return EFI_UNSUPPORTED;\r
280 }\r
281\r
282 //\r
283 // Make sure the protocol was produced by this driver\r
284 //\r
285 if (IdeControllerInit != &gEfiIdeControllerInit) {\r
286 return EFI_UNSUPPORTED;\r
287 }\r
288\r
289 //\r
290 // Uninstall the IDE Controller Init Protocol\r
291 //\r
292 Status = gBS->UninstallMultipleProtocolInterfaces (\r
293 Controller,\r
294 &gEfiIdeControllerInitProtocolGuid, &gEfiIdeControllerInit,\r
295 NULL\r
296 );\r
297 if (EFI_ERROR (Status)) {\r
298 return Status;\r
299 }\r
300\r
301 //\r
302 // Close protocols opened by Ide controller driver\r
303 //\r
304 return gBS->CloseProtocol (\r
305 Controller,\r
306 &gEfiPciIoProtocolGuid,\r
307 This->DriverBindingHandle,\r
308 Controller\r
309 );\r
310}\r
311\r
312//\r
313// Interface functions of IDE_CONTROLLER_INIT protocol\r
314//\r
20c1e33f 315/**\r
316 This function can be used to obtain information about a specified channel. \r
317 It's usually used by IDE Bus driver during enumeration process. \r
318\r
319 @param This the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
320 @param Channel Channel number (0 based, either 0 or 1)\r
321 @param Enabled TRUE if the channel is enabled. If the channel is disabled, \r
322 then it will no be enumerated.\r
323 @param MaxDevices The Max number of IDE devices that the bus driver can expect\r
324 on this channel. For ATA/ATAPI, this number is either 1 or 2.\r
325 \r
326 @retval EFI_SUCCESS Success to get channel information\r
327 @retval EFI_INVALID_PARAMETER Invalid channel id.\r
328**/\r
a1f11f75 329EFI_STATUS\r
330EFIAPI\r
331IdeInitGetChannelInfo (\r
332 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
333 IN UINT8 Channel,\r
334 OUT BOOLEAN *Enabled,\r
335 OUT UINT8 *MaxDevices\r
336 )\r
a1f11f75 337{\r
338 //\r
339 // Channel number (0 based, either 0 or 1)\r
340 //\r
341 if (Channel < ICH_IDE_MAX_CHANNEL) {\r
342 *Enabled = TRUE;\r
343 *MaxDevices = ICH_IDE_MAX_DEVICES;\r
344 return EFI_SUCCESS;\r
345 }\r
346\r
347 *Enabled = FALSE;\r
348 return EFI_INVALID_PARAMETER;\r
349}\r
350\r
20c1e33f 351/**\r
352 This function is called by IdeBus driver before executing certain actions. \r
353 This allows IDE Controller Init to prepare for each action. \r
a1f11f75 354\r
20c1e33f 355 @param This the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
356 @param Phase phase indicator defined by IDE_CONTROLLER_INIT protocol\r
357 @param Channel Channel number (0 based, either 0 or 1)\r
358 \r
359 @return EFI_SUCCESS Success operation.\r
360**/\r
a1f11f75 361EFI_STATUS\r
362EFIAPI\r
363IdeInitNotifyPhase (\r
364 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
365 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,\r
366 IN UINT8 Channel\r
367 )\r
a1f11f75 368{\r
369 return EFI_SUCCESS;\r
370}\r
371\r
20c1e33f 372/**\r
373 This function is called by IdeBus driver to submit EFI_IDENTIFY_DATA data structure\r
374 obtained from IDE deivce. This structure is used to set IDE timing \r
375\r
376 @param This The EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
377 @param Channel IDE channel number (0 based, either 0 or 1)\r
378 @param Device IDE device number\r
379 @param IdentifyData A pointer to EFI_IDENTIFY_DATA data structure\r
380 \r
381 @return EFI_SUCCESS Success operation. \r
382**/\r
a1f11f75 383EFI_STATUS\r
384EFIAPI\r
385IdeInitSubmitData (\r
386 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
387 IN UINT8 Channel,\r
388 IN UINT8 Device,\r
389 IN EFI_IDENTIFY_DATA *IdentifyData\r
390 )\r
a1f11f75 391{\r
392 return EFI_SUCCESS;\r
393}\r
394\r
20c1e33f 395/**\r
396 This function is called by IdeBus driver to disqualify unsupported operation\r
397 mode on specfic IDE device \r
398\r
399 @param This the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
400 @param Channel IDE channel number (0 based, either 0 or 1)\r
401 @param Device IDE device number\r
402 @param BadModes Operation mode indicator\r
403 \r
404 @return EFI_SUCCESS Success operation. \r
405**/\r
a1f11f75 406EFI_STATUS\r
407EFIAPI\r
408IdeInitDisqualifyMode (\r
409 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
410 IN UINT8 Channel,\r
411 IN UINT8 Device,\r
412 IN EFI_ATA_COLLECTIVE_MODE *BadModes\r
413 )\r
a1f11f75 414{\r
415 return EFI_SUCCESS;\r
416}\r
417\r
20c1e33f 418/**\r
419 This function is called by IdeBus driver to calculate the best operation mode\r
420 supported by specific IDE device \r
421\r
422 @param This the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
423 @param Channel IDE channel number (0 based, either 0 or 1)\r
424 @param Device IDE device number\r
425 @param SupportedModes Modes collection supported by IDE device\r
426 \r
427 @retval EFI_OUT_OF_RESOURCES Fail to allocate pool. \r
428 @retval EFI_INVALID_PARAMETER Invalid channel id and device id.\r
429**/\r
a1f11f75 430EFI_STATUS\r
431EFIAPI\r
432IdeInitCalculateMode (\r
433 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
434 IN UINT8 Channel,\r
435 IN UINT8 Device,\r
436 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes\r
437 )\r
a1f11f75 438{\r
439 if (Channel >= ICH_IDE_MAX_CHANNEL || Device >= ICH_IDE_MAX_DEVICES) {\r
440 return EFI_INVALID_PARAMETER;\r
441 }\r
442\r
443 *SupportedModes = AllocateCopyPool (sizeof (EFI_ATA_COLLECTIVE_MODE), &gEfiAtaCollectiveModeTemplate);\r
444 if (*SupportedModes == NULL) {\r
445 return EFI_OUT_OF_RESOURCES;\r
446 }\r
447\r
448 return EFI_SUCCESS;\r
449}\r
450\r
20c1e33f 451/**\r
452 This function is called by IdeBus driver to set appropriate timing on IDE\r
453 controller according supported operation mode. \r
a1f11f75 454\r
20c1e33f 455 @param This the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
456 @param Channel IDE channel number (0 based, either 0 or 1)\r
457 @param Device IDE device number\r
458 @param Modes IDE device modes\r
459 \r
460 @retval EFI_SUCCESS Sucess operation.\r
461**/\r
a1f11f75 462EFI_STATUS\r
463EFIAPI\r
464IdeInitSetTiming (\r
465 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
466 IN UINT8 Channel,\r
467 IN UINT8 Device,\r
468 IN EFI_ATA_COLLECTIVE_MODE *Modes\r
469 )\r
a1f11f75 470{\r
471 return EFI_SUCCESS;\r
472}\r