2 Helper routines with common PEI / DXE implementation.
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"
18 CHAR16
*mPlatTypeNameTable
[] = { EFI_PLATFORM_TYPE_NAME_TABLE_DEFINITION
};
19 UINTN mPlatTypeNameTableLen
= ((sizeof(mPlatTypeNameTable
)) / sizeof (CHAR16
*));
22 // Routines defined in other source modules of this component.
26 // Routines local to this source module.
30 // Routines shared with other souce modules in this component.
34 WriteFirstFreeSpiProtect (
35 IN CONST UINT32 PchRootComplexBar
,
36 IN CONST UINT32 DirectValue
,
37 IN CONST UINT32 BaseAddress
,
38 IN CONST UINT32 Length
,
46 ASSERT (PchRootComplexBar
> 0);
49 if (OffsetPtr
!= NULL
) {
52 if (MmioRead32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR0
) == 0) {
53 Offset
= R_QNC_RCRB_SPIPBR0
;
55 if (MmioRead32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR1
) == 0) {
56 Offset
= R_QNC_RCRB_SPIPBR1
;
58 if (MmioRead32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR2
) == 0) {
59 Offset
= R_QNC_RCRB_SPIPBR2
;
64 if (DirectValue
== 0) {
65 StepLen
= ALIGN_VALUE (Length
,SIZE_4KB
); // Bring up to 4K boundary.
66 RegVal
= BaseAddress
+ StepLen
- 1;
67 RegVal
&= 0x00FFF000; // Set EDS Protected Range Limit (PRL).
68 RegVal
|= ((BaseAddress
>> 12) & 0xfff); // or in EDS Protected Range Base (PRB).
75 RegVal
|= B_QNC_RCRB_SPIPBRn_WPE
;
76 MmioWrite32 (PchRootComplexBar
+ Offset
, RegVal
);
77 if (RegVal
== MmioRead32 (PchRootComplexBar
+ Offset
)) {
78 if (OffsetPtr
!= NULL
) {
83 return EFI_DEVICE_ERROR
;
89 // Routines exported by this component.
93 Read 8bit character from debug stream.
95 Block until character is read.
97 @return 8bit character read from debug stream.
102 PlatformDebugPortGetChar8 (
109 if (SerialPortPoll ()) {
110 if (SerialPortRead ((UINT8
*) &Got
, 1) == 1) {
120 Clear SPI Protect registers.
122 @retval EFI_SUCCESS SPI protect registers cleared.
123 @retval EFI_ACCESS_DENIED Unable to clear SPI protect registers.
128 PlatformClearSpiProtect (
132 UINT32 PchRootComplexBar
;
134 PchRootComplexBar
= QNC_RCRB_BASE
;
136 // Check if the SPI interface has been locked-down.
138 if ((MmioRead16 (PchRootComplexBar
+ R_QNC_RCRB_SPIS
) & B_QNC_RCRB_SPIS_SCL
) != 0) {
139 return EFI_ACCESS_DENIED
;
141 MmioWrite32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR0
, 0);
142 if (MmioRead32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR0
) != 0) {
143 return EFI_ACCESS_DENIED
;
145 MmioWrite32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR1
, 0);
146 if (MmioRead32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR0
) != 0) {
147 return EFI_ACCESS_DENIED
;
149 MmioWrite32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR2
, 0);
150 if (MmioRead32 (PchRootComplexBar
+ R_QNC_RCRB_SPIPBR0
) != 0) {
151 return EFI_ACCESS_DENIED
;
157 Determine if an SPI address range is protected.
159 @param SpiBaseAddress Base of SPI range.
160 @param Length Length of SPI range.
162 @retval TRUE Range is protected.
163 @retval FALSE Range is not protected.
167 PlatformIsSpiRangeProtected (
168 IN CONST UINT32 SpiBaseAddress
,
169 IN CONST UINT32 Length
175 UINT32 ProtectedBase
;
176 UINT32 ProtectedLimit
;
177 UINT32 PchRootComplexBar
;
179 PchRootComplexBar
= QNC_RCRB_BASE
;
182 Offset
= R_QNC_RCRB_SPIPBR0
;
183 Limit
= SpiBaseAddress
+ (Length
- 1);
185 RegVal
= MmioRead32 (PchRootComplexBar
+ Offset
);
186 if ((RegVal
& B_QNC_RCRB_SPIPBRn_WPE
) != 0) {
187 ProtectedBase
= (RegVal
& 0xfff) << 12;
188 ProtectedLimit
= (RegVal
& 0x00fff000) + 0xfff;
189 if (SpiBaseAddress
>= ProtectedBase
&& Limit
<= ProtectedLimit
) {
193 if (Offset
== R_QNC_RCRB_SPIPBR0
) {
194 Offset
= R_QNC_RCRB_SPIPBR1
;
195 } else if (Offset
== R_QNC_RCRB_SPIPBR1
) {
196 Offset
= R_QNC_RCRB_SPIPBR2
;
206 Set Legacy GPIO Level
208 @param LevelRegOffset GPIO level register Offset from GPIO Base Address.
209 @param GpioNum GPIO bit to change.
210 @param HighLevel If TRUE set GPIO High else Set GPIO low.
215 PlatformLegacyGpioSetLevel (
216 IN CONST UINT32 LevelRegOffset
,
217 IN CONST UINT32 GpioNum
,
218 IN CONST BOOLEAN HighLevel
222 UINT32 GpioBaseAddress
;
225 GpioBaseAddress
= LpcPciCfg32 (R_QNC_LPC_GBA_BASE
) & B_QNC_LPC_GPA_BASE_MASK
;
226 ASSERT (GpioBaseAddress
> 0);
228 RegValue
= IoRead32 (GpioBaseAddress
+ LevelRegOffset
);
229 GpioNumMask
= (1 << GpioNum
);
231 RegValue
|= (GpioNumMask
);
233 RegValue
&= ~(GpioNumMask
);
235 IoWrite32 (GpioBaseAddress
+ LevelRegOffset
, RegValue
);
239 Get Legacy GPIO Level
241 @param LevelRegOffset GPIO level register Offset from GPIO Base Address.
242 @param GpioNum GPIO bit to check.
244 @retval TRUE If bit is SET.
245 @retval FALSE If bit is CLEAR.
250 PlatformLegacyGpioGetLevel (
251 IN CONST UINT32 LevelRegOffset
,
252 IN CONST UINT32 GpioNum
256 UINT32 GpioBaseAddress
;
259 GpioBaseAddress
= LpcPciCfg32 (R_QNC_LPC_GBA_BASE
) & B_QNC_LPC_GPA_BASE_MASK
;
260 RegValue
= IoRead32 (GpioBaseAddress
+ LevelRegOffset
);
261 GpioNumMask
= (1 << GpioNum
);
262 return ((RegValue
& GpioNumMask
) != 0);