]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/IsaIoDxe/IsaDriver.c
Check in the IsaIoDxe device driver that consumes EFI_SIO_PROTOCOL to produce EFI_ISA...
[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
5 \r
6Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
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
34 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
35 @param[in] SystemTable A pointer to the EFI System Table.\r
36 \r
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
65/** \r
66 Tests to see if a controller can be managed by the IsaIo driver.\r
67\r
68 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. \r
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
71 \r
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
74 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver \r
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
109 if (!EFI_ERROR (Status)) {\r
110 if ((DevicePathType (DevicePath) != ACPI_DEVICE_PATH) ||\r
111 ((DevicePathSubType (DevicePath) != ACPI_DP) && (DevicePathSubType (DevicePath) != ACPI_EXTENDED_DP))) {\r
112 Status = EFI_UNSUPPORTED;\r
113 }\r
114 }\r
115 }\r
116\r
117 if (EFI_ERROR (Status)) {\r
118 return Status;\r
119 }\r
120\r
121 //\r
122 // Try to open the Super IO protocol on the controller\r
123 //\r
124 Status = gBS->OpenProtocol (\r
125 Controller,\r
126 &gEfiSioProtocolGuid,\r
127 (VOID **) &Sio,\r
128 This->DriverBindingHandle,\r
129 Controller,\r
130 EFI_OPEN_PROTOCOL_BY_DRIVER\r
131 );\r
132 if (!EFI_ERROR (Status)) {\r
133 gBS->CloseProtocol (\r
134 Controller,\r
135 &gEfiSioProtocolGuid,\r
136 This->DriverBindingHandle,\r
137 Controller\r
138 );\r
139 }\r
140\r
141 return Status;\r
142}\r
143\r
144/**\r
145 Start this driver on ControllerHandle. \r
146 \r
147 The Start() function is designed to be invoked from the EFI boot service ConnectController(). \r
148 As a result, much of the error checking on the parameters to Start() has been moved into this \r
149 common boot service. It is legal to call Start() from other locations, but the following calling \r
150 restrictions must be followed or the system behavior will not be deterministic.\r
151 1. ControllerHandle must be a valid EFI_HANDLE.\r
152 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
153 EFI_DEVICE_PATH_PROTOCOL.\r
154 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
155 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r
156\r
157 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
158 @param[in] ControllerHandle The handle of the controller to start. This handle \r
159 must support a protocol interface that supplies \r
160 an I/O abstraction to the driver.\r
161 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. \r
162 This parameter is ignored by device drivers, and is optional for bus drivers.\r
163\r
164 @retval EFI_SUCCESS The device was started.\r
165 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r
166 Currently not implemented.\r
167 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
168 @retval Others The driver failded to start the device.\r
169**/\r
170EFI_STATUS\r
171EFIAPI\r
172IsaIoDriverStart (\r
173 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
174 IN EFI_HANDLE Controller,\r
175 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
176 )\r
177{\r
178 EFI_STATUS Status;\r
179 EFI_PCI_IO_PROTOCOL *PciIo;\r
180 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
181 EFI_HANDLE PciHandle;\r
182 EFI_SIO_PROTOCOL *Sio;\r
183 ACPI_RESOURCE_HEADER_PTR Resources;\r
184 EFI_DEVICE_PATH_PROTOCOL *AcpiNode;\r
185 ISA_IO_DEVICE *IsaIoDevice;\r
186\r
187 PciIo = NULL;\r
188 Sio = NULL;\r
189\r
190 //\r
191 // Open Device Path Protocol\r
192 //\r
193 Status = gBS->OpenProtocol (\r
194 Controller,\r
195 &gEfiDevicePathProtocolGuid,\r
196 (VOID **) &DevicePath,\r
197 This->DriverBindingHandle,\r
198 Controller,\r
199 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
200 );\r
201 if (EFI_ERROR (Status)) {\r
202 return Status;\r
203 }\r
204\r
205 //\r
206 // Get the PciIo protocol from its parent controller.\r
207 //\r
208 AcpiNode = DevicePath;\r
209 Status = gBS->LocateDevicePath (&gEfiPciIoProtocolGuid, &AcpiNode, &PciHandle);\r
210 if (!EFI_ERROR (Status)) {\r
211 //\r
212 // AcpiNode should point to the ACPI node now.\r
213 //\r
214 ASSERT ((DevicePathType (AcpiNode) == ACPI_DEVICE_PATH) &&\r
215 ((DevicePathSubType (AcpiNode) == ACPI_DP) || (DevicePathSubType (AcpiNode) == ACPI_EXTENDED_DP))\r
216 );\r
217\r
218 Status = gBS->HandleProtocol (PciHandle, &gEfiPciIoProtocolGuid, &PciIo);\r
219 ASSERT_EFI_ERROR (Status);\r
220\r
221 //\r
222 // Open Super IO Protocol\r
223 //\r
224 Status = gBS->OpenProtocol (\r
225 Controller,\r
226 &gEfiSioProtocolGuid,\r
227 (VOID **) &Sio,\r
228 This->DriverBindingHandle,\r
229 Controller,\r
230 EFI_OPEN_PROTOCOL_BY_DRIVER\r
231 );\r
232 }\r
233\r
234 if (EFI_ERROR (Status)) {\r
235 //\r
236 // Fail due to LocateDevicePath(...) or OpenProtocol(Sio, BY_DRIVER)\r
237 //\r
238 return Status;\r
239 }\r
240\r
241 Status = Sio->GetResources (Sio, &Resources);\r
242 ASSERT_EFI_ERROR (Status);\r
243\r
244 IsaIoDevice = AllocatePool (sizeof (ISA_IO_DEVICE));\r
245 ASSERT (IsaIoDevice != NULL);\r
246\r
247 IsaIoDevice->Signature = ISA_IO_DEVICE_SIGNATURE;\r
248 IsaIoDevice->PciIo = PciIo;\r
249\r
250 //\r
251 // Initialize the ISA I/O instance structure\r
252 //\r
253 InitializeIsaIoInstance (IsaIoDevice, DevicePath, Resources);\r
254\r
255 //\r
256 // Install the ISA I/O protocol on the Controller handle\r
257 //\r
258 Status = gBS->InstallMultipleProtocolInterfaces (\r
259 &Controller,\r
260 &gEfiIsaIoProtocolGuid,\r
261 &IsaIoDevice->IsaIo,\r
262 NULL\r
263 );\r
264 ASSERT_EFI_ERROR (Status);\r
265\r
266 return EFI_SUCCESS;\r
267}\r
268\r
269/**\r
270 Stop this driver on ControllerHandle. \r
271 \r
272 The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
273 As a result, much of the error checking on the parameters to Stop() has been moved \r
274 into this common boot service. It is legal to call Stop() from other locations, \r
275 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
276 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
277 same driver's Start() function.\r
278 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
279 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
280 Start() function, and the Start() function must have called OpenProtocol() on\r
281 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
282 \r
283 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
284 @param[in] ControllerHandle A handle to the device being stopped. The handle must \r
285 support a bus specific I/O protocol for the driver \r
286 to use to stop the device.\r
287 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
288 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r
289 if NumberOfChildren is 0.\r
290\r
291 @retval EFI_SUCCESS The device was stopped.\r
292 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
293**/\r
294EFI_STATUS\r
295EFIAPI\r
296IsaIoDriverStop (\r
297 IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
298 IN EFI_HANDLE Controller,\r
299 IN UINTN NumberOfChildren,\r
300 IN EFI_HANDLE * ChildHandleBuffer OPTIONAL\r
301 )\r
302{\r
303 EFI_STATUS Status;\r
304 ISA_IO_DEVICE *IsaIoDevice;\r
305 EFI_ISA_IO_PROTOCOL *IsaIo;\r
306\r
307 Status = gBS->OpenProtocol (\r
308 Controller,\r
309 &gEfiIsaIoProtocolGuid,\r
310 (VOID **) &IsaIo,\r
311 This->DriverBindingHandle,\r
312 Controller,\r
313 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
314 );\r
315 if (EFI_ERROR (Status)) {\r
316 return EFI_UNSUPPORTED;\r
317 }\r
318\r
319 IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo);\r
320\r
321 Status = gBS->UninstallMultipleProtocolInterfaces (\r
322 Controller,\r
323 &gEfiIsaIoProtocolGuid,\r
324 &IsaIoDevice->IsaIo,\r
325 NULL\r
326 );\r
327 if (!EFI_ERROR (Status)) {\r
328 Status = gBS->CloseProtocol (\r
329 Controller,\r
330 &gEfiSioProtocolGuid,\r
331 This->DriverBindingHandle,\r
332 Controller\r
333 );\r
334 FreePool (IsaIoDevice->IsaIo.ResourceList);\r
335 FreePool (IsaIoDevice);\r
336 }\r
337\r
338 return Status;\r
339}