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
);
111 if (EFI_ERROR (Status
)) {
116 // Try to open the Super IO protocol on the controller
118 Status
= gBS
->OpenProtocol (
120 &gEfiSioProtocolGuid
,
122 This
->DriverBindingHandle
,
124 EFI_OPEN_PROTOCOL_BY_DRIVER
126 if (!EFI_ERROR (Status
)) {
129 &gEfiSioProtocolGuid
,
130 This
->DriverBindingHandle
,
139 Start this driver on ControllerHandle.
141 The Start() function is designed to be invoked from the EFI boot service ConnectController().
142 As a result, much of the error checking on the parameters to Start() has been moved into this
143 common boot service. It is legal to call Start() from other locations, but the following calling
144 restrictions must be followed or the system behavior will not be deterministic.
145 1. ControllerHandle must be a valid EFI_HANDLE.
146 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
147 EFI_DEVICE_PATH_PROTOCOL.
148 3. Prior to calling Start(), the Supported() function for the driver specified by This must
149 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
151 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
152 @param[in] ControllerHandle The handle of the controller to start. This handle
153 must support a protocol interface that supplies
154 an I/O abstraction to the driver.
155 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
156 This parameter is ignored by device drivers, and is optional for bus drivers.
158 @retval EFI_SUCCESS The device was started.
159 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
160 Currently not implemented.
161 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
162 @retval Others The driver failded to start the device.
167 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
168 IN EFI_HANDLE Controller
,
169 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
173 EFI_PCI_IO_PROTOCOL
*PciIo
;
174 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
175 EFI_HANDLE PciHandle
;
176 EFI_SIO_PROTOCOL
*Sio
;
177 ACPI_RESOURCE_HEADER_PTR Resources
;
178 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
179 ISA_IO_DEVICE
*IsaIoDevice
;
185 // Open Device Path Protocol
187 Status
= gBS
->OpenProtocol (
189 &gEfiDevicePathProtocolGuid
,
190 (VOID
**) &DevicePath
,
191 This
->DriverBindingHandle
,
193 EFI_OPEN_PROTOCOL_GET_PROTOCOL
195 if (EFI_ERROR (Status
)) {
200 // Get the PciIo protocol from its parent controller.
202 TempDevicePath
= DevicePath
;
203 Status
= gBS
->LocateDevicePath (&gEfiPciIoProtocolGuid
, &TempDevicePath
, &PciHandle
);
204 if (!EFI_ERROR (Status
)) {
205 Status
= gBS
->HandleProtocol (PciHandle
, &gEfiPciIoProtocolGuid
, (VOID
**) &PciIo
);
206 ASSERT_EFI_ERROR (Status
);
209 // Open Super IO Protocol
211 Status
= gBS
->OpenProtocol (
213 &gEfiSioProtocolGuid
,
215 This
->DriverBindingHandle
,
217 EFI_OPEN_PROTOCOL_BY_DRIVER
221 if (EFI_ERROR (Status
)) {
223 // Fail due to LocateDevicePath(...) or OpenProtocol(Sio, BY_DRIVER)
228 Status
= Sio
->GetResources (Sio
, &Resources
);
229 ASSERT_EFI_ERROR (Status
);
231 IsaIoDevice
= AllocatePool (sizeof (ISA_IO_DEVICE
));
232 ASSERT (IsaIoDevice
!= NULL
);
234 IsaIoDevice
->Signature
= ISA_IO_DEVICE_SIGNATURE
;
235 IsaIoDevice
->PciIo
= PciIo
;
238 // Initialize the ISA I/O instance structure
240 InitializeIsaIoInstance (IsaIoDevice
, DevicePath
, Resources
);
243 // Install the ISA I/O protocol on the Controller handle
245 Status
= gBS
->InstallMultipleProtocolInterfaces (
247 &gEfiIsaIoProtocolGuid
,
251 ASSERT_EFI_ERROR (Status
);
257 Stop this driver on ControllerHandle.
259 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
260 As a result, much of the error checking on the parameters to Stop() has been moved
261 into this common boot service. It is legal to call Stop() from other locations,
262 but the following calling restrictions must be followed or the system behavior will not be deterministic.
263 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
264 same driver's Start() function.
265 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
266 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
267 Start() function, and the Start() function must have called OpenProtocol() on
268 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
270 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
271 @param[in] ControllerHandle A handle to the device being stopped. The handle must
272 support a bus specific I/O protocol for the driver
273 to use to stop the device.
274 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
275 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
276 if NumberOfChildren is 0.
278 @retval EFI_SUCCESS The device was stopped.
279 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
284 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
285 IN EFI_HANDLE Controller
,
286 IN UINTN NumberOfChildren
,
287 IN EFI_HANDLE
* ChildHandleBuffer OPTIONAL
291 ISA_IO_DEVICE
*IsaIoDevice
;
292 EFI_ISA_IO_PROTOCOL
*IsaIo
;
294 Status
= gBS
->OpenProtocol (
296 &gEfiIsaIoProtocolGuid
,
298 This
->DriverBindingHandle
,
300 EFI_OPEN_PROTOCOL_GET_PROTOCOL
302 if (EFI_ERROR (Status
)) {
303 return EFI_UNSUPPORTED
;
306 IsaIoDevice
= ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo
);
308 Status
= gBS
->UninstallMultipleProtocolInterfaces (
310 &gEfiIsaIoProtocolGuid
,
314 if (!EFI_ERROR (Status
)) {
315 Status
= gBS
->CloseProtocol (
317 &gEfiSioProtocolGuid
,
318 This
->DriverBindingHandle
,
321 FreePool (IsaIoDevice
->IsaIo
.ResourceList
);
322 FreePool (IsaIoDevice
);