]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/IsaIoDxe/IsaDriver.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaIoDxe / IsaDriver.c
1 /** @file
2 IsaIo UEFI driver.
3
4 Produce an instance of the ISA I/O Protocol for every SIO controller.
5
6 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include "IsaDriver.h"
12
13 //
14 // IsaIo Driver Global Variables
15 //
16 EFI_DRIVER_BINDING_PROTOCOL gIsaIoDriver = {
17 IsaIoDriverSupported,
18 IsaIoDriverStart,
19 IsaIoDriverStop,
20 0xa,
21 NULL,
22 NULL
23 };
24
25 /**
26 The main entry point for the IsaIo driver.
27
28 @param[in] ImageHandle The firmware allocated handle for the EFI image.
29 @param[in] SystemTable A pointer to the EFI System Table.
30
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.
33 **/
34 EFI_STATUS
35 EFIAPI
36 InitializeIsaIo (
37 IN EFI_HANDLE ImageHandle,
38 IN EFI_SYSTEM_TABLE *SystemTable
39 )
40 {
41 EFI_STATUS Status;
42
43 //
44 // Install driver model protocol(s).
45 //
46 Status = EfiLibInstallDriverBindingComponentName2 (
47 ImageHandle,
48 SystemTable,
49 &gIsaIoDriver,
50 ImageHandle,
51 &gIsaIoComponentName,
52 &gIsaIoComponentName2
53 );
54 ASSERT_EFI_ERROR (Status);
55
56 return Status;
57 }
58
59 /**
60 Tests to see if a controller can be managed by the IsaIo driver.
61
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.
65
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.
71
72 **/
73 EFI_STATUS
74 EFIAPI
75 IsaIoDriverSupported (
76 IN EFI_DRIVER_BINDING_PROTOCOL *This,
77 IN EFI_HANDLE Controller,
78 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
79 )
80 {
81 EFI_STATUS Status;
82 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
83 EFI_SIO_PROTOCOL *Sio;
84 EFI_HANDLE PciHandle;
85
86 //
87 // Try to open EFI DEVICE PATH protocol on the controller
88 //
89 Status = gBS->OpenProtocol (
90 Controller,
91 &gEfiDevicePathProtocolGuid,
92 (VOID **) &DevicePath,
93 This->DriverBindingHandle,
94 Controller,
95 EFI_OPEN_PROTOCOL_GET_PROTOCOL
96 );
97
98 if (!EFI_ERROR (Status)) {
99 //
100 // Get the PciIo protocol from its parent controller.
101 //
102 Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &DevicePath, &PciHandle);
103 }
104
105 if (EFI_ERROR (Status)) {
106 return Status;
107 }
108
109 //
110 // Try to open the Super IO protocol on the controller
111 //
112 Status = gBS->OpenProtocol (
113 Controller,
114 &gEfiSioProtocolGuid,
115 (VOID **) &Sio,
116 This->DriverBindingHandle,
117 Controller,
118 EFI_OPEN_PROTOCOL_BY_DRIVER
119 );
120 if (!EFI_ERROR (Status)) {
121 gBS->CloseProtocol (
122 Controller,
123 &gEfiSioProtocolGuid,
124 This->DriverBindingHandle,
125 Controller
126 );
127 }
128
129 return Status;
130 }
131
132 /**
133 Start this driver on ControllerHandle.
134
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.
144
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.
151
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.
157 **/
158 EFI_STATUS
159 EFIAPI
160 IsaIoDriverStart (
161 IN EFI_DRIVER_BINDING_PROTOCOL *This,
162 IN EFI_HANDLE Controller,
163 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
164 )
165 {
166 EFI_STATUS Status;
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;
174
175 PciIo = NULL;
176 Sio = NULL;
177
178 //
179 // Open Device Path Protocol
180 //
181 Status = gBS->OpenProtocol (
182 Controller,
183 &gEfiDevicePathProtocolGuid,
184 (VOID **) &DevicePath,
185 This->DriverBindingHandle,
186 Controller,
187 EFI_OPEN_PROTOCOL_GET_PROTOCOL
188 );
189 if (EFI_ERROR (Status)) {
190 return Status;
191 }
192
193 //
194 // Get the PciIo protocol from its parent controller.
195 //
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);
201
202 //
203 // Open Super IO Protocol
204 //
205 Status = gBS->OpenProtocol (
206 Controller,
207 &gEfiSioProtocolGuid,
208 (VOID **) &Sio,
209 This->DriverBindingHandle,
210 Controller,
211 EFI_OPEN_PROTOCOL_BY_DRIVER
212 );
213 }
214
215 if (EFI_ERROR (Status)) {
216 //
217 // Fail due to LocateDevicePath(...) or OpenProtocol(Sio, BY_DRIVER)
218 //
219 return Status;
220 }
221
222 Status = Sio->GetResources (Sio, &Resources);
223 ASSERT_EFI_ERROR (Status);
224
225 IsaIoDevice = AllocatePool (sizeof (ISA_IO_DEVICE));
226 ASSERT (IsaIoDevice != NULL);
227
228 IsaIoDevice->Signature = ISA_IO_DEVICE_SIGNATURE;
229 IsaIoDevice->PciIo = PciIo;
230
231 //
232 // Initialize the ISA I/O instance structure
233 //
234 InitializeIsaIoInstance (IsaIoDevice, DevicePath, Resources);
235
236 //
237 // Install the ISA I/O protocol on the Controller handle
238 //
239 Status = gBS->InstallMultipleProtocolInterfaces (
240 &Controller,
241 &gEfiIsaIoProtocolGuid,
242 &IsaIoDevice->IsaIo,
243 NULL
244 );
245 ASSERT_EFI_ERROR (Status);
246
247 return EFI_SUCCESS;
248 }
249
250 /**
251 Stop this driver on ControllerHandle.
252
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.
263
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.
271
272 @retval EFI_SUCCESS The device was stopped.
273 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
274 **/
275 EFI_STATUS
276 EFIAPI
277 IsaIoDriverStop (
278 IN EFI_DRIVER_BINDING_PROTOCOL * This,
279 IN EFI_HANDLE Controller,
280 IN UINTN NumberOfChildren,
281 IN EFI_HANDLE * ChildHandleBuffer OPTIONAL
282 )
283 {
284 EFI_STATUS Status;
285 ISA_IO_DEVICE *IsaIoDevice;
286 EFI_ISA_IO_PROTOCOL *IsaIo;
287
288 Status = gBS->OpenProtocol (
289 Controller,
290 &gEfiIsaIoProtocolGuid,
291 (VOID **) &IsaIo,
292 This->DriverBindingHandle,
293 Controller,
294 EFI_OPEN_PROTOCOL_GET_PROTOCOL
295 );
296 if (EFI_ERROR (Status)) {
297 return EFI_UNSUPPORTED;
298 }
299
300 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo);
301
302 Status = gBS->UninstallMultipleProtocolInterfaces (
303 Controller,
304 &gEfiIsaIoProtocolGuid,
305 &IsaIoDevice->IsaIo,
306 NULL
307 );
308 if (!EFI_ERROR (Status)) {
309 Status = gBS->CloseProtocol (
310 Controller,
311 &gEfiSioProtocolGuid,
312 This->DriverBindingHandle,
313 Controller
314 );
315 FreePool (IsaIoDevice->IsaIo.ResourceList);
316 FreePool (IsaIoDevice);
317 }
318
319 return Status;
320 }