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
*Sio1Ptr
;
37 DEVICE_PRODUCER_PARALLEL
*Sio2Ptr
;
38 DEVICE_PRODUCER_FLOPPY
*Sio3Ptr
;
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
;
56 // Get the list of ISA controllers in the system
58 Status
= gBS
->LocateHandleBuffer (
60 &gEfiIsaIoProtocolGuid
,
65 if (EFI_ERROR (Status
)) {
69 // Collect legacy information from each of the ISA controllers in the system
71 for (Index
= 0; Index
< HandleCount
; Index
++) {
73 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], &gEfiIsaIoProtocolGuid
, (VOID
**) &IsaIo
);
74 if (EFI_ERROR (Status
)) {
78 ResourceList
= IsaIo
->ResourceList
;
80 if (ResourceList
== NULL
) {
84 // Collect the resource types neededto fill in the SIO data structure
88 InterruptResource
= NULL
;
89 for (ResourceIndex
= 0;
90 ResourceList
->ResourceItem
[ResourceIndex
].Type
!= EfiIsaAcpiResourceEndOfList
;
93 switch (ResourceList
->ResourceItem
[ResourceIndex
].Type
) {
94 case EfiIsaAcpiResourceIo
:
95 IoResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
98 case EfiIsaAcpiResourceMemory
:
101 case EfiIsaAcpiResourceDma
:
102 DmaResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
105 case EfiIsaAcpiResourceInterrupt
:
106 InterruptResource
= &ResourceList
->ResourceItem
[ResourceIndex
];
114 // See if this is an ISA serial port
116 // Ignore DMA resource since it is always returned NULL
118 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x500) || ResourceList
->Device
.HID
== EISA_PNP_ID (0x501)) {
120 if (ResourceList
->Device
.UID
<= 3 &&
121 IoResource
!= NULL
&&
122 InterruptResource
!= NULL
125 // Get the handle of the child device that has opened the ISA I/O Protocol
127 Status
= gBS
->OpenProtocolInformation (
129 &gEfiIsaIoProtocolGuid
,
133 if (EFI_ERROR (Status
)) {
137 // We want resource for legacy even if no 32-bit driver installed
139 for (ChildIndex
= 0; ChildIndex
< EntryCount
; ChildIndex
++) {
140 Sio1Ptr
= &SioPtr
->Serial
[ResourceList
->Device
.UID
];
141 Sio1Ptr
->Address
= (UINT16
) IoResource
->StartRange
;
142 Sio1Ptr
->Irq
= (UINT8
) InterruptResource
->StartRange
;
143 Sio1Ptr
->Mode
= DEVICE_SERIAL_MODE_NORMAL
| DEVICE_SERIAL_MODE_DUPLEX_HALF
;
146 FreePool (OpenInfoBuffer
);
150 // See if this is an ISA parallel port
152 // Ignore DMA resource since it is always returned NULL, port
153 // only used in output mode.
155 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x400) || ResourceList
->Device
.HID
== EISA_PNP_ID (0x401)) {
156 if (ResourceList
->Device
.UID
<= 2 &&
157 IoResource
!= NULL
&&
158 InterruptResource
!= NULL
&&
161 Sio2Ptr
= &SioPtr
->Parallel
[ResourceList
->Device
.UID
];
162 Sio2Ptr
->Address
= (UINT16
) IoResource
->StartRange
;
163 Sio2Ptr
->Irq
= (UINT8
) InterruptResource
->StartRange
;
164 Sio2Ptr
->Dma
= (UINT8
) DmaResource
->StartRange
;
165 Sio2Ptr
->Mode
= DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY
;
169 // See if this is an ISA floppy controller
171 if (ResourceList
->Device
.HID
== EISA_PNP_ID (0x604)) {
172 if (IoResource
!= NULL
&& InterruptResource
!= NULL
&& DmaResource
!= NULL
) {
173 Status
= gBS
->HandleProtocol (HandleBuffer
[Index
], &gEfiBlockIoProtocolGuid
, (VOID
**) &BlockIo
);
174 if (!EFI_ERROR (Status
)) {
175 Sio3Ptr
= &SioPtr
->Floppy
;
176 Sio3Ptr
->Address
= (UINT16
) IoResource
->StartRange
;
177 Sio3Ptr
->Irq
= (UINT8
) InterruptResource
->StartRange
;
178 Sio3Ptr
->Dma
= (UINT8
) DmaResource
->StartRange
;
179 Sio3Ptr
->NumberOfFloppy
++;
184 // See if this is a mouse
185 // Always set mouse found so USB hot plug will work
187 // Ignore lower byte of HID. Pnp0fxx is any type of mouse.
189 // Hid = ResourceList->Device.HID & 0xff00ffff;
190 // PnpId = EISA_PNP_ID(0x0f00);
191 // if (Hid == PnpId) {
192 // if (ResourceList->Device.UID == 1) {
193 // Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiSimplePointerProtocolGuid, &SimplePointer);
194 // if (!EFI_ERROR (Status)) {
196 SioPtr
->MousePresent
= 0x01;
204 FreePool (HandleBuffer
);
209 Collect EFI Info about legacy devices.
211 @param Private Legacy BIOS Instance data
213 @retval EFI_SUCCESS It should always work.
217 LegacyBiosBuildSioData (
218 IN LEGACY_BIOS_INSTANCE
*Private
222 DEVICE_PRODUCER_DATA_HEADER
*SioPtr
;
223 EFI_HANDLE IsaBusController
;
225 EFI_HANDLE
*HandleBuffer
;
228 // Get the pointer to the SIO data structure
230 SioPtr
= &Private
->IntThunk
->EfiToLegacy16BootTable
.SioData
;
233 // Zero the data in the SIO data structure
235 gBS
->SetMem (SioPtr
, sizeof (DEVICE_PRODUCER_DATA_HEADER
), 0);
238 // Find the ISA Bus Controller used for legacy
240 Status
= Private
->LegacyBiosPlatform
->GetPlatformHandle (
241 Private
->LegacyBiosPlatform
,
242 EfiGetPlatformIsaBusHandle
,
248 IsaBusController
= HandleBuffer
[0];
249 if (!EFI_ERROR (Status
)) {
251 // Force ISA Bus Controller to produce all ISA devices
253 gBS
->ConnectController (IsaBusController
, NULL
, NULL
, TRUE
);
256 LegacyBiosBuildSioDataFromIsaIo (SioPtr
);