LegacyRegion.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /** @file
  2. Legacy Region Support
  3. Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _LEGACY_REGION_DXE_H_
  7. #define _LEGACY_REGION_DXE_H_
  8. #include <PiDxe.h>
  9. #include <Protocol/LegacyRegion2.h>
  10. #include <IndustryStandard/Pci.h>
  11. #include <IndustryStandard/Q35MchIch9.h>
  12. #include <IndustryStandard/I440FxPiix4.h>
  13. #include <Library/PciLib.h>
  14. #include <Library/PcdLib.h>
  15. #include <Library/DebugLib.h>
  16. #include <Library/MemoryAllocationLib.h>
  17. #include <Library/UefiBootServicesTableLib.h>
  18. #define PAM_BASE_ADDRESS 0xc0000
  19. #define PAM_LIMIT_ADDRESS BASE_1MB
  20. //
  21. // Describes Legacy Region blocks and status.
  22. //
  23. typedef struct {
  24. UINT32 Start;
  25. UINT32 Length;
  26. BOOLEAN ReadEnabled;
  27. BOOLEAN WriteEnabled;
  28. } LEGACY_MEMORY_SECTION_INFO;
  29. //
  30. // Provides a map of the PAM registers and bits used to set Read/Write access.
  31. //
  32. typedef struct {
  33. UINTN PAMRegPciLibAddress;
  34. UINT8 ReadEnableData;
  35. UINT8 WriteEnableData;
  36. } PAM_REGISTER_VALUE;
  37. /**
  38. Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
  39. If the On parameter evaluates to TRUE, this function enables memory reads in the address range
  40. Start to (Start + Length - 1).
  41. If the On parameter evaluates to FALSE, this function disables memory reads in the address range
  42. Start to (Start + Length - 1).
  43. @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
  44. @param Start[in] The beginning of the physical address of the region whose attributes
  45. should be modified.
  46. @param Length[in] The number of bytes of memory whose attributes should be modified.
  47. The actual number of bytes modified may be greater than the number
  48. specified.
  49. @param Granularity[out] The number of bytes in the last region affected. This may be less
  50. than the total number of bytes affected if the starting address
  51. was not aligned to a region's starting address or if the length
  52. was greater than the number of bytes in the first region.
  53. @param On[in] Decode / Non-Decode flag.
  54. @retval EFI_SUCCESS The region's attributes were successfully modified.
  55. @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
  56. **/
  57. EFI_STATUS
  58. EFIAPI
  59. LegacyRegion2Decode (
  60. IN EFI_LEGACY_REGION2_PROTOCOL *This,
  61. IN UINT32 Start,
  62. IN UINT32 Length,
  63. OUT UINT32 *Granularity,
  64. IN BOOLEAN *On
  65. );
  66. /**
  67. Modify the hardware to disallow memory writes in a region.
  68. This function changes the attributes of a memory range to not allow writes.
  69. @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
  70. @param Start[in] The beginning of the physical address of the region whose
  71. attributes should be modified.
  72. @param Length[in] The number of bytes of memory whose attributes should be modified.
  73. The actual number of bytes modified may be greater than the number
  74. specified.
  75. @param Granularity[out] The number of bytes in the last region affected. This may be less
  76. than the total number of bytes affected if the starting address was
  77. not aligned to a region's starting address or if the length was
  78. greater than the number of bytes in the first region.
  79. @retval EFI_SUCCESS The region's attributes were successfully modified.
  80. @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
  81. **/
  82. EFI_STATUS
  83. EFIAPI
  84. LegacyRegion2Lock (
  85. IN EFI_LEGACY_REGION2_PROTOCOL *This,
  86. IN UINT32 Start,
  87. IN UINT32 Length,
  88. OUT UINT32 *Granularity
  89. );
  90. /**
  91. Modify the hardware to disallow memory attribute changes in a region.
  92. This function makes the attributes of a region read only. Once a region is boot-locked with this
  93. function, the read and write attributes of that region cannot be changed until a power cycle has
  94. reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
  95. @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
  96. @param Start[in] The beginning of the physical address of the region whose
  97. attributes should be modified.
  98. @param Length[in] The number of bytes of memory whose attributes should be modified.
  99. The actual number of bytes modified may be greater than the number
  100. specified.
  101. @param Granularity[out] The number of bytes in the last region affected. This may be less
  102. than the total number of bytes affected if the starting address was
  103. not aligned to a region's starting address or if the length was
  104. greater than the number of bytes in the first region.
  105. @retval EFI_SUCCESS The region's attributes were successfully modified.
  106. @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
  107. @retval EFI_UNSUPPORTED The chipset does not support locking the configuration registers in
  108. a way that will not affect memory regions outside the legacy memory
  109. region.
  110. **/
  111. EFI_STATUS
  112. EFIAPI
  113. LegacyRegion2BootLock (
  114. IN EFI_LEGACY_REGION2_PROTOCOL *This,
  115. IN UINT32 Start,
  116. IN UINT32 Length,
  117. OUT UINT32 *Granularity
  118. );
  119. /**
  120. Modify the hardware to allow memory writes in a region.
  121. This function changes the attributes of a memory range to allow writes.
  122. @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
  123. @param Start[in] The beginning of the physical address of the region whose
  124. attributes should be modified.
  125. @param Length[in] The number of bytes of memory whose attributes should be modified.
  126. The actual number of bytes modified may be greater than the number
  127. specified.
  128. @param Granularity[out] The number of bytes in the last region affected. This may be less
  129. than the total number of bytes affected if the starting address was
  130. not aligned to a region's starting address or if the length was
  131. greater than the number of bytes in the first region.
  132. @retval EFI_SUCCESS The region's attributes were successfully modified.
  133. @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
  134. **/
  135. EFI_STATUS
  136. EFIAPI
  137. LegacyRegion2Unlock (
  138. IN EFI_LEGACY_REGION2_PROTOCOL *This,
  139. IN UINT32 Start,
  140. IN UINT32 Length,
  141. OUT UINT32 *Granularity
  142. );
  143. /**
  144. Get region information for the attributes of the Legacy Region.
  145. This function is used to discover the granularity of the attributes for the memory in the legacy
  146. region. Each attribute may have a different granularity and the granularity may not be the same
  147. for all memory ranges in the legacy region.
  148. @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
  149. @param DescriptorCount[out] The number of region descriptor entries returned in the Descriptor
  150. buffer.
  151. @param Descriptor[out] A pointer to a pointer used to return a buffer where the legacy
  152. region information is deposited. This buffer will contain a list of
  153. DescriptorCount number of region descriptors. This function will
  154. provide the memory for the buffer.
  155. @retval EFI_SUCCESS The region's attributes were successfully modified.
  156. @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
  157. **/
  158. EFI_STATUS
  159. EFIAPI
  160. LegacyRegionGetInfo (
  161. IN EFI_LEGACY_REGION2_PROTOCOL *This,
  162. OUT UINT32 *DescriptorCount,
  163. OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor
  164. );
  165. #endif