]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Csm/LegacyBiosDxe/LegacySio.c
IntelFrameworkModulePkg/LegacyBios: Get SIO data in separate function
[mirror_edk2.git] / IntelFrameworkModulePkg / Csm / LegacyBiosDxe / LegacySio.c
CommitLineData
bcecde14 1/** @file\r
2 Collect Sio information from Native EFI Drivers.\r
3 Sio is floppy, parallel, serial, ... hardware\r
4\r
26a7ece7 5Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
bcecde14 6\r
7This program and the accompanying materials\r
8are licensed and made available under the terms and conditions\r
9of the BSD License which accompanies this distribution. The\r
10full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php\r
12\r
13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15\r
16**/\r
17\r
18#include "LegacyBiosInterface.h"\r
19\r
20\r
21/**\r
26a7ece7 22 Collect EFI Info about legacy devices through ISA IO interface.\r
bcecde14 23\r
26a7ece7 24 @param SioPtr Pointer to SIO data.\r
bcecde14 25\r
26 @retval EFI_SUCCESS It should always work.\r
27\r
28**/\r
29EFI_STATUS\r
26a7ece7
RN
30LegacyBiosBuildSioDataFromIsaIo (\r
31 IN DEVICE_PRODUCER_DATA_HEADER *SioPtr\r
bcecde14 32 )\r
33{\r
34 EFI_STATUS Status;\r
bcecde14 35 DEVICE_PRODUCER_SERIAL *Sio1Ptr;\r
36 DEVICE_PRODUCER_PARALLEL *Sio2Ptr;\r
37 DEVICE_PRODUCER_FLOPPY *Sio3Ptr;\r
bcecde14 38 UINTN HandleCount;\r
39 EFI_HANDLE *HandleBuffer;\r
40 UINTN Index;\r
41 UINTN ResourceIndex;\r
42 UINTN ChildIndex;\r
43 EFI_ISA_IO_PROTOCOL *IsaIo;\r
44 EFI_ISA_ACPI_RESOURCE_LIST *ResourceList;\r
45 EFI_ISA_ACPI_RESOURCE *IoResource;\r
46 EFI_ISA_ACPI_RESOURCE *DmaResource;\r
47 EFI_ISA_ACPI_RESOURCE *InterruptResource;\r
48 UINTN EntryCount;\r
49 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
50 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
51\r
bcecde14 52\r
bcecde14 53\r
bcecde14 54 //\r
55 // Get the list of ISA controllers in the system\r
56 //\r
57 Status = gBS->LocateHandleBuffer (\r
58 ByProtocol,\r
59 &gEfiIsaIoProtocolGuid,\r
60 NULL,\r
61 &HandleCount,\r
62 &HandleBuffer\r
63 );\r
64 if (EFI_ERROR (Status)) {\r
65 return EFI_SUCCESS;\r
66 }\r
67 //\r
68 // Collect legacy information from each of the ISA controllers in the system\r
69 //\r
70 for (Index = 0; Index < HandleCount; Index++) {\r
71\r
72 Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiIsaIoProtocolGuid, (VOID **) &IsaIo);\r
73 if (EFI_ERROR (Status)) {\r
74 continue;\r
75 }\r
76\r
77 ResourceList = IsaIo->ResourceList;\r
78\r
79 if (ResourceList == NULL) {\r
80 continue;\r
81 }\r
82 //\r
83 // Collect the resource types neededto fill in the SIO data structure\r
84 //\r
85 IoResource = NULL;\r
86 DmaResource = NULL;\r
87 InterruptResource = NULL;\r
88 for (ResourceIndex = 0;\r
89 ResourceList->ResourceItem[ResourceIndex].Type != EfiIsaAcpiResourceEndOfList;\r
90 ResourceIndex++\r
91 ) {\r
92 switch (ResourceList->ResourceItem[ResourceIndex].Type) {\r
93 case EfiIsaAcpiResourceIo:\r
94 IoResource = &ResourceList->ResourceItem[ResourceIndex];\r
95 break;\r
96\r
97 case EfiIsaAcpiResourceMemory:\r
98 break;\r
99\r
100 case EfiIsaAcpiResourceDma:\r
101 DmaResource = &ResourceList->ResourceItem[ResourceIndex];\r
102 break;\r
103\r
104 case EfiIsaAcpiResourceInterrupt:\r
105 InterruptResource = &ResourceList->ResourceItem[ResourceIndex];\r
106 break;\r
107\r
108 default:\r
109 break;\r
110 }\r
111 }\r
112 //\r
113 // See if this is an ISA serial port\r
114 //\r
115 // Ignore DMA resource since it is always returned NULL\r
116 //\r
117 if (ResourceList->Device.HID == EISA_PNP_ID (0x500) || ResourceList->Device.HID == EISA_PNP_ID (0x501)) {\r
118\r
119 if (ResourceList->Device.UID <= 3 &&\r
120 IoResource != NULL &&\r
121 InterruptResource != NULL\r
122 ) {\r
123 //\r
124 // Get the handle of the child device that has opened the ISA I/O Protocol\r
125 //\r
126 Status = gBS->OpenProtocolInformation (\r
127 HandleBuffer[Index],\r
128 &gEfiIsaIoProtocolGuid,\r
129 &OpenInfoBuffer,\r
130 &EntryCount\r
131 );\r
132 if (EFI_ERROR (Status)) {\r
133 continue;\r
134 }\r
135 //\r
136 // We want resource for legacy even if no 32-bit driver installed\r
137 //\r
138 for (ChildIndex = 0; ChildIndex < EntryCount; ChildIndex++) {\r
139 Sio1Ptr = &SioPtr->Serial[ResourceList->Device.UID];\r
140 Sio1Ptr->Address = (UINT16) IoResource->StartRange;\r
141 Sio1Ptr->Irq = (UINT8) InterruptResource->StartRange;\r
142 Sio1Ptr->Mode = DEVICE_SERIAL_MODE_NORMAL | DEVICE_SERIAL_MODE_DUPLEX_HALF;\r
143 }\r
144\r
145 FreePool (OpenInfoBuffer);\r
146 }\r
147 }\r
148 //\r
149 // See if this is an ISA parallel port\r
150 //\r
151 // Ignore DMA resource since it is always returned NULL, port\r
152 // only used in output mode.\r
153 //\r
154 if (ResourceList->Device.HID == EISA_PNP_ID (0x400) || ResourceList->Device.HID == EISA_PNP_ID (0x401)) {\r
155 if (ResourceList->Device.UID <= 2 &&\r
156 IoResource != NULL &&\r
157 InterruptResource != NULL &&\r
158 DmaResource != NULL\r
159 ) {\r
160 Sio2Ptr = &SioPtr->Parallel[ResourceList->Device.UID];\r
161 Sio2Ptr->Address = (UINT16) IoResource->StartRange;\r
162 Sio2Ptr->Irq = (UINT8) InterruptResource->StartRange;\r
163 Sio2Ptr->Dma = (UINT8) DmaResource->StartRange;\r
164 Sio2Ptr->Mode = DEVICE_PARALLEL_MODE_MODE_OUTPUT_ONLY;\r
165 }\r
166 }\r
167 //\r
168 // See if this is an ISA floppy controller\r
169 //\r
170 if (ResourceList->Device.HID == EISA_PNP_ID (0x604)) {\r
171 if (IoResource != NULL && InterruptResource != NULL && DmaResource != NULL) {\r
172 Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo);\r
173 if (!EFI_ERROR (Status)) {\r
174 Sio3Ptr = &SioPtr->Floppy;\r
175 Sio3Ptr->Address = (UINT16) IoResource->StartRange;\r
176 Sio3Ptr->Irq = (UINT8) InterruptResource->StartRange;\r
177 Sio3Ptr->Dma = (UINT8) DmaResource->StartRange;\r
178 Sio3Ptr->NumberOfFloppy++;\r
179 }\r
180 }\r
181 }\r
182 //\r
183 // See if this is a mouse\r
184 // Always set mouse found so USB hot plug will work\r
185 //\r
186 // Ignore lower byte of HID. Pnp0fxx is any type of mouse.\r
187 //\r
188 // Hid = ResourceList->Device.HID & 0xff00ffff;\r
189 // PnpId = EISA_PNP_ID(0x0f00);\r
190 // if (Hid == PnpId) {\r
191 // if (ResourceList->Device.UID == 1) {\r
192 // Status = gBS->HandleProtocol (HandleBuffer[Index], &gEfiSimplePointerProtocolGuid, &SimplePointer);\r
193 // if (!EFI_ERROR (Status)) {\r
194 //\r
195 SioPtr->MousePresent = 0x01;\r
196 //\r
197 // }\r
198 // }\r
199 // }\r
200 //\r
201 }\r
202\r
203 FreePool (HandleBuffer);\r
26a7ece7
RN
204 return EFI_SUCCESS;\r
205}\r
206\r
207/**\r
208 Collect EFI Info about legacy devices.\r
209\r
210 @param Private Legacy BIOS Instance data\r
211\r
212 @retval EFI_SUCCESS It should always work.\r
213\r
214**/\r
215EFI_STATUS\r
216LegacyBiosBuildSioData (\r
217 IN LEGACY_BIOS_INSTANCE *Private\r
218 )\r
219{\r
220 EFI_STATUS Status;\r
221 DEVICE_PRODUCER_DATA_HEADER *SioPtr;\r
222 EFI_HANDLE IsaBusController;\r
223 UINTN HandleCount;\r
224 EFI_HANDLE *HandleBuffer;\r
225\r
226 //\r
227 // Get the pointer to the SIO data structure\r
228 //\r
229 SioPtr = &Private->IntThunk->EfiToLegacy16BootTable.SioData;\r
230\r
231 //\r
232 // Zero the data in the SIO data structure\r
233 //\r
234 gBS->SetMem (SioPtr, sizeof (DEVICE_PRODUCER_DATA_HEADER), 0);\r
235\r
236 //\r
237 // Find the ISA Bus Controller used for legacy\r
238 //\r
239 Status = Private->LegacyBiosPlatform->GetPlatformHandle (\r
240 Private->LegacyBiosPlatform,\r
241 EfiGetPlatformIsaBusHandle,\r
242 0,\r
243 &HandleBuffer,\r
244 &HandleCount,\r
245 NULL\r
246 );\r
247 IsaBusController = HandleBuffer[0];\r
248 if (!EFI_ERROR (Status)) {\r
249 //\r
250 // Force ISA Bus Controller to produce all ISA devices\r
251 //\r
252 gBS->ConnectController (IsaBusController, NULL, NULL, TRUE);\r
253 }\r
254\r
255 LegacyBiosBuildSioDataFromIsaIo (SioPtr);\r
bcecde14 256\r
257 return EFI_SUCCESS;\r
258}\r