]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Bus/Isa/IsaIoDxe/IsaDriver.c
Fix GCC build failure
[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, 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
11
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.
14
15 **/
16
17 #include "IsaDriver.h"
18
19 //
20 // IsaIo Driver Global Variables
21 //
22 EFI_DRIVER_BINDING_PROTOCOL gIsaIoDriver = {
23 IsaIoDriverSupported,
24 IsaIoDriverStart,
25 IsaIoDriverStop,
26 0xa,
27 NULL,
28 NULL
29 };
30
31 /**
32 The main entry point for the IsaIo driver.
33
34 @param[in] ImageHandle The firmware allocated handle for the EFI image.
35 @param[in] SystemTable A pointer to the EFI System Table.
36
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.
39 **/
40 EFI_STATUS
41 EFIAPI
42 InitializeIsaIo (
43 IN EFI_HANDLE ImageHandle,
44 IN EFI_SYSTEM_TABLE *SystemTable
45 )
46 {
47 EFI_STATUS Status;
48
49 //
50 // Install driver model protocol(s).
51 //
52 Status = EfiLibInstallDriverBindingComponentName2 (
53 ImageHandle,
54 SystemTable,
55 &gIsaIoDriver,
56 ImageHandle,
57 &gIsaIoComponentName,
58 &gIsaIoComponentName2
59 );
60 ASSERT_EFI_ERROR (Status);
61
62 return Status;
63 }
64
65 /**
66 Tests to see if a controller can be managed by the IsaIo driver.
67
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.
71
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.
77
78 **/
79 EFI_STATUS
80 EFIAPI
81 IsaIoDriverSupported (
82 IN EFI_DRIVER_BINDING_PROTOCOL *This,
83 IN EFI_HANDLE Controller,
84 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
85 )
86 {
87 EFI_STATUS Status;
88 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
89 EFI_SIO_PROTOCOL *Sio;
90 EFI_HANDLE PciHandle;
91
92 //
93 // Try to open EFI DEVICE PATH protocol on the controller
94 //
95 Status = gBS->OpenProtocol (
96 Controller,
97 &gEfiDevicePathProtocolGuid,
98 (VOID **) &DevicePath,
99 This->DriverBindingHandle,
100 Controller,
101 EFI_OPEN_PROTOCOL_GET_PROTOCOL
102 );
103
104 if (!EFI_ERROR (Status)) {
105 //
106 // Get the PciIo protocol from its parent controller.
107 //
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;
113 }
114 }
115 }
116
117 if (EFI_ERROR (Status)) {
118 return Status;
119 }
120
121 //
122 // Try to open the Super IO protocol on the controller
123 //
124 Status = gBS->OpenProtocol (
125 Controller,
126 &gEfiSioProtocolGuid,
127 (VOID **) &Sio,
128 This->DriverBindingHandle,
129 Controller,
130 EFI_OPEN_PROTOCOL_BY_DRIVER
131 );
132 if (!EFI_ERROR (Status)) {
133 gBS->CloseProtocol (
134 Controller,
135 &gEfiSioProtocolGuid,
136 This->DriverBindingHandle,
137 Controller
138 );
139 }
140
141 return Status;
142 }
143
144 /**
145 Start this driver on ControllerHandle.
146
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.
156
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.
163
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.
169 **/
170 EFI_STATUS
171 EFIAPI
172 IsaIoDriverStart (
173 IN EFI_DRIVER_BINDING_PROTOCOL *This,
174 IN EFI_HANDLE Controller,
175 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
176 )
177 {
178 EFI_STATUS Status;
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;
186
187 PciIo = NULL;
188 Sio = NULL;
189
190 //
191 // Open Device Path Protocol
192 //
193 Status = gBS->OpenProtocol (
194 Controller,
195 &gEfiDevicePathProtocolGuid,
196 (VOID **) &DevicePath,
197 This->DriverBindingHandle,
198 Controller,
199 EFI_OPEN_PROTOCOL_GET_PROTOCOL
200 );
201 if (EFI_ERROR (Status)) {
202 return Status;
203 }
204
205 //
206 // Get the PciIo protocol from its parent controller.
207 //
208 AcpiNode = DevicePath;
209 Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &AcpiNode, &PciHandle);
210 if (!EFI_ERROR (Status)) {
211 //
212 // AcpiNode should point to the ACPI node now.
213 //
214 ASSERT ((DevicePathType (AcpiNode) == ACPI_DEVICE_PATH) &&
215 ((DevicePathSubType (AcpiNode) == ACPI_DP) || (DevicePathSubType (AcpiNode) == ACPI_EXTENDED_DP))
216 );
217
218 Status = gBS->HandleProtocol (PciHandle, &gEfiPciIoProtocolGuid, (VOID **) &PciIo);
219 ASSERT_EFI_ERROR (Status);
220
221 //
222 // Open Super IO Protocol
223 //
224 Status = gBS->OpenProtocol (
225 Controller,
226 &gEfiSioProtocolGuid,
227 (VOID **) &Sio,
228 This->DriverBindingHandle,
229 Controller,
230 EFI_OPEN_PROTOCOL_BY_DRIVER
231 );
232 }
233
234 if (EFI_ERROR (Status)) {
235 //
236 // Fail due to LocateDevicePath(...) or OpenProtocol(Sio, BY_DRIVER)
237 //
238 return Status;
239 }
240
241 Status = Sio->GetResources (Sio, &Resources);
242 ASSERT_EFI_ERROR (Status);
243
244 IsaIoDevice = AllocatePool (sizeof (ISA_IO_DEVICE));
245 ASSERT (IsaIoDevice != NULL);
246
247 IsaIoDevice->Signature = ISA_IO_DEVICE_SIGNATURE;
248 IsaIoDevice->PciIo = PciIo;
249
250 //
251 // Initialize the ISA I/O instance structure
252 //
253 InitializeIsaIoInstance (IsaIoDevice, DevicePath, Resources);
254
255 //
256 // Install the ISA I/O protocol on the Controller handle
257 //
258 Status = gBS->InstallMultipleProtocolInterfaces (
259 &Controller,
260 &gEfiIsaIoProtocolGuid,
261 &IsaIoDevice->IsaIo,
262 NULL
263 );
264 ASSERT_EFI_ERROR (Status);
265
266 return EFI_SUCCESS;
267 }
268
269 /**
270 Stop this driver on ControllerHandle.
271
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.
282
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.
290
291 @retval EFI_SUCCESS The device was stopped.
292 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
293 **/
294 EFI_STATUS
295 EFIAPI
296 IsaIoDriverStop (
297 IN EFI_DRIVER_BINDING_PROTOCOL * This,
298 IN EFI_HANDLE Controller,
299 IN UINTN NumberOfChildren,
300 IN EFI_HANDLE * ChildHandleBuffer OPTIONAL
301 )
302 {
303 EFI_STATUS Status;
304 ISA_IO_DEVICE *IsaIoDevice;
305 EFI_ISA_IO_PROTOCOL *IsaIo;
306
307 Status = gBS->OpenProtocol (
308 Controller,
309 &gEfiIsaIoProtocolGuid,
310 (VOID **) &IsaIo,
311 This->DriverBindingHandle,
312 Controller,
313 EFI_OPEN_PROTOCOL_GET_PROTOCOL
314 );
315 if (EFI_ERROR (Status)) {
316 return EFI_UNSUPPORTED;
317 }
318
319 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo);
320
321 Status = gBS->UninstallMultipleProtocolInterfaces (
322 Controller,
323 &gEfiIsaIoProtocolGuid,
324 &IsaIoDevice->IsaIo,
325 NULL
326 );
327 if (!EFI_ERROR (Status)) {
328 Status = gBS->CloseProtocol (
329 Controller,
330 &gEfiSioProtocolGuid,
331 This->DriverBindingHandle,
332 Controller
333 );
334 FreePool (IsaIoDevice->IsaIo.ResourceList);
335 FreePool (IsaIoDevice);
336 }
337
338 return Status;
339 }