ArmVirtPciHostBridgeUtilityLib.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /** @file
  2. PCI Host Bridge utility functions for ArmVirt.
  3. Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <IndustryStandard/Acpi10.h>
  7. #include <IndustryStandard/Pci.h>
  8. #include <Library/BaseMemoryLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/DevicePathLib.h>
  11. #include <Library/MemoryAllocationLib.h>
  12. #include <Library/PciHostBridgeLib.h>
  13. #include <Library/PciHostBridgeUtilityLib.h>
  14. #include <Library/PciLib.h>
  15. #pragma pack(1)
  16. typedef struct {
  17. ACPI_HID_DEVICE_PATH AcpiDevicePath;
  18. EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
  19. } EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;
  20. #pragma pack ()
  21. GLOBAL_REMOVE_IF_UNREFERENCED
  22. CHAR16 *mPciHostBridgeAcpiAddressSpaceTypeStr[] = {
  23. L"Mem",
  24. L"I/O",
  25. L"Bus"
  26. };
  27. STATIC CONST EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath = {
  28. {
  29. {
  30. ACPI_DEVICE_PATH,
  31. ACPI_DP,
  32. {
  33. (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)),
  34. (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
  35. }
  36. },
  37. EISA_PNP_ID (0x0A03), // HID
  38. 0 // UID
  39. },
  40. {
  41. END_DEVICE_PATH_TYPE,
  42. END_ENTIRE_DEVICE_PATH_SUBTYPE,
  43. {
  44. END_DEVICE_PATH_LENGTH,
  45. 0
  46. }
  47. }
  48. };
  49. GLOBAL_REMOVE_IF_UNREFERENCED
  50. CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] = {
  51. L"Mem", L"I/O", L"Bus"
  52. };
  53. STATIC PCI_ROOT_BRIDGE mRootBridge;
  54. /**
  55. Utility function to return all the root bridge instances in an array.
  56. @param [out] Count The number of root bridge instances.
  57. @param [in] Attributes Initial attributes.
  58. @param [in] AllocationAttributes Allocation attributes.
  59. @param [in] DmaAbove4G DMA above 4GB memory.
  60. @param [in] NoExtendedConfigSpace No Extended Config Space.
  61. @param [in] BusMin Minimum Bus number, inclusive.
  62. @param [in] BusMax Maximum Bus number, inclusive.
  63. @param [in] Io IO aperture.
  64. @param [in] Mem MMIO aperture.
  65. @param [in] MemAbove4G MMIO aperture above 4G.
  66. @param [in] PMem Prefetchable MMIO aperture.
  67. @param [in] PMemAbove4G Prefetchable MMIO aperture above 4G.
  68. @return All the root bridge instances in an array.
  69. **/
  70. PCI_ROOT_BRIDGE *
  71. EFIAPI
  72. PciHostBridgeUtilityGetRootBridges (
  73. OUT UINTN *Count,
  74. IN UINT64 Attributes,
  75. IN UINT64 AllocationAttributes,
  76. IN BOOLEAN DmaAbove4G,
  77. IN BOOLEAN NoExtendedConfigSpace,
  78. IN UINTN BusMin,
  79. IN UINTN BusMax,
  80. IN PCI_ROOT_BRIDGE_APERTURE *Io,
  81. IN PCI_ROOT_BRIDGE_APERTURE *Mem,
  82. IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
  83. IN PCI_ROOT_BRIDGE_APERTURE *PMem,
  84. IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G
  85. )
  86. {
  87. if ((Count == NULL) ||
  88. (Io == NULL) ||
  89. (Mem == NULL) ||
  90. (MemAbove4G == NULL) ||
  91. (PMem == NULL) ||
  92. (PMemAbove4G == NULL))
  93. {
  94. return NULL;
  95. }
  96. *Count = 1;
  97. mRootBridge.Segment = 0;
  98. mRootBridge.Supports = Attributes;
  99. mRootBridge.Attributes = Attributes;
  100. mRootBridge.DmaAbove4G = DmaAbove4G;
  101. mRootBridge.NoExtendedConfigSpace = NoExtendedConfigSpace;
  102. mRootBridge.ResourceAssigned = FALSE;
  103. mRootBridge.AllocationAttributes = AllocationAttributes;
  104. mRootBridge.Bus.Base = BusMin;
  105. mRootBridge.Bus.Limit = BusMax;
  106. mRootBridge.Io.Base = Io->Base;
  107. mRootBridge.Io.Limit = Io->Limit;
  108. mRootBridge.Mem.Base = Mem->Base;
  109. mRootBridge.Mem.Limit = Mem->Limit;
  110. mRootBridge.MemAbove4G.Base = MemAbove4G->Base;
  111. mRootBridge.MemAbove4G.Limit = MemAbove4G->Limit;
  112. mRootBridge.PMem.Base = PMem->Base;
  113. mRootBridge.PMem.Limit = PMem->Limit;
  114. mRootBridge.PMemAbove4G.Base = PMemAbove4G->Base;
  115. mRootBridge.PMemAbove4G.Limit = PMemAbove4G->Limit;
  116. mRootBridge.DevicePath =
  117. (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridgeDevicePath;
  118. return &mRootBridge;
  119. }
  120. /**
  121. Utility function to free root bridge instances array from
  122. PciHostBridgeUtilityGetRootBridges().
  123. @param[in] Bridges The root bridge instances array.
  124. @param[in] Count The count of the array.
  125. **/
  126. VOID
  127. EFIAPI
  128. PciHostBridgeUtilityFreeRootBridges (
  129. IN PCI_ROOT_BRIDGE *Bridges,
  130. IN UINTN Count
  131. )
  132. {
  133. // Nothing to do here.
  134. }
  135. /**
  136. Utility function to inform the platform that the resource conflict happens.
  137. @param[in] Configuration Pointer to PCI I/O and PCI memory resource
  138. descriptors. The Configuration contains the
  139. resources for all the root bridges. The resource
  140. for each root bridge is terminated with END
  141. descriptor and an additional END is appended
  142. indicating the end of the entire resources. The
  143. resource descriptor field values follow the
  144. description in
  145. EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
  146. .SubmitResources().
  147. **/
  148. VOID
  149. EFIAPI
  150. PciHostBridgeUtilityResourceConflict (
  151. IN VOID *Configuration
  152. )
  153. {
  154. EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;
  155. UINTN RootBridgeIndex;
  156. DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n"));
  157. RootBridgeIndex = 0;
  158. Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)Configuration;
  159. while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
  160. DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));
  161. for ( ; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
  162. ASSERT (
  163. Descriptor->ResType <
  164. ARRAY_SIZE (mPciHostBridgeAcpiAddressSpaceTypeStr)
  165. );
  166. DEBUG ((
  167. DEBUG_ERROR,
  168. " %s: Length/Alignment = 0x%lx / 0x%lx\n",
  169. mPciHostBridgeAcpiAddressSpaceTypeStr[Descriptor->ResType],
  170. Descriptor->AddrLen,
  171. Descriptor->AddrRangeMax
  172. ));
  173. if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {
  174. DEBUG ((
  175. DEBUG_ERROR,
  176. " Granularity/SpecificFlag = %ld / %02x%s\n",
  177. Descriptor->AddrSpaceGranularity,
  178. Descriptor->SpecificFlag,
  179. ((Descriptor->SpecificFlag &
  180. EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE
  181. ) != 0) ? L" (Prefetchable)" : L""
  182. ));
  183. }
  184. }
  185. //
  186. // Skip the END descriptor for root bridge
  187. //
  188. ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR);
  189. Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(
  190. (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1
  191. );
  192. }
  193. }