2 QNC Legacy Region Driver
4 Copyright (c) 2013-2015 Intel Corporation.
6 This program and the accompanying materials
7 are 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
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.
16 #include "CommonHeader.h"
17 #include "LegacyRegion.h"
20 // Handle used to install the Legacy Region Protocol
22 EFI_HANDLE mLegacyRegion2Handle
= NULL
;
25 // Instance of the Legacy Region Protocol to install into the handle database
27 EFI_LEGACY_REGION2_PROTOCOL mLegacyRegion2
= {
30 LegacyRegion2BootLock
,
37 Modify the hardware to allow (decode) or disallow (not decode) memory reads in a region.
39 If the On parameter evaluates to TRUE, this function enables memory reads in the address range
40 Start to (Start + Length - 1).
41 If the On parameter evaluates to FALSE, this function disables memory reads in the address range
42 Start to (Start + Length - 1).
44 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
45 @param Start[in] The beginning of the physical address of the region whose attributes
47 @param Length[in] The number of bytes of memory whose attributes should be modified.
48 The actual number of bytes modified may be greater than the number
50 @param Granularity[out] The number of bytes in the last region affected. This may be less
51 than the total number of bytes affected if the starting address
52 was not aligned to a region's starting address or if the length
53 was greater than the number of bytes in the first region.
54 @param On[in] Decode / Non-Decode flag.
56 @retval EFI_SUCCESS The region's attributes were successfully modified.
57 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
63 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
66 OUT UINT32
*Granularity
,
70 return QNCLegacyRegionManipulation (Start
, Length
, On
, NULL
, Granularity
);
75 Modify the hardware to disallow memory attribute changes in a region.
77 This function makes the attributes of a region read only. Once a region is boot-locked with this
78 function, the read and write attributes of that region cannot be changed until a power cycle has
79 reset the boot-lock attribute. Calls to Decode(), Lock() and Unlock() will have no effect.
81 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
82 @param Start[in] The beginning of the physical address of the region whose
83 attributes should be modified.
84 @param Length[in] The number of bytes of memory whose attributes should be modified.
85 The actual number of bytes modified may be greater than the number
87 @param Granularity[out] The number of bytes in the last region affected. This may be less
88 than the total number of bytes affected if the starting address was
89 not aligned to a region's starting address or if the length was
90 greater than the number of bytes in the first region.
92 @retval EFI_SUCCESS The region's attributes were successfully modified.
93 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
94 @retval EFI_UNSUPPORTED The chipset does not support locking the configuration registers in
95 a way that will not affect memory regions outside the legacy memory
101 LegacyRegion2BootLock (
102 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
105 OUT UINT32
*Granularity
108 if ((Start
< 0xC0000) || ((Start
+ Length
- 1) > 0xFFFFF)) {
109 return EFI_INVALID_PARAMETER
;
112 return EFI_UNSUPPORTED
;
117 Modify the hardware to disallow memory writes in a region.
119 This function changes the attributes of a memory range to not allow writes.
121 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
122 @param Start[in] The beginning of the physical address of the region whose
123 attributes should be modified.
124 @param Length[in] The number of bytes of memory whose attributes should be modified.
125 The actual number of bytes modified may be greater than the number
127 @param Granularity[out] The number of bytes in the last region affected. This may be less
128 than the total number of bytes affected if the starting address was
129 not aligned to a region's starting address or if the length was
130 greater than the number of bytes in the first region.
132 @retval EFI_SUCCESS The region's attributes were successfully modified.
133 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
139 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
142 OUT UINT32
*Granularity
148 return QNCLegacyRegionManipulation (Start
, Length
, NULL
, &WriteEnable
, Granularity
);
153 Modify the hardware to allow memory writes in a region.
155 This function changes the attributes of a memory range to allow writes.
157 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
158 @param Start[in] The beginning of the physical address of the region whose
159 attributes should be modified.
160 @param Length[in] The number of bytes of memory whose attributes should be modified.
161 The actual number of bytes modified may be greater than the number
163 @param Granularity[out] The number of bytes in the last region affected. This may be less
164 than the total number of bytes affected if the starting address was
165 not aligned to a region's starting address or if the length was
166 greater than the number of bytes in the first region.
168 @retval EFI_SUCCESS The region's attributes were successfully modified.
169 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
174 LegacyRegion2Unlock (
175 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
178 OUT UINT32
*Granularity
184 return QNCLegacyRegionManipulation (Start
, Length
, NULL
, &WriteEnable
, Granularity
);
188 Get region information for the attributes of the Legacy Region.
190 This function is used to discover the granularity of the attributes for the memory in the legacy
191 region. Each attribute may have a different granularity and the granularity may not be the same
192 for all memory ranges in the legacy region.
194 @param This[in] Indicates the EFI_LEGACY_REGION_PROTOCOL instance.
195 @param DescriptorCount[out] The number of region descriptor entries returned in the Descriptor
197 @param Descriptor[out] A pointer to a pointer used to return a buffer where the legacy
198 region information is deposited. This buffer will contain a list of
199 DescriptorCount number of region descriptors. This function will
200 provide the memory for the buffer.
202 @retval EFI_SUCCESS The region's attributes were successfully modified.
203 @retval EFI_INVALID_PARAMETER If Start or Length describe an address not in the Legacy Region.
208 LegacyRegionGetInfo (
209 IN EFI_LEGACY_REGION2_PROTOCOL
*This
,
210 OUT UINT32
*DescriptorCount
,
211 OUT EFI_LEGACY_REGION_DESCRIPTOR
**Descriptor
215 return EFI_UNSUPPORTED
;
219 Entry point to the DXE Driver that produces the Legacy Region Protocol.
221 @retval EFI_SUCCESS One or more of the drivers returned a success code.
222 @retval !EFI_SUCESS The return status from the last driver entry point in the list.
232 // Install the Legacy Region Protocol on a new handle
234 Status
= gBS
->InstallMultipleProtocolInterfaces (
235 &mLegacyRegion2Handle
,
236 &gEfiLegacyRegion2ProtocolGuid
, &mLegacyRegion2
,
240 ASSERT_EFI_ERROR (Status
);