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