blob: dfc1cb8644fa7692d134ee170d18f150019de463 [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 Huber82fe1232024-07-19 17:28:47 +020074 return 6;
Nico Huberd2d39932019-01-18 16:49:37 +010075 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +020076 case CHIPSET_GEMINI_LAKE:
Werner Zehe57d4e42022-01-03 09:44:29 +010077 case CHIPSET_ELKHART_LAKE:
Nico Huber82fe1232024-07-19 17:28:47 +020078 return 2;
David Hendricksa5216362017-08-08 20:02:22 -070079 default:
Nico Huber82fe1232024-07-19 17:28:47 +020080 if (cs >= SPI_ENGINE_PCH100)
81 return 5;
David Hendricksa5216362017-08-08 20:02:22 -070082 if (cont->NM < MAX_NUM_MASTERS)
83 return cont->NM + 1;
84 }
85
86 return -1;
Nico Huberfa622942017-03-24 17:25:37 +010087}
88
Nico Huber157b8182024-07-19 17:48:12 +020089static bool has_classic_proc_straps(const enum ich_chipset cs)
90{
91 switch (cs) {
92 case CHIPSET_100_SERIES_SUNRISE_POINT:
93 case CHIPSET_C620_SERIES_LEWISBURG:
94 return true;
95 default:
96 return cs < SPI_ENGINE_PCH100;
97 }
98}
99
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000100void prettyprint_ich_reg_vscc(uint32_t reg_val, int verbosity, bool print_vcl)
Stefan Tauner1e146392011-09-15 23:52:55 +0000101{
102 print(verbosity, "BES=0x%x, ", (reg_val & VSCC_BES) >> VSCC_BES_OFF);
103 print(verbosity, "WG=%d, ", (reg_val & VSCC_WG) >> VSCC_WG_OFF);
104 print(verbosity, "WSR=%d, ", (reg_val & VSCC_WSR) >> VSCC_WSR_OFF);
105 print(verbosity, "WEWS=%d, ", (reg_val & VSCC_WEWS) >> VSCC_WEWS_OFF);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000106 print(verbosity, "EO=0x%x", (reg_val & VSCC_EO) >> VSCC_EO_OFF);
107 if (print_vcl)
108 print(verbosity, ", VCL=%d", (reg_val & VSCC_VCL) >> VSCC_VCL_OFF);
109 print(verbosity, "\n");
Stefan Tauner1e146392011-09-15 23:52:55 +0000110}
111
112#define getFCBA(cont) (((cont)->FLMAP0 << 4) & 0x00000ff0)
113#define getFRBA(cont) (((cont)->FLMAP0 >> 12) & 0x00000ff0)
114#define getFMBA(cont) (((cont)->FLMAP1 << 4) & 0x00000ff0)
115#define getFISBA(cont) (((cont)->FLMAP1 >> 12) & 0x00000ff0)
116#define getFMSBA(cont) (((cont)->FLMAP2 << 4) & 0x00000ff0)
117
Nico Huber67d71792017-06-17 03:10:15 +0200118void prettyprint_ich_chipset(enum ich_chipset cs)
119{
120 static const char *const chipset_names[] = {
121 "Unknown ICH", "ICH8", "ICH9", "ICH10",
122 "5 series Ibex Peak", "6 series Cougar Point", "7 series Panther Point",
Nico Huberdfd06472024-07-14 23:45:05 +0200123 "Baytrail", "8 series Lynx Point", "8 series Lynx Point LP", "8 series Wellsburg",
Nico Huber67d71792017-06-17 03:10:15 +0200124 "9 series Wildcat Point", "9 series Wildcat Point LP", "100 series Sunrise Point",
Angel Pons4db0fdf2020-07-10 17:04:10 +0200125 "C620 series Lewisburg", "300/400 series Cannon/Comet Point",
Nico Huber29c23dd2022-12-21 15:25:09 +0000126 "500/600 series Tiger/Alder Point", "Apollo Lake", "Gemini Lake", "Elkhart Lake",
Nico Huber67d71792017-06-17 03:10:15 +0200127 };
128 if (cs < CHIPSET_ICH8 || cs - CHIPSET_ICH8 + 1 >= ARRAY_SIZE(chipset_names))
129 cs = 0;
130 else
131 cs = cs - CHIPSET_ICH8 + 1;
132 msg_pdbg2("Assuming chipset '%s'.\n", chipset_names[cs]);
133}
134
Stefan Tauner1e146392011-09-15 23:52:55 +0000135void prettyprint_ich_descriptors(enum ich_chipset cs, const struct ich_descriptors *desc)
136{
Nico Huberfa622942017-03-24 17:25:37 +0100137 prettyprint_ich_descriptor_content(cs, &desc->content);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000138 prettyprint_ich_descriptor_component(cs, desc);
Nico Huberfa622942017-03-24 17:25:37 +0100139 prettyprint_ich_descriptor_region(cs, desc);
140 prettyprint_ich_descriptor_master(cs, desc);
Nico Huberad186312016-05-02 15:15:29 +0200141#ifdef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +0000142 if (cs >= CHIPSET_ICH8) {
143 prettyprint_ich_descriptor_upper_map(&desc->upper);
144 prettyprint_ich_descriptor_straps(cs, desc);
145 }
Nico Huberad186312016-05-02 15:15:29 +0200146#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */
Stefan Tauner1e146392011-09-15 23:52:55 +0000147}
148
Nico Huberfa622942017-03-24 17:25:37 +0100149void prettyprint_ich_descriptor_content(enum ich_chipset cs, const struct ich_desc_content *cont)
Stefan Tauner1e146392011-09-15 23:52:55 +0000150{
151 msg_pdbg2("=== Content Section ===\n");
152 msg_pdbg2("FLVALSIG 0x%08x\n", cont->FLVALSIG);
153 msg_pdbg2("FLMAP0 0x%08x\n", cont->FLMAP0);
154 msg_pdbg2("FLMAP1 0x%08x\n", cont->FLMAP1);
155 msg_pdbg2("FLMAP2 0x%08x\n", cont->FLMAP2);
156 msg_pdbg2("\n");
157
158 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100159 msg_pdbg2("NR (Number of Regions): %5zd\n", ich_number_of_regions(cs, cont));
160 msg_pdbg2("FRBA (Flash Region Base Address): 0x%03x\n", getFRBA(cont));
161 msg_pdbg2("NC (Number of Components): %5d\n", cont->NC + 1);
162 msg_pdbg2("FCBA (Flash Component Base Address): 0x%03x\n", getFCBA(cont));
Nico Huberd2d39932019-01-18 16:49:37 +0100163 msg_pdbg2("ISL (ICH/PCH/SoC Strap Length): %5d\n", cont->ISL);
164 msg_pdbg2("FISBA/FPSBA (Flash ICH/PCH/SoC Strap Base Addr): 0x%03x\n", getFISBA(cont));
Nico Huberfa622942017-03-24 17:25:37 +0100165 msg_pdbg2("NM (Number of Masters): %5zd\n", ich_number_of_masters(cs, cont));
166 msg_pdbg2("FMBA (Flash Master Base Address): 0x%03x\n", getFMBA(cont));
Nico Huber157b8182024-07-19 17:48:12 +0200167 if (has_classic_proc_straps(cs)) {
168 msg_pdbg2("MSL/PSL (MCH/PROC Strap Length): %5d\n", cont->MSL);
169 msg_pdbg2("FMSBA (Flash MCH/PROC Strap Base Address): 0x%03x\n", getFMSBA(cont));
170 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000171 msg_pdbg2("\n");
172}
173
Nico Huberdfd06472024-07-14 23:45:05 +0200174static unsigned int get_density_index(
175 enum ich_chipset cs, const struct ich_descriptors *desc, unsigned int component)
176{
177 if (cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY) {
178 if (component == 0)
179 return desc->component.dens_old.comp1_density;
180 else
181 return desc->component.dens_old.comp2_density;
182 } else {
183 if (component == 0)
184 return desc->component.dens_new.comp1_density;
185 else
186 return desc->component.dens_new.comp2_density;
187 }
188}
189
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000190static const char *pprint_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
191{
192 if (idx > 1) {
193 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Nico Huberdfd06472024-07-14 23:45:05 +0200194 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000195 }
Nico Huberdfd06472024-07-14 23:45:05 +0200196 if (cs == CHIPSET_ICH_UNKNOWN)
197 return "unknown";
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000198
199 if (desc->content.NC == 0 && idx > 0)
200 return "unused";
201
202 static const char * const size_str[] = {
203 "512 kB", /* 0000 */
204 "1 MB", /* 0001 */
205 "2 MB", /* 0010 */
206 "4 MB", /* 0011 */
207 "8 MB", /* 0100 */
208 "16 MB", /* 0101 */ /* Maximum up to Lynx Point (excl.) */
209 "32 MB", /* 0110 */
210 "64 MB", /* 0111 */
211 };
Nico Huberdfd06472024-07-14 23:45:05 +0200212 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
213 const unsigned int size_idx = get_density_index(cs, desc, idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000214
Nico Huberdfd06472024-07-14 23:45:05 +0200215 if (size_idx > max_idx)
216 return "reserved";
217
218 return size_str[size_idx];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000219}
220
221static const char *pprint_freq(enum ich_chipset cs, uint8_t value)
Stefan Tauner1e146392011-09-15 23:52:55 +0000222{
Werner Zehe57d4e42022-01-03 09:44:29 +0100223 static const char *const freq_str[5][8] = { {
Nico Huber129e9382019-06-06 15:43:27 +0200224 "20 MHz",
225 "33 MHz",
226 "reserved",
227 "reserved",
228 "50 MHz", /* New since Ibex Peak */
229 "reserved",
230 "reserved",
231 "reserved"
Nico Huberfa622942017-03-24 17:25:37 +0100232 }, {
Nico Huber129e9382019-06-06 15:43:27 +0200233 "reserved",
234 "reserved",
235 "48 MHz",
236 "reserved",
237 "30 MHz",
238 "reserved",
239 "17 MHz",
240 "reserved"
Nico Huberd2d39932019-01-18 16:49:37 +0100241 }, {
242 "reserved",
243 "50 MHz",
244 "40 MHz",
245 "reserved",
246 "25 MHz",
247 "reserved",
248 "14 MHz / 17 MHz",
249 "reserved"
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200250 }, {
251 "100 MHz",
252 "50 MHz",
253 "reserved",
254 "33 MHz",
255 "25 MHz",
256 "reserved",
257 "14 MHz",
258 "reserved"
Werner Zehe57d4e42022-01-03 09:44:29 +0100259 }, {
260 "reserved",
261 "50 MHz",
262 "reserved",
263 "reserved",
264 "33 MHz",
265 "20 MHz",
266 "reserved",
267 "reserved",
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200268 }};
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000269
270 switch (cs) {
271 case CHIPSET_ICH8:
272 case CHIPSET_ICH9:
273 case CHIPSET_ICH10:
274 if (value > 1)
275 return "reserved";
Richard Hughesdb7482b2018-12-19 12:04:30 +0000276 /* Fall through. */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000277 case CHIPSET_5_SERIES_IBEX_PEAK:
278 case CHIPSET_6_SERIES_COUGAR_POINT:
279 case CHIPSET_7_SERIES_PANTHER_POINT:
280 case CHIPSET_8_SERIES_LYNX_POINT:
Duncan Laurie4095ed72014-08-20 15:39:32 +0000281 case CHIPSET_BAYTRAIL:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000282 case CHIPSET_8_SERIES_LYNX_POINT_LP:
283 case CHIPSET_8_SERIES_WELLSBURG:
Duncan Laurie823096e2014-08-20 15:39:38 +0000284 case CHIPSET_9_SERIES_WILDCAT_POINT:
Nico Huber51205912017-03-17 17:59:54 +0100285 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
Nico Huberfa622942017-03-24 17:25:37 +0100286 return freq_str[0][value];
287 case CHIPSET_100_SERIES_SUNRISE_POINT:
David Hendricksa5216362017-08-08 20:02:22 -0700288 case CHIPSET_C620_SERIES_LEWISBURG:
Nico Huber2a5dfaf2019-07-04 16:01:51 +0200289 case CHIPSET_300_SERIES_CANNON_POINT:
Nico Huberfa622942017-03-24 17:25:37 +0100290 return freq_str[1][value];
Nico Huberd2d39932019-01-18 16:49:37 +0100291 case CHIPSET_APOLLO_LAKE:
Angel Pons4db0fdf2020-07-10 17:04:10 +0200292 case CHIPSET_GEMINI_LAKE:
Nico Huberd2d39932019-01-18 16:49:37 +0100293 return freq_str[2][value];
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200294 case CHIPSET_500_SERIES_TIGER_POINT:
295 return freq_str[3][value];
Werner Zehe57d4e42022-01-03 09:44:29 +0100296 case CHIPSET_ELKHART_LAKE:
297 return freq_str[4][value];
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000298 case CHIPSET_ICH_UNKNOWN:
299 default:
300 return "unknown";
301 }
302}
303
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200304static void pprint_read_freq(enum ich_chipset cs, uint8_t value)
305{
306 static const char *const freq_str[1][8] = { {
307 "20 MHz",
308 "24 MHz",
309 "30 MHz",
310 "48 MHz",
311 "60 MHz",
312 "reserved",
313 "reserved",
314 "reserved"
315 }};
316
317 switch (cs) {
318 case CHIPSET_300_SERIES_CANNON_POINT:
319 msg_pdbg2("eSPI/EC Bus Clock Frequency: %s\n", freq_str[0][value]);
320 return;
321 case CHIPSET_500_SERIES_TIGER_POINT:
322 msg_pdbg2("Read Clock Frequency: %s\n", "reserved");
323 return;
324 default:
325 msg_pdbg2("Read Clock Frequency: %s\n", pprint_freq(cs, value));
326 return;
327 }
328}
329
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000330void prettyprint_ich_descriptor_component(enum ich_chipset cs, const struct ich_descriptors *desc)
331{
Nico Huberb2ad9fd2024-07-14 23:18:53 +0200332 const bool has_flill1 = cs >= SPI_ENGINE_PCH100;
Stefan Tauner1e146392011-09-15 23:52:55 +0000333
334 msg_pdbg2("=== Component Section ===\n");
335 msg_pdbg2("FLCOMP 0x%08x\n", desc->component.FLCOMP);
336 msg_pdbg2("FLILL 0x%08x\n", desc->component.FLILL );
Nico Huberd2d39932019-01-18 16:49:37 +0100337 if (has_flill1)
Nico Huberfa622942017-03-24 17:25:37 +0100338 msg_pdbg2("FLILL1 0x%08x\n", desc->component.FLILL1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000339 msg_pdbg2("\n");
340
341 msg_pdbg2("--- Details ---\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000342 msg_pdbg2("Component 1 density: %s\n", pprint_density(cs, desc, 0));
Stefan Tauner1e146392011-09-15 23:52:55 +0000343 if (desc->content.NC)
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000344 msg_pdbg2("Component 2 density: %s\n", pprint_density(cs, desc, 1));
Stefan Tauner1e146392011-09-15 23:52:55 +0000345 else
346 msg_pdbg2("Component 2 is not used.\n");
Michał Żygowski5c9f5422021-06-16 15:13:54 +0200347
348 pprint_read_freq(cs, desc->component.modes.freq_read);
349
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000350 msg_pdbg2("Read ID and Status Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_read_id));
351 msg_pdbg2("Write and Erase Clock Freq.: %s\n", pprint_freq(cs, desc->component.modes.freq_write));
352 msg_pdbg2("Fast Read is %ssupported.\n", desc->component.modes.fastread ? "" : "not ");
353 if (desc->component.modes.fastread)
Stefan Tauner1e146392011-09-15 23:52:55 +0000354 msg_pdbg2("Fast Read Clock Frequency: %s\n",
Tai-Hong Wu60dead42015-01-05 23:00:14 +0000355 pprint_freq(cs, desc->component.modes.freq_fastread));
Nico Huber3f75d442024-07-14 19:17:56 +0200356 switch (cs) {
357 case CHIPSET_7_SERIES_PANTHER_POINT:
358 case CHIPSET_8_SERIES_LYNX_POINT:
359 case CHIPSET_BAYTRAIL:
360 case CHIPSET_8_SERIES_LYNX_POINT_LP:
361 case CHIPSET_8_SERIES_WELLSBURG:
362 case CHIPSET_9_SERIES_WILDCAT_POINT:
363 case CHIPSET_9_SERIES_WILDCAT_POINT_LP:
364 case CHIPSET_100_SERIES_SUNRISE_POINT:
365 case CHIPSET_APOLLO_LAKE:
366 case CHIPSET_C620_SERIES_LEWISBURG:
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000367 msg_pdbg2("Dual Output Fast Read Support: %sabled\n",
Werner Zehd3e8fd92022-01-25 07:02:49 +0100368 desc->component.modes.dual_output ? "en" : "dis");
Nico Huber3f75d442024-07-14 19:17:56 +0200369 break;
370 default:
371 break;
372 }
David Hendricksa5216362017-08-08 20:02:22 -0700373
Felix Singerd68a0ec2022-08-19 03:23:35 +0200374 bool has_forbidden_opcode = false;
David Hendricksa5216362017-08-08 20:02:22 -0700375 if (desc->component.FLILL != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200376 has_forbidden_opcode = true;
Stefan Tauner1e146392011-09-15 23:52:55 +0000377 msg_pdbg2("Invalid instruction 0: 0x%02x\n",
378 desc->component.invalid_instr0);
379 msg_pdbg2("Invalid instruction 1: 0x%02x\n",
380 desc->component.invalid_instr1);
381 msg_pdbg2("Invalid instruction 2: 0x%02x\n",
382 desc->component.invalid_instr2);
383 msg_pdbg2("Invalid instruction 3: 0x%02x\n",
384 desc->component.invalid_instr3);
David Hendricksa5216362017-08-08 20:02:22 -0700385 }
Nico Huberd2d39932019-01-18 16:49:37 +0100386 if (has_flill1) {
David Hendricksa5216362017-08-08 20:02:22 -0700387 if (desc->component.FLILL1 != 0) {
Felix Singerd68a0ec2022-08-19 03:23:35 +0200388 has_forbidden_opcode = true;
Nico Huberfa622942017-03-24 17:25:37 +0100389 msg_pdbg2("Invalid instruction 4: 0x%02x\n",
390 desc->component.invalid_instr4);
391 msg_pdbg2("Invalid instruction 5: 0x%02x\n",
392 desc->component.invalid_instr5);
393 msg_pdbg2("Invalid instruction 6: 0x%02x\n",
394 desc->component.invalid_instr6);
395 msg_pdbg2("Invalid instruction 7: 0x%02x\n",
396 desc->component.invalid_instr7);
397 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000398 }
David Hendricksa5216362017-08-08 20:02:22 -0700399 if (!has_forbidden_opcode)
400 msg_pdbg2("No forbidden opcodes.\n");
401
Stefan Tauner1e146392011-09-15 23:52:55 +0000402 msg_pdbg2("\n");
403}
404
405static void pprint_freg(const struct ich_desc_region *reg, uint32_t i)
406{
Nico Huberfa622942017-03-24 17:25:37 +0100407 static const char *const region_names[] = {
Nico Huberd2d39932019-01-18 16:49:37 +0100408 "Descr.", "BIOS", "ME", "GbE", "Platf.", "DevExp", "BIOS2", "unknown",
David Hendricksa5216362017-08-08 20:02:22 -0700409 "EC/BMC", "unknown", "IE", "10GbE", "unknown", "unknown", "unknown", "unknown"
Stefan Tauner1e146392011-09-15 23:52:55 +0000410 };
Nico Huberfa622942017-03-24 17:25:37 +0100411 if (i >= ARRAY_SIZE(region_names)) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000412 msg_pdbg2("%s: region index too high.\n", __func__);
413 return;
414 }
415 uint32_t base = ICH_FREG_BASE(reg->FLREGs[i]);
416 uint32_t limit = ICH_FREG_LIMIT(reg->FLREGs[i]);
Nico Huberfa622942017-03-24 17:25:37 +0100417 msg_pdbg2("Region %d (%-7s) ", i, region_names[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000418 if (base > limit)
419 msg_pdbg2("is unused.\n");
420 else
Nico Huber0bb3f712017-03-29 16:44:33 +0200421 msg_pdbg2("0x%08x - 0x%08x\n", base, limit);
Stefan Tauner1e146392011-09-15 23:52:55 +0000422}
423
Nico Huberfa622942017-03-24 17:25:37 +0100424void prettyprint_ich_descriptor_region(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000425{
Nico Huber519be662018-12-23 20:03:35 +0100426 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100427 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000428 msg_pdbg2("=== Region Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100429 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +0000430 msg_pdbg2("%s: number of regions too high (%d).\n", __func__,
Nico Huberfa622942017-03-24 17:25:37 +0100431 desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +0000432 return;
433 }
Nico Huberfa622942017-03-24 17:25:37 +0100434 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100435 msg_pdbg2("FLREG%zd 0x%08x\n", i, desc->region.FLREGs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000436 msg_pdbg2("\n");
437
438 msg_pdbg2("--- Details ---\n");
Nico Huberfa622942017-03-24 17:25:37 +0100439 for (i = 0; i < nr; i++)
Nico Huber519be662018-12-23 20:03:35 +0100440 pprint_freg(&desc->region, (uint32_t)i);
Stefan Tauner1e146392011-09-15 23:52:55 +0000441 msg_pdbg2("\n");
442}
443
Nico Huberb3cc2c62024-07-15 00:45:17 +0200444static char prettify_flag(const unsigned int mask, const unsigned int bit, const char flag)
445{
446 return mask & (1 << bit) ? flag : ' ';
447}
448
449/* Takes NULL-terminated lists of names, assumes max. 5 chars per name. */
450static void prettyprint_pch100_masters(
451 const struct ich_descriptors *const desc,
452 const unsigned int number_masters, const char *const masters[],
453 const unsigned int number_regions, const char *const regions[])
454{
455 unsigned int m, r;
456
457 msg_pdbg2(" ");
458 for (r = 0; r < number_regions && regions[r] != NULL; ++r)
459 msg_pdbg2(" %-5s", regions[r]);
460 msg_pdbg2("\n");
461
462 for (m = 0; m < number_masters; ++m) {
463 const unsigned int ext_start = 12;
464
465 if (masters[m] == NULL)
466 break;
467
468 const struct ich_desc_master_region_access master = desc->master.mstr[m];
469
470 msg_pdbg2("%-5s", masters[m]);
471 for (r = 0; r < ext_start && r < number_regions && regions[r] != NULL; ++r)
472 msg_pdbg2(" %c%c ",
473 prettify_flag(master.read, r, 'r'),
474 prettify_flag(master.write, r, 'w'));
475 for (; r < number_regions && regions[r] != NULL; ++r)
476 msg_pdbg2(" %c%c ",
477 prettify_flag(master.ext_read, r - ext_start, 'r'),
478 prettify_flag(master.ext_write, r - ext_start, 'w'));
479 msg_pdbg2("\n");
480 }
481}
482
Nico Huberfa622942017-03-24 17:25:37 +0100483void prettyprint_ich_descriptor_master(const enum ich_chipset cs, const struct ich_descriptors *const desc)
Stefan Tauner1e146392011-09-15 23:52:55 +0000484{
Nico Huber519be662018-12-23 20:03:35 +0100485 ssize_t i;
Nico Huberfa622942017-03-24 17:25:37 +0100486 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
Stefan Tauner1e146392011-09-15 23:52:55 +0000487 msg_pdbg2("=== Master Section ===\n");
Nico Huberfa622942017-03-24 17:25:37 +0100488 if (nm < 0) {
489 msg_pdbg2("%s: number of masters too high (%d).\n", __func__,
490 desc->content.NM + 1);
491 return;
492 }
493 for (i = 0; i < nm; i++)
Nico Huber519be662018-12-23 20:03:35 +0100494 msg_pdbg2("FLMSTR%zd 0x%08x\n", i + 1, desc->master.FLMSTRs[i]);
Stefan Tauner1e146392011-09-15 23:52:55 +0000495 msg_pdbg2("\n");
496
497 msg_pdbg2("--- Details ---\n");
Nico Huberb3cc2c62024-07-15 00:45:17 +0200498 if (cs >= SPI_ENGINE_PCH100) {
499 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
500 if (nr < 0)
Nico Huberfa622942017-03-24 17:25:37 +0100501 return;
Nico Huberfa622942017-03-24 17:25:37 +0100502
Nico Huberb3cc2c62024-07-15 00:45:17 +0200503 if (cs == CHIPSET_APOLLO_LAKE ||
504 cs == CHIPSET_GEMINI_LAKE ||
505 cs == CHIPSET_ELKHART_LAKE) {
506 const char *const masters[] = {
507 "BIOS", "TXE", NULL
508 };
509 const char *const regions[] = {
510 " FD", "IFWI", " TXE", " n/a", "Pltf.", "DevExp", NULL
511 };
512 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
513 } else if (cs == CHIPSET_C620_SERIES_LEWISBURG) {
514 const char *const masters[] = {
515 "BIOS", "ME", "GbE", "DE", "BMC", "IE", NULL
516 };
517 const char *const regions[] = {
518 " FD ", " BIOS", " ME ", " GbE ", "Pltf.",
David Hendricksa5216362017-08-08 20:02:22 -0700519 " DE ", "BIOS2", " Reg7", " BMC ", " DE2 ",
520 " IE ", "10GbE", "OpROM", "Reg13", "Reg14",
Nico Huberb3cc2c62024-07-15 00:45:17 +0200521 "Reg15", NULL
522 };
523 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
524 } else {
525 const char *const masters[] = {
526 "BIOS", "ME", "GbE", "unkn.", "EC", NULL
527 };
528 const char *const regions[] = {
529 " FD ", "BIOS ", " ME ", " GbE ", "Pltf.",
530 "Reg5 ", "Reg6 ", "Reg7 ", " EC ", "Reg9 ",
531 "Reg10", "Reg11", "Reg12", "Reg13", "Reg14",
532 "Reg15", NULL
533 };
534 prettyprint_pch100_masters(desc, nm, masters, nr, regions);
Nico Huberd2d39932019-01-18 16:49:37 +0100535 }
Nico Huberfa622942017-03-24 17:25:37 +0100536 } else {
537 const struct ich_desc_master *const mstr = &desc->master;
538 msg_pdbg2(" Descr. BIOS ME GbE Platf.\n");
539 msg_pdbg2("BIOS %c%c %c%c %c%c %c%c %c%c\n",
540 (mstr->BIOS_descr_r) ?'r':' ', (mstr->BIOS_descr_w) ?'w':' ',
541 (mstr->BIOS_BIOS_r) ?'r':' ', (mstr->BIOS_BIOS_w) ?'w':' ',
542 (mstr->BIOS_ME_r) ?'r':' ', (mstr->BIOS_ME_w) ?'w':' ',
543 (mstr->BIOS_GbE_r) ?'r':' ', (mstr->BIOS_GbE_w) ?'w':' ',
544 (mstr->BIOS_plat_r) ?'r':' ', (mstr->BIOS_plat_w) ?'w':' ');
545 msg_pdbg2("ME %c%c %c%c %c%c %c%c %c%c\n",
546 (mstr->ME_descr_r) ?'r':' ', (mstr->ME_descr_w) ?'w':' ',
547 (mstr->ME_BIOS_r) ?'r':' ', (mstr->ME_BIOS_w) ?'w':' ',
548 (mstr->ME_ME_r) ?'r':' ', (mstr->ME_ME_w) ?'w':' ',
549 (mstr->ME_GbE_r) ?'r':' ', (mstr->ME_GbE_w) ?'w':' ',
550 (mstr->ME_plat_r) ?'r':' ', (mstr->ME_plat_w) ?'w':' ');
551 msg_pdbg2("GbE %c%c %c%c %c%c %c%c %c%c\n",
552 (mstr->GbE_descr_r) ?'r':' ', (mstr->GbE_descr_w) ?'w':' ',
553 (mstr->GbE_BIOS_r) ?'r':' ', (mstr->GbE_BIOS_w) ?'w':' ',
554 (mstr->GbE_ME_r) ?'r':' ', (mstr->GbE_ME_w) ?'w':' ',
555 (mstr->GbE_GbE_r) ?'r':' ', (mstr->GbE_GbE_w) ?'w':' ',
556 (mstr->GbE_plat_r) ?'r':' ', (mstr->GbE_plat_w) ?'w':' ');
557 }
Stefan Tauner1e146392011-09-15 23:52:55 +0000558 msg_pdbg2("\n");
559}
560
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600561static void prettyprint_ich_descriptor_straps_ich8(const struct ich_descriptors *desc)
Stefan Taunerb3850962011-12-24 00:00:32 +0000562{
563 static const char * const str_GPIO12[4] = {
564 "GPIO12",
565 "LAN PHY Power Control Function (Native Output)",
566 "GLAN_DOCK# (Native Input)",
567 "invalid configuration",
568 };
569
570 msg_pdbg2("--- MCH details ---\n");
571 msg_pdbg2("ME B is %sabled.\n", desc->north.ich8.MDB ? "dis" : "en");
572 msg_pdbg2("\n");
573
574 msg_pdbg2("--- ICH details ---\n");
575 msg_pdbg2("ME SMBus Address 1: 0x%02x\n", desc->south.ich8.ASD);
576 msg_pdbg2("ME SMBus Address 2: 0x%02x\n", desc->south.ich8.ASD2);
577 msg_pdbg2("ME SMBus Controller is connected to the %s.\n",
578 desc->south.ich8.MESM2SEL ? "SMLink pins" : "SMBus pins");
579 msg_pdbg2("SPI CS1 is used for %s.\n",
580 desc->south.ich8.SPICS1_LANPHYPC_SEL ?
581 "LAN PHY Power Control Function" :
582 "SPI Chip Select");
583 msg_pdbg2("GPIO12 is used as %s.\n",
584 str_GPIO12[desc->south.ich8.GPIO12_SEL]);
585 msg_pdbg2("PCIe Port 6 is used for %s.\n",
586 desc->south.ich8.GLAN_PCIE_SEL ? "integrated LAN" : "PCI Express");
587 msg_pdbg2("%sn BMC Mode: "
588 "Intel AMT SMBus Controller 1 is connected to %s.\n",
589 desc->south.ich8.BMCMODE ? "I" : "Not i",
590 desc->south.ich8.BMCMODE ? "SMLink" : "SMBus");
591 msg_pdbg2("TCO is in %s Mode.\n",
592 desc->south.ich8.TCOMODE ? "Advanced TCO" : "Legacy/Compatible");
593 msg_pdbg2("ME A is %sabled.\n",
594 desc->south.ich8.ME_DISABLE ? "dis" : "en");
595 msg_pdbg2("\n");
596}
597
598static void prettyprint_ich_descriptor_straps_56_pciecs(uint8_t conf, uint8_t off)
599{
600 msg_pdbg2("PCI Express Port Configuration Strap %d: ", off+1);
601
602 off *= 4;
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000603 switch (conf){
Stefan Taunerb3850962011-12-24 00:00:32 +0000604 case 0:
605 msg_pdbg2("4x1 Ports %d-%d (x1)", 1+off, 4+off);
606 break;
607 case 1:
608 msg_pdbg2("1x2, 2x1 Port %d (x2), Port %d (disabled), "
609 "Ports %d, %d (x1)", 1+off, 2+off, 3+off, 4+off);
610 break;
611 case 2:
612 msg_pdbg2("2x2 Port %d (x2), Port %d (x2), Ports "
613 "%d, %d (disabled)", 1+off, 3+off, 2+off, 4+off);
614 break;
615 case 3:
616 msg_pdbg2("1x4 Port %d (x4), Ports %d-%d (disabled)",
617 1+off, 2+off, 4+off);
618 break;
619 }
620 msg_pdbg2("\n");
621}
622
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600623static void prettyprint_ich_descriptor_pchstraps45678_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000624{
625 /* PCHSTRP4 */
626 msg_pdbg2("Intel PHY is %s.\n",
627 (s->ibex.PHYCON == 2) ? "connected" :
628 (s->ibex.PHYCON == 0) ? "disconnected" : "reserved");
629 msg_pdbg2("GbE MAC SMBus address is %sabled.\n",
630 s->ibex.GBEMAC_SMBUS_ADDR_EN ? "en" : "dis");
631 msg_pdbg2("GbE MAC SMBus address: 0x%02x\n",
632 s->ibex.GBEMAC_SMBUS_ADDR);
633 msg_pdbg2("GbE PHY SMBus address: 0x%02x\n",
634 s->ibex.GBEPHY_SMBUS_ADDR);
635
636 /* PCHSTRP5 */
637 /* PCHSTRP6 */
638 /* PCHSTRP7 */
639 msg_pdbg2("Intel ME SMBus Subsystem Vendor ID: 0x%04x\n",
640 s->ibex.MESMA2UDID_VENDOR);
641 msg_pdbg2("Intel ME SMBus Subsystem Device ID: 0x%04x\n",
642 s->ibex.MESMA2UDID_VENDOR);
643
644 /* PCHSTRP8 */
645}
646
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600647static void prettyprint_ich_descriptor_pchstraps111213_56(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000648{
649 /* PCHSTRP11 */
650 msg_pdbg2("SMLink1 GP Address is %sabled.\n",
651 s->ibex.SML1GPAEN ? "en" : "dis");
652 msg_pdbg2("SMLink1 controller General Purpose Target address: 0x%02x\n",
653 s->ibex.SML1GPA);
654 msg_pdbg2("SMLink1 I2C Target address is %sabled.\n",
655 s->ibex.SML1I2CAEN ? "en" : "dis");
656 msg_pdbg2("SMLink1 I2C Target address: 0x%02x\n",
657 s->ibex.SML1I2CA);
658
659 /* PCHSTRP12 */
660 /* PCHSTRP13 */
661}
662
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600663static void prettyprint_ich_descriptor_straps_ibex(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000664{
Stefan Tauner67d163d2013-01-15 17:37:48 +0000665 static const uint8_t dec_t209min[4] = {
Stefan Taunerb3850962011-12-24 00:00:32 +0000666 100,
667 50,
668 5,
669 1
670 };
671
672 msg_pdbg2("--- PCH ---\n");
673
674 /* PCHSTRP0 */
675 msg_pdbg2("Chipset configuration Softstrap 2: %d\n", s->ibex.cs_ss2);
676 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
677 s->ibex.SMB_EN ? "en" : "dis");
678 msg_pdbg2("SMLink0 segment is %sabled.\n",
679 s->ibex.SML0_EN ? "en" : "dis");
680 msg_pdbg2("SMLink1 segment is %sabled.\n",
681 s->ibex.SML1_EN ? "en" : "dis");
682 msg_pdbg2("SMLink1 Frequency: %s\n",
683 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
684 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
685 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
686 msg_pdbg2("SMLink0 Frequency: %s\n",
687 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
688 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
689 "LAN_PHY_PWR_CTRL" : "general purpose output");
690 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->ibex.cs_ss1);
691 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
692 s->ibex.DMI_REQID_DIS ? "en" : "dis");
693 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
694 1 << (6 + s->ibex.BBBS));
695
696 /* PCHSTRP1 */
697 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
698
699 /* PCHSTRP2 */
700 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
701 s->ibex.MESMASDEN ? "en" : "dis");
702 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
703 s->ibex.MESMASDA);
704 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
705 s->ibex.MESMI2CEN ? "en" : "dis");
706 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
707 s->ibex.MESMI2CA);
708
709 /* PCHSTRP3 */
710 prettyprint_ich_descriptor_pchstraps45678_56(s);
711 /* PCHSTRP9 */
712 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
713 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
714 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
715 s->ibex.PCIELR1 ? "" : "not ");
716 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
717 s->ibex.PCIELR2 ? "" : "not ");
718 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
719 s->ibex.DMILR ? "" : "not ");
720 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
721 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
722 s->ibex.PHY_PCIE_EN ? "en" : "dis");
723
724 /* PCHSTRP10 */
725 msg_pdbg2("Management Engine will boot from %sflash.\n",
726 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
727 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->ibex.cs_ss5);
728 msg_pdbg2("Virtualization Engine Enable 1 is %sabled.\n",
729 s->ibex.VE_EN ? "en" : "dis");
730 msg_pdbg2("ME Memory-attached Debug Display Device is %sabled.\n",
731 s->ibex.MMDDE ? "en" : "dis");
732 msg_pdbg2("ME Memory-attached Debug Display Device address: 0x%02x\n",
733 s->ibex.MMADDR);
734 msg_pdbg2("Chipset configuration Softstrap 7: %d\n", s->ibex.cs_ss7);
735 msg_pdbg2("Integrated Clocking Configuration is %d.\n",
736 (s->ibex.ICC_SEL == 7) ? 0 : s->ibex.ICC_SEL);
737 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a "
738 "reset.\n", s->ibex.MER_CL1 ? "" : "not ");
739
740 prettyprint_ich_descriptor_pchstraps111213_56(s);
741
742 /* PCHSTRP14 */
743 msg_pdbg2("Virtualization Engine Enable 2 is %sabled.\n",
744 s->ibex.VE_EN2 ? "en" : "dis");
745 msg_pdbg2("Virtualization Engine will boot from %sflash.\n",
746 s->ibex.VE_BOOT_FLASH ? "" : "ROM, then ");
747 msg_pdbg2("Braidwood SSD functionality is %sabled.\n",
748 s->ibex.BW_SSD ? "en" : "dis");
749 msg_pdbg2("Braidwood NVMHCI functionality is %sabled.\n",
750 s->ibex.NVMHCI_EN ? "en" : "dis");
751
752 /* PCHSTRP15 */
753 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->ibex.cs_ss6);
754 msg_pdbg2("Integrated wired LAN Solution is %sabled.\n",
755 s->ibex.IWL_EN ? "en" : "dis");
756 msg_pdbg2("t209 min Timing: %d ms\n",
757 dec_t209min[s->ibex.t209min]);
758 msg_pdbg2("\n");
759}
760
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600761static void prettyprint_ich_descriptor_straps_cougar(const struct ich_desc_south_strap *s)
Stefan Taunerb3850962011-12-24 00:00:32 +0000762{
763 msg_pdbg2("--- PCH ---\n");
764
765 /* PCHSTRP0 */
766 msg_pdbg2("Chipset configuration Softstrap 1: %d\n", s->cougar.cs_ss1);
767 msg_pdbg2("Intel ME SMBus Select is %sabled.\n",
768 s->ibex.SMB_EN ? "en" : "dis");
769 msg_pdbg2("SMLink0 segment is %sabled.\n",
770 s->ibex.SML0_EN ? "en" : "dis");
771 msg_pdbg2("SMLink1 segment is %sabled.\n",
772 s->ibex.SML1_EN ? "en" : "dis");
773 msg_pdbg2("SMLink1 Frequency: %s\n",
774 (s->ibex.SML1FRQ == 1) ? "100 kHz" : "reserved");
775 msg_pdbg2("Intel ME SMBus Frequency: %s\n",
776 (s->ibex.SMB0FRQ == 1) ? "100 kHz" : "reserved");
777 msg_pdbg2("SMLink0 Frequency: %s\n",
778 (s->ibex.SML0FRQ == 1) ? "100 kHz" : "reserved");
779 msg_pdbg2("GPIO12 is used as %s.\n", s->ibex.LANPHYPC_GP12_SEL ?
780 "LAN_PHY_PWR_CTRL" : "general purpose output");
781 msg_pdbg2("LinkSec is %sabled.\n",
782 s->cougar.LINKSEC_DIS ? "en" : "dis");
783 msg_pdbg2("DMI RequesterID Checks are %sabled.\n",
784 s->ibex.DMI_REQID_DIS ? "en" : "dis");
785 msg_pdbg2("BIOS Boot-Block size (BBBS): %d kB.\n",
786 1 << (6 + s->ibex.BBBS));
787
788 /* PCHSTRP1 */
789 msg_pdbg2("Chipset configuration Softstrap 3: 0x%x\n", s->ibex.cs_ss3);
790 msg_pdbg2("Chipset configuration Softstrap 2: 0x%x\n", s->ibex.cs_ss2);
791
792 /* PCHSTRP2 */
793 msg_pdbg2("ME SMBus ASD address is %sabled.\n",
794 s->ibex.MESMASDEN ? "en" : "dis");
795 msg_pdbg2("ME SMBus Controller ASD Target address: 0x%02x\n",
796 s->ibex.MESMASDA);
797 msg_pdbg2("ME SMBus MCTP Address is %sabled.\n",
798 s->cougar.MESMMCTPAEN ? "en" : "dis");
799 msg_pdbg2("ME SMBus MCTP target address: 0x%02x\n",
800 s->cougar.MESMMCTPA);
801 msg_pdbg2("ME SMBus I2C address is %sabled.\n",
802 s->ibex.MESMI2CEN ? "en" : "dis");
803 msg_pdbg2("ME SMBus I2C target address: 0x%02x\n",
804 s->ibex.MESMI2CA);
805
806 /* PCHSTRP3 */
807 prettyprint_ich_descriptor_pchstraps45678_56(s);
808 /* PCHSTRP9 */
809 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 0);
810 prettyprint_ich_descriptor_straps_56_pciecs(s->ibex.PCIEPCS1, 1);
811 msg_pdbg2("PCIe Lane Reversal 1: PCIe Lanes 0-3 are %sreserved.\n",
812 s->ibex.PCIELR1 ? "" : "not ");
813 msg_pdbg2("PCIe Lane Reversal 2: PCIe Lanes 4-7 are %sreserved.\n",
814 s->ibex.PCIELR2 ? "" : "not ");
815 msg_pdbg2("DMI Lane Reversal: DMI Lanes 0-3 are %sreserved.\n",
816 s->ibex.DMILR ? "" : "not ");
817 msg_pdbg2("ME Debug status writes over SMBUS are %sabled.\n",
818 s->cougar.MDSMBE_EN ? "en" : "dis");
819 msg_pdbg2("ME Debug SMBus Emergency Mode address: 0x%02x (raw)\n",
820 s->cougar.MDSMBE_ADD);
821 msg_pdbg2("Default PHY PCIe Port is %d.\n", s->ibex.PHY_PCIEPORTSEL+1);
822 msg_pdbg2("Integrated MAC/PHY communication over PCIe is %sabled.\n",
823 s->ibex.PHY_PCIE_EN ? "en" : "dis");
824 msg_pdbg2("PCIe ports Subtractive Decode Agent is %sabled.\n",
825 s->cougar.SUB_DECODE_EN ? "en" : "dis");
826 msg_pdbg2("GPIO74 is used as %s.\n", s->cougar.PCHHOT_SML1ALERT_SEL ?
827 "PCHHOT#" : "SML1ALERT#");
828
829 /* PCHSTRP10 */
830 msg_pdbg2("Management Engine will boot from %sflash.\n",
831 s->ibex.ME_BOOT_FLASH ? "" : "ROM, then ");
832
833 msg_pdbg2("ME Debug SMBus Emergency Mode is %sabled.\n",
834 s->cougar.MDSMBE_EN ? "en" : "dis");
835 msg_pdbg2("ME Debug SMBus Emergency Mode Address: 0x%02x\n",
836 s->cougar.MDSMBE_ADD);
837
838 msg_pdbg2("Integrated Clocking Configuration used: %d\n",
839 s->cougar.ICC_SEL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000840 msg_pdbg2("PCH Signal CL_RST1# does %sassert when Intel ME performs a reset.\n",
841 s->ibex.MER_CL1 ? "" : "not ");
Stefan Taunerb3850962011-12-24 00:00:32 +0000842 msg_pdbg2("ICC Profile is selected by %s.\n",
843 s->cougar.ICC_PRO_SEL ? "Softstraps" : "BIOS");
844 msg_pdbg2("Deep SX is %ssupported on the platform.\n",
845 s->cougar.Deep_SX_EN ? "not " : "");
846 msg_pdbg2("ME Debug LAN Emergency Mode is %sabled.\n",
847 s->cougar.ME_DBG_LAN ? "en" : "dis");
848
849 prettyprint_ich_descriptor_pchstraps111213_56(s);
850
851 /* PCHSTRP14 */
852 /* PCHSTRP15 */
853 msg_pdbg2("Chipset configuration Softstrap 6: %d\n", s->cougar.cs_ss6);
854 msg_pdbg2("Integrated wired LAN is %sabled.\n",
855 s->cougar.IWL_EN ? "en" : "dis");
856 msg_pdbg2("Chipset configuration Softstrap 5: %d\n", s->cougar.cs_ss5);
857 msg_pdbg2("SMLink1 provides temperature from %s.\n",
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000858 s->cougar.SMLINK1_THERM_SEL ? "PCH only" : "the CPU, PCH and DIMMs");
Stefan Taunerb3850962011-12-24 00:00:32 +0000859 msg_pdbg2("GPIO29 is used as %s.\n", s->cougar.SLP_LAN_GP29_SEL ?
860 "general purpose output" : "SLP_LAN#");
861
862 /* PCHSTRP16 */
863 /* PCHSTRP17 */
864 msg_pdbg2("Integrated Clock: %s Clock Mode\n",
865 s->cougar.ICML ? "Buffered Through" : "Full Integrated");
866 msg_pdbg2("\n");
867}
868
869void prettyprint_ich_descriptor_straps(enum ich_chipset cs, const struct ich_descriptors *desc)
870{
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000871 unsigned int i, max_count;
Stefan Taunerb3850962011-12-24 00:00:32 +0000872 msg_pdbg2("=== Softstraps ===\n");
873
Nico Huber157b8182024-07-19 17:48:12 +0200874 if (has_classic_proc_straps(cs)) {
875 max_count = MIN(ARRAY_SIZE(desc->north.STRPs), desc->content.MSL);
876 if (max_count < desc->content.MSL) {
877 msg_pdbg2("MSL (%u) is greater than the current maximum of %u entries.\n",
878 desc->content.MSL, max_count);
879 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
880 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000881
Nico Huber157b8182024-07-19 17:48:12 +0200882 msg_pdbg2("--- North/MCH/PROC (%d entries) ---\n", max_count);
883 for (i = 0; i < max_count; i++)
884 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->north.STRPs[i]);
885 msg_pdbg2("\n");
886 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000887
Nico Huber519be662018-12-23 20:03:35 +0100888 max_count = MIN(ARRAY_SIZE(desc->south.STRPs), desc->content.ISL);
Nico Huberd7c75522017-03-29 16:31:49 +0200889 if (max_count < desc->content.ISL) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000890 msg_pdbg2("ISL (%u) is greater than the current maximum of %u entries.\n",
891 desc->content.ISL, max_count);
892 msg_pdbg2("Only the first %u entries will be printed.\n", max_count);
Nico Huberd7c75522017-03-29 16:31:49 +0200893 }
Stefan Taunerb3850962011-12-24 00:00:32 +0000894
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000895 msg_pdbg2("--- South/ICH/PCH (%d entries) ---\n", max_count);
896 for (i = 0; i < max_count; i++)
Stefan Taunerb3850962011-12-24 00:00:32 +0000897 msg_pdbg2("STRP%-2d = 0x%08x\n", i, desc->south.STRPs[i]);
898 msg_pdbg2("\n");
899
900 switch (cs) {
901 case CHIPSET_ICH8:
902 if (sizeof(desc->north.ich8) / 4 != desc->content.MSL)
903 msg_pdbg2("Detailed North/MCH/PROC information is "
904 "probably not reliable, printing anyway.\n");
905 if (sizeof(desc->south.ich8) / 4 != desc->content.ISL)
906 msg_pdbg2("Detailed South/ICH/PCH information is "
907 "probably not reliable, printing anyway.\n");
908 prettyprint_ich_descriptor_straps_ich8(desc);
909 break;
910 case CHIPSET_5_SERIES_IBEX_PEAK:
911 /* PCH straps only. PROCSTRPs are unknown. */
912 if (sizeof(desc->south.ibex) / 4 != desc->content.ISL)
913 msg_pdbg2("Detailed South/ICH/PCH information is "
914 "probably not reliable, printing anyway.\n");
915 prettyprint_ich_descriptor_straps_ibex(&desc->south);
916 break;
917 case CHIPSET_6_SERIES_COUGAR_POINT:
918 /* PCH straps only. PROCSTRP0 is "reserved". */
919 if (sizeof(desc->south.cougar) / 4 != desc->content.ISL)
920 msg_pdbg2("Detailed South/ICH/PCH information is "
921 "probably not reliable, printing anyway.\n");
922 prettyprint_ich_descriptor_straps_cougar(&desc->south);
923 break;
924 case CHIPSET_ICH_UNKNOWN:
925 break;
926 default:
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000927 msg_pdbg2("The meaning of the descriptor straps are unknown yet.\n\n");
Stefan Taunerb3850962011-12-24 00:00:32 +0000928 break;
929 }
930}
931
Jacob Garberbeeb8bc2019-06-21 15:24:17 -0600932static void prettyprint_rdid(uint32_t reg_val)
Stefan Taunerb3850962011-12-24 00:00:32 +0000933{
934 uint8_t mid = reg_val & 0xFF;
935 uint16_t did = ((reg_val >> 16) & 0xFF) | (reg_val & 0xFF00);
936 msg_pdbg2("Manufacturer ID 0x%02x, Device ID 0x%04x\n", mid, did);
937}
938
939void prettyprint_ich_descriptor_upper_map(const struct ich_desc_upper_map *umap)
940{
941 int i;
942 msg_pdbg2("=== Upper Map Section ===\n");
943 msg_pdbg2("FLUMAP1 0x%08x\n", umap->FLUMAP1);
944 msg_pdbg2("\n");
945
946 msg_pdbg2("--- Details ---\n");
947 msg_pdbg2("VTL (length in DWORDS) = %d\n", umap->VTL);
948 msg_pdbg2("VTBA (base address) = 0x%6.6x\n", getVTBA(umap));
949 msg_pdbg2("\n");
950
951 msg_pdbg2("VSCC Table: %d entries\n", umap->VTL/2);
Stefan Taunera1a14ec2012-08-13 08:45:13 +0000952 for (i = 0; i < umap->VTL/2; i++) {
Stefan Taunerb3850962011-12-24 00:00:32 +0000953 uint32_t jid = umap->vscc_table[i].JID;
954 uint32_t vscc = umap->vscc_table[i].VSCC;
955 msg_pdbg2(" JID%d = 0x%08x\n", i, jid);
956 msg_pdbg2(" VSCC%d = 0x%08x\n", i, vscc);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600957 msg_pdbg2(" "); /* indentation */
Stefan Taunerb3850962011-12-24 00:00:32 +0000958 prettyprint_rdid(jid);
Martin Rothf6c1cb12022-03-15 10:55:25 -0600959 msg_pdbg2(" "); /* indentation */
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +0000960 prettyprint_ich_reg_vscc(vscc, 0, false);
Stefan Taunerb3850962011-12-24 00:00:32 +0000961 }
962 msg_pdbg2("\n");
963}
964
David Hendricks66565a72021-09-20 21:56:40 -0700965static inline void warn_peculiar_desc(const char *const name)
Nico Huber964007a2021-06-17 21:12:47 +0200966{
Nico Huber964007a2021-06-17 21:12:47 +0200967 msg_pwarn("Peculiar flash descriptor, assuming %s compatibility.\n", name);
968}
969
Nico Huber1dc3d422017-06-17 00:09:31 +0200970/*
971 * Guesses a minimum chipset version based on the maximum number of
Nico Huber3ad9aad2021-06-17 22:05:00 +0200972 * soft straps per generation and presence of the MIP base (MDTBA).
Nico Huber1dc3d422017-06-17 00:09:31 +0200973 */
Nico Huberdb878fb2024-07-19 17:37:09 +0200974static enum ich_chipset guess_ich_chipset(const struct ich_desc_content *const content,
975 const struct ich_desc_upper_map *const upper)
Nico Huber1dc3d422017-06-17 00:09:31 +0200976{
977 if (content->ICCRIBA == 0x00) {
978 if (content->MSL == 0 && content->ISL <= 2)
979 return CHIPSET_ICH8;
Nico Huber83b01c82021-06-17 21:20:09 +0200980 if (content->ISL <= 2)
Nico Huber1dc3d422017-06-17 00:09:31 +0200981 return CHIPSET_ICH9;
Nico Huber83b01c82021-06-17 21:20:09 +0200982 if (content->ISL <= 10)
Nico Huber1dc3d422017-06-17 00:09:31 +0200983 return CHIPSET_ICH10;
David Hendricks66565a72021-09-20 21:56:40 -0700984 if (content->ISL <= 16)
985 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber83b01c82021-06-17 21:20:09 +0200986 if (content->FLMAP2 == 0) {
Nico Huber81965f32021-06-17 23:25:35 +0200987 if (content->ISL == 19)
988 return CHIPSET_APOLLO_LAKE;
David Hendricks66565a72021-09-20 21:56:40 -0700989 if (content->ISL == 23)
990 return CHIPSET_GEMINI_LAKE;
991 warn_peculiar_desc("Gemini Lake");
Nico Huber81965f32021-06-17 23:25:35 +0200992 return CHIPSET_GEMINI_LAKE;
Nico Huberd2d39932019-01-18 16:49:37 +0100993 }
Jonathan Zhang3bf7cfb2021-08-30 23:25:06 -0700994 if (content->ISL <= 80)
995 return CHIPSET_C620_SERIES_LEWISBURG;
David Hendricks66565a72021-09-20 21:56:40 -0700996 warn_peculiar_desc("Ibex Peak");
Nico Huber1dc3d422017-06-17 00:09:31 +0200997 return CHIPSET_5_SERIES_IBEX_PEAK;
Nico Huber3ad9aad2021-06-17 22:05:00 +0200998 } else if (upper->MDTBA == 0x00) {
999 if (content->ICCRIBA < 0x31 && content->FMSBA < 0x30) {
1000 if (content->MSL == 0 && content->ISL <= 17)
1001 return CHIPSET_BAYTRAIL;
1002 if (content->MSL <= 1 && content->ISL <= 18)
1003 return CHIPSET_6_SERIES_COUGAR_POINT;
David Hendricks66565a72021-09-20 21:56:40 -07001004 if (content->MSL <= 1 && content->ISL <= 21)
1005 return CHIPSET_8_SERIES_LYNX_POINT;
1006 warn_peculiar_desc("Lynx Point");
Nico Huber81965f32021-06-17 23:25:35 +02001007 return CHIPSET_8_SERIES_LYNX_POINT;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001008 }
1009 if (content->NM == 6) {
David Hendricks66565a72021-09-20 21:56:40 -07001010 if (content->ICCRIBA <= 0x34)
1011 return CHIPSET_C620_SERIES_LEWISBURG;
1012 warn_peculiar_desc("C620 series");
Nico Huber2a5dfaf2019-07-04 16:01:51 +02001013 return CHIPSET_C620_SERIES_LEWISBURG;
Nico Huber3ad9aad2021-06-17 22:05:00 +02001014 }
David Hendricks66565a72021-09-20 21:56:40 -07001015 if (content->ICCRIBA == 0x31)
1016 return CHIPSET_100_SERIES_SUNRISE_POINT;
1017 warn_peculiar_desc("100 series");
Nico Huber83b01c82021-06-17 21:20:09 +02001018 return CHIPSET_100_SERIES_SUNRISE_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001019 } else {
David Hendricks66565a72021-09-20 21:56:40 -07001020 if (content->ICCRIBA == 0x34)
1021 return CHIPSET_300_SERIES_CANNON_POINT;
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001022 if (content->CSSL == 0x11)
1023 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber29c23dd2022-12-21 15:25:09 +00001024 if (content->CSSL == 0x14) /* backwards compatible Alder Point */
1025 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber756b6b32022-12-21 17:15:13 +00001026 if (content->CSSL == 0x03) {
1027 if (content->CSSO == 0x58)
1028 return CHIPSET_ELKHART_LAKE;
1029 else if (content->CSSO == 0x6c) /* backwards compatible Jasper Lake */
1030 return CHIPSET_300_SERIES_CANNON_POINT;
1031 }
Michał Żygowski5c9f5422021-06-16 15:13:54 +02001032 msg_pwarn("Unknown flash descriptor, assuming 500 series compatibility.\n");
1033 return CHIPSET_500_SERIES_TIGER_POINT;
Nico Huber1dc3d422017-06-17 00:09:31 +02001034 }
1035}
1036
Stefan Taunerb3850962011-12-24 00:00:32 +00001037/* len is the length of dump in bytes */
Nico Huberfa622942017-03-24 17:25:37 +01001038int read_ich_descriptors_from_dump(const uint32_t *const dump, const size_t len,
1039 enum ich_chipset *const cs, struct ich_descriptors *const desc)
Stefan Taunerb3850962011-12-24 00:00:32 +00001040{
Nico Huber519be662018-12-23 20:03:35 +01001041 ssize_t i, max_count;
1042 size_t pch_bug_offset = 0;
Stefan Taunerb3850962011-12-24 00:00:32 +00001043
1044 if (dump == NULL || desc == NULL)
1045 return ICH_RET_PARAM;
1046
1047 if (dump[0] != DESCRIPTOR_MODE_SIGNATURE) {
1048 if (dump[4] == DESCRIPTOR_MODE_SIGNATURE)
1049 pch_bug_offset = 4;
1050 else
1051 return ICH_RET_ERR;
1052 }
1053
1054 /* map */
Nico Huber9e14aed2017-03-28 17:08:46 +02001055 if (len < (4 + pch_bug_offset) * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001056 return ICH_RET_OOB;
1057 desc->content.FLVALSIG = dump[0 + pch_bug_offset];
1058 desc->content.FLMAP0 = dump[1 + pch_bug_offset];
1059 desc->content.FLMAP1 = dump[2 + pch_bug_offset];
1060 desc->content.FLMAP2 = dump[3 + pch_bug_offset];
1061
1062 /* component */
Nico Huber9e14aed2017-03-28 17:08:46 +02001063 if (len < getFCBA(&desc->content) + 3 * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001064 return ICH_RET_OOB;
1065 desc->component.FLCOMP = dump[(getFCBA(&desc->content) >> 2) + 0];
1066 desc->component.FLILL = dump[(getFCBA(&desc->content) >> 2) + 1];
1067 desc->component.FLPB = dump[(getFCBA(&desc->content) >> 2) + 2];
1068
Nico Huber8a03c902021-06-17 21:23:29 +02001069 /* upper map */
1070 desc->upper.FLUMAP1 = dump[(UPPER_MAP_OFFSET >> 2) + 0];
1071
1072 /* VTL is 8 bits long. Quote from the Ibex Peak SPI programming guide:
1073 * "Identifies the 1s based number of DWORDS contained in the VSCC
1074 * Table. Each SPI component entry in the table is 2 DWORDS long." So
1075 * the maximum of 255 gives us 127.5 SPI components(!?) 8 bytes each. A
1076 * check ensures that the maximum offset actually accessed is available.
1077 */
1078 if (len < getVTBA(&desc->upper) + (desc->upper.VTL / 2 * 8))
1079 return ICH_RET_OOB;
1080
1081 for (i = 0; i < desc->upper.VTL/2; i++) {
1082 desc->upper.vscc_table[i].JID = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 0];
1083 desc->upper.vscc_table[i].VSCC = dump[(getVTBA(&desc->upper) >> 2) + i * 2 + 1];
1084 }
1085
Nico Huber67d71792017-06-17 03:10:15 +02001086 if (*cs == CHIPSET_ICH_UNKNOWN) {
Nico Huberdb878fb2024-07-19 17:37:09 +02001087 *cs = guess_ich_chipset(&desc->content, &desc->upper);
Nico Huber67d71792017-06-17 03:10:15 +02001088 prettyprint_ich_chipset(*cs);
1089 }
Nico Huberfa622942017-03-24 17:25:37 +01001090
Stefan Taunerb3850962011-12-24 00:00:32 +00001091 /* region */
Nico Huberfa622942017-03-24 17:25:37 +01001092 const ssize_t nr = ich_number_of_regions(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001093 if (nr < 0 || len < getFRBA(&desc->content) + (size_t)nr * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001094 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001095 for (i = 0; i < nr; i++)
1096 desc->region.FLREGs[i] = dump[(getFRBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001097
1098 /* master */
Nico Huberfa622942017-03-24 17:25:37 +01001099 const ssize_t nm = ich_number_of_masters(*cs, &desc->content);
Nico Huber519be662018-12-23 20:03:35 +01001100 if (nm < 0 || len < getFMBA(&desc->content) + (size_t)nm * 4)
Stefan Taunerb3850962011-12-24 00:00:32 +00001101 return ICH_RET_OOB;
Nico Huberfa622942017-03-24 17:25:37 +01001102 for (i = 0; i < nm; i++)
1103 desc->master.FLMSTRs[i] = dump[(getFMBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001104
Nico Huber157b8182024-07-19 17:48:12 +02001105 if (has_classic_proc_straps(*cs)) {
1106 /* MCH/PROC (aka. North) straps */
1107 if (len < getFMSBA(&desc->content) + desc->content.MSL * 4)
1108 return ICH_RET_OOB;
Stefan Taunerb3850962011-12-24 00:00:32 +00001109
Nico Huber157b8182024-07-19 17:48:12 +02001110 /* limit the range to be written */
1111 max_count = MIN(sizeof(desc->north.STRPs) / 4, desc->content.MSL);
1112 for (i = 0; i < max_count; i++)
1113 desc->north.STRPs[i] = dump[(getFMSBA(&desc->content) >> 2) + i];
1114 }
Stefan Taunerb3850962011-12-24 00:00:32 +00001115
1116 /* ICH/PCH (aka. South) straps */
1117 if (len < getFISBA(&desc->content) + desc->content.ISL * 4)
1118 return ICH_RET_OOB;
1119
1120 /* limit the range to be written */
Nico Huber519be662018-12-23 20:03:35 +01001121 max_count = MIN(sizeof(desc->south.STRPs) / 4, desc->content.ISL);
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001122 for (i = 0; i < max_count; i++)
1123 desc->south.STRPs[i] = dump[(getFISBA(&desc->content) >> 2) + i];
Stefan Taunerb3850962011-12-24 00:00:32 +00001124
1125 return ICH_RET_OK;
1126}
1127
Nico Huberad186312016-05-02 15:15:29 +02001128#ifndef ICH_DESCRIPTORS_FROM_DUMP_ONLY
Stefan Taunerb3850962011-12-24 00:00:32 +00001129
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001130/** Returns the integer representation of the component density with index
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001131\em idx in bytes or -1 if the correct size can not be determined. */
1132int getFCBA_component_density(enum ich_chipset cs, const struct ich_descriptors *desc, uint8_t idx)
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001133{
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001134 if (idx > 1) {
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001135 msg_perr("Only ICH SPI component index 0 or 1 are supported yet.\n");
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001136 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001137 }
Nico Huberdfd06472024-07-14 23:45:05 +02001138 if (cs == CHIPSET_ICH_UNKNOWN) {
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001139 msg_pwarn("Density encoding is unknown on this chipset.\n");
1140 return -1;
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001141 }
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001142
Nico Huberdfd06472024-07-14 23:45:05 +02001143 if (desc->content.NC == 0 && idx > 0)
1144 return 0;
1145
1146 const unsigned int max_idx = cs < CHIPSET_HAS_NEW_COMPONENT_DENSITY ? 5 : 7;
1147 const unsigned int size_idx = get_density_index(cs, desc, idx);
1148
1149 if (size_idx > max_idx) {
Tai-Hong Wu60dead42015-01-05 23:00:14 +00001150 msg_perr("Density of ICH SPI component with index %d is invalid.\n"
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001151 "Encoded density is 0x%x while maximum allowed is 0x%x.\n",
Nico Huberdfd06472024-07-14 23:45:05 +02001152 idx, size_idx, max_idx);
Stefan Tauner2ba9f6e2014-08-20 15:39:19 +00001153 return -1;
1154 }
1155
Nico Huberdfd06472024-07-14 23:45:05 +02001156 return 1 << (19 + size_idx);
Stefan Taunerd0c5dc22011-10-20 12:57:14 +00001157}
1158
Nico Huber8d494992017-06-19 12:18:33 +02001159/* Only used by ichspi.c */
1160#if CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__))
Nico Huberd54e4f42017-03-23 23:45:47 +01001161static uint32_t read_descriptor_reg(enum ich_chipset cs, uint8_t section, uint16_t offset, void *spibar)
Stefan Tauner1e146392011-09-15 23:52:55 +00001162{
1163 uint32_t control = 0;
1164 control |= (section << FDOC_FDSS_OFF) & FDOC_FDSS;
1165 control |= (offset << FDOC_FDSI_OFF) & FDOC_FDSI;
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001166
1167 if (cs >= SPI_ENGINE_PCH100) {
Nico Huberd54e4f42017-03-23 23:45:47 +01001168 mmio_le_writel(control, spibar + PCH100_REG_FDOC);
1169 return mmio_le_readl(spibar + PCH100_REG_FDOD);
Nico Huberb2ad9fd2024-07-14 23:18:53 +02001170 } else {
Nico Huberd54e4f42017-03-23 23:45:47 +01001171 mmio_le_writel(control, spibar + ICH9_REG_FDOC);
1172 return mmio_le_readl(spibar + ICH9_REG_FDOD);
1173 }
Stefan Tauner1e146392011-09-15 23:52:55 +00001174}
1175
Nico Huberd54e4f42017-03-23 23:45:47 +01001176int read_ich_descriptors_via_fdo(enum ich_chipset cs, void *spibar, struct ich_descriptors *desc)
Stefan Tauner1e146392011-09-15 23:52:55 +00001177{
Nico Huber519be662018-12-23 20:03:35 +01001178 ssize_t i;
Stefan Tauner1e146392011-09-15 23:52:55 +00001179 struct ich_desc_region *r = &desc->region;
1180
1181 /* Test if bit-fields are working as expected.
1182 * FIXME: Replace this with dynamic bitfield fixup
1183 */
1184 for (i = 0; i < 4; i++)
1185 desc->region.FLREGs[i] = 0x5A << (i * 8);
Nico Huberfa622942017-03-24 17:25:37 +01001186 if (r->old_reg[0].base != 0x005A || r->old_reg[0].limit != 0x0000 ||
1187 r->old_reg[1].base != 0x1A00 || r->old_reg[1].limit != 0x0000 ||
1188 r->old_reg[2].base != 0x0000 || r->old_reg[2].limit != 0x005A ||
1189 r->old_reg[3].base != 0x0000 || r->old_reg[3].limit != 0x1A00) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001190 msg_pdbg("The combination of compiler and CPU architecture used"
1191 "does not lay out bit-fields as expected, sorry.\n");
Nico Huberfa622942017-03-24 17:25:37 +01001192 msg_pspew("r->old_reg[0].base = 0x%04X (0x005A)\n", r->old_reg[0].base);
1193 msg_pspew("r->old_reg[0].limit = 0x%04X (0x0000)\n", r->old_reg[0].limit);
1194 msg_pspew("r->old_reg[1].base = 0x%04X (0x1A00)\n", r->old_reg[1].base);
1195 msg_pspew("r->old_reg[1].limit = 0x%04X (0x0000)\n", r->old_reg[1].limit);
1196 msg_pspew("r->old_reg[2].base = 0x%04X (0x0000)\n", r->old_reg[2].base);
1197 msg_pspew("r->old_reg[2].limit = 0x%04X (0x005A)\n", r->old_reg[2].limit);
1198 msg_pspew("r->old_reg[3].base = 0x%04X (0x0000)\n", r->old_reg[3].base);
1199 msg_pspew("r->old_reg[3].limit = 0x%04X (0x1A00)\n", r->old_reg[3].limit);
Stefan Tauner1e146392011-09-15 23:52:55 +00001200 return ICH_RET_ERR;
1201 }
1202
Stefan Taunera1a14ec2012-08-13 08:45:13 +00001203 msg_pdbg2("Reading flash descriptors mapped by the chipset via FDOC/FDOD...");
Stefan Tauner1e146392011-09-15 23:52:55 +00001204 /* content section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001205 desc->content.FLVALSIG = read_descriptor_reg(cs, 0, 0, spibar);
1206 desc->content.FLMAP0 = read_descriptor_reg(cs, 0, 1, spibar);
1207 desc->content.FLMAP1 = read_descriptor_reg(cs, 0, 2, spibar);
1208 desc->content.FLMAP2 = read_descriptor_reg(cs, 0, 3, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001209
1210 /* component section */
Nico Huberd54e4f42017-03-23 23:45:47 +01001211 desc->component.FLCOMP = read_descriptor_reg(cs, 1, 0, spibar);
1212 desc->component.FLILL = read_descriptor_reg(cs, 1, 1, spibar);
1213 desc->component.FLPB = read_descriptor_reg(cs, 1, 2, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001214
1215 /* region section */
Nico Huberfa622942017-03-24 17:25:37 +01001216 const ssize_t nr = ich_number_of_regions(cs, &desc->content);
1217 if (nr < 0) {
Stefan Tauner1e146392011-09-15 23:52:55 +00001218 msg_pdbg2("%s: number of regions too high (%d) - failed\n",
Nico Huberfa622942017-03-24 17:25:37 +01001219 __func__, desc->content.NR + 1);
Stefan Tauner1e146392011-09-15 23:52:55 +00001220 return ICH_RET_ERR;
1221 }
Nico Huberfa622942017-03-24 17:25:37 +01001222 for (i = 0; i < nr; i++)
Nico Huberd54e4f42017-03-23 23:45:47 +01001223 desc->region.FLREGs[i] = read_descriptor_reg(cs, 2, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001224
1225 /* master section */
Nico Huberfa622942017-03-24 17:25:37 +01001226 const ssize_t nm = ich_number_of_masters(cs, &desc->content);
1227 if (nm < 0) {
1228 msg_pdbg2("%s: number of masters too high (%d) - failed\n",
1229 __func__, desc->content.NM + 1);
1230 return ICH_RET_ERR;
1231 }
1232 for (i = 0; i < nm; i++)
1233 desc->master.FLMSTRs[i] = read_descriptor_reg(cs, 3, i, spibar);
Stefan Tauner1e146392011-09-15 23:52:55 +00001234
1235 /* Accessing the strap section via FDOC/D is only possible on ICH8 and
1236 * reading the upper map is impossible on all chipsets, so don't bother.
1237 */
1238
1239 msg_pdbg2(" done.\n");
1240 return ICH_RET_OK;
1241}
Nico Huber8d494992017-06-19 12:18:33 +02001242#endif
Nico Huber305f4172013-06-14 11:55:26 +02001243
1244/**
1245 * @brief Read a layout from the dump of an Intel ICH descriptor.
1246 *
1247 * @param layout Pointer where to store the layout.
1248 * @param dump The descriptor dump to read from.
1249 * @param len The length of the descriptor dump.
1250 *
1251 * @return 0 on success,
Nico Huber70461a92019-06-15 14:56:19 +02001252 * 1 if the descriptor couldn't be parsed,
1253 * 2 when out of memory.
Nico Huber305f4172013-06-14 11:55:26 +02001254 */
Nico Huber5bd990c2019-06-16 19:46:46 +02001255int layout_from_ich_descriptors(
Nico Huberc3b02dc2023-08-12 01:13:45 +02001256 struct flashprog_layout **const layout,
Nico Huber5bd990c2019-06-16 19:46:46 +02001257 const void *const dump, const size_t len)
Nico Huber305f4172013-06-14 11:55:26 +02001258{
Nico Huberfa622942017-03-24 17:25:37 +01001259 static const char *const regions[] = {
David Hendricksa5216362017-08-08 20:02:22 -07001260 "fd", "bios", "me", "gbe", "pd", "reg5", "bios2", "reg7", "ec", "reg9", "ie",
1261 "10gbe", "reg12", "reg13", "reg14", "reg15"
Nico Huberfa622942017-03-24 17:25:37 +01001262 };
Nico Huber305f4172013-06-14 11:55:26 +02001263
1264 struct ich_descriptors desc;
Nico Huberfa622942017-03-24 17:25:37 +01001265 enum ich_chipset cs = CHIPSET_ICH_UNKNOWN;
1266 if (read_ich_descriptors_from_dump(dump, len, &cs, &desc))
Nico Huber305f4172013-06-14 11:55:26 +02001267 return 1;
1268
Nico Huberc3b02dc2023-08-12 01:13:45 +02001269 if (flashprog_layout_new(layout))
Nico Huber5bd990c2019-06-16 19:46:46 +02001270 return 2;
Nico Huber305f4172013-06-14 11:55:26 +02001271
Nico Huber92e0b622019-06-15 15:55:11 +02001272 ssize_t i;
Nico Huber519be662018-12-23 20:03:35 +01001273 const ssize_t nr = MIN(ich_number_of_regions(cs, &desc.content), (ssize_t)ARRAY_SIZE(regions));
Nico Huber92e0b622019-06-15 15:55:11 +02001274 for (i = 0; i < nr; ++i) {
Nico Huber305f4172013-06-14 11:55:26 +02001275 const chipoff_t base = ICH_FREG_BASE(desc.region.FLREGs[i]);
Nico Huber0bb3f712017-03-29 16:44:33 +02001276 const chipoff_t limit = ICH_FREG_LIMIT(desc.region.FLREGs[i]);
Nico Huber305f4172013-06-14 11:55:26 +02001277 if (limit <= base)
1278 continue;
Nico Huberc3b02dc2023-08-12 01:13:45 +02001279 if (flashprog_layout_add_region(*layout, base, limit, regions[i])) {
1280 flashprog_layout_release(*layout);
Nico Huber5bd990c2019-06-16 19:46:46 +02001281 *layout = NULL;
Nico Huber70461a92019-06-15 14:56:19 +02001282 return 2;
Nico Huber5bd990c2019-06-16 19:46:46 +02001283 }
Nico Huber305f4172013-06-14 11:55:26 +02001284 }
Nico Huber305f4172013-06-14 11:55:26 +02001285 return 0;
1286}
1287
Nico Huberad186312016-05-02 15:15:29 +02001288#endif /* ICH_DESCRIPTORS_FROM_DUMP_ONLY */