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
= {
30 { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x3F8, 8
32 { ACPI_END_TAG_DESCRIPTOR
, 0 }
36 // COM 2 UART Controller
38 GLOBAL_REMOVE_IF_UNREFERENCED
39 SIO_RESOURCES_IO mCom2Resources
= {
41 { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x2F8, 8
43 { ACPI_END_TAG_DESCRIPTOR
, 0 }
47 // PS/2 Keyboard Controller
49 GLOBAL_REMOVE_IF_UNREFERENCED
50 SIO_RESOURCES_IO mPs2KeyboardDeviceResources
= {
52 { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x60, 5
54 { ACPI_END_TAG_DESCRIPTOR
, 0 }
58 // Table of SIO Controllers
60 GLOBAL_REMOVE_IF_UNREFERENCED
61 SIO_DEVICE_INFO mDevicesInfo
[] = {
65 { (ACPI_SMALL_RESOURCE_HEADER
*)&mCom1Resources
}
66 }, // COM 1 UART Controller
70 { (ACPI_SMALL_RESOURCE_HEADER
*)&mCom2Resources
}
71 }, // COM 2 UART Controller
75 { (ACPI_SMALL_RESOURCE_HEADER
*)&mPs2KeyboardDeviceResources
}
76 } // PS/2 Keyboard Controller
80 // ACPI Device Path Node template
82 GLOBAL_REMOVE_IF_UNREFERENCED
83 ACPI_HID_DEVICE_PATH mAcpiDeviceNodeTemplate
= {
88 (UINT8
)(sizeof (ACPI_HID_DEVICE_PATH
)),
89 (UINT8
)((sizeof (ACPI_HID_DEVICE_PATH
)) >> 8)
97 Provides a low level access to the registers for the Super I/O.
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
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.
132 IN CONST EFI_SIO_PROTOCOL
*This
,
134 IN BOOLEAN ExitCfgMode
,
143 Provides an interface to get a list of the current resources consumed by the
144 device in the ACPI Resource Descriptor format.
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.
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
157 @retval EFI_SUCCESS The operation completed successfully.
158 @retval EFI_INVALID_PARAMETER ResourceList is NULL.
164 IN CONST EFI_SIO_PROTOCOL
*This
,
165 OUT ACPI_RESOURCE_HEADER_PTR
*ResourceList
170 if (ResourceList
== NULL
) {
171 return EFI_INVALID_PARAMETER
;
174 SioDevice
= SIO_DEV_FROM_SIO (This
);
175 if (SioDevice
->DeviceIndex
< ARRAY_SIZE (mDevicesInfo
)) {
176 *ResourceList
= mDevicesInfo
[SioDevice
->DeviceIndex
].Resources
;
183 Sets the resources for the device.
185 @param[in] This Indicates a pointer to the calling context.
186 @param[in] ResourceList Pointer to the ACPI resource descriptor list.
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
197 IN CONST EFI_SIO_PROTOCOL
*This
,
198 IN ACPI_RESOURCE_HEADER_PTR ResourceList
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.
209 @param[in] This Indicates a pointer to the calling context.
210 @param[out] ResourceCollection Collection of the resource descriptor
213 @retval EFI_SUCCESS The operation completed successfully.
214 @retval EFI_INVALID_PARAMETER ResourceCollection is NULL.
219 SioPossibleResources (
220 IN CONST EFI_SIO_PROTOCOL
*This
,
221 OUT ACPI_RESOURCE_HEADER_PTR
*ResourceCollection
228 Provides an interface for a table based programming of the Super I/O
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
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
246 @param[in] NumberOfCommands Number of elements in the Command array.
248 @retval EFI_SUCCESS The operation completed successfully.
249 @retval EFI_INVALID_PARAMETER Command is NULL.
255 IN CONST EFI_SIO_PROTOCOL
*This
,
256 IN CONST EFI_SIO_REGISTER_MODIFY
*Command
,
257 IN UINTN NumberOfCommands
264 Create the child device with a given device index.
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.
272 @retval EFI_SUCCESS The child device has been created successfully.
273 @retval Others Error occurred during the child device creation.
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
289 // Initialize the SIO_DEV structure
291 SioDevice
= AllocateZeroPool (sizeof (SIO_DEV
));
292 if (SioDevice
== NULL
) {
293 return EFI_OUT_OF_RESOURCES
;
296 SioDevice
->Signature
= SIO_DEV_SIGNATURE
;
297 SioDevice
->Handle
= NULL
;
298 SioDevice
->PciIo
= PciIo
;
301 // Construct the child device path
303 mAcpiDeviceNodeTemplate
.HID
= mDevicesInfo
[DeviceIndex
].Hid
;
304 mAcpiDeviceNodeTemplate
.UID
= mDevicesInfo
[DeviceIndex
].Uid
;
305 SioDevice
->DevicePath
= AppendDevicePathNode (
307 (EFI_DEVICE_PATH_PROTOCOL
*)&mAcpiDeviceNodeTemplate
309 if (SioDevice
->DevicePath
== NULL
) {
310 Status
= EFI_OUT_OF_RESOURCES
;
314 CopyMem (&SioDevice
->Sio
, &mSioInterface
, sizeof (EFI_SIO_PROTOCOL
));
315 SioDevice
->DeviceIndex
= DeviceIndex
;
318 // Create a child handle and install Device Path and Super I/O protocols
320 Status
= gBS
->InstallMultipleProtocolInterfaces (
322 &gEfiDevicePathProtocolGuid
,
323 SioDevice
->DevicePath
,
324 &gEfiSioProtocolGuid
,
328 if (EFI_ERROR (Status
)) {
332 Status
= gBS
->OpenProtocol (
334 &gEfiPciIoProtocolGuid
,
336 This
->DriverBindingHandle
,
338 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
340 if (EFI_ERROR (Status
)) {
341 gBS
->UninstallMultipleProtocolInterfaces (
343 &gEfiDevicePathProtocolGuid
,
344 SioDevice
->DevicePath
,
345 &gEfiSioProtocolGuid
,
352 if (EFI_ERROR (Status
)) {
353 if (SioDevice
->DevicePath
!= NULL
) {
354 FreePool (SioDevice
->DevicePath
);
357 FreePool (SioDevice
);
364 Create all the ISA child devices on the ISA bus controller (PCI to ISA
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.
372 @retval The number of child device that is successfully created.
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
384 UINT32 ChildDeviceNumber
;
387 ChildDeviceNumber
= 0;
389 for (Index
= 0; Index
< ARRAY_SIZE (mDevicesInfo
); Index
++) {
390 Status
= SioCreateChildDevice (
397 if (!EFI_ERROR (Status
)) {
402 return ChildDeviceNumber
;