blob: 01ff649df09053ff5b4f93b77e0ad0d4a21b72aa [file] [log] [blame]
Stefan Tauner1e146392011-09-15 23:52:55 +00001/*
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.
Stefan Tauner1e146392011-09-15 23:52:55 +000016 */
17
Thomas Heijligen3f4d35d2022-01-17 15:11:43 +010018#include "hwaccess_physmap.h"
Stefan Tauner1e146392011-09-15 23:52:55 +000019#include "ich_descriptors.h"
Stefan Taunerb3850962011-12-24 00:00:32 +000020
Nico Huberad186312016-05-02 15:15:29 +020021#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +000022#include <stdio.h>
Nico Huber305f4172013-06-14 11:55:26 +020023#include <string.h>
Stefan Taunerb3850962011-12-24 00:00:32 +000024#define print(t, ...) printf(__VA_ARGS__)
Nico Huberad186312016-05-02 15:15:29 +020025#endif
26
Stefan Taunerb3850962011-12-24 00:00:32 +000027#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
Felix Singerd68a0ec2022-08-19 03:23:35 +020034#include <stdbool.h>
Nico Huber4d440a72017-08-15 11:26:48 +020035#include <sys/types.h>
Nico Huberad186312016-05-02 15:15:29 +020036#include <string.h>
Stefan Tauner1e146392011-09-15 23:52:55 +000037#include "flash.h" /* for msg_* */
38#include "programmer.h"
39
Nico Huberfa622942017-03-24 17:25:37 +010040ssize_t ich_number_of_regions(const enum ich_chipset cs, const struct ich_desc_content *const cont)
41{
42 switch (cs) {
Nico Huberd2d39932019-01-18 16:49:37 +010043 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +020044 case CHIPSET_GEMINI_LAKE:
Nico Huberd2d39932019-01-18 16:49:37 +010045 return 6;
David Hendricksa5216362017-08-08 20:02:22 -070046 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +020047 case CHIPSET_300_SERIES_CANNON_POINT:
Michał Żygowski5c9f5422021-06-16 15:13:54 +020048 case CHIPSET_500_SERIES_TIGER_POINT:
Werner Zehe57d4e42022-01-03 09:44:29 +010049 case CHIPSET_ELKHART_LAKE:
David Hendricksa5216362017-08-08 20:02:22 -070050 return 16;
Nico Huberfa622942017-03-24 17:25:37 +010051 case CHIPSET_100_SERIES_SUNRISE_POINT:
52 return 10;
53 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
54 case CHIPSET_9_SERIES_WILDCAT_POINT:
55 case CHIPSET_8_SERIES_LYNX_POINT_LP:
56 case CHIPSET_8_SERIES_LYNX_POINT:
57 case CHIPSET_8_SERIES_WELLSBURG:
58 if (cont->NR <= 6)
59 return cont->NR + 1;
60 else
61 return -1;
62 default:
63 if (cont->NR <= 4)
64 return cont->NR + 1;
65 else
66 return -1;
67 }
68}
69
70ssize_t ich_number_of_masters(const enum ich_chipset cs, const struct ich_desc_content *const cont)
71{
David Hendricksa5216362017-08-08 20:02:22 -070072 switch (cs) {
73 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huberd2d39932019-01-18 16:49:37 +010074 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +020075 case CHIPSET_GEMINI_LAKE:
Werner Zehe57d4e42022-01-03 09:44:29 +010076 case CHIPSET_ELKHART_LAKE:
David Hendricksa5216362017-08-08 20:02:22 -070077 if (cont->NM <= MAX_NUM_MASTERS)
78 return cont->NM;
Richard Hughesdb7482b2018-12-19 12:04:30 +000079 break;
David Hendricksa5216362017-08-08 20:02:22 -070080 default:
81 if (cont->NM < MAX_NUM_MASTERS)
82 return cont->NM + 1;
83 }
84
85 return -1;
Nico Huberfa622942017-03-24 17:25:37 +010086}
87
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +000088void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
Stefan Tauner1e146392011-09-15 23:52:55 +000089{
90 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
91 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
92 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
93 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +000094 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
95 if (print_vcl)
96 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
97 print(verbosity, "\n");
Stefan Tauner1e146392011-09-15 23:52:55 +000098}
99
100#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
101#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
102#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
103#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
104#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
105
Nico Huber67d71792017-06-17 03:10:15 +0200106void prettyprint_ich_chipset(enum ich_chipset cs)
107{
108 static const char *const chipset_names[] = {
109 "Unknown ICH", "ICH8", "ICH9", "ICH10",
110 "5 series Ibex Peak", "6 series Cougar Point", "7 series Panther Point",
Nico Huberdfd06472024-07-14 23:45:05 +0200111 "Baytrail", "8 series Lynx Point", "8 series Lynx Point LP", "8 series Wellsburg",
Nico Huber67d71792017-06-17 03:10:15 +0200112 "9 series Wildcat Point", "9 series Wildcat Point LP", "100 series Sunrise Point",
Angel Pons4db0fdf2020-07-10 17:04:10 +0200113 "C620 series Lewisburg", "300/400 series Cannon/Comet Point",
Nico Huber29c23dd2022-12-21 15:25:09 +0000114 "500/600 series Tiger/Alder Point", "Apollo Lake", "Gemini Lake", "Elkhart Lake",
Nico Huber67d71792017-06-17 03:10:15 +0200115 };
116 if (cs < CHIPSET_ICH8 || cs - CHIPSET_ICH8 + 1 >= ARRAY_SIZE(chipset_names))
117 cs = 0;
118 else
119 cs = cs - CHIPSET_ICH8 + 1;
120 msg_pdbg2("Assuming chipset '%s'.\n", chipset_names[cs]);
121}
122
Stefan Tauner1e146392011-09-15 23:52:55 +0000123void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
124{
Nico Huberfa622942017-03-24 17:25:37 +0100125 prettyprint_ich_descriptor_content(cs, &desc->content);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000126 prettyprint_ich_descriptor_component(cs, desc);
Nico Huberfa622942017-03-24 17:25:37 +0100127 prettyprint_ich_descriptor_region(cs, desc);
128 prettyprint_ich_descriptor_master(cs, desc);
Nico Huberad186312016-05-02 15:15:29 +0200129#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000130 if (cs >= CHIPSET_ICH8) {
131 prettyprint_ich_descriptor_upper_map(&desc->upper);
132 prettyprint_ich_descriptor_straps(cs, desc);
133 }
Nico Huberad186312016-05-02 15:15:29 +0200134#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */
Stefan Tauner1e146392011-09-15 23:52:55 +0000135}
136
Nico Huberfa622942017-03-24 17:25:37 +0100137void prettyprint_ich_descriptor_content(enum ich_chipset cs, const struct ich_desc_content *cont)
Stefan Tauner1e146392011-09-15 23:52:55 +0000138{
139 msg_pdbg2("=== Content Section ===\n");
140 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
141 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
142 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
143 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
144 msg_pdbg2("\n");
145
146 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100147 msg_pdbg2("NR (Number of Regions): %5zd\n", ich_number_of_regions(cs, cont));
148 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
149 msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
150 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
Nico Huberd2d39932019-01-18 16:49:37 +0100151 msg_pdbg2("ISL (ICH/PCH/SoC Strap Length): %5d\n", cont->ISL);
152 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH/SoC Strap Base Addr): 0x%03x\n", getFISBA(cont));
Nico Huberfa622942017-03-24 17:25:37 +0100153 msg_pdbg2("NM (Number of Masters): %5zd\n", ich_number_of_masters(cs, cont));
154 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
155 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
156 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
Stefan Tauner1e146392011-09-15 23:52:55 +0000157 msg_pdbg2("\n");
158}
159
Nico Huberdfd06472024-07-14 23:45:05 +0200160static unsigned int get_density_index(
161 enum ich_chipset cs, const struct ich_descriptors *desc, unsigned int component)
162{
163 if (cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY) {
164 if (component == 0)
165 return desc->component.dens_old.comp1_density;
166 else
167 return desc->component.dens_old.comp2_density;
168 } else {
169 if (component == 0)
170 return desc->component.dens_new.comp1_density;
171 else
172 return desc->component.dens_new.comp2_density;
173 }
174}
175
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000176static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
177{
178 if (idx > 1) {
179 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Nico Huberdfd06472024-07-14 23:45:05 +0200180 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000181 }
Nico Huberdfd06472024-07-14 23:45:05 +0200182 if (cs == CHIPSET_ICH_UNKNOWN)
183 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000184
185 if (desc->content.NC == 0 && idx > 0)
186 return "unused";
187
188 static const char * const size_str[] = {
189 "512 kB", /* 0000 */
190 "1 MB", /* 0001 */
191 "2 MB", /* 0010 */
192 "4 MB", /* 0011 */
193 "8 MB", /* 0100 */
194 "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
195 "32 MB", /* 0110 */
196 "64 MB", /* 0111 */
197 };
Nico Huberdfd06472024-07-14 23:45:05 +0200198 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
199 const unsigned int size_idx = get_density_index(cs, desc, idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000200
Nico Huberdfd06472024-07-14 23:45:05 +0200201 if (size_idx > max_idx)
202 return "reserved";
203
204 return size_str[size_idx];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000205}
206
207static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000208{
Werner Zehe57d4e42022-01-03 09:44:29 +0100209 static const char *const freq_str[5][8] = { {
Nico Huber129e9382019-06-06 15:43:27 +0200210 "20 MHz",
211 "33 MHz",
212 "reserved",
213 "reserved",
214 "50 MHz", /* New since Ibex Peak */
215 "reserved",
216 "reserved",
217 "reserved"
Nico Huberfa622942017-03-24 17:25:37 +0100218 }, {
Nico Huber129e9382019-06-06 15:43:27 +0200219 "reserved",
220 "reserved",
221 "48 MHz",
222 "reserved",
223 "30 MHz",
224 "reserved",
225 "17 MHz",
226 "reserved"
Nico Huberd2d39932019-01-18 16:49:37 +0100227 }, {
228 "reserved",
229 "50 MHz",
230 "40 MHz",
231 "reserved",
232 "25 MHz",
233 "reserved",
234 "14 MHz / 17 MHz",
235 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200236 }, {
237 "100 MHz",
238 "50 MHz",
239 "reserved",
240 "33 MHz",
241 "25 MHz",
242 "reserved",
243 "14 MHz",
244 "reserved"
Werner Zehe57d4e42022-01-03 09:44:29 +0100245 }, {
246 "reserved",
247 "50 MHz",
248 "reserved",
249 "reserved",
250 "33 MHz",
251 "20 MHz",
252 "reserved",
253 "reserved",
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200254 }};
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000255
256 switch (cs) {
257 case CHIPSET_ICH8:
258 case CHIPSET_ICH9:
259 case CHIPSET_ICH10:
260 if (value > 1)
261 return "reserved";
Richard Hughesdb7482b2018-12-19 12:04:30 +0000262 /* Fall through. */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000263 case CHIPSET_5_SERIES_IBEX_PEAK:
264 case CHIPSET_6_SERIES_COUGAR_POINT:
265 case CHIPSET_7_SERIES_PANTHER_POINT:
266 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000267 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000268 case CHIPSET_8_SERIES_LYNX_POINT_LP:
269 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000270 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100271 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Nico Huberfa622942017-03-24 17:25:37 +0100272 return freq_str[0][value];
273 case CHIPSET_100_SERIES_SUNRISE_POINT:
David Hendricksa5216362017-08-08 20:02:22 -0700274 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200275 case CHIPSET_300_SERIES_CANNON_POINT:
Nico Huberfa622942017-03-24 17:25:37 +0100276 return freq_str[1][value];
Nico Huberd2d39932019-01-18 16:49:37 +0100277 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +0200278 case CHIPSET_GEMINI_LAKE:
Nico Huberd2d39932019-01-18 16:49:37 +0100279 return freq_str[2][value];
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200280 case CHIPSET_500_SERIES_TIGER_POINT:
281 return freq_str[3][value];
Werner Zehe57d4e42022-01-03 09:44:29 +0100282 case CHIPSET_ELKHART_LAKE:
283 return freq_str[4][value];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000284 case CHIPSET_ICH_UNKNOWN:
285 default:
286 return "unknown";
287 }
288}
289
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200290static void pprint_read_freq(enum ich_chipset cs, uint8_t value)
291{
292 static const char *const freq_str[1][8] = { {
293 "20 MHz",
294 "24 MHz",
295 "30 MHz",
296 "48 MHz",
297 "60 MHz",
298 "reserved",
299 "reserved",
300 "reserved"
301 }};
302
303 switch (cs) {
304 case CHIPSET_300_SERIES_CANNON_POINT:
305 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[0][value]);
306 return;
307 case CHIPSET_500_SERIES_TIGER_POINT:
308 msg_pdbg2("Read Clock Frequency: %s\n", "reserved");
309 return;
310 default:
311 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, value));
312 return;
313 }
314}
315
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000316void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
317{
Nico Huberb2ad9fd2024-07-14 23:18:53 +0200318 const bool has_flill1 = cs >= SPI_ENGINE_PCH100;
Stefan Tauner1e146392011-09-15 23:52:55 +0000319
320 msg_pdbg2("=== Component Section ===\n");
321 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
322 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
Nico Huberd2d39932019-01-18 16:49:37 +0100323 if (has_flill1)
Nico Huberfa622942017-03-24 17:25:37 +0100324 msg_pdbg2("FLILL1 0x%08x\n", desc->component.FLILL1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000325 msg_pdbg2("\n");
326
327 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000328 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000329 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000330 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000331 else
332 msg_pdbg2("Component 2 is not used.\n");
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200333
334 pprint_read_freq(cs, desc->component.modes.freq_read);
335
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000336 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
337 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
338 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
339 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000340 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000341 pprint_freq(cs, desc->component.modes.freq_fastread));
Nico Huber3f75d442024-07-14 19:17:56 +0200342 switch (cs) {
343 case CHIPSET_7_SERIES_PANTHER_POINT:
344 case CHIPSET_8_SERIES_LYNX_POINT:
345 case CHIPSET_BAYTRAIL:
346 case CHIPSET_8_SERIES_LYNX_POINT_LP:
347 case CHIPSET_8_SERIES_WELLSBURG:
348 case CHIPSET_9_SERIES_WILDCAT_POINT:
349 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
350 case CHIPSET_100_SERIES_SUNRISE_POINT:
351 case CHIPSET_APOLLO_LAKE:
352 case CHIPSET_C620_SERIES_LEWISBURG:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000353 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Werner Zehd3e8fd92022-01-25 07:02:49 +0100354 desc->component.modes.dual_output ? "en" : "dis");
Nico Huber3f75d442024-07-14 19:17:56 +0200355 break;
356 default:
357 break;
358 }
David Hendricksa5216362017-08-08 20:02:22 -0700359
Felix Singerd68a0ec2022-08-19 03:23:35 +0200360 bool has_forbidden_opcode = false;
David Hendricksa5216362017-08-08 20:02:22 -0700361 if (desc->component.FLILL != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200362 has_forbidden_opcode = true;
Stefan Tauner1e146392011-09-15 23:52:55 +0000363 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
364 desc->component.invalid_instr0);
365 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
366 desc->component.invalid_instr1);
367 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
368 desc->component.invalid_instr2);
369 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
370 desc->component.invalid_instr3);
David Hendricksa5216362017-08-08 20:02:22 -0700371 }
Nico Huberd2d39932019-01-18 16:49:37 +0100372 if (has_flill1) {
David Hendricksa5216362017-08-08 20:02:22 -0700373 if (desc->component.FLILL1 != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200374 has_forbidden_opcode = true;
Nico Huberfa622942017-03-24 17:25:37 +0100375 msg_pdbg2("Invalid instruction 4: 0x%02x\n",
376 desc->component.invalid_instr4);
377 msg_pdbg2("Invalid instruction 5: 0x%02x\n",
378 desc->component.invalid_instr5);
379 msg_pdbg2("Invalid instruction 6: 0x%02x\n",
380 desc->component.invalid_instr6);
381 msg_pdbg2("Invalid instruction 7: 0x%02x\n",
382 desc->component.invalid_instr7);
383 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000384 }
David Hendricksa5216362017-08-08 20:02:22 -0700385 if (!has_forbidden_opcode)
386 msg_pdbg2("No forbidden opcodes.\n");
387
Stefan Tauner1e146392011-09-15 23:52:55 +0000388 msg_pdbg2("\n");
389}
390
391static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
392{
Nico Huberfa622942017-03-24 17:25:37 +0100393 static const char *const region_names[] = {
Nico Huberd2d39932019-01-18 16:49:37 +0100394 "Descr.", "BIOS", "ME", "GbE", "Platf.", "DevExp", "BIOS2", "unknown",
David Hendricksa5216362017-08-08 20:02:22 -0700395 "EC/BMC", "unknown", "IE", "10GbE", "unknown", "unknown", "unknown", "unknown"
Stefan Tauner1e146392011-09-15 23:52:55 +0000396 };
Nico Huberfa622942017-03-24 17:25:37 +0100397 if (i >= ARRAY_SIZE(region_names)) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000398 msg_pdbg2("%s: region index too high.\n", __func__);
399 return;
400 }
401 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
402 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
Nico Huberfa622942017-03-24 17:25:37 +0100403 msg_pdbg2("Region %d (%-7s) ", i, region_names[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000404 if (base > limit)
405 msg_pdbg2("is unused.\n");
406 else
Nico Huber0bb3f712017-03-29 16:44:33 +0200407 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
Stefan Tauner1e146392011-09-15 23:52:55 +0000408}
409
Nico Huberfa622942017-03-24 17:25:37 +0100410void prettyprint_ich_descriptor_region(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000411{
Nico Huber519be662018-12-23 20:03:35 +0100412 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100413 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000414 msg_pdbg2("=== Region Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100415 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000416 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
Nico Huberfa622942017-03-24 17:25:37 +0100417 desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000418 return;
419 }
Nico Huberfa622942017-03-24 17:25:37 +0100420 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100421 msg_pdbg2("FLREG%zd 0x%08x\n", i, desc->region.FLREGs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000422 msg_pdbg2("\n");
423
424 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100425 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100426 pprint_freg(&desc->region, (uint32_t)i);
Stefan Tauner1e146392011-09-15 23:52:55 +0000427 msg_pdbg2("\n");
428}
429
Nico Huberfa622942017-03-24 17:25:37 +0100430void prettyprint_ich_descriptor_master(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000431{
Nico Huber519be662018-12-23 20:03:35 +0100432 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100433 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000434 msg_pdbg2("=== Master Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100435 if (nm < 0) {
436 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
437 desc->content.NM + 1);
438 return;
439 }
440 for (i = 0; i < nm; i++)
Nico Huber519be662018-12-23 20:03:35 +0100441 msg_pdbg2("FLMSTR%zd 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000442 msg_pdbg2("\n");
443
444 msg_pdbg2("--- Details ---\n");
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200445 if (cs == CHIPSET_100_SERIES_SUNRISE_POINT ||
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200446 cs == CHIPSET_300_SERIES_CANNON_POINT ||
447 cs == CHIPSET_500_SERIES_TIGER_POINT) {
Nico Huberfa622942017-03-24 17:25:37 +0100448 const char *const master_names[] = {
449 "BIOS", "ME", "GbE", "unknown", "EC",
450 };
Nico Huber519be662018-12-23 20:03:35 +0100451 if (nm >= (ssize_t)ARRAY_SIZE(master_names)) {
Nico Huberfa622942017-03-24 17:25:37 +0100452 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
453 desc->content.NM + 1);
454 return;
455 }
456
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200457 size_t num_regions;
458 msg_pdbg2(" FD BIOS ME GbE Pltf Reg5 Reg6 Reg7 EC Reg9");
459 if (cs == CHIPSET_100_SERIES_SUNRISE_POINT) {
460 num_regions = 10;
461 msg_pdbg2("\n");
462 } else {
463 num_regions = 16;
464 msg_pdbg2(" RegA RegB RegC RegD RegE RegF\n");
465 }
Nico Huberfa622942017-03-24 17:25:37 +0100466 for (i = 0; i < nm; i++) {
aarya0ac29562022-03-13 15:35:12 +0530467 const unsigned int ext_region_start = 12;
Nico Huberfa622942017-03-24 17:25:37 +0100468 size_t j;
469 msg_pdbg2("%-4s", master_names[i]);
aarya0ac29562022-03-13 15:35:12 +0530470 for (j = 0; j < (size_t)min(num_regions, ext_region_start); j++)
Nico Huberfa622942017-03-24 17:25:37 +0100471 msg_pdbg2(" %c%c ",
472 desc->master.mstr[i].read & (1 << j) ? 'r' : ' ',
473 desc->master.mstr[i].write & (1 << j) ? 'w' : ' ');
aarya0ac29562022-03-13 15:35:12 +0530474 for (j = ext_region_start; j < num_regions; j++)
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200475 msg_pdbg2(" %c%c ",
aarya0ac29562022-03-13 15:35:12 +0530476 desc->master.mstr[i].ext_read & (1 << (j - ext_region_start)) ? 'r' : ' ',
477 desc->master.mstr[i].ext_write & (1 << (j - ext_region_start)) ? 'w' : ' ');
Nico Huberfa622942017-03-24 17:25:37 +0100478 msg_pdbg2("\n");
479 }
David Hendricksa5216362017-08-08 20:02:22 -0700480 } else if (cs == CHIPSET_C620_SERIES_LEWISBURG) {
481 const char *const master_names[] = {
482 "BIOS", "ME", "GbE", "DE", "BMC", "IE",
483 };
484 /* NM starts at 1 instead of 0 for LBG */
Nico Huber519be662018-12-23 20:03:35 +0100485 if (nm > (ssize_t)ARRAY_SIZE(master_names)) {
David Hendricksa5216362017-08-08 20:02:22 -0700486 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
487 desc->content.NM);
488 return;
489 }
490
491 msg_pdbg2("%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",
492 " ", /* width of master name (4 chars minimum) */
493 " FD ", " BIOS", " ME ", " GbE ", " Pltf",
494 " DE ", "BIOS2", " Reg7", " BMC ", " DE2 ",
495 " IE ", "10GbE", "OpROM", "Reg13", "Reg14",
496 "Reg15");
497 for (i = 0; i < nm; i++) {
498 size_t j;
499 msg_pdbg2("%-4s", master_names[i]);
500 for (j = 0; j < 16; j++)
501 msg_pdbg2(" %c%c ",
502 desc->master.mstr[i].read & (1 << j) ? 'r' : ' ',
503 desc->master.mstr[i].write & (1 << j) ? 'w' : ' ');
504 msg_pdbg2("\n");
505 }
Werner Zehe57d4e42022-01-03 09:44:29 +0100506 } else if (cs == CHIPSET_APOLLO_LAKE || cs == CHIPSET_GEMINI_LAKE || cs == CHIPSET_ELKHART_LAKE) {
Nico Huberd2d39932019-01-18 16:49:37 +0100507 const char *const master_names[] = { "BIOS", "TXE", };
Nico Huber519be662018-12-23 20:03:35 +0100508 if (nm > (ssize_t)ARRAY_SIZE(master_names)) {
Nico Huberd2d39932019-01-18 16:49:37 +0100509 msg_pdbg2("%s: number of masters too high (%d).\n", __func__, desc->content.NM);
510 return;
511 }
512
513 msg_pdbg2(" FD IFWI TXE n/a Platf DevExp\n");
514 for (i = 0; i < nm; i++) {
Nico Huber519be662018-12-23 20:03:35 +0100515 ssize_t j;
Nico Huberd2d39932019-01-18 16:49:37 +0100516 msg_pdbg2("%-4s", master_names[i]);
517 for (j = 0; j < ich_number_of_regions(cs, &desc->content); j++)
518 msg_pdbg2(" %c%c ",
519 desc->master.mstr[i].read & (1 << j) ? 'r' : ' ',
520 desc->master.mstr[i].write & (1 << j) ? 'w' : ' ');
521 msg_pdbg2("\n");
522 }
Nico Huberfa622942017-03-24 17:25:37 +0100523 } else {
524 const struct ich_desc_master *const mstr = &desc->master;
525 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
526 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
527 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
528 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
529 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
530 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
531 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
532 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
533 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
534 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
535 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
536 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
537 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
538 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
539 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
540 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
541 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
542 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
543 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
544 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000545 msg_pdbg2("\n");
546}
547
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600548static void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
Stefan Taunerb3850962011-12-24 00:00:32 +0000549{
550 static const char * const str_GPIO12[4] = {
551 "GPIO12",
552 "LAN PHY Power Control Function (Native Output)",
553 "GLAN_DOCK# (Native Input)",
554 "invalid configuration",
555 };
556
557 msg_pdbg2("--- MCH details ---\n");
558 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
559 msg_pdbg2("\n");
560
561 msg_pdbg2("--- ICH details ---\n");
562 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
563 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
564 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
565 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
566 msg_pdbg2("SPI CS1 is used for %s.\n",
567 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
568 "LAN PHY Power Control Function" :
569 "SPI Chip Select");
570 msg_pdbg2("GPIO12 is used as %s.\n",
571 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
572 msg_pdbg2("PCIe Port 6 is used for %s.\n",
573 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
574 msg_pdbg2("%sn BMC Mode: "
575 "Intel AMT SMBus Controller 1 is connected to %s.\n",
576 desc->south.ich8.BMCMODE ? "I" : "Not i",
577 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
578 msg_pdbg2("TCO is in %s Mode.\n",
579 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
580 msg_pdbg2("ME A is %sabled.\n",
581 desc->south.ich8.ME_DISABLE ? "dis" : "en");
582 msg_pdbg2("\n");
583}
584
585static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
586{
587 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
588
589 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000590 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000591 case 0:
592 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
593 break;
594 case 1:
595 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
596 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
597 break;
598 case 2:
599 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
600 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
601 break;
602 case 3:
603 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
604 1+off, 2+off, 4+off);
605 break;
606 }
607 msg_pdbg2("\n");
608}
609
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600610static void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000611{
612 /* PCHSTRP4 */
613 msg_pdbg2("Intel PHY is %s.\n",
614 (s->ibex.PHYCON == 2) ? "connected" :
615 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
616 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
617 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
618 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
619 s->ibex.GBEMAC_SMBUS_ADDR);
620 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
621 s->ibex.GBEPHY_SMBUS_ADDR);
622
623 /* PCHSTRP5 */
624 /* PCHSTRP6 */
625 /* PCHSTRP7 */
626 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
627 s->ibex.MESMA2UDID_VENDOR);
628 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
629 s->ibex.MESMA2UDID_VENDOR);
630
631 /* PCHSTRP8 */
632}
633
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600634static void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000635{
636 /* PCHSTRP11 */
637 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
638 s->ibex.SML1GPAEN ? "en" : "dis");
639 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
640 s->ibex.SML1GPA);
641 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
642 s->ibex.SML1I2CAEN ? "en" : "dis");
643 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
644 s->ibex.SML1I2CA);
645
646 /* PCHSTRP12 */
647 /* PCHSTRP13 */
648}
649
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600650static void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000651{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000652 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000653 100,
654 50,
655 5,
656 1
657 };
658
659 msg_pdbg2("--- PCH ---\n");
660
661 /* PCHSTRP0 */
662 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
663 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
664 s->ibex.SMB_EN ? "en" : "dis");
665 msg_pdbg2("SMLink0 segment is %sabled.\n",
666 s->ibex.SML0_EN ? "en" : "dis");
667 msg_pdbg2("SMLink1 segment is %sabled.\n",
668 s->ibex.SML1_EN ? "en" : "dis");
669 msg_pdbg2("SMLink1 Frequency: %s\n",
670 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
671 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
672 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
673 msg_pdbg2("SMLink0 Frequency: %s\n",
674 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
675 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
676 "LAN_PHY_PWR_CTRL" : "general purpose output");
677 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
678 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
679 s->ibex.DMI_REQID_DIS ? "en" : "dis");
680 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
681 1 << (6 + s->ibex.BBBS));
682
683 /* PCHSTRP1 */
684 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
685
686 /* PCHSTRP2 */
687 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
688 s->ibex.MESMASDEN ? "en" : "dis");
689 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
690 s->ibex.MESMASDA);
691 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
692 s->ibex.MESMI2CEN ? "en" : "dis");
693 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
694 s->ibex.MESMI2CA);
695
696 /* PCHSTRP3 */
697 prettyprint_ich_descriptor_pchstraps45678_56(s);
698 /* PCHSTRP9 */
699 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
700 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
701 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
702 s->ibex.PCIELR1 ? "" : "not ");
703 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
704 s->ibex.PCIELR2 ? "" : "not ");
705 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
706 s->ibex.DMILR ? "" : "not ");
707 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
708 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
709 s->ibex.PHY_PCIE_EN ? "en" : "dis");
710
711 /* PCHSTRP10 */
712 msg_pdbg2("Management Engine will boot from %sflash.\n",
713 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
714 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
715 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
716 s->ibex.VE_EN ? "en" : "dis");
717 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
718 s->ibex.MMDDE ? "en" : "dis");
719 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
720 s->ibex.MMADDR);
721 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
722 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
723 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
724 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
725 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
726
727 prettyprint_ich_descriptor_pchstraps111213_56(s);
728
729 /* PCHSTRP14 */
730 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
731 s->ibex.VE_EN2 ? "en" : "dis");
732 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
733 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
734 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
735 s->ibex.BW_SSD ? "en" : "dis");
736 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
737 s->ibex.NVMHCI_EN ? "en" : "dis");
738
739 /* PCHSTRP15 */
740 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
741 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
742 s->ibex.IWL_EN ? "en" : "dis");
743 msg_pdbg2("t209 min Timing: %d ms\n",
744 dec_t209min[s->ibex.t209min]);
745 msg_pdbg2("\n");
746}
747
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600748static void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000749{
750 msg_pdbg2("--- PCH ---\n");
751
752 /* PCHSTRP0 */
753 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
754 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
755 s->ibex.SMB_EN ? "en" : "dis");
756 msg_pdbg2("SMLink0 segment is %sabled.\n",
757 s->ibex.SML0_EN ? "en" : "dis");
758 msg_pdbg2("SMLink1 segment is %sabled.\n",
759 s->ibex.SML1_EN ? "en" : "dis");
760 msg_pdbg2("SMLink1 Frequency: %s\n",
761 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
762 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
763 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
764 msg_pdbg2("SMLink0 Frequency: %s\n",
765 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
766 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
767 "LAN_PHY_PWR_CTRL" : "general purpose output");
768 msg_pdbg2("LinkSec is %sabled.\n",
769 s->cougar.LINKSEC_DIS ? "en" : "dis");
770 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
771 s->ibex.DMI_REQID_DIS ? "en" : "dis");
772 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
773 1 << (6 + s->ibex.BBBS));
774
775 /* PCHSTRP1 */
776 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
777 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
778
779 /* PCHSTRP2 */
780 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
781 s->ibex.MESMASDEN ? "en" : "dis");
782 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
783 s->ibex.MESMASDA);
784 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
785 s->cougar.MESMMCTPAEN ? "en" : "dis");
786 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
787 s->cougar.MESMMCTPA);
788 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
789 s->ibex.MESMI2CEN ? "en" : "dis");
790 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
791 s->ibex.MESMI2CA);
792
793 /* PCHSTRP3 */
794 prettyprint_ich_descriptor_pchstraps45678_56(s);
795 /* PCHSTRP9 */
796 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
797 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
798 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
799 s->ibex.PCIELR1 ? "" : "not ");
800 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
801 s->ibex.PCIELR2 ? "" : "not ");
802 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
803 s->ibex.DMILR ? "" : "not ");
804 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
805 s->cougar.MDSMBE_EN ? "en" : "dis");
806 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
807 s->cougar.MDSMBE_ADD);
808 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
809 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
810 s->ibex.PHY_PCIE_EN ? "en" : "dis");
811 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
812 s->cougar.SUB_DECODE_EN ? "en" : "dis");
813 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
814 "PCHHOT#" : "SML1ALERT#");
815
816 /* PCHSTRP10 */
817 msg_pdbg2("Management Engine will boot from %sflash.\n",
818 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
819
820 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
821 s->cougar.MDSMBE_EN ? "en" : "dis");
822 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
823 s->cougar.MDSMBE_ADD);
824
825 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
826 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000827 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
828 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000829 msg_pdbg2("ICC Profile is selected by %s.\n",
830 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
831 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
832 s->cougar.Deep_SX_EN ? "not " : "");
833 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
834 s->cougar.ME_DBG_LAN ? "en" : "dis");
835
836 prettyprint_ich_descriptor_pchstraps111213_56(s);
837
838 /* PCHSTRP14 */
839 /* PCHSTRP15 */
840 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
841 msg_pdbg2("Integrated wired LAN is %sabled.\n",
842 s->cougar.IWL_EN ? "en" : "dis");
843 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
844 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000845 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000846 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
847 "general purpose output" : "SLP_LAN#");
848
849 /* PCHSTRP16 */
850 /* PCHSTRP17 */
851 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
852 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
853 msg_pdbg2("\n");
854}
855
856void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
857{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000858 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000859 msg_pdbg2("=== Softstraps ===\n");
860
Nico Huber519be662018-12-23 20:03:35 +0100861 max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
Nico Huberd7c75522017-03-29 16:31:49 +0200862 if (max_count < desc->content.MSL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000863 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
Nico Huberd7c75522017-03-29 16:31:49 +0200864 desc->content.MSL, max_count);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000865 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200866 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000867
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000868 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
869 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000870 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
871 msg_pdbg2("\n");
872
Nico Huber519be662018-12-23 20:03:35 +0100873 max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
Nico Huberd7c75522017-03-29 16:31:49 +0200874 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000875 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
876 desc->content.ISL, max_count);
877 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200878 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000879
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000880 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
881 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000882 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
883 msg_pdbg2("\n");
884
885 switch (cs) {
886 case CHIPSET_ICH8:
887 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
888 msg_pdbg2("Detailed North/MCH/PROC information is "
889 "probably not reliable, printing anyway.\n");
890 if (sizeof(desc->south.ich8) / 4 != desc->content.ISL)
891 msg_pdbg2("Detailed South/ICH/PCH information is "
892 "probably not reliable, printing anyway.\n");
893 prettyprint_ich_descriptor_straps_ich8(desc);
894 break;
895 case CHIPSET_5_SERIES_IBEX_PEAK:
896 /* PCH straps only. PROCSTRPs are unknown. */
897 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
898 msg_pdbg2("Detailed South/ICH/PCH information is "
899 "probably not reliable, printing anyway.\n");
900 prettyprint_ich_descriptor_straps_ibex(&desc->south);
901 break;
902 case CHIPSET_6_SERIES_COUGAR_POINT:
903 /* PCH straps only. PROCSTRP0 is "reserved". */
904 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
905 msg_pdbg2("Detailed South/ICH/PCH information is "
906 "probably not reliable, printing anyway.\n");
907 prettyprint_ich_descriptor_straps_cougar(&desc->south);
908 break;
909 case CHIPSET_ICH_UNKNOWN:
910 break;
911 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000912 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000913 break;
914 }
915}
916
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600917static void prettyprint_rdid(uint32_t reg_val)
Stefan Taunerb3850962011-12-24 00:00:32 +0000918{
919 uint8_t mid = reg_val & 0xFF;
920 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
921 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
922}
923
924void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
925{
926 int i;
927 msg_pdbg2("=== Upper Map Section ===\n");
928 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
929 msg_pdbg2("\n");
930
931 msg_pdbg2("--- Details ---\n");
932 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
933 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
934 msg_pdbg2("\n");
935
936 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000937 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +0000938 uint32_t jid = umap->vscc_table[i].JID;
939 uint32_t vscc = umap->vscc_table[i].VSCC;
940 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
941 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600942 msg_pdbg2(" "); /* indentation */
Stefan Taunerb3850962011-12-24 00:00:32 +0000943 prettyprint_rdid(jid);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600944 msg_pdbg2(" "); /* indentation */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000945 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +0000946 }
947 msg_pdbg2("\n");
948}
949
David Hendricks66565a72021-09-20 21:56:40 -0700950static inline void warn_peculiar_desc(const char *const name)
Nico Huber964007a2021-06-17 21:12:47 +0200951{
Nico Huber964007a2021-06-17 21:12:47 +0200952 msg_pwarn("Peculiar flash descriptor, assuming %s compatibility.\n", name);
953}
954
Nico Huber1dc3d422017-06-17 00:09:31 +0200955/*
956 * Guesses a minimum chipset version based on the maximum number of
Nico Huber3ad9aad2021-06-17 22:05:00 +0200957 * soft straps per generation and presence of the MIP base (MDTBA).
Nico Huber1dc3d422017-06-17 00:09:31 +0200958 */
Nico Huber3ad9aad2021-06-17 22:05:00 +0200959static enum ich_chipset guess_ich_chipset_from_content(const struct ich_desc_content *const content,
960 const struct ich_desc_upper_map *const upper)
Nico Huber1dc3d422017-06-17 00:09:31 +0200961{
962 if (content->ICCRIBA == 0x00) {
963 if (content->MSL == 0 && content->ISL <= 2)
964 return CHIPSET_ICH8;
Nico Huber83b01c82021-06-17 21:20:09 +0200965 if (content->ISL <= 2)
Nico Huber1dc3d422017-06-17 00:09:31 +0200966 return CHIPSET_ICH9;
Nico Huber83b01c82021-06-17 21:20:09 +0200967 if (content->ISL <= 10)
Nico Huber1dc3d422017-06-17 00:09:31 +0200968 return CHIPSET_ICH10;
David Hendricks66565a72021-09-20 21:56:40 -0700969 if (content->ISL <= 16)
970 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber83b01c82021-06-17 21:20:09 +0200971 if (content->FLMAP2 == 0) {
Nico Huber81965f32021-06-17 23:25:35 +0200972 if (content->ISL == 19)
973 return CHIPSET_APOLLO_LAKE;
David Hendricks66565a72021-09-20 21:56:40 -0700974 if (content->ISL == 23)
975 return CHIPSET_GEMINI_LAKE;
976 warn_peculiar_desc("Gemini Lake");
Nico Huber81965f32021-06-17 23:25:35 +0200977 return CHIPSET_GEMINI_LAKE;
Nico Huberd2d39932019-01-18 16:49:37 +0100978 }
Jonathan Zhang3bf7cfb2021-08-30 23:25:06 -0700979 if (content->ISL <= 80)
980 return CHIPSET_C620_SERIES_LEWISBURG;
David Hendricks66565a72021-09-20 21:56:40 -0700981 warn_peculiar_desc("Ibex Peak");
Nico Huber1dc3d422017-06-17 00:09:31 +0200982 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber3ad9aad2021-06-17 22:05:00 +0200983 } else if (upper->MDTBA == 0x00) {
984 if (content->ICCRIBA < 0x31 && content->FMSBA < 0x30) {
985 if (content->MSL == 0 && content->ISL <= 17)
986 return CHIPSET_BAYTRAIL;
987 if (content->MSL <= 1 && content->ISL <= 18)
988 return CHIPSET_6_SERIES_COUGAR_POINT;
David Hendricks66565a72021-09-20 21:56:40 -0700989 if (content->MSL <= 1 && content->ISL <= 21)
990 return CHIPSET_8_SERIES_LYNX_POINT;
991 warn_peculiar_desc("Lynx Point");
Nico Huber81965f32021-06-17 23:25:35 +0200992 return CHIPSET_8_SERIES_LYNX_POINT;
Nico Huber3ad9aad2021-06-17 22:05:00 +0200993 }
994 if (content->NM == 6) {
David Hendricks66565a72021-09-20 21:56:40 -0700995 if (content->ICCRIBA <= 0x34)
996 return CHIPSET_C620_SERIES_LEWISBURG;
997 warn_peculiar_desc("C620 series");
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200998 return CHIPSET_C620_SERIES_LEWISBURG;
Nico Huber3ad9aad2021-06-17 22:05:00 +0200999 }
David Hendricks66565a72021-09-20 21:56:40 -07001000 if (content->ICCRIBA == 0x31)
1001 return CHIPSET_100_SERIES_SUNRISE_POINT;
1002 warn_peculiar_desc("100 series");
Nico Huber83b01c82021-06-17 21:20:09 +02001003 return CHIPSET_100_SERIES_SUNRISE_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001004 } else {
David Hendricks66565a72021-09-20 21:56:40 -07001005 if (content->ICCRIBA == 0x34)
1006 return CHIPSET_300_SERIES_CANNON_POINT;
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001007 if (content->CSSL == 0x11)
1008 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber29c23dd2022-12-21 15:25:09 +00001009 if (content->CSSL == 0x14) /* backwards compatible Alder Point */
1010 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber756b6b32022-12-21 17:15:13 +00001011 if (content->CSSL == 0x03) {
1012 if (content->CSSO == 0x58)
1013 return CHIPSET_ELKHART_LAKE;
1014 else if (content->CSSO == 0x6c) /* backwards compatible Jasper Lake */
1015 return CHIPSET_300_SERIES_CANNON_POINT;
1016 }
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001017 msg_pwarn("Unknown flash descriptor, assuming 500 series compatibility.\n");
1018 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001019 }
1020}
1021
1022/*
1023 * As an additional measure, we check the read frequency like `ifdtool`.
1024 * The frequency value 6 (17MHz) was reserved before Skylake and is the
1025 * only valid value since. Skylake is currently the most important dis-
1026 * tinction because of the dropped number of regions field (NR).
1027 */
Nico Huberfa622942017-03-24 17:25:37 +01001028static enum ich_chipset guess_ich_chipset(const struct ich_desc_content *const content,
Nico Huber3ad9aad2021-06-17 22:05:00 +02001029 const struct ich_desc_component *const component,
1030 const struct ich_desc_upper_map *const upper)
Nico Huber1dc3d422017-06-17 00:09:31 +02001031{
Nico Huber3ad9aad2021-06-17 22:05:00 +02001032 const enum ich_chipset guess = guess_ich_chipset_from_content(content, upper);
Nico Huber1dc3d422017-06-17 00:09:31 +02001033
Nico Huberd2d39932019-01-18 16:49:37 +01001034 switch (guess) {
Nico Huber2a5dfaf2019-07-04 16:01:51 +02001035 case CHIPSET_300_SERIES_CANNON_POINT:
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001036 case CHIPSET_500_SERIES_TIGER_POINT:
Angel Pons4db0fdf2020-07-10 17:04:10 +02001037 case CHIPSET_GEMINI_LAKE:
Werner Zehe57d4e42022-01-03 09:44:29 +01001038 case CHIPSET_ELKHART_LAKE:
Nico Huber2a5dfaf2019-07-04 16:01:51 +02001039 /* `freq_read` was repurposed, so can't check on it any more. */
Nico Huber72a9dc02021-06-17 22:47:00 +02001040 break;
Nico Huberd2d39932019-01-18 16:49:37 +01001041 case CHIPSET_100_SERIES_SUNRISE_POINT:
1042 case CHIPSET_C620_SERIES_LEWISBURG:
1043 case CHIPSET_APOLLO_LAKE:
1044 if (component->modes.freq_read != 6) {
Nico Huber964007a2021-06-17 21:12:47 +02001045 msg_pwarn("\nThe flash descriptor looks like a Skylake/Sunrise Point descriptor.\n"
Nico Huberd2d39932019-01-18 16:49:37 +01001046 "However, the read frequency isn't set to 17MHz (the only valid value).\n"
1047 "Please report this message, the output of `ich_descriptors_tool` for\n"
Nico Huberc3b02dc2023-08-12 01:13:45 +02001048 "your descriptor and the output of `lspci -nn` to flashprog@flashprog.org\n\n");
Nico Huberd2d39932019-01-18 16:49:37 +01001049 }
Nico Huber72a9dc02021-06-17 22:47:00 +02001050 break;
Nico Huberd2d39932019-01-18 16:49:37 +01001051 default:
1052 if (component->modes.freq_read == 6) {
Nico Huber964007a2021-06-17 21:12:47 +02001053 msg_pwarn("\nThe flash descriptor has the read frequency set to 17MHz. However,\n"
Nico Huber1dc3d422017-06-17 00:09:31 +02001054 "it doesn't look like a Skylake/Sunrise Point compatible descriptor.\n"
1055 "Please report this message, the output of `ich_descriptors_tool` for\n"
Nico Huberc3b02dc2023-08-12 01:13:45 +02001056 "your descriptor and the output of `lspci -nn` to flashprog@flashprog.org\n\n");
David Hendricksa5216362017-08-08 20:02:22 -07001057 }
Nico Huber1dc3d422017-06-17 00:09:31 +02001058 }
Nico Huber72a9dc02021-06-17 22:47:00 +02001059 return guess;
Nico Huber1dc3d422017-06-17 00:09:31 +02001060}
1061
Stefan Taunerb3850962011-12-24 00:00:32 +00001062/* len is the length of dump in bytes */
Nico Huberfa622942017-03-24 17:25:37 +01001063int read_ich_descriptors_from_dump(const uint32_t *const dump, const size_t len,
1064 enum ich_chipset *const cs, struct ich_descriptors *const desc)
Stefan Taunerb3850962011-12-24 00:00:32 +00001065{
Nico Huber519be662018-12-23 20:03:35 +01001066 ssize_t i, max_count;
1067 size_t pch_bug_offset = 0;
Stefan Taunerb3850962011-12-24 00:00:32 +00001068
1069 if (dump == NULL || desc == NULL)
1070 return ICH_RET_PARAM;
1071
1072 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
1073 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
1074 pch_bug_offset = 4;
1075 else
1076 return ICH_RET_ERR;
1077 }
1078
1079 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +02001080 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001081 return ICH_RET_OOB;
1082 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
1083 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
1084 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
1085 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
1086
1087 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +02001088 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001089 return ICH_RET_OOB;
1090 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
1091 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
1092 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
1093
Nico Huber8a03c902021-06-17 21:23:29 +02001094 /* upper map */
1095 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
1096
1097 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
1098 * "Identifies the 1s based number of DWORDS contained in the VSCC
1099 * Table. Each SPI component entry in the table is 2 DWORDS long." So
1100 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
1101 * check ensures that the maximum offset actually accessed is available.
1102 */
1103 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
1104 return ICH_RET_OOB;
1105
1106 for (i = 0; i < desc->upper.VTL/2; i++) {
1107 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
1108 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
1109 }
1110
Nico Huber67d71792017-06-17 03:10:15 +02001111 if (*cs == CHIPSET_ICH_UNKNOWN) {
Nico Huber3ad9aad2021-06-17 22:05:00 +02001112 *cs = guess_ich_chipset(&desc->content, &desc->component, &desc->upper);
Nico Huber67d71792017-06-17 03:10:15 +02001113 prettyprint_ich_chipset(*cs);
1114 }
Nico Huberfa622942017-03-24 17:25:37 +01001115
Stefan Taunerb3850962011-12-24 00:00:32 +00001116 /* region */
Nico Huberfa622942017-03-24 17:25:37 +01001117 const ssize_t nr = ich_number_of_regions(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001118 if (nr < 0 || len < getFRBA(&desc->content) + (size_t)nr * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001119 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001120 for (i = 0; i < nr; i++)
1121 desc->region.FLREGs[i] = dump[(getFRBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001122
1123 /* master */
Nico Huberfa622942017-03-24 17:25:37 +01001124 const ssize_t nm = ich_number_of_masters(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001125 if (nm < 0 || len < getFMBA(&desc->content) + (size_t)nm * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001126 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001127 for (i = 0; i < nm; i++)
1128 desc->master.FLMSTRs[i] = dump[(getFMBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001129
Stefan Taunerb3850962011-12-24 00:00:32 +00001130 /* MCH/PROC (aka. North) straps */
1131 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
1132 return ICH_RET_OOB;
1133
1134 /* limit the range to be written */
Nico Huber519be662018-12-23 20:03:35 +01001135 max_count = MIN(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001136 for (i = 0; i < max_count; i++)
1137 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001138
1139 /* ICH/PCH (aka. South) straps */
1140 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
1141 return ICH_RET_OOB;
1142
1143 /* limit the range to be written */
Nico Huber519be662018-12-23 20:03:35 +01001144 max_count = MIN(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001145 for (i = 0; i < max_count; i++)
1146 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001147
1148 return ICH_RET_OK;
1149}
1150
Nico Huberad186312016-05-02 15:15:29 +02001151#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +00001152
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001153/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001154\em idx in bytes or -1 if the correct size can not be determined. */
1155int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001156{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001157 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001158 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001159 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001160 }
Nico Huberdfd06472024-07-14 23:45:05 +02001161 if (cs == CHIPSET_ICH_UNKNOWN) {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001162 msg_pwarn("Density encoding is unknown on this chipset.\n");
1163 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001164 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001165
Nico Huberdfd06472024-07-14 23:45:05 +02001166 if (desc->content.NC == 0 && idx > 0)
1167 return 0;
1168
1169 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
1170 const unsigned int size_idx = get_density_index(cs, desc, idx);
1171
1172 if (size_idx > max_idx) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +00001173 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001174 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
Nico Huberdfd06472024-07-14 23:45:05 +02001175 idx, size_idx, max_idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001176 return -1;
1177 }
1178
Nico Huberdfd06472024-07-14 23:45:05 +02001179 return 1 << (19 + size_idx);
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001180}
1181
Nico Huber8d494992017-06-19 12:18:33 +02001182/* Only used by ichspi.c */
1183#if CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__))
Nico Huberd54e4f42017-03-23 23:45:47 +01001184static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
Stefan Tauner1e146392011-09-15 23:52:55 +00001185{
1186 uint32_t control = 0;
1187 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
1188 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001189
1190 if (cs >= SPI_ENGINE_PCH100) {
Nico Huberd54e4f42017-03-23 23:45:47 +01001191 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
1192 return mmio_le_readl(spibar + PCH100_REG_FDOD);
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001193 } else {
Nico Huberd54e4f42017-03-23 23:45:47 +01001194 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
1195 return mmio_le_readl(spibar + ICH9_REG_FDOD);
1196 }
Stefan Tauner1e146392011-09-15 23:52:55 +00001197}
1198
Nico Huberd54e4f42017-03-23 23:45:47 +01001199int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
Stefan Tauner1e146392011-09-15 23:52:55 +00001200{
Nico Huber519be662018-12-23 20:03:35 +01001201 ssize_t i;
Stefan Tauner1e146392011-09-15 23:52:55 +00001202 struct ich_desc_region *r = &desc->region;
1203
1204 /* Test if bit-fields are working as expected.
1205 * FIXME: Replace this with dynamic bitfield fixup
1206 */
1207 for (i = 0; i < 4; i++)
1208 desc->region.FLREGs[i] = 0x5A << (i * 8);
Nico Huberfa622942017-03-24 17:25:37 +01001209 if (r->old_reg[0].base != 0x005A || r->old_reg[0].limit != 0x0000 ||
1210 r->old_reg[1].base != 0x1A00 || r->old_reg[1].limit != 0x0000 ||
1211 r->old_reg[2].base != 0x0000 || r->old_reg[2].limit != 0x005A ||
1212 r->old_reg[3].base != 0x0000 || r->old_reg[3].limit != 0x1A00) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001213 msg_pdbg("The combination of compiler and CPU architecture used"
1214 "does not lay out bit-fields as expected, sorry.\n");
Nico Huberfa622942017-03-24 17:25:37 +01001215 msg_pspew("r->old_reg[0].base = 0x%04X (0x005A)\n", r->old_reg[0].base);
1216 msg_pspew("r->old_reg[0].limit = 0x%04X (0x0000)\n", r->old_reg[0].limit);
1217 msg_pspew("r->old_reg[1].base = 0x%04X (0x1A00)\n", r->old_reg[1].base);
1218 msg_pspew("r->old_reg[1].limit = 0x%04X (0x0000)\n", r->old_reg[1].limit);
1219 msg_pspew("r->old_reg[2].base = 0x%04X (0x0000)\n", r->old_reg[2].base);
1220 msg_pspew("r->old_reg[2].limit = 0x%04X (0x005A)\n", r->old_reg[2].limit);
1221 msg_pspew("r->old_reg[3].base = 0x%04X (0x0000)\n", r->old_reg[3].base);
1222 msg_pspew("r->old_reg[3].limit = 0x%04X (0x1A00)\n", r->old_reg[3].limit);
Stefan Tauner1e146392011-09-15 23:52:55 +00001223 return ICH_RET_ERR;
1224 }
1225
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001226 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +00001227 /* content section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001228 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
1229 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
1230 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
1231 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001232
1233 /* component section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001234 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
1235 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
1236 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001237
1238 /* region section */
Nico Huberfa622942017-03-24 17:25:37 +01001239 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
1240 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001241 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
Nico Huberfa622942017-03-24 17:25:37 +01001242 __func__, desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +00001243 return ICH_RET_ERR;
1244 }
Nico Huberfa622942017-03-24 17:25:37 +01001245 for (i = 0; i < nr; i++)
Nico Huberd54e4f42017-03-23 23:45:47 +01001246 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001247
1248 /* master section */
Nico Huberfa622942017-03-24 17:25:37 +01001249 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
1250 if (nm < 0) {
1251 msg_pdbg2("%s: number of masters too high (%d) - failed\n",
1252 __func__, desc->content.NM + 1);
1253 return ICH_RET_ERR;
1254 }
1255 for (i = 0; i < nm; i++)
1256 desc->master.FLMSTRs[i] = read_descriptor_reg(cs, 3, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001257
1258 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
1259 * reading the upper map is impossible on all chipsets, so don't bother.
1260 */
1261
1262 msg_pdbg2(" done.\n");
1263 return ICH_RET_OK;
1264}
Nico Huber8d494992017-06-19 12:18:33 +02001265#endif
Nico Huber305f4172013-06-14 11:55:26 +02001266
1267/**
1268 * @brief Read a layout from the dump of an Intel ICH descriptor.
1269 *
1270 * @param layout Pointer where to store the layout.
1271 * @param dump The descriptor dump to read from.
1272 * @param len The length of the descriptor dump.
1273 *
1274 * @return 0 on success,
Nico Huber70461a92019-06-15 14:56:19 +02001275 * 1 if the descriptor couldn't be parsed,
1276 * 2 when out of memory.
Nico Huber305f4172013-06-14 11:55:26 +02001277 */
Nico Huber5bd990c2019-06-16 19:46:46 +02001278int layout_from_ich_descriptors(
Nico Huberc3b02dc2023-08-12 01:13:45 +02001279 struct flashprog_layout **const layout,
Nico Huber5bd990c2019-06-16 19:46:46 +02001280 const void *const dump, const size_t len)
Nico Huber305f4172013-06-14 11:55:26 +02001281{
Nico Huberfa622942017-03-24 17:25:37 +01001282 static const char *const regions[] = {
David Hendricksa5216362017-08-08 20:02:22 -07001283 "fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
1284 "10gbe", "reg12", "reg13", "reg14", "reg15"
Nico Huberfa622942017-03-24 17:25:37 +01001285 };
Nico Huber305f4172013-06-14 11:55:26 +02001286
1287 struct ich_descriptors desc;
Nico Huberfa622942017-03-24 17:25:37 +01001288 enum ich_chipset cs = CHIPSET_ICH_UNKNOWN;
1289 if (read_ich_descriptors_from_dump(dump, len, &cs, &desc))
Nico Huber305f4172013-06-14 11:55:26 +02001290 return 1;
1291
Nico Huberc3b02dc2023-08-12 01:13:45 +02001292 if (flashprog_layout_new(layout))
Nico Huber5bd990c2019-06-16 19:46:46 +02001293 return 2;
Nico Huber305f4172013-06-14 11:55:26 +02001294
Nico Huber92e0b622019-06-15 15:55:11 +02001295 ssize_t i;
Nico Huber519be662018-12-23 20:03:35 +01001296 const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
Nico Huber92e0b622019-06-15 15:55:11 +02001297 for (i = 0; i < nr; ++i) {
Nico Huber305f4172013-06-14 11:55:26 +02001298 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
Nico Huber0bb3f712017-03-29 16:44:33 +02001299 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
Nico Huber305f4172013-06-14 11:55:26 +02001300 if (limit <= base)
1301 continue;
Nico Huberc3b02dc2023-08-12 01:13:45 +02001302 if (flashprog_layout_add_region(*layout, base, limit, regions[i])) {
1303 flashprog_layout_release(*layout);
Nico Huber5bd990c2019-06-16 19:46:46 +02001304 *layout = NULL;
Nico Huber70461a92019-06-15 14:56:19 +02001305 return 2;
Nico Huber5bd990c2019-06-16 19:46:46 +02001306 }
Nico Huber305f4172013-06-14 11:55:26 +02001307 }
Nico Huber305f4172013-06-14 11:55:26 +02001308 return 0;
1309}
1310
Nico Huberad186312016-05-02 15:15:29 +02001311#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */