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