2 The SioBusDxe driver is used to create child devices on the ISA bus and
3 installs the Super I/O protocols on them.
5 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "SioBusDxe.h"
14 // Super I/O Protocol interfaces
16 EFI_SIO_PROTOCOL mSioInterface
= {
25 // COM 1 UART Controller
27 GLOBAL_REMOVE_IF_UNREFERENCED
28 SIO_RESOURCES_IO mCom1Resources
= {
29 { { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x3F8, 8 },
30 { ACPI_END_TAG_DESCRIPTOR
, 0 }
34 // COM 2 UART Controller
36 GLOBAL_REMOVE_IF_UNREFERENCED
37 SIO_RESOURCES_IO mCom2Resources
= {
38 { { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x2F8, 8 },
39 { ACPI_END_TAG_DESCRIPTOR
, 0 }
43 // PS/2 Keyboard Controller
45 GLOBAL_REMOVE_IF_UNREFERENCED
46 SIO_RESOURCES_IO mPs2KeyboardDeviceResources
= {
47 { { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x60, 5 },
48 { ACPI_END_TAG_DESCRIPTOR
, 0 }
52 // Table of SIO Controllers
54 GLOBAL_REMOVE_IF_UNREFERENCED
55 SIO_DEVICE_INFO mDevicesInfo
[] = {
59 { (ACPI_SMALL_RESOURCE_HEADER
*) &mCom1Resources
}
60 }, // COM 1 UART Controller
64 { (ACPI_SMALL_RESOURCE_HEADER
*) &mCom2Resources
}
65 }, // COM 2 UART Controller
69 { (ACPI_SMALL_RESOURCE_HEADER
*) &mPs2KeyboardDeviceResources
}
70 } // PS/2 Keyboard Controller
74 // ACPI Device Path Node template
76 GLOBAL_REMOVE_IF_UNREFERENCED
77 ACPI_HID_DEVICE_PATH mAcpiDeviceNodeTemplate
= {
82 (UINT8
) (sizeof (ACPI_HID_DEVICE_PATH
)),
83 (UINT8
) ((sizeof (ACPI_HID_DEVICE_PATH
)) >> 8)
92 Provides a low level access to the registers for the Super I/O.
94 @param[in] This Indicates a pointer to the calling context.
95 @param[in] Write Specifies the type of the register operation.
96 If this parameter is TRUE, Value is interpreted
97 as an input parameter and the operation is a
98 register write. If this parameter is FALSE,
99 Value is interpreted as an output parameter and
100 the operation is a register read.
101 @param[in] ExitCfgMode Exit Configuration Mode Indicator. If this
102 parameter is set to TRUE, the Super I/O driver
103 will turn off configuration mode of the Super
104 I/O prior to returning from this function. If
105 this parameter is set to FALSE, the Super I/O
106 driver will leave Super I/O in the
107 configuration mode. The Super I/O driver must
108 track the current state of the Super I/O and
109 enable the configuration mode of Super I/O if
110 necessary prior to register access.
111 @param[in] Register Register number.
112 @param[in,out] Value If Write is TRUE, Value is a pointer to the
113 buffer containing the byte of data to be
114 written to the Super I/O register. If Write is
115 FALSE, Value is a pointer to the destination
116 buffer for the byte of data to be read from the
119 @retval EFI_SUCCESS The operation completed successfully.
120 @retval EFI_INVALID_PARAMETER The Value is NULL.
121 @retval EFI_INVALID_PARAMETER Invalid Register number.
127 IN CONST EFI_SIO_PROTOCOL
*This
,
129 IN BOOLEAN ExitCfgMode
,
138 Provides an interface to get a list of the current resources consumed by the
139 device in the ACPI Resource Descriptor format.
141 GetResources() returns a list of resources currently consumed by the device.
142 The ResourceList is a pointer to the buffer containing resource descriptors
143 for the device. The descriptors are in the format of Small or Large ACPI
144 resource descriptor as defined by ACPI specification (2.0 & 3.0). The buffer
145 of resource descriptors is terminated with the 'End tag' resource descriptor.
147 @param[in] This Indicates a pointer to the calling context.
148 @param[out] ResourceList A pointer to an ACPI resource descriptor list
149 that defines the current resources used by the
152 @retval EFI_SUCCESS The operation completed successfully.
153 @retval EFI_INVALID_PARAMETER ResourceList is NULL.
159 IN CONST EFI_SIO_PROTOCOL
*This
,
160 OUT ACPI_RESOURCE_HEADER_PTR
*ResourceList
165 if (ResourceList
== NULL
) {
166 return EFI_INVALID_PARAMETER
;
169 SioDevice
= SIO_DEV_FROM_SIO (This
);
170 if (SioDevice
->DeviceIndex
< ARRAY_SIZE (mDevicesInfo
)) {
171 *ResourceList
= mDevicesInfo
[SioDevice
->DeviceIndex
].Resources
;
178 Sets the resources for the device.
180 @param[in] This Indicates a pointer to the calling context.
181 @param[in] ResourceList Pointer to the ACPI resource descriptor list.
183 @retval EFI_SUCCESS The operation completed successfully.
184 @retval EFI_INVALID_PARAMETER ResourceList is invalid.
185 @retval EFI_ACCESS_DENIED Some of the resources in ResourceList are in
192 IN CONST EFI_SIO_PROTOCOL
*This
,
193 IN ACPI_RESOURCE_HEADER_PTR ResourceList
200 Provides a collection of resource descriptor lists. Each resource descriptor
201 list in the collection defines a combination of resources that can
202 potentially be used by the device.
204 @param[in] This Indicates a pointer to the calling context.
205 @param[out] ResourceCollection Collection of the resource descriptor
208 @retval EFI_SUCCESS The operation completed successfully.
209 @retval EFI_INVALID_PARAMETER ResourceCollection is NULL.
214 SioPossibleResources (
215 IN CONST EFI_SIO_PROTOCOL
*This
,
216 OUT ACPI_RESOURCE_HEADER_PTR
*ResourceCollection
223 Provides an interface for a table based programming of the Super I/O
226 The Modify() function provides an interface for table based programming of
227 the Super I/O registers. This function can be used to perform programming of
228 multiple Super I/O registers with a single function call. For each table
229 entry, the Register is read, its content is bitwise ANDed with AndMask, and
230 then ORed with OrMask before being written back to the Register. The Super
231 I/O driver must track the current state of the Super I/O and enable the
232 configuration mode of Super I/O if necessary prior to table processing. Once
233 the table is processed, the Super I/O device has to be returned to the
236 @param[in] This Indicates a pointer to the calling context.
237 @param[in] Command A pointer to an array of NumberOfCommands
238 EFI_SIO_REGISTER_MODIFY structures. Each
239 structure specifies a single Super I/O register
241 @param[in] NumberOfCommands Number of elements in the Command array.
243 @retval EFI_SUCCESS The operation completed successfully.
244 @retval EFI_INVALID_PARAMETER Command is NULL.
250 IN CONST EFI_SIO_PROTOCOL
*This
,
251 IN CONST EFI_SIO_REGISTER_MODIFY
*Command
,
252 IN UINTN NumberOfCommands
259 Create the child device with a given device index.
261 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
262 @param[in] Controller The handle of ISA bus controller.
263 @param[in] PciIo The pointer to the PCI protocol.
264 @param[in] ParentDevicePath Device path of the ISA bus controller.
265 @param[in] DeviceIndex Index of the device supported by this driver.
267 @retval EFI_SUCCESS The child device has been created successfully.
268 @retval Others Error occured during the child device creation.
272 SioCreateChildDevice (
273 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
274 IN EFI_HANDLE Controller
,
275 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
276 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
277 IN UINT32 DeviceIndex
284 // Initialize the SIO_DEV structure
286 SioDevice
= AllocateZeroPool (sizeof (SIO_DEV
));
287 if (SioDevice
== NULL
) {
288 return EFI_OUT_OF_RESOURCES
;
291 SioDevice
->Signature
= SIO_DEV_SIGNATURE
;
292 SioDevice
->Handle
= NULL
;
293 SioDevice
->PciIo
= PciIo
;
296 // Construct the child device path
298 mAcpiDeviceNodeTemplate
.HID
= mDevicesInfo
[DeviceIndex
].Hid
;
299 mAcpiDeviceNodeTemplate
.UID
= mDevicesInfo
[DeviceIndex
].Uid
;
300 SioDevice
->DevicePath
= AppendDevicePathNode (
302 (EFI_DEVICE_PATH_PROTOCOL
*) &mAcpiDeviceNodeTemplate
304 if (SioDevice
->DevicePath
== NULL
) {
305 Status
= EFI_OUT_OF_RESOURCES
;
309 CopyMem (&SioDevice
->Sio
, &mSioInterface
, sizeof (EFI_SIO_PROTOCOL
));
310 SioDevice
->DeviceIndex
= DeviceIndex
;
313 // Create a child handle and install Device Path and Super I/O protocols
315 Status
= gBS
->InstallMultipleProtocolInterfaces (
317 &gEfiDevicePathProtocolGuid
,
318 SioDevice
->DevicePath
,
319 &gEfiSioProtocolGuid
,
323 if (EFI_ERROR (Status
)) {
327 Status
= gBS
->OpenProtocol (
329 &gEfiPciIoProtocolGuid
,
331 This
->DriverBindingHandle
,
333 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
335 if (EFI_ERROR (Status
)) {
336 gBS
->UninstallMultipleProtocolInterfaces (
338 &gEfiDevicePathProtocolGuid
,
339 SioDevice
->DevicePath
,
340 &gEfiSioProtocolGuid
,
347 if (EFI_ERROR (Status
)) {
348 if (SioDevice
->DevicePath
!= NULL
) {
349 FreePool (SioDevice
->DevicePath
);
352 FreePool (SioDevice
);
359 Create all the ISA child devices on the ISA bus controller (PCI to ISA
362 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
363 @param[in] Controller The handle of ISA bus controller.
364 @param[in] PciIo The pointer to the PCI protocol.
365 @param[in] ParentDevicePath Device path of the ISA bus controller.
367 @retval The number of child device that is successfully created.
371 SioCreateAllChildDevices (
372 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
373 IN EFI_HANDLE Controller
,
374 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
375 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
379 UINT32 ChildDeviceNumber
;
382 ChildDeviceNumber
= 0;
384 for (Index
= 0; Index
< ARRAY_SIZE (mDevicesInfo
); Index
++) {
385 Status
= SioCreateChildDevice (
392 if (!EFI_ERROR (Status
)) {
397 return ChildDeviceNumber
;