]> git.proxmox.com Git - mirror_edk2.git/blame - QuarkSocPkg/QuarkNorthCluster/QNCInit/Dxe/LegacyRegion.c
QuarkSocPkg/QncSmmDispatcher: Fix context passed to SMI handlers
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / QNCInit / Dxe / LegacyRegion.c
CommitLineData
9b6bbcdb
MK
1/** @file\r
2QNC Legacy Region Driver\r
3\r
4Copyright (c) 2013-2015 Intel Corporation.\r
5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "CommonHeader.h"\r
17#include "LegacyRegion.h"\r
18\r
19//\r
20// Handle used to install the Legacy Region Protocol\r
21//\r
22EFI_HANDLE mLegacyRegion2Handle = NULL;\r
23\r
24//\r
25// Instance of the Legacy Region Protocol to install into the handle database\r
26//\r
27EFI_LEGACY_REGION2_PROTOCOL mLegacyRegion2 = {\r
28 LegacyRegion2Decode,\r
29 LegacyRegion2Lock,\r
30 LegacyRegion2BootLock,\r
31 LegacyRegion2Unlock,\r
32 LegacyRegionGetInfo\r
33};\r
34\r
35\r
36/**\r
37 Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.\r
38\r
39 If the On parameter evaluates to TRUE, this function enables memory reads in the address range\r
40 Start to (Start + Length - 1).\r
41 If the On parameter evaluates to FALSE, this function disables memory reads in the address range\r
42 Start to (Start + Length - 1).\r
43\r
44 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.\r
45 @param Start[in] The beginning of the physical address of the region whose attributes\r
46 should be modified.\r
47 @param Length[in] The number of bytes of memory whose attributes should be modified.\r
48 The actual number of bytes modified may be greater than the number\r
49 specified.\r
50 @param Granularity[out] The number of bytes in the last region affected. This may be less\r
51 than the total number of bytes affected if the starting address\r
52 was not aligned to a region's starting address or if the length\r
53 was greater than the number of bytes in the first region.\r
54 @param On[in] Decode / Non-Decode flag.\r
55\r
56 @retval EFI_SUCCESS The region's attributes were successfully modified.\r
57 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.\r
58\r
59**/\r
60EFI_STATUS\r
61EFIAPI\r
62LegacyRegion2Decode (\r
63 IN EFI_LEGACY_REGION2_PROTOCOL *This,\r
64 IN UINT32 Start,\r
65 IN UINT32 Length,\r
66 OUT UINT32 *Granularity,\r
67 IN BOOLEAN *On\r
68 )\r
69{\r
70 return QNCLegacyRegionManipulation (Start, Length, On, NULL, Granularity);\r
71}\r
72\r
73\r
74/**\r
75 Modify the hardware to disallow memory attribute changes in a region.\r
76\r
77 This function makes the attributes of a region read only. Once a region is boot-locked with this\r
78 function, the read and write attributes of that region cannot be changed until a power cycle has\r
79 reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.\r
80\r
81 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.\r
82 @param Start[in] The beginning of the physical address of the region whose\r
83 attributes should be modified.\r
84 @param Length[in] The number of bytes of memory whose attributes should be modified.\r
85 The actual number of bytes modified may be greater than the number\r
86 specified.\r
87 @param Granularity[out] The number of bytes in the last region affected. This may be less\r
88 than the total number of bytes affected if the starting address was\r
89 not aligned to a region's starting address or if the length was\r
90 greater than the number of bytes in the first region.\r
91\r
92 @retval EFI_SUCCESS The region's attributes were successfully modified.\r
93 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.\r
94 @retval EFI_UNSUPPORTED The chipset does not support locking the configuration registers in\r
95 a way that will not affect memory regions outside the legacy memory\r
96 region.\r
97\r
98**/\r
99EFI_STATUS\r
100EFIAPI\r
101LegacyRegion2BootLock (\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 )\r
107{\r
108 if ((Start < 0xC0000) || ((Start + Length - 1) > 0xFFFFF)) {\r
109 return EFI_INVALID_PARAMETER;\r
110 }\r
111\r
112 return EFI_UNSUPPORTED;\r
113}\r
114\r
115\r
116/**\r
117 Modify the hardware to disallow memory writes in a region.\r
118\r
119 This function changes the attributes of a memory range to not allow writes.\r
120\r
121 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.\r
122 @param Start[in] The beginning of the physical address of the region whose\r
123 attributes should be modified.\r
124 @param Length[in] The number of bytes of memory whose attributes should be modified.\r
125 The actual number of bytes modified may be greater than the number\r
126 specified.\r
127 @param Granularity[out] The number of bytes in the last region affected. This may be less\r
128 than the total number of bytes affected if the starting address was\r
129 not aligned to a region's starting address or if the length was\r
130 greater than the number of bytes in the first region.\r
131\r
132 @retval EFI_SUCCESS The region's attributes were successfully modified.\r
133 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.\r
134\r
135**/\r
136EFI_STATUS\r
137EFIAPI\r
138LegacyRegion2Lock (\r
139 IN EFI_LEGACY_REGION2_PROTOCOL *This,\r
140 IN UINT32 Start,\r
141 IN UINT32 Length,\r
142 OUT UINT32 *Granularity\r
143 )\r
144{\r
145 BOOLEAN WriteEnable;\r
146\r
147 WriteEnable = FALSE;\r
148 return QNCLegacyRegionManipulation (Start, Length, NULL, &WriteEnable, Granularity);\r
149}\r
150\r
151\r
152/**\r
153 Modify the hardware to allow memory writes in a region.\r
154\r
155 This function changes the attributes of a memory range to allow writes.\r
156\r
157 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.\r
158 @param Start[in] The beginning of the physical address of the region whose\r
159 attributes should be modified.\r
160 @param Length[in] The number of bytes of memory whose attributes should be modified.\r
161 The actual number of bytes modified may be greater than the number\r
162 specified.\r
163 @param Granularity[out] The number of bytes in the last region affected. This may be less\r
164 than the total number of bytes affected if the starting address was\r
165 not aligned to a region's starting address or if the length was\r
166 greater than the number of bytes in the first region.\r
167\r
168 @retval EFI_SUCCESS The region's attributes were successfully modified.\r
169 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.\r
170\r
171**/\r
172EFI_STATUS\r
173EFIAPI\r
174LegacyRegion2Unlock (\r
175 IN EFI_LEGACY_REGION2_PROTOCOL *This,\r
176 IN UINT32 Start,\r
177 IN UINT32 Length,\r
178 OUT UINT32 *Granularity\r
179 )\r
180{\r
181 BOOLEAN WriteEnable;\r
182\r
183 WriteEnable = TRUE;\r
184 return QNCLegacyRegionManipulation (Start, Length, NULL, &WriteEnable, Granularity);\r
185}\r
186\r
187/**\r
188 Get region information for the attributes of the Legacy Region.\r
189\r
190 This function is used to discover the granularity of the attributes for the memory in the legacy\r
191 region. Each attribute may have a different granularity and the granularity may not be the same\r
192 for all memory ranges in the legacy region.\r
193\r
194 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.\r
195 @param DescriptorCount[out] The number of region descriptor entries returned in the Descriptor\r
196 buffer.\r
197 @param Descriptor[out] A pointer to a pointer used to return a buffer where the legacy\r
198 region information is deposited. This buffer will contain a list of\r
199 DescriptorCount number of region descriptors. This function will\r
200 provide the memory for the buffer.\r
201\r
202 @retval EFI_SUCCESS The region's attributes were successfully modified.\r
203 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.\r
204\r
205**/\r
206EFI_STATUS\r
207EFIAPI\r
208LegacyRegionGetInfo (\r
209 IN EFI_LEGACY_REGION2_PROTOCOL *This,\r
210 OUT UINT32 *DescriptorCount,\r
211 OUT EFI_LEGACY_REGION_DESCRIPTOR **Descriptor\r
212 )\r
213{\r
214\r
215 return EFI_UNSUPPORTED;\r
216}\r
217\r
218/**\r
219 Entry point to the DXE Driver that produces the Legacy Region Protocol.\r
220\r
221 @retval EFI_SUCCESS One or more of the drivers returned a success code.\r
222 @retval !EFI_SUCESS The return status from the last driver entry point in the list.\r
223\r
224**/\r
225EFI_STATUS\r
226LegacyRegionInit (\r
227 )\r
228{\r
229 EFI_STATUS Status;\r
230\r
231 //\r
232 // Install the Legacy Region Protocol on a new handle\r
233 //\r
234 Status = gBS->InstallMultipleProtocolInterfaces (\r
235 &mLegacyRegion2Handle,\r
236 &gEfiLegacyRegion2ProtocolGuid, &mLegacyRegion2,\r
237 NULL\r
238 );\r
239\r
240 ASSERT_EFI_ERROR (Status);\r
241\r
242 return Status;\r
243}\r