]> git.proxmox.com Git - mirror_edk2.git/blob - QuarkSocPkg/QuarkNorthCluster/QNCInit/Dxe/LegacyRegion.c
QuarkSocPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / QuarkSocPkg / QuarkNorthCluster / QNCInit / Dxe / LegacyRegion.c
1 /** @file
2 QNC Legacy Region Driver
3
4 Copyright (c) 2013-2015 Intel Corporation.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "CommonHeader.h"
11 #include "LegacyRegion.h"
12
13 //
14 // Handle used to install the Legacy Region Protocol
15 //
16 EFI_HANDLE mLegacyRegion2Handle = NULL;
17
18 //
19 // Instance of the Legacy Region Protocol to install into the handle database
20 //
21 EFI_LEGACY_REGION2_PROTOCOL mLegacyRegion2 = {
22 LegacyRegion2Decode,
23 LegacyRegion2Lock,
24 LegacyRegion2BootLock,
25 LegacyRegion2Unlock,
26 LegacyRegionGetInfo
27 };
28
29
30 /**
31 Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
32
33 If the On parameter evaluates to TRUE, this function enables memory reads in the address range
34 Start to (Start + Length - 1).
35 If the On parameter evaluates to FALSE, this function disables memory reads in the address range
36 Start to (Start + Length - 1).
37
38 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
39 @param Start[in] The beginning of the physical address of the region whose attributes
40 should be modified.
41 @param Length[in] The number of bytes of memory whose attributes should be modified.
42 The actual number of bytes modified may be greater than the number
43 specified.
44 @param Granularity[out] The number of bytes in the last region affected. This may be less
45 than the total number of bytes affected if the starting address
46 was not aligned to a region's starting address or if the length
47 was greater than the number of bytes in the first region.
48 @param On[in] Decode / Non-Decode flag.
49
50 @retval EFI_SUCCESS The region's attributes were successfully modified.
51 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
52
53 **/
54 EFI_STATUS
55 EFIAPI
56 LegacyRegion2Decode (
57 IN EFI_LEGACY_REGION2_PROTOCOL *This,
58 IN UINT32 Start,
59 IN UINT32 Length,
60 OUT UINT32 *Granularity,
61 IN BOOLEAN *On
62 )
63 {
64 return QNCLegacyRegionManipulation (Start, Length, On, NULL, Granularity);
65 }
66
67
68 /**
69 Modify the hardware to disallow memory attribute changes in a region.
70
71 This function makes the attributes of a region read only. Once a region is boot-locked with this
72 function, the read and write attributes of that region cannot be changed until a power cycle has
73 reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
74
75 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
76 @param Start[in] The beginning of the physical address of the region whose
77 attributes should be modified.
78 @param Length[in] The number of bytes of memory whose attributes should be modified.
79 The actual number of bytes modified may be greater than the number
80 specified.
81 @param Granularity[out] The number of bytes in the last region affected. This may be less
82 than the total number of bytes affected if the starting address was
83 not aligned to a region's starting address or if the length was
84 greater than the number of bytes in the first region.
85
86 @retval EFI_SUCCESS The region's attributes were successfully modified.
87 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
88 @retval EFI_UNSUPPORTED The chipset does not support locking the configuration registers in
89 a way that will not affect memory regions outside the legacy memory
90 region.
91
92 **/
93 EFI_STATUS
94 EFIAPI
95 LegacyRegion2BootLock (
96 IN EFI_LEGACY_REGION2_PROTOCOL *This,
97 IN UINT32 Start,
98 IN UINT32 Length,
99 OUT UINT32 *Granularity
100 )
101 {
102 if ((Start < 0xC0000) || ((Start + Length - 1) > 0xFFFFF)) {
103 return EFI_INVALID_PARAMETER;
104 }
105
106 return EFI_UNSUPPORTED;
107 }
108
109
110 /**
111 Modify the hardware to disallow memory writes in a region.
112
113 This function changes the attributes of a memory range to not allow writes.
114
115 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
116 @param Start[in] The beginning of the physical address of the region whose
117 attributes should be modified.
118 @param Length[in] The number of bytes of memory whose attributes should be modified.
119 The actual number of bytes modified may be greater than the number
120 specified.
121 @param Granularity[out] The number of bytes in the last region affected. This may be less
122 than the total number of bytes affected if the starting address was
123 not aligned to a region's starting address or if the length was
124 greater than the number of bytes in the first region.
125
126 @retval EFI_SUCCESS The region's attributes were successfully modified.
127 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
128
129 **/
130 EFI_STATUS
131 EFIAPI
132 LegacyRegion2Lock (
133 IN EFI_LEGACY_REGION2_PROTOCOL *This,
134 IN UINT32 Start,
135 IN UINT32 Length,
136 OUT UINT32 *Granularity
137 )
138 {
139 BOOLEAN WriteEnable;
140
141 WriteEnable = FALSE;
142 return QNCLegacyRegionManipulation (Start, Length, NULL, &WriteEnable, Granularity);
143 }
144
145
146 /**
147 Modify the hardware to allow memory writes in a region.
148
149 This function changes the attributes of a memory range to allow writes.
150
151 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
152 @param Start[in] The beginning of the physical address of the region whose
153 attributes should be modified.
154 @param Length[in] The number of bytes of memory whose attributes should be modified.
155 The actual number of bytes modified may be greater than the number
156 specified.
157 @param Granularity[out] The number of bytes in the last region affected. This may be less
158 than the total number of bytes affected if the starting address was
159 not aligned to a region's starting address or if the length was
160 greater than the number of bytes in the first region.
161
162 @retval EFI_SUCCESS The region's attributes were successfully modified.
163 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
164
165 **/
166 EFI_STATUS
167 EFIAPI
168 LegacyRegion2Unlock (
169 IN EFI_LEGACY_REGION2_PROTOCOL *This,
170 IN UINT32 Start,
171 IN UINT32 Length,
172 OUT UINT32 *Granularity
173 )
174 {
175 BOOLEAN WriteEnable;
176
177 WriteEnable = TRUE;
178 return QNCLegacyRegionManipulation (Start, Length, NULL, &WriteEnable, 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
209 return EFI_UNSUPPORTED;
210 }
211
212 /**
213 Entry point to the DXE Driver that produces the Legacy Region Protocol.
214
215 @retval EFI_SUCCESS One or more of the drivers returned a success code.
216 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
217
218 **/
219 EFI_STATUS
220 LegacyRegionInit (
221 )
222 {
223 EFI_STATUS Status;
224
225 //
226 // Install the Legacy Region Protocol on a new handle
227 //
228 Status = gBS->InstallMultipleProtocolInterfaces (
229 &mLegacyRegion2Handle,
230 &gEfiLegacyRegion2ProtocolGuid, &mLegacyRegion2,
231 NULL
232 );
233
234 ASSERT_EFI_ERROR (Status);
235
236 return Status;
237 }