blob: b9af2878b5fa39e1c45ae4fb734b378168844767 [file] [log] [blame]
David Hendricksce6b2fa2011-07-11 22:12:43 -07001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (c) 2010 Matthias Wenzel <bios at mazzoo dot de>
5 * Copyright (c) 2011 Stefan Tauner
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
David Hendricksce6b2fa2011-07-11 22:12:43 -070016 */
17
David Hendricksce6b2fa2011-07-11 22:12:43 -070018#if defined(__i386__) || defined(__x86_64__)
19
stefanct1fc3a732011-09-15 23:52:55 +000020#include "ich_descriptors.h"
Stefan Tauner34f6f5a2016-08-03 11:20:38 -070021
22#ifdef ICH_DESCRIPTORS_FROM_DUMP
23
24#include <stdio.h>
Edward O'Callaghan568cd262020-05-26 23:10:45 +100025#include <string.h>
Stefan Tauner34f6f5a2016-08-03 11:20:38 -070026#define print(t, ...) printf(__VA_ARGS__)
27#define DESCRIPTOR_MODE_SIGNATURE 0x0ff0a55a
28/* The upper map is located in the word before the 256B-long OEM section at the
29 * end of the 4kB-long flash descriptor.
30 */
31#define UPPER_MAP_OFFSET (4096 - 256 - 4)
32#define getVTBA(flumap) (((flumap)->FLUMAP1 << 4) & 0x00000ff0)
33
34#else /* ICH_DESCRIPTORS_FROM_DUMP */
35
David Hendricksce6b2fa2011-07-11 22:12:43 -070036#include "flash.h" /* for msg_* */
stefanct1fc3a732011-09-15 23:52:55 +000037#include "programmer.h"
David Hendricksce6b2fa2011-07-11 22:12:43 -070038
Stefan Tauner34f6f5a2016-08-03 11:20:38 -070039#endif /* ICH_DESCRIPTORS_FROM_DUMP */
40
41#ifndef min
42#define min(a, b) (a < b) ? a : b
43#endif
44
Edward O'Callaghand757b422020-05-26 21:22:12 +100045void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
David Hendricksce6b2fa2011-07-11 22:12:43 -070046{
stefanct1fc3a732011-09-15 23:52:55 +000047 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
48 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
49 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
50 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Edward O'Callaghand757b422020-05-26 21:22:12 +100051 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
52 if (print_vcl)
53 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
54 print(verbosity, "\n");
David Hendricksce6b2fa2011-07-11 22:12:43 -070055}
56
stefanct1fc3a732011-09-15 23:52:55 +000057#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
58#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
59#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
60#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
61#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
62
63void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
David Hendricksce6b2fa2011-07-11 22:12:43 -070064{
stefanct1fc3a732011-09-15 23:52:55 +000065 prettyprint_ich_descriptor_content(&desc->content);
66 prettyprint_ich_descriptor_component(desc);
67 prettyprint_ich_descriptor_region(desc);
Duncan Lauriedbbf2222019-04-25 12:06:19 -070068 prettyprint_ich_descriptor_master(cs, &desc->master);
Stefan Tauner34f6f5a2016-08-03 11:20:38 -070069#ifdef ICH_DESCRIPTORS_FROM_DUMP
70 if (cs >= CHIPSET_ICH8) {
71 prettyprint_ich_descriptor_upper_map(&desc->upper);
72 prettyprint_ich_descriptor_straps(cs, desc);
73 }
74#endif /* ICH_DESCRIPTORS_FROM_DUMP */
David Hendricksce6b2fa2011-07-11 22:12:43 -070075}
76
stefanct1fc3a732011-09-15 23:52:55 +000077void prettyprint_ich_descriptor_content(const struct ich_desc_content *cont)
David Hendricksce6b2fa2011-07-11 22:12:43 -070078{
stefanct1fc3a732011-09-15 23:52:55 +000079 msg_pdbg2("=== Content Section ===\n");
80 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
81 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
82 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
83 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
84 msg_pdbg2("\n");
85
86 msg_pdbg2("--- Details ---\n");
87 msg_pdbg2("NR (Number of Regions): %5d\n",
88 cont->NR + 1);
89 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n",
90 getFRBA(cont));
91 msg_pdbg2("NC (Number of Components): %5d\n",
92 cont->NC + 1);
93 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n",
94 getFCBA(cont));
95 msg_pdbg2("ISL (ICH/PCH Strap Length): %5d\n",
96 cont->ISL);
97 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH Strap Base Address): 0x%03x\n",
98 getFISBA(cont));
99 msg_pdbg2("NM (Number of Masters): %5d\n",
100 cont->NM + 1);
101 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n",
102 getFMBA(cont));
103 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n",
104 cont->MSL);
105 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n",
106 getFMSBA(cont));
107 msg_pdbg2("\n");
David Hendricksce6b2fa2011-07-11 22:12:43 -0700108}
109
stefanct1fc3a732011-09-15 23:52:55 +0000110void prettyprint_ich_descriptor_component(const struct ich_descriptors *desc)
David Hendricksce6b2fa2011-07-11 22:12:43 -0700111{
stefanct1fc3a732011-09-15 23:52:55 +0000112 static const char * const freq_str[8] = {
113 "20 MHz", /* 000 */
114 "33 MHz", /* 001 */
115 "reserved", /* 010 */
116 "reserved", /* 011 */
117 "50 MHz", /* 100 */
118 "reserved", /* 101 */
119 "reserved", /* 110 */
120 "reserved" /* 111 */
121 };
122 static const char * const size_str[8] = {
123 "512 kB", /* 000 */
124 " 1 MB", /* 001 */
125 " 2 MB", /* 010 */
126 " 4 MB", /* 011 */
127 " 8 MB", /* 100 */
128 " 16 MB", /* 101 */
Satya Popuri87ecc332016-07-25 17:04:04 -0700129 " 32 MB", /* 110 */
130 " 64 MB", /* 111 */
David Hendricksce6b2fa2011-07-11 22:12:43 -0700131 };
132
stefanct1fc3a732011-09-15 23:52:55 +0000133 msg_pdbg2("=== Component Section ===\n");
134 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
135 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
136 msg_pdbg2("\n");
David Hendricksce6b2fa2011-07-11 22:12:43 -0700137
stefanct1fc3a732011-09-15 23:52:55 +0000138 msg_pdbg2("--- Details ---\n");
139 msg_pdbg2("Component 1 density: %s\n",
140 size_str[desc->component.comp1_density]);
141 if (desc->content.NC)
142 msg_pdbg2("Component 2 density: %s\n",
143 size_str[desc->component.comp2_density]);
David Hendricksce6b2fa2011-07-11 22:12:43 -0700144 else
stefanct1fc3a732011-09-15 23:52:55 +0000145 msg_pdbg2("Component 2 is not used.\n");
146 msg_pdbg2("Read Clock Frequency: %s\n",
147 freq_str[desc->component.freq_read]);
148 msg_pdbg2("Read ID and Status Clock Freq.: %s\n",
149 freq_str[desc->component.freq_read_id]);
150 msg_pdbg2("Write and Erase Clock Freq.: %s\n",
151 freq_str[desc->component.freq_write]);
152 msg_pdbg2("Fast Read is %ssupported.\n",
153 desc->component.fastread ? "" : "not ");
154 if (desc->component.fastread)
155 msg_pdbg2("Fast Read Clock Frequency: %s\n",
156 freq_str[desc->component.freq_fastread]);
157 if (desc->component.FLILL == 0)
158 msg_pdbg2("No forbidden opcodes.\n");
159 else {
160 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
161 desc->component.invalid_instr0);
162 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
163 desc->component.invalid_instr1);
164 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
165 desc->component.invalid_instr2);
166 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
167 desc->component.invalid_instr3);
168 }
169 msg_pdbg2("\n");
David Hendricksce6b2fa2011-07-11 22:12:43 -0700170}
171
stefanct1fc3a732011-09-15 23:52:55 +0000172static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
David Hendricksce6b2fa2011-07-11 22:12:43 -0700173{
Edward O'Callaghan133ef002020-05-26 23:15:56 +1000174 static const char *const region_names[] = {
175 "Descr.", "BIOS", "ME", "GbE", "Platf.", "DevExp", "BIOS2", "unknown",
176 "EC/BMC", "unknown", "IE", "10GbE", "unknown", "unknown", "unknown", "unknown"
David Hendricksce6b2fa2011-07-11 22:12:43 -0700177 };
Edward O'Callaghan133ef002020-05-26 23:15:56 +1000178 if (i >= ARRAY_SIZE(region_names)) {
stefanct1fc3a732011-09-15 23:52:55 +0000179 msg_pdbg2("%s: region index too high.\n", __func__);
180 return;
David Hendricksce6b2fa2011-07-11 22:12:43 -0700181 }
stefanct1fc3a732011-09-15 23:52:55 +0000182 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
183 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
Edward O'Callaghan133ef002020-05-26 23:15:56 +1000184 msg_pdbg2("Region %d (%-7s) ", i, region_names[i]);
stefanct1fc3a732011-09-15 23:52:55 +0000185 if (base > limit)
186 msg_pdbg2("is unused.\n");
187 else
Edward O'Callaghan133ef002020-05-26 23:15:56 +1000188 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
David Hendricksce6b2fa2011-07-11 22:12:43 -0700189}
190
stefanct1fc3a732011-09-15 23:52:55 +0000191void prettyprint_ich_descriptor_region(const struct ich_descriptors *desc)
David Hendricksce6b2fa2011-07-11 22:12:43 -0700192{
stefanct1fc3a732011-09-15 23:52:55 +0000193 uint8_t i;
194 uint8_t nr = desc->content.NR + 1;
195 msg_pdbg2("=== Region Section ===\n");
196 if (nr >= 5) {
197 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
198 nr);
199 return;
200 }
201 for (i = 0; i <= nr; i++)
202 msg_pdbg2("FLREG%d 0x%08x\n", i, desc->region.FLREGs[i]);
203 msg_pdbg2("\n");
204
205 msg_pdbg2("--- Details ---\n");
206 for (i = 0; i <= nr; i++)
207 pprint_freg(&desc->region, i);
208 msg_pdbg2("\n");
David Hendricksce6b2fa2011-07-11 22:12:43 -0700209}
210
Duncan Lauriedbbf2222019-04-25 12:06:19 -0700211static void prettyprint_ich_descriptor_master_ich(const struct ich_desc_master_ich *mstr)
David Hendricksce6b2fa2011-07-11 22:12:43 -0700212{
stefanct1fc3a732011-09-15 23:52:55 +0000213 msg_pdbg2("=== Master Section ===\n");
214 msg_pdbg2("FLMSTR1 0x%08x\n", mstr->FLMSTR1);
215 msg_pdbg2("FLMSTR2 0x%08x\n", mstr->FLMSTR2);
216 msg_pdbg2("FLMSTR3 0x%08x\n", mstr->FLMSTR3);
217 msg_pdbg2("\n");
David Hendricksce6b2fa2011-07-11 22:12:43 -0700218
stefanct1fc3a732011-09-15 23:52:55 +0000219 msg_pdbg2("--- Details ---\n");
220 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
221 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
222 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
223 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
224 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
225 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
226 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
227 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
228 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
229 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
230 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
231 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
232 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
233 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
234 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
235 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
236 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
237 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
238 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
239 msg_pdbg2("\n");
David Hendricksce6b2fa2011-07-11 22:12:43 -0700240}
241
Duncan Lauriedbbf2222019-04-25 12:06:19 -0700242static void prettyprint_ich_descriptor_master_pch100(const struct ich_desc_master_pch100 *mstr)
243{
244 msg_pdbg2("=== Master Section ===\n");
245 msg_pdbg2("FLMSTR1 0x%08x\n", mstr->FLMSTR1);
246 msg_pdbg2("FLMSTR2 0x%08x\n", mstr->FLMSTR2);
247 msg_pdbg2("FLMSTR3 0x%08x\n", mstr->FLMSTR3);
248 msg_pdbg2("FLMSTR4 0x%08x\n", mstr->FLMSTR4);
249 msg_pdbg2("FLMSTR5 0x%08x\n", mstr->FLMSTR5);
250 msg_pdbg2("\n");
251
252 msg_pdbg2("--- Details ---\n");
253 msg_pdbg2(" Descr. BIOS ME GbE Plat EC\n");
254 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c %c%c\n",
255 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
256 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
257 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
258 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
259 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ',
260 (mstr->BIOS_EC_r) ?'r':' ', (mstr->BIOS_EC_w) ?'w':' ');
261 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c %c%c\n",
262 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
263 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
264 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
265 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
266 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ',
267 (mstr->ME_EC_r) ?'r':' ', (mstr->ME_EC_w) ?'w':' ');
268 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c %c%c\n",
269 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
270 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
271 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
272 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
273 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ',
274 (mstr->GbE_EC_r) ?'r':' ', (mstr->GbE_EC_w) ?'w':' ');
275 msg_pdbg2("Plat %c%c %c%c %c%c %c%c %c%c %c%c\n",
276 (mstr->plat_descr_r) ?'r':' ', (mstr->plat_descr_w) ?'w':' ',
277 (mstr->plat_BIOS_r) ?'r':' ', (mstr->plat_BIOS_w) ?'w':' ',
278 (mstr->plat_ME_r) ?'r':' ', (mstr->plat_ME_w) ?'w':' ',
279 (mstr->plat_GbE_r) ?'r':' ', (mstr->plat_GbE_w) ?'w':' ',
280 (mstr->plat_plat_r) ?'r':' ', (mstr->plat_plat_w) ?'w':' ',
281 (mstr->plat_EC_r) ?'r':' ', (mstr->plat_EC_w) ?'w':' ');
282 msg_pdbg2("EC %c%c %c%c %c%c %c%c %c%c %c%c\n",
283 (mstr->EC_descr_r) ?'r':' ', (mstr->EC_descr_w) ?'w':' ',
284 (mstr->EC_BIOS_r) ?'r':' ', (mstr->EC_BIOS_w) ?'w':' ',
285 (mstr->EC_ME_r) ?'r':' ', (mstr->EC_ME_w) ?'w':' ',
286 (mstr->EC_GbE_r) ?'r':' ', (mstr->EC_GbE_w) ?'w':' ',
287 (mstr->EC_plat_r) ?'r':' ', (mstr->EC_plat_w) ?'w':' ',
288 (mstr->EC_EC_r) ?'r':' ', (mstr->EC_EC_w) ?'w':' ');
289 msg_pdbg2("\n");
290}
291
292void prettyprint_ich_descriptor_master(enum ich_chipset cs,
293 const struct ich_desc_master *mstr)
294{
295 msg_pdbg2("%s: cs=%d\n", __func__, cs);
296 if (cs >= CHIPSET_100_SERIES_SUNRISE_POINT)
297 prettyprint_ich_descriptor_master_pch100(&mstr->pch100);
298 else
299 prettyprint_ich_descriptor_master_ich(&mstr->ich);
300}
301
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700302#ifdef ICH_DESCRIPTORS_FROM_DUMP
303
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000304static void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700305{
306 static const char * const str_GPIO12[4] = {
307 "GPIO12",
308 "LAN PHY Power Control Function (Native Output)",
309 "GLAN_DOCK# (Native Input)",
310 "invalid configuration",
311 };
312
313 msg_pdbg2("--- MCH details ---\n");
314 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
315 msg_pdbg2("\n");
316
317 msg_pdbg2("--- ICH details ---\n");
318 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
319 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
320 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
321 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
322 msg_pdbg2("SPI CS1 is used for %s.\n",
323 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
324 "LAN PHY Power Control Function" :
325 "SPI Chip Select");
326 msg_pdbg2("GPIO12 is used as %s.\n",
327 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
328 msg_pdbg2("PCIe Port 6 is used for %s.\n",
329 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
330 msg_pdbg2("%sn BMC Mode: "
331 "Intel AMT SMBus Controller 1 is connected to %s.\n",
332 desc->south.ich8.BMCMODE ? "I" : "Not i",
333 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
334 msg_pdbg2("TCO is in %s Mode.\n",
335 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
336 msg_pdbg2("ME A is %sabled.\n",
337 desc->south.ich8.ME_DISABLE ? "dis" : "en");
338 msg_pdbg2("\n");
339}
340
341static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
342{
343 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
344
345 off *= 4;
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000346 switch (conf){
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700347 case 0:
348 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
349 break;
350 case 1:
351 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
352 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
353 break;
354 case 2:
355 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
356 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
357 break;
358 case 3:
359 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
360 1+off, 2+off, 4+off);
361 break;
362 }
363 msg_pdbg2("\n");
364}
365
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000366static void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700367{
368 /* PCHSTRP4 */
369 msg_pdbg2("Intel PHY is %s.\n",
370 (s->ibex.PHYCON == 2) ? "connected" :
371 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
372 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
373 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
374 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
375 s->ibex.GBEMAC_SMBUS_ADDR);
376 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
377 s->ibex.GBEPHY_SMBUS_ADDR);
378
379 /* PCHSTRP5 */
380 /* PCHSTRP6 */
381 /* PCHSTRP7 */
382 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
383 s->ibex.MESMA2UDID_VENDOR);
384 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
385 s->ibex.MESMA2UDID_VENDOR);
386
387 /* PCHSTRP8 */
388}
389
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000390static void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700391{
392 /* PCHSTRP11 */
393 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
394 s->ibex.SML1GPAEN ? "en" : "dis");
395 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
396 s->ibex.SML1GPA);
397 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
398 s->ibex.SML1I2CAEN ? "en" : "dis");
399 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
400 s->ibex.SML1I2CA);
401
402 /* PCHSTRP12 */
403 /* PCHSTRP13 */
404}
405
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000406static void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700407{
Patrick Georgi3a5bcb92017-04-11 20:45:07 +0200408 static const uint8_t dec_t209min[4] = {
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700409 100,
410 50,
411 5,
412 1
413 };
414
415 msg_pdbg2("--- PCH ---\n");
416
417 /* PCHSTRP0 */
418 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
419 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
420 s->ibex.SMB_EN ? "en" : "dis");
421 msg_pdbg2("SMLink0 segment is %sabled.\n",
422 s->ibex.SML0_EN ? "en" : "dis");
423 msg_pdbg2("SMLink1 segment is %sabled.\n",
424 s->ibex.SML1_EN ? "en" : "dis");
425 msg_pdbg2("SMLink1 Frequency: %s\n",
426 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
427 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
428 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
429 msg_pdbg2("SMLink0 Frequency: %s\n",
430 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
431 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
432 "LAN_PHY_PWR_CTRL" : "general purpose output");
433 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
434 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
435 s->ibex.DMI_REQID_DIS ? "en" : "dis");
436 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
437 1 << (6 + s->ibex.BBBS));
438
439 /* PCHSTRP1 */
440 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
441
442 /* PCHSTRP2 */
443 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
444 s->ibex.MESMASDEN ? "en" : "dis");
445 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
446 s->ibex.MESMASDA);
447 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
448 s->ibex.MESMI2CEN ? "en" : "dis");
449 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
450 s->ibex.MESMI2CA);
451
452 /* PCHSTRP3 */
453 prettyprint_ich_descriptor_pchstraps45678_56(s);
454 /* PCHSTRP9 */
455 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
456 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
457 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
458 s->ibex.PCIELR1 ? "" : "not ");
459 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
460 s->ibex.PCIELR2 ? "" : "not ");
461 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
462 s->ibex.DMILR ? "" : "not ");
463 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
464 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
465 s->ibex.PHY_PCIE_EN ? "en" : "dis");
466
467 /* PCHSTRP10 */
468 msg_pdbg2("Management Engine will boot from %sflash.\n",
469 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
470 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
471 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
472 s->ibex.VE_EN ? "en" : "dis");
473 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
474 s->ibex.MMDDE ? "en" : "dis");
475 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
476 s->ibex.MMADDR);
477 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
478 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
479 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
480 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
481 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
482
483 prettyprint_ich_descriptor_pchstraps111213_56(s);
484
485 /* PCHSTRP14 */
486 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
487 s->ibex.VE_EN2 ? "en" : "dis");
488 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
489 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
490 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
491 s->ibex.BW_SSD ? "en" : "dis");
492 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
493 s->ibex.NVMHCI_EN ? "en" : "dis");
494
495 /* PCHSTRP15 */
496 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
497 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
498 s->ibex.IWL_EN ? "en" : "dis");
499 msg_pdbg2("t209 min Timing: %d ms\n",
500 dec_t209min[s->ibex.t209min]);
501 msg_pdbg2("\n");
502}
503
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000504static void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700505{
506 msg_pdbg2("--- PCH ---\n");
507
508 /* PCHSTRP0 */
509 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
510 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
511 s->ibex.SMB_EN ? "en" : "dis");
512 msg_pdbg2("SMLink0 segment is %sabled.\n",
513 s->ibex.SML0_EN ? "en" : "dis");
514 msg_pdbg2("SMLink1 segment is %sabled.\n",
515 s->ibex.SML1_EN ? "en" : "dis");
516 msg_pdbg2("SMLink1 Frequency: %s\n",
517 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
518 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
519 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
520 msg_pdbg2("SMLink0 Frequency: %s\n",
521 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
522 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
523 "LAN_PHY_PWR_CTRL" : "general purpose output");
524 msg_pdbg2("LinkSec is %sabled.\n",
525 s->cougar.LINKSEC_DIS ? "en" : "dis");
526 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
527 s->ibex.DMI_REQID_DIS ? "en" : "dis");
528 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
529 1 << (6 + s->ibex.BBBS));
530
531 /* PCHSTRP1 */
532 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
533 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
534
535 /* PCHSTRP2 */
536 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
537 s->ibex.MESMASDEN ? "en" : "dis");
538 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
539 s->ibex.MESMASDA);
540 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
541 s->cougar.MESMMCTPAEN ? "en" : "dis");
542 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
543 s->cougar.MESMMCTPA);
544 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
545 s->ibex.MESMI2CEN ? "en" : "dis");
546 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
547 s->ibex.MESMI2CA);
548
549 /* PCHSTRP3 */
550 prettyprint_ich_descriptor_pchstraps45678_56(s);
551 /* PCHSTRP9 */
552 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
553 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
554 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
555 s->ibex.PCIELR1 ? "" : "not ");
556 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
557 s->ibex.PCIELR2 ? "" : "not ");
558 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
559 s->ibex.DMILR ? "" : "not ");
560 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
561 s->cougar.MDSMBE_EN ? "en" : "dis");
562 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
563 s->cougar.MDSMBE_ADD);
564 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
565 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
566 s->ibex.PHY_PCIE_EN ? "en" : "dis");
567 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
568 s->cougar.SUB_DECODE_EN ? "en" : "dis");
569 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
570 "PCHHOT#" : "SML1ALERT#");
571
572 /* PCHSTRP10 */
573 msg_pdbg2("Management Engine will boot from %sflash.\n",
574 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
575
576 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
577 s->cougar.MDSMBE_EN ? "en" : "dis");
578 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
579 s->cougar.MDSMBE_ADD);
580
581 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
582 s->cougar.ICC_SEL);
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000583 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
584 s->ibex.MER_CL1 ? "" : "not ");
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700585 msg_pdbg2("ICC Profile is selected by %s.\n",
586 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
587 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
588 s->cougar.Deep_SX_EN ? "not " : "");
589 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
590 s->cougar.ME_DBG_LAN ? "en" : "dis");
591
592 prettyprint_ich_descriptor_pchstraps111213_56(s);
593
594 /* PCHSTRP14 */
595 /* PCHSTRP15 */
596 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
597 msg_pdbg2("Integrated wired LAN is %sabled.\n",
598 s->cougar.IWL_EN ? "en" : "dis");
599 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
600 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000601 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700602 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
603 "general purpose output" : "SLP_LAN#");
604
605 /* PCHSTRP16 */
606 /* PCHSTRP17 */
607 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
608 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
609 msg_pdbg2("\n");
610}
611
612void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
613{
Edward O'Callaghanc172e172020-05-26 23:19:02 +1000614 unsigned int i, max_count;
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700615 msg_pdbg2("=== Softstraps ===\n");
616
Edward O'Callaghanc172e172020-05-26 23:19:02 +1000617 max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
618 if (max_count < desc->content.MSL) {
619 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
620 desc->content.MSL, max_count);
621 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
622 }
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700623
Edward O'Callaghanc172e172020-05-26 23:19:02 +1000624 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
625 for (i = 0; i < max_count; i++)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700626 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
627 msg_pdbg2("\n");
628
Edward O'Callaghanc172e172020-05-26 23:19:02 +1000629 max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
630 if (max_count < desc->content.ISL) {
631 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
632 desc->content.ISL, max_count);
633 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
634 }
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700635
Edward O'Callaghanc172e172020-05-26 23:19:02 +1000636 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
637 for (i = 0; i < max_count; i++)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700638 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
639 msg_pdbg2("\n");
640
641 switch (cs) {
642 case CHIPSET_ICH8:
643 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
644 msg_pdbg2("Detailed North/MCH/PROC information is "
645 "probably not reliable, printing anyway.\n");
646 if (sizeof(desc->south.ich8) / 4 != desc->content.ISL)
647 msg_pdbg2("Detailed South/ICH/PCH information is "
648 "probably not reliable, printing anyway.\n");
649 prettyprint_ich_descriptor_straps_ich8(desc);
650 break;
651 case CHIPSET_5_SERIES_IBEX_PEAK:
652 /* PCH straps only. PROCSTRPs are unknown. */
653 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
654 msg_pdbg2("Detailed South/ICH/PCH information is "
655 "probably not reliable, printing anyway.\n");
656 prettyprint_ich_descriptor_straps_ibex(&desc->south);
657 break;
658 case CHIPSET_6_SERIES_COUGAR_POINT:
659 /* PCH straps only. PROCSTRP0 is "reserved". */
660 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
661 msg_pdbg2("Detailed South/ICH/PCH information is "
662 "probably not reliable, printing anyway.\n");
663 prettyprint_ich_descriptor_straps_cougar(&desc->south);
664 break;
665 case CHIPSET_ICH_UNKNOWN:
666 break;
667 default:
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000668 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700669 break;
670 }
671}
672
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000673static void prettyprint_rdid(uint32_t reg_val)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700674{
675 uint8_t mid = reg_val & 0xFF;
676 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
677 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
678}
679
680void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
681{
682 int i;
683 msg_pdbg2("=== Upper Map Section ===\n");
684 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
685 msg_pdbg2("\n");
686
687 msg_pdbg2("--- Details ---\n");
688 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
689 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
690 msg_pdbg2("\n");
691
692 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000693 for (i = 0; i < umap->VTL/2; i++) {
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700694 uint32_t jid = umap->vscc_table[i].JID;
695 uint32_t vscc = umap->vscc_table[i].VSCC;
696 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
697 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
698 msg_pdbg2(" "); /* indention */
699 prettyprint_rdid(jid);
700 msg_pdbg2(" "); /* indention */
Edward O'Callaghand757b422020-05-26 21:22:12 +1000701 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700702 }
703 msg_pdbg2("\n");
704}
705
706/* len is the length of dump in bytes */
Duncan Lauriedbbf2222019-04-25 12:06:19 -0700707int read_ich_descriptors_from_dump(const uint32_t *dump, unsigned int len,
708 struct ich_descriptors *desc,
709 enum ich_chipset cs)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700710{
711 unsigned int i, max;
712 uint8_t pch_bug_offset = 0;
713
714 if (dump == NULL || desc == NULL)
715 return ICH_RET_PARAM;
716
717 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
718 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
719 pch_bug_offset = 4;
720 else
721 return ICH_RET_ERR;
722 }
723
724 /* map */
Nico Huber61b10c72017-03-28 17:08:46 +0200725 if (len < (4 + pch_bug_offset) * 4)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700726 return ICH_RET_OOB;
727 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
728 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
729 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
730 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
731
732 /* component */
Nico Huber61b10c72017-03-28 17:08:46 +0200733 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700734 return ICH_RET_OOB;
735 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
736 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
737 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
738
739 /* region */
Nico Huber61b10c72017-03-28 17:08:46 +0200740 if (len < getFRBA(&desc->content) + 5 * 4)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700741 return ICH_RET_OOB;
742 desc->region.FLREGs[0] = dump[(getFRBA(&desc->content) >> 2) + 0];
743 desc->region.FLREGs[1] = dump[(getFRBA(&desc->content) >> 2) + 1];
744 desc->region.FLREGs[2] = dump[(getFRBA(&desc->content) >> 2) + 2];
745 desc->region.FLREGs[3] = dump[(getFRBA(&desc->content) >> 2) + 3];
746 desc->region.FLREGs[4] = dump[(getFRBA(&desc->content) >> 2) + 4];
747
748 /* master */
Nico Huber61b10c72017-03-28 17:08:46 +0200749 if (len < getFMBA(&desc->content) + 3 * 4)
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700750 return ICH_RET_OOB;
Duncan Lauriedbbf2222019-04-25 12:06:19 -0700751 if (cs >= CHIPSET_100_SERIES_SUNRISE_POINT) {
752 desc->master.pch100.FLMSTR1 = dump[(getFMBA(&desc->content) >> 2) + 0];
753 desc->master.pch100.FLMSTR2 = dump[(getFMBA(&desc->content) >> 2) + 1];
754 desc->master.pch100.FLMSTR3 = dump[(getFMBA(&desc->content) >> 2) + 2];
755 desc->master.pch100.FLMSTR4 = dump[(getFMBA(&desc->content) >> 2) + 3];
756 desc->master.pch100.FLMSTR5 = dump[(getFMBA(&desc->content) >> 2) + 4];
757 } else {
758 desc->master.ich.FLMSTR1 = dump[(getFMBA(&desc->content) >> 2) + 0];
759 desc->master.ich.FLMSTR2 = dump[(getFMBA(&desc->content) >> 2) + 1];
760 desc->master.ich.FLMSTR3 = dump[(getFMBA(&desc->content) >> 2) + 2];
761 }
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700762
763 /* upper map */
764 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
765
766 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
767 * "Identifies the 1s based number of DWORDS contained in the VSCC
768 * Table. Each SPI component entry in the table is 2 DWORDS long." So
769 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
770 * check ensures that the maximum offset actually accessed is available.
771 */
Nico Huber61b10c72017-03-28 17:08:46 +0200772 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700773 return ICH_RET_OOB;
774
775 for (i = 0; i < desc->upper.VTL/2; i++) {
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000776 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
777 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700778 }
779
780 /* MCH/PROC (aka. North) straps */
781 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
782 return ICH_RET_OOB;
783
784 /* limit the range to be written */
785 max = min(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
786 for (i = 0; i < max; i++)
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000787 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700788
789 /* ICH/PCH (aka. South) straps */
790 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
791 return ICH_RET_OOB;
792
793 /* limit the range to be written */
794 max = min(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
795 for (i = 0; i < max; i++)
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000796 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700797
798 return ICH_RET_OK;
799}
800
801#else /* ICH_DESCRIPTORS_FROM_DUMP */
802
stefanct3d3b6ee2011-10-20 12:57:14 +0000803/** Returns the integer representation of the component density with index
804idx in bytes or 0 if a correct size can not be determined. */
805int getFCBA_component_density(const struct ich_descriptors *desc, uint8_t idx)
806{
807 uint8_t size_enc;
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700808
stefanct3d3b6ee2011-10-20 12:57:14 +0000809 switch(idx) {
810 case 0:
811 size_enc = desc->component.comp1_density;
812 break;
813 case 1:
814 if (desc->content.NC == 0)
815 return 0;
816 size_enc = desc->component.comp2_density;
817 break;
818 default:
819 msg_perr("Only ICH SPI component index 0 or 1 are supported "
820 "yet.\n");
821 return 0;
822 }
Satya Popuri87ecc332016-07-25 17:04:04 -0700823 if (size_enc > 7) {
stefanct3d3b6ee2011-10-20 12:57:14 +0000824 msg_perr("Density of ICH SPI component with index %d is "
825 "invalid. Encoded density is 0x%x.\n", idx, size_enc);
826 return 0;
827 }
828 return (1 << (19 + size_enc));
829}
830
Edward O'Callaghan5a7ae7a2020-05-18 16:29:45 +1000831static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
David Hendricksce6b2fa2011-07-11 22:12:43 -0700832{
833 uint32_t control = 0;
834 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
835 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Edward O'Callaghan5a7ae7a2020-05-18 16:29:45 +1000836 if ((cs == CHIPSET_100_SERIES_SUNRISE_POINT) ||
Edward O'Callaghan272b27c2020-05-26 17:06:04 +1000837 (cs == CHIPSET_APOLLO_LAKE)) {
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530838 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
839 return mmio_le_readl(spibar + PCH100_REG_FDOD);
840 } else {
841 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
842 return mmio_le_readl(spibar + ICH9_REG_FDOD);
843 }
844
David Hendricksce6b2fa2011-07-11 22:12:43 -0700845}
846
Edward O'Callaghan4b90b622020-05-18 16:20:56 +1000847int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
David Hendricksce6b2fa2011-07-11 22:12:43 -0700848{
stefanct1fc3a732011-09-15 23:52:55 +0000849 uint8_t i;
850 uint8_t nr;
851 struct ich_desc_region *r = &desc->region;
852
853 /* Test if bit-fields are working as expected.
854 * FIXME: Replace this with dynamic bitfield fixup
855 */
856 for (i = 0; i < 4; i++)
857 desc->region.FLREGs[i] = 0x5A << (i * 8);
858 if (r->reg0_base != 0x005A || r->reg0_limit != 0x0000 ||
859 r->reg1_base != 0x1A00 || r->reg1_limit != 0x0000 ||
860 r->reg2_base != 0x0000 || r->reg2_limit != 0x005A ||
861 r->reg3_base != 0x0000 || r->reg3_limit != 0x1A00) {
862 msg_pdbg("The combination of compiler and CPU architecture used"
863 "does not lay out bit-fields as expected, sorry.\n");
864 msg_pspew("r->reg0_base = 0x%04X (0x005A)\n", r->reg0_base);
865 msg_pspew("r->reg0_limit = 0x%04X (0x0000)\n", r->reg0_limit);
866 msg_pspew("r->reg1_base = 0x%04X (0x1A00)\n", r->reg1_base);
867 msg_pspew("r->reg1_limit = 0x%04X (0x0000)\n", r->reg1_limit);
868 msg_pspew("r->reg2_base = 0x%04X (0x0000)\n", r->reg2_base);
869 msg_pspew("r->reg2_limit = 0x%04X (0x005A)\n", r->reg2_limit);
870 msg_pspew("r->reg3_base = 0x%04X (0x0000)\n", r->reg3_base);
871 msg_pspew("r->reg3_limit = 0x%04X (0x1A00)\n", r->reg3_limit);
872 return ICH_RET_ERR;
873 }
874
Edward O'Callaghan568cd262020-05-26 23:10:45 +1000875 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
stefanct1fc3a732011-09-15 23:52:55 +0000876 /* content section */
Edward O'Callaghan5a7ae7a2020-05-18 16:29:45 +1000877 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
878 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
879 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
880 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
David Hendricksce6b2fa2011-07-11 22:12:43 -0700881
882 /* component section */
Edward O'Callaghan5a7ae7a2020-05-18 16:29:45 +1000883 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
884 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
885 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
David Hendricksce6b2fa2011-07-11 22:12:43 -0700886
887 /* region section */
stefanct1fc3a732011-09-15 23:52:55 +0000888 nr = desc->content.NR + 1;
889 if (nr >= 5) {
890 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
891 __func__, nr);
892 return ICH_RET_ERR;
893 }
894 for (i = 0; i <= nr; i++)
Edward O'Callaghan5a7ae7a2020-05-18 16:29:45 +1000895 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
David Hendricksce6b2fa2011-07-11 22:12:43 -0700896
897 /* master section */
Edward O'Callaghan4b90b622020-05-18 16:20:56 +1000898 if (cs >= CHIPSET_100_SERIES_SUNRISE_POINT) {
Edward O'Callaghan5a7ae7a2020-05-18 16:29:45 +1000899 desc->master.pch100.FLMSTR1 = read_descriptor_reg(cs, 3, 0, spibar);
900 desc->master.pch100.FLMSTR2 = read_descriptor_reg(cs, 3, 1, spibar);
901 desc->master.pch100.FLMSTR3 = read_descriptor_reg(cs, 3, 2, spibar);
902 desc->master.pch100.FLMSTR4 = read_descriptor_reg(cs, 3, 3, spibar);
903 desc->master.pch100.FLMSTR5 = read_descriptor_reg(cs, 3, 4, spibar);
Duncan Lauriedbbf2222019-04-25 12:06:19 -0700904 } else {
Edward O'Callaghan5a7ae7a2020-05-18 16:29:45 +1000905 desc->master.ich.FLMSTR1 = read_descriptor_reg(cs, 3, 0, spibar);
906 desc->master.ich.FLMSTR2 = read_descriptor_reg(cs, 3, 1, spibar);
907 desc->master.ich.FLMSTR3 = read_descriptor_reg(cs, 3, 2, spibar);
Duncan Lauriedbbf2222019-04-25 12:06:19 -0700908 }
David Hendricksce6b2fa2011-07-11 22:12:43 -0700909
stefanct1fc3a732011-09-15 23:52:55 +0000910 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
911 * reading the upper map is impossible on all chipsets, so don't bother.
912 */
913
914 msg_pdbg2(" done.\n");
915 return ICH_RET_OK;
David Hendricksce6b2fa2011-07-11 22:12:43 -0700916}
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700917#endif /* ICH_DESCRIPTORS_FROM_DUMP */
stefanct1fc3a732011-09-15 23:52:55 +0000918#endif /* defined(__i386__) || defined(__x86_64__) */