summaryrefslogtreecommitdiffstats
path: root/resources/libreboot/patch/kgpe-d16/0078-northbridge-amd-amdmct-mct_ddr3-Fix-null-pointer-acc.patch
blob: 2b4ab06e26e0b5e40be58a4c4dffb1d3b54023bb (plain)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
From e708c2a00f881e5bb37a9b224f72109e2c9ffecc Mon Sep 17 00:00:00 2001
From: Timothy Pearson <kb9vqf@pearsoncomputing.net>
Date: Fri, 26 Jun 2015 12:17:48 -0500
Subject: [PATCH 078/146] northbridge/amd/amdmct/mct_ddr3: Fix null pointer
 access and related hangs

---
 src/northbridge/amd/amdmct/mct_ddr3/mct_d.c  |   58 ++++++++++++++------------
 src/northbridge/amd/amdmct/mct_ddr3/mctsdi.c |    8 ++--
 2 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/src/northbridge/amd/amdmct/mct_ddr3/mct_d.c b/src/northbridge/amd/amdmct/mct_ddr3/mct_d.c
index e7eb6af..61293ba 100644
--- a/src/northbridge/amd/amdmct/mct_ddr3/mct_d.c
+++ b/src/northbridge/amd/amdmct/mct_ddr3/mct_d.c
@@ -826,7 +826,7 @@ static uint32_t fam15h_output_driver_compensation_code(struct DCTStatStruc *pDCT
 			/* RDIMM */
 			/* Fam15h BKDG Rev. 3.14 section 2.10.5.3.4 Table 74 */
 			if (MaxDimmsInstallable == 1) {
-				rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+				rank_count_dimm0 = pDCTstat->DimmRanks[(1 * 2) + dct];
 
 				if (MemClkFreq == 0x4) {
 					/* DDR3-667 */
@@ -850,8 +850,8 @@ static uint32_t fam15h_output_driver_compensation_code(struct DCTStatStruc *pDCT
 					calibration_code |= 0x22 << 16;
 				}
 			} else if (MaxDimmsInstallable == 2) {
-				rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[0];
-				rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+				rank_count_dimm0 = pDCTstat->DimmRanks[(0 * 2) + dct];
+				rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 
 				if (dimm_count == 1) {
 					/* 1 DIMM detected */
@@ -875,8 +875,8 @@ static uint32_t fam15h_output_driver_compensation_code(struct DCTStatStruc *pDCT
 					}
 				} else if (dimm_count == 2) {
 					/* 2 DIMMs detected */
-					rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[0];
-					rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm0 = pDCTstat->DimmRanks[(0 * 2) + dct];
+					rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 					
 					if (MemClkFreq == 0x4) {
 						/* DDR3-667 */
@@ -943,8 +943,8 @@ static uint32_t fam15h_output_driver_compensation_code(struct DCTStatStruc *pDCT
 					}
 				} else if (dimm_count == 2) {
 					/* 2 DIMMs detected */
-					rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[0];
-					rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm0 = pDCTstat->DimmRanks[(0 * 2) + dct];
+					rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 					
 					if (MemClkFreq == 0x4) {
 						/* DDR3-667 */
@@ -1065,7 +1065,7 @@ static uint32_t fam15h_address_timing_compensation_code(struct DCTStatStruc *pDC
 			/* UDIMM */
 			/* Fam15h BKDG Rev. 3.14 section 2.10.5.3.4 Table 73 */
 			if (MaxDimmsInstallable == 1) {
-				rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+				rank_count_dimm0 = pDCTstat->DimmRanks[(1 * 2) + dct];
 	
 				if (MemClkFreq == 0x4) {
 					/* DDR3-667 */
@@ -1098,7 +1098,7 @@ static uint32_t fam15h_address_timing_compensation_code(struct DCTStatStruc *pDC
 			} else if (MaxDimmsInstallable == 2) {
 				if (dimm_count == 1) {
 					/* 1 DIMM detected */
-					rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm0 = pDCTstat->DimmRanks[(1 * 2) + dct];
 	
 					if (MemClkFreq == 0x4) {
 						/* DDR3-667 */
@@ -1127,8 +1127,8 @@ static uint32_t fam15h_address_timing_compensation_code(struct DCTStatStruc *pDC
 					}
 				} else if (dimm_count == 2) {
 					/* 2 DIMMs detected */
-					rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[0];
-					rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm0 = pDCTstat->DimmRanks[(0 * 2) + dct];
+					rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 	
 					if (MemClkFreq == 0x4) {
 						/* DDR3-667 */
@@ -1196,7 +1196,7 @@ static uint8_t fam15h_slow_access_mode(struct DCTStatStruc *pDCTstat, uint8_t dc
 			/* UDIMM */
 			/* Fam15h BKDG Rev. 3.14 section 2.10.5.3.4 Table 73 */
 			if (MaxDimmsInstallable == 1) {
-				rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+				rank_count_dimm0 = pDCTstat->DimmRanks[(1 * 2) + dct];
 	
 				if ((MemClkFreq == 0x4) || (MemClkFreq == 0x6)
 					|| (MemClkFreq == 0xa) | (MemClkFreq == 0xe)) {
@@ -1212,7 +1212,7 @@ static uint8_t fam15h_slow_access_mode(struct DCTStatStruc *pDCTstat, uint8_t dc
 			} else if (MaxDimmsInstallable == 2) {
 				if (dimm_count == 1) {
 					/* 1 DIMM detected */
-					rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm0 = pDCTstat->DimmRanks[(1 * 2) + dct];
 	
 					if ((MemClkFreq == 0x4) || (MemClkFreq == 0x6)
 						|| (MemClkFreq == 0xa) | (MemClkFreq == 0xe)) {
@@ -1227,8 +1227,8 @@ static uint8_t fam15h_slow_access_mode(struct DCTStatStruc *pDCTstat, uint8_t dc
 					}
 				} else if (dimm_count == 2) {
 					/* 2 DIMMs detected */
-					rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[0];
-					rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm0 = pDCTstat->DimmRanks[(0 * 2) + dct];
+					rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 	
 					if ((MemClkFreq == 0x4) || (MemClkFreq == 0x6)
 						|| (MemClkFreq == 0xa)) {
@@ -5840,14 +5840,18 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 		uint8_t write_odt_delay;
 		uint8_t read_odt_delay;
 
+		/* NOTE
+		 * Rank count per DIMM and DCT is encoded by pDCTstat->DimmRanks[(<dimm number> * 2) + dct]
+		 */
+
 		/* Select appropriate ODT pattern for installed DIMMs
 		 * Refer to the Fam15h BKDG Rev. 3.14, page 149 onwards
 		 */
-		if (pDCTstat->C_DCTPtr[dct]->Status[DCT_STATUS_REGISTERED]) {
+		if (pDCTstat->Status & (1 << SB_Registered)) {
 			if (MaxDimmsInstallable == 2) {
 				if (dimm_count == 1) {
 					/* 1 DIMM detected */
-					rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 					if (rank_count_dimm1 == 1) {
 						odt_pattern_0 = 0x00000000;
 						odt_pattern_1 = 0x00000000;
@@ -5872,8 +5876,8 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 					}
 				} else {
 					/* 2 DIMMs detected */
-					rank_count_dimm0 = pDCTstat->C_DCTPtr[dct]->DimmRanks[0];
-					rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm0 = pDCTstat->DimmRanks[(0 * 2) + dct];
+					rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 					if ((rank_count_dimm0 < 4) && (rank_count_dimm1 < 4)) {
 						odt_pattern_0 = 0x00000000;
 						odt_pattern_1 = 0x01010202;
@@ -5911,7 +5915,7 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 				odt_pattern_2 = 0x00000000;
 				odt_pattern_3 = 0x00000000;
 			}
-		} else if (pDCTstat->C_DCTPtr[dct]->Status[DCT_STATUS_LOAD_REDUCED]) {
+		} else if (pDCTstat->Status & (1 << SB_LoadReduced)) {
 			/* TODO
 			 * Load reduced dimms UNIMPLEMENTED
 			 */
@@ -5923,7 +5927,7 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 			if (MaxDimmsInstallable == 2) {
 				if (dimm_count == 1) {
 					/* 1 DIMM detected */
-					rank_count_dimm1 = pDCTstat->C_DCTPtr[dct]->DimmRanks[1];
+					rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + dct];
 					if (rank_count_dimm1 == 1) {
 						odt_pattern_0 = 0x00000000;
 						odt_pattern_1 = 0x00000000;
@@ -5959,7 +5963,7 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 			}
 		}
 
-		if (pDCTstat->C_DCTPtr[dct]->Status[DCT_STATUS_LOAD_REDUCED]) {
+		if (pDCTstat->Status & (1 << SB_LoadReduced)) {
 			/* TODO
 			 * Load reduced dimms UNIMPLEMENTED
 			 */
@@ -6019,11 +6023,11 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 			/* Select appropriate ODT pattern for installed DIMMs
 			 * Refer to the Fam10h BKDG Rev. 3.62, page 120 onwards
 			 */
-			if (pDCTstat->C_DCTPtr[i]->Status[DCT_STATUS_REGISTERED]) {
+			if (pDCTstat->Status & (1 << SB_Registered)) {
 				if (MaxDimmsInstallable == 2) {
 					if (dimm_count == 1) {
 						/* 1 DIMM detected */
-						rank_count_dimm1 = pDCTstat->C_DCTPtr[i]->DimmRanks[1];
+						rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + i];
 						if (rank_count_dimm1 == 1) {
 							odt_pattern_0 = 0x00000000;
 							odt_pattern_1 = 0x00000000;
@@ -6048,8 +6052,8 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 						}
 					} else {
 						/* 2 DIMMs detected */
-						rank_count_dimm0 = pDCTstat->C_DCTPtr[i]->DimmRanks[0];
-						rank_count_dimm1 = pDCTstat->C_DCTPtr[i]->DimmRanks[1];
+						rank_count_dimm0 = pDCTstat->DimmRanks[(0 * 2) + i];
+						rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + i];
 						if ((rank_count_dimm0 < 4) && (rank_count_dimm1 < 4)) {
 							odt_pattern_0 = 0x00000000;
 							odt_pattern_1 = 0x01010202;
@@ -6091,7 +6095,7 @@ static void mct_ProgramODT_D(struct MCTStatStruc *pMCTstat,
 				if (MaxDimmsInstallable == 2) {
 					if (dimm_count == 1) {
 						/* 1 DIMM detected */
-						rank_count_dimm1 = pDCTstat->C_DCTPtr[i]->DimmRanks[1];
+						rank_count_dimm1 = pDCTstat->DimmRanks[(1 * 2) + i];
 						if (rank_count_dimm1 == 1) {
 							odt_pattern_0 = 0x00000000;
 							odt_pattern_1 = 0x00000000;
diff --git a/src/northbridge/amd/amdmct/mct_ddr3/mctsdi.c b/src/northbridge/amd/amdmct/mct_ddr3/mctsdi.c
index 380c5f2..c7d7463 100644
--- a/src/northbridge/amd/amdmct/mct_ddr3/mctsdi.c
+++ b/src/northbridge/amd/amdmct/mct_ddr3/mctsdi.c
@@ -38,10 +38,9 @@ static uint8_t fam15_dimm_dic(struct DCTStatStruc *pDCTstat, uint8_t dct, uint8_
 static uint8_t fam15_rttwr(struct DCTStatStruc *pDCTstat, uint8_t dct, uint8_t dimm, uint8_t rank, uint8_t package_type)
 {
 	uint8_t term = 0;
-	sDCTStruct *pDCTData = pDCTstat->C_DCTPtr[dct];
-	uint8_t number_of_dimms = pDCTData->MaxDimmsInstalled;
+	uint8_t number_of_dimms = pDCTstat->MAdimms[dct];
 	uint8_t frequency_index;
-	uint8_t rank_count = pDCTData->DimmRanks[dimm];
+	uint8_t rank_count = pDCTstat->DimmRanks[(dimm * 2) + dct];
 
 	if (is_fam15h())
 		frequency_index = Get_NB32_DCT(pDCTstat->dev_dct, dct, 0x94) & 0x1f;
@@ -101,8 +100,7 @@ static uint8_t fam15_rttwr(struct DCTStatStruc *pDCTstat, uint8_t dct, uint8_t d
 static uint8_t fam15_rttnom(struct DCTStatStruc *pDCTstat, uint8_t dct, uint8_t dimm, uint8_t rank, uint8_t package_type)
 {
 	uint8_t term = 0;
-	sDCTStruct *pDCTData = pDCTstat->C_DCTPtr[dct];
-	uint8_t number_of_dimms = pDCTData->MaxDimmsInstalled;
+	uint8_t number_of_dimms = pDCTstat->MAdimms[dct];
 	uint8_t frequency_index;
 
 	if (is_fam15h())
-- 
1.7.9.5