]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/SioBusDxe/SioService.c
IntelFsp2Pkg/SplitFspBin.py: Support rebasing 1.x binary.
[mirror_edk2.git] / OvmfPkg / SioBusDxe / SioService.c
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 { { ACPI_FIXED_LOCATION_IO_PORT_DESCRIPTOR }, 0x3F8, 8 },
30 { ACPI_END_TAG_DESCRIPTOR, 0 }
31 };
32
33 //
34 // COM 2 UART Controller
35 //
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 }
40 };
41
42 //
43 // PS/2 Keyboard Controller
44 //
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 }
49 };
50
51 //
52 // Table of SIO Controllers
53 //
54 GLOBAL_REMOVE_IF_UNREFERENCED
55 SIO_DEVICE_INFO mDevicesInfo[] = {
56 {
57 EISA_PNP_ID (0x501),
58 0,
59 { (ACPI_SMALL_RESOURCE_HEADER *) &mCom1Resources }
60 }, // COM 1 UART Controller
61 {
62 EISA_PNP_ID (0x501),
63 1,
64 { (ACPI_SMALL_RESOURCE_HEADER *) &mCom2Resources }
65 }, // COM 2 UART Controller
66 {
67 EISA_PNP_ID(0x303),
68 0,
69 { (ACPI_SMALL_RESOURCE_HEADER *) &mPs2KeyboardDeviceResources }
70 } // PS/2 Keyboard Controller
71 };
72
73 //
74 // ACPI Device Path Node template
75 //
76 GLOBAL_REMOVE_IF_UNREFERENCED
77 ACPI_HID_DEVICE_PATH mAcpiDeviceNodeTemplate = {
78 { // Header
79 ACPI_DEVICE_PATH,
80 ACPI_DP,
81 {
82 (UINT8) (sizeof (ACPI_HID_DEVICE_PATH)),
83 (UINT8) ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
84 }
85 },
86 0x0, // HID
87 0x0 // UID
88 };
89
90
91 /**
92 Provides a low level access to the registers for the Super I/O.
93
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
117 Super I/O register.
118
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.
122
123 **/
124 EFI_STATUS
125 EFIAPI
126 SioRegisterAccess (
127 IN CONST EFI_SIO_PROTOCOL *This,
128 IN BOOLEAN Write,
129 IN BOOLEAN ExitCfgMode,
130 IN UINT8 Register,
131 IN OUT UINT8 *Value
132 )
133 {
134 return EFI_SUCCESS;
135 }
136
137 /**
138 Provides an interface to get a list of the current resources consumed by the
139 device in the ACPI Resource Descriptor format.
140
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.
146
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
150 device.
151
152 @retval EFI_SUCCESS The operation completed successfully.
153 @retval EFI_INVALID_PARAMETER ResourceList is NULL.
154
155 **/
156 EFI_STATUS
157 EFIAPI
158 SioGetResources (
159 IN CONST EFI_SIO_PROTOCOL *This,
160 OUT ACPI_RESOURCE_HEADER_PTR *ResourceList
161 )
162 {
163 SIO_DEV *SioDevice;
164
165 if (ResourceList == NULL) {
166 return EFI_INVALID_PARAMETER;
167 }
168
169 SioDevice = SIO_DEV_FROM_SIO (This);
170 if (SioDevice->DeviceIndex < ARRAY_SIZE (mDevicesInfo)) {
171 *ResourceList = mDevicesInfo[SioDevice->DeviceIndex].Resources;
172 }
173
174 return EFI_SUCCESS;
175 }
176
177 /**
178 Sets the resources for the device.
179
180 @param[in] This Indicates a pointer to the calling context.
181 @param[in] ResourceList Pointer to the ACPI resource descriptor list.
182
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
186 use.
187
188 **/
189 EFI_STATUS
190 EFIAPI
191 SioSetResources (
192 IN CONST EFI_SIO_PROTOCOL *This,
193 IN ACPI_RESOURCE_HEADER_PTR ResourceList
194 )
195 {
196 return EFI_SUCCESS;
197 }
198
199 /**
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.
203
204 @param[in] This Indicates a pointer to the calling context.
205 @param[out] ResourceCollection Collection of the resource descriptor
206 lists.
207
208 @retval EFI_SUCCESS The operation completed successfully.
209 @retval EFI_INVALID_PARAMETER ResourceCollection is NULL.
210
211 **/
212 EFI_STATUS
213 EFIAPI
214 SioPossibleResources (
215 IN CONST EFI_SIO_PROTOCOL *This,
216 OUT ACPI_RESOURCE_HEADER_PTR *ResourceCollection
217 )
218 {
219 return EFI_SUCCESS;
220 }
221
222 /**
223 Provides an interface for a table based programming of the Super I/O
224 registers.
225
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
234 original state.
235
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
240 modify operation.
241 @param[in] NumberOfCommands Number of elements in the Command array.
242
243 @retval EFI_SUCCESS The operation completed successfully.
244 @retval EFI_INVALID_PARAMETER Command is NULL.
245
246 **/
247 EFI_STATUS
248 EFIAPI
249 SioModify (
250 IN CONST EFI_SIO_PROTOCOL *This,
251 IN CONST EFI_SIO_REGISTER_MODIFY *Command,
252 IN UINTN NumberOfCommands
253 )
254 {
255 return EFI_SUCCESS;
256 }
257
258 /**
259 Create the child device with a given device index.
260
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.
266
267 @retval EFI_SUCCESS The child device has been created successfully.
268 @retval Others Error occured during the child device creation.
269
270 **/
271 EFI_STATUS
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
278 )
279 {
280 EFI_STATUS Status;
281 SIO_DEV *SioDevice;
282
283 //
284 // Initialize the SIO_DEV structure
285 //
286 SioDevice = AllocateZeroPool (sizeof (SIO_DEV));
287 if (SioDevice == NULL) {
288 return EFI_OUT_OF_RESOURCES;
289 }
290
291 SioDevice->Signature = SIO_DEV_SIGNATURE;
292 SioDevice->Handle = NULL;
293 SioDevice->PciIo = PciIo;
294
295 //
296 // Construct the child device path
297 //
298 mAcpiDeviceNodeTemplate.HID = mDevicesInfo[DeviceIndex].Hid;
299 mAcpiDeviceNodeTemplate.UID = mDevicesInfo[DeviceIndex].Uid;
300 SioDevice->DevicePath = AppendDevicePathNode (
301 ParentDevicePath,
302 (EFI_DEVICE_PATH_PROTOCOL *) &mAcpiDeviceNodeTemplate
303 );
304 if (SioDevice->DevicePath == NULL) {
305 Status = EFI_OUT_OF_RESOURCES;
306 goto Done;
307 }
308
309 CopyMem (&SioDevice->Sio, &mSioInterface, sizeof (EFI_SIO_PROTOCOL));
310 SioDevice->DeviceIndex = DeviceIndex;
311
312 //
313 // Create a child handle and install Device Path and Super I/O protocols
314 //
315 Status = gBS->InstallMultipleProtocolInterfaces (
316 &SioDevice->Handle,
317 &gEfiDevicePathProtocolGuid,
318 SioDevice->DevicePath,
319 &gEfiSioProtocolGuid,
320 &SioDevice->Sio,
321 NULL
322 );
323 if (EFI_ERROR (Status)) {
324 goto Done;
325 }
326
327 Status = gBS->OpenProtocol (
328 Controller,
329 &gEfiPciIoProtocolGuid,
330 (VOID **) &PciIo,
331 This->DriverBindingHandle,
332 SioDevice->Handle,
333 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
334 );
335 if (EFI_ERROR (Status)) {
336 gBS->UninstallMultipleProtocolInterfaces (
337 SioDevice->Handle,
338 &gEfiDevicePathProtocolGuid,
339 SioDevice->DevicePath,
340 &gEfiSioProtocolGuid,
341 &SioDevice->Sio,
342 NULL
343 );
344 }
345
346 Done:
347 if (EFI_ERROR (Status)) {
348 if (SioDevice->DevicePath != NULL) {
349 FreePool (SioDevice->DevicePath);
350 }
351
352 FreePool (SioDevice);
353 }
354
355 return Status;
356 }
357
358 /**
359 Create all the ISA child devices on the ISA bus controller (PCI to ISA
360 bridge).
361
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.
366
367 @retval The number of child device that is successfully created.
368
369 **/
370 UINT32
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
376 )
377 {
378 UINT32 Index;
379 UINT32 ChildDeviceNumber;
380 EFI_STATUS Status;
381
382 ChildDeviceNumber = 0;
383
384 for (Index = 0; Index < ARRAY_SIZE (mDevicesInfo); Index++) {
385 Status = SioCreateChildDevice (
386 This,
387 Controller,
388 PciIo,
389 ParentDevicePath,
390 Index
391 );
392 if (!EFI_ERROR (Status)) {
393 ChildDeviceNumber++;
394 }
395 }
396
397 return ChildDeviceNumber;
398 }