TianoCore EDK2 master
Loading...
Searching...
No Matches
SioService.c
Go to the documentation of this file.
1
11#include "SioBusDxe.h"
12
13//
14// Super I/O Protocol interfaces
15//
16EFI_SIO_PROTOCOL mSioInterface = {
22};
23
24//
25// COM 1 UART Controller
26//
28SIO_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//
39SIO_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//
50SIO_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//
61SIO_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//
83ACPI_HID_DEVICE_PATH mAcpiDeviceNodeTemplate = {
84 { // Header
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
130EFIAPI
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
162EFIAPI
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
195EFIAPI
198 IN ACPI_RESOURCE_HEADER_PTR ResourceList
199 )
200{
201 return EFI_SUCCESS;
202}
203
218EFIAPI
221 OUT ACPI_RESOURCE_HEADER_PTR *ResourceCollection
222 )
223{
224 return EFI_SUCCESS;
225}
226
253EFIAPI
257 IN UINTN NumberOfCommands
258 )
259{
260 return EFI_SUCCESS;
261}
262
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
351Done:
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
375UINT32
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}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define ACPI_DEVICE_PATH
Definition: DevicePath.h:190
#define ACPI_DP
Definition: DevicePath.h:195
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
UINT32 SioCreateAllChildDevices(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath)
Definition: SioService.c:376
EFI_STATUS EFIAPI SioGetResources(IN CONST EFI_SIO_PROTOCOL *This, OUT ACPI_RESOURCE_HEADER_PTR *ResourceList)
Definition: SioService.c:163
EFI_STATUS EFIAPI SioPossibleResources(IN CONST EFI_SIO_PROTOCOL *This, OUT ACPI_RESOURCE_HEADER_PTR *ResourceCollection)
Definition: SioService.c:219
EFI_STATUS EFIAPI SioRegisterAccess(IN CONST EFI_SIO_PROTOCOL *This, IN BOOLEAN Write, IN BOOLEAN ExitCfgMode, IN UINT8 Register, IN OUT UINT8 *Value)
Definition: SioService.c:131
EFI_STATUS EFIAPI SioSetResources(IN CONST EFI_SIO_PROTOCOL *This, IN ACPI_RESOURCE_HEADER_PTR ResourceList)
Definition: SioService.c:196
EFI_STATUS EFIAPI SioModify(IN CONST EFI_SIO_PROTOCOL *This, IN CONST EFI_SIO_REGISTER_MODIFY *Command, IN UINTN NumberOfCommands)
Definition: SioService.c:254
EFI_STATUS SioCreateChildDevice(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath, IN UINT32 DeviceIndex)
Definition: SioService.c:277
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS