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