blob: f24d3534fdce8e8411eebacd8cecf341b8dbc50f [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
Nico Huber157b8182024-07-19 17:48:12 +020088static bool has_classic_proc_straps(const enum ich_chipset cs)
89{
90 switch (cs) {
91 case CHIPSET_100_SERIES_SUNRISE_POINT:
92 case CHIPSET_C620_SERIES_LEWISBURG:
93 return true;
94 default:
95 return cs < SPI_ENGINE_PCH100;
96 }
97}
98
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +000099void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
Stefan Tauner1e146392011-09-15 23:52:55 +0000100{
101 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
102 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
103 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
104 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000105 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
106 if (print_vcl)
107 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
108 print(verbosity, "\n");
Stefan Tauner1e146392011-09-15 23:52:55 +0000109}
110
111#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
112#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
113#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
114#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
115#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
116
Nico Huber67d71792017-06-17 03:10:15 +0200117void prettyprint_ich_chipset(enum ich_chipset cs)
118{
119 static const char *const chipset_names[] = {
120 "Unknown ICH", "ICH8", "ICH9", "ICH10",
121 "5 series Ibex Peak", "6 series Cougar Point", "7 series Panther Point",
Nico Huberdfd06472024-07-14 23:45:05 +0200122 "Baytrail", "8 series Lynx Point", "8 series Lynx Point LP", "8 series Wellsburg",
Nico Huber67d71792017-06-17 03:10:15 +0200123 "9 series Wildcat Point", "9 series Wildcat Point LP", "100 series Sunrise Point",
Angel Pons4db0fdf2020-07-10 17:04:10 +0200124 "C620 series Lewisburg", "300/400 series Cannon/Comet Point",
Nico Huber29c23dd2022-12-21 15:25:09 +0000125 "500/600 series Tiger/Alder Point", "Apollo Lake", "Gemini Lake", "Elkhart Lake",
Nico Huber67d71792017-06-17 03:10:15 +0200126 };
127 if (cs < CHIPSET_ICH8 || cs - CHIPSET_ICH8 + 1 >= ARRAY_SIZE(chipset_names))
128 cs = 0;
129 else
130 cs = cs - CHIPSET_ICH8 + 1;
131 msg_pdbg2("Assuming chipset '%s'.\n", chipset_names[cs]);
132}
133
Stefan Tauner1e146392011-09-15 23:52:55 +0000134void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
135{
Nico Huberfa622942017-03-24 17:25:37 +0100136 prettyprint_ich_descriptor_content(cs, &desc->content);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000137 prettyprint_ich_descriptor_component(cs, desc);
Nico Huberfa622942017-03-24 17:25:37 +0100138 prettyprint_ich_descriptor_region(cs, desc);
139 prettyprint_ich_descriptor_master(cs, desc);
Nico Huberad186312016-05-02 15:15:29 +0200140#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000141 if (cs >= CHIPSET_ICH8) {
142 prettyprint_ich_descriptor_upper_map(&desc->upper);
143 prettyprint_ich_descriptor_straps(cs, desc);
144 }
Nico Huberad186312016-05-02 15:15:29 +0200145#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */
Stefan Tauner1e146392011-09-15 23:52:55 +0000146}
147
Nico Huberfa622942017-03-24 17:25:37 +0100148void prettyprint_ich_descriptor_content(enum ich_chipset cs, const struct ich_desc_content *cont)
Stefan Tauner1e146392011-09-15 23:52:55 +0000149{
150 msg_pdbg2("=== Content Section ===\n");
151 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
152 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
153 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
154 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
155 msg_pdbg2("\n");
156
157 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100158 msg_pdbg2("NR (Number of Regions): %5zd\n", ich_number_of_regions(cs, cont));
159 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
160 msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
161 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
Nico Huberd2d39932019-01-18 16:49:37 +0100162 msg_pdbg2("ISL (ICH/PCH/SoC Strap Length): %5d\n", cont->ISL);
163 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH/SoC Strap Base Addr): 0x%03x\n", getFISBA(cont));
Nico Huberfa622942017-03-24 17:25:37 +0100164 msg_pdbg2("NM (Number of Masters): %5zd\n", ich_number_of_masters(cs, cont));
165 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
Nico Huber157b8182024-07-19 17:48:12 +0200166 if (has_classic_proc_straps(cs)) {
167 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
168 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
169 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000170 msg_pdbg2("\n");
171}
172
Nico Huberdfd06472024-07-14 23:45:05 +0200173static unsigned int get_density_index(
174 enum ich_chipset cs, const struct ich_descriptors *desc, unsigned int component)
175{
176 if (cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY) {
177 if (component == 0)
178 return desc->component.dens_old.comp1_density;
179 else
180 return desc->component.dens_old.comp2_density;
181 } else {
182 if (component == 0)
183 return desc->component.dens_new.comp1_density;
184 else
185 return desc->component.dens_new.comp2_density;
186 }
187}
188
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000189static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
190{
191 if (idx > 1) {
192 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Nico Huberdfd06472024-07-14 23:45:05 +0200193 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000194 }
Nico Huberdfd06472024-07-14 23:45:05 +0200195 if (cs == CHIPSET_ICH_UNKNOWN)
196 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000197
198 if (desc->content.NC == 0 && idx > 0)
199 return "unused";
200
201 static const char * const size_str[] = {
202 "512 kB", /* 0000 */
203 "1 MB", /* 0001 */
204 "2 MB", /* 0010 */
205 "4 MB", /* 0011 */
206 "8 MB", /* 0100 */
207 "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
208 "32 MB", /* 0110 */
209 "64 MB", /* 0111 */
210 };
Nico Huberdfd06472024-07-14 23:45:05 +0200211 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
212 const unsigned int size_idx = get_density_index(cs, desc, idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000213
Nico Huberdfd06472024-07-14 23:45:05 +0200214 if (size_idx > max_idx)
215 return "reserved";
216
217 return size_str[size_idx];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000218}
219
220static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000221{
Werner Zehe57d4e42022-01-03 09:44:29 +0100222 static const char *const freq_str[5][8] = { {
Nico Huber129e9382019-06-06 15:43:27 +0200223 "20 MHz",
224 "33 MHz",
225 "reserved",
226 "reserved",
227 "50 MHz", /* New since Ibex Peak */
228 "reserved",
229 "reserved",
230 "reserved"
Nico Huberfa622942017-03-24 17:25:37 +0100231 }, {
Nico Huber129e9382019-06-06 15:43:27 +0200232 "reserved",
233 "reserved",
234 "48 MHz",
235 "reserved",
236 "30 MHz",
237 "reserved",
238 "17 MHz",
239 "reserved"
Nico Huberd2d39932019-01-18 16:49:37 +0100240 }, {
241 "reserved",
242 "50 MHz",
243 "40 MHz",
244 "reserved",
245 "25 MHz",
246 "reserved",
247 "14 MHz / 17 MHz",
248 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200249 }, {
250 "100 MHz",
251 "50 MHz",
252 "reserved",
253 "33 MHz",
254 "25 MHz",
255 "reserved",
256 "14 MHz",
257 "reserved"
Werner Zehe57d4e42022-01-03 09:44:29 +0100258 }, {
259 "reserved",
260 "50 MHz",
261 "reserved",
262 "reserved",
263 "33 MHz",
264 "20 MHz",
265 "reserved",
266 "reserved",
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200267 }};
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000268
269 switch (cs) {
270 case CHIPSET_ICH8:
271 case CHIPSET_ICH9:
272 case CHIPSET_ICH10:
273 if (value > 1)
274 return "reserved";
Richard Hughesdb7482b2018-12-19 12:04:30 +0000275 /* Fall through. */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000276 case CHIPSET_5_SERIES_IBEX_PEAK:
277 case CHIPSET_6_SERIES_COUGAR_POINT:
278 case CHIPSET_7_SERIES_PANTHER_POINT:
279 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000280 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000281 case CHIPSET_8_SERIES_LYNX_POINT_LP:
282 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000283 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100284 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Nico Huberfa622942017-03-24 17:25:37 +0100285 return freq_str[0][value];
286 case CHIPSET_100_SERIES_SUNRISE_POINT:
David Hendricksa5216362017-08-08 20:02:22 -0700287 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200288 case CHIPSET_300_SERIES_CANNON_POINT:
Nico Huberfa622942017-03-24 17:25:37 +0100289 return freq_str[1][value];
Nico Huberd2d39932019-01-18 16:49:37 +0100290 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +0200291 case CHIPSET_GEMINI_LAKE:
Nico Huberd2d39932019-01-18 16:49:37 +0100292 return freq_str[2][value];
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200293 case CHIPSET_500_SERIES_TIGER_POINT:
294 return freq_str[3][value];
Werner Zehe57d4e42022-01-03 09:44:29 +0100295 case CHIPSET_ELKHART_LAKE:
296 return freq_str[4][value];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000297 case CHIPSET_ICH_UNKNOWN:
298 default:
299 return "unknown";
300 }
301}
302
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200303static void pprint_read_freq(enum ich_chipset cs, uint8_t value)
304{
305 static const char *const freq_str[1][8] = { {
306 "20 MHz",
307 "24 MHz",
308 "30 MHz",
309 "48 MHz",
310 "60 MHz",
311 "reserved",
312 "reserved",
313 "reserved"
314 }};
315
316 switch (cs) {
317 case CHIPSET_300_SERIES_CANNON_POINT:
318 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[0][value]);
319 return;
320 case CHIPSET_500_SERIES_TIGER_POINT:
321 msg_pdbg2("Read Clock Frequency: %s\n", "reserved");
322 return;
323 default:
324 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, value));
325 return;
326 }
327}
328
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000329void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
330{
Nico Huberb2ad9fd2024-07-14 23:18:53 +0200331 const bool has_flill1 = cs >= SPI_ENGINE_PCH100;
Stefan Tauner1e146392011-09-15 23:52:55 +0000332
333 msg_pdbg2("=== Component Section ===\n");
334 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
335 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
Nico Huberd2d39932019-01-18 16:49:37 +0100336 if (has_flill1)
Nico Huberfa622942017-03-24 17:25:37 +0100337 msg_pdbg2("FLILL1 0x%08x\n", desc->component.FLILL1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000338 msg_pdbg2("\n");
339
340 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000341 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000342 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000343 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000344 else
345 msg_pdbg2("Component 2 is not used.\n");
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200346
347 pprint_read_freq(cs, desc->component.modes.freq_read);
348
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000349 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
350 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
351 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
352 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000353 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000354 pprint_freq(cs, desc->component.modes.freq_fastread));
Nico Huber3f75d442024-07-14 19:17:56 +0200355 switch (cs) {
356 case CHIPSET_7_SERIES_PANTHER_POINT:
357 case CHIPSET_8_SERIES_LYNX_POINT:
358 case CHIPSET_BAYTRAIL:
359 case CHIPSET_8_SERIES_LYNX_POINT_LP:
360 case CHIPSET_8_SERIES_WELLSBURG:
361 case CHIPSET_9_SERIES_WILDCAT_POINT:
362 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
363 case CHIPSET_100_SERIES_SUNRISE_POINT:
364 case CHIPSET_APOLLO_LAKE:
365 case CHIPSET_C620_SERIES_LEWISBURG:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000366 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Werner Zehd3e8fd92022-01-25 07:02:49 +0100367 desc->component.modes.dual_output ? "en" : "dis");
Nico Huber3f75d442024-07-14 19:17:56 +0200368 break;
369 default:
370 break;
371 }
David Hendricksa5216362017-08-08 20:02:22 -0700372
Felix Singerd68a0ec2022-08-19 03:23:35 +0200373 bool has_forbidden_opcode = false;
David Hendricksa5216362017-08-08 20:02:22 -0700374 if (desc->component.FLILL != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200375 has_forbidden_opcode = true;
Stefan Tauner1e146392011-09-15 23:52:55 +0000376 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
377 desc->component.invalid_instr0);
378 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
379 desc->component.invalid_instr1);
380 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
381 desc->component.invalid_instr2);
382 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
383 desc->component.invalid_instr3);
David Hendricksa5216362017-08-08 20:02:22 -0700384 }
Nico Huberd2d39932019-01-18 16:49:37 +0100385 if (has_flill1) {
David Hendricksa5216362017-08-08 20:02:22 -0700386 if (desc->component.FLILL1 != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200387 has_forbidden_opcode = true;
Nico Huberfa622942017-03-24 17:25:37 +0100388 msg_pdbg2("Invalid instruction 4: 0x%02x\n",
389 desc->component.invalid_instr4);
390 msg_pdbg2("Invalid instruction 5: 0x%02x\n",
391 desc->component.invalid_instr5);
392 msg_pdbg2("Invalid instruction 6: 0x%02x\n",
393 desc->component.invalid_instr6);
394 msg_pdbg2("Invalid instruction 7: 0x%02x\n",
395 desc->component.invalid_instr7);
396 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000397 }
David Hendricksa5216362017-08-08 20:02:22 -0700398 if (!has_forbidden_opcode)
399 msg_pdbg2("No forbidden opcodes.\n");
400
Stefan Tauner1e146392011-09-15 23:52:55 +0000401 msg_pdbg2("\n");
402}
403
404static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
405{
Nico Huberfa622942017-03-24 17:25:37 +0100406 static const char *const region_names[] = {
Nico Huberd2d39932019-01-18 16:49:37 +0100407 "Descr.", "BIOS", "ME", "GbE", "Platf.", "DevExp", "BIOS2", "unknown",
David Hendricksa5216362017-08-08 20:02:22 -0700408 "EC/BMC", "unknown", "IE", "10GbE", "unknown", "unknown", "unknown", "unknown"
Stefan Tauner1e146392011-09-15 23:52:55 +0000409 };
Nico Huberfa622942017-03-24 17:25:37 +0100410 if (i >= ARRAY_SIZE(region_names)) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000411 msg_pdbg2("%s: region index too high.\n", __func__);
412 return;
413 }
414 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
415 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
Nico Huberfa622942017-03-24 17:25:37 +0100416 msg_pdbg2("Region %d (%-7s) ", i, region_names[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000417 if (base > limit)
418 msg_pdbg2("is unused.\n");
419 else
Nico Huber0bb3f712017-03-29 16:44:33 +0200420 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
Stefan Tauner1e146392011-09-15 23:52:55 +0000421}
422
Nico Huberfa622942017-03-24 17:25:37 +0100423void prettyprint_ich_descriptor_region(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000424{
Nico Huber519be662018-12-23 20:03:35 +0100425 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100426 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000427 msg_pdbg2("=== Region Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100428 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000429 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
Nico Huberfa622942017-03-24 17:25:37 +0100430 desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000431 return;
432 }
Nico Huberfa622942017-03-24 17:25:37 +0100433 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100434 msg_pdbg2("FLREG%zd 0x%08x\n", i, desc->region.FLREGs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000435 msg_pdbg2("\n");
436
437 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100438 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100439 pprint_freg(&desc->region, (uint32_t)i);
Stefan Tauner1e146392011-09-15 23:52:55 +0000440 msg_pdbg2("\n");
441}
442
Nico Huberb3cc2c62024-07-15 00:45:17 +0200443static char prettify_flag(const unsigned int mask, const unsigned int bit, const char flag)
444{
445 return mask & (1 << bit) ? flag : ' ';
446}
447
448/* Takes NULL-terminated lists of names, assumes max. 5 chars per name. */
449static void prettyprint_pch100_masters(
450 const struct ich_descriptors *const desc,
451 const unsigned int number_masters, const char *const masters[],
452 const unsigned int number_regions, const char *const regions[])
453{
454 unsigned int m, r;
455
456 msg_pdbg2(" ");
457 for (r = 0; r < number_regions && regions[r] != NULL; ++r)
458 msg_pdbg2(" %-5s", regions[r]);
459 msg_pdbg2("\n");
460
461 for (m = 0; m < number_masters; ++m) {
462 const unsigned int ext_start = 12;
463
464 if (masters[m] == NULL)
465 break;
466
467 const struct ich_desc_master_region_access master = desc->master.mstr[m];
468
469 msg_pdbg2("%-5s", masters[m]);
470 for (r = 0; r < ext_start && r < number_regions && regions[r] != NULL; ++r)
471 msg_pdbg2(" %c%c ",
472 prettify_flag(master.read, r, 'r'),
473 prettify_flag(master.write, r, 'w'));
474 for (; r < number_regions && regions[r] != NULL; ++r)
475 msg_pdbg2(" %c%c ",
476 prettify_flag(master.ext_read, r - ext_start, 'r'),
477 prettify_flag(master.ext_write, r - ext_start, 'w'));
478 msg_pdbg2("\n");
479 }
480}
481
Nico Huberfa622942017-03-24 17:25:37 +0100482void prettyprint_ich_descriptor_master(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000483{
Nico Huber519be662018-12-23 20:03:35 +0100484 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100485 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000486 msg_pdbg2("=== Master Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100487 if (nm < 0) {
488 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
489 desc->content.NM + 1);
490 return;
491 }
492 for (i = 0; i < nm; i++)
Nico Huber519be662018-12-23 20:03:35 +0100493 msg_pdbg2("FLMSTR%zd 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000494 msg_pdbg2("\n");
495
496 msg_pdbg2("--- Details ---\n");
Nico Huberb3cc2c62024-07-15 00:45:17 +0200497 if (cs >= SPI_ENGINE_PCH100) {
498 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
499 if (nr < 0)
Nico Huberfa622942017-03-24 17:25:37 +0100500 return;
Nico Huberfa622942017-03-24 17:25:37 +0100501
Nico Huberb3cc2c62024-07-15 00:45:17 +0200502 if (cs == CHIPSET_APOLLO_LAKE ||
503 cs == CHIPSET_GEMINI_LAKE ||
504 cs == CHIPSET_ELKHART_LAKE) {
505 const char *const masters[] = {
506 "BIOS", "TXE", NULL
507 };
508 const char *const regions[] = {
509 " FD", "IFWI", " TXE", " n/a", "Pltf.", "DevExp", NULL
510 };
511 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
512 } else if (cs == CHIPSET_C620_SERIES_LEWISBURG) {
513 const char *const masters[] = {
514 "BIOS", "ME", "GbE", "DE", "BMC", "IE", NULL
515 };
516 const char *const regions[] = {
517 " FD ", " BIOS", " ME ", " GbE ", "Pltf.",
David Hendricksa5216362017-08-08 20:02:22 -0700518 " DE ", "BIOS2", " Reg7", " BMC ", " DE2 ",
519 " IE ", "10GbE", "OpROM", "Reg13", "Reg14",
Nico Huberb3cc2c62024-07-15 00:45:17 +0200520 "Reg15", NULL
521 };
522 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
523 } else {
524 const char *const masters[] = {
525 "BIOS", "ME", "GbE", "unkn.", "EC", NULL
526 };
527 const char *const regions[] = {
528 " FD ", "BIOS ", " ME ", " GbE ", "Pltf.",
529 "Reg5 ", "Reg6 ", "Reg7 ", " EC ", "Reg9 ",
530 "Reg10", "Reg11", "Reg12", "Reg13", "Reg14",
531 "Reg15", NULL
532 };
533 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huberd2d39932019-01-18 16:49:37 +0100534 }
Nico Huberfa622942017-03-24 17:25:37 +0100535 } else {
536 const struct ich_desc_master *const mstr = &desc->master;
537 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
538 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
539 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
540 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
541 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
542 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
543 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
544 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
545 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
546 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
547 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
548 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
549 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
550 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
551 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
552 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
553 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
554 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
555 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
556 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000557 msg_pdbg2("\n");
558}
559
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600560static void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
Stefan Taunerb3850962011-12-24 00:00:32 +0000561{
562 static const char * const str_GPIO12[4] = {
563 "GPIO12",
564 "LAN PHY Power Control Function (Native Output)",
565 "GLAN_DOCK# (Native Input)",
566 "invalid configuration",
567 };
568
569 msg_pdbg2("--- MCH details ---\n");
570 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
571 msg_pdbg2("\n");
572
573 msg_pdbg2("--- ICH details ---\n");
574 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
575 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
576 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
577 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
578 msg_pdbg2("SPI CS1 is used for %s.\n",
579 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
580 "LAN PHY Power Control Function" :
581 "SPI Chip Select");
582 msg_pdbg2("GPIO12 is used as %s.\n",
583 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
584 msg_pdbg2("PCIe Port 6 is used for %s.\n",
585 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
586 msg_pdbg2("%sn BMC Mode: "
587 "Intel AMT SMBus Controller 1 is connected to %s.\n",
588 desc->south.ich8.BMCMODE ? "I" : "Not i",
589 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
590 msg_pdbg2("TCO is in %s Mode.\n",
591 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
592 msg_pdbg2("ME A is %sabled.\n",
593 desc->south.ich8.ME_DISABLE ? "dis" : "en");
594 msg_pdbg2("\n");
595}
596
597static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
598{
599 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
600
601 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000602 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000603 case 0:
604 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
605 break;
606 case 1:
607 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
608 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
609 break;
610 case 2:
611 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
612 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
613 break;
614 case 3:
615 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
616 1+off, 2+off, 4+off);
617 break;
618 }
619 msg_pdbg2("\n");
620}
621
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600622static void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000623{
624 /* PCHSTRP4 */
625 msg_pdbg2("Intel PHY is %s.\n",
626 (s->ibex.PHYCON == 2) ? "connected" :
627 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
628 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
629 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
630 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
631 s->ibex.GBEMAC_SMBUS_ADDR);
632 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
633 s->ibex.GBEPHY_SMBUS_ADDR);
634
635 /* PCHSTRP5 */
636 /* PCHSTRP6 */
637 /* PCHSTRP7 */
638 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
639 s->ibex.MESMA2UDID_VENDOR);
640 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
641 s->ibex.MESMA2UDID_VENDOR);
642
643 /* PCHSTRP8 */
644}
645
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600646static void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000647{
648 /* PCHSTRP11 */
649 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
650 s->ibex.SML1GPAEN ? "en" : "dis");
651 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
652 s->ibex.SML1GPA);
653 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
654 s->ibex.SML1I2CAEN ? "en" : "dis");
655 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
656 s->ibex.SML1I2CA);
657
658 /* PCHSTRP12 */
659 /* PCHSTRP13 */
660}
661
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600662static void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000663{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000664 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000665 100,
666 50,
667 5,
668 1
669 };
670
671 msg_pdbg2("--- PCH ---\n");
672
673 /* PCHSTRP0 */
674 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
675 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
676 s->ibex.SMB_EN ? "en" : "dis");
677 msg_pdbg2("SMLink0 segment is %sabled.\n",
678 s->ibex.SML0_EN ? "en" : "dis");
679 msg_pdbg2("SMLink1 segment is %sabled.\n",
680 s->ibex.SML1_EN ? "en" : "dis");
681 msg_pdbg2("SMLink1 Frequency: %s\n",
682 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
683 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
684 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
685 msg_pdbg2("SMLink0 Frequency: %s\n",
686 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
687 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
688 "LAN_PHY_PWR_CTRL" : "general purpose output");
689 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
690 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
691 s->ibex.DMI_REQID_DIS ? "en" : "dis");
692 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
693 1 << (6 + s->ibex.BBBS));
694
695 /* PCHSTRP1 */
696 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
697
698 /* PCHSTRP2 */
699 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
700 s->ibex.MESMASDEN ? "en" : "dis");
701 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
702 s->ibex.MESMASDA);
703 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
704 s->ibex.MESMI2CEN ? "en" : "dis");
705 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
706 s->ibex.MESMI2CA);
707
708 /* PCHSTRP3 */
709 prettyprint_ich_descriptor_pchstraps45678_56(s);
710 /* PCHSTRP9 */
711 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
712 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
713 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
714 s->ibex.PCIELR1 ? "" : "not ");
715 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
716 s->ibex.PCIELR2 ? "" : "not ");
717 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
718 s->ibex.DMILR ? "" : "not ");
719 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
720 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
721 s->ibex.PHY_PCIE_EN ? "en" : "dis");
722
723 /* PCHSTRP10 */
724 msg_pdbg2("Management Engine will boot from %sflash.\n",
725 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
726 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
727 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
728 s->ibex.VE_EN ? "en" : "dis");
729 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
730 s->ibex.MMDDE ? "en" : "dis");
731 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
732 s->ibex.MMADDR);
733 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
734 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
735 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
736 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
737 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
738
739 prettyprint_ich_descriptor_pchstraps111213_56(s);
740
741 /* PCHSTRP14 */
742 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
743 s->ibex.VE_EN2 ? "en" : "dis");
744 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
745 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
746 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
747 s->ibex.BW_SSD ? "en" : "dis");
748 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
749 s->ibex.NVMHCI_EN ? "en" : "dis");
750
751 /* PCHSTRP15 */
752 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
753 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
754 s->ibex.IWL_EN ? "en" : "dis");
755 msg_pdbg2("t209 min Timing: %d ms\n",
756 dec_t209min[s->ibex.t209min]);
757 msg_pdbg2("\n");
758}
759
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600760static void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000761{
762 msg_pdbg2("--- PCH ---\n");
763
764 /* PCHSTRP0 */
765 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
766 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
767 s->ibex.SMB_EN ? "en" : "dis");
768 msg_pdbg2("SMLink0 segment is %sabled.\n",
769 s->ibex.SML0_EN ? "en" : "dis");
770 msg_pdbg2("SMLink1 segment is %sabled.\n",
771 s->ibex.SML1_EN ? "en" : "dis");
772 msg_pdbg2("SMLink1 Frequency: %s\n",
773 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
774 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
775 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
776 msg_pdbg2("SMLink0 Frequency: %s\n",
777 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
778 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
779 "LAN_PHY_PWR_CTRL" : "general purpose output");
780 msg_pdbg2("LinkSec is %sabled.\n",
781 s->cougar.LINKSEC_DIS ? "en" : "dis");
782 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
783 s->ibex.DMI_REQID_DIS ? "en" : "dis");
784 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
785 1 << (6 + s->ibex.BBBS));
786
787 /* PCHSTRP1 */
788 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
789 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
790
791 /* PCHSTRP2 */
792 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
793 s->ibex.MESMASDEN ? "en" : "dis");
794 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
795 s->ibex.MESMASDA);
796 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
797 s->cougar.MESMMCTPAEN ? "en" : "dis");
798 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
799 s->cougar.MESMMCTPA);
800 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
801 s->ibex.MESMI2CEN ? "en" : "dis");
802 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
803 s->ibex.MESMI2CA);
804
805 /* PCHSTRP3 */
806 prettyprint_ich_descriptor_pchstraps45678_56(s);
807 /* PCHSTRP9 */
808 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
809 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
810 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
811 s->ibex.PCIELR1 ? "" : "not ");
812 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
813 s->ibex.PCIELR2 ? "" : "not ");
814 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
815 s->ibex.DMILR ? "" : "not ");
816 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
817 s->cougar.MDSMBE_EN ? "en" : "dis");
818 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
819 s->cougar.MDSMBE_ADD);
820 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
821 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
822 s->ibex.PHY_PCIE_EN ? "en" : "dis");
823 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
824 s->cougar.SUB_DECODE_EN ? "en" : "dis");
825 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
826 "PCHHOT#" : "SML1ALERT#");
827
828 /* PCHSTRP10 */
829 msg_pdbg2("Management Engine will boot from %sflash.\n",
830 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
831
832 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
833 s->cougar.MDSMBE_EN ? "en" : "dis");
834 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
835 s->cougar.MDSMBE_ADD);
836
837 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
838 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000839 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
840 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000841 msg_pdbg2("ICC Profile is selected by %s.\n",
842 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
843 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
844 s->cougar.Deep_SX_EN ? "not " : "");
845 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
846 s->cougar.ME_DBG_LAN ? "en" : "dis");
847
848 prettyprint_ich_descriptor_pchstraps111213_56(s);
849
850 /* PCHSTRP14 */
851 /* PCHSTRP15 */
852 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
853 msg_pdbg2("Integrated wired LAN is %sabled.\n",
854 s->cougar.IWL_EN ? "en" : "dis");
855 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
856 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000857 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000858 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
859 "general purpose output" : "SLP_LAN#");
860
861 /* PCHSTRP16 */
862 /* PCHSTRP17 */
863 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
864 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
865 msg_pdbg2("\n");
866}
867
868void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
869{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000870 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000871 msg_pdbg2("=== Softstraps ===\n");
872
Nico Huber157b8182024-07-19 17:48:12 +0200873 if (has_classic_proc_straps(cs)) {
874 max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
875 if (max_count < desc->content.MSL) {
876 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
877 desc->content.MSL, max_count);
878 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
879 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000880
Nico Huber157b8182024-07-19 17:48:12 +0200881 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
882 for (i = 0; i < max_count; i++)
883 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
884 msg_pdbg2("\n");
885 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000886
Nico Huber519be662018-12-23 20:03:35 +0100887 max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
Nico Huberd7c75522017-03-29 16:31:49 +0200888 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000889 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
890 desc->content.ISL, max_count);
891 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200892 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000893
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000894 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
895 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000896 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
897 msg_pdbg2("\n");
898
899 switch (cs) {
900 case CHIPSET_ICH8:
901 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
902 msg_pdbg2("Detailed North/MCH/PROC information is "
903 "probably not reliable, printing anyway.\n");
904 if (sizeof(desc->south.ich8) / 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_ich8(desc);
908 break;
909 case CHIPSET_5_SERIES_IBEX_PEAK:
910 /* PCH straps only. PROCSTRPs are unknown. */
911 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
912 msg_pdbg2("Detailed South/ICH/PCH information is "
913 "probably not reliable, printing anyway.\n");
914 prettyprint_ich_descriptor_straps_ibex(&desc->south);
915 break;
916 case CHIPSET_6_SERIES_COUGAR_POINT:
917 /* PCH straps only. PROCSTRP0 is "reserved". */
918 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
919 msg_pdbg2("Detailed South/ICH/PCH information is "
920 "probably not reliable, printing anyway.\n");
921 prettyprint_ich_descriptor_straps_cougar(&desc->south);
922 break;
923 case CHIPSET_ICH_UNKNOWN:
924 break;
925 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000926 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000927 break;
928 }
929}
930
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600931static void prettyprint_rdid(uint32_t reg_val)
Stefan Taunerb3850962011-12-24 00:00:32 +0000932{
933 uint8_t mid = reg_val & 0xFF;
934 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
935 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
936}
937
938void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
939{
940 int i;
941 msg_pdbg2("=== Upper Map Section ===\n");
942 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
943 msg_pdbg2("\n");
944
945 msg_pdbg2("--- Details ---\n");
946 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
947 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
948 msg_pdbg2("\n");
949
950 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000951 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +0000952 uint32_t jid = umap->vscc_table[i].JID;
953 uint32_t vscc = umap->vscc_table[i].VSCC;
954 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
955 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600956 msg_pdbg2(" "); /* indentation */
Stefan Taunerb3850962011-12-24 00:00:32 +0000957 prettyprint_rdid(jid);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600958 msg_pdbg2(" "); /* indentation */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000959 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +0000960 }
961 msg_pdbg2("\n");
962}
963
David Hendricks66565a72021-09-20 21:56:40 -0700964static inline void warn_peculiar_desc(const char *const name)
Nico Huber964007a2021-06-17 21:12:47 +0200965{
Nico Huber964007a2021-06-17 21:12:47 +0200966 msg_pwarn("Peculiar flash descriptor, assuming %s compatibility.\n", name);
967}
968
Nico Huber1dc3d422017-06-17 00:09:31 +0200969/*
970 * Guesses a minimum chipset version based on the maximum number of
Nico Huber3ad9aad2021-06-17 22:05:00 +0200971 * soft straps per generation and presence of the MIP base (MDTBA).
Nico Huber1dc3d422017-06-17 00:09:31 +0200972 */
Nico Huberdb878fb2024-07-19 17:37:09 +0200973static enum ich_chipset guess_ich_chipset(const struct ich_desc_content *const content,
974 const struct ich_desc_upper_map *const upper)
Nico Huber1dc3d422017-06-17 00:09:31 +0200975{
976 if (content->ICCRIBA == 0x00) {
977 if (content->MSL == 0 && content->ISL <= 2)
978 return CHIPSET_ICH8;
Nico Huber83b01c82021-06-17 21:20:09 +0200979 if (content->ISL <= 2)
Nico Huber1dc3d422017-06-17 00:09:31 +0200980 return CHIPSET_ICH9;
Nico Huber83b01c82021-06-17 21:20:09 +0200981 if (content->ISL <= 10)
Nico Huber1dc3d422017-06-17 00:09:31 +0200982 return CHIPSET_ICH10;
David Hendricks66565a72021-09-20 21:56:40 -0700983 if (content->ISL <= 16)
984 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber83b01c82021-06-17 21:20:09 +0200985 if (content->FLMAP2 == 0) {
Nico Huber81965f32021-06-17 23:25:35 +0200986 if (content->ISL == 19)
987 return CHIPSET_APOLLO_LAKE;
David Hendricks66565a72021-09-20 21:56:40 -0700988 if (content->ISL == 23)
989 return CHIPSET_GEMINI_LAKE;
990 warn_peculiar_desc("Gemini Lake");
Nico Huber81965f32021-06-17 23:25:35 +0200991 return CHIPSET_GEMINI_LAKE;
Nico Huberd2d39932019-01-18 16:49:37 +0100992 }
Jonathan Zhang3bf7cfb2021-08-30 23:25:06 -0700993 if (content->ISL <= 80)
994 return CHIPSET_C620_SERIES_LEWISBURG;
David Hendricks66565a72021-09-20 21:56:40 -0700995 warn_peculiar_desc("Ibex Peak");
Nico Huber1dc3d422017-06-17 00:09:31 +0200996 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber3ad9aad2021-06-17 22:05:00 +0200997 } else if (upper->MDTBA == 0x00) {
998 if (content->ICCRIBA < 0x31 && content->FMSBA < 0x30) {
999 if (content->MSL == 0 && content->ISL <= 17)
1000 return CHIPSET_BAYTRAIL;
1001 if (content->MSL <= 1 && content->ISL <= 18)
1002 return CHIPSET_6_SERIES_COUGAR_POINT;
David Hendricks66565a72021-09-20 21:56:40 -07001003 if (content->MSL <= 1 && content->ISL <= 21)
1004 return CHIPSET_8_SERIES_LYNX_POINT;
1005 warn_peculiar_desc("Lynx Point");
Nico Huber81965f32021-06-17 23:25:35 +02001006 return CHIPSET_8_SERIES_LYNX_POINT;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001007 }
1008 if (content->NM == 6) {
David Hendricks66565a72021-09-20 21:56:40 -07001009 if (content->ICCRIBA <= 0x34)
1010 return CHIPSET_C620_SERIES_LEWISBURG;
1011 warn_peculiar_desc("C620 series");
Nico Huber2a5dfaf2019-07-04 16:01:51 +02001012 return CHIPSET_C620_SERIES_LEWISBURG;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001013 }
David Hendricks66565a72021-09-20 21:56:40 -07001014 if (content->ICCRIBA == 0x31)
1015 return CHIPSET_100_SERIES_SUNRISE_POINT;
1016 warn_peculiar_desc("100 series");
Nico Huber83b01c82021-06-17 21:20:09 +02001017 return CHIPSET_100_SERIES_SUNRISE_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001018 } else {
David Hendricks66565a72021-09-20 21:56:40 -07001019 if (content->ICCRIBA == 0x34)
1020 return CHIPSET_300_SERIES_CANNON_POINT;
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001021 if (content->CSSL == 0x11)
1022 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber29c23dd2022-12-21 15:25:09 +00001023 if (content->CSSL == 0x14) /* backwards compatible Alder Point */
1024 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber756b6b32022-12-21 17:15:13 +00001025 if (content->CSSL == 0x03) {
1026 if (content->CSSO == 0x58)
1027 return CHIPSET_ELKHART_LAKE;
1028 else if (content->CSSO == 0x6c) /* backwards compatible Jasper Lake */
1029 return CHIPSET_300_SERIES_CANNON_POINT;
1030 }
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001031 msg_pwarn("Unknown flash descriptor, assuming 500 series compatibility.\n");
1032 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001033 }
1034}
1035
Stefan Taunerb3850962011-12-24 00:00:32 +00001036/* len is the length of dump in bytes */
Nico Huberfa622942017-03-24 17:25:37 +01001037int read_ich_descriptors_from_dump(const uint32_t *const dump, const size_t len,
1038 enum ich_chipset *const cs, struct ich_descriptors *const desc)
Stefan Taunerb3850962011-12-24 00:00:32 +00001039{
Nico Huber519be662018-12-23 20:03:35 +01001040 ssize_t i, max_count;
1041 size_t pch_bug_offset = 0;
Stefan Taunerb3850962011-12-24 00:00:32 +00001042
1043 if (dump == NULL || desc == NULL)
1044 return ICH_RET_PARAM;
1045
1046 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
1047 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
1048 pch_bug_offset = 4;
1049 else
1050 return ICH_RET_ERR;
1051 }
1052
1053 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +02001054 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001055 return ICH_RET_OOB;
1056 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
1057 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
1058 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
1059 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
1060
1061 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +02001062 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001063 return ICH_RET_OOB;
1064 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
1065 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
1066 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
1067
Nico Huber8a03c902021-06-17 21:23:29 +02001068 /* upper map */
1069 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
1070
1071 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
1072 * "Identifies the 1s based number of DWORDS contained in the VSCC
1073 * Table. Each SPI component entry in the table is 2 DWORDS long." So
1074 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
1075 * check ensures that the maximum offset actually accessed is available.
1076 */
1077 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
1078 return ICH_RET_OOB;
1079
1080 for (i = 0; i < desc->upper.VTL/2; i++) {
1081 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
1082 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
1083 }
1084
Nico Huber67d71792017-06-17 03:10:15 +02001085 if (*cs == CHIPSET_ICH_UNKNOWN) {
Nico Huberdb878fb2024-07-19 17:37:09 +02001086 *cs = guess_ich_chipset(&desc->content, &desc->upper);
Nico Huber67d71792017-06-17 03:10:15 +02001087 prettyprint_ich_chipset(*cs);
1088 }
Nico Huberfa622942017-03-24 17:25:37 +01001089
Stefan Taunerb3850962011-12-24 00:00:32 +00001090 /* region */
Nico Huberfa622942017-03-24 17:25:37 +01001091 const ssize_t nr = ich_number_of_regions(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001092 if (nr < 0 || len < getFRBA(&desc->content) + (size_t)nr * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001093 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001094 for (i = 0; i < nr; i++)
1095 desc->region.FLREGs[i] = dump[(getFRBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001096
1097 /* master */
Nico Huberfa622942017-03-24 17:25:37 +01001098 const ssize_t nm = ich_number_of_masters(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001099 if (nm < 0 || len < getFMBA(&desc->content) + (size_t)nm * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001100 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001101 for (i = 0; i < nm; i++)
1102 desc->master.FLMSTRs[i] = dump[(getFMBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001103
Nico Huber157b8182024-07-19 17:48:12 +02001104 if (has_classic_proc_straps(*cs)) {
1105 /* MCH/PROC (aka. North) straps */
1106 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
1107 return ICH_RET_OOB;
Stefan Taunerb3850962011-12-24 00:00:32 +00001108
Nico Huber157b8182024-07-19 17:48:12 +02001109 /* limit the range to be written */
1110 max_count = MIN(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
1111 for (i = 0; i < max_count; i++)
1112 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
1113 }
Stefan Taunerb3850962011-12-24 00:00:32 +00001114
1115 /* ICH/PCH (aka. South) straps */
1116 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
1117 return ICH_RET_OOB;
1118
1119 /* limit the range to be written */
Nico Huber519be662018-12-23 20:03:35 +01001120 max_count = MIN(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001121 for (i = 0; i < max_count; i++)
1122 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001123
1124 return ICH_RET_OK;
1125}
1126
Nico Huberad186312016-05-02 15:15:29 +02001127#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +00001128
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001129/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001130\em idx in bytes or -1 if the correct size can not be determined. */
1131int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001132{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001133 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001134 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001135 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001136 }
Nico Huberdfd06472024-07-14 23:45:05 +02001137 if (cs == CHIPSET_ICH_UNKNOWN) {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001138 msg_pwarn("Density encoding is unknown on this chipset.\n");
1139 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001140 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001141
Nico Huberdfd06472024-07-14 23:45:05 +02001142 if (desc->content.NC == 0 && idx > 0)
1143 return 0;
1144
1145 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
1146 const unsigned int size_idx = get_density_index(cs, desc, idx);
1147
1148 if (size_idx > max_idx) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +00001149 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001150 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
Nico Huberdfd06472024-07-14 23:45:05 +02001151 idx, size_idx, max_idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001152 return -1;
1153 }
1154
Nico Huberdfd06472024-07-14 23:45:05 +02001155 return 1 << (19 + size_idx);
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001156}
1157
Nico Huber8d494992017-06-19 12:18:33 +02001158/* Only used by ichspi.c */
1159#if CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__))
Nico Huberd54e4f42017-03-23 23:45:47 +01001160static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
Stefan Tauner1e146392011-09-15 23:52:55 +00001161{
1162 uint32_t control = 0;
1163 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
1164 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001165
1166 if (cs >= SPI_ENGINE_PCH100) {
Nico Huberd54e4f42017-03-23 23:45:47 +01001167 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
1168 return mmio_le_readl(spibar + PCH100_REG_FDOD);
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001169 } else {
Nico Huberd54e4f42017-03-23 23:45:47 +01001170 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
1171 return mmio_le_readl(spibar + ICH9_REG_FDOD);
1172 }
Stefan Tauner1e146392011-09-15 23:52:55 +00001173}
1174
Nico Huberd54e4f42017-03-23 23:45:47 +01001175int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
Stefan Tauner1e146392011-09-15 23:52:55 +00001176{
Nico Huber519be662018-12-23 20:03:35 +01001177 ssize_t i;
Stefan Tauner1e146392011-09-15 23:52:55 +00001178 struct ich_desc_region *r = &desc->region;
1179
1180 /* Test if bit-fields are working as expected.
1181 * FIXME: Replace this with dynamic bitfield fixup
1182 */
1183 for (i = 0; i < 4; i++)
1184 desc->region.FLREGs[i] = 0x5A << (i * 8);
Nico Huberfa622942017-03-24 17:25:37 +01001185 if (r->old_reg[0].base != 0x005A || r->old_reg[0].limit != 0x0000 ||
1186 r->old_reg[1].base != 0x1A00 || r->old_reg[1].limit != 0x0000 ||
1187 r->old_reg[2].base != 0x0000 || r->old_reg[2].limit != 0x005A ||
1188 r->old_reg[3].base != 0x0000 || r->old_reg[3].limit != 0x1A00) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001189 msg_pdbg("The combination of compiler and CPU architecture used"
1190 "does not lay out bit-fields as expected, sorry.\n");
Nico Huberfa622942017-03-24 17:25:37 +01001191 msg_pspew("r->old_reg[0].base = 0x%04X (0x005A)\n", r->old_reg[0].base);
1192 msg_pspew("r->old_reg[0].limit = 0x%04X (0x0000)\n", r->old_reg[0].limit);
1193 msg_pspew("r->old_reg[1].base = 0x%04X (0x1A00)\n", r->old_reg[1].base);
1194 msg_pspew("r->old_reg[1].limit = 0x%04X (0x0000)\n", r->old_reg[1].limit);
1195 msg_pspew("r->old_reg[2].base = 0x%04X (0x0000)\n", r->old_reg[2].base);
1196 msg_pspew("r->old_reg[2].limit = 0x%04X (0x005A)\n", r->old_reg[2].limit);
1197 msg_pspew("r->old_reg[3].base = 0x%04X (0x0000)\n", r->old_reg[3].base);
1198 msg_pspew("r->old_reg[3].limit = 0x%04X (0x1A00)\n", r->old_reg[3].limit);
Stefan Tauner1e146392011-09-15 23:52:55 +00001199 return ICH_RET_ERR;
1200 }
1201
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001202 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +00001203 /* content section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001204 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
1205 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
1206 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
1207 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001208
1209 /* component section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001210 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
1211 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
1212 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001213
1214 /* region section */
Nico Huberfa622942017-03-24 17:25:37 +01001215 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
1216 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001217 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
Nico Huberfa622942017-03-24 17:25:37 +01001218 __func__, desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +00001219 return ICH_RET_ERR;
1220 }
Nico Huberfa622942017-03-24 17:25:37 +01001221 for (i = 0; i < nr; i++)
Nico Huberd54e4f42017-03-23 23:45:47 +01001222 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001223
1224 /* master section */
Nico Huberfa622942017-03-24 17:25:37 +01001225 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
1226 if (nm < 0) {
1227 msg_pdbg2("%s: number of masters too high (%d) - failed\n",
1228 __func__, desc->content.NM + 1);
1229 return ICH_RET_ERR;
1230 }
1231 for (i = 0; i < nm; i++)
1232 desc->master.FLMSTRs[i] = read_descriptor_reg(cs, 3, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001233
1234 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
1235 * reading the upper map is impossible on all chipsets, so don't bother.
1236 */
1237
1238 msg_pdbg2(" done.\n");
1239 return ICH_RET_OK;
1240}
Nico Huber8d494992017-06-19 12:18:33 +02001241#endif
Nico Huber305f4172013-06-14 11:55:26 +02001242
1243/**
1244 * @brief Read a layout from the dump of an Intel ICH descriptor.
1245 *
1246 * @param layout Pointer where to store the layout.
1247 * @param dump The descriptor dump to read from.
1248 * @param len The length of the descriptor dump.
1249 *
1250 * @return 0 on success,
Nico Huber70461a92019-06-15 14:56:19 +02001251 * 1 if the descriptor couldn't be parsed,
1252 * 2 when out of memory.
Nico Huber305f4172013-06-14 11:55:26 +02001253 */
Nico Huber5bd990c2019-06-16 19:46:46 +02001254int layout_from_ich_descriptors(
Nico Huberc3b02dc2023-08-12 01:13:45 +02001255 struct flashprog_layout **const layout,
Nico Huber5bd990c2019-06-16 19:46:46 +02001256 const void *const dump, const size_t len)
Nico Huber305f4172013-06-14 11:55:26 +02001257{
Nico Huberfa622942017-03-24 17:25:37 +01001258 static const char *const regions[] = {
David Hendricksa5216362017-08-08 20:02:22 -07001259 "fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
1260 "10gbe", "reg12", "reg13", "reg14", "reg15"
Nico Huberfa622942017-03-24 17:25:37 +01001261 };
Nico Huber305f4172013-06-14 11:55:26 +02001262
1263 struct ich_descriptors desc;
Nico Huberfa622942017-03-24 17:25:37 +01001264 enum ich_chipset cs = CHIPSET_ICH_UNKNOWN;
1265 if (read_ich_descriptors_from_dump(dump, len, &cs, &desc))
Nico Huber305f4172013-06-14 11:55:26 +02001266 return 1;
1267
Nico Huberc3b02dc2023-08-12 01:13:45 +02001268 if (flashprog_layout_new(layout))
Nico Huber5bd990c2019-06-16 19:46:46 +02001269 return 2;
Nico Huber305f4172013-06-14 11:55:26 +02001270
Nico Huber92e0b622019-06-15 15:55:11 +02001271 ssize_t i;
Nico Huber519be662018-12-23 20:03:35 +01001272 const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
Nico Huber92e0b622019-06-15 15:55:11 +02001273 for (i = 0; i < nr; ++i) {
Nico Huber305f4172013-06-14 11:55:26 +02001274 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
Nico Huber0bb3f712017-03-29 16:44:33 +02001275 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
Nico Huber305f4172013-06-14 11:55:26 +02001276 if (limit <= base)
1277 continue;
Nico Huberc3b02dc2023-08-12 01:13:45 +02001278 if (flashprog_layout_add_region(*layout, base, limit, regions[i])) {
1279 flashprog_layout_release(*layout);
Nico Huber5bd990c2019-06-16 19:46:46 +02001280 *layout = NULL;
Nico Huber70461a92019-06-15 14:56:19 +02001281 return 2;
Nico Huber5bd990c2019-06-16 19:46:46 +02001282 }
Nico Huber305f4172013-06-14 11:55:26 +02001283 }
Nico Huber305f4172013-06-14 11:55:26 +02001284 return 0;
1285}
1286
Nico Huberad186312016-05-02 15:15:29 +02001287#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */