1 | /** @file
|
---|
2 | The SioBusDxe driver is used to create child devices on the ISA bus and
|
---|
3 | installs the Super I/O protocols on them.
|
---|
4 |
|
---|
5 | Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #include "SioBusDxe.h"
|
---|
12 |
|
---|
13 | //
|
---|
14 | // Super I/O Protocol interfaces
|
---|
15 | //
|
---|
16 | EFI_SIO_PROTOCOL mSioInterface = {
|
---|
17 | SioRegisterAccess,
|
---|
18 | SioGetResources,
|
---|
19 | SioSetResources,
|
---|
20 | SioPossibleResources,
|
---|
21 | SioModify
|
---|
22 | };
|
---|
23 |
|
---|
24 | //
|
---|
25 | // COM 1 UART Controller
|
---|
26 | //
|
---|
27 | GLOBAL_REMOVE_IF_UNREFERENCED
|
---|
28 | SIO_RESOURCES_IO mCom1Resources = {
|
---|
29 | {
|
---|
30 | { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR }, 0x3F8, 8
|
---|
31 | },
|
---|
32 | { ACPI_END_TAG_DESCRIPTOR, 0 }
|
---|
33 | };
|
---|
34 |
|
---|
35 | //
|
---|
36 | // COM 2 UART Controller
|
---|
37 | //
|
---|
38 | GLOBAL_REMOVE_IF_UNREFERENCED
|
---|
39 | SIO_RESOURCES_IO mCom2Resources = {
|
---|
40 | {
|
---|
41 | { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR }, 0x2F8, 8
|
---|
42 | },
|
---|
43 | { ACPI_END_TAG_DESCRIPTOR, 0 }
|
---|
44 | };
|
---|
45 |
|
---|
46 | //
|
---|
47 | // PS/2 Keyboard Controller
|
---|
48 | //
|
---|
49 | GLOBAL_REMOVE_IF_UNREFERENCED
|
---|
50 | SIO_RESOURCES_IO mPs2KeyboardDeviceResources = {
|
---|
51 | {
|
---|
52 | { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR }, 0x60, 5
|
---|
53 | },
|
---|
54 | { ACPI_END_TAG_DESCRIPTOR, 0 }
|
---|
55 | };
|
---|
56 |
|
---|
57 | //
|
---|
58 | // Table of SIO Controllers
|
---|
59 | //
|
---|
60 | GLOBAL_REMOVE_IF_UNREFERENCED
|
---|
61 | SIO_DEVICE_INFO mDevicesInfo[] = {
|
---|
62 | {
|
---|
63 | EISA_PNP_ID (0x501),
|
---|
64 | 0,
|
---|
65 | { (ACPI_SMALL_RESOURCE_HEADER *)&mCom1Resources }
|
---|
66 | }, // COM 1 UART Controller
|
---|
67 | {
|
---|
68 | EISA_PNP_ID (0x501),
|
---|
69 | 1,
|
---|
70 | { (ACPI_SMALL_RESOURCE_HEADER *)&mCom2Resources }
|
---|
71 | }, // COM 2 UART Controller
|
---|
72 | {
|
---|
73 | EISA_PNP_ID (0x303),
|
---|
74 | 0,
|
---|
75 | { (ACPI_SMALL_RESOURCE_HEADER *)&mPs2KeyboardDeviceResources }
|
---|
76 | } // PS/2 Keyboard Controller
|
---|
77 | };
|
---|
78 |
|
---|
79 | //
|
---|
80 | // ACPI Device Path Node template
|
---|
81 | //
|
---|
82 | GLOBAL_REMOVE_IF_UNREFERENCED
|
---|
83 | ACPI_HID_DEVICE_PATH mAcpiDeviceNodeTemplate = {
|
---|
84 | { // Header
|
---|
85 | ACPI_DEVICE_PATH,
|
---|
86 | ACPI_DP,
|
---|
87 | {
|
---|
88 | (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)),
|
---|
89 | (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
|
---|
90 | }
|
---|
91 | },
|
---|
92 | 0x0, // HID
|
---|
93 | 0x0 // UID
|
---|
94 | };
|
---|
95 |
|
---|
96 | /**
|
---|
97 | Provides a low level access to the registers for the Super I/O.
|
---|
98 |
|
---|
99 | @param[in] This Indicates a pointer to the calling context.
|
---|
100 | @param[in] Write Specifies the type of the register operation.
|
---|
101 | If this parameter is TRUE, Value is interpreted
|
---|
102 | as an input parameter and the operation is a
|
---|
103 | register write. If this parameter is FALSE,
|
---|
104 | Value is interpreted as an output parameter and
|
---|
105 | the operation is a register read.
|
---|
106 | @param[in] ExitCfgMode Exit Configuration Mode Indicator. If this
|
---|
107 | parameter is set to TRUE, the Super I/O driver
|
---|
108 | will turn off configuration mode of the Super
|
---|
109 | I/O prior to returning from this function. If
|
---|
110 | this parameter is set to FALSE, the Super I/O
|
---|
111 | driver will leave Super I/O in the
|
---|
112 | configuration mode. The Super I/O driver must
|
---|
113 | track the current state of the Super I/O and
|
---|
114 | enable the configuration mode of Super I/O if
|
---|
115 | necessary prior to register access.
|
---|
116 | @param[in] Register Register number.
|
---|
117 | @param[in,out] Value If Write is TRUE, Value is a pointer to the
|
---|
118 | buffer containing the byte of data to be
|
---|
119 | written to the Super I/O register. If Write is
|
---|
120 | FALSE, Value is a pointer to the destination
|
---|
121 | buffer for the byte of data to be read from the
|
---|
122 | Super I/O register.
|
---|
123 |
|
---|
124 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
125 | @retval EFI_INVALID_PARAMETER The Value is NULL.
|
---|
126 | @retval EFI_INVALID_PARAMETER Invalid Register number.
|
---|
127 |
|
---|
128 | **/
|
---|
129 | EFI_STATUS
|
---|
130 | EFIAPI
|
---|
131 | SioRegisterAccess (
|
---|
132 | IN CONST EFI_SIO_PROTOCOL *This,
|
---|
133 | IN BOOLEAN Write,
|
---|
134 | IN BOOLEAN ExitCfgMode,
|
---|
135 | IN UINT8 Register,
|
---|
136 | IN OUT UINT8 *Value
|
---|
137 | )
|
---|
138 | {
|
---|
139 | return EFI_SUCCESS;
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | Provides an interface to get a list of the current resources consumed by the
|
---|
144 | device in the ACPI Resource Descriptor format.
|
---|
145 |
|
---|
146 | GetResources() returns a list of resources currently consumed by the device.
|
---|
147 | The ResourceList is a pointer to the buffer containing resource descriptors
|
---|
148 | for the device. The descriptors are in the format of Small or Large ACPI
|
---|
149 | resource descriptor as defined by ACPI specification (2.0 & 3.0). The buffer
|
---|
150 | of resource descriptors is terminated with the 'End tag' resource descriptor.
|
---|
151 |
|
---|
152 | @param[in] This Indicates a pointer to the calling context.
|
---|
153 | @param[out] ResourceList A pointer to an ACPI resource descriptor list
|
---|
154 | that defines the current resources used by the
|
---|
155 | device.
|
---|
156 |
|
---|
157 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
158 | @retval EFI_INVALID_PARAMETER ResourceList is NULL.
|
---|
159 |
|
---|
160 | **/
|
---|
161 | EFI_STATUS
|
---|
162 | EFIAPI
|
---|
163 | SioGetResources (
|
---|
164 | IN CONST EFI_SIO_PROTOCOL *This,
|
---|
165 | OUT ACPI_RESOURCE_HEADER_PTR *ResourceList
|
---|
166 | )
|
---|
167 | {
|
---|
168 | SIO_DEV *SioDevice;
|
---|
169 |
|
---|
170 | if (ResourceList == NULL) {
|
---|
171 | return EFI_INVALID_PARAMETER;
|
---|
172 | }
|
---|
173 |
|
---|
174 | SioDevice = SIO_DEV_FROM_SIO (This);
|
---|
175 | if (SioDevice->DeviceIndex < ARRAY_SIZE (mDevicesInfo)) {
|
---|
176 | *ResourceList = mDevicesInfo[SioDevice->DeviceIndex].Resources;
|
---|
177 | }
|
---|
178 |
|
---|
179 | return EFI_SUCCESS;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /**
|
---|
183 | Sets the resources for the device.
|
---|
184 |
|
---|
185 | @param[in] This Indicates a pointer to the calling context.
|
---|
186 | @param[in] ResourceList Pointer to the ACPI resource descriptor list.
|
---|
187 |
|
---|
188 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
189 | @retval EFI_INVALID_PARAMETER ResourceList is invalid.
|
---|
190 | @retval EFI_ACCESS_DENIED Some of the resources in ResourceList are in
|
---|
191 | use.
|
---|
192 |
|
---|
193 | **/
|
---|
194 | EFI_STATUS
|
---|
195 | EFIAPI
|
---|
196 | SioSetResources (
|
---|
197 | IN CONST EFI_SIO_PROTOCOL *This,
|
---|
198 | IN ACPI_RESOURCE_HEADER_PTR ResourceList
|
---|
199 | )
|
---|
200 | {
|
---|
201 | return EFI_SUCCESS;
|
---|
202 | }
|
---|
203 |
|
---|
204 | /**
|
---|
205 | Provides a collection of resource descriptor lists. Each resource descriptor
|
---|
206 | list in the collection defines a combination of resources that can
|
---|
207 | potentially be used by the device.
|
---|
208 |
|
---|
209 | @param[in] This Indicates a pointer to the calling context.
|
---|
210 | @param[out] ResourceCollection Collection of the resource descriptor
|
---|
211 | lists.
|
---|
212 |
|
---|
213 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
214 | @retval EFI_INVALID_PARAMETER ResourceCollection is NULL.
|
---|
215 |
|
---|
216 | **/
|
---|
217 | EFI_STATUS
|
---|
218 | EFIAPI
|
---|
219 | SioPossibleResources (
|
---|
220 | IN CONST EFI_SIO_PROTOCOL *This,
|
---|
221 | OUT ACPI_RESOURCE_HEADER_PTR *ResourceCollection
|
---|
222 | )
|
---|
223 | {
|
---|
224 | return EFI_SUCCESS;
|
---|
225 | }
|
---|
226 |
|
---|
227 | /**
|
---|
228 | Provides an interface for a table based programming of the Super I/O
|
---|
229 | registers.
|
---|
230 |
|
---|
231 | The Modify() function provides an interface for table based programming of
|
---|
232 | the Super I/O registers. This function can be used to perform programming of
|
---|
233 | multiple Super I/O registers with a single function call. For each table
|
---|
234 | entry, the Register is read, its content is bitwise ANDed with AndMask, and
|
---|
235 | then ORed with OrMask before being written back to the Register. The Super
|
---|
236 | I/O driver must track the current state of the Super I/O and enable the
|
---|
237 | configuration mode of Super I/O if necessary prior to table processing. Once
|
---|
238 | the table is processed, the Super I/O device has to be returned to the
|
---|
239 | original state.
|
---|
240 |
|
---|
241 | @param[in] This Indicates a pointer to the calling context.
|
---|
242 | @param[in] Command A pointer to an array of NumberOfCommands
|
---|
243 | EFI_SIO_REGISTER_MODIFY structures. Each
|
---|
244 | structure specifies a single Super I/O register
|
---|
245 | modify operation.
|
---|
246 | @param[in] NumberOfCommands Number of elements in the Command array.
|
---|
247 |
|
---|
248 | @retval EFI_SUCCESS The operation completed successfully.
|
---|
249 | @retval EFI_INVALID_PARAMETER Command is NULL.
|
---|
250 |
|
---|
251 | **/
|
---|
252 | EFI_STATUS
|
---|
253 | EFIAPI
|
---|
254 | SioModify (
|
---|
255 | IN CONST EFI_SIO_PROTOCOL *This,
|
---|
256 | IN CONST EFI_SIO_REGISTER_MODIFY *Command,
|
---|
257 | IN UINTN NumberOfCommands
|
---|
258 | )
|
---|
259 | {
|
---|
260 | return EFI_SUCCESS;
|
---|
261 | }
|
---|
262 |
|
---|
263 | /**
|
---|
264 | Create the child device with a given device index.
|
---|
265 |
|
---|
266 | @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
|
---|
267 | @param[in] Controller The handle of ISA bus controller.
|
---|
268 | @param[in] PciIo The pointer to the PCI protocol.
|
---|
269 | @param[in] ParentDevicePath Device path of the ISA bus controller.
|
---|
270 | @param[in] DeviceIndex Index of the device supported by this driver.
|
---|
271 |
|
---|
272 | @retval EFI_SUCCESS The child device has been created successfully.
|
---|
273 | @retval Others Error occurred during the child device creation.
|
---|
274 |
|
---|
275 | **/
|
---|
276 | EFI_STATUS
|
---|
277 | SioCreateChildDevice (
|
---|
278 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
279 | IN EFI_HANDLE Controller,
|
---|
280 | IN EFI_PCI_IO_PROTOCOL *PciIo,
|
---|
281 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
|
---|
282 | IN UINT32 DeviceIndex
|
---|
283 | )
|
---|
284 | {
|
---|
285 | EFI_STATUS Status;
|
---|
286 | SIO_DEV *SioDevice;
|
---|
287 |
|
---|
288 | //
|
---|
289 | // Initialize the SIO_DEV structure
|
---|
290 | //
|
---|
291 | SioDevice = AllocateZeroPool (sizeof (SIO_DEV));
|
---|
292 | if (SioDevice == NULL) {
|
---|
293 | return EFI_OUT_OF_RESOURCES;
|
---|
294 | }
|
---|
295 |
|
---|
296 | SioDevice->Signature = SIO_DEV_SIGNATURE;
|
---|
297 | SioDevice->Handle = NULL;
|
---|
298 | SioDevice->PciIo = PciIo;
|
---|
299 |
|
---|
300 | //
|
---|
301 | // Construct the child device path
|
---|
302 | //
|
---|
303 | mAcpiDeviceNodeTemplate.HID = mDevicesInfo[DeviceIndex].Hid;
|
---|
304 | mAcpiDeviceNodeTemplate.UID = mDevicesInfo[DeviceIndex].Uid;
|
---|
305 | SioDevice->DevicePath = AppendDevicePathNode (
|
---|
306 | ParentDevicePath,
|
---|
307 | (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiDeviceNodeTemplate
|
---|
308 | );
|
---|
309 | if (SioDevice->DevicePath == NULL) {
|
---|
310 | Status = EFI_OUT_OF_RESOURCES;
|
---|
311 | goto Done;
|
---|
312 | }
|
---|
313 |
|
---|
314 | CopyMem (&SioDevice->Sio, &mSioInterface, sizeof (EFI_SIO_PROTOCOL));
|
---|
315 | SioDevice->DeviceIndex = DeviceIndex;
|
---|
316 |
|
---|
317 | //
|
---|
318 | // Create a child handle and install Device Path and Super I/O protocols
|
---|
319 | //
|
---|
320 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
321 | &SioDevice->Handle,
|
---|
322 | &gEfiDevicePathProtocolGuid,
|
---|
323 | SioDevice->DevicePath,
|
---|
324 | &gEfiSioProtocolGuid,
|
---|
325 | &SioDevice->Sio,
|
---|
326 | NULL
|
---|
327 | );
|
---|
328 | if (EFI_ERROR (Status)) {
|
---|
329 | goto Done;
|
---|
330 | }
|
---|
331 |
|
---|
332 | Status = gBS->OpenProtocol (
|
---|
333 | Controller,
|
---|
334 | &gEfiPciIoProtocolGuid,
|
---|
335 | (VOID **)&PciIo,
|
---|
336 | This->DriverBindingHandle,
|
---|
337 | SioDevice->Handle,
|
---|
338 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
|
---|
339 | );
|
---|
340 | if (EFI_ERROR (Status)) {
|
---|
341 | gBS->UninstallMultipleProtocolInterfaces (
|
---|
342 | SioDevice->Handle,
|
---|
343 | &gEfiDevicePathProtocolGuid,
|
---|
344 | SioDevice->DevicePath,
|
---|
345 | &gEfiSioProtocolGuid,
|
---|
346 | &SioDevice->Sio,
|
---|
347 | NULL
|
---|
348 | );
|
---|
349 | }
|
---|
350 |
|
---|
351 | Done:
|
---|
352 | if (EFI_ERROR (Status)) {
|
---|
353 | if (SioDevice->DevicePath != NULL) {
|
---|
354 | FreePool (SioDevice->DevicePath);
|
---|
355 | }
|
---|
356 |
|
---|
357 | FreePool (SioDevice);
|
---|
358 | }
|
---|
359 |
|
---|
360 | return Status;
|
---|
361 | }
|
---|
362 |
|
---|
363 | /**
|
---|
364 | Create all the ISA child devices on the ISA bus controller (PCI to ISA
|
---|
365 | bridge).
|
---|
366 |
|
---|
367 | @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
|
---|
368 | @param[in] Controller The handle of ISA bus controller.
|
---|
369 | @param[in] PciIo The pointer to the PCI protocol.
|
---|
370 | @param[in] ParentDevicePath Device path of the ISA bus controller.
|
---|
371 |
|
---|
372 | @retval The number of child device that is successfully created.
|
---|
373 |
|
---|
374 | **/
|
---|
375 | UINT32
|
---|
376 | SioCreateAllChildDevices (
|
---|
377 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
378 | IN EFI_HANDLE Controller,
|
---|
379 | IN EFI_PCI_IO_PROTOCOL *PciIo,
|
---|
380 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath
|
---|
381 | )
|
---|
382 | {
|
---|
383 | UINT32 Index;
|
---|
384 | UINT32 ChildDeviceNumber;
|
---|
385 | EFI_STATUS Status;
|
---|
386 |
|
---|
387 | ChildDeviceNumber = 0;
|
---|
388 |
|
---|
389 | for (Index = 0; Index < ARRAY_SIZE (mDevicesInfo); Index++) {
|
---|
390 | Status = SioCreateChildDevice (
|
---|
391 | This,
|
---|
392 | Controller,
|
---|
393 | PciIo,
|
---|
394 | ParentDevicePath,
|
---|
395 | Index
|
---|
396 | );
|
---|
397 | if (!EFI_ERROR (Status)) {
|
---|
398 | ChildDeviceNumber++;
|
---|
399 | }
|
---|
400 | }
|
---|
401 |
|
---|
402 | return ChildDeviceNumber;
|
---|
403 | }
|
---|