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