]>
Commit | Line | Data |
---|---|---|
9595e3cd LE |
1 | /** @file\r |
2 | Provides the basic interfaces to abstract a PCI Host Bridge Resource Allocation\r | |
3 | \r | |
4 | Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials are\r | |
6 | licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
d1c561f9 | 13 | **/\r |
9595e3cd LE |
14 | \r |
15 | #include "PciHostBridge.h"\r | |
16 | \r | |
17 | //\r | |
18 | // Hard code: Root Bridge Number within the host bridge\r | |
19 | // Root Bridge's attribute\r | |
20 | // Root Bridge's device path\r | |
21 | // Root Bridge's resource aperture\r | |
22 | //\r | |
23 | UINTN RootBridgeNumber[1] = { 1 };\r | |
24 | \r | |
25 | UINT64 RootBridgeAttribute[1][1] = { { EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM } };\r | |
26 | \r | |
27 | EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath[1][1] = {\r | |
28 | {\r | |
29 | {\r | |
30 | {\r | |
31 | {\r | |
32 | ACPI_DEVICE_PATH,\r | |
33 | ACPI_DP,\r | |
34 | {\r | |
35 | (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),\r | |
36 | (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)\r | |
37 | }\r | |
38 | },\r | |
39 | EISA_PNP_ID(0x0A03),\r | |
40 | 0\r | |
41 | },\r | |
d1c561f9 | 42 | \r |
9595e3cd LE |
43 | {\r |
44 | END_DEVICE_PATH_TYPE,\r | |
45 | END_ENTIRE_DEVICE_PATH_SUBTYPE,\r | |
46 | {\r | |
47 | END_DEVICE_PATH_LENGTH,\r | |
48 | 0\r | |
49 | }\r | |
50 | }\r | |
51 | }\r | |
52 | }\r | |
53 | };\r | |
54 | \r | |
aca7e8b6 | 55 | STATIC PCI_ROOT_BRIDGE_RESOURCE_APERTURE mResAperture[1][1];\r |
9595e3cd LE |
56 | \r |
57 | EFI_HANDLE mDriverImageHandle;\r | |
58 | \r | |
59 | PCI_HOST_BRIDGE_INSTANCE mPciHostBridgeInstanceTemplate = {\r | |
60 | PCI_HOST_BRIDGE_SIGNATURE, // Signature\r | |
61 | NULL, // HostBridgeHandle\r | |
62 | 0, // RootBridgeNumber\r | |
63 | {NULL, NULL}, // Head\r | |
64 | FALSE, // ResourceSubiteed\r | |
65 | TRUE, // CanRestarted\r | |
66 | {\r | |
67 | NotifyPhase,\r | |
68 | GetNextRootBridge,\r | |
69 | GetAttributes,\r | |
70 | StartBusEnumeration,\r | |
71 | SetBusNumbers,\r | |
72 | SubmitResources,\r | |
73 | GetProposedResources,\r | |
74 | PreprocessController\r | |
75 | }\r | |
76 | };\r | |
77 | \r | |
78 | //\r | |
79 | // Implementation\r | |
80 | //\r | |
81 | \r | |
cd2178bb AB |
82 | STATIC\r |
83 | VOID\r | |
84 | SetLinuxPciProbeOnlyProperty (\r | |
85 | IN FDT_CLIENT_PROTOCOL *FdtClient\r | |
86 | )\r | |
87 | {\r | |
88 | INT32 Node;\r | |
89 | UINT32 Tmp;\r | |
90 | EFI_STATUS Status;\r | |
91 | \r | |
92 | if (!FeaturePcdGet (PcdPureAcpiBoot)) {\r | |
93 | //\r | |
94 | // Set the /chosen/linux,pci-probe-only property to 1, so that the PCI\r | |
95 | // setup we will perform in the firmware is honored by the Linux OS,\r | |
96 | // rather than torn down and done from scratch. This is generally a more\r | |
97 | // sensible approach, and aligns with what ACPI based OSes do typically.\r | |
98 | //\r | |
99 | // In case we are exposing an emulated VGA PCI device to the guest, which\r | |
100 | // may subsequently get exposed via the Graphics Output protocol and\r | |
101 | // driven as an efifb by Linux, we need this setting to prevent the\r | |
102 | // framebuffer from becoming unresponsive.\r | |
103 | //\r | |
104 | Status = FdtClient->GetOrInsertChosenNode (FdtClient, &Node);\r | |
105 | \r | |
106 | if (!EFI_ERROR (Status)) {\r | |
107 | Tmp = SwapBytes32 (1);\r | |
108 | Status = FdtClient->SetNodeProperty (FdtClient, Node,\r | |
109 | "linux,pci-probe-only", &Tmp, sizeof (Tmp));\r | |
110 | }\r | |
111 | if (EFI_ERROR (Status)) {\r | |
112 | DEBUG ((EFI_D_WARN,\r | |
113 | "Failed to set /chosen/linux,pci-probe-only property\n"));\r | |
114 | }\r | |
115 | }\r | |
116 | }\r | |
117 | \r | |
118 | //\r | |
119 | // We expect the "ranges" property of "pci-host-ecam-generic" to consist of\r | |
120 | // records like this.\r | |
121 | //\r | |
122 | #pragma pack (1)\r | |
123 | typedef struct {\r | |
124 | UINT32 Type;\r | |
125 | UINT64 ChildBase;\r | |
126 | UINT64 CpuBase;\r | |
127 | UINT64 Size;\r | |
128 | } DTB_PCI_HOST_RANGE_RECORD;\r | |
129 | #pragma pack ()\r | |
130 | \r | |
131 | #define DTB_PCI_HOST_RANGE_RELOCATABLE BIT31\r | |
132 | #define DTB_PCI_HOST_RANGE_PREFETCHABLE BIT30\r | |
133 | #define DTB_PCI_HOST_RANGE_ALIASED BIT29\r | |
134 | #define DTB_PCI_HOST_RANGE_MMIO32 BIT25\r | |
135 | #define DTB_PCI_HOST_RANGE_MMIO64 (BIT25 | BIT24)\r | |
136 | #define DTB_PCI_HOST_RANGE_IO BIT24\r | |
137 | #define DTB_PCI_HOST_RANGE_TYPEMASK (BIT31 | BIT30 | BIT29 | BIT25 | BIT24)\r | |
138 | \r | |
139 | STATIC\r | |
140 | EFI_STATUS\r | |
141 | ProcessPciHost (\r | |
142 | OUT UINT64 *IoBase,\r | |
143 | OUT UINT64 *IoSize,\r | |
144 | OUT UINT64 *IoTranslation,\r | |
145 | OUT UINT64 *MmioBase,\r | |
146 | OUT UINT64 *MmioSize,\r | |
147 | OUT UINT64 *MmioTranslation,\r | |
148 | OUT UINT32 *BusMin,\r | |
149 | OUT UINT32 *BusMax\r | |
150 | )\r | |
151 | {\r | |
152 | FDT_CLIENT_PROTOCOL *FdtClient;\r | |
153 | INT32 Node;\r | |
154 | UINT64 ConfigBase, ConfigSize;\r | |
155 | CONST VOID *Prop;\r | |
156 | UINT32 Len;\r | |
157 | UINT32 RecordIdx;\r | |
158 | EFI_STATUS Status;\r | |
159 | \r | |
160 | //\r | |
161 | // The following output arguments are initialized only in\r | |
162 | // order to suppress '-Werror=maybe-uninitialized' warnings\r | |
163 | // *incorrectly* emitted by some gcc versions.\r | |
164 | //\r | |
165 | *IoBase = 0;\r | |
166 | *IoTranslation = 0;\r | |
167 | *MmioBase = 0;\r | |
168 | *MmioTranslation = 0;\r | |
169 | *BusMin = 0;\r | |
170 | *BusMax = 0;\r | |
171 | \r | |
172 | //\r | |
173 | // *IoSize and *MmioSize are initialized to zero because the logic below\r | |
174 | // requires it. However, since they are also affected by the issue reported\r | |
175 | // above, they are initialized early.\r | |
176 | //\r | |
177 | *IoSize = 0;\r | |
178 | *MmioSize = 0;\r | |
179 | \r | |
180 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r | |
181 | (VOID **)&FdtClient);\r | |
182 | ASSERT_EFI_ERROR (Status);\r | |
183 | \r | |
184 | Status = FdtClient->FindCompatibleNode (FdtClient, "pci-host-ecam-generic",\r | |
185 | &Node);\r | |
186 | if (EFI_ERROR (Status)) {\r | |
187 | DEBUG ((EFI_D_INFO,\r | |
188 | "%a: No 'pci-host-ecam-generic' compatible DT node found\n",\r | |
189 | __FUNCTION__));\r | |
190 | return EFI_NOT_FOUND;\r | |
191 | }\r | |
192 | \r | |
193 | DEBUG_CODE (\r | |
194 | INT32 Tmp;\r | |
195 | \r | |
196 | //\r | |
197 | // A DT can legally describe multiple PCI host bridges, but we are not\r | |
198 | // equipped to deal with that. So assert that there is only one.\r | |
199 | //\r | |
200 | Status = FdtClient->FindNextCompatibleNode (FdtClient,\r | |
201 | "pci-host-ecam-generic", Node, &Tmp);\r | |
202 | ASSERT (Status == EFI_NOT_FOUND);\r | |
203 | );\r | |
204 | \r | |
205 | Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg", &Prop, &Len);\r | |
206 | if (EFI_ERROR (Status) || Len != 2 * sizeof (UINT64)) {\r | |
207 | DEBUG ((EFI_D_ERROR, "%a: 'reg' property not found or invalid\n",\r | |
208 | __FUNCTION__));\r | |
209 | return EFI_PROTOCOL_ERROR;\r | |
210 | }\r | |
211 | \r | |
212 | //\r | |
213 | // Fetch the ECAM window.\r | |
214 | //\r | |
215 | ConfigBase = SwapBytes64 (((CONST UINT64 *)Prop)[0]);\r | |
216 | ConfigSize = SwapBytes64 (((CONST UINT64 *)Prop)[1]);\r | |
217 | \r | |
218 | //\r | |
219 | // Fetch the bus range (note: inclusive).\r | |
220 | //\r | |
221 | Status = FdtClient->GetNodeProperty (FdtClient, Node, "bus-range", &Prop,\r | |
222 | &Len);\r | |
223 | if (EFI_ERROR (Status) || Len != 2 * sizeof (UINT32)) {\r | |
224 | DEBUG ((EFI_D_ERROR, "%a: 'bus-range' not found or invalid\n",\r | |
225 | __FUNCTION__));\r | |
226 | return EFI_PROTOCOL_ERROR;\r | |
227 | }\r | |
228 | *BusMin = SwapBytes32 (((CONST UINT32 *)Prop)[0]);\r | |
229 | *BusMax = SwapBytes32 (((CONST UINT32 *)Prop)[1]);\r | |
230 | \r | |
231 | //\r | |
232 | // Sanity check: the config space must accommodate all 4K register bytes of\r | |
233 | // all 8 functions of all 32 devices of all buses.\r | |
234 | //\r | |
235 | if (*BusMax < *BusMin || *BusMax - *BusMin == MAX_UINT32 ||\r | |
236 | DivU64x32 (ConfigSize, SIZE_4KB * 8 * 32) < *BusMax - *BusMin + 1) {\r | |
237 | DEBUG ((EFI_D_ERROR, "%a: invalid 'bus-range' and/or 'reg'\n",\r | |
238 | __FUNCTION__));\r | |
239 | return EFI_PROTOCOL_ERROR;\r | |
240 | }\r | |
241 | \r | |
242 | //\r | |
243 | // Iterate over "ranges".\r | |
244 | //\r | |
245 | Status = FdtClient->GetNodeProperty (FdtClient, Node, "ranges", &Prop, &Len);\r | |
246 | if (EFI_ERROR (Status) || Len == 0 ||\r | |
247 | Len % sizeof (DTB_PCI_HOST_RANGE_RECORD) != 0) {\r | |
248 | DEBUG ((EFI_D_ERROR, "%a: 'ranges' not found or invalid\n", __FUNCTION__));\r | |
249 | return EFI_PROTOCOL_ERROR;\r | |
250 | }\r | |
251 | \r | |
252 | for (RecordIdx = 0; RecordIdx < Len / sizeof (DTB_PCI_HOST_RANGE_RECORD);\r | |
253 | ++RecordIdx) {\r | |
254 | CONST DTB_PCI_HOST_RANGE_RECORD *Record;\r | |
255 | \r | |
256 | Record = (CONST DTB_PCI_HOST_RANGE_RECORD *)Prop + RecordIdx;\r | |
257 | switch (SwapBytes32 (Record->Type) & DTB_PCI_HOST_RANGE_TYPEMASK) {\r | |
258 | case DTB_PCI_HOST_RANGE_IO:\r | |
259 | *IoBase = SwapBytes64 (Record->ChildBase);\r | |
260 | *IoSize = SwapBytes64 (Record->Size);\r | |
261 | *IoTranslation = SwapBytes64 (Record->CpuBase) - *IoBase;\r | |
262 | break;\r | |
263 | \r | |
264 | case DTB_PCI_HOST_RANGE_MMIO32:\r | |
265 | *MmioBase = SwapBytes64 (Record->ChildBase);\r | |
266 | *MmioSize = SwapBytes64 (Record->Size);\r | |
267 | *MmioTranslation = SwapBytes64 (Record->CpuBase) - *MmioBase;\r | |
268 | \r | |
269 | if (*MmioBase > MAX_UINT32 || *MmioSize > MAX_UINT32 ||\r | |
270 | *MmioBase + *MmioSize > SIZE_4GB) {\r | |
271 | DEBUG ((EFI_D_ERROR, "%a: MMIO32 space invalid\n", __FUNCTION__));\r | |
272 | return EFI_PROTOCOL_ERROR;\r | |
273 | }\r | |
274 | \r | |
275 | if (*MmioTranslation != 0) {\r | |
276 | DEBUG ((EFI_D_ERROR, "%a: unsupported nonzero MMIO32 translation "\r | |
277 | "0x%Lx\n", __FUNCTION__, *MmioTranslation));\r | |
278 | return EFI_UNSUPPORTED;\r | |
279 | }\r | |
280 | \r | |
281 | break;\r | |
282 | }\r | |
283 | }\r | |
284 | if (*IoSize == 0 || *MmioSize == 0) {\r | |
285 | DEBUG ((EFI_D_ERROR, "%a: %a space empty\n", __FUNCTION__,\r | |
286 | (*IoSize == 0) ? "IO" : "MMIO32"));\r | |
287 | return EFI_PROTOCOL_ERROR;\r | |
288 | }\r | |
289 | \r | |
290 | //\r | |
291 | // The dynamic PCD PcdPciExpressBaseAddress should have already been set,\r | |
292 | // and should match the value we found in the DT node.\r | |
293 | //\r | |
294 | ASSERT (PcdGet64 (PcdPciExpressBaseAddress) == ConfigBase);\r | |
295 | \r | |
296 | SetLinuxPciProbeOnlyProperty (FdtClient);\r | |
297 | \r | |
298 | DEBUG ((EFI_D_INFO, "%a: Config[0x%Lx+0x%Lx) Bus[0x%x..0x%x] "\r | |
299 | "Io[0x%Lx+0x%Lx)@0x%Lx Mem[0x%Lx+0x%Lx)@0x%Lx\n", __FUNCTION__, ConfigBase,\r | |
300 | ConfigSize, *BusMin, *BusMax, *IoBase, *IoSize, *IoTranslation, *MmioBase,\r | |
301 | *MmioSize, *MmioTranslation));\r | |
302 | return EFI_SUCCESS;\r | |
303 | }\r | |
304 | \r | |
305 | \r | |
9595e3cd LE |
306 | /**\r |
307 | Entry point of this driver\r | |
308 | \r | |
309 | @param ImageHandle Handle of driver image\r | |
310 | @param SystemTable Point to EFI_SYSTEM_TABLE\r | |
311 | \r | |
120a25c2 | 312 | @retval EFI_ABORTED PCI host bridge not present\r |
9595e3cd LE |
313 | @retval EFI_OUT_OF_RESOURCES Can not allocate memory resource\r |
314 | @retval EFI_DEVICE_ERROR Can not install the protocol instance\r | |
315 | @retval EFI_SUCCESS Success to initialize the Pci host bridge.\r | |
316 | **/\r | |
317 | EFI_STATUS\r | |
318 | EFIAPI\r | |
319 | InitializePciHostBridge (\r | |
320 | IN EFI_HANDLE ImageHandle,\r | |
321 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
322 | )\r | |
323 | {\r | |
f9a8be42 | 324 | UINT64 MmioAttributes;\r |
9595e3cd LE |
325 | EFI_STATUS Status;\r |
326 | UINTN Loop1;\r | |
327 | UINTN Loop2;\r | |
328 | PCI_HOST_BRIDGE_INSTANCE *HostBridge;\r | |
329 | PCI_ROOT_BRIDGE_INSTANCE *PrivateData;\r | |
cd2178bb AB |
330 | UINT64 IoBase, IoSize, IoTranslation;\r |
331 | UINT64 MmioBase, MmioSize, MmioTranslation;\r | |
332 | UINT32 BusMin, BusMax;\r | |
d1c561f9 | 333 | \r |
120a25c2 LE |
334 | if (PcdGet64 (PcdPciExpressBaseAddress) == 0) {\r |
335 | DEBUG ((EFI_D_INFO, "%a: PCI host bridge not present\n", __FUNCTION__));\r | |
336 | return EFI_ABORTED;\r | |
337 | }\r | |
338 | \r | |
cd2178bb AB |
339 | Status = ProcessPciHost (&IoBase, &IoSize, &IoTranslation, &MmioBase,\r |
340 | &MmioSize, &MmioTranslation, &BusMin, &BusMax);\r | |
341 | if (EFI_ERROR (Status)) {\r | |
342 | return Status;\r | |
343 | }\r | |
344 | \r | |
9595e3cd | 345 | mDriverImageHandle = ImageHandle;\r |
d1c561f9 | 346 | \r |
cd2178bb AB |
347 | mResAperture[0][0].BusBase = BusMin;\r |
348 | mResAperture[0][0].BusLimit = BusMax;\r | |
aca7e8b6 | 349 | \r |
cd2178bb AB |
350 | mResAperture[0][0].MemBase = MmioBase;\r |
351 | mResAperture[0][0].MemLimit = MmioBase + MmioSize - 1;\r | |
aca7e8b6 | 352 | \r |
cd2178bb AB |
353 | mResAperture[0][0].IoBase = IoBase;\r |
354 | mResAperture[0][0].IoLimit = IoBase + IoSize - 1;\r | |
355 | mResAperture[0][0].IoTranslation = IoTranslation;\r | |
aca7e8b6 | 356 | \r |
807c26d3 LE |
357 | //\r |
358 | // Add IO and MMIO memory space, so that resources can be allocated in the\r | |
359 | // EfiPciHostBridgeAllocateResources phase.\r | |
360 | //\r | |
361 | Status = gDS->AddIoSpace (\r | |
362 | EfiGcdIoTypeIo,\r | |
cd2178bb AB |
363 | IoBase,\r |
364 | IoSize\r | |
807c26d3 LE |
365 | );\r |
366 | ASSERT_EFI_ERROR (Status);\r | |
367 | \r | |
3ef3209d | 368 | MmioAttributes = EFI_MEMORY_UC;\r |
f9a8be42 | 369 | \r |
807c26d3 LE |
370 | Status = gDS->AddMemorySpace (\r |
371 | EfiGcdMemoryTypeMemoryMappedIo,\r | |
cd2178bb AB |
372 | MmioBase,\r |
373 | MmioSize,\r | |
f9a8be42 | 374 | MmioAttributes\r |
807c26d3 LE |
375 | );\r |
376 | if (EFI_ERROR (Status)) {\r | |
377 | DEBUG ((EFI_D_ERROR, "%a: AddMemorySpace: %r\n", __FUNCTION__, Status));\r | |
378 | return Status;\r | |
379 | }\r | |
380 | \r | |
f9a8be42 | 381 | Status = gDS->SetMemorySpaceAttributes (\r |
cd2178bb AB |
382 | MmioBase,\r |
383 | MmioSize,\r | |
f9a8be42 LE |
384 | MmioAttributes\r |
385 | );\r | |
386 | if (EFI_ERROR (Status)) {\r | |
387 | DEBUG ((EFI_D_ERROR, "%a: SetMemorySpaceAttributes: %r\n", __FUNCTION__,\r | |
388 | Status));\r | |
389 | return Status;\r | |
390 | }\r | |
391 | \r | |
9595e3cd LE |
392 | //\r |
393 | // Create Host Bridge Device Handle\r | |
394 | //\r | |
395 | for (Loop1 = 0; Loop1 < HOST_BRIDGE_NUMBER; Loop1++) {\r | |
396 | HostBridge = AllocateCopyPool (sizeof(PCI_HOST_BRIDGE_INSTANCE), &mPciHostBridgeInstanceTemplate);\r | |
397 | if (HostBridge == NULL) {\r | |
398 | return EFI_OUT_OF_RESOURCES;\r | |
399 | }\r | |
d1c561f9 | 400 | \r |
9595e3cd LE |
401 | HostBridge->RootBridgeNumber = RootBridgeNumber[Loop1];\r |
402 | InitializeListHead (&HostBridge->Head);\r | |
403 | \r | |
404 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
d1c561f9 | 405 | &HostBridge->HostBridgeHandle,\r |
9595e3cd LE |
406 | &gEfiPciHostBridgeResourceAllocationProtocolGuid, &HostBridge->ResAlloc,\r |
407 | NULL\r | |
408 | );\r | |
409 | if (EFI_ERROR (Status)) {\r | |
410 | FreePool (HostBridge);\r | |
411 | return EFI_DEVICE_ERROR;\r | |
412 | }\r | |
d1c561f9 | 413 | \r |
9595e3cd LE |
414 | //\r |
415 | // Create Root Bridge Device Handle in this Host Bridge\r | |
416 | //\r | |
d1c561f9 | 417 | \r |
9595e3cd LE |
418 | for (Loop2 = 0; Loop2 < HostBridge->RootBridgeNumber; Loop2++) {\r |
419 | PrivateData = AllocateZeroPool (sizeof(PCI_ROOT_BRIDGE_INSTANCE));\r | |
420 | if (PrivateData == NULL) {\r | |
421 | return EFI_OUT_OF_RESOURCES;\r | |
422 | }\r | |
423 | \r | |
424 | PrivateData->Signature = PCI_ROOT_BRIDGE_SIGNATURE;\r | |
425 | PrivateData->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridgeDevicePath[Loop1][Loop2];\r | |
426 | \r | |
427 | RootBridgeConstructor (\r | |
d1c561f9 OM |
428 | &PrivateData->Io,\r |
429 | HostBridge->HostBridgeHandle,\r | |
430 | RootBridgeAttribute[Loop1][Loop2],\r | |
9595e3cd LE |
431 | &mResAperture[Loop1][Loop2]\r |
432 | );\r | |
d1c561f9 | 433 | \r |
9595e3cd | 434 | Status = gBS->InstallMultipleProtocolInterfaces(\r |
d1c561f9 | 435 | &PrivateData->Handle,\r |
9595e3cd LE |
436 | &gEfiDevicePathProtocolGuid, PrivateData->DevicePath,\r |
437 | &gEfiPciRootBridgeIoProtocolGuid, &PrivateData->Io,\r | |
438 | NULL\r | |
439 | );\r | |
440 | if (EFI_ERROR (Status)) {\r | |
441 | FreePool(PrivateData);\r | |
442 | return EFI_DEVICE_ERROR;\r | |
443 | }\r | |
d1c561f9 | 444 | \r |
9595e3cd LE |
445 | InsertTailList (&HostBridge->Head, &PrivateData->Link);\r |
446 | }\r | |
d1c561f9 | 447 | }\r |
9595e3cd LE |
448 | \r |
449 | return EFI_SUCCESS;\r | |
450 | }\r | |
451 | \r | |
452 | \r | |
453 | /**\r | |
454 | These are the notifications from the PCI bus driver that it is about to enter a certain\r | |
455 | phase of the PCI enumeration process.\r | |
456 | \r | |
457 | This member function can be used to notify the host bridge driver to perform specific actions,\r | |
458 | including any chipset-specific initialization, so that the chipset is ready to enter the next phase.\r | |
459 | Eight notification points are defined at this time. See belows:\r | |
460 | EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures and internal data\r | |
461 | structures. The PCI enumerator should issue this notification\r | |
462 | before starting a fresh enumeration process. Enumeration cannot\r | |
463 | be restarted after sending any other notification such as\r | |
464 | EfiPciHostBridgeBeginBusAllocation.\r | |
465 | EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to begin. No specific action is\r | |
466 | required here. This notification can be used to perform any\r | |
467 | chipset-specific programming.\r | |
468 | EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming phase is complete. No\r | |
469 | specific action is required here. This notification can be used to\r | |
470 | perform any chipset-specific programming.\r | |
471 | EfiPciHostBridgeBeginResourceAllocation\r | |
472 | The resource allocation phase is about to begin. No specific\r | |
473 | action is required here. This notification can be used to perform\r | |
474 | any chipset-specific programming.\r | |
475 | EfiPciHostBridgeAllocateResources Allocates resources per previously submitted requests for all the PCI\r | |
476 | root bridges. These resource settings are returned on the next call to\r | |
477 | GetProposedResources(). Before calling NotifyPhase() with a Phase of\r | |
478 | EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible\r | |
479 | for gathering I/O and memory requests for\r | |
480 | all the PCI root bridges and submitting these requests using\r | |
481 | SubmitResources(). This function pads the resource amount\r | |
482 | to suit the root bridge hardware, takes care of dependencies between\r | |
483 | the PCI root bridges, and calls the Global Coherency Domain (GCD)\r | |
484 | with the allocation request. In the case of padding, the allocated range\r | |
485 | could be bigger than what was requested.\r | |
486 | EfiPciHostBridgeSetResources Programs the host bridge hardware to decode previously allocated\r | |
487 | resources (proposed resources) for all the PCI root bridges. After the\r | |
488 | hardware is programmed, reassigning resources will not be supported.\r | |
489 | The bus settings are not affected.\r | |
490 | EfiPciHostBridgeFreeResources Deallocates resources that were previously allocated for all the PCI\r | |
491 | root bridges and resets the I/O and memory apertures to their initial\r | |
492 | state. The bus settings are not affected. If the request to allocate\r | |
493 | resources fails, the PCI enumerator can use this notification to\r | |
494 | deallocate previous resources, adjust the requests, and retry\r | |
495 | allocation.\r | |
496 | EfiPciHostBridgeEndResourceAllocation The resource allocation phase is completed. No specific action is\r | |
497 | required here. This notification can be used to perform any chipsetspecific\r | |
498 | programming.\r | |
499 | \r | |
500 | @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r | |
501 | @param[in] Phase The phase during enumeration\r | |
502 | \r | |
503 | @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error\r | |
504 | is valid for a Phase of EfiPciHostBridgeAllocateResources if\r | |
505 | SubmitResources() has not been called for one or more\r | |
506 | PCI root bridges before this call\r | |
507 | @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid\r | |
508 | for a Phase of EfiPciHostBridgeSetResources.\r | |
509 | @retval EFI_INVALID_PARAMETER Invalid phase parameter\r | |
510 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
511 | This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the\r | |
512 | previously submitted resource requests cannot be fulfilled or\r | |
513 | were only partially fulfilled.\r | |
514 | @retval EFI_SUCCESS The notification was accepted without any errors.\r | |
515 | \r | |
516 | **/\r | |
517 | EFI_STATUS\r | |
518 | EFIAPI\r | |
519 | NotifyPhase(\r | |
520 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
521 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase\r | |
522 | )\r | |
523 | {\r | |
524 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r | |
525 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
526 | PCI_RESOURCE_TYPE Index;\r | |
527 | LIST_ENTRY *List;\r | |
528 | EFI_PHYSICAL_ADDRESS BaseAddress;\r | |
529 | UINT64 AddrLen;\r | |
530 | UINTN BitsOfAlignment;\r | |
531 | EFI_STATUS Status;\r | |
532 | EFI_STATUS ReturnStatus;\r | |
d1c561f9 | 533 | \r |
9595e3cd | 534 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r |
d1c561f9 | 535 | \r |
9595e3cd LE |
536 | switch (Phase) {\r |
537 | \r | |
538 | case EfiPciHostBridgeBeginEnumeration:\r | |
539 | if (HostBridgeInstance->CanRestarted) {\r | |
540 | //\r | |
d1c561f9 | 541 | // Reset the Each Root Bridge\r |
9595e3cd LE |
542 | //\r |
543 | List = HostBridgeInstance->Head.ForwardLink;\r | |
d1c561f9 | 544 | \r |
9595e3cd LE |
545 | while (List != &HostBridgeInstance->Head) {\r |
546 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
547 | for (Index = TypeIo; Index < TypeMax; Index++) {\r | |
548 | RootBridgeInstance->ResAllocNode[Index].Type = Index;\r | |
549 | RootBridgeInstance->ResAllocNode[Index].Base = 0;\r | |
550 | RootBridgeInstance->ResAllocNode[Index].Length = 0;\r | |
551 | RootBridgeInstance->ResAllocNode[Index].Status = ResNone;\r | |
552 | }\r | |
d1c561f9 | 553 | \r |
9595e3cd LE |
554 | List = List->ForwardLink;\r |
555 | }\r | |
d1c561f9 | 556 | \r |
9595e3cd LE |
557 | HostBridgeInstance->ResourceSubmited = FALSE;\r |
558 | HostBridgeInstance->CanRestarted = TRUE;\r | |
559 | } else {\r | |
560 | //\r | |
561 | // Can not restart\r | |
d1c561f9 | 562 | //\r |
9595e3cd | 563 | return EFI_NOT_READY;\r |
d1c561f9 | 564 | }\r |
9595e3cd LE |
565 | break;\r |
566 | \r | |
567 | case EfiPciHostBridgeEndEnumeration:\r | |
568 | break;\r | |
569 | \r | |
570 | case EfiPciHostBridgeBeginBusAllocation:\r | |
571 | //\r | |
572 | // No specific action is required here, can perform any chipset specific programing\r | |
573 | //\r | |
574 | HostBridgeInstance->CanRestarted = FALSE;\r | |
575 | break;\r | |
576 | \r | |
577 | case EfiPciHostBridgeEndBusAllocation:\r | |
578 | //\r | |
579 | // No specific action is required here, can perform any chipset specific programing\r | |
580 | //\r | |
581 | //HostBridgeInstance->CanRestarted = FALSE;\r | |
582 | break;\r | |
583 | \r | |
584 | case EfiPciHostBridgeBeginResourceAllocation:\r | |
585 | //\r | |
586 | // No specific action is required here, can perform any chipset specific programing\r | |
587 | //\r | |
588 | //HostBridgeInstance->CanRestarted = FALSE;\r | |
589 | break;\r | |
590 | \r | |
591 | case EfiPciHostBridgeAllocateResources:\r | |
592 | ReturnStatus = EFI_SUCCESS;\r | |
593 | if (HostBridgeInstance->ResourceSubmited) {\r | |
594 | //\r | |
d1c561f9 | 595 | // Take care of the resource dependencies between the root bridges\r |
9595e3cd LE |
596 | //\r |
597 | List = HostBridgeInstance->Head.ForwardLink;\r | |
598 | \r | |
599 | while (List != &HostBridgeInstance->Head) {\r | |
600 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
601 | for (Index = TypeIo; Index < TypeBus; Index++) {\r | |
602 | if (RootBridgeInstance->ResAllocNode[Index].Status != ResNone) {\r | |
d1c561f9 | 603 | \r |
9595e3cd | 604 | AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r |
d1c561f9 | 605 | \r |
9595e3cd LE |
606 | //\r |
607 | // Get the number of '1' in Alignment.\r | |
608 | //\r | |
609 | BitsOfAlignment = (UINTN) (HighBitSet64 (RootBridgeInstance->ResAllocNode[Index].Alignment) + 1);\r | |
d1c561f9 | 610 | \r |
9595e3cd LE |
611 | switch (Index) {\r |
612 | \r | |
d1c561f9 | 613 | case TypeIo:\r |
9595e3cd LE |
614 | //\r |
615 | // It is impossible for this chipset to align 0xFFFF for IO16\r | |
616 | // So clear it\r | |
617 | //\r | |
618 | if (BitsOfAlignment >= 16) {\r | |
619 | BitsOfAlignment = 0;\r | |
620 | }\r | |
d1c561f9 | 621 | \r |
ef8dba7d | 622 | BaseAddress = mResAperture[0][0].IoLimit;\r |
9595e3cd | 623 | Status = gDS->AllocateIoSpace (\r |
ef8dba7d | 624 | EfiGcdAllocateMaxAddressSearchTopDown,\r |
d1c561f9 | 625 | EfiGcdIoTypeIo,\r |
9595e3cd LE |
626 | BitsOfAlignment,\r |
627 | AddrLen,\r | |
628 | &BaseAddress,\r | |
629 | mDriverImageHandle,\r | |
630 | NULL\r | |
631 | );\r | |
d1c561f9 | 632 | \r |
9595e3cd LE |
633 | if (!EFI_ERROR (Status)) {\r |
634 | RootBridgeInstance->ResAllocNode[Index].Base = (UINTN)BaseAddress;\r | |
d1c561f9 | 635 | RootBridgeInstance->ResAllocNode[Index].Status = ResAllocated;\r |
9595e3cd | 636 | } else {\r |
d1c561f9 | 637 | ReturnStatus = Status;\r |
9595e3cd LE |
638 | if (Status != EFI_OUT_OF_RESOURCES) {\r |
639 | RootBridgeInstance->ResAllocNode[Index].Length = 0;\r | |
640 | }\r | |
641 | }\r | |
642 | \r | |
643 | break;\r | |
644 | \r | |
645 | \r | |
646 | case TypeMem32:\r | |
647 | //\r | |
648 | // It is impossible for this chipset to align 0xFFFFFFFF for Mem32\r | |
d1c561f9 | 649 | // So clear it\r |
9595e3cd | 650 | //\r |
d1c561f9 | 651 | \r |
9595e3cd LE |
652 | if (BitsOfAlignment >= 32) {\r |
653 | BitsOfAlignment = 0;\r | |
654 | }\r | |
d1c561f9 | 655 | \r |
b9a44dca | 656 | BaseAddress = mResAperture[0][0].MemLimit;\r |
9595e3cd | 657 | Status = gDS->AllocateMemorySpace (\r |
b9a44dca | 658 | EfiGcdAllocateMaxAddressSearchTopDown,\r |
d1c561f9 | 659 | EfiGcdMemoryTypeMemoryMappedIo,\r |
9595e3cd LE |
660 | BitsOfAlignment,\r |
661 | AddrLen,\r | |
662 | &BaseAddress,\r | |
663 | mDriverImageHandle,\r | |
664 | NULL\r | |
665 | );\r | |
d1c561f9 | 666 | \r |
9595e3cd LE |
667 | if (!EFI_ERROR (Status)) {\r |
668 | // We were able to allocate the PCI memory\r | |
669 | RootBridgeInstance->ResAllocNode[Index].Base = (UINTN)BaseAddress;\r | |
670 | RootBridgeInstance->ResAllocNode[Index].Status = ResAllocated;\r | |
d1c561f9 | 671 | \r |
9595e3cd LE |
672 | } else {\r |
673 | // Not able to allocate enough PCI memory\r | |
d1c561f9 OM |
674 | ReturnStatus = Status;\r |
675 | \r | |
9595e3cd LE |
676 | if (Status != EFI_OUT_OF_RESOURCES) {\r |
677 | RootBridgeInstance->ResAllocNode[Index].Length = 0;\r | |
d1c561f9 | 678 | }\r |
9595e3cd LE |
679 | ASSERT (FALSE);\r |
680 | }\r | |
681 | break;\r | |
d1c561f9 OM |
682 | \r |
683 | case TypePMem32:\r | |
684 | case TypeMem64:\r | |
9595e3cd LE |
685 | case TypePMem64:\r |
686 | ReturnStatus = EFI_ABORTED;\r | |
d1c561f9 | 687 | break;\r |
9595e3cd LE |
688 | default:\r |
689 | ASSERT (FALSE);\r | |
690 | break;\r | |
691 | }; //end switch\r | |
692 | }\r | |
693 | }\r | |
d1c561f9 | 694 | \r |
9595e3cd LE |
695 | List = List->ForwardLink;\r |
696 | }\r | |
d1c561f9 | 697 | \r |
9595e3cd | 698 | return ReturnStatus;\r |
9595e3cd LE |
699 | } else {\r |
700 | return EFI_NOT_READY;\r | |
701 | }\r | |
9595e3cd LE |
702 | \r |
703 | case EfiPciHostBridgeSetResources:\r | |
704 | break;\r | |
705 | \r | |
706 | case EfiPciHostBridgeFreeResources:\r | |
707 | ReturnStatus = EFI_SUCCESS;\r | |
708 | List = HostBridgeInstance->Head.ForwardLink;\r | |
709 | while (List != &HostBridgeInstance->Head) {\r | |
710 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
711 | for (Index = TypeIo; Index < TypeBus; Index++) {\r | |
712 | if (RootBridgeInstance->ResAllocNode[Index].Status == ResAllocated) {\r | |
713 | AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r | |
714 | BaseAddress = RootBridgeInstance->ResAllocNode[Index].Base;\r | |
715 | switch (Index) {\r | |
716 | \r | |
d1c561f9 OM |
717 | case TypeIo:\r |
718 | Status = gDS->FreeIoSpace (BaseAddress, AddrLen);\r | |
9595e3cd LE |
719 | if (EFI_ERROR (Status)) {\r |
720 | ReturnStatus = Status;\r | |
721 | }\r | |
722 | break;\r | |
723 | \r | |
724 | case TypeMem32:\r | |
725 | Status = gDS->FreeMemorySpace (BaseAddress, AddrLen);\r | |
726 | if (EFI_ERROR (Status)) {\r | |
727 | ReturnStatus = Status;\r | |
728 | }\r | |
729 | break;\r | |
730 | \r | |
731 | case TypePMem32:\r | |
732 | break;\r | |
733 | \r | |
734 | case TypeMem64:\r | |
735 | break;\r | |
736 | \r | |
737 | case TypePMem64:\r | |
d1c561f9 | 738 | break;\r |
9595e3cd LE |
739 | \r |
740 | default:\r | |
741 | ASSERT (FALSE);\r | |
742 | break;\r | |
743 | \r | |
744 | }; //end switch\r | |
745 | RootBridgeInstance->ResAllocNode[Index].Type = Index;\r | |
746 | RootBridgeInstance->ResAllocNode[Index].Base = 0;\r | |
747 | RootBridgeInstance->ResAllocNode[Index].Length = 0;\r | |
748 | RootBridgeInstance->ResAllocNode[Index].Status = ResNone;\r | |
749 | }\r | |
750 | }\r | |
d1c561f9 | 751 | \r |
9595e3cd LE |
752 | List = List->ForwardLink;\r |
753 | }\r | |
d1c561f9 | 754 | \r |
9595e3cd | 755 | HostBridgeInstance->ResourceSubmited = FALSE;\r |
d1c561f9 | 756 | HostBridgeInstance->CanRestarted = TRUE;\r |
9595e3cd LE |
757 | return ReturnStatus;\r |
758 | \r | |
759 | case EfiPciHostBridgeEndResourceAllocation:\r | |
760 | HostBridgeInstance->CanRestarted = FALSE;\r | |
761 | break;\r | |
762 | \r | |
763 | default:\r | |
764 | return EFI_INVALID_PARAMETER;\r | |
765 | }\r | |
d1c561f9 OM |
766 | \r |
767 | return EFI_SUCCESS;\r | |
9595e3cd LE |
768 | }\r |
769 | \r | |
770 | /**\r | |
771 | Return the device handle of the next PCI root bridge that is associated with this Host Bridge.\r | |
772 | \r | |
773 | This function is called multiple times to retrieve the device handles of all the PCI root bridges that\r | |
774 | are associated with this PCI host bridge. Each PCI host bridge is associated with one or more PCI\r | |
775 | root bridges. On each call, the handle that was returned by the previous call is passed into the\r | |
776 | interface, and on output the interface returns the device handle of the next PCI root bridge. The\r | |
777 | caller can use the handle to obtain the instance of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL\r | |
778 | for that root bridge. When there are no more PCI root bridges to report, the interface returns\r | |
779 | EFI_NOT_FOUND. A PCI enumerator must enumerate the PCI root bridges in the order that they\r | |
780 | are returned by this function.\r | |
781 | For D945 implementation, there is only one root bridge in PCI host bridge.\r | |
782 | \r | |
783 | @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r | |
784 | @param[in, out] RootBridgeHandle Returns the device handle of the next PCI root bridge.\r | |
d1c561f9 | 785 | \r |
9595e3cd | 786 | @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then return the first Rootbridge handle of the\r |
d1c561f9 | 787 | specific Host bridge and return EFI_SUCCESS.\r |
9595e3cd LE |
788 | @retval EFI_NOT_FOUND Can not find the any more root bridge in specific host bridge.\r |
789 | @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was\r | |
790 | returned on a previous call to GetNextRootBridge().\r | |
791 | **/\r | |
792 | EFI_STATUS\r | |
793 | EFIAPI\r | |
794 | GetNextRootBridge(\r | |
795 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
796 | IN OUT EFI_HANDLE *RootBridgeHandle\r | |
797 | )\r | |
798 | {\r | |
d1c561f9 OM |
799 | BOOLEAN NoRootBridge;\r |
800 | LIST_ENTRY *List;\r | |
9595e3cd LE |
801 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r |
802 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
d1c561f9 | 803 | \r |
9595e3cd LE |
804 | NoRootBridge = TRUE;\r |
805 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r | |
806 | List = HostBridgeInstance->Head.ForwardLink;\r | |
d1c561f9 OM |
807 | \r |
808 | \r | |
9595e3cd LE |
809 | while (List != &HostBridgeInstance->Head) {\r |
810 | NoRootBridge = FALSE;\r | |
811 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
812 | if (*RootBridgeHandle == NULL) {\r | |
813 | //\r | |
814 | // Return the first Root Bridge Handle of the Host Bridge\r | |
815 | //\r | |
816 | *RootBridgeHandle = RootBridgeInstance->Handle;\r | |
817 | return EFI_SUCCESS;\r | |
818 | } else {\r | |
819 | if (*RootBridgeHandle == RootBridgeInstance->Handle) {\r | |
820 | //\r | |
821 | // Get next if have\r | |
822 | //\r | |
823 | List = List->ForwardLink;\r | |
824 | if (List!=&HostBridgeInstance->Head) {\r | |
825 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
826 | *RootBridgeHandle = RootBridgeInstance->Handle;\r | |
d1c561f9 | 827 | return EFI_SUCCESS;\r |
9595e3cd LE |
828 | } else {\r |
829 | return EFI_NOT_FOUND;\r | |
830 | }\r | |
831 | }\r | |
832 | }\r | |
d1c561f9 | 833 | \r |
9595e3cd LE |
834 | List = List->ForwardLink;\r |
835 | } //end while\r | |
d1c561f9 | 836 | \r |
9595e3cd LE |
837 | if (NoRootBridge) {\r |
838 | return EFI_NOT_FOUND;\r | |
839 | } else {\r | |
840 | return EFI_INVALID_PARAMETER;\r | |
841 | }\r | |
842 | }\r | |
843 | \r | |
844 | /**\r | |
845 | Returns the allocation attributes of a PCI root bridge.\r | |
846 | \r | |
847 | The function returns the allocation attributes of a specific PCI root bridge. The attributes can vary\r | |
848 | from one PCI root bridge to another. These attributes are different from the decode-related\r | |
849 | attributes that are returned by the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The\r | |
850 | RootBridgeHandle parameter is used to specify the instance of the PCI root bridge. The device\r | |
851 | handles of all the root bridges that are associated with this host bridge must be obtained by calling\r | |
852 | GetNextRootBridge(). The attributes are static in the sense that they do not change during or\r | |
853 | after the enumeration process. The hardware may provide mechanisms to change the attributes on\r | |
d1c561f9 | 854 | the fly, but such changes must be completed before EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is\r |
9595e3cd LE |
855 | installed. The permitted values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in\r |
856 | "Related Definitions" below. The caller uses these attributes to combine multiple resource requests.\r | |
d1c561f9 OM |
857 | For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI bus enumerator needs to\r |
858 | include requests for the prefetchable memory in the nonprefetchable memory pool and not request any\r | |
9595e3cd LE |
859 | prefetchable memory.\r |
860 | Attribute Description\r | |
861 | ------------------------------------ ----------------------------------------------------------------------\r | |
862 | EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root bridge does not support separate\r | |
863 | windows for nonprefetchable and prefetchable memory. A PCI bus\r | |
864 | driver needs to include requests for prefetchable memory in the\r | |
865 | nonprefetchable memory pool.\r | |
866 | \r | |
867 | EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root bridge supports 64-bit memory\r | |
868 | windows. If this bit is not set, the PCI bus driver needs to include\r | |
869 | requests for a 64-bit memory address in the corresponding 32-bit\r | |
870 | memory pool.\r | |
871 | \r | |
872 | @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r | |
873 | @param[in] RootBridgeHandle The device handle of the PCI root bridge in which the caller is interested. Type\r | |
874 | EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.\r | |
875 | @param[out] Attributes The pointer to attribte of root bridge, it is output parameter\r | |
d1c561f9 | 876 | \r |
9595e3cd LE |
877 | @retval EFI_INVALID_PARAMETER Attribute pointer is NULL\r |
878 | @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.\r | |
879 | @retval EFI_SUCCESS Success to get attribute of interested root bridge.\r | |
880 | \r | |
881 | **/\r | |
882 | EFI_STATUS\r | |
883 | EFIAPI\r | |
884 | GetAttributes(\r | |
885 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
886 | IN EFI_HANDLE RootBridgeHandle,\r | |
887 | OUT UINT64 *Attributes\r | |
888 | )\r | |
889 | {\r | |
d1c561f9 | 890 | LIST_ENTRY *List;\r |
9595e3cd LE |
891 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r |
892 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
d1c561f9 | 893 | \r |
9595e3cd LE |
894 | if (Attributes == NULL) {\r |
895 | return EFI_INVALID_PARAMETER;\r | |
896 | }\r | |
d1c561f9 | 897 | \r |
9595e3cd LE |
898 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r |
899 | List = HostBridgeInstance->Head.ForwardLink;\r | |
d1c561f9 | 900 | \r |
9595e3cd LE |
901 | while (List != &HostBridgeInstance->Head) {\r |
902 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
903 | if (RootBridgeHandle == RootBridgeInstance->Handle) {\r | |
904 | *Attributes = RootBridgeInstance->RootBridgeAttrib;\r | |
905 | return EFI_SUCCESS;\r | |
906 | }\r | |
907 | List = List->ForwardLink;\r | |
908 | }\r | |
d1c561f9 | 909 | \r |
9595e3cd | 910 | //\r |
d1c561f9 | 911 | // RootBridgeHandle is not an EFI_HANDLE\r |
9595e3cd LE |
912 | // that was returned on a previous call to GetNextRootBridge()\r |
913 | //\r | |
914 | return EFI_INVALID_PARAMETER;\r | |
915 | }\r | |
916 | \r | |
917 | /**\r | |
918 | Sets up the specified PCI root bridge for the bus enumeration process.\r | |
919 | \r | |
920 | This member function sets up the root bridge for bus enumeration and returns the PCI bus range\r | |
921 | over which the search should be performed in ACPI 2.0 resource descriptor format.\r | |
922 | \r | |
923 | @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.\r | |
924 | @param[in] RootBridgeHandle The PCI Root Bridge to be set up.\r | |
925 | @param[out] Configuration Pointer to the pointer to the PCI bus resource descriptor.\r | |
d1c561f9 | 926 | \r |
9595e3cd LE |
927 | @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle\r |
928 | @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.\r | |
929 | @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.\r | |
930 | \r | |
931 | **/\r | |
932 | EFI_STATUS\r | |
933 | EFIAPI\r | |
934 | StartBusEnumeration(\r | |
935 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
936 | IN EFI_HANDLE RootBridgeHandle,\r | |
937 | OUT VOID **Configuration\r | |
938 | )\r | |
939 | {\r | |
d1c561f9 | 940 | LIST_ENTRY *List;\r |
9595e3cd LE |
941 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r |
942 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
943 | VOID *Buffer;\r | |
944 | UINT8 *Temp;\r | |
945 | UINT64 BusStart;\r | |
946 | UINT64 BusEnd;\r | |
d1c561f9 | 947 | \r |
9595e3cd LE |
948 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r |
949 | List = HostBridgeInstance->Head.ForwardLink;\r | |
d1c561f9 | 950 | \r |
9595e3cd LE |
951 | while (List != &HostBridgeInstance->Head) {\r |
952 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
953 | if (RootBridgeHandle == RootBridgeInstance->Handle) {\r | |
954 | //\r | |
955 | // Set up the Root Bridge for Bus Enumeration\r | |
956 | //\r | |
957 | BusStart = RootBridgeInstance->BusBase;\r | |
958 | BusEnd = RootBridgeInstance->BusLimit;\r | |
959 | //\r | |
960 | // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR\r | |
961 | //\r | |
d1c561f9 | 962 | \r |
9595e3cd LE |
963 | Buffer = AllocatePool (sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR));\r |
964 | if (Buffer == NULL) {\r | |
965 | return EFI_OUT_OF_RESOURCES;\r | |
966 | }\r | |
d1c561f9 | 967 | \r |
9595e3cd | 968 | Temp = (UINT8 *)Buffer;\r |
d1c561f9 | 969 | \r |
9595e3cd LE |
970 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->Desc = 0x8A;\r |
971 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->Len = 0x2B;\r | |
972 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->ResType = 2;\r | |
d1c561f9 | 973 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->GenFlag = 0;\r |
9595e3cd LE |
974 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->SpecificFlag = 0;\r |
975 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrSpaceGranularity = 0;\r | |
976 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrRangeMin = BusStart;\r | |
977 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrRangeMax = 0;\r | |
d1c561f9 | 978 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrTranslationOffset = 0;\r |
9595e3cd | 979 | ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrLen = BusEnd - BusStart + 1;\r |
d1c561f9 | 980 | \r |
9595e3cd | 981 | Temp = Temp + sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r |
d1c561f9 | 982 | ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Desc = 0x79;\r |
9595e3cd | 983 | ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Checksum = 0x0;\r |
d1c561f9 OM |
984 | \r |
985 | *Configuration = Buffer;\r | |
9595e3cd LE |
986 | return EFI_SUCCESS;\r |
987 | }\r | |
988 | List = List->ForwardLink;\r | |
989 | }\r | |
d1c561f9 | 990 | \r |
9595e3cd LE |
991 | return EFI_INVALID_PARAMETER;\r |
992 | }\r | |
993 | \r | |
994 | /**\r | |
995 | Programs the PCI root bridge hardware so that it decodes the specified PCI bus range.\r | |
996 | \r | |
997 | This member function programs the specified PCI root bridge to decode the bus range that is\r | |
998 | specified by the input parameter Configuration.\r | |
999 | The bus range information is specified in terms of the ACPI 2.0 resource descriptor format.\r | |
1000 | \r | |
1001 | @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance\r | |
1002 | @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be programmed\r | |
1003 | @param[in] Configuration The pointer to the PCI bus resource descriptor\r | |
d1c561f9 | 1004 | \r |
9595e3cd LE |
1005 | @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r |
1006 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
1007 | @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.\r | |
1008 | @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI 2.0 bus resource descriptor.\r | |
d1c561f9 | 1009 | @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource descriptors other than\r |
9595e3cd LE |
1010 | bus descriptors.\r |
1011 | @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid ACPI resource descriptors.\r | |
1012 | @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this root bridge.\r | |
1013 | @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this root bridge.\r | |
1014 | @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.\r | |
1015 | @retval EFI_SUCCESS The bus range for the PCI root bridge was programmed.\r | |
1016 | \r | |
1017 | **/\r | |
1018 | EFI_STATUS\r | |
1019 | EFIAPI\r | |
1020 | SetBusNumbers(\r | |
1021 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
1022 | IN EFI_HANDLE RootBridgeHandle,\r | |
1023 | IN VOID *Configuration\r | |
1024 | )\r | |
1025 | {\r | |
d1c561f9 | 1026 | LIST_ENTRY *List;\r |
9595e3cd LE |
1027 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r |
1028 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
1029 | UINT8 *Ptr;\r | |
1030 | UINTN BusStart;\r | |
1031 | UINTN BusEnd;\r | |
1032 | UINTN BusLen;\r | |
d1c561f9 | 1033 | \r |
9595e3cd LE |
1034 | if (Configuration == NULL) {\r |
1035 | return EFI_INVALID_PARAMETER;\r | |
1036 | }\r | |
d1c561f9 | 1037 | \r |
9595e3cd | 1038 | Ptr = Configuration;\r |
d1c561f9 | 1039 | \r |
9595e3cd LE |
1040 | //\r |
1041 | // Check the Configuration is valid\r | |
1042 | //\r | |
1043 | if(*Ptr != ACPI_ADDRESS_SPACE_DESCRIPTOR) {\r | |
1044 | return EFI_INVALID_PARAMETER;\r | |
1045 | }\r | |
d1c561f9 | 1046 | \r |
9595e3cd LE |
1047 | if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Ptr)->ResType != 2) {\r |
1048 | return EFI_INVALID_PARAMETER;\r | |
1049 | }\r | |
1050 | \r | |
1051 | Ptr += sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r | |
1052 | if (*Ptr != ACPI_END_TAG_DESCRIPTOR) {\r | |
1053 | return EFI_INVALID_PARAMETER;\r | |
1054 | }\r | |
d1c561f9 | 1055 | \r |
9595e3cd LE |
1056 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r |
1057 | List = HostBridgeInstance->Head.ForwardLink;\r | |
d1c561f9 | 1058 | \r |
9595e3cd | 1059 | Ptr = Configuration;\r |
d1c561f9 | 1060 | \r |
9595e3cd LE |
1061 | while (List != &HostBridgeInstance->Head) {\r |
1062 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
1063 | if (RootBridgeHandle == RootBridgeInstance->Handle) {\r | |
1064 | BusStart = (UINTN)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Ptr)->AddrRangeMin;\r | |
1065 | BusLen = (UINTN)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Ptr)->AddrLen;\r | |
1066 | BusEnd = BusStart + BusLen - 1;\r | |
d1c561f9 | 1067 | \r |
9595e3cd LE |
1068 | if (BusStart > BusEnd) {\r |
1069 | return EFI_INVALID_PARAMETER;\r | |
1070 | }\r | |
d1c561f9 | 1071 | \r |
9595e3cd LE |
1072 | if ((BusStart < RootBridgeInstance->BusBase) || (BusEnd > RootBridgeInstance->BusLimit)) {\r |
1073 | return EFI_INVALID_PARAMETER;\r | |
1074 | }\r | |
d1c561f9 | 1075 | \r |
9595e3cd LE |
1076 | //\r |
1077 | // Update the Bus Range\r | |
1078 | //\r | |
1079 | RootBridgeInstance->ResAllocNode[TypeBus].Base = BusStart;\r | |
1080 | RootBridgeInstance->ResAllocNode[TypeBus].Length = BusLen;\r | |
1081 | RootBridgeInstance->ResAllocNode[TypeBus].Status = ResAllocated;\r | |
d1c561f9 | 1082 | \r |
9595e3cd LE |
1083 | //\r |
1084 | // Program the Root Bridge Hardware\r | |
1085 | //\r | |
d1c561f9 | 1086 | \r |
9595e3cd LE |
1087 | return EFI_SUCCESS;\r |
1088 | }\r | |
d1c561f9 | 1089 | \r |
9595e3cd LE |
1090 | List = List->ForwardLink;\r |
1091 | }\r | |
d1c561f9 | 1092 | \r |
9595e3cd LE |
1093 | return EFI_INVALID_PARAMETER;\r |
1094 | }\r | |
1095 | \r | |
1096 | \r | |
1097 | /**\r | |
1098 | Submits the I/O and memory resource requirements for the specified PCI root bridge.\r | |
1099 | \r | |
1100 | This function is used to submit all the I/O and memory resources that are required by the specified\r | |
1101 | PCI root bridge. The input parameter Configuration is used to specify the following:\r | |
1102 | - The various types of resources that are required\r | |
1103 | - The associated lengths in terms of ACPI 2.0 resource descriptor format\r | |
1104 | \r | |
1105 | @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.\r | |
1106 | @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory resource requirements are being submitted.\r | |
1107 | @param[in] Configuration The pointer to the PCI I/O and PCI memory resource descriptor.\r | |
d1c561f9 | 1108 | \r |
9595e3cd LE |
1109 | @retval EFI_SUCCESS The I/O and memory resource requests for a PCI root bridge were accepted.\r |
1110 | @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r | |
1111 | @retval EFI_INVALID_PARAMETER Configuration is NULL.\r | |
1112 | @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.\r | |
d1c561f9 OM |
1113 | @retval EFI_INVALID_PARAMETER Configuration includes requests for one or more resource types that are\r |
1114 | not supported by this PCI root bridge. This error will happen if the caller\r | |
9595e3cd LE |
1115 | did not combine resources according to Attributes that were returned by\r |
1116 | GetAllocAttributes().\r | |
1117 | @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.\r | |
1118 | @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI root bridge.\r | |
1119 | @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for this PCI root bridge.\r | |
1120 | \r | |
1121 | **/\r | |
1122 | EFI_STATUS\r | |
1123 | EFIAPI\r | |
1124 | SubmitResources(\r | |
1125 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
1126 | IN EFI_HANDLE RootBridgeHandle,\r | |
1127 | IN VOID *Configuration\r | |
1128 | )\r | |
1129 | {\r | |
d1c561f9 | 1130 | LIST_ENTRY *List;\r |
9595e3cd LE |
1131 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r |
1132 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
1133 | UINT8 *Temp;\r | |
1134 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Ptr;\r | |
1135 | UINT64 AddrLen;\r | |
1136 | UINT64 Alignment;\r | |
d1c561f9 | 1137 | \r |
9595e3cd LE |
1138 | //\r |
1139 | // Check the input parameter: Configuration\r | |
1140 | //\r | |
1141 | if (Configuration == NULL) {\r | |
1142 | return EFI_INVALID_PARAMETER;\r | |
1143 | }\r | |
d1c561f9 | 1144 | \r |
9595e3cd LE |
1145 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r |
1146 | List = HostBridgeInstance->Head.ForwardLink;\r | |
d1c561f9 | 1147 | \r |
9595e3cd | 1148 | Temp = (UINT8 *)Configuration;\r |
d1c561f9 | 1149 | while ( *Temp == 0x8A) {\r |
9595e3cd LE |
1150 | Temp += sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) ;\r |
1151 | }\r | |
1152 | if (*Temp != 0x79) {\r | |
1153 | return EFI_INVALID_PARAMETER;\r | |
1154 | }\r | |
d1c561f9 | 1155 | \r |
9595e3cd LE |
1156 | Temp = (UINT8 *)Configuration;\r |
1157 | while (List != &HostBridgeInstance->Head) {\r | |
1158 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
1159 | if (RootBridgeHandle == RootBridgeInstance->Handle) {\r | |
1a1d6376 LE |
1160 | for (;\r |
1161 | *Temp == 0x8A;\r | |
1162 | Temp += sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR)\r | |
1163 | ) {\r | |
9595e3cd LE |
1164 | Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Temp ;\r |
1165 | \r | |
1166 | //\r | |
1167 | // Check Address Length\r | |
1168 | //\r | |
1a1d6376 LE |
1169 | if (Ptr->AddrLen == 0) {\r |
1170 | HostBridgeInstance->ResourceSubmited = TRUE;\r | |
1171 | continue;\r | |
1172 | }\r | |
9595e3cd LE |
1173 | if (Ptr->AddrLen > 0xffffffff) {\r |
1174 | return EFI_INVALID_PARAMETER;\r | |
1175 | }\r | |
1176 | \r | |
1177 | //\r | |
1178 | // Check address range alignment\r | |
1179 | //\r | |
1180 | if (Ptr->AddrRangeMax >= 0xffffffff || Ptr->AddrRangeMax != (GetPowerOfTwo64 (Ptr->AddrRangeMax + 1) - 1)) {\r | |
1181 | return EFI_INVALID_PARAMETER;\r | |
1182 | }\r | |
d1c561f9 | 1183 | \r |
9595e3cd LE |
1184 | switch (Ptr->ResType) {\r |
1185 | \r | |
1186 | case 0:\r | |
d1c561f9 | 1187 | \r |
9595e3cd LE |
1188 | //\r |
1189 | // Check invalid Address Sapce Granularity\r | |
1190 | //\r | |
1191 | if (Ptr->AddrSpaceGranularity != 32) {\r | |
1192 | return EFI_INVALID_PARAMETER;\r | |
1193 | }\r | |
d1c561f9 | 1194 | \r |
9595e3cd LE |
1195 | //\r |
1196 | // check the memory resource request is supported by PCI root bridge\r | |
1197 | //\r | |
1198 | if (RootBridgeInstance->RootBridgeAttrib == EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM &&\r | |
1199 | Ptr->SpecificFlag == 0x06) {\r | |
1200 | return EFI_INVALID_PARAMETER;\r | |
1201 | }\r | |
d1c561f9 | 1202 | \r |
9595e3cd LE |
1203 | AddrLen = Ptr->AddrLen;\r |
1204 | Alignment = Ptr->AddrRangeMax;\r | |
1205 | if (Ptr->AddrSpaceGranularity == 32) {\r | |
1206 | if (Ptr->SpecificFlag == 0x06) {\r | |
1207 | //\r | |
1208 | // Apply from GCD\r | |
1209 | //\r | |
1210 | RootBridgeInstance->ResAllocNode[TypePMem32].Status = ResSubmitted;\r | |
1211 | } else {\r | |
1212 | RootBridgeInstance->ResAllocNode[TypeMem32].Length = AddrLen;\r | |
1213 | RootBridgeInstance->ResAllocNode[TypeMem32].Alignment = Alignment;\r | |
d1c561f9 | 1214 | RootBridgeInstance->ResAllocNode[TypeMem32].Status = ResRequested;\r |
9595e3cd LE |
1215 | HostBridgeInstance->ResourceSubmited = TRUE;\r |
1216 | }\r | |
1217 | }\r | |
1218 | \r | |
1219 | if (Ptr->AddrSpaceGranularity == 64) {\r | |
1220 | if (Ptr->SpecificFlag == 0x06) {\r | |
1221 | RootBridgeInstance->ResAllocNode[TypePMem64].Status = ResSubmitted;\r | |
1222 | } else {\r | |
1223 | RootBridgeInstance->ResAllocNode[TypeMem64].Status = ResSubmitted;\r | |
1224 | }\r | |
1225 | }\r | |
1226 | break;\r | |
1227 | \r | |
1228 | case 1:\r | |
1229 | AddrLen = (UINTN) Ptr->AddrLen;\r | |
1230 | Alignment = (UINTN) Ptr->AddrRangeMax;\r | |
1231 | RootBridgeInstance->ResAllocNode[TypeIo].Length = AddrLen;\r | |
1232 | RootBridgeInstance->ResAllocNode[TypeIo].Alignment = Alignment;\r | |
1233 | RootBridgeInstance->ResAllocNode[TypeIo].Status = ResRequested;\r | |
d1c561f9 | 1234 | HostBridgeInstance->ResourceSubmited = TRUE;\r |
9595e3cd LE |
1235 | break;\r |
1236 | \r | |
1237 | default:\r | |
1238 | break;\r | |
1239 | };\r | |
d1c561f9 OM |
1240 | }\r |
1241 | \r | |
9595e3cd LE |
1242 | return EFI_SUCCESS;\r |
1243 | }\r | |
d1c561f9 | 1244 | \r |
9595e3cd LE |
1245 | List = List->ForwardLink;\r |
1246 | }\r | |
d1c561f9 | 1247 | \r |
9595e3cd LE |
1248 | return EFI_INVALID_PARAMETER;\r |
1249 | }\r | |
1250 | \r | |
1251 | /**\r | |
1252 | Returns the proposed resource settings for the specified PCI root bridge.\r | |
1253 | \r | |
1254 | This member function returns the proposed resource settings for the specified PCI root bridge. The\r | |
1255 | proposed resource settings are prepared when NotifyPhase() is called with a Phase of\r | |
1256 | EfiPciHostBridgeAllocateResources. The output parameter Configuration\r | |
1257 | specifies the following:\r | |
1258 | - The various types of resources, excluding bus resources, that are allocated\r | |
1259 | - The associated lengths in terms of ACPI 2.0 resource descriptor format\r | |
1260 | \r | |
1261 | @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.\r | |
1262 | @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.\r | |
1263 | @param[out] Configuration The pointer to the pointer to the PCI I/O and memory resource descriptor.\r | |
d1c561f9 | 1264 | \r |
9595e3cd LE |
1265 | @retval EFI_SUCCESS The requested parameters were returned.\r |
1266 | @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r | |
1267 | @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.\r | |
1268 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
1269 | \r | |
1270 | **/\r | |
1271 | EFI_STATUS\r | |
1272 | EFIAPI\r | |
1273 | GetProposedResources(\r | |
1274 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
1275 | IN EFI_HANDLE RootBridgeHandle,\r | |
1276 | OUT VOID **Configuration\r | |
1277 | )\r | |
1278 | {\r | |
d1c561f9 | 1279 | LIST_ENTRY *List;\r |
9595e3cd LE |
1280 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r |
1281 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
1282 | UINTN Index;\r | |
d1c561f9 OM |
1283 | UINTN Number;\r |
1284 | VOID *Buffer;\r | |
9595e3cd LE |
1285 | UINT8 *Temp;\r |
1286 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Ptr;\r | |
1287 | UINT64 ResStatus;\r | |
d1c561f9 | 1288 | \r |
9595e3cd LE |
1289 | Buffer = NULL;\r |
1290 | Number = 0;\r | |
1291 | //\r | |
1292 | // Get the Host Bridge Instance from the resource allocation protocol\r | |
1293 | //\r | |
1294 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r | |
1295 | List = HostBridgeInstance->Head.ForwardLink;\r | |
d1c561f9 | 1296 | \r |
9595e3cd LE |
1297 | //\r |
1298 | // Enumerate the root bridges in this host bridge\r | |
1299 | //\r | |
1300 | while (List != &HostBridgeInstance->Head) {\r | |
1301 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
1302 | if (RootBridgeHandle == RootBridgeInstance->Handle) {\r | |
1303 | for (Index = 0; Index < TypeBus; Index ++) {\r | |
1304 | if (RootBridgeInstance->ResAllocNode[Index].Status != ResNone) {\r | |
1305 | Number ++;\r | |
d1c561f9 | 1306 | }\r |
9595e3cd | 1307 | }\r |
d1c561f9 | 1308 | \r |
9595e3cd | 1309 | if (Number == 0) {\r |
e5ceb6c9 LE |
1310 | EFI_ACPI_END_TAG_DESCRIPTOR *End;\r |
1311 | \r | |
1312 | End = AllocateZeroPool (sizeof *End);\r | |
1313 | if (End == NULL) {\r | |
1314 | return EFI_OUT_OF_RESOURCES;\r | |
1315 | }\r | |
1316 | End->Desc = ACPI_END_TAG_DESCRIPTOR;\r | |
1317 | *Configuration = End;\r | |
1318 | return EFI_SUCCESS;\r | |
9595e3cd LE |
1319 | }\r |
1320 | \r | |
1321 | Buffer = AllocateZeroPool (Number * sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR));\r | |
1322 | if (Buffer == NULL) {\r | |
1323 | return EFI_OUT_OF_RESOURCES;\r | |
1324 | }\r | |
d1c561f9 | 1325 | \r |
9595e3cd LE |
1326 | Temp = Buffer;\r |
1327 | for (Index = 0; Index < TypeBus; Index ++) {\r | |
1328 | if (RootBridgeInstance->ResAllocNode[Index].Status != ResNone) {\r | |
1329 | Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Temp ;\r | |
1330 | ResStatus = RootBridgeInstance->ResAllocNode[Index].Status;\r | |
d1c561f9 | 1331 | \r |
9595e3cd LE |
1332 | switch (Index) {\r |
1333 | \r | |
1334 | case TypeIo:\r | |
1335 | //\r | |
1336 | // Io\r | |
1337 | //\r | |
1338 | Ptr->Desc = 0x8A;\r | |
1339 | Ptr->Len = 0x2B;\r | |
1340 | Ptr->ResType = 1;\r | |
d1c561f9 | 1341 | Ptr->GenFlag = 0;\r |
9595e3cd LE |
1342 | Ptr->SpecificFlag = 0;\r |
1343 | Ptr->AddrRangeMin = RootBridgeInstance->ResAllocNode[Index].Base;\r | |
1344 | Ptr->AddrRangeMax = 0;\r | |
1345 | Ptr->AddrTranslationOffset = \\r | |
1346 | (ResStatus == ResAllocated) ? EFI_RESOURCE_SATISFIED : EFI_RESOURCE_LESS;\r | |
1347 | Ptr->AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r | |
1348 | break;\r | |
1349 | \r | |
1350 | case TypeMem32:\r | |
1351 | //\r | |
1352 | // Memory 32\r | |
d1c561f9 | 1353 | //\r |
9595e3cd LE |
1354 | Ptr->Desc = 0x8A;\r |
1355 | Ptr->Len = 0x2B;\r | |
1356 | Ptr->ResType = 0;\r | |
d1c561f9 | 1357 | Ptr->GenFlag = 0;\r |
9595e3cd LE |
1358 | Ptr->SpecificFlag = 0;\r |
1359 | Ptr->AddrSpaceGranularity = 32;\r | |
1360 | Ptr->AddrRangeMin = RootBridgeInstance->ResAllocNode[Index].Base;\r | |
1361 | Ptr->AddrRangeMax = 0;\r | |
1362 | Ptr->AddrTranslationOffset = \\r | |
d1c561f9 | 1363 | (ResStatus == ResAllocated) ? EFI_RESOURCE_SATISFIED : EFI_RESOURCE_LESS;\r |
9595e3cd LE |
1364 | Ptr->AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r |
1365 | break;\r | |
1366 | \r | |
1367 | case TypePMem32:\r | |
1368 | //\r | |
1369 | // Prefetch memory 32\r | |
1370 | //\r | |
1371 | Ptr->Desc = 0x8A;\r | |
1372 | Ptr->Len = 0x2B;\r | |
1373 | Ptr->ResType = 0;\r | |
d1c561f9 | 1374 | Ptr->GenFlag = 0;\r |
9595e3cd LE |
1375 | Ptr->SpecificFlag = 6;\r |
1376 | Ptr->AddrSpaceGranularity = 32;\r | |
1377 | Ptr->AddrRangeMin = 0;\r | |
1378 | Ptr->AddrRangeMax = 0;\r | |
d1c561f9 | 1379 | Ptr->AddrTranslationOffset = EFI_RESOURCE_NONEXISTENT;\r |
9595e3cd LE |
1380 | Ptr->AddrLen = 0;\r |
1381 | break;\r | |
1382 | \r | |
1383 | case TypeMem64:\r | |
1384 | //\r | |
1385 | // Memory 64\r | |
1386 | //\r | |
1387 | Ptr->Desc = 0x8A;\r | |
1388 | Ptr->Len = 0x2B;\r | |
1389 | Ptr->ResType = 0;\r | |
d1c561f9 | 1390 | Ptr->GenFlag = 0;\r |
9595e3cd LE |
1391 | Ptr->SpecificFlag = 0;\r |
1392 | Ptr->AddrSpaceGranularity = 64;\r | |
1393 | Ptr->AddrRangeMin = 0;\r | |
1394 | Ptr->AddrRangeMax = 0;\r | |
d1c561f9 | 1395 | Ptr->AddrTranslationOffset = EFI_RESOURCE_NONEXISTENT;\r |
9595e3cd LE |
1396 | Ptr->AddrLen = 0;\r |
1397 | break;\r | |
1398 | \r | |
1399 | case TypePMem64:\r | |
1400 | //\r | |
1401 | // Prefetch memory 64\r | |
1402 | //\r | |
1403 | Ptr->Desc = 0x8A;\r | |
1404 | Ptr->Len = 0x2B;\r | |
1405 | Ptr->ResType = 0;\r | |
d1c561f9 | 1406 | Ptr->GenFlag = 0;\r |
9595e3cd LE |
1407 | Ptr->SpecificFlag = 6;\r |
1408 | Ptr->AddrSpaceGranularity = 64;\r | |
1409 | Ptr->AddrRangeMin = 0;\r | |
1410 | Ptr->AddrRangeMax = 0;\r | |
d1c561f9 | 1411 | Ptr->AddrTranslationOffset = EFI_RESOURCE_NONEXISTENT;\r |
9595e3cd LE |
1412 | Ptr->AddrLen = 0;\r |
1413 | break;\r | |
1414 | };\r | |
d1c561f9 | 1415 | \r |
9595e3cd | 1416 | Temp += sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r |
d1c561f9 | 1417 | }\r |
9595e3cd | 1418 | }\r |
d1c561f9 OM |
1419 | \r |
1420 | ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Desc = 0x79;\r | |
9595e3cd | 1421 | ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Checksum = 0x0;\r |
d1c561f9 OM |
1422 | \r |
1423 | *Configuration = Buffer;\r | |
1424 | \r | |
9595e3cd LE |
1425 | return EFI_SUCCESS;\r |
1426 | }\r | |
d1c561f9 | 1427 | \r |
9595e3cd LE |
1428 | List = List->ForwardLink;\r |
1429 | }\r | |
d1c561f9 | 1430 | \r |
9595e3cd LE |
1431 | return EFI_INVALID_PARAMETER;\r |
1432 | }\r | |
1433 | \r | |
1434 | /**\r | |
1435 | Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various\r | |
1436 | stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual\r | |
1437 | PCI controllers before enumeration.\r | |
1438 | \r | |
1439 | This function is called during the PCI enumeration process. No specific action is expected from this\r | |
1440 | member function. It allows the host bridge driver to preinitialize individual PCI controllers before\r | |
1441 | enumeration.\r | |
1442 | \r | |
1443 | @param This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.\r | |
1444 | @param RootBridgeHandle The associated PCI root bridge handle. Type EFI_HANDLE is defined in\r | |
1445 | InstallProtocolInterface() in the UEFI 2.0 Specification.\r | |
1446 | @param PciAddress The address of the PCI device on the PCI bus. This address can be passed to the\r | |
1447 | EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to access the PCI\r | |
1448 | configuration space of the device. See Table 12-1 in the UEFI 2.0 Specification for\r | |
1449 | the definition of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.\r | |
d1c561f9 OM |
1450 | @param Phase The phase of the PCI device enumeration.\r |
1451 | \r | |
9595e3cd LE |
1452 | @retval EFI_SUCCESS The requested parameters were returned.\r |
1453 | @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r | |
1454 | @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in\r | |
1455 | EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.\r | |
1456 | @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should\r | |
1457 | not enumerate this device, including its child devices if it is a PCI-to-PCI\r | |
1458 | bridge.\r | |
1459 | \r | |
1460 | **/\r | |
1461 | EFI_STATUS\r | |
1462 | EFIAPI\r | |
1463 | PreprocessController (\r | |
1464 | IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r | |
1465 | IN EFI_HANDLE RootBridgeHandle,\r | |
1466 | IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress,\r | |
1467 | IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase\r | |
1468 | )\r | |
1469 | {\r | |
1470 | PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r | |
1471 | PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r | |
d1c561f9 | 1472 | LIST_ENTRY *List;\r |
9595e3cd LE |
1473 | \r |
1474 | HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r | |
1475 | List = HostBridgeInstance->Head.ForwardLink;\r | |
1476 | \r | |
1477 | //\r | |
1478 | // Enumerate the root bridges in this host bridge\r | |
1479 | //\r | |
1480 | while (List != &HostBridgeInstance->Head) {\r | |
1481 | RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r | |
1482 | if (RootBridgeHandle == RootBridgeInstance->Handle) {\r | |
1483 | break;\r | |
1484 | }\r | |
1485 | List = List->ForwardLink;\r | |
1486 | }\r | |
1487 | if (List == &HostBridgeInstance->Head) {\r | |
1488 | return EFI_INVALID_PARAMETER;\r | |
1489 | }\r | |
1490 | \r | |
1491 | if ((UINT32)Phase > EfiPciBeforeResourceCollection) {\r | |
1492 | return EFI_INVALID_PARAMETER;\r | |
1493 | }\r | |
1494 | \r | |
1495 | return EFI_SUCCESS;\r | |
1496 | }\r |