1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/** @file
Margining for PEG Training
@copyright
Copyright (c) 2012 Intel Corporation. All rights reserved
This software and associated documentation (if any) is furnished
under a license and may only be used or copied in accordance
with the terms of the license. Except as permitted by such
license, no part of this software or documentation may be
reproduced, stored in a retrieval system, or transmitted in any
form or by any means without the express written consent of
Intel Corporation.
This file contains an 'Intel Peripheral Driver' and uniquely
identified as "Intel Reference Module" and is
licensed for Intel CPUs and chipsets under the terms of your
license agreement with Intel or your vendor. This file may
be modified by the user, subject to additional terms of the
license agreement
**/
#include "PcieTraining.h"
#ifdef PEG_FLAG
///
/// Jitter Calculations
///
JITTER_SETTING Jitter_Gen3[/* 083.333 */] = {{1, 64, 1, 0}, {1, 33, 2, 0}, {3, 64, 3, 0}, {4, 80, 4, 0}, {5, 97, 5, 0}, {6, 128, 6, 0}, {7, 129, 7, 0}, {8, 161, 8, 0}, {9, 192, 9, 0}, {10, 193, 10, 0}, {11, 225, 11, 0}, {12, 128, 12, 1}, {13, 129, 13, 1}, {14, 145, 14, 1}, {15, 160, 15, 1}, {16, 161, 16, 1}, {17, 177, 17, 1}, {18, 192, 18, 1}, {19, 193, 19, 1}, {20, 209, 20, 1}, {21, 224, 21, 1}, {22, 225, 22, 1}, {23, 241, 23, 1}, {24, 246, 24, 1}};
EFI_STATUS
SetJitterTolerance (
IN UINT8 *LaneList,
IN UINT8 LaneListLength,
IN UINT8 ReportedMargin
)
{
JITTER_SETTING Settings = {0, 0, 0, 0};
UINT8 i;
BOOLEAN Found;
if (ReportedMargin > 0) {
Found = FALSE;
for (i = 0; i < (JITTER_LENGTH - 1); ++i) {
Settings = Jitter_Gen3[i];
if (Settings.ReportedMargin == ReportedMargin) {
Found = TRUE;
break;
}
}
if (Found) {
return SetRawJitterTolerance (
LaneList,
LaneListLength,
Settings.Step,
Settings.Depth,
Settings.DoubleMargin,
TRUE
);
} else {
return EFI_INVALID_PARAMETER;
}
} else {
return SetRawJitterTolerance (
LaneList,
LaneListLength,
Settings.Step,
Settings.Depth,
Settings.DoubleMargin,
FALSE
);
}
}
EFI_STATUS
SetRawJitterTolerance (
IN UINT8 *LaneList,
IN UINT8 LaneListLength,
IN UINT8 Step,
IN UINT8 Depth,
IN UINT8 DoubleMargin,
IN BOOLEAN EnableJitter
)
{
UINT8 BundleList[8];
UINT8 BundleListLength;
UINT8 i;
UINT8 Lane;
UINT8 Bundle;
BundleListLength = 0;
GetBundleList (LaneList, LaneListLength, &BundleList[0], &BundleListLength);
for (i = 0; i < LaneListLength; ++i) {
Lane = LaneList[i];
McD1PciCfg32And (R_SA_PEG_AFELN0CFG0_OFFSET + (Lane * LANE_STEP), 0xFFFFFBFF);
}
for (i = 0; i < BundleListLength; ++i) {
Bundle = BundleList[i];
McD1PciCfg32AndThenOr (
R_SA_PEG_AFEBND0CFG0_OFFSET + (Bundle * BUNDLE_STEP),
(UINT32) ~(BIT28 | BIT17 | BIT16 | BIT15 | BIT14 | BIT13 | BIT12 | BIT11 | BIT10),
(UINT32) ((DoubleMargin << 28) | (Step << 10))
);
McD1PciCfg32AndThenOr (
R_SA_PEG_AFEBND0CFG3_OFFSET + (Bundle * BUNDLE_STEP),
(UINT32) ~(BIT16 | BIT15 | BIT14 | BIT13 | BIT12 | BIT11),
(UINT32) (Depth << 11)
);
}
if (EnableJitter) {
for (i = 0; i < LaneListLength; ++i) {
Lane = LaneList[i];
McD1PciCfg32Or (R_SA_PEG_AFELN0CFG0_OFFSET + (Lane * LANE_STEP), BIT10);
}
}
return EFI_SUCCESS;
}
VOID
EnableTxJitterInjection (
IN UINT8 Lane,
IN BOOLEAN EnableTxJitter
)
{
UINT8 Bundle;
Bundle = Lane / 2;
if (EnableTxJitter) {
McD1PciCfg32AndThenOr (
R_SA_PEG_AFEBND0CFG0_OFFSET + (Bundle * BUNDLE_STEP),
~(BIT1 | BIT2),
0x6
);
} else {
McD1PciCfg32And (
R_SA_PEG_AFEBND0CFG0_OFFSET + (Bundle * BUNDLE_STEP),
~(BIT1 | BIT2)
);
}
}
VOID
ConfigureTxJitterMux (
IN UINT8 Lane,
IN UINT32 MchBar
)
{
CPU_FAMILY CpuFamilyId;
CPU_STEPPING CpuSteppingId;
UINT32 SequenceId;
CpuFamilyId = GetCpuFamily ();
CpuSteppingId = GetCpuStepping ();
SequenceId = V_SA_VCU_SEQID_SET_TXJITTER_MUX;
#ifndef AMI_OVERRIDE_FOR_ULT_FASTBOOT
if (CpuFamilyId == EnumCpuHswUlt) return;
#endif // AMI_OVERRIDE_FOR_ULT_FASTBOOT
if ((CpuFamilyId == EnumCpuHsw) && (CpuSteppingId == EnumHswA0)) {
SendVcuApiCmd (MchBar, V_SA_VCU_OPCODE_OPEN_SEQ_REV1, SequenceId);
} else {
SendVcuApiCmd (MchBar, V_SA_VCU_OPCODE_OPEN_SEQ_REV2, SequenceId);
}
SendVcuApiCmd (MchBar, V_SA_VCU_OPCODE_SET_TXJITTER_MUX, Lane);
if ((CpuFamilyId == EnumCpuHsw) && (CpuSteppingId == EnumHswA0)) {
SendVcuApiCmd (MchBar, V_SA_VCU_OPCODE_CLOSE_SEQ_REV1, 0);
} else {
SendVcuApiCmd (MchBar, V_SA_VCU_OPCODE_CLOSE_SEQ_REV2, 0);
}
return;
}
EFI_STATUS
GetBundleList (
IN UINT8 *LaneList,
IN UINT8 LaneListLength,
OUT UINT8 *BundleList,
OUT UINT8 *BundleListLength
)
{
UINT8 Bundle;
BOOLEAN HasBundle;
UINT8 i;
UINT8 j;
(*BundleListLength) = 0;
for (i = 0; i < LaneListLength; ++i) {
Bundle = LaneList[i] / 2;
HasBundle = FALSE;
for (j = 0; j < (*BundleListLength); ++j) {
if (BundleList[j] == Bundle) {
HasBundle = TRUE;
break;
}
}
if (!HasBundle) {
BundleList[*BundleListLength] = Bundle;
++(*BundleListLength);
}
}
return EFI_SUCCESS;
}
#endif // PEG_FLAG
|