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