2 Collect Sio information from Native EFI Drivers.
3 Sio is floppy, parallel, serial, ... hardware
5 Copyright (c) 2006 - 2010, 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 "LegacyBiosInterface.h"
22 Collect EFI Info about legacy devices.
24 @param Private Legacy BIOS Instance data
26 @retval EFI_SUCCESS It should always work.
30 LegacyBiosBuildSioData (
31 IN LEGACY_BIOS_INSTANCE
*Private
35 DEVICE_PRODUCER_DATA_HEADER
*SioPtr
;
36 DEVICE_PRODUCER_SERIAL
*Sio1Ptr
;
37 DEVICE_PRODUCER_PARALLEL
*Sio2Ptr
;
38 DEVICE_PRODUCER_FLOPPY
*Sio3Ptr
;
39 EFI_HANDLE IsaBusController
;
41 EFI_HANDLE
*HandleBuffer
;
45 EFI_ISA_IO_PROTOCOL
*IsaIo
;
46 EFI_ISA_ACPI_RESOURCE_LIST
*ResourceList
;
47 EFI_ISA_ACPI_RESOURCE
*IoResource
;
48 EFI_ISA_ACPI_RESOURCE
*DmaResource
;
49 EFI_ISA_ACPI_RESOURCE
*InterruptResource
;
51 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
52 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
55 // Get the pointer to the SIO data structure
57 SioPtr
= &Private
->IntThunk
->EfiToLegacy16BootTable
.SioData
;
60 // Zero the data in the SIO data structure
62 gBS
->SetMem (SioPtr
, sizeof (DEVICE_PRODUCER_DATA_HEADER
), 0);
65 // Find the ISA Bus Controller used for legacy
67 Status
= Private
->LegacyBiosPlatform
->GetPlatformHandle (
68 Private
->LegacyBiosPlatform
,
69 EfiGetPlatformIsaBusHandle
,
75 IsaBusController
= HandleBuffer
[0];
76 if (!EFI_ERROR (Status
)) {
78 // Force ISA Bus Controller to produce all ISA devices
80 gBS
->ConnectController (IsaBusController
, NULL
, NULL
, TRUE
);
83 // Get the list of ISA controllers in the system
85 Status
= gBS
->LocateHandleBuffer (
87 &gEfiIsaIoProtocolGuid
,
92 if (EFI_ERROR (Status
)) {
96 // Collect legacy information from each of the ISA controllers in the system
98 for (Index
= 0; Index
< HandleCount
; Index
++) {
100 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], &gEfiIsaIoProtocolGuid
, (VOID
**) &IsaIo
);
101 if (EFI_ERROR (Status
)) {
105 ResourceList
= IsaIo
->ResourceList
;
107 if (ResourceList
== NULL
) {
111 // Collect the resource types neededto fill in the SIO data structure
115 InterruptResource
= NULL
;
116 for (ResourceIndex
= 0;
117 ResourceList
->ResourceItem
[ResourceIndex
].Type
!= EfiIsaAcpiResourceEndOfList
;
120 switch (ResourceList
->ResourceItem
[ResourceIndex
].Type
) {
121 case EfiIsaAcpiResourceIo
:
122 IoResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
125 case EfiIsaAcpiResourceMemory
:
128 case EfiIsaAcpiResourceDma
:
129 DmaResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
132 case EfiIsaAcpiResourceInterrupt
:
133 InterruptResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
141 // See if this is an ISA serial port
143 // Ignore DMA resource since it is always returned NULL
145 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x500) || ResourceList
->Device
.HID
== EISA_PNP_ID (0x501)) {
147 if (ResourceList
->Device
.UID
<= 3 &&
148 IoResource
!= NULL
&&
149 InterruptResource
!= NULL
152 // Get the handle of the child device that has opened the ISA I/O Protocol
154 Status
= gBS
->OpenProtocolInformation (
156 &gEfiIsaIoProtocolGuid
,
160 if (EFI_ERROR (Status
)) {
164 // We want resource for legacy even if no 32-bit driver installed
166 for (ChildIndex
= 0; ChildIndex
< EntryCount
; ChildIndex
++) {
167 Sio1Ptr
= &SioPtr
->Serial
[ResourceList
->Device
.UID
];
168 Sio1Ptr
->Address
= (UINT16
) IoResource
->StartRange
;
169 Sio1Ptr
->Irq
= (UINT8
) InterruptResource
->StartRange
;
170 Sio1Ptr
->Mode
= DEVICE_SERIAL_MODE_NORMAL
| DEVICE_SERIAL_MODE_DUPLEX_HALF
;
173 FreePool (OpenInfoBuffer
);
177 // See if this is an ISA parallel port
179 // Ignore DMA resource since it is always returned NULL, port
180 // only used in output mode.
182 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x400) || ResourceList
->Device
.HID
== EISA_PNP_ID (0x401)) {
183 if (ResourceList
->Device
.UID
<= 2 &&
184 IoResource
!= NULL
&&
185 InterruptResource
!= NULL
&&
188 Sio2Ptr
= &SioPtr
->Parallel
[ResourceList
->Device
.UID
];
189 Sio2Ptr
->Address
= (UINT16
) IoResource
->StartRange
;
190 Sio2Ptr
->Irq
= (UINT8
) InterruptResource
->StartRange
;
191 Sio2Ptr
->Dma
= (UINT8
) DmaResource
->StartRange
;
192 Sio2Ptr
->Mode
= DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY
;
196 // See if this is an ISA floppy controller
198 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x604)) {
199 if (IoResource
!= NULL
&& InterruptResource
!= NULL
&& DmaResource
!= NULL
) {
200 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], &gEfiBlockIoProtocolGuid
, (VOID
**) &BlockIo
);
201 if (!EFI_ERROR (Status
)) {
202 Sio3Ptr
= &SioPtr
->Floppy
;
203 Sio3Ptr
->Address
= (UINT16
) IoResource
->StartRange
;
204 Sio3Ptr
->Irq
= (UINT8
) InterruptResource
->StartRange
;
205 Sio3Ptr
->Dma
= (UINT8
) DmaResource
->StartRange
;
206 Sio3Ptr
->NumberOfFloppy
++;
211 // See if this is a mouse
212 // Always set mouse found so USB hot plug will work
214 // Ignore lower byte of HID. Pnp0fxx is any type of mouse.
216 // Hid = ResourceList->Device.HID & 0xff00ffff;
217 // PnpId = EISA_PNP_ID(0x0f00);
218 // if (Hid == PnpId) {
219 // if (ResourceList->Device.UID == 1) {
220 // Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiSimplePointerProtocolGuid, &SimplePointer);
221 // if (!EFI_ERROR (Status)) {
223 SioPtr
->MousePresent
= 0x01;
231 FreePool (HandleBuffer
);