VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxIdeControllerDxe/IdeController.c@ 48674

Last change on this file since 48674 was 48674, checked in by vboxsync, 11 years ago

EFI: Export newly imported tinaocore UEFI sources to OSE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.9 KB
Line 
1/* $Id: IdeController.c 48674 2013-09-25 08:26:15Z vboxsync $ */
2/** @file
3 * IdeController.c
4 */
5
6/*
7 * Copyright (C) 2009-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/** @file
28 This driver module produces IDE_CONTROLLER_INIT protocol and will be used by
29 IDE Bus driver to support platform dependent timing information. This driver
30 is responsible for early initialization of IDE controller.
31
32 Copyright (c) 2008 - 2009 Intel Corporation. <BR>
33 All rights reserved. This program and the accompanying materials
34 are licensed and made available under the terms and conditions of the BSD License
35 which accompanies this distribution. The full text of the license may be found at
36 http://opensource.org/licenses/bsd-license.php
37
38 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
39 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
40
41**/
42
43#include "IdeController.h"
44
45//
46// EFI_DRIVER_BINDING_PROTOCOL instance
47//
48EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding = {
49 IdeControllerSupported,
50 IdeControllerStart,
51 IdeControllerStop,
52 0xa,
53 NULL,
54 NULL
55};
56
57//
58// EFI_IDE_CONTROLLER_PROVATE_DATA Template
59//
60EFI_IDE_CONTROLLER_INIT_PROTOCOL gEfiIdeControllerInit = {
61 IdeInitGetChannelInfo,
62 IdeInitNotifyPhase,
63 IdeInitSubmitData,
64 IdeInitDisqualifyMode,
65 IdeInitCalculateMode,
66 IdeInitSetTiming,
67 ICH_IDE_ENUMER_ALL,
68 ICH_IDE_MAX_CHANNEL
69};
70
71//
72// EFI_ATA_COLLECTIVE_MODE Template
73//
74EFI_ATA_COLLECTIVE_MODE gEfiAtaCollectiveModeTemplate = {
75 {
76 TRUE, // PioMode.Valid
77 0 // PioMode.Mode
78 },
79 {
80 TRUE, // SingleWordDmaMode.Valid
81 0
82 },
83 {
84 FALSE, // MultiWordDmaMode.Valid
85 0
86 },
87 {
88 TRUE, // UdmaMode.Valid
89 0 // UdmaMode.Mode
90 }
91};
92
93static BOOLEAN gfIdeAhciEmulation = FALSE;
94
95EFI_STATUS
96EFIAPI
97InitializeIdeControllerDriver (
98 IN EFI_HANDLE ImageHandle,
99 IN EFI_SYSTEM_TABLE *SystemTable
100 )
101/*++
102 Routine Description:
103
104 Chipset Ide Driver EntryPoint function. It follows the standard EFI driver
105 model. It's called by StartImage() of DXE Core
106
107 Arguments:
108
109 ImageHandle -- While the driver image loaded be the ImageLoader(),
110 an image handle is assigned to this driver binary,
111 all activities of the driver is tied to this ImageHandle
112 *SystemTable -- A pointer to the system table, for all BS(Boo Services) and
113 RT(Runtime Services)
114
115 Returns:
116
117 Always call EfiLibInstallDriverBindingProtocol( ) and return the result
118
119--*/
120{
121 EFI_STATUS Status;
122
123 //
124 // Install driver model protocol(s).
125 //
126 Status = EfiLibInstallDriverBindingComponentName2 (
127 ImageHandle,
128 SystemTable,
129 &gIdeControllerDriverBinding,
130 ImageHandle,
131 &gIdeControllerComponentName,
132 &gIdeControllerComponentName2
133 );
134 ASSERT_EFI_ERROR (Status);
135
136 return Status;
137}
138
139EFI_STATUS
140EFIAPI
141IdeControllerSupported (
142 IN EFI_DRIVER_BINDING_PROTOCOL *This,
143 IN EFI_HANDLE Controller,
144 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
145 )
146/*++
147
148 Routine Description:
149
150 Register Driver Binding protocol for this driver.
151
152 Arguments:
153
154 This -- a pointer points to the Binding Protocol instance
155 Controller -- The handle of controller to be tested.
156 *RemainingDevicePath -- A pointer to the device path. Ignored by device
157 driver but used by bus driver
158
159 Returns:
160
161 EFI_SUCCESS -- Driver loaded.
162 other -- Driver not loaded.
163--*/
164{
165 EFI_STATUS Status;
166 EFI_PCI_IO_PROTOCOL *PciIo;
167 UINT8 PciClass;
168 UINT8 PciSubClass;
169
170 //
171 // Attempt to Open PCI I/O Protocol
172 //
173 Status = gBS->OpenProtocol (
174 Controller,
175 &gEfiPciIoProtocolGuid,
176 (VOID **) &PciIo,
177 This->DriverBindingHandle,
178 Controller,
179 EFI_OPEN_PROTOCOL_BY_DRIVER
180 );
181 if (EFI_ERROR (Status)) {
182 return Status;
183 }
184
185 //
186 // Now further check the PCI header: Base class (offset 0x0B) and
187 // Sub Class (offset 0x0A). This controller should be an Ide controller
188 //
189 Status = PciIo->Pci.Read (
190 PciIo,
191 EfiPciIoWidthUint8,
192 PCI_CLASSCODE_OFFSET + 2,
193 1,
194 &PciClass
195 );
196 if (EFI_ERROR (Status)) {
197 goto Done;
198 }
199
200 Status = PciIo->Pci.Read (
201 PciIo,
202 EfiPciIoWidthUint8,
203 PCI_CLASSCODE_OFFSET + 1,
204 1,
205 &PciSubClass
206 );
207 if (EFI_ERROR (Status)) {
208 goto Done;
209 }
210
211 //
212 // Examine Ide PCI Configuration table fields
213 //
214 if ((PciClass != PCI_CLASS_MASS_STORAGE) || ((PciSubClass != PCI_CLASS_MASS_STORAGE_IDE) && (PciSubClass != 0x06 /*SATA*/))) {
215 Status = EFI_UNSUPPORTED;
216 }
217 if (PciSubClass == 0x6)
218 gfIdeAhciEmulation = TRUE;
219
220Done:
221 gBS->CloseProtocol (
222 Controller,
223 &gEfiPciIoProtocolGuid,
224 This->DriverBindingHandle,
225 Controller
226 );
227
228 return Status;
229}
230
231EFI_STATUS
232EFIAPI
233IdeControllerStart (
234 IN EFI_DRIVER_BINDING_PROTOCOL *This,
235 IN EFI_HANDLE Controller,
236 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
237 )
238/*++
239
240 Routine Description:
241
242 This routine is called right after the .Supported() called and return
243 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols
244 are closed.
245
246 Arguments:
247
248 This -- a pointer points to the Binding Protocol instance
249 Controller -- The handle of controller to be tested. Parameter
250 passed by the caller
251 *RemainingDevicePath -- A pointer to the device path. Should be ignored by
252 device driver
253--*/
254{
255 EFI_STATUS Status;
256 EFI_PCI_IO_PROTOCOL *PciIo;
257
258 //
259 // Now test and open the EfiPciIoProtocol
260 //
261 Status = gBS->OpenProtocol (
262 Controller,
263 &gEfiPciIoProtocolGuid,
264 (VOID **) &PciIo,
265 This->DriverBindingHandle,
266 Controller,
267 EFI_OPEN_PROTOCOL_BY_DRIVER
268 );
269 //
270 // Status == EFI_SUCCESS - A normal execution flow, SUCCESS and the program proceeds.
271 // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates
272 // that the protocol has been opened and should be treated as a
273 // normal condition and the program proceeds. The Protocol will not
274 // opened 'again' by this call.
275 // Status != ALREADY_STARTED - Error status, terminate program execution
276 //
277 if (EFI_ERROR (Status)) {
278 return Status;
279 }
280
281 //
282 // Install IDE_CONTROLLER_INIT protocol
283 //
284 return gBS->InstallMultipleProtocolInterfaces (
285 &Controller,
286 &gEfiIdeControllerInitProtocolGuid, &gEfiIdeControllerInit,
287 NULL
288 );
289}
290
291EFI_STATUS
292EFIAPI
293IdeControllerStop (
294 IN EFI_DRIVER_BINDING_PROTOCOL *This,
295 IN EFI_HANDLE Controller,
296 IN UINTN NumberOfChildren,
297 IN EFI_HANDLE *ChildHandleBuffer
298 )
299/*++
300
301 Routine Description:
302 Stop this driver on Controller Handle.
303
304 Arguments:
305 This - Protocol instance pointer.
306 Controller - Handle of device to stop driver on
307 NumberOfChildren - Not used
308 ChildHandleBuffer - Not used
309
310 Returns:
311 EFI_SUCCESS - This driver is removed DeviceHandle
312 other - This driver was not removed from this device
313
314--*/
315{
316 EFI_STATUS Status;
317 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeControllerInit;
318
319 //
320 // Open the produced protocol
321 //
322 Status = gBS->OpenProtocol (
323 Controller,
324 &gEfiIdeControllerInitProtocolGuid,
325 (VOID **) &IdeControllerInit,
326 This->DriverBindingHandle,
327 Controller,
328 EFI_OPEN_PROTOCOL_GET_PROTOCOL
329 );
330 if (EFI_ERROR (Status)) {
331 return EFI_UNSUPPORTED;
332 }
333
334 //
335 // Make sure the protocol was produced by this driver
336 //
337 if (IdeControllerInit != &gEfiIdeControllerInit) {
338 return EFI_UNSUPPORTED;
339 }
340
341 //
342 // Uninstall the IDE Controller Init Protocol
343 //
344 Status = gBS->UninstallMultipleProtocolInterfaces (
345 Controller,
346 &gEfiIdeControllerInitProtocolGuid, &gEfiIdeControllerInit,
347 NULL
348 );
349 if (EFI_ERROR (Status)) {
350 return Status;
351 }
352
353 //
354 // Close protocols opened by Ide controller driver
355 //
356 return gBS->CloseProtocol (
357 Controller,
358 &gEfiPciIoProtocolGuid,
359 This->DriverBindingHandle,
360 Controller
361 );
362}
363
364//
365// Interface functions of IDE_CONTROLLER_INIT protocol
366//
367EFI_STATUS
368EFIAPI
369IdeInitGetChannelInfo (
370 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
371 IN UINT8 Channel,
372 OUT BOOLEAN *Enabled,
373 OUT UINT8 *MaxDevices
374 )
375/*++
376Routine Description:
377
378 This function can be used to obtain information about a specified channel.
379 It's usually used by IDE Bus driver during enumeration process.
380
381Arguments:
382
383 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
384 Channel -- Channel number (0 based, either 0 or 1)
385 Enabled -- TRUE if the channel is enabled. If the channel is disabled,
386 then it will no be enumerated.
387 MaxDevices -- The Max number of IDE devices that the bus driver can expect
388 on this channel. For ATA/ATAPI, this number is either 1 or 2.
389
390Returns:
391 EFI_STATUS
392
393--*/
394{
395 //
396 // Channel number (0 based, either 0 or 1)
397 //
398 if (Channel < ICH_IDE_MAX_CHANNEL) {
399 *Enabled = TRUE;
400 *MaxDevices = ICH_IDE_MAX_DEVICES;
401 return EFI_SUCCESS;
402 }
403
404 *Enabled = FALSE;
405 return EFI_INVALID_PARAMETER;
406}
407
408
409EFI_STATUS
410EFIAPI
411IdeInitNotifyPhase (
412 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
413 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,
414 IN UINT8 Channel
415 )
416/*++
417
418Routine Description:
419
420 This function is called by IdeBus driver before executing certain actions.
421 This allows IDE Controller Init to prepare for each action.
422
423Arguments:
424
425 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
426 Phase -- phase indicator defined by IDE_CONTROLLER_INIT protocol
427 Channel -- Channel number (0 based, either 0 or 1)
428
429Returns:
430
431--*/
432{
433 return EFI_SUCCESS;
434}
435
436EFI_STATUS
437EFIAPI
438IdeInitSubmitData (
439 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
440 IN UINT8 Channel,
441 IN UINT8 Device,
442 IN EFI_IDENTIFY_DATA *IdentifyData
443 )
444/*++
445
446Routine Description:
447
448 This function is called by IdeBus driver to submit EFI_IDENTIFY_DATA data structure
449 obtained from IDE deivce. This structure is used to set IDE timing
450
451Arguments:
452
453 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
454 Channel -- IDE channel number (0 based, either 0 or 1)
455 Device -- IDE device number
456 IdentifyData -- A pointer to EFI_IDENTIFY_DATA data structure
457
458Returns:
459
460--*/
461{
462 return EFI_SUCCESS;
463}
464
465EFI_STATUS
466EFIAPI
467IdeInitDisqualifyMode (
468 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
469 IN UINT8 Channel,
470 IN UINT8 Device,
471 IN EFI_ATA_COLLECTIVE_MODE *BadModes
472 )
473/*++
474
475Routine Description:
476
477 This function is called by IdeBus driver to disqualify unsupported operation
478 mode on specific IDE device
479
480Arguments:
481
482 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
483 Channel -- IDE channel number (0 based, either 0 or 1)
484 Device -- IDE device number
485 BadModes -- Operation mode indicator
486
487Returns:
488
489--*/
490{
491 return EFI_SUCCESS;
492}
493
494EFI_STATUS
495EFIAPI
496IdeInitCalculateMode (
497 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
498 IN UINT8 Channel,
499 IN UINT8 Device,
500 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes
501 )
502/*++
503
504Routine Description:
505
506 This function is called by IdeBus driver to calculate the best operation mode
507 supported by specific IDE device
508
509Arguments:
510
511 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
512 Channel -- IDE channel number (0 based, either 0 or 1)
513 Device -- IDE device number
514 SupportedModes -- Modes collection supported by IDE device
515
516Returns:
517
518--*/
519{
520 if (Channel >= ICH_IDE_MAX_CHANNEL || Device >= ICH_IDE_MAX_DEVICES) {
521 return EFI_INVALID_PARAMETER;
522 }
523
524 *SupportedModes = AllocateCopyPool (sizeof (EFI_ATA_COLLECTIVE_MODE), &gEfiAtaCollectiveModeTemplate);
525 if (*SupportedModes == NULL) {
526 return EFI_OUT_OF_RESOURCES;
527 }
528 EFI_ATA_COLLECTIVE_MODE *pSupportedModes = (*SupportedModes);
529 pSupportedModes->PioMode.Mode = 3; /* AtaPioMode4 see VBoxIdeBusDxe/IdeData.h */
530 if (gfIdeAhciEmulation)
531 {
532 pSupportedModes->UdmaMode.Valid = FALSE;
533 pSupportedModes->MultiWordDmaMode.Valid = FALSE;
534 }
535
536 return EFI_SUCCESS;
537}
538
539
540EFI_STATUS
541EFIAPI
542IdeInitSetTiming (
543 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
544 IN UINT8 Channel,
545 IN UINT8 Device,
546 IN EFI_ATA_COLLECTIVE_MODE *Modes
547 )
548/*++
549
550Routine Description:
551
552 This function is called by IdeBus driver to set appropriate timing on IDE
553 controller according supported operation mode
554
555Arguments:
556
557 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
558 Channel -- IDE channel number (0 based, either 0 or 1)
559 Device -- IDE device number
560
561Returns:
562
563--*/
564{
565 return EFI_SUCCESS;
566}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette