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 This program and the accompanying materials
8 are licensed and made available under the terms and conditions
9 of the BSD License which accompanies this distribution. The
10 full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "SioBusDxe.h"
21 // Super I/O Protocol interfaces
23 EFI_SIO_PROTOCOL mSioInterface
= {
32 // COM 1 UART Controller
34 GLOBAL_REMOVE_IF_UNREFERENCED
35 SIO_RESOURCES_IO mCom1Resources
= {
36 { { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x3F8, 8 },
37 { ACPI_END_TAG_DESCRIPTOR
, 0 }
41 // COM 2 UART Controller
43 GLOBAL_REMOVE_IF_UNREFERENCED
44 SIO_RESOURCES_IO mCom2Resources
= {
45 { { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x2F8, 8 },
46 { ACPI_END_TAG_DESCRIPTOR
, 0 }
50 // PS/2 Keyboard Controller
52 GLOBAL_REMOVE_IF_UNREFERENCED
53 SIO_RESOURCES_IO mPs2KeyboardDeviceResources
= {
54 { { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR
}, 0x60, 5 },
55 { ACPI_END_TAG_DESCRIPTOR
, 0 }
59 // Table of SIO Controllers
61 GLOBAL_REMOVE_IF_UNREFERENCED
62 SIO_DEVICE_INFO mDevicesInfo
[] = {
66 { (ACPI_SMALL_RESOURCE_HEADER
*) &mCom1Resources
}
67 }, // COM 1 UART Controller
71 { (ACPI_SMALL_RESOURCE_HEADER
*) &mCom2Resources
}
72 }, // COM 2 UART Controller
76 { (ACPI_SMALL_RESOURCE_HEADER
*) &mPs2KeyboardDeviceResources
}
77 } // PS/2 Keyboard Controller
81 // ACPI Device Path Node template
83 GLOBAL_REMOVE_IF_UNREFERENCED
84 ACPI_HID_DEVICE_PATH mAcpiDeviceNodeTemplate
= {
89 (UINT8
) (sizeof (ACPI_HID_DEVICE_PATH
)),
90 (UINT8
) ((sizeof (ACPI_HID_DEVICE_PATH
)) >> 8)
99 Provides a low level access to the registers for the Super I/O.
101 @param[in] This Indicates a pointer to the calling context.
102 @param[in] Write Specifies the type of the register operation.
103 If this parameter is TRUE, Value is interpreted
104 as an input parameter and the operation is a
105 register write. If this parameter is FALSE,
106 Value is interpreted as an output parameter and
107 the operation is a register read.
108 @param[in] ExitCfgMode Exit Configuration Mode Indicator. If this
109 parameter is set to TRUE, the Super I/O driver
110 will turn off configuration mode of the Super
111 I/O prior to returning from this function. If
112 this parameter is set to FALSE, the Super I/O
113 driver will leave Super I/O in the
114 configuration mode. The Super I/O driver must
115 track the current state of the Super I/O and
116 enable the configuration mode of Super I/O if
117 necessary prior to register access.
118 @param[in] Register Register number.
119 @param[in,out] Value If Write is TRUE, Value is a pointer to the
120 buffer containing the byte of data to be
121 written to the Super I/O register. If Write is
122 FALSE, Value is a pointer to the destination
123 buffer for the byte of data to be read from the
126 @retval EFI_SUCCESS The operation completed successfully.
127 @retval EFI_INVALID_PARAMETER The Value is NULL.
128 @retval EFI_INVALID_PARAMETER Invalid Register number.
134 IN CONST EFI_SIO_PROTOCOL
*This
,
136 IN BOOLEAN ExitCfgMode
,
145 Provides an interface to get a list of the current resources consumed by the
146 device in the ACPI Resource Descriptor format.
148 GetResources() returns a list of resources currently consumed by the device.
149 The ResourceList is a pointer to the buffer containing resource descriptors
150 for the device. The descriptors are in the format of Small or Large ACPI
151 resource descriptor as defined by ACPI specification (2.0 & 3.0). The buffer
152 of resource descriptors is terminated with the 'End tag' resource descriptor.
154 @param[in] This Indicates a pointer to the calling context.
155 @param[out] ResourceList A pointer to an ACPI resource descriptor list
156 that defines the current resources used by the
159 @retval EFI_SUCCESS The operation completed successfully.
160 @retval EFI_INVALID_PARAMETER ResourceList is NULL.
166 IN CONST EFI_SIO_PROTOCOL
*This
,
167 OUT ACPI_RESOURCE_HEADER_PTR
*ResourceList
172 if (ResourceList
== NULL
) {
173 return EFI_INVALID_PARAMETER
;
176 SioDevice
= SIO_DEV_FROM_SIO (This
);
177 if (SioDevice
->DeviceIndex
< ARRAY_SIZE (mDevicesInfo
)) {
178 *ResourceList
= mDevicesInfo
[SioDevice
->DeviceIndex
].Resources
;
185 Sets the resources for the device.
187 @param[in] This Indicates a pointer to the calling context.
188 @param[in] ResourceList Pointer to the ACPI resource descriptor list.
190 @retval EFI_SUCCESS The operation completed successfully.
191 @retval EFI_INVALID_PARAMETER ResourceList is invalid.
192 @retval EFI_ACCESS_DENIED Some of the resources in ResourceList are in
199 IN CONST EFI_SIO_PROTOCOL
*This
,
200 IN ACPI_RESOURCE_HEADER_PTR ResourceList
207 Provides a collection of resource descriptor lists. Each resource descriptor
208 list in the collection defines a combination of resources that can
209 potentially be used by the device.
211 @param[in] This Indicates a pointer to the calling context.
212 @param[out] ResourceCollection Collection of the resource descriptor
215 @retval EFI_SUCCESS The operation completed successfully.
216 @retval EFI_INVALID_PARAMETER ResourceCollection is NULL.
221 SioPossibleResources (
222 IN CONST EFI_SIO_PROTOCOL
*This
,
223 OUT ACPI_RESOURCE_HEADER_PTR
*ResourceCollection
230 Provides an interface for a table based programming of the Super I/O
233 The Modify() function provides an interface for table based programming of
234 the Super I/O registers. This function can be used to perform programming of
235 multiple Super I/O registers with a single function call. For each table
236 entry, the Register is read, its content is bitwise ANDed with AndMask, and
237 then ORed with OrMask before being written back to the Register. The Super
238 I/O driver must track the current state of the Super I/O and enable the
239 configuration mode of Super I/O if necessary prior to table processing. Once
240 the table is processed, the Super I/O device has to be returned to the
243 @param[in] This Indicates a pointer to the calling context.
244 @param[in] Command A pointer to an array of NumberOfCommands
245 EFI_SIO_REGISTER_MODIFY structures. Each
246 structure specifies a single Super I/O register
248 @param[in] NumberOfCommands Number of elements in the Command array.
250 @retval EFI_SUCCESS The operation completed successfully.
251 @retval EFI_INVALID_PARAMETER Command is NULL.
257 IN CONST EFI_SIO_PROTOCOL
*This
,
258 IN CONST EFI_SIO_REGISTER_MODIFY
*Command
,
259 IN UINTN NumberOfCommands
266 Create the child device with a given device index.
268 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
269 @param[in] Controller The handle of ISA bus controller.
270 @param[in] PciIo The pointer to the PCI protocol.
271 @param[in] ParentDevicePath Device path of the ISA bus controller.
272 @param[in] DeviceIndex Index of the device supported by this driver.
274 @retval EFI_SUCCESS The child device has been created successfully.
275 @retval Others Error occured during the child device creation.
279 SioCreateChildDevice (
280 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
281 IN EFI_HANDLE Controller
,
282 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
283 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
284 IN UINT32 DeviceIndex
291 // Initialize the SIO_DEV structure
293 SioDevice
= AllocateZeroPool (sizeof (SIO_DEV
));
294 if (SioDevice
== NULL
) {
295 return EFI_OUT_OF_RESOURCES
;
298 SioDevice
->Signature
= SIO_DEV_SIGNATURE
;
299 SioDevice
->Handle
= NULL
;
300 SioDevice
->PciIo
= PciIo
;
303 // Construct the child device path
305 mAcpiDeviceNodeTemplate
.HID
= mDevicesInfo
[DeviceIndex
].Hid
;
306 mAcpiDeviceNodeTemplate
.UID
= mDevicesInfo
[DeviceIndex
].Uid
;
307 SioDevice
->DevicePath
= AppendDevicePathNode (
309 (EFI_DEVICE_PATH_PROTOCOL
*) &mAcpiDeviceNodeTemplate
311 if (SioDevice
->DevicePath
== NULL
) {
312 Status
= EFI_OUT_OF_RESOURCES
;
316 CopyMem (&SioDevice
->Sio
, &mSioInterface
, sizeof (EFI_SIO_PROTOCOL
));
317 SioDevice
->DeviceIndex
= DeviceIndex
;
320 // Create a child handle and install Device Path and Super I/O protocols
322 Status
= gBS
->InstallMultipleProtocolInterfaces (
324 &gEfiDevicePathProtocolGuid
,
325 SioDevice
->DevicePath
,
326 &gEfiSioProtocolGuid
,
330 if (EFI_ERROR (Status
)) {
334 Status
= gBS
->OpenProtocol (
336 &gEfiPciIoProtocolGuid
,
338 This
->DriverBindingHandle
,
340 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
342 if (EFI_ERROR (Status
)) {
343 gBS
->UninstallMultipleProtocolInterfaces (
345 &gEfiDevicePathProtocolGuid
,
346 SioDevice
->DevicePath
,
347 &gEfiSioProtocolGuid
,
354 if (EFI_ERROR (Status
)) {
355 if (SioDevice
->DevicePath
!= NULL
) {
356 FreePool (SioDevice
->DevicePath
);
359 FreePool (SioDevice
);
366 Create all the ISA child devices on the ISA bus controller (PCI to ISA
369 @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance.
370 @param[in] Controller The handle of ISA bus controller.
371 @param[in] PciIo The pointer to the PCI protocol.
372 @param[in] ParentDevicePath Device path of the ISA bus controller.
374 @retval The number of child device that is successfully created.
378 SioCreateAllChildDevices (
379 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
380 IN EFI_HANDLE Controller
,
381 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
382 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
386 UINT32 ChildDeviceNumber
;
389 ChildDeviceNumber
= 0;
391 for (Index
= 0; Index
< ARRAY_SIZE (mDevicesInfo
); Index
++) {
392 Status
= SioCreateChildDevice (
399 if (!EFI_ERROR (Status
)) {
404 return ChildDeviceNumber
;