PciHostBridge.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /** @file
  2. @copyright
  3. Copyright 1999 - 2021 Intel Corporation. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _PCI_HOST_BRIDGE_H_
  7. #define _PCI_HOST_BRIDGE_H_
  8. #include <PiDxe.h>
  9. #include <IndustryStandard/Acpi.h>
  10. #include <Library/UefiDriverEntryPoint.h>
  11. #include <Library/MemoryAllocationLib.h>
  12. #include <Library/PciHostBridgeLib.h>
  13. #include <Protocol/PciHostBridgeResourceAllocation.h>
  14. #include <Protocol/IoMmu.h>
  15. #include "PciRootBridge.h"
  16. #define PCI_HOST_BRIDGE_SIGNATURE SIGNATURE_32 ('p', 'h', 'b', 'g')
  17. typedef struct {
  18. UINTN Signature;
  19. EFI_HANDLE Handle;
  20. UINTN RootBridgeCount;
  21. LIST_ENTRY RootBridges;
  22. BOOLEAN ResourceSubmited;
  23. BOOLEAN CanRestarted;
  24. EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL ResAlloc;
  25. } PCI_HOST_BRIDGE_INSTANCE;
  26. #define PCI_HOST_BRIDGE_FROM_THIS(a) CR (a, PCI_HOST_BRIDGE_INSTANCE, ResAlloc, PCI_HOST_BRIDGE_SIGNATURE)
  27. //
  28. // Driver Entry Point
  29. //
  30. /**
  31. Entry point of this driver.
  32. @param ImageHandle - Image handle of this driver.
  33. @param SystemTable - Pointer to standard EFI system table.
  34. @retval EFI_SUCCESS - Succeed.
  35. @retval EFI_DEVICE_ERROR - Fail to install PCI_ROOT_BRIDGE_IO protocol.
  36. **/
  37. EFI_STATUS
  38. EFIAPI
  39. InitializePciHostBridge (
  40. IN EFI_HANDLE ImageHandle,
  41. IN EFI_SYSTEM_TABLE *SystemTable
  42. );
  43. //
  44. // HostBridge Resource Allocation interface
  45. //
  46. /**
  47. Enter a certain phase of the PCI enumeration process.
  48. @param This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL instance.
  49. @param Phase The phase during enumeration.
  50. @retval EFI_SUCCESS Succeed.
  51. @retval EFI_INVALID_PARAMETER Wrong phase parameter passed in.
  52. @retval EFI_NOT_READY Resources have not been submitted yet.
  53. **/
  54. EFI_STATUS
  55. EFIAPI
  56. NotifyPhase (
  57. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  58. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
  59. );
  60. /**
  61. Return the device handle of the next PCI root bridge that is associated with
  62. this Host Bridge.
  63. @param This The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
  64. @param RootBridgeHandle Returns the device handle of the next PCI Root Bridge.
  65. On input, it holds the RootBridgeHandle returned by the most
  66. recent call to GetNextRootBridge().The handle for the first
  67. PCI Root Bridge is returned if RootBridgeHandle is NULL on input.
  68. @retval EFI_SUCCESS Succeed.
  69. @retval EFI_NOT_FOUND Next PCI root bridge not found.
  70. @retval EFI_INVALID_PARAMETER Wrong parameter passed in.
  71. **/
  72. EFI_STATUS
  73. EFIAPI
  74. GetNextRootBridge (
  75. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  76. IN OUT EFI_HANDLE *RootBridgeHandle
  77. );
  78. /**
  79. Returns the attributes of a PCI Root Bridge.
  80. @param This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance
  81. @param RootBridgeHandle - The device handle of the PCI Root Bridge
  82. that the caller is interested in
  83. @param Attributes - The pointer to attributes of the PCI Root Bridge
  84. @retval EFI_SUCCESS - Succeed.
  85. @retval EFI_INVALID_PARAMETER - Attributes parameter passed in is NULL or
  86. @retval RootBridgeHandle is not an EFI_HANDLE
  87. @retval that was returned on a previous call to
  88. @retval GetNextRootBridge().
  89. **/
  90. EFI_STATUS
  91. EFIAPI
  92. GetAttributes (
  93. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  94. IN EFI_HANDLE RootBridgeHandle,
  95. OUT UINT64 *Attributes
  96. );
  97. /**
  98. This is the request from the PCI enumerator to set up
  99. the specified PCI Root Bridge for bus enumeration process.
  100. @param This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
  101. @param RootBridgeHandle - The PCI Root Bridge to be set up.
  102. @param Configuration - Pointer to the pointer to the PCI bus resource descriptor.
  103. @retval EFI_SUCCESS - Succeed.
  104. @retval EFI_OUT_OF_RESOURCES - Not enough pool to be allocated.
  105. @retval EFI_INVALID_PARAMETER - RootBridgeHandle is not a valid handle.
  106. **/
  107. EFI_STATUS
  108. EFIAPI
  109. StartBusEnumeration (
  110. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  111. IN EFI_HANDLE RootBridgeHandle,
  112. OUT VOID **Configuration
  113. );
  114. /**
  115. This function programs the PCI Root Bridge hardware so that
  116. it decodes the specified PCI bus range.
  117. @param This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
  118. @param RootBridgeHandle - The PCI Root Bridge whose bus range is to be programmed.
  119. @param Configuration - The pointer to the PCI bus resource descriptor.
  120. @retval EFI_SUCCESS - Succeed.
  121. @retval EFI_INVALID_PARAMETER - Wrong parameters passed in.
  122. **/
  123. EFI_STATUS
  124. EFIAPI
  125. SetBusNumbers (
  126. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  127. IN EFI_HANDLE RootBridgeHandle,
  128. IN VOID *Configuration
  129. );
  130. /**
  131. Submits the I/O and memory resource requirements for the specified PCI Root Bridge.
  132. @param This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance
  133. @param RootBridgeHandle - The PCI Root Bridge whose I/O and memory resource requirements
  134. are being submitted
  135. @param Configuration - The pointer to the PCI I/O and PCI memory resource descriptor
  136. @retval EFI_SUCCESS - Succeed.
  137. @retval EFI_INVALID_PARAMETER - Wrong parameters passed in.
  138. **/
  139. EFI_STATUS
  140. EFIAPI
  141. SubmitResources (
  142. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  143. IN EFI_HANDLE RootBridgeHandle,
  144. IN VOID *Configuration
  145. );
  146. /**
  147. This function returns the proposed resource settings for the specified
  148. PCI Root Bridge.
  149. @param This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
  150. @param RootBridgeHandle - The PCI Root Bridge handle.
  151. @param Configuration - The pointer to the pointer to the PCI I/O
  152. and memory resource descriptor.
  153. @retval EFI_SUCCESS - Succeed.
  154. @retval EFI_OUT_OF_RESOURCES - Not enough pool to be allocated.
  155. @retval EFI_INVALID_PARAMETER - RootBridgeHandle is not a valid handle.
  156. **/
  157. EFI_STATUS
  158. EFIAPI
  159. GetProposedResources (
  160. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  161. IN EFI_HANDLE RootBridgeHandle,
  162. OUT VOID **Configuration
  163. );
  164. /**
  165. This function is called for all the PCI controllers that the PCI
  166. bus driver finds. Can be used to Preprogram the controller.
  167. @param This - The EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_ PROTOCOL instance.
  168. @param RootBridgeHandle - The PCI Root Bridge handle.
  169. @param PciAddress - Address of the controller on the PCI bus.
  170. @param Phase - The Phase during resource allocation.
  171. @retval EFI_SUCCESS - Succeed.
  172. @retval EFI_INVALID_PARAMETER - RootBridgeHandle is not a valid handle.
  173. **/
  174. EFI_STATUS
  175. EFIAPI
  176. PreprocessController (
  177. IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL *This,
  178. IN EFI_HANDLE RootBridgeHandle,
  179. IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS PciAddress,
  180. IN EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE Phase
  181. );
  182. //
  183. // Host Bridge Silicon specific hooks
  184. //
  185. /**
  186. Returns the Allocation attributes for the BNB Root Bridge.
  187. @param RootBridgeIndex - The root bridge number. 0 based.
  188. @retval EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM | EFI_PCI_HOST_BRIDGE_MEM64_DECODE
  189. **/
  190. UINT64
  191. GetAllocAttributes (
  192. IN UINTN RootBridgeIndex
  193. )
  194. ;
  195. /**
  196. Returns memory apertures for the BNB Root Bridge.
  197. @param PciRootBridgeIo - Pointer to Efi Pci root bridge Io protocol interface instance.
  198. @param Mem32Base - Pointer to 32 bit memory base. This is the lowest 32 bit memory address
  199. that is decoded by the Host Bridge.
  200. @param Mem32Limit - Pointer to 32 bit memory limit.This is the highest 32 bit memory address
  201. that is decoded by the Host Bridge. The size of the 32 bit window is
  202. (Mem32Limit - Mem32base + 1).
  203. @param Mem64Base - Pointer to 64 bit memory base. This is the lowest 64 bit memory address
  204. that is decoded by the Host Bridge.
  205. @param Mem64Limit - Pointer to 64 bit memory limit.This is the highest 64 bit memory address
  206. that is decoded by the Host Bridge. The size of the 64 bit window is
  207. (Mem64Limit - Mem64base + 1). Set Mem64Limit < Mem64Base if the Host bridge
  208. does not support 64 bit memory addresses.
  209. @retval EFI_SUCCESS - Success.
  210. **/
  211. EFI_STATUS
  212. GetHostBridgeMemApertures (
  213. IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *PciRootBridgeIo,
  214. OUT UINT32 *Mem32Base,
  215. OUT UINT32 *Mem32Limit,
  216. OUT UINT64 *Mem64Base,
  217. OUT UINT64 *Mem64Limit
  218. );
  219. /**
  220. Calculate maximum memory length that can be fit to a mtrr.
  221. @param MemoryLength - Input memory length.
  222. @retval Returned Maximum length.
  223. **/
  224. UINT64
  225. Power2MaxMemory (
  226. IN UINT64 MemoryLength
  227. );
  228. extern EDKII_IOMMU_PROTOCOL *mIoMmu;
  229. #endif // _PCI_HOST_BRIDGE_H_