2 QNC Legacy Region Driver
4 Copyright (c) 2013-2015 Intel Corporation.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "CommonHeader.h"
11 #include "LegacyRegion.h"
14 // Handle used to install the Legacy Region Protocol
16 EFI_HANDLE mLegacyRegion2Handle
= NULL
;
19 // Instance of the Legacy Region Protocol to install into the handle database
21 EFI_LEGACY_REGION2_PROTOCOL mLegacyRegion2
= {
24 LegacyRegion2BootLock
,
31 Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
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).
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
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
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.
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.
57 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
60 OUT UINT32
*Granularity
,
64 return QNCLegacyRegionManipulation (Start
, Length
, On
, NULL
, Granularity
);
69 Modify the hardware to disallow memory attribute changes in a region.
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.
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
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.
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
95 LegacyRegion2BootLock (
96 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
99 OUT UINT32
*Granularity
102 if ((Start
< 0xC0000) || ((Start
+ Length
- 1) > 0xFFFFF)) {
103 return EFI_INVALID_PARAMETER
;
106 return EFI_UNSUPPORTED
;
111 Modify the hardware to disallow memory writes in a region.
113 This function changes the attributes of a memory range to not allow writes.
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
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.
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.
133 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
136 OUT UINT32
*Granularity
142 return QNCLegacyRegionManipulation (Start
, Length
, NULL
, &WriteEnable
, Granularity
);
147 Modify the hardware to allow memory writes in a region.
149 This function changes the attributes of a memory range to allow writes.
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
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.
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.
168 LegacyRegion2Unlock (
169 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
172 OUT UINT32
*Granularity
178 return QNCLegacyRegionManipulation (Start
, Length
, NULL
, &WriteEnable
, Granularity
);
182 Get region information for the attributes of the Legacy Region.
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.
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
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.
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.
202 LegacyRegionGetInfo (
203 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
204 OUT UINT32
*DescriptorCount
,
205 OUT EFI_LEGACY_REGION_DESCRIPTOR
**Descriptor
209 return EFI_UNSUPPORTED
;
213 Entry point to the DXE Driver that produces the Legacy Region Protocol.
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.
226 // Install the Legacy Region Protocol on a new handle
228 Status
= gBS
->InstallMultipleProtocolInterfaces (
229 &mLegacyRegion2Handle
,
230 &gEfiLegacyRegion2ProtocolGuid
, &mLegacyRegion2
,
234 ASSERT_EFI_ERROR (Status
);