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