2 Collect Sio information from Native EFI Drivers.
3 Sio is floppy, parallel, serial, ... hardware
5 Copyright (c) 2006 - 2016, 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 through ISA IO interface.
24 @param SioPtr Pointer to SIO data.
26 @retval EFI_SUCCESS When SIO data is got successfully.
27 @retval EFI_NOT_FOUND When ISA IO interface is absent.
31 LegacyBiosBuildSioDataFromIsaIo (
32 IN DEVICE_PRODUCER_DATA_HEADER
*SioPtr
36 DEVICE_PRODUCER_SERIAL
*SioSerial
;
37 DEVICE_PRODUCER_PARALLEL
*SioParallel
;
38 DEVICE_PRODUCER_FLOPPY
*SioFloppy
;
40 EFI_HANDLE
*HandleBuffer
;
44 EFI_ISA_IO_PROTOCOL
*IsaIo
;
45 EFI_ISA_ACPI_RESOURCE_LIST
*ResourceList
;
46 EFI_ISA_ACPI_RESOURCE
*IoResource
;
47 EFI_ISA_ACPI_RESOURCE
*DmaResource
;
48 EFI_ISA_ACPI_RESOURCE
*InterruptResource
;
50 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
51 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
52 EFI_SERIAL_IO_PROTOCOL
*SerialIo
;
55 // Get the list of ISA controllers in the system
57 Status
= gBS
->LocateHandleBuffer (
59 &gEfiIsaIoProtocolGuid
,
64 if (EFI_ERROR (Status
)) {
68 // Collect legacy information from each of the ISA controllers in the system
70 for (Index
= 0; Index
< HandleCount
; Index
++) {
72 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], &gEfiIsaIoProtocolGuid
, (VOID
**) &IsaIo
);
73 if (EFI_ERROR (Status
)) {
77 ResourceList
= IsaIo
->ResourceList
;
79 if (ResourceList
== NULL
) {
83 // Collect the resource types neededto fill in the SIO data structure
87 InterruptResource
= NULL
;
88 for (ResourceIndex
= 0;
89 ResourceList
->ResourceItem
[ResourceIndex
].Type
!= EfiIsaAcpiResourceEndOfList
;
92 switch (ResourceList
->ResourceItem
[ResourceIndex
].Type
) {
93 case EfiIsaAcpiResourceIo
:
94 IoResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
97 case EfiIsaAcpiResourceMemory
:
100 case EfiIsaAcpiResourceDma
:
101 DmaResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
104 case EfiIsaAcpiResourceInterrupt
:
105 InterruptResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
113 // See if this is an ISA serial port
115 // Ignore DMA resource since it is always returned NULL
117 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x500) || ResourceList
->Device
.HID
== EISA_PNP_ID (0x501)) {
119 if (ResourceList
->Device
.UID
<= 3 &&
120 IoResource
!= NULL
&&
121 InterruptResource
!= NULL
124 // Get the handle of the child device that has opened the ISA I/O Protocol
126 Status
= gBS
->OpenProtocolInformation (
128 &gEfiIsaIoProtocolGuid
,
132 if (EFI_ERROR (Status
)) {
136 // We want resource for legacy even if no 32-bit driver installed
138 for (ChildIndex
= 0; ChildIndex
< EntryCount
; ChildIndex
++) {
139 if ((OpenInfoBuffer
[ChildIndex
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
140 Status
= gBS
->HandleProtocol (OpenInfoBuffer
[ChildIndex
].AgentHandle
, &gEfiSerialIoProtocolGuid
, (VOID
**) &SerialIo
);
141 if (!EFI_ERROR (Status
)) {
142 SioSerial
= &SioPtr
->Serial
[ResourceList
->Device
.UID
];
143 SioSerial
->Address
= (UINT16
) IoResource
->StartRange
;
144 SioSerial
->Irq
= (UINT8
) InterruptResource
->StartRange
;
145 SioSerial
->Mode
= DEVICE_SERIAL_MODE_NORMAL
| DEVICE_SERIAL_MODE_DUPLEX_HALF
;
151 FreePool (OpenInfoBuffer
);
155 // See if this is an ISA parallel port
157 // Ignore DMA resource since it is always returned NULL, port
158 // only used in output mode.
160 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x400) || ResourceList
->Device
.HID
== EISA_PNP_ID (0x401)) {
161 if (ResourceList
->Device
.UID
<= 2 &&
162 IoResource
!= NULL
&&
163 InterruptResource
!= NULL
&&
166 SioParallel
= &SioPtr
->Parallel
[ResourceList
->Device
.UID
];
167 SioParallel
->Address
= (UINT16
) IoResource
->StartRange
;
168 SioParallel
->Irq
= (UINT8
) InterruptResource
->StartRange
;
169 SioParallel
->Dma
= (UINT8
) DmaResource
->StartRange
;
170 SioParallel
->Mode
= DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY
;
174 // See if this is an ISA floppy controller
176 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x604)) {
177 if (IoResource
!= NULL
&& InterruptResource
!= NULL
&& DmaResource
!= NULL
) {
178 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], &gEfiBlockIoProtocolGuid
, (VOID
**) &BlockIo
);
179 if (!EFI_ERROR (Status
)) {
180 SioFloppy
= &SioPtr
->Floppy
;
181 SioFloppy
->Address
= (UINT16
) IoResource
->StartRange
;
182 SioFloppy
->Irq
= (UINT8
) InterruptResource
->StartRange
;
183 SioFloppy
->Dma
= (UINT8
) DmaResource
->StartRange
;
184 SioFloppy
->NumberOfFloppy
++;
189 // See if this is a mouse
190 // Always set mouse found so USB hot plug will work
192 // Ignore lower byte of HID. Pnp0fxx is any type of mouse.
194 // Hid = ResourceList->Device.HID & 0xff00ffff;
195 // PnpId = EISA_PNP_ID(0x0f00);
196 // if (Hid == PnpId) {
197 // if (ResourceList->Device.UID == 1) {
198 // Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiSimplePointerProtocolGuid, &SimplePointer);
199 // if (!EFI_ERROR (Status)) {
201 SioPtr
->MousePresent
= 0x01;
209 FreePool (HandleBuffer
);
214 Collect EFI Info about legacy devices.
216 @param Private Legacy BIOS Instance data
218 @retval EFI_SUCCESS It should always work.
222 LegacyBiosBuildSioData (
223 IN LEGACY_BIOS_INSTANCE
*Private
227 DEVICE_PRODUCER_DATA_HEADER
*SioPtr
;
228 EFI_HANDLE IsaBusController
;
230 EFI_HANDLE
*HandleBuffer
;
233 // Get the pointer to the SIO data structure
235 SioPtr
= &Private
->IntThunk
->EfiToLegacy16BootTable
.SioData
;
238 // Zero the data in the SIO data structure
240 gBS
->SetMem (SioPtr
, sizeof (DEVICE_PRODUCER_DATA_HEADER
), 0);
243 // Find the ISA Bus Controller used for legacy
245 Status
= Private
->LegacyBiosPlatform
->GetPlatformHandle (
246 Private
->LegacyBiosPlatform
,
247 EfiGetPlatformIsaBusHandle
,
253 IsaBusController
= HandleBuffer
[0];
254 if (!EFI_ERROR (Status
)) {
256 // Force ISA Bus Controller to produce all ISA devices
258 gBS
->ConnectController (IsaBusController
, NULL
, NULL
, TRUE
);
261 LegacyBiosBuildSioDataFromIsaIo (SioPtr
);