]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/IsaIoDxe/IsaDriver.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaIoDxe / IsaDriver.c
CommitLineData
558be455
RN
1/** @file\r
2 IsaIo UEFI driver.\r
3\r
4 Produce an instance of the ISA I/O Protocol for every SIO controller.\r
0a6f4824
LG
5\r
6Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
558be455
RN
7This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include "IsaDriver.h"\r
18\r
19//\r
20// IsaIo Driver Global Variables\r
21//\r
22EFI_DRIVER_BINDING_PROTOCOL gIsaIoDriver = {\r
23 IsaIoDriverSupported,\r
24 IsaIoDriverStart,\r
25 IsaIoDriverStop,\r
26 0xa,\r
27 NULL,\r
28 NULL\r
29};\r
30\r
31/**\r
32 The main entry point for the IsaIo driver.\r
33\r
0a6f4824 34 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
558be455 35 @param[in] SystemTable A pointer to the EFI System Table.\r
0a6f4824 36\r
558be455
RN
37 @retval EFI_SUCCESS The entry point is executed successfully.\r
38 @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to install all the protocols.\r
39**/\r
40EFI_STATUS\r
41EFIAPI\r
42InitializeIsaIo (\r
43 IN EFI_HANDLE ImageHandle,\r
44 IN EFI_SYSTEM_TABLE *SystemTable\r
45 )\r
46{\r
47 EFI_STATUS Status;\r
48\r
49 //\r
50 // Install driver model protocol(s).\r
51 //\r
52 Status = EfiLibInstallDriverBindingComponentName2 (\r
53 ImageHandle,\r
54 SystemTable,\r
55 &gIsaIoDriver,\r
56 ImageHandle,\r
57 &gIsaIoComponentName,\r
58 &gIsaIoComponentName2\r
59 );\r
60 ASSERT_EFI_ERROR (Status);\r
61\r
62 return Status;\r
63}\r
64\r
0a6f4824 65/**\r
558be455
RN
66 Tests to see if a controller can be managed by the IsaIo driver.\r
67\r
0a6f4824 68 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
558be455
RN
69 @param[in] Controller The handle of the controller to test.\r
70 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r
0a6f4824 71\r
558be455
RN
72 @retval EFI_SUCCESS The device is supported by this driver.\r
73 @retval EFI_ALREADY_STARTED The device is already being managed by this driver.\r
0a6f4824 74 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver\r
558be455
RN
75 or an application that requires exclusive access.\r
76 @retval EFI_UNSUPPORTED The device is is not supported by this driver.\r
77\r
78**/\r
79EFI_STATUS\r
80EFIAPI\r
81IsaIoDriverSupported (\r
82 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
83 IN EFI_HANDLE Controller,\r
84 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
85 )\r
86{\r
87 EFI_STATUS Status;\r
88 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
89 EFI_SIO_PROTOCOL *Sio;\r
90 EFI_HANDLE PciHandle;\r
91\r
92 //\r
93 // Try to open EFI DEVICE PATH protocol on the controller\r
94 //\r
95 Status = gBS->OpenProtocol (\r
96 Controller,\r
97 &gEfiDevicePathProtocolGuid,\r
98 (VOID **) &DevicePath,\r
99 This->DriverBindingHandle,\r
100 Controller,\r
101 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
102 );\r
103\r
104 if (!EFI_ERROR (Status)) {\r
105 //\r
106 // Get the PciIo protocol from its parent controller.\r
107 //\r
108 Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &DevicePath, &PciHandle);\r
558be455
RN
109 }\r
110\r
111 if (EFI_ERROR (Status)) {\r
112 return Status;\r
113 }\r
114\r
115 //\r
116 // Try to open the Super IO protocol on the controller\r
117 //\r
118 Status = gBS->OpenProtocol (\r
119 Controller,\r
120 &gEfiSioProtocolGuid,\r
121 (VOID **) &Sio,\r
122 This->DriverBindingHandle,\r
123 Controller,\r
124 EFI_OPEN_PROTOCOL_BY_DRIVER\r
125 );\r
126 if (!EFI_ERROR (Status)) {\r
127 gBS->CloseProtocol (\r
128 Controller,\r
129 &gEfiSioProtocolGuid,\r
130 This->DriverBindingHandle,\r
131 Controller\r
132 );\r
133 }\r
134\r
135 return Status;\r
136}\r
137\r
138/**\r
0a6f4824
LG
139 Start this driver on ControllerHandle.\r
140\r
141 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
142 As a result, much of the error checking on the parameters to Start() has been moved into this\r
143 common boot service. It is legal to call Start() from other locations, but the following calling\r
558be455
RN
144 restrictions must be followed or the system behavior will not be deterministic.\r
145 1. ControllerHandle must be a valid EFI_HANDLE.\r
146 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
147 EFI_DEVICE_PATH_PROTOCOL.\r
148 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
0a6f4824 149 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
558be455
RN
150\r
151 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
0a6f4824
LG
152 @param[in] ControllerHandle The handle of the controller to start. This handle\r
153 must support a protocol interface that supplies\r
558be455 154 an I/O abstraction to the driver.\r
0a6f4824 155 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r
558be455
RN
156 This parameter is ignored by device drivers, and is optional for bus drivers.\r
157\r
158 @retval EFI_SUCCESS The device was started.\r
159 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r
160 Currently not implemented.\r
161 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
162 @retval Others The driver failded to start the device.\r
163**/\r
164EFI_STATUS\r
165EFIAPI\r
166IsaIoDriverStart (\r
167 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
168 IN EFI_HANDLE Controller,\r
169 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
170 )\r
171{\r
172 EFI_STATUS Status;\r
173 EFI_PCI_IO_PROTOCOL *PciIo;\r
174 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
175 EFI_HANDLE PciHandle;\r
176 EFI_SIO_PROTOCOL *Sio;\r
177 ACPI_RESOURCE_HEADER_PTR Resources;\r
12b7f509 178 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
558be455
RN
179 ISA_IO_DEVICE *IsaIoDevice;\r
180\r
181 PciIo = NULL;\r
182 Sio = NULL;\r
183\r
184 //\r
185 // Open Device Path Protocol\r
186 //\r
187 Status = gBS->OpenProtocol (\r
188 Controller,\r
189 &gEfiDevicePathProtocolGuid,\r
190 (VOID **) &DevicePath,\r
191 This->DriverBindingHandle,\r
192 Controller,\r
193 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
194 );\r
195 if (EFI_ERROR (Status)) {\r
196 return Status;\r
197 }\r
198\r
199 //\r
200 // Get the PciIo protocol from its parent controller.\r
201 //\r
12b7f509
RN
202 TempDevicePath = DevicePath;\r
203 Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &TempDevicePath, &PciHandle);\r
558be455 204 if (!EFI_ERROR (Status)) {\r
f6aa9c1b 205 Status = gBS->HandleProtocol (PciHandle, &gEfiPciIoProtocolGuid, (VOID **) &PciIo);\r
558be455
RN
206 ASSERT_EFI_ERROR (Status);\r
207\r
208 //\r
209 // Open Super IO Protocol\r
210 //\r
211 Status = gBS->OpenProtocol (\r
212 Controller,\r
213 &gEfiSioProtocolGuid,\r
214 (VOID **) &Sio,\r
215 This->DriverBindingHandle,\r
216 Controller,\r
217 EFI_OPEN_PROTOCOL_BY_DRIVER\r
218 );\r
219 }\r
220\r
221 if (EFI_ERROR (Status)) {\r
222 //\r
223 // Fail due to LocateDevicePath(...) or OpenProtocol(Sio, BY_DRIVER)\r
224 //\r
225 return Status;\r
226 }\r
227\r
228 Status = Sio->GetResources (Sio, &Resources);\r
229 ASSERT_EFI_ERROR (Status);\r
230\r
231 IsaIoDevice = AllocatePool (sizeof (ISA_IO_DEVICE));\r
232 ASSERT (IsaIoDevice != NULL);\r
233\r
234 IsaIoDevice->Signature = ISA_IO_DEVICE_SIGNATURE;\r
235 IsaIoDevice->PciIo = PciIo;\r
236\r
237 //\r
238 // Initialize the ISA I/O instance structure\r
239 //\r
240 InitializeIsaIoInstance (IsaIoDevice, DevicePath, Resources);\r
241\r
242 //\r
243 // Install the ISA I/O protocol on the Controller handle\r
244 //\r
245 Status = gBS->InstallMultipleProtocolInterfaces (\r
246 &Controller,\r
247 &gEfiIsaIoProtocolGuid,\r
248 &IsaIoDevice->IsaIo,\r
249 NULL\r
250 );\r
251 ASSERT_EFI_ERROR (Status);\r
252\r
253 return EFI_SUCCESS;\r
254}\r
255\r
256/**\r
0a6f4824
LG
257 Stop this driver on ControllerHandle.\r
258\r
259 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
260 As a result, much of the error checking on the parameters to Stop() has been moved\r
261 into this common boot service. It is legal to call Stop() from other locations,\r
558be455
RN
262 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
263 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
264 same driver's Start() function.\r
265 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
266 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
267 Start() function, and the Start() function must have called OpenProtocol() on\r
268 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
0a6f4824 269\r
558be455 270 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
0a6f4824
LG
271 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
272 support a bus specific I/O protocol for the driver\r
558be455
RN
273 to use to stop the device.\r
274 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
0a6f4824 275 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
558be455
RN
276 if NumberOfChildren is 0.\r
277\r
278 @retval EFI_SUCCESS The device was stopped.\r
279 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
280**/\r
281EFI_STATUS\r
282EFIAPI\r
283IsaIoDriverStop (\r
284 IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
285 IN EFI_HANDLE Controller,\r
286 IN UINTN NumberOfChildren,\r
287 IN EFI_HANDLE * ChildHandleBuffer OPTIONAL\r
288 )\r
289{\r
290 EFI_STATUS Status;\r
291 ISA_IO_DEVICE *IsaIoDevice;\r
292 EFI_ISA_IO_PROTOCOL *IsaIo;\r
293\r
294 Status = gBS->OpenProtocol (\r
295 Controller,\r
296 &gEfiIsaIoProtocolGuid,\r
297 (VOID **) &IsaIo,\r
298 This->DriverBindingHandle,\r
299 Controller,\r
300 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
301 );\r
302 if (EFI_ERROR (Status)) {\r
303 return EFI_UNSUPPORTED;\r
304 }\r
305\r
306 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo);\r
307\r
308 Status = gBS->UninstallMultipleProtocolInterfaces (\r
309 Controller,\r
310 &gEfiIsaIoProtocolGuid,\r
311 &IsaIoDevice->IsaIo,\r
312 NULL\r
313 );\r
314 if (!EFI_ERROR (Status)) {\r
315 Status = gBS->CloseProtocol (\r
316 Controller,\r
317 &gEfiSioProtocolGuid,\r
318 This->DriverBindingHandle,\r
319 Controller\r
320 );\r
321 FreePool (IsaIoDevice->IsaIo.ResourceList);\r
322 FreePool (IsaIoDevice);\r
323 }\r
324\r
325 return Status;\r
f6aa9c1b 326}\r