4 Produce an instance of the ISA I/O Protocol for every SIO controller.
6 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "IsaDriver.h"
20 // IsaIo Driver Global Variables
22 EFI_DRIVER_BINDING_PROTOCOL gIsaIoDriver
= {
32 The main entry point for the IsaIo driver.
34 @param[in] ImageHandle The firmware allocated handle for the EFI image.
35 @param[in] SystemTable A pointer to the EFI System Table.
37 @retval EFI_SUCCESS The entry point is executed successfully.
38 @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to install all the protocols.
43 IN EFI_HANDLE ImageHandle
,
44 IN EFI_SYSTEM_TABLE
*SystemTable
50 // Install driver model protocol(s).
52 Status
= EfiLibInstallDriverBindingComponentName2 (
60 ASSERT_EFI_ERROR (Status
);
66 Tests to see if a controller can be managed by the IsaIo driver.
68 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
69 @param[in] Controller The handle of the controller to test.
70 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
72 @retval EFI_SUCCESS The device is supported by this driver.
73 @retval EFI_ALREADY_STARTED The device is already being managed by this driver.
74 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver
75 or an application that requires exclusive access.
76 @retval EFI_UNSUPPORTED The device is is not supported by this driver.
81 IsaIoDriverSupported (
82 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
83 IN EFI_HANDLE Controller
,
84 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
88 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
89 EFI_SIO_PROTOCOL
*Sio
;
93 // Try to open EFI DEVICE PATH protocol on the controller
95 Status
= gBS
->OpenProtocol (
97 &gEfiDevicePathProtocolGuid
,
98 (VOID
**) &DevicePath
,
99 This
->DriverBindingHandle
,
101 EFI_OPEN_PROTOCOL_GET_PROTOCOL
104 if (!EFI_ERROR (Status
)) {
106 // Get the PciIo protocol from its parent controller.
108 Status
= gBS
->LocateDevicePath (&gEfiPciIoProtocolGuid
, &DevicePath
, &PciHandle
);
109 if (!EFI_ERROR (Status
)) {
110 if ((DevicePathType (DevicePath
) != ACPI_DEVICE_PATH
) ||
111 ((DevicePathSubType (DevicePath
) != ACPI_DP
) && (DevicePathSubType (DevicePath
) != ACPI_EXTENDED_DP
))) {
112 Status
= EFI_UNSUPPORTED
;
117 if (EFI_ERROR (Status
)) {
122 // Try to open the Super IO protocol on the controller
124 Status
= gBS
->OpenProtocol (
126 &gEfiSioProtocolGuid
,
128 This
->DriverBindingHandle
,
130 EFI_OPEN_PROTOCOL_BY_DRIVER
132 if (!EFI_ERROR (Status
)) {
135 &gEfiSioProtocolGuid
,
136 This
->DriverBindingHandle
,
145 Start this driver on ControllerHandle.
147 The Start() function is designed to be invoked from the EFI boot service ConnectController().
148 As a result, much of the error checking on the parameters to Start() has been moved into this
149 common boot service. It is legal to call Start() from other locations, but the following calling
150 restrictions must be followed or the system behavior will not be deterministic.
151 1. ControllerHandle must be a valid EFI_HANDLE.
152 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
153 EFI_DEVICE_PATH_PROTOCOL.
154 3. Prior to calling Start(), the Supported() function for the driver specified by This must
155 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
157 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
158 @param[in] ControllerHandle The handle of the controller to start. This handle
159 must support a protocol interface that supplies
160 an I/O abstraction to the driver.
161 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
162 This parameter is ignored by device drivers, and is optional for bus drivers.
164 @retval EFI_SUCCESS The device was started.
165 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
166 Currently not implemented.
167 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
168 @retval Others The driver failded to start the device.
173 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
174 IN EFI_HANDLE Controller
,
175 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
179 EFI_PCI_IO_PROTOCOL
*PciIo
;
180 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
181 EFI_HANDLE PciHandle
;
182 EFI_SIO_PROTOCOL
*Sio
;
183 ACPI_RESOURCE_HEADER_PTR Resources
;
184 EFI_DEVICE_PATH_PROTOCOL
*AcpiNode
;
185 ISA_IO_DEVICE
*IsaIoDevice
;
191 // Open Device Path Protocol
193 Status
= gBS
->OpenProtocol (
195 &gEfiDevicePathProtocolGuid
,
196 (VOID
**) &DevicePath
,
197 This
->DriverBindingHandle
,
199 EFI_OPEN_PROTOCOL_GET_PROTOCOL
201 if (EFI_ERROR (Status
)) {
206 // Get the PciIo protocol from its parent controller.
208 AcpiNode
= DevicePath
;
209 Status
= gBS
->LocateDevicePath (&gEfiPciIoProtocolGuid
, &AcpiNode
, &PciHandle
);
210 if (!EFI_ERROR (Status
)) {
212 // AcpiNode should point to the ACPI node now.
214 ASSERT ((DevicePathType (AcpiNode
) == ACPI_DEVICE_PATH
) &&
215 ((DevicePathSubType (AcpiNode
) == ACPI_DP
) || (DevicePathSubType (AcpiNode
) == ACPI_EXTENDED_DP
))
218 Status
= gBS
->HandleProtocol (PciHandle
, &gEfiPciIoProtocolGuid
, (VOID
**) &PciIo
);
219 ASSERT_EFI_ERROR (Status
);
222 // Open Super IO Protocol
224 Status
= gBS
->OpenProtocol (
226 &gEfiSioProtocolGuid
,
228 This
->DriverBindingHandle
,
230 EFI_OPEN_PROTOCOL_BY_DRIVER
234 if (EFI_ERROR (Status
)) {
236 // Fail due to LocateDevicePath(...) or OpenProtocol(Sio, BY_DRIVER)
241 Status
= Sio
->GetResources (Sio
, &Resources
);
242 ASSERT_EFI_ERROR (Status
);
244 IsaIoDevice
= AllocatePool (sizeof (ISA_IO_DEVICE
));
245 ASSERT (IsaIoDevice
!= NULL
);
247 IsaIoDevice
->Signature
= ISA_IO_DEVICE_SIGNATURE
;
248 IsaIoDevice
->PciIo
= PciIo
;
251 // Initialize the ISA I/O instance structure
253 InitializeIsaIoInstance (IsaIoDevice
, DevicePath
, Resources
);
256 // Install the ISA I/O protocol on the Controller handle
258 Status
= gBS
->InstallMultipleProtocolInterfaces (
260 &gEfiIsaIoProtocolGuid
,
264 ASSERT_EFI_ERROR (Status
);
270 Stop this driver on ControllerHandle.
272 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
273 As a result, much of the error checking on the parameters to Stop() has been moved
274 into this common boot service. It is legal to call Stop() from other locations,
275 but the following calling restrictions must be followed or the system behavior will not be deterministic.
276 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
277 same driver's Start() function.
278 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
279 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
280 Start() function, and the Start() function must have called OpenProtocol() on
281 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
283 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
284 @param[in] ControllerHandle A handle to the device being stopped. The handle must
285 support a bus specific I/O protocol for the driver
286 to use to stop the device.
287 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
288 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
289 if NumberOfChildren is 0.
291 @retval EFI_SUCCESS The device was stopped.
292 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
297 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
298 IN EFI_HANDLE Controller
,
299 IN UINTN NumberOfChildren
,
300 IN EFI_HANDLE
* ChildHandleBuffer OPTIONAL
304 ISA_IO_DEVICE
*IsaIoDevice
;
305 EFI_ISA_IO_PROTOCOL
*IsaIo
;
307 Status
= gBS
->OpenProtocol (
309 &gEfiIsaIoProtocolGuid
,
311 This
->DriverBindingHandle
,
313 EFI_OPEN_PROTOCOL_GET_PROTOCOL
315 if (EFI_ERROR (Status
)) {
316 return EFI_UNSUPPORTED
;
319 IsaIoDevice
= ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo
);
321 Status
= gBS
->UninstallMultipleProtocolInterfaces (
323 &gEfiIsaIoProtocolGuid
,
327 if (!EFI_ERROR (Status
)) {
328 Status
= gBS
->CloseProtocol (
330 &gEfiSioProtocolGuid
,
331 This
->DriverBindingHandle
,
334 FreePool (IsaIoDevice
->IsaIo
.ResourceList
);
335 FreePool (IsaIoDevice
);