]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPlatformPkg/ArmVirtualizationPkg/PciHostBridgeDxe/PciHostBridge.c
ArmVirtualizationPkg/PciHostBridgeDxe: set Root Bridge apertures from PCDs
[mirror_edk2.git] / ArmPlatformPkg / ArmVirtualizationPkg / PciHostBridgeDxe / PciHostBridge.c
CommitLineData
9595e3cd
LE
1/** @file\r
2 Provides the basic interfaces to abstract a PCI Host Bridge Resource Allocation\r
3\r
4Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials are\r
6licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/ \r
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
23UINTN RootBridgeNumber[1] = { 1 };\r
24\r
25UINT64 RootBridgeAttribute[1][1] = { { EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM } };\r
26\r
27EFI_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
42 \r
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 55STATIC PCI_ROOT_BRIDGE_RESOURCE_APERTURE mResAperture[1][1];\r
9595e3cd
LE
56\r
57EFI_HANDLE mDriverImageHandle;\r
58\r
59PCI_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
82/**\r
83 Entry point of this driver\r
84\r
85 @param ImageHandle Handle of driver image\r
86 @param SystemTable Point to EFI_SYSTEM_TABLE\r
87\r
88 @retval EFI_OUT_OF_RESOURCES Can not allocate memory resource\r
89 @retval EFI_DEVICE_ERROR Can not install the protocol instance\r
90 @retval EFI_SUCCESS Success to initialize the Pci host bridge.\r
91**/\r
92EFI_STATUS\r
93EFIAPI\r
94InitializePciHostBridge (\r
95 IN EFI_HANDLE ImageHandle,\r
96 IN EFI_SYSTEM_TABLE *SystemTable\r
97 )\r
98{\r
99 EFI_STATUS Status;\r
100 UINTN Loop1;\r
101 UINTN Loop2;\r
102 PCI_HOST_BRIDGE_INSTANCE *HostBridge;\r
103 PCI_ROOT_BRIDGE_INSTANCE *PrivateData;\r
104 \r
105 mDriverImageHandle = ImageHandle;\r
106 \r
aca7e8b6
LE
107 mResAperture[0][0].BusBase = PcdGet32 (PcdPciBusMin);\r
108 mResAperture[0][0].BusLimit = PcdGet32 (PcdPciBusMax);\r
109\r
110 mResAperture[0][0].MemBase = PcdGet32 (PcdPciMmio32Base);\r
111 mResAperture[0][0].MemLimit = (UINT64)PcdGet32 (PcdPciMmio32Base) +\r
112 PcdGet32 (PcdPciMmio32Size) - 1;\r
113\r
114 mResAperture[0][0].IoBase = PcdGet64 (PcdPciIoBase);\r
115 mResAperture[0][0].IoLimit = PcdGet64 (PcdPciIoBase) +\r
116 PcdGet64 (PcdPciIoSize) - 1;\r
117 mResAperture[0][0].IoTranslation = PcdGet64 (PcdPciIoTranslation);\r
118\r
9595e3cd
LE
119 //\r
120 // Create Host Bridge Device Handle\r
121 //\r
122 for (Loop1 = 0; Loop1 < HOST_BRIDGE_NUMBER; Loop1++) {\r
123 HostBridge = AllocateCopyPool (sizeof(PCI_HOST_BRIDGE_INSTANCE), &mPciHostBridgeInstanceTemplate);\r
124 if (HostBridge == NULL) {\r
125 return EFI_OUT_OF_RESOURCES;\r
126 }\r
127 \r
128 HostBridge->RootBridgeNumber = RootBridgeNumber[Loop1];\r
129 InitializeListHead (&HostBridge->Head);\r
130\r
131 Status = gBS->InstallMultipleProtocolInterfaces (\r
132 &HostBridge->HostBridgeHandle, \r
133 &gEfiPciHostBridgeResourceAllocationProtocolGuid, &HostBridge->ResAlloc,\r
134 NULL\r
135 );\r
136 if (EFI_ERROR (Status)) {\r
137 FreePool (HostBridge);\r
138 return EFI_DEVICE_ERROR;\r
139 }\r
140 \r
141 //\r
142 // Create Root Bridge Device Handle in this Host Bridge\r
143 //\r
144 \r
145 for (Loop2 = 0; Loop2 < HostBridge->RootBridgeNumber; Loop2++) {\r
146 PrivateData = AllocateZeroPool (sizeof(PCI_ROOT_BRIDGE_INSTANCE));\r
147 if (PrivateData == NULL) {\r
148 return EFI_OUT_OF_RESOURCES;\r
149 }\r
150\r
151 PrivateData->Signature = PCI_ROOT_BRIDGE_SIGNATURE;\r
152 PrivateData->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridgeDevicePath[Loop1][Loop2];\r
153\r
154 RootBridgeConstructor (\r
155 &PrivateData->Io, \r
156 HostBridge->HostBridgeHandle, \r
157 RootBridgeAttribute[Loop1][Loop2], \r
158 &mResAperture[Loop1][Loop2]\r
159 );\r
160 \r
161 Status = gBS->InstallMultipleProtocolInterfaces(\r
162 &PrivateData->Handle, \r
163 &gEfiDevicePathProtocolGuid, PrivateData->DevicePath,\r
164 &gEfiPciRootBridgeIoProtocolGuid, &PrivateData->Io,\r
165 NULL\r
166 );\r
167 if (EFI_ERROR (Status)) {\r
168 FreePool(PrivateData);\r
169 return EFI_DEVICE_ERROR;\r
170 }\r
171 \r
172 InsertTailList (&HostBridge->Head, &PrivateData->Link);\r
173 }\r
174 } \r
175\r
176 return EFI_SUCCESS;\r
177}\r
178\r
179\r
180/**\r
181 These are the notifications from the PCI bus driver that it is about to enter a certain\r
182 phase of the PCI enumeration process.\r
183\r
184 This member function can be used to notify the host bridge driver to perform specific actions,\r
185 including any chipset-specific initialization, so that the chipset is ready to enter the next phase.\r
186 Eight notification points are defined at this time. See belows:\r
187 EfiPciHostBridgeBeginEnumeration Resets the host bridge PCI apertures and internal data\r
188 structures. The PCI enumerator should issue this notification\r
189 before starting a fresh enumeration process. Enumeration cannot\r
190 be restarted after sending any other notification such as\r
191 EfiPciHostBridgeBeginBusAllocation.\r
192 EfiPciHostBridgeBeginBusAllocation The bus allocation phase is about to begin. No specific action is\r
193 required here. This notification can be used to perform any\r
194 chipset-specific programming.\r
195 EfiPciHostBridgeEndBusAllocation The bus allocation and bus programming phase is complete. No\r
196 specific action is required here. This notification can be used to\r
197 perform any chipset-specific programming.\r
198 EfiPciHostBridgeBeginResourceAllocation\r
199 The resource allocation phase is about to begin. No specific\r
200 action is required here. This notification can be used to perform\r
201 any chipset-specific programming.\r
202 EfiPciHostBridgeAllocateResources Allocates resources per previously submitted requests for all the PCI\r
203 root bridges. These resource settings are returned on the next call to\r
204 GetProposedResources(). Before calling NotifyPhase() with a Phase of\r
205 EfiPciHostBridgeAllocateResource, the PCI bus enumerator is responsible\r
206 for gathering I/O and memory requests for\r
207 all the PCI root bridges and submitting these requests using\r
208 SubmitResources(). This function pads the resource amount\r
209 to suit the root bridge hardware, takes care of dependencies between\r
210 the PCI root bridges, and calls the Global Coherency Domain (GCD)\r
211 with the allocation request. In the case of padding, the allocated range\r
212 could be bigger than what was requested.\r
213 EfiPciHostBridgeSetResources Programs the host bridge hardware to decode previously allocated\r
214 resources (proposed resources) for all the PCI root bridges. After the\r
215 hardware is programmed, reassigning resources will not be supported.\r
216 The bus settings are not affected.\r
217 EfiPciHostBridgeFreeResources Deallocates resources that were previously allocated for all the PCI\r
218 root bridges and resets the I/O and memory apertures to their initial\r
219 state. The bus settings are not affected. If the request to allocate\r
220 resources fails, the PCI enumerator can use this notification to\r
221 deallocate previous resources, adjust the requests, and retry\r
222 allocation.\r
223 EfiPciHostBridgeEndResourceAllocation The resource allocation phase is completed. No specific action is\r
224 required here. This notification can be used to perform any chipsetspecific\r
225 programming.\r
226\r
227 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r
228 @param[in] Phase The phase during enumeration\r
229\r
230 @retval EFI_NOT_READY This phase cannot be entered at this time. For example, this error\r
231 is valid for a Phase of EfiPciHostBridgeAllocateResources if\r
232 SubmitResources() has not been called for one or more\r
233 PCI root bridges before this call\r
234 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. This error is valid\r
235 for a Phase of EfiPciHostBridgeSetResources.\r
236 @retval EFI_INVALID_PARAMETER Invalid phase parameter\r
237 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
238 This error is valid for a Phase of EfiPciHostBridgeAllocateResources if the\r
239 previously submitted resource requests cannot be fulfilled or\r
240 were only partially fulfilled.\r
241 @retval EFI_SUCCESS The notification was accepted without any errors.\r
242\r
243**/\r
244EFI_STATUS\r
245EFIAPI\r
246NotifyPhase(\r
247 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
248 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase\r
249 )\r
250{\r
251 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
252 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
253 PCI_RESOURCE_TYPE Index;\r
254 LIST_ENTRY *List;\r
255 EFI_PHYSICAL_ADDRESS BaseAddress;\r
256 UINT64 AddrLen;\r
257 UINTN BitsOfAlignment;\r
258 EFI_STATUS Status;\r
259 EFI_STATUS ReturnStatus;\r
260 \r
261 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
262 \r
263 switch (Phase) {\r
264\r
265 case EfiPciHostBridgeBeginEnumeration:\r
266 if (HostBridgeInstance->CanRestarted) {\r
267 //\r
268 // Reset the Each Root Bridge \r
269 //\r
270 List = HostBridgeInstance->Head.ForwardLink;\r
271 \r
272 while (List != &HostBridgeInstance->Head) {\r
273 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
274 for (Index = TypeIo; Index < TypeMax; Index++) {\r
275 RootBridgeInstance->ResAllocNode[Index].Type = Index;\r
276 RootBridgeInstance->ResAllocNode[Index].Base = 0;\r
277 RootBridgeInstance->ResAllocNode[Index].Length = 0;\r
278 RootBridgeInstance->ResAllocNode[Index].Status = ResNone;\r
279 }\r
280 \r
281 List = List->ForwardLink;\r
282 }\r
283 \r
284 HostBridgeInstance->ResourceSubmited = FALSE;\r
285 HostBridgeInstance->CanRestarted = TRUE;\r
286 } else {\r
287 //\r
288 // Can not restart\r
289 // \r
290 return EFI_NOT_READY;\r
291 } \r
292 break;\r
293\r
294 case EfiPciHostBridgeEndEnumeration:\r
295 break;\r
296\r
297 case EfiPciHostBridgeBeginBusAllocation:\r
298 //\r
299 // No specific action is required here, can perform any chipset specific programing\r
300 //\r
301 HostBridgeInstance->CanRestarted = FALSE;\r
302 break;\r
303\r
304 case EfiPciHostBridgeEndBusAllocation:\r
305 //\r
306 // No specific action is required here, can perform any chipset specific programing\r
307 //\r
308 //HostBridgeInstance->CanRestarted = FALSE;\r
309 break;\r
310\r
311 case EfiPciHostBridgeBeginResourceAllocation:\r
312 //\r
313 // No specific action is required here, can perform any chipset specific programing\r
314 //\r
315 //HostBridgeInstance->CanRestarted = FALSE;\r
316 break;\r
317\r
318 case EfiPciHostBridgeAllocateResources:\r
319 ReturnStatus = EFI_SUCCESS;\r
320 if (HostBridgeInstance->ResourceSubmited) {\r
321 //\r
322 // Take care of the resource dependencies between the root bridges \r
323 //\r
324 List = HostBridgeInstance->Head.ForwardLink;\r
325\r
326 while (List != &HostBridgeInstance->Head) {\r
327 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
328 for (Index = TypeIo; Index < TypeBus; Index++) {\r
329 if (RootBridgeInstance->ResAllocNode[Index].Status != ResNone) {\r
330 \r
331 AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r
332 \r
333 //\r
334 // Get the number of '1' in Alignment.\r
335 //\r
336 BitsOfAlignment = (UINTN) (HighBitSet64 (RootBridgeInstance->ResAllocNode[Index].Alignment) + 1);\r
337 \r
338 switch (Index) {\r
339\r
340 case TypeIo: \r
341 //\r
342 // It is impossible for this chipset to align 0xFFFF for IO16\r
343 // So clear it\r
344 //\r
345 if (BitsOfAlignment >= 16) {\r
346 BitsOfAlignment = 0;\r
347 }\r
348 \r
349 Status = gDS->AllocateIoSpace (\r
350 EfiGcdAllocateAnySearchBottomUp, \r
351 EfiGcdIoTypeIo, \r
352 BitsOfAlignment,\r
353 AddrLen,\r
354 &BaseAddress,\r
355 mDriverImageHandle,\r
356 NULL\r
357 );\r
358 \r
359 if (!EFI_ERROR (Status)) {\r
360 RootBridgeInstance->ResAllocNode[Index].Base = (UINTN)BaseAddress;\r
361 RootBridgeInstance->ResAllocNode[Index].Status = ResAllocated; \r
362 } else {\r
363 ReturnStatus = Status; \r
364 if (Status != EFI_OUT_OF_RESOURCES) {\r
365 RootBridgeInstance->ResAllocNode[Index].Length = 0;\r
366 }\r
367 }\r
368\r
369 break;\r
370\r
371\r
372 case TypeMem32:\r
373 //\r
374 // It is impossible for this chipset to align 0xFFFFFFFF for Mem32\r
375 // So clear it \r
376 //\r
377 \r
378 if (BitsOfAlignment >= 32) {\r
379 BitsOfAlignment = 0;\r
380 }\r
381 \r
382 Status = gDS->AllocateMemorySpace (\r
383 EfiGcdAllocateAnySearchBottomUp, \r
384 EfiGcdMemoryTypeMemoryMappedIo, \r
385 BitsOfAlignment,\r
386 AddrLen,\r
387 &BaseAddress,\r
388 mDriverImageHandle,\r
389 NULL\r
390 );\r
391 \r
392 if (!EFI_ERROR (Status)) {\r
393 // We were able to allocate the PCI memory\r
394 RootBridgeInstance->ResAllocNode[Index].Base = (UINTN)BaseAddress;\r
395 RootBridgeInstance->ResAllocNode[Index].Status = ResAllocated;\r
396 \r
397 } else {\r
398 // Not able to allocate enough PCI memory\r
399 ReturnStatus = Status; \r
400 \r
401 if (Status != EFI_OUT_OF_RESOURCES) {\r
402 RootBridgeInstance->ResAllocNode[Index].Length = 0;\r
403 } \r
404 ASSERT (FALSE);\r
405 }\r
406 break;\r
407 \r
408 case TypePMem32: \r
409 case TypeMem64: \r
410 case TypePMem64:\r
411 ReturnStatus = EFI_ABORTED;\r
412 break; \r
413 default:\r
414 ASSERT (FALSE);\r
415 break;\r
416 }; //end switch\r
417 }\r
418 }\r
419 \r
420 List = List->ForwardLink;\r
421 }\r
422 \r
423 return ReturnStatus;\r
424\r
425 } else {\r
426 return EFI_NOT_READY;\r
427 }\r
428 break;\r
429\r
430 case EfiPciHostBridgeSetResources:\r
431 break;\r
432\r
433 case EfiPciHostBridgeFreeResources:\r
434 ReturnStatus = EFI_SUCCESS;\r
435 List = HostBridgeInstance->Head.ForwardLink;\r
436 while (List != &HostBridgeInstance->Head) {\r
437 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
438 for (Index = TypeIo; Index < TypeBus; Index++) {\r
439 if (RootBridgeInstance->ResAllocNode[Index].Status == ResAllocated) {\r
440 AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r
441 BaseAddress = RootBridgeInstance->ResAllocNode[Index].Base;\r
442 switch (Index) {\r
443\r
444 case TypeIo: \r
445 Status = gDS->FreeIoSpace (BaseAddress, AddrLen); \r
446 if (EFI_ERROR (Status)) {\r
447 ReturnStatus = Status;\r
448 }\r
449 break;\r
450\r
451 case TypeMem32:\r
452 Status = gDS->FreeMemorySpace (BaseAddress, AddrLen);\r
453 if (EFI_ERROR (Status)) {\r
454 ReturnStatus = Status;\r
455 }\r
456 break;\r
457\r
458 case TypePMem32:\r
459 break;\r
460\r
461 case TypeMem64:\r
462 break;\r
463\r
464 case TypePMem64:\r
465 break; \r
466\r
467 default:\r
468 ASSERT (FALSE);\r
469 break;\r
470\r
471 }; //end switch\r
472 RootBridgeInstance->ResAllocNode[Index].Type = Index;\r
473 RootBridgeInstance->ResAllocNode[Index].Base = 0;\r
474 RootBridgeInstance->ResAllocNode[Index].Length = 0;\r
475 RootBridgeInstance->ResAllocNode[Index].Status = ResNone;\r
476 }\r
477 }\r
478 \r
479 List = List->ForwardLink;\r
480 }\r
481 \r
482 HostBridgeInstance->ResourceSubmited = FALSE;\r
483 HostBridgeInstance->CanRestarted = TRUE; \r
484 return ReturnStatus;\r
485\r
486 case EfiPciHostBridgeEndResourceAllocation:\r
487 HostBridgeInstance->CanRestarted = FALSE;\r
488 break;\r
489\r
490 default:\r
491 return EFI_INVALID_PARAMETER;\r
492 }\r
493 \r
494 return EFI_SUCCESS; \r
495}\r
496\r
497/**\r
498 Return the device handle of the next PCI root bridge that is associated with this Host Bridge.\r
499\r
500 This function is called multiple times to retrieve the device handles of all the PCI root bridges that\r
501 are associated with this PCI host bridge. Each PCI host bridge is associated with one or more PCI\r
502 root bridges. On each call, the handle that was returned by the previous call is passed into the\r
503 interface, and on output the interface returns the device handle of the next PCI root bridge. The\r
504 caller can use the handle to obtain the instance of the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL\r
505 for that root bridge. When there are no more PCI root bridges to report, the interface returns\r
506 EFI_NOT_FOUND. A PCI enumerator must enumerate the PCI root bridges in the order that they\r
507 are returned by this function.\r
508 For D945 implementation, there is only one root bridge in PCI host bridge.\r
509\r
510 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r
511 @param[in, out] RootBridgeHandle Returns the device handle of the next PCI root bridge.\r
512 \r
513 @retval EFI_SUCCESS If parameter RootBridgeHandle = NULL, then return the first Rootbridge handle of the\r
514 specific Host bridge and return EFI_SUCCESS. \r
515 @retval EFI_NOT_FOUND Can not find the any more root bridge in specific host bridge.\r
516 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not an EFI_HANDLE that was\r
517 returned on a previous call to GetNextRootBridge().\r
518**/\r
519EFI_STATUS\r
520EFIAPI\r
521GetNextRootBridge(\r
522 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
523 IN OUT EFI_HANDLE *RootBridgeHandle\r
524 )\r
525{\r
526 BOOLEAN NoRootBridge; \r
527 LIST_ENTRY *List; \r
528 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
529 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
530 \r
531 NoRootBridge = TRUE;\r
532 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
533 List = HostBridgeInstance->Head.ForwardLink;\r
534 \r
535 \r
536 while (List != &HostBridgeInstance->Head) {\r
537 NoRootBridge = FALSE;\r
538 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
539 if (*RootBridgeHandle == NULL) {\r
540 //\r
541 // Return the first Root Bridge Handle of the Host Bridge\r
542 //\r
543 *RootBridgeHandle = RootBridgeInstance->Handle;\r
544 return EFI_SUCCESS;\r
545 } else {\r
546 if (*RootBridgeHandle == RootBridgeInstance->Handle) {\r
547 //\r
548 // Get next if have\r
549 //\r
550 List = List->ForwardLink;\r
551 if (List!=&HostBridgeInstance->Head) {\r
552 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
553 *RootBridgeHandle = RootBridgeInstance->Handle;\r
554 return EFI_SUCCESS; \r
555 } else {\r
556 return EFI_NOT_FOUND;\r
557 }\r
558 }\r
559 }\r
560 \r
561 List = List->ForwardLink;\r
562 } //end while\r
563 \r
564 if (NoRootBridge) {\r
565 return EFI_NOT_FOUND;\r
566 } else {\r
567 return EFI_INVALID_PARAMETER;\r
568 }\r
569}\r
570\r
571/**\r
572 Returns the allocation attributes of a PCI root bridge.\r
573\r
574 The function returns the allocation attributes of a specific PCI root bridge. The attributes can vary\r
575 from one PCI root bridge to another. These attributes are different from the decode-related\r
576 attributes that are returned by the EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL.GetAttributes() member function. The\r
577 RootBridgeHandle parameter is used to specify the instance of the PCI root bridge. The device\r
578 handles of all the root bridges that are associated with this host bridge must be obtained by calling\r
579 GetNextRootBridge(). The attributes are static in the sense that they do not change during or\r
580 after the enumeration process. The hardware may provide mechanisms to change the attributes on\r
581 the fly, but such changes must be completed before EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL is \r
582 installed. The permitted values of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ATTRIBUTES are defined in\r
583 "Related Definitions" below. The caller uses these attributes to combine multiple resource requests.\r
584 For example, if the flag EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM is set, the PCI bus enumerator needs to \r
585 include requests for the prefetchable memory in the nonprefetchable memory pool and not request any \r
586 prefetchable memory.\r
587 Attribute Description\r
588 ------------------------------------ ----------------------------------------------------------------------\r
589 EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM If this bit is set, then the PCI root bridge does not support separate\r
590 windows for nonprefetchable and prefetchable memory. A PCI bus\r
591 driver needs to include requests for prefetchable memory in the\r
592 nonprefetchable memory pool.\r
593\r
594 EFI_PCI_HOST_BRIDGE_MEM64_DECODE If this bit is set, then the PCI root bridge supports 64-bit memory\r
595 windows. If this bit is not set, the PCI bus driver needs to include\r
596 requests for a 64-bit memory address in the corresponding 32-bit\r
597 memory pool.\r
598\r
599 @param[in] This The instance pointer of EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL\r
600 @param[in] RootBridgeHandle The device handle of the PCI root bridge in which the caller is interested. Type\r
601 EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.\r
602 @param[out] Attributes The pointer to attribte of root bridge, it is output parameter\r
603 \r
604 @retval EFI_INVALID_PARAMETER Attribute pointer is NULL\r
605 @retval EFI_INVALID_PARAMETER RootBridgehandle is invalid.\r
606 @retval EFI_SUCCESS Success to get attribute of interested root bridge.\r
607\r
608**/\r
609EFI_STATUS\r
610EFIAPI\r
611GetAttributes(\r
612 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
613 IN EFI_HANDLE RootBridgeHandle,\r
614 OUT UINT64 *Attributes\r
615 )\r
616{\r
617 LIST_ENTRY *List; \r
618 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
619 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
620 \r
621 if (Attributes == NULL) {\r
622 return EFI_INVALID_PARAMETER;\r
623 }\r
624 \r
625 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
626 List = HostBridgeInstance->Head.ForwardLink;\r
627 \r
628 while (List != &HostBridgeInstance->Head) {\r
629 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
630 if (RootBridgeHandle == RootBridgeInstance->Handle) {\r
631 *Attributes = RootBridgeInstance->RootBridgeAttrib;\r
632 return EFI_SUCCESS;\r
633 }\r
634 List = List->ForwardLink;\r
635 }\r
636 \r
637 //\r
638 // RootBridgeHandle is not an EFI_HANDLE \r
639 // that was returned on a previous call to GetNextRootBridge()\r
640 //\r
641 return EFI_INVALID_PARAMETER;\r
642}\r
643\r
644/**\r
645 Sets up the specified PCI root bridge for the bus enumeration process.\r
646\r
647 This member function sets up the root bridge for bus enumeration and returns the PCI bus range\r
648 over which the search should be performed in ACPI 2.0 resource descriptor format.\r
649\r
650 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.\r
651 @param[in] RootBridgeHandle The PCI Root Bridge to be set up.\r
652 @param[out] Configuration Pointer to the pointer to the PCI bus resource descriptor.\r
653 \r
654 @retval EFI_INVALID_PARAMETER Invalid Root bridge's handle\r
655 @retval EFI_OUT_OF_RESOURCES Fail to allocate ACPI resource descriptor tag.\r
656 @retval EFI_SUCCESS Sucess to allocate ACPI resource descriptor.\r
657\r
658**/\r
659EFI_STATUS\r
660EFIAPI\r
661StartBusEnumeration(\r
662 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
663 IN EFI_HANDLE RootBridgeHandle,\r
664 OUT VOID **Configuration\r
665 )\r
666{\r
667 LIST_ENTRY *List; \r
668 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
669 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
670 VOID *Buffer;\r
671 UINT8 *Temp;\r
672 UINT64 BusStart;\r
673 UINT64 BusEnd;\r
674 \r
675 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
676 List = HostBridgeInstance->Head.ForwardLink;\r
677 \r
678 while (List != &HostBridgeInstance->Head) {\r
679 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
680 if (RootBridgeHandle == RootBridgeInstance->Handle) {\r
681 //\r
682 // Set up the Root Bridge for Bus Enumeration\r
683 //\r
684 BusStart = RootBridgeInstance->BusBase;\r
685 BusEnd = RootBridgeInstance->BusLimit;\r
686 //\r
687 // Program the Hardware(if needed) if error return EFI_DEVICE_ERROR\r
688 //\r
689 \r
690 Buffer = AllocatePool (sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR));\r
691 if (Buffer == NULL) {\r
692 return EFI_OUT_OF_RESOURCES;\r
693 }\r
694 \r
695 Temp = (UINT8 *)Buffer;\r
696 \r
697 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->Desc = 0x8A;\r
698 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->Len = 0x2B;\r
699 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->ResType = 2;\r
700 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->GenFlag = 0; \r
701 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->SpecificFlag = 0;\r
702 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrSpaceGranularity = 0;\r
703 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrRangeMin = BusStart;\r
704 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrRangeMax = 0;\r
705 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrTranslationOffset = 0; \r
706 ((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Temp)->AddrLen = BusEnd - BusStart + 1;\r
707 \r
708 Temp = Temp + sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r
709 ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Desc = 0x79; \r
710 ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Checksum = 0x0;\r
711 \r
712 *Configuration = Buffer; \r
713 return EFI_SUCCESS;\r
714 }\r
715 List = List->ForwardLink;\r
716 }\r
717 \r
718 return EFI_INVALID_PARAMETER;\r
719}\r
720\r
721/**\r
722 Programs the PCI root bridge hardware so that it decodes the specified PCI bus range.\r
723\r
724 This member function programs the specified PCI root bridge to decode the bus range that is\r
725 specified by the input parameter Configuration.\r
726 The bus range information is specified in terms of the ACPI 2.0 resource descriptor format.\r
727\r
728 @param[in] This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance\r
729 @param[in] RootBridgeHandle The PCI Root Bridge whose bus range is to be programmed\r
730 @param[in] Configuration The pointer to the PCI bus resource descriptor\r
731 \r
732 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r
733 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
734 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.\r
735 @retval EFI_INVALID_PARAMETER Configuration does not include a valid ACPI 2.0 bus resource descriptor.\r
736 @retval EFI_INVALID_PARAMETER Configuration includes valid ACPI 2.0 resource descriptors other than \r
737 bus descriptors.\r
738 @retval EFI_INVALID_PARAMETER Configuration contains one or more invalid ACPI resource descriptors.\r
739 @retval EFI_INVALID_PARAMETER "Address Range Minimum" is invalid for this root bridge.\r
740 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this root bridge.\r
741 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.\r
742 @retval EFI_SUCCESS The bus range for the PCI root bridge was programmed.\r
743\r
744**/\r
745EFI_STATUS\r
746EFIAPI\r
747SetBusNumbers(\r
748 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
749 IN EFI_HANDLE RootBridgeHandle,\r
750 IN VOID *Configuration\r
751 )\r
752{\r
753 LIST_ENTRY *List; \r
754 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
755 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
756 UINT8 *Ptr;\r
757 UINTN BusStart;\r
758 UINTN BusEnd;\r
759 UINTN BusLen;\r
760 \r
761 if (Configuration == NULL) {\r
762 return EFI_INVALID_PARAMETER;\r
763 }\r
764 \r
765 Ptr = Configuration;\r
766 \r
767 //\r
768 // Check the Configuration is valid\r
769 //\r
770 if(*Ptr != ACPI_ADDRESS_SPACE_DESCRIPTOR) {\r
771 return EFI_INVALID_PARAMETER;\r
772 }\r
773 \r
774 if (((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Ptr)->ResType != 2) {\r
775 return EFI_INVALID_PARAMETER;\r
776 }\r
777\r
778 Ptr += sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r
779 if (*Ptr != ACPI_END_TAG_DESCRIPTOR) {\r
780 return EFI_INVALID_PARAMETER;\r
781 }\r
782 \r
783 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
784 List = HostBridgeInstance->Head.ForwardLink;\r
785 \r
786 Ptr = Configuration;\r
787 \r
788 while (List != &HostBridgeInstance->Head) {\r
789 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
790 if (RootBridgeHandle == RootBridgeInstance->Handle) {\r
791 BusStart = (UINTN)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Ptr)->AddrRangeMin;\r
792 BusLen = (UINTN)((EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Ptr)->AddrLen;\r
793 BusEnd = BusStart + BusLen - 1;\r
794 \r
795 if (BusStart > BusEnd) {\r
796 return EFI_INVALID_PARAMETER;\r
797 }\r
798 \r
799 if ((BusStart < RootBridgeInstance->BusBase) || (BusEnd > RootBridgeInstance->BusLimit)) {\r
800 return EFI_INVALID_PARAMETER;\r
801 }\r
802 \r
803 //\r
804 // Update the Bus Range\r
805 //\r
806 RootBridgeInstance->ResAllocNode[TypeBus].Base = BusStart;\r
807 RootBridgeInstance->ResAllocNode[TypeBus].Length = BusLen;\r
808 RootBridgeInstance->ResAllocNode[TypeBus].Status = ResAllocated;\r
809 \r
810 //\r
811 // Program the Root Bridge Hardware\r
812 //\r
813 \r
814 return EFI_SUCCESS;\r
815 }\r
816 \r
817 List = List->ForwardLink;\r
818 }\r
819 \r
820 return EFI_INVALID_PARAMETER;\r
821}\r
822\r
823\r
824/**\r
825 Submits the I/O and memory resource requirements for the specified PCI root bridge.\r
826\r
827 This function is used to submit all the I/O and memory resources that are required by the specified\r
828 PCI root bridge. The input parameter Configuration is used to specify the following:\r
829 - The various types of resources that are required\r
830 - The associated lengths in terms of ACPI 2.0 resource descriptor format\r
831\r
832 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.\r
833 @param[in] RootBridgeHandle The PCI root bridge whose I/O and memory resource requirements are being submitted.\r
834 @param[in] Configuration The pointer to the PCI I/O and PCI memory resource descriptor.\r
835 \r
836 @retval EFI_SUCCESS The I/O and memory resource requests for a PCI root bridge were accepted.\r
837 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r
838 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
839 @retval EFI_INVALID_PARAMETER Configuration does not point to a valid ACPI 2.0 resource descriptor.\r
840 @retval EFI_INVALID_PARAMETER Configuration includes requests for one or more resource types that are \r
841 not supported by this PCI root bridge. This error will happen if the caller \r
842 did not combine resources according to Attributes that were returned by\r
843 GetAllocAttributes().\r
844 @retval EFI_INVALID_PARAMETER Address Range Maximum" is invalid.\r
845 @retval EFI_INVALID_PARAMETER "Address Range Length" is invalid for this PCI root bridge.\r
846 @retval EFI_INVALID_PARAMETER "Address Space Granularity" is invalid for this PCI root bridge.\r
847\r
848**/\r
849EFI_STATUS\r
850EFIAPI\r
851SubmitResources(\r
852 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
853 IN EFI_HANDLE RootBridgeHandle,\r
854 IN VOID *Configuration\r
855 )\r
856{\r
857 LIST_ENTRY *List; \r
858 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
859 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
860 UINT8 *Temp;\r
861 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Ptr;\r
862 UINT64 AddrLen;\r
863 UINT64 Alignment;\r
864 \r
865 //\r
866 // Check the input parameter: Configuration\r
867 //\r
868 if (Configuration == NULL) {\r
869 return EFI_INVALID_PARAMETER;\r
870 }\r
871 \r
872 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
873 List = HostBridgeInstance->Head.ForwardLink;\r
874 \r
875 Temp = (UINT8 *)Configuration;\r
876 while ( *Temp == 0x8A) { \r
877 Temp += sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) ;\r
878 }\r
879 if (*Temp != 0x79) {\r
880 return EFI_INVALID_PARAMETER;\r
881 }\r
882 \r
883 Temp = (UINT8 *)Configuration;\r
884 while (List != &HostBridgeInstance->Head) {\r
885 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
886 if (RootBridgeHandle == RootBridgeInstance->Handle) {\r
887 while ( *Temp == 0x8A) {\r
888 Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Temp ;\r
889\r
890 //\r
891 // Check Address Length\r
892 //\r
893 if (Ptr->AddrLen > 0xffffffff) {\r
894 return EFI_INVALID_PARAMETER;\r
895 }\r
896\r
897 //\r
898 // Check address range alignment\r
899 //\r
900 if (Ptr->AddrRangeMax >= 0xffffffff || Ptr->AddrRangeMax != (GetPowerOfTwo64 (Ptr->AddrRangeMax + 1) - 1)) {\r
901 return EFI_INVALID_PARAMETER;\r
902 }\r
903 \r
904 switch (Ptr->ResType) {\r
905\r
906 case 0:\r
907 \r
908 //\r
909 // Check invalid Address Sapce Granularity\r
910 //\r
911 if (Ptr->AddrSpaceGranularity != 32) {\r
912 return EFI_INVALID_PARAMETER;\r
913 }\r
914 \r
915 //\r
916 // check the memory resource request is supported by PCI root bridge\r
917 //\r
918 if (RootBridgeInstance->RootBridgeAttrib == EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM &&\r
919 Ptr->SpecificFlag == 0x06) {\r
920 return EFI_INVALID_PARAMETER;\r
921 }\r
922 \r
923 AddrLen = Ptr->AddrLen;\r
924 Alignment = Ptr->AddrRangeMax;\r
925 if (Ptr->AddrSpaceGranularity == 32) {\r
926 if (Ptr->SpecificFlag == 0x06) {\r
927 //\r
928 // Apply from GCD\r
929 //\r
930 RootBridgeInstance->ResAllocNode[TypePMem32].Status = ResSubmitted;\r
931 } else {\r
932 RootBridgeInstance->ResAllocNode[TypeMem32].Length = AddrLen;\r
933 RootBridgeInstance->ResAllocNode[TypeMem32].Alignment = Alignment;\r
934 RootBridgeInstance->ResAllocNode[TypeMem32].Status = ResRequested; \r
935 HostBridgeInstance->ResourceSubmited = TRUE;\r
936 }\r
937 }\r
938\r
939 if (Ptr->AddrSpaceGranularity == 64) {\r
940 if (Ptr->SpecificFlag == 0x06) {\r
941 RootBridgeInstance->ResAllocNode[TypePMem64].Status = ResSubmitted;\r
942 } else {\r
943 RootBridgeInstance->ResAllocNode[TypeMem64].Status = ResSubmitted;\r
944 }\r
945 }\r
946 break;\r
947\r
948 case 1:\r
949 AddrLen = (UINTN) Ptr->AddrLen;\r
950 Alignment = (UINTN) Ptr->AddrRangeMax;\r
951 RootBridgeInstance->ResAllocNode[TypeIo].Length = AddrLen;\r
952 RootBridgeInstance->ResAllocNode[TypeIo].Alignment = Alignment;\r
953 RootBridgeInstance->ResAllocNode[TypeIo].Status = ResRequested;\r
954 HostBridgeInstance->ResourceSubmited = TRUE; \r
955 break;\r
956\r
957 default:\r
958 break;\r
959 };\r
960 \r
961 Temp += sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) ;\r
962 } \r
963 \r
964 return EFI_SUCCESS;\r
965 }\r
966 \r
967 List = List->ForwardLink;\r
968 }\r
969 \r
970 return EFI_INVALID_PARAMETER;\r
971}\r
972\r
973/**\r
974 Returns the proposed resource settings for the specified PCI root bridge.\r
975\r
976 This member function returns the proposed resource settings for the specified PCI root bridge. The\r
977 proposed resource settings are prepared when NotifyPhase() is called with a Phase of\r
978 EfiPciHostBridgeAllocateResources. The output parameter Configuration\r
979 specifies the following:\r
980 - The various types of resources, excluding bus resources, that are allocated\r
981 - The associated lengths in terms of ACPI 2.0 resource descriptor format\r
982\r
983 @param[in] This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.\r
984 @param[in] RootBridgeHandle The PCI root bridge handle. Type EFI_HANDLE is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.\r
985 @param[out] Configuration The pointer to the pointer to the PCI I/O and memory resource descriptor.\r
986 \r
987 @retval EFI_SUCCESS The requested parameters were returned.\r
988 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r
989 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error.\r
990 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
991\r
992**/\r
993EFI_STATUS\r
994EFIAPI\r
995GetProposedResources(\r
996 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
997 IN EFI_HANDLE RootBridgeHandle,\r
998 OUT VOID **Configuration\r
999 )\r
1000{\r
1001 LIST_ENTRY *List; \r
1002 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
1003 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
1004 UINTN Index;\r
1005 UINTN Number; \r
1006 VOID *Buffer; \r
1007 UINT8 *Temp;\r
1008 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Ptr;\r
1009 UINT64 ResStatus;\r
1010 \r
1011 Buffer = NULL;\r
1012 Number = 0;\r
1013 //\r
1014 // Get the Host Bridge Instance from the resource allocation protocol\r
1015 //\r
1016 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
1017 List = HostBridgeInstance->Head.ForwardLink;\r
1018 \r
1019 //\r
1020 // Enumerate the root bridges in this host bridge\r
1021 //\r
1022 while (List != &HostBridgeInstance->Head) {\r
1023 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
1024 if (RootBridgeHandle == RootBridgeInstance->Handle) {\r
1025 for (Index = 0; Index < TypeBus; Index ++) {\r
1026 if (RootBridgeInstance->ResAllocNode[Index].Status != ResNone) {\r
1027 Number ++;\r
1028 } \r
1029 }\r
1030 \r
1031 if (Number == 0) {\r
1032 return EFI_INVALID_PARAMETER;\r
1033 }\r
1034\r
1035 Buffer = AllocateZeroPool (Number * sizeof(EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR) + sizeof(EFI_ACPI_END_TAG_DESCRIPTOR));\r
1036 if (Buffer == NULL) {\r
1037 return EFI_OUT_OF_RESOURCES;\r
1038 }\r
1039 \r
1040 Temp = Buffer;\r
1041 for (Index = 0; Index < TypeBus; Index ++) {\r
1042 if (RootBridgeInstance->ResAllocNode[Index].Status != ResNone) {\r
1043 Ptr = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Temp ;\r
1044 ResStatus = RootBridgeInstance->ResAllocNode[Index].Status;\r
1045 \r
1046 switch (Index) {\r
1047\r
1048 case TypeIo:\r
1049 //\r
1050 // Io\r
1051 //\r
1052 Ptr->Desc = 0x8A;\r
1053 Ptr->Len = 0x2B;\r
1054 Ptr->ResType = 1;\r
1055 Ptr->GenFlag = 0; \r
1056 Ptr->SpecificFlag = 0;\r
1057 Ptr->AddrRangeMin = RootBridgeInstance->ResAllocNode[Index].Base;\r
1058 Ptr->AddrRangeMax = 0;\r
1059 Ptr->AddrTranslationOffset = \\r
1060 (ResStatus == ResAllocated) ? EFI_RESOURCE_SATISFIED : EFI_RESOURCE_LESS;\r
1061 Ptr->AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r
1062 break;\r
1063\r
1064 case TypeMem32:\r
1065 //\r
1066 // Memory 32\r
1067 // \r
1068 Ptr->Desc = 0x8A;\r
1069 Ptr->Len = 0x2B;\r
1070 Ptr->ResType = 0;\r
1071 Ptr->GenFlag = 0; \r
1072 Ptr->SpecificFlag = 0;\r
1073 Ptr->AddrSpaceGranularity = 32;\r
1074 Ptr->AddrRangeMin = RootBridgeInstance->ResAllocNode[Index].Base;\r
1075 Ptr->AddrRangeMax = 0;\r
1076 Ptr->AddrTranslationOffset = \\r
1077 (ResStatus == ResAllocated) ? EFI_RESOURCE_SATISFIED : EFI_RESOURCE_LESS; \r
1078 Ptr->AddrLen = RootBridgeInstance->ResAllocNode[Index].Length;\r
1079 break;\r
1080\r
1081 case TypePMem32:\r
1082 //\r
1083 // Prefetch memory 32\r
1084 //\r
1085 Ptr->Desc = 0x8A;\r
1086 Ptr->Len = 0x2B;\r
1087 Ptr->ResType = 0;\r
1088 Ptr->GenFlag = 0; \r
1089 Ptr->SpecificFlag = 6;\r
1090 Ptr->AddrSpaceGranularity = 32;\r
1091 Ptr->AddrRangeMin = 0;\r
1092 Ptr->AddrRangeMax = 0;\r
1093 Ptr->AddrTranslationOffset = EFI_RESOURCE_NONEXISTENT; \r
1094 Ptr->AddrLen = 0;\r
1095 break;\r
1096\r
1097 case TypeMem64:\r
1098 //\r
1099 // Memory 64\r
1100 //\r
1101 Ptr->Desc = 0x8A;\r
1102 Ptr->Len = 0x2B;\r
1103 Ptr->ResType = 0;\r
1104 Ptr->GenFlag = 0; \r
1105 Ptr->SpecificFlag = 0;\r
1106 Ptr->AddrSpaceGranularity = 64;\r
1107 Ptr->AddrRangeMin = 0;\r
1108 Ptr->AddrRangeMax = 0;\r
1109 Ptr->AddrTranslationOffset = EFI_RESOURCE_NONEXISTENT; \r
1110 Ptr->AddrLen = 0;\r
1111 break;\r
1112\r
1113 case TypePMem64:\r
1114 //\r
1115 // Prefetch memory 64\r
1116 //\r
1117 Ptr->Desc = 0x8A;\r
1118 Ptr->Len = 0x2B;\r
1119 Ptr->ResType = 0;\r
1120 Ptr->GenFlag = 0; \r
1121 Ptr->SpecificFlag = 6;\r
1122 Ptr->AddrSpaceGranularity = 64;\r
1123 Ptr->AddrRangeMin = 0;\r
1124 Ptr->AddrRangeMax = 0;\r
1125 Ptr->AddrTranslationOffset = EFI_RESOURCE_NONEXISTENT; \r
1126 Ptr->AddrLen = 0;\r
1127 break;\r
1128 };\r
1129 \r
1130 Temp += sizeof (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR);\r
1131 } \r
1132 }\r
1133 \r
1134 ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Desc = 0x79; \r
1135 ((EFI_ACPI_END_TAG_DESCRIPTOR *)Temp)->Checksum = 0x0;\r
1136 \r
1137 *Configuration = Buffer; \r
1138 \r
1139 return EFI_SUCCESS;\r
1140 }\r
1141 \r
1142 List = List->ForwardLink;\r
1143 }\r
1144 \r
1145 return EFI_INVALID_PARAMETER;\r
1146}\r
1147\r
1148/**\r
1149 Provides the hooks from the PCI bus driver to every PCI controller (device/function) at various\r
1150 stages of the PCI enumeration process that allow the host bridge driver to preinitialize individual\r
1151 PCI controllers before enumeration.\r
1152\r
1153 This function is called during the PCI enumeration process. No specific action is expected from this\r
1154 member function. It allows the host bridge driver to preinitialize individual PCI controllers before\r
1155 enumeration.\r
1156\r
1157 @param This Pointer to the EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.\r
1158 @param RootBridgeHandle The associated PCI root bridge handle. Type EFI_HANDLE is defined in\r
1159 InstallProtocolInterface() in the UEFI 2.0 Specification.\r
1160 @param PciAddress The address of the PCI device on the PCI bus. This address can be passed to the\r
1161 EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL member functions to access the PCI\r
1162 configuration space of the device. See Table 12-1 in the UEFI 2.0 Specification for\r
1163 the definition of EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS.\r
1164 @param Phase The phase of the PCI device enumeration. \r
1165 \r
1166 @retval EFI_SUCCESS The requested parameters were returned.\r
1167 @retval EFI_INVALID_PARAMETER RootBridgeHandle is not a valid root bridge handle.\r
1168 @retval EFI_INVALID_PARAMETER Phase is not a valid phase that is defined in\r
1169 EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE.\r
1170 @retval EFI_DEVICE_ERROR Programming failed due to a hardware error. The PCI enumerator should\r
1171 not enumerate this device, including its child devices if it is a PCI-to-PCI\r
1172 bridge.\r
1173\r
1174**/\r
1175EFI_STATUS\r
1176EFIAPI\r
1177PreprocessController (\r
1178 IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,\r
1179 IN EFI_HANDLE RootBridgeHandle,\r
1180 IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress,\r
1181 IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase\r
1182 )\r
1183{\r
1184 PCI_HOST_BRIDGE_INSTANCE *HostBridgeInstance;\r
1185 PCI_ROOT_BRIDGE_INSTANCE *RootBridgeInstance;\r
1186 LIST_ENTRY *List; \r
1187\r
1188 HostBridgeInstance = INSTANCE_FROM_RESOURCE_ALLOCATION_THIS (This);\r
1189 List = HostBridgeInstance->Head.ForwardLink;\r
1190\r
1191 //\r
1192 // Enumerate the root bridges in this host bridge\r
1193 //\r
1194 while (List != &HostBridgeInstance->Head) {\r
1195 RootBridgeInstance = DRIVER_INSTANCE_FROM_LIST_ENTRY (List);\r
1196 if (RootBridgeHandle == RootBridgeInstance->Handle) {\r
1197 break;\r
1198 }\r
1199 List = List->ForwardLink;\r
1200 }\r
1201 if (List == &HostBridgeInstance->Head) {\r
1202 return EFI_INVALID_PARAMETER;\r
1203 }\r
1204\r
1205 if ((UINT32)Phase > EfiPciBeforeResourceCollection) {\r
1206 return EFI_INVALID_PARAMETER;\r
1207 }\r
1208\r
1209 return EFI_SUCCESS;\r
1210}\r