]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Csm/CsmSupportLib/LegacyRegion.h
OvmfPkg/CsmSupportLib: move PAM register addresses to IndustryStandard
[mirror_edk2.git] / OvmfPkg / Csm / CsmSupportLib / LegacyRegion.h
1 /** @file
2 Legacy Region Support
3
4 Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials are
7 licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _LEGACY_REGION_DXE_H_
17 #define _LEGACY_REGION_DXE_H_
18
19 #include <PiDxe.h>
20
21 #include <Protocol/LegacyRegion2.h>
22
23 #include <IndustryStandard/Pci.h>
24 #include <IndustryStandard/Q35MchIch9.h>
25 #include <IndustryStandard/I440FxPiix4.h>
26
27 #include <Library/PciLib.h>
28 #include <Library/PcdLib.h>
29 #include <Library/DebugLib.h>
30 #include <Library/MemoryAllocationLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32
33 #define PAM_BASE_ADDRESS 0xc0000
34 #define PAM_LIMIT_ADDRESS BASE_1MB
35
36 //
37 // Describes Legacy Region blocks and status.
38 //
39 typedef struct {
40 UINT32 Start;
41 UINT32 Length;
42 BOOLEAN ReadEnabled;
43 BOOLEAN WriteEnabled;
44 } LEGACY_MEMORY_SECTION_INFO;
45
46 //
47 // Provides a map of the PAM registers and bits used to set Read/Write access.
48 //
49 typedef struct {
50 UINTN PAMRegPciLibAddress;
51 UINT8 ReadEnableData;
52 UINT8 WriteEnableData;
53 } PAM_REGISTER_VALUE;
54
55 /**
56 Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
57
58 If the On parameter evaluates to TRUE, this function enables memory reads in the address range
59 Start to (Start + Length - 1).
60 If the On parameter evaluates to FALSE, this function disables memory reads in the address range
61 Start to (Start + Length - 1).
62
63 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
64 @param Start[in] The beginning of the physical address of the region whose attributes
65 should be modified.
66 @param Length[in] The number of bytes of memory whose attributes should be modified.
67 The actual number of bytes modified may be greater than the number
68 specified.
69 @param Granularity[out] The number of bytes in the last region affected. This may be less
70 than the total number of bytes affected if the starting address
71 was not aligned to a region's starting address or if the length
72 was greater than the number of bytes in the first region.
73 @param On[in] Decode / Non-Decode flag.
74
75 @retval EFI_SUCCESS The region's attributes were successfully modified.
76 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
77
78 **/
79 EFI_STATUS
80 EFIAPI
81 LegacyRegion2Decode (
82 IN EFI_LEGACY_REGION2_PROTOCOL *This,
83 IN UINT32 Start,
84 IN UINT32 Length,
85 OUT UINT32 *Granularity,
86 IN BOOLEAN *On
87 );
88
89 /**
90 Modify the hardware to disallow memory writes in a region.
91
92 This function changes the attributes of a memory range to not allow writes.
93
94 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
95 @param Start[in] The beginning of the physical address of the region whose
96 attributes should be modified.
97 @param Length[in] The number of bytes of memory whose attributes should be modified.
98 The actual number of bytes modified may be greater than the number
99 specified.
100 @param Granularity[out] The number of bytes in the last region affected. This may be less
101 than the total number of bytes affected if the starting address was
102 not aligned to a region's starting address or if the length was
103 greater than the number of bytes in the first region.
104
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
108 **/
109 EFI_STATUS
110 EFIAPI
111 LegacyRegion2Lock (
112 IN EFI_LEGACY_REGION2_PROTOCOL *This,
113 IN UINT32 Start,
114 IN UINT32 Length,
115 OUT UINT32 *Granularity
116 );
117
118 /**
119 Modify the hardware to disallow memory attribute changes in a region.
120
121 This function makes the attributes of a region read only. Once a region is boot-locked with this
122 function, the read and write attributes of that region cannot be changed until a power cycle has
123 reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
124
125 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
126 @param Start[in] The beginning of the physical address of the region whose
127 attributes should be modified.
128 @param Length[in] The number of bytes of memory whose attributes should be modified.
129 The actual number of bytes modified may be greater than the number
130 specified.
131 @param Granularity[out] The number of bytes in the last region affected. This may be less
132 than the total number of bytes affected if the starting address was
133 not aligned to a region's starting address or if the length was
134 greater than the number of bytes in the first region.
135
136 @retval EFI_SUCCESS The region's attributes were successfully modified.
137 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
138 @retval EFI_UNSUPPORTED The chipset does not support locking the configuration registers in
139 a way that will not affect memory regions outside the legacy memory
140 region.
141
142 **/
143 EFI_STATUS
144 EFIAPI
145 LegacyRegion2BootLock (
146 IN EFI_LEGACY_REGION2_PROTOCOL *This,
147 IN UINT32 Start,
148 IN UINT32 Length,
149 OUT UINT32 *Granularity
150 );
151
152 /**
153 Modify the hardware to allow memory writes in a region.
154
155 This function changes the attributes of a memory range to allow writes.
156
157 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
158 @param Start[in] The beginning of the physical address of the region whose
159 attributes should be modified.
160 @param Length[in] The number of bytes of memory whose attributes should be modified.
161 The actual number of bytes modified may be greater than the number
162 specified.
163 @param Granularity[out] The number of bytes in the last region affected. This may be less
164 than the total number of bytes affected if the starting address was
165 not aligned to a region's starting address or if the length was
166 greater than the number of bytes in the first region.
167
168 @retval EFI_SUCCESS The region's attributes were successfully modified.
169 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
170
171 **/
172 EFI_STATUS
173 EFIAPI
174 LegacyRegion2Unlock (
175 IN EFI_LEGACY_REGION2_PROTOCOL *This,
176 IN UINT32 Start,
177 IN UINT32 Length,
178 OUT UINT32 *Granularity
179 );
180
181 /**
182 Get region information for the attributes of the Legacy Region.
183
184 This function is used to discover the granularity of the attributes for the memory in the legacy
185 region. Each attribute may have a different granularity and the granularity may not be the same
186 for all memory ranges in the legacy region.
187
188 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
189 @param DescriptorCount[out] The number of region descriptor entries returned in the Descriptor
190 buffer.
191 @param Descriptor[out] A pointer to a pointer used to return a buffer where the legacy
192 region information is deposited. This buffer will contain a list of
193 DescriptorCount number of region descriptors. This function will
194 provide the memory for the buffer.
195
196 @retval EFI_SUCCESS The region's attributes were successfully modified.
197 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 LegacyRegionGetInfo (
203 IN EFI_LEGACY_REGION2_PROTOCOL *This,
204 OUT UINT32 *DescriptorCount,
205 OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor
206 );
207
208 #endif
209