PciPlatform.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /** @file
  2. Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. #include <PiDxe.h>
  6. #include "PciPlatform.h"
  7. #include <Library/PcdLib.h>
  8. #ifdef EFI_PCI_IOV_SUPPORT
  9. #include "PciIovPlatformPolicy.h"
  10. #endif
  11. PCI_PLATFORM_PRIVATE_DATA mPciPrivateData;
  12. BOOLEAN FirstCall = TRUE;
  13. UINT8 sSataRaidLoadEfiDriverOption;
  14. UINT8 SataRaidLoadEfiDriverOption;
  15. UINT8 BootNetworkOption;
  16. /**
  17. Set the PciPolicy as EFI_RESERVE_ISA_IO_NO_ALIAS | EFI_RESERVE_VGA_IO_NO_ALIAS.
  18. @param This - The pointer to the Protocol itself.
  19. PciPolicy - the returned Policy.
  20. @retval EFI_UNSUPPORTED - Function not supported.
  21. @retval EFI_INVALID_PARAMETER - Invalid PciPolicy value.
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. GetPlatformPolicy (
  26. IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
  27. OUT EFI_PCI_PLATFORM_POLICY *PciPolicy
  28. )
  29. {
  30. if (PciPolicy == NULL) {
  31. return EFI_INVALID_PARAMETER;
  32. }
  33. return EFI_UNSUPPORTED;
  34. }
  35. /**
  36. Return a PCI ROM image for the onboard device represented by PciHandle.
  37. @param This - Protocol instance pointer.
  38. PciHandle - PCI device to return the ROM image for.
  39. RomImage - PCI Rom Image for onboard device.
  40. RomSize - Size of RomImage in bytes.
  41. @retval EFI_SUCCESS - RomImage is valid.
  42. @retval EFI_NOT_FOUND - No RomImage.
  43. **/
  44. EFI_STATUS
  45. EFIAPI
  46. GetPciRom (
  47. IN CONST EFI_PCI_PLATFORM_PROTOCOL *This,
  48. IN EFI_HANDLE PciHandle,
  49. OUT VOID **RomImage,
  50. OUT UINTN *RomSize
  51. )
  52. {
  53. return EFI_NOT_FOUND;
  54. }
  55. /**
  56. GC_TODO: Add function description
  57. @param This - GC_TODO: add argument description
  58. @param Function - GC_TODO: add argument description
  59. @param Phase - GC_TODO: add argument description
  60. @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
  61. @retval EFI_INVALID_PARAMETER - GC_TODO: Add description for return value
  62. @retval EFI_UNSUPPORTED - GC_TODO: Add description for return value
  63. @retval EFI_SUCCESS - GC_TODO: Add description for return value
  64. **/
  65. EFI_STATUS
  66. EFIAPI
  67. RegisterPciCallback (
  68. IN EFI_PCI_CALLBACK_PROTOCOL *This,
  69. IN EFI_PCI_CALLBACK_FUNC Function,
  70. IN EFI_PCI_ENUMERATION_PHASE Phase
  71. )
  72. {
  73. LIST_ENTRY *NodeEntry;
  74. PCI_CALLBACK_DATA *PciCallbackData;
  75. if (Function == NULL) {
  76. return EFI_INVALID_PARAMETER;
  77. }
  78. if ( (Phase & (EfiPciEnumerationDeviceScanning | EfiPciEnumerationBusNumberAssigned \
  79. | EfiPciEnumerationResourceAssigned)) == 0) {
  80. return EFI_INVALID_PARAMETER;
  81. }
  82. //
  83. // Check if the node has been added
  84. //
  85. NodeEntry = GetFirstNode (&mPciPrivateData.PciCallbackList);
  86. while (!IsNull (&mPciPrivateData.PciCallbackList, NodeEntry)) {
  87. PciCallbackData = PCI_CALLBACK_DATA_FROM_LINK (NodeEntry);
  88. if (PciCallbackData->Function == Function) {
  89. return EFI_UNSUPPORTED;
  90. }
  91. NodeEntry = GetNextNode (&mPciPrivateData.PciCallbackList, NodeEntry);
  92. }
  93. PciCallbackData = NULL;
  94. PciCallbackData = AllocateZeroPool (sizeof (PCI_CALLBACK_DATA));
  95. ASSERT (PciCallbackData != NULL);
  96. if(PciCallbackData != NULL){
  97. PciCallbackData->Signature = PCI_CALLBACK_DATA_SIGNATURE;
  98. PciCallbackData->Function = Function;
  99. PciCallbackData->Phase = Phase;
  100. InsertTailList (&mPciPrivateData.PciCallbackList, &PciCallbackData->Link);
  101. return EFI_SUCCESS;
  102. } else {
  103. return EFI_UNSUPPORTED;
  104. }
  105. }
  106. /**
  107. Main Entry point of the Pci Platform Driver.
  108. @param ImageHandle - Handle to the image.
  109. @param SystemTable - Handle to System Table.
  110. @retval EFI_STATUS - Status of the function calling.
  111. **/
  112. EFI_STATUS
  113. EFIAPI
  114. PciPlatformDriverEntry (
  115. IN EFI_HANDLE ImageHandle,
  116. IN EFI_SYSTEM_TABLE *SystemTable
  117. )
  118. {
  119. EFI_STATUS Status;
  120. ZeroMem (&mPciPrivateData, sizeof (mPciPrivateData));
  121. InitializeListHead (&mPciPrivateData.PciCallbackList);
  122. mPciPrivateData.PciPlatform.PlatformNotify = PhaseNotify;
  123. mPciPrivateData.PciPlatform.PlatformPrepController = PlatformPrepController;
  124. mPciPrivateData.PciPlatform.GetPlatformPolicy = GetPlatformPolicy;
  125. mPciPrivateData.PciPlatform.GetPciRom = GetPciRom;
  126. mPciPrivateData.PciCallback.RegisterPciCallback = RegisterPciCallback;
  127. #ifdef EFI_PCI_IOV_SUPPORT
  128. mPciPrivateData.PciIovPlatform.GetSystemLowestPageSize = GetSystemLowestPageSize;
  129. mPciPrivateData.PciIovPlatform.GetPlatformPolicy = GetIovPlatformPolicy;
  130. #endif
  131. //
  132. // Install on a new handle
  133. //
  134. Status = gBS->InstallMultipleProtocolInterfaces (
  135. &mPciPrivateData.PciPlatformHandle,
  136. &gEfiPciPlatformProtocolGuid,
  137. &mPciPrivateData.PciPlatform,
  138. &gEfiPciCallbackProtocolGuid,
  139. &mPciPrivateData.PciCallback,
  140. #ifdef EFI_PCI_IOV_SUPPORT
  141. &gEfiPciIovPlatformProtocolGuid,
  142. &mPciPrivateData.PciIovPlatform,
  143. #endif
  144. NULL
  145. );
  146. return Status;
  147. }