4 Produce an instance of the ISA I/O Protocol for every SIO controller.
6 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "IsaDriver.h"
14 // IsaIo Driver Global Variables
16 EFI_DRIVER_BINDING_PROTOCOL gIsaIoDriver
= {
26 The main entry point for the IsaIo driver.
28 @param[in] ImageHandle The firmware allocated handle for the EFI image.
29 @param[in] SystemTable A pointer to the EFI System Table.
31 @retval EFI_SUCCESS The entry point is executed successfully.
32 @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to install all the protocols.
37 IN EFI_HANDLE ImageHandle
,
38 IN EFI_SYSTEM_TABLE
*SystemTable
44 // Install driver model protocol(s).
46 Status
= EfiLibInstallDriverBindingComponentName2 (
54 ASSERT_EFI_ERROR (Status
);
60 Tests to see if a controller can be managed by the IsaIo driver.
62 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
63 @param[in] Controller The handle of the controller to test.
64 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
66 @retval EFI_SUCCESS The device is supported by this driver.
67 @retval EFI_ALREADY_STARTED The device is already being managed by this driver.
68 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver
69 or an application that requires exclusive access.
70 @retval EFI_UNSUPPORTED The device is is not supported by this driver.
75 IsaIoDriverSupported (
76 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
77 IN EFI_HANDLE Controller
,
78 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
82 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
83 EFI_SIO_PROTOCOL
*Sio
;
87 // Try to open EFI DEVICE PATH protocol on the controller
89 Status
= gBS
->OpenProtocol (
91 &gEfiDevicePathProtocolGuid
,
92 (VOID
**) &DevicePath
,
93 This
->DriverBindingHandle
,
95 EFI_OPEN_PROTOCOL_GET_PROTOCOL
98 if (!EFI_ERROR (Status
)) {
100 // Get the PciIo protocol from its parent controller.
102 Status
= gBS
->LocateDevicePath (&gEfiPciIoProtocolGuid
, &DevicePath
, &PciHandle
);
105 if (EFI_ERROR (Status
)) {
110 // Try to open the Super IO protocol on the controller
112 Status
= gBS
->OpenProtocol (
114 &gEfiSioProtocolGuid
,
116 This
->DriverBindingHandle
,
118 EFI_OPEN_PROTOCOL_BY_DRIVER
120 if (!EFI_ERROR (Status
)) {
123 &gEfiSioProtocolGuid
,
124 This
->DriverBindingHandle
,
133 Start this driver on ControllerHandle.
135 The Start() function is designed to be invoked from the EFI boot service ConnectController().
136 As a result, much of the error checking on the parameters to Start() has been moved into this
137 common boot service. It is legal to call Start() from other locations, but the following calling
138 restrictions must be followed or the system behavior will not be deterministic.
139 1. ControllerHandle must be a valid EFI_HANDLE.
140 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
141 EFI_DEVICE_PATH_PROTOCOL.
142 3. Prior to calling Start(), the Supported() function for the driver specified by This must
143 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
145 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
146 @param[in] ControllerHandle The handle of the controller to start. This handle
147 must support a protocol interface that supplies
148 an I/O abstraction to the driver.
149 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.
150 This parameter is ignored by device drivers, and is optional for bus drivers.
152 @retval EFI_SUCCESS The device was started.
153 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.
154 Currently not implemented.
155 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
156 @retval Others The driver failded to start the device.
161 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
162 IN EFI_HANDLE Controller
,
163 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
167 EFI_PCI_IO_PROTOCOL
*PciIo
;
168 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
169 EFI_HANDLE PciHandle
;
170 EFI_SIO_PROTOCOL
*Sio
;
171 ACPI_RESOURCE_HEADER_PTR Resources
;
172 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
173 ISA_IO_DEVICE
*IsaIoDevice
;
179 // Open Device Path Protocol
181 Status
= gBS
->OpenProtocol (
183 &gEfiDevicePathProtocolGuid
,
184 (VOID
**) &DevicePath
,
185 This
->DriverBindingHandle
,
187 EFI_OPEN_PROTOCOL_GET_PROTOCOL
189 if (EFI_ERROR (Status
)) {
194 // Get the PciIo protocol from its parent controller.
196 TempDevicePath
= DevicePath
;
197 Status
= gBS
->LocateDevicePath (&gEfiPciIoProtocolGuid
, &TempDevicePath
, &PciHandle
);
198 if (!EFI_ERROR (Status
)) {
199 Status
= gBS
->HandleProtocol (PciHandle
, &gEfiPciIoProtocolGuid
, (VOID
**) &PciIo
);
200 ASSERT_EFI_ERROR (Status
);
203 // Open Super IO Protocol
205 Status
= gBS
->OpenProtocol (
207 &gEfiSioProtocolGuid
,
209 This
->DriverBindingHandle
,
211 EFI_OPEN_PROTOCOL_BY_DRIVER
215 if (EFI_ERROR (Status
)) {
217 // Fail due to LocateDevicePath(...) or OpenProtocol(Sio, BY_DRIVER)
222 Status
= Sio
->GetResources (Sio
, &Resources
);
223 ASSERT_EFI_ERROR (Status
);
225 IsaIoDevice
= AllocatePool (sizeof (ISA_IO_DEVICE
));
226 ASSERT (IsaIoDevice
!= NULL
);
228 IsaIoDevice
->Signature
= ISA_IO_DEVICE_SIGNATURE
;
229 IsaIoDevice
->PciIo
= PciIo
;
232 // Initialize the ISA I/O instance structure
234 InitializeIsaIoInstance (IsaIoDevice
, DevicePath
, Resources
);
237 // Install the ISA I/O protocol on the Controller handle
239 Status
= gBS
->InstallMultipleProtocolInterfaces (
241 &gEfiIsaIoProtocolGuid
,
245 ASSERT_EFI_ERROR (Status
);
251 Stop this driver on ControllerHandle.
253 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
254 As a result, much of the error checking on the parameters to Stop() has been moved
255 into this common boot service. It is legal to call Stop() from other locations,
256 but the following calling restrictions must be followed or the system behavior will not be deterministic.
257 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
258 same driver's Start() function.
259 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
260 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
261 Start() function, and the Start() function must have called OpenProtocol() on
262 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
264 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
265 @param[in] ControllerHandle A handle to the device being stopped. The handle must
266 support a bus specific I/O protocol for the driver
267 to use to stop the device.
268 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
269 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
270 if NumberOfChildren is 0.
272 @retval EFI_SUCCESS The device was stopped.
273 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
278 IN EFI_DRIVER_BINDING_PROTOCOL
* This
,
279 IN EFI_HANDLE Controller
,
280 IN UINTN NumberOfChildren
,
281 IN EFI_HANDLE
* ChildHandleBuffer OPTIONAL
285 ISA_IO_DEVICE
*IsaIoDevice
;
286 EFI_ISA_IO_PROTOCOL
*IsaIo
;
288 Status
= gBS
->OpenProtocol (
290 &gEfiIsaIoProtocolGuid
,
292 This
->DriverBindingHandle
,
294 EFI_OPEN_PROTOCOL_GET_PROTOCOL
296 if (EFI_ERROR (Status
)) {
297 return EFI_UNSUPPORTED
;
300 IsaIoDevice
= ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo
);
302 Status
= gBS
->UninstallMultipleProtocolInterfaces (
304 &gEfiIsaIoProtocolGuid
,
308 if (!EFI_ERROR (Status
)) {
309 Status
= gBS
->CloseProtocol (
311 &gEfiSioProtocolGuid
,
312 This
->DriverBindingHandle
,
315 FreePool (IsaIoDevice
->IsaIo
.ResourceList
);
316 FreePool (IsaIoDevice
);